* fixing typos * merge Dynamic commands (#3) * Update README.md * Update README.md * fixing typos * dynamically read new commands inside folder. * eslint, update package.json due to moving files Co-authored-by: Marcus Netz <marcus.netz@godyo.com> * fix talent checking on empty arguments list * Origin/message embed (#4) * add first embedded message on tp.js * move db from message commands * fix missing arguments list, add need_args * add global Message Replies. * add more global Message Replies. * more embedded messages. fixing string * missing comma * adding a few more strings on talents. Co-authored-by: Marcus Netz <marcus.netz@godyo.com> * fixing creating from json file * bugfix: db not defined * possible fix for nonworking talent? * fix double msg * fix: aliases are now being used * change: show command displays now some character attributes * added various aliases to commands, added global strings. * added melee combat rolling. * removed purse from creation of character * added attack command to bring some combat features. * added weapons command, renamed some command files. * updated README for new commands Co-authored-by: Marcus Netz <marcus.netz@godyo.com>
86 lines
2.7 KiB
JavaScript
86 lines
2.7 KiB
JavaScript
const globals = require('../globals');
|
|
const Random = require('random');
|
|
const db = globals.db
|
|
|
|
module.exports = {
|
|
name: 'attribute',
|
|
description: '',
|
|
aliases: ['ap', 'ep'],
|
|
usage: '<Eigenschaft> / <Eigenschaftswert>',
|
|
needs_args: true,
|
|
async exec(message, args) {
|
|
try {
|
|
let level = 8;
|
|
let attributename;
|
|
|
|
await db.find({
|
|
user: message.author.tag,
|
|
}, async function(err, docs) {
|
|
|
|
// user calls with text. need to gather info from database
|
|
if (isNaN(args[0])) {
|
|
if (!docs.length > 0) {
|
|
message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
|
|
return;
|
|
}
|
|
else {
|
|
// try to get id of short formatted attributes.
|
|
if (args[0].length == 2) {
|
|
for (const i in globals.Werte) {
|
|
if (globals.Werte[i].kuerzel == args[0].toUpperCase()) {
|
|
attributename = globals.Werte[i].id;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
attributename = args[0].toLowerCase();
|
|
}
|
|
for (const i in docs[0].character.attributes) {
|
|
if (docs[0].character.attributes[i].id == attributename) level = docs[0].character.attributes[i].level;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
level = args[0];
|
|
}
|
|
Random.use(message.author.tag);
|
|
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
|
|
const dice = [];
|
|
dice.push(Random.int(1, 20));
|
|
if (dice[0] == 1 || dice[0] == 20) {
|
|
dice.push(Random.int(1, 20));
|
|
}
|
|
// handle crits
|
|
if (countOccurrences(dice, 1) == 2) {
|
|
message.reply('Du hast einen kritischen Erfolg erzielt (' + dice.join(', ') + ')! 🎉🥳🎆');
|
|
return;
|
|
}
|
|
else if (countOccurrences(dice, 20) == 2) {
|
|
message.reply('Du hast einen Patzer (' + dice.join(', ') + ')! 😭 Viel Erfolg beim nächsten mal!');
|
|
return;
|
|
}
|
|
if ((dice.length == 2 && dice[0] != 20 && dice[1] <= level) || (dice.length == 1 && dice[0] <= level)) {
|
|
if (attributename) {
|
|
message.reply('Du hast die Probe auf ' + attributename + ' (Stufe ' + level + ') bestanden.\n' +
|
|
'Deine 🎲: ' + dice.join(', '));
|
|
}
|
|
else {
|
|
message.reply('Du hast die Probe (Stufe ' + level + ') bestanden.\n' +
|
|
'Deine 🎲: ' + dice.join(', '));
|
|
}
|
|
}
|
|
else if (attributename) {
|
|
message.reply('Du hast die Probe auf ' + attributename + ' (Stufe ' + level + ') leider nicht bestanden 😢.\n' +
|
|
'Deine 🎲: ' + dice.join(', '));
|
|
}
|
|
else {
|
|
message.reply('Du hast die Probe (Stufe ' + level + ') leider nicht bestanden 😢.\n' +
|
|
'Deine 🎲: ' + dice.join(', '));
|
|
}
|
|
});
|
|
}
|
|
catch (e) {
|
|
throw e;
|
|
}
|
|
},
|
|
}; |