* linting, rolling dice now calculates the sum of each shown value.

* package update
This commit is contained in:
2021-02-09 17:23:23 +01:00
committed by GitHub
parent 20fb66643e
commit 9c0c365cd5
13 changed files with 201 additions and 202 deletions

View File

@ -1,6 +1,6 @@
const globals = require('../globals') const globals = require('../globals');
const db = globals.db const db = globals.db;
const Random = require('random') const Random = require('random');
module.exports = { module.exports = {
name: 'attack', name: 'attack',
@ -14,103 +14,103 @@ module.exports = {
db.find({ db.find({
user: message.author.tag, user: message.author.tag,
}, function(err, docs) { }, function(err, docs) {
if (!docs.length > 0) { if (docs.length === 0) {
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string); return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
} }
else { else {
Random.use(message.author.tag); Random.use(message.author.tag);
const Player = docs[0].character const Player = docs[0].character;
const Weapon = globals.Weapons.find(w => w.id === args[0].toLowerCase()) const Weapon = globals.Weapons.find(w => w.id === args[0].toLowerCase());
if(!Weapon) { return message.reply(globals.Replies.find(r => r.id === 'NO_SUCH_WEAPON').string)} if(!Weapon) { return message.reply(globals.Replies.find(r => r.id === 'NO_SUCH_WEAPON').string); }
// Determining Both Attack and Ranged Attack Values. // Determining Both Attack and Ranged Attack Values.
const CombatTechnique = globals.CombatTechniques.find(technique => technique.id === Weapon.combattechnique) const CombatTechnique = globals.CombatTechniques.find(technique => technique.id === Weapon.combattechnique);
let PlayerCombatTechnique = Player.combattechniques.find(technique => technique.id === CombatTechnique.id) let PlayerCombatTechnique = Player.combattechniques.find(technique => technique.id === CombatTechnique.id);
let CombatTechniqueValue = null let CombatTechniqueValue = null;
if (PlayerCombatTechnique) { CombatTechniqueValue = PlayerCombatTechnique.level } if (PlayerCombatTechnique) { CombatTechniqueValue = PlayerCombatTechnique.level; }
if(!CombatTechniqueValue) { CombatTechniqueValue = 6 } if(!CombatTechniqueValue) { CombatTechniqueValue = 6; }
let Attribute let Attribute;
let AttackValue = CombatTechniqueValue let AttackValue = CombatTechniqueValue;
if (globals.MeleeWeapons.find(MeleeWeapon => MeleeWeapon.id === Weapon.id)) { if (globals.MeleeWeapons.find(MeleeWeapon => MeleeWeapon.id === Weapon.id)) {
// For melee combat, MU is used for determining the Attack Value. Also, any weapon-based attack modifiers apply. // For melee combat, MU is used for determining the Attack Value. Also, any weapon-based attack modifiers apply.
Attribute = Player.attributes.find(a => a.id === 'mut').level Attribute = Player.attributes.find(a => a.id === 'mut').level;
AttackValue += Weapon.at_mod AttackValue += Weapon.at_mod;
} }
else { else {
// For ranged combat, FF is used for determining Attack Value // For ranged combat, FF is used for determining Attack Value
Attribute = Player.attributes.find(a => a.id === 'fingerfertigkeit').level Attribute = Player.attributes.find(a => a.id === 'fingerfertigkeit').level;
} }
AttackValue += Math.floor((Attribute - 8)/3) AttackValue += Math.floor((Attribute - 8)/3);
let dice = [] let dice = [];
let Bonus = 0 let Bonus = 0;
if(args[1] && !isNaN(parseInt(args[1]))) { Bonus = parseInt(args[1]) } if(args[1] && !isNaN(parseInt(args[1]))) { Bonus = parseInt(args[1]); }
let Comparison = Math.floor(AttackValue + Bonus) let Comparison = Math.floor(AttackValue + Bonus);
let CriticalHit = false let CriticalHit = false;
let Patzer = false let Patzer = false;
let Ok = false let Ok = false;
let DoubleDamage = false let DoubleDamage = false;
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
dice.push(Random.int(1,20)) dice.push(Random.int(1,20));
} }
// If there is a cleaner way to do these checks, I'm all into it. // If there is a cleaner way to do these checks, I'm all into it.
if((dice[0] == 1) && dice[1] <= Comparison) { CriticalHit = true; DoubleDamage = true; Ok = true } if((dice[0] == 1) && dice[1] <= Comparison) { CriticalHit = true; DoubleDamage = true; Ok = true; }
else if((dice[0] == 1) && dice[1] > Comparison) { CriticalHit = true; Ok = true } else if((dice[0] == 1) && dice[1] > Comparison) { CriticalHit = true; Ok = true; }
else if((dice[0] == 20) && dice[1] > Comparison) { Patzer = true } else if((dice[0] == 20) && dice[1] > Comparison) { Patzer = true; }
else if(dice[0] <= Comparison && !CriticalHit) { Ok = true; dice.pop(); } else if(dice[0] <= Comparison && !CriticalHit) { Ok = true; dice.pop(); }
else if(dice[0] > Comparison ) { dice.pop(); } else if(dice[0] > Comparison ) { dice.pop(); }
let Reply = 'Du greifst mit ' + globals.Declination[Weapon.article] + ' ' + Weapon.name + ' an.\n' let Reply = 'Du greifst mit ' + globals.Declination[Weapon.article] + ' ' + Weapon.name + ' an.\n';
Reply += 'Dein Angriffswert für ' + CombatTechnique.name + ' ist ' + Math.floor(((Attribute - 8)/3) + CombatTechniqueValue) + '. (KtW: ' + CombatTechniqueValue + ')\n' Reply += 'Dein Angriffswert für ' + CombatTechnique.name + ' ist ' + Math.floor(((Attribute - 8)/3) + CombatTechniqueValue) + '. (KtW: ' + CombatTechniqueValue + ')\n';
Reply += 'Deine 🎲: ` ' + dice.join(', ') + ' `.\n\n' Reply += 'Deine 🎲: ` ' + dice.join(', ') + ' `.\n\n';
if(!Ok) { if(!Ok) {
Reply += globals.Replies.find(reply => reply.id === 'COMBAT_FAIL').string Reply += globals.Replies.find(reply => reply.id === 'COMBAT_FAIL').string;
if(Patzer) { Reply += globals.Replies.find(reply => reply.id === 'COMBAT_CRIT_FAIL').string } if(Patzer) { Reply += globals.Replies.find(reply => reply.id === 'COMBAT_CRIT_FAIL').string; }
} }
else { else {
if(CriticalHit) { Reply += globals.Replies.find(reply => reply.id === 'COMBAT_CRIT_SUCCESS').string } if(CriticalHit) { Reply += globals.Replies.find(reply => reply.id === 'COMBAT_CRIT_SUCCESS').string; }
if(DoubleDamage) { Reply += globals.Replies.find(reply => reply.id === 'COMBAT_DOUBLEDAMAGE').string } if(DoubleDamage) { Reply += globals.Replies.find(reply => reply.id === 'COMBAT_DOUBLEDAMAGE').string; }
if(!CriticalHit) { Reply += globals.Replies.find(reply => reply.id === 'COMBAT_SUCCESS').string } if(!CriticalHit) { Reply += globals.Replies.find(reply => reply.id === 'COMBAT_SUCCESS').string; }
// adding 1 to damage for every point above weapon's "Leiteigenschaft" // adding 1 to damage for every point above weapon's "Leiteigenschaft"
// applies only to Melee Weapons. // applies only to Melee Weapons.
let AttackBonus = 0 let AttackBonus = 0;
if (globals.MeleeWeapons.find(MeleeWeapon => MeleeWeapon.id === Weapon.id)) if (globals.MeleeWeapons.find(MeleeWeapon => MeleeWeapon.id === Weapon.id))
{ {
if(Weapon.DmgThreshold) { if(Weapon.DmgThreshold) {
CombatTechnique.Leiteigenschaft.forEach(LEKuerzel => { CombatTechnique.Leiteigenschaft.forEach(LEKuerzel => {
let Leiteigenschaft = globals.Werte.find(attribute => attribute.kuerzel === LEKuerzel) let Leiteigenschaft = globals.Werte.find(attribute => attribute.kuerzel === LEKuerzel);
let DmgThreshold = Weapon.DmgThreshold let DmgThreshold = Weapon.DmgThreshold;
let AttributeValue = Player.attributes.find(attribute => attribute.id === Leiteigenschaft.id).level let AttributeValue = Player.attributes.find(attribute => attribute.id === Leiteigenschaft.id).level;
if(DmgThreshold<AttributeValue) { if(DmgThreshold<AttributeValue) {
AttackBonus += Math.floor(AttributeValue - DmgThreshold) AttackBonus += Math.floor(AttributeValue - DmgThreshold);
} }
}) });
} }
} }
const DieModificator = Weapon.diemodificator const DieModificator = Weapon.diemodificator;
let Damage = DieModificator + AttackBonus let Damage = DieModificator + AttackBonus;
let DamageDice = [] let DamageDice = [];
for (let i = 0; i < Weapon.dice; i++) { for (let i = 0; i < Weapon.dice; i++) {
DamageDice.push(Random.int(1,6)) DamageDice.push(Random.int(1,6));
} }
DamageDice.forEach(result => { DamageDice.forEach(result => {
Damage += result Damage += result;
}) });
if(DoubleDamage) { Damage *= 2 } if(DoubleDamage) { Damage *= 2; }
Reply += '\n\nHier aufklappen, wenn der Gegner nicht parieren/Ausweichen konnte:\n' Reply += '\n\nHier aufklappen, wenn der Gegner nicht parieren/Ausweichen konnte:\n';
Reply += '||' + globals.Articles[Weapon.article] + ' ' + Weapon.name + ' (' + Weapon.dice + 'W6+' + Weapon.diemodificator +') erzielt ` ' + Damage + ' ` Schaden.' Reply += '||' + globals.Articles[Weapon.article] + ' ' + Weapon.name + ' (' + Weapon.dice + 'W6+' + Weapon.diemodificator +') erzielt ` ' + Damage + ' ` Schaden.';
Reply += '\nDeine 🎲: ` ' + DamageDice.join(',') + ' `.||\n' Reply += '\nDeine 🎲: ` ' + DamageDice.join(',') + ' `.||\n';
} }
return message.reply( Reply ) return message.reply( Reply );
} }
}); });

View File

@ -1,6 +1,6 @@
const globals = require('../globals'); const globals = require('../globals');
const Random = require('random'); const Random = require('random');
const db = globals.db const db = globals.db;
module.exports = { module.exports = {
name: 'attribute', name: 'attribute',
@ -19,7 +19,7 @@ module.exports = {
// user calls with text. need to gather info from database // user calls with text. need to gather info from database
if (isNaN(args[0])) { if (isNaN(args[0])) {
if (!docs.length > 0) { if (docs.length === 0) {
message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string); message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
return; return;
} }

View File

@ -1,6 +1,6 @@
const globals = require('../globals') const globals = require('../globals');
const db = globals.db const db = globals.db;
const Random = require('random') const Random = require('random');
/* /*
"meleeweapons": [{ "meleeweapons": [{
"amount": 1, "amount": 1,
@ -32,27 +32,24 @@ module.exports = {
db.find({ db.find({
user: message.author.tag, user: message.author.tag,
}, function(err, docs) { }, function(err, docs) {
if (!docs.length > 0) { if (docs.length === 0) {
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string); return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
} }
else { else {
Random.use(message.author.tag); Random.use(message.author.tag);
let dice = [] let dice = [];
/*for (i in docs[0].character.skills) { const Weapon = globals.MeleeWeapons.find(weapon => weapon.id === args[0]);
if (docs[0].character.skills[i].id == args[0]) level = docs[0].character.skills[i].level;
} if(!Weapon) { return message.reply(globals.Replies.find(r => r.id === 'NO_SUCH_WEAPON').string);}
*/ const DieModificator = Weapon.diemodificator;
const Weapon = globals.MeleeWeapons.find(weapon => weapon.id === args[0]) let sum = DieModificator;
if(!Weapon) { return message.reply(globals.Replies.find(r => r.id === 'NO_SUCH_WEAPON').string)}
const DieModificator = Weapon.diemodificator
let sum = DieModificator
for (let i = 0; i < Weapon.dice; i++) { for (let i = 0; i < Weapon.dice; i++) {
dice.push(Random.int(1,6)) dice.push(Random.int(1,6));
} }
dice.forEach(result => { dice.forEach(result => {
sum += result sum += result;
}) });
message.reply('Deine 🎲: ' + dice.join(',') + '.\n' + Weapon.name + ' richtet ` ' + sum + ' ` Schaden an. (' + Weapon.dice + 'W6+' + Weapon.diemodificator +')'); message.reply('Deine 🎲: ' + dice.join(',') + '.\n' + Weapon.name + ' richtet ` ' + sum + ' ` Schaden an. (' + Weapon.dice + 'W6+' + Weapon.diemodificator +')');
} }
}); });

View File

@ -1,6 +1,6 @@
const globals = require('../globals') const globals = require('../globals');
const db = globals.db const db = globals.db;
const Random = require('random') const Random = require('random');
module.exports = { module.exports = {
name: 'parry', name: 'parry',
@ -14,66 +14,66 @@ module.exports = {
db.find({ db.find({
user: message.author.tag, user: message.author.tag,
}, function(err, docs) { }, function(err, docs) {
if (!docs.length > 0) { if (docs.length === 0) {
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string); return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
} }
else { else {
Random.use(message.author.tag); Random.use(message.author.tag);
const Player = docs[0].character const Player = docs[0].character;
const Weapon = globals.Weapons.find(w => w.id === args[0].toLowerCase()) const Weapon = globals.Weapons.find(w => w.id === args[0].toLowerCase());
if(!Weapon) { return message.reply(globals.Replies.find(r => r.id === 'NO_SUCH_WEAPON').string)} if(!Weapon) { return message.reply(globals.Replies.find(r => r.id === 'NO_SUCH_WEAPON').string);}
if(!globals.MeleeWeapons.find(MeleeWeapon => MeleeWeapon.id === Weapon.id)) { if(!globals.MeleeWeapons.find(MeleeWeapon => MeleeWeapon.id === Weapon.id)) {
return message.reply(globals.Replies.find(r => r.id === 'PARRY_WRONG_WEAPON').string) return message.reply(globals.Replies.find(r => r.id === 'PARRY_WRONG_WEAPON').string);
} }
const CombatTechnique = globals.CombatTechniques.find(technique => technique.id === Weapon.combattechnique) const CombatTechnique = globals.CombatTechniques.find(technique => technique.id === Weapon.combattechnique);
let PlayerCombatTechnique = Player.combattechniques.find(technique => technique.id === CombatTechnique.id) let PlayerCombatTechnique = Player.combattechniques.find(technique => technique.id === CombatTechnique.id);
let CombatTechniqueValue = null let CombatTechniqueValue = null;
if (PlayerCombatTechnique) { CombatTechniqueValue = PlayerCombatTechnique.level } if (PlayerCombatTechnique) { CombatTechniqueValue = PlayerCombatTechnique.level; }
if(!CombatTechniqueValue) { CombatTechniqueValue = 6 } if(!CombatTechniqueValue) { CombatTechniqueValue = 6; }
let ParryValue = Math.ceil(CombatTechniqueValue/2) let ParryValue = Math.ceil(CombatTechniqueValue/2);
for (let i in CombatTechnique.Leiteigenschaft) { CombatTechniqueValue.Leiteigenschaft.forEach( Property => {
let Attribute = globals.Werte.find(a => a.kuerzel === CombatTechnique.Leiteigenschaft[i]).id let Attribute = globals.Werte.find(a => a.kuerzel === Property.id);
ParryValue += Math.floor((Player.attributes.find(a => a.id === Attribute).level - 8)/3) ParryValue += Math.floor((Player.attributes.find(a => a.id === Attribute).level - 8)/3);
} });
ParryValue += Weapon.pa_mod ParryValue += Weapon.pa_mod;
let dice = [] let dice = [];
let Bonus = 0 let Bonus = 0;
if(args[1] && !isNaN(parseInt(args[1]))) { Bonus = parseInt(args[1]) } if(args[1] && !isNaN(parseInt(args[1]))) { Bonus = parseInt(args[1]); }
let Comparison = Math.floor(ParryValue + Bonus) let Comparison = Math.floor(ParryValue + Bonus);
let Patzer = false let Patzer = false;
let Critical = false let Critical = false;
let Ok = false let Ok = false;
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
dice.push(Random.int(1,20)) dice.push(Random.int(1,20));
} }
// If there is a cleaner way to do these checks, I'm all into it. // If there is a cleaner way to do these checks, I'm all into it.
if((dice[0] == 1) && dice[1] <= Comparison) { Critical = true; Ok = true } if((dice[0] == 1) && dice[1] <= Comparison) { Critical = true; Ok = true; }
else if(dice[0] <= Comparison && !Critical) { Ok = true; dice.pop(); } else if(dice[0] <= Comparison && !Critical) { Ok = true; dice.pop(); }
else if((dice[0] == 20) && dice[1] > Comparison) { Patzer = true } else if((dice[0] == 20) && dice[1] > Comparison) { Patzer = true; }
else if(dice[0] > Comparison ) { dice.pop(); } else if(dice[0] > Comparison ) { dice.pop(); }
let Reply = 'Du versuchst, mit ' + globals.Declination[Weapon.article] + ' ' + Weapon.name + ' zu parieren.\n' let Reply = 'Du versuchst, mit ' + globals.Declination[Weapon.article] + ' ' + Weapon.name + ' zu parieren.\n';
Reply += 'Dein Paradewert für ' + CombatTechnique.name + ' ist ' + Math.floor(ParryValue - Weapon.pa_mod) + '. (Waffe: ' + Weapon.pa_mod + ')\n' Reply += 'Dein Paradewert für ' + CombatTechnique.name + ' ist ' + Math.floor(ParryValue - Weapon.pa_mod) + '. (Waffe: ' + Weapon.pa_mod + ')\n';
Reply += 'Deine 🎲: ` ' + dice.join(', ') + ' `.\n\n' Reply += 'Deine 🎲: ` ' + dice.join(', ') + ' `.\n\n';
if(!Ok) { if(!Ok) {
Reply += globals.Replies.find(reply => reply.id === 'PARRY_FAIL').string Reply += globals.Replies.find(reply => reply.id === 'PARRY_FAIL').string;
if(Patzer) { Reply += globals.Replies.find(reply => reply.id === 'PARRY_CRIT_FAIL').string } if(Patzer) { Reply += globals.Replies.find(reply => reply.id === 'PARRY_CRIT_FAIL').string; }
} }
else { else {
if(Critical) { Reply += globals.Replies.find(reply => reply.id === 'PARRY_CRIT_SUCCESS').string } if(Critical) { Reply += globals.Replies.find(reply => reply.id === 'PARRY_CRIT_SUCCESS').string; }
if(!Critical) { Reply += globals.Replies.find(reply => reply.id === 'PARRY_SUCCESS').string } if(!Critical) { Reply += globals.Replies.find(reply => reply.id === 'PARRY_SUCCESS').string; }
} }
return message.reply( Reply ) return message.reply( Reply );
} }
}); });

View File

@ -1,6 +1,6 @@
const globals = require('../globals') const globals = require('../globals');
const db = globals.db const db = globals.db;
const Random = require('random') const Random = require('random');
/* /*
"meleeweapons": [{ "meleeweapons": [{
"amount": 1, "amount": 1,
@ -32,27 +32,27 @@ module.exports = {
db.find({ db.find({
user: message.author.tag, user: message.author.tag,
}, function(err, docs) { }, function(err, docs) {
if (!docs.length > 0) { if (docs.length === 0) {
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string); return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
} }
else { else {
Random.use(message.author.tag); Random.use(message.author.tag);
let dice = [] let dice = [];
/*for (i in docs[0].character.skills) { /*for (i in docs[0].character.skills) {
if (docs[0].character.skills[i].id == args[0]) level = docs[0].character.skills[i].level; if (docs[0].character.skills[i].id == args[0]) level = docs[0].character.skills[i].level;
} }
*/ */
const Weapon = globals.MeleeWeapons.find(weapon => weapon.id === args[0]) const Weapon = globals.MeleeWeapons.find(weapon => weapon.id === args[0]);
if(!Weapon) { return message.reply(globals.Replies.find(r => r.id === 'NO_SUCH_WEAPON').string)} if(!Weapon) { return message.reply(globals.Replies.find(r => r.id === 'NO_SUCH_WEAPON').string);}
const DieModificator = Weapon.diemodificator const DieModificator = Weapon.diemodificator;
let sum = DieModificator let sum = DieModificator;
for (let i = 0; i < Weapon.dice; i++) { for (let i = 0; i < Weapon.dice; i++) {
dice.push(Random.int(1,6)) dice.push(Random.int(1,6));
} }
dice.forEach(result => { dice.forEach(result => {
sum += result sum += result;
}) });
message.reply('Du schlägst mit ' + Weapon.name + ' zu. (' + Weapon.dice + 'W6+' + Weapon.diemodificator +')\nDeine 🎲: ' + dice.join(',') + '.\n' + 'Dein Angriff macht **' + sum + '** Schaden.'); message.reply('Du schlägst mit ' + Weapon.name + ' zu. (' + Weapon.dice + 'W6+' + Weapon.diemodificator +')\nDeine 🎲: ' + dice.join(',') + '.\n' + 'Dein Angriff macht **' + sum + '** Schaden.');
} }
}); });

View File

@ -1,5 +1,5 @@
const globals = require('../globals') const globals = require('../globals');
const db = globals.db const db = globals.db;
module.exports = { module.exports = {
name: 'remove', name: 'remove',
description: 'Löscht deinen Charakter aus der Datenbank. Sinnvoll, wenn du mir eine neue zusenden möchtest.', description: 'Löscht deinen Charakter aus der Datenbank. Sinnvoll, wenn du mir eine neue zusenden möchtest.',

View File

@ -13,16 +13,18 @@ module.exports = {
Random.use(message.author.tag); Random.use(message.author.tag);
let msg; let msg;
let arguments = args.join(''); let arguments = args.join('').split(globals.DiceRegex);
arguments = arguments.split(globals.DiceRegex); if (arguments.length >= 2) {
if (arguments.length == 2) { let bonus = 0;
const numberOfDice = parseInt(arguments[0]); const numberOfDice = parseInt(arguments[0]);
const diceValues = parseInt(arguments[1]); const diceValues = parseInt(arguments[1]);
console.log(diceValues) if (arguments.length==3) { bonus = parseInt(arguments[2]); }
let sum = bonus;
const roll = []; const roll = [];
for (let i = 0; i < numberOfDice; i++) { for (let i = 0; i < numberOfDice; i++) {
const a = Random.int(1, diceValues); const a = Random.int(1, diceValues);
roll.push(a); roll.push(a);
sum += a;
} }
if (numberOfDice == 1) { if (numberOfDice == 1) {
msg = 'n'; msg = 'n';
@ -30,7 +32,8 @@ module.exports = {
else { else {
msg = ' ' + numberOfDice; msg = ' ' + numberOfDice;
} }
message.reply('Das sind deine Ergebnisse für deine' + msg + ' ' + diceValues + '-seitigen 🎲: ' + roll.join(', ') + '.'); //message.reply('Das sind deine Ergebnisse für deine' + msg + ' ' + diceValues + '-seitigen 🎲: ' + roll.join(', ') + '. (Gesamt: ' + roll.reduce((pv, cv) => pv + cv, 0) + ' + ' + bonus[1] + ' = ' + sum + ')');
message.reply(`Das sind die Ergebnisse für deine${msg} ${diceValues}-seitigen 🎲: ${roll.join(', ')}. (Gesamt: ${roll.reduce((pv, cv) => pv + cv, 0)} + ${bonus} = ${sum})`);
} }
}, },
}; };

View File

@ -1,7 +1,7 @@
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const globals = require('../globals') const globals = require('../globals');
const Discord = require('discord.js') const Discord = require('discord.js');
const db = globals.db const db = globals.db;
module.exports = { module.exports = {
name: 'show', name: 'show',
@ -15,18 +15,18 @@ module.exports = {
db.find({ db.find({
user: message.author.tag, user: message.author.tag,
}, function(err, docs) { }, function(err, docs) {
if (!docs.length > 0) { if (docs.length === 0) {
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string); return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
} }
else { else {
let gender let gender;
if (docs[0].character.sex == 'female') { gender = '♀️' } if (docs[0].character.sex == 'female') { gender = '♀️'; }
else { gender = '♂️' } else { gender = '♂️'; }
const Reply = new Discord.MessageEmbed() const Reply = new Discord.MessageEmbed();
Reply.setColor('#0099ff') Reply.setColor('#0099ff');
Reply.setTitle(gender + ' ' + docs[0].character.name) Reply.setTitle(gender + ' ' + docs[0].character.name);
Reply.setDescription(docs[0].character.age + ' Jahre, ' + docs[0].character.race + '/' + docs[0].character.culture) Reply.setDescription(docs[0].character.age + ' Jahre, ' + docs[0].character.race + '/' + docs[0].character.culture);
Reply.addField(docs[0].character.professionname, docs[0].character.xp.startinglevel) Reply.addField(docs[0].character.professionname, docs[0].character.xp.startinglevel);
message.reply( Reply ); message.reply( Reply );
} }

View File

@ -1,5 +1,5 @@
const globals = require('../globals') const globals = require('../globals');
const db = globals.db const db = globals.db;
module.exports = { module.exports = {
name: 'skill', name: 'skill',
description: 'Zeigt dir deinen Fertigkeitswert im jeweiligen Talent.', description: 'Zeigt dir deinen Fertigkeitswert im jeweiligen Talent.',
@ -12,12 +12,12 @@ module.exports = {
db.find({ db.find({
user: message.author.tag, user: message.author.tag,
}, function(err, docs) { }, function(err, docs) {
if (!docs.length > 0) { if (docs.length === 0) {
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string); return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
} }
else { else {
let level = 0; let level = 0;
for (i in docs[0].character.skills) { for (let i in docs[0].character.skills) {
if (docs[0].character.skills[i].id == args[0]) level = docs[0].character.skills[i].level; if (docs[0].character.skills[i].id == args[0]) level = docs[0].character.skills[i].level;
} }
message.reply('Du hast folgenden Talentwert in ' + args[0] + ': ' + level); message.reply('Du hast folgenden Talentwert in ' + args[0] + ': ' + level);

View File

@ -1,7 +1,7 @@
const globals = require('../globals'); const globals = require('../globals');
const Random = require('random'); const Random = require('random');
const Discord = require('discord.js') const Discord = require('discord.js');
const db = globals.db const db = globals.db;
module.exports = { module.exports = {
name: 'talent', name: 'talent',
@ -16,11 +16,11 @@ module.exports = {
db.find({ db.find({
user: message.author.tag, user: message.author.tag,
}, function(err, docs) { }, function(err, docs) {
if (!docs.length > 0) { if (docs.length === 0) {
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string); return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
} }
if(!isNaN(args[0])) { if(!isNaN(args[0])) {
return message.reply(globals.Replies.find(x => x.id === 'WRONG_ARGUMENTS').string) return message.reply(globals.Replies.find(x => x.id === 'WRONG_ARGUMENTS').string);
} }
else { else {
Random.use(message.author.tag); Random.use(message.author.tag);
@ -32,7 +32,7 @@ module.exports = {
let ok = 0; let ok = 0;
let patzer = 0; let patzer = 0;
let crit = 0; let crit = 0;
let erschwernis = 0 let erschwernis = 0;
if (args[1]) { if (args[1]) {
erschwernis = parseInt(args[1]); erschwernis = parseInt(args[1]);
@ -59,12 +59,12 @@ module.exports = {
const bonus_orig = bonus; const bonus_orig = bonus;
const result = globals.Talente.find(t => t.id === talent); const result = globals.Talente.find(t => t.id === talent);
for (i in result.values) { result.values.forEach(value => {
const kuerzel = globals.Werte.find(wert => wert.kuerzel === result.values[i]); let kuerzel = globals.Werte.find(wert => wert.kuerzel === value);
for (val in docs[0].character.attributes) { docs[0].character.attributes.forEach(attr => {
if (docs[0].character.attributes[val].id == kuerzel.id) values.push(docs[0].character.attributes[val].level); if (attr == kuerzel.id) { values.push(attr.level);}
} });
} });
for (let i = 1; i <= 3; i++) { for (let i = 1; i <= 3; i++) {
roll.push(Random.int(1, 20)); roll.push(Random.int(1, 20));
@ -81,25 +81,25 @@ module.exports = {
if (roll[i] == 1) crit++; if (roll[i] == 1) crit++;
if (roll[i] == 20) patzer++; if (roll[i] == 20) patzer++;
} }
const Reply = new Discord.MessageEmbed() const Reply = new Discord.MessageEmbed();
Reply.setTitle('Du würfelst auf das Talent ' + result.name + '.') Reply.setTitle('Du würfelst auf das Talent ' + result.name + '.');
Reply.setDescription('Deine Werte für ' + result.values.join(', ') + ' sind ' + values.join(', ') + '. (Bonus: ' + bonus_orig + ')') Reply.setDescription('Deine Werte für ' + result.values.join(', ') + ' sind ' + values.join(', ') + '. (Bonus: ' + bonus_orig + ')');
Reply.addFields({ Reply.addFields({
name: 'Deine 🎲: ' + roll.join(', ') + '.', name: 'Deine 🎲: ' + roll.join(', ') + '.',
value: '\u200B', inline: false}) value: '\u200B', inline: false});
if (patzer >= 2) { if (patzer >= 2) {
Reply.setColor('#900c3f') Reply.setColor('#900c3f');
Reply.addFields({ Reply.addFields({
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_FAILURE').string, name: globals.Replies.find(x => x.id === 'TITLE_CRIT_FAILURE').string,
value: globals.Replies.find(x => x.id === 'MSG_CRIT_FAILURE').string, value: globals.Replies.find(x => x.id === 'MSG_CRIT_FAILURE').string,
inline: false}) inline: false});
} }
else if (crit >= 2) { else if (crit >= 2) {
Reply.setColor('#1E8449') Reply.setColor('#1E8449');
Reply.addFields({ Reply.addFields({
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_SUCCESS').string, name: globals.Replies.find(x => x.id === 'TITLE_CRIT_SUCCESS').string,
value:globals.Replies.find(x => x.id === 'MSG_CRIT_SUCCESS').string, value:globals.Replies.find(x => x.id === 'MSG_CRIT_SUCCESS').string,
inline: false}) inline: false});
} }
else if (ok < 3) { else if (ok < 3) {
Reply.addFields({name: globals.Replies.find(x => x.id === 'TITLE_FAILURE').string, Reply.addFields({name: globals.Replies.find(x => x.id === 'TITLE_FAILURE').string,
@ -109,10 +109,10 @@ module.exports = {
else { else {
Reply.addFields({name: globals.Replies.find(x => x.id === 'TITLE_SUCCESS').string, Reply.addFields({name: globals.Replies.find(x => x.id === 'TITLE_SUCCESS').string,
value: ok + '/3 Proben erfolgreich. Dein Bonus: ' + bonus + '/' + bonus_orig + '.', value: ok + '/3 Proben erfolgreich. Dein Bonus: ' + bonus + '/' + bonus_orig + '.',
inline: false}) inline: false});
} }
message.reply(Reply) message.reply(Reply);
} }
}); });
} }

View File

@ -1,7 +1,7 @@
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const Random = require('random'); const Random = require('random');
const globals = require('../globals') const globals = require('../globals');
const Discord = require('discord.js') const Discord = require('discord.js');
module.exports = { module.exports = {
name: 'tp', name: 'tp',
@ -15,17 +15,17 @@ module.exports = {
async exec(message, args) { async exec(message, args) {
if(isNaN(args[0])) { if(isNaN(args[0])) {
return message.reply(globals.Replies.find(x => x.id === 'WRONG_ARGUMENTS').string) return message.reply(globals.Replies.find(x => x.id === 'WRONG_ARGUMENTS').string);
} }
Random.use(message.author.tag); Random.use(message.author.tag);
const roll = []; const roll = [];
let bonus = 0 let bonus = 0;
let bonus_orig = 0 let bonus_orig = 0;
let erschwernis = 0 let erschwernis = 0;
if (args[3]) { if (args[3]) {
bonus_orig = parseInt(args[3]); bonus_orig = parseInt(args[3]);
bonus = bonus_orig bonus = bonus_orig;
} }
if (args[4]) { if (args[4]) {
erschwernis = parseInt(args[4]); erschwernis = parseInt(args[4]);
@ -48,36 +48,36 @@ module.exports = {
if (roll[i] == 20) patzer++; if (roll[i] == 20) patzer++;
} }
const Reply = new Discord.MessageEmbed() const Reply = new Discord.MessageEmbed();
//Reply.setTitle('Du würfelst auf ' + args[0] + ' ' + args[1] + ' ' + args[2] + ' (Bonus: ' + bonus_orig + ')') //Reply.setTitle('Du würfelst auf ' + args[0] + ' ' + args[1] + ' ' + args[2] + ' (Bonus: ' + bonus_orig + ')')
Reply.setTitle('Deine 🎲: ' + roll.join(', ') + '.') Reply.setTitle('Deine 🎲: ' + roll.join(', ') + '.');
if (patzer >= 2) { if (patzer >= 2) {
Reply.setColor('#900c3f') Reply.setColor('#900c3f');
Reply.addFields({ Reply.addFields({
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_FAILURE').string, name: globals.Replies.find(x => x.id === 'TITLE_CRIT_FAILURE').string,
value: globals.Replies.find(x => x.id === 'MSG_CRIT_FAILURE').string, value: globals.Replies.find(x => x.id === 'MSG_CRIT_FAILURE').string,
inline: false inline: false
}) });
} else if (crit >= 2) { } else if (crit >= 2) {
Reply.setColor('#1E8449') Reply.setColor('#1E8449');
Reply.addFields({ Reply.addFields({
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_SUCCESS').string, name: globals.Replies.find(x => x.id === 'TITLE_CRIT_SUCCESS').string,
value: globals.Replies.find(x => x.id === 'MSG_CRIT_SUCCESS').string, value: globals.Replies.find(x => x.id === 'MSG_CRIT_SUCCESS').string,
inline: false inline: false
}) });
} else if (ok < 3) { } else if (ok < 3) {
Reply.addFields({ Reply.addFields({
name: globals.Replies.find(x => x.id === 'TITLE_FAILURE').string, name: globals.Replies.find(x => x.id === 'TITLE_FAILURE').string,
value: 'Nur ' + ok + '/3 Proben erfolgreich. 😪', value: 'Nur ' + ok + '/3 Proben erfolgreich. 😪',
inline: false inline: false
}) });
} else { } else {
Reply.addFields({ Reply.addFields({
name: globals.Replies.find(x => x.id === 'TITLE_SUCCESS').string, name: globals.Replies.find(x => x.id === 'TITLE_SUCCESS').string,
value: ok + '/3 Proben erfolgreich. Dein Bonus: ' + bonus + '/' + bonus_orig + '.', value: ok + '/3 Proben erfolgreich. Dein Bonus: ' + bonus + '/' + bonus_orig + '.',
inline: false inline: false
}) });
} }
message.reply(Reply) message.reply(Reply);
} }
} };

View File

@ -1,15 +1,15 @@
const Discord = require('discord.js') const Discord = require('discord.js');
const Datastore = require('nedb'), const Datastore = require('nedb'),
db = new Datastore({ db = new Datastore({
filename: 'data/dsabot.db', filename: 'data/dsabot.db',
autoload: true, autoload: true,
}); });
const MessageEmbed = new Discord.MessageEmbed() const MessageEmbed = new Discord.MessageEmbed();
const money = [{ const money = [{
'GD': 'Golddukaten', 'GD': 'Golddukaten',
'ST': 'Silbertaler', 'ST': 'Silbertaler',
}]; }];
const DiceRegex = /\s?[DdWw]\s?/; const DiceRegex = /\s?[DdWw]\s?|(?=\-|\+)/;
const Coin = ['Kopf', 'Zahl']; const Coin = ['Kopf', 'Zahl'];
const Werte = [ const Werte = [
{ id: 'mut', kuerzel: 'MU', name: 'Mut' }, { id: 'mut', kuerzel: 'MU', name: 'Mut' },
@ -21,7 +21,7 @@ const Werte = [
{ id: 'konstitution', kuerzel: 'KO', name: 'Konstitution' }, { id: 'konstitution', kuerzel: 'KO', name: 'Konstitution' },
{ id: 'koerperkraft', kuerzel: 'KK', name: 'Körperkraft' }, { id: 'koerperkraft', kuerzel: 'KK', name: 'Körperkraft' },
]; ];
const TalentKategorien = ['Körpertalente','Gesellschaftstalente','Naturtalente','Wissenstalente','Handwerkstalente'] const TalentKategorien = ['Körpertalente','Gesellschaftstalente','Naturtalente','Wissenstalente','Handwerkstalente'];
const Talente = [ const Talente = [
// Körpertalente // Körpertalente
@ -140,8 +140,8 @@ const Replies = [
{ id: 'PARRY_SUCCESS', string: 'Parade erfolgreich.'}, { id: 'PARRY_SUCCESS', string: 'Parade erfolgreich.'},
{ id: 'PARRY_CRIT_SUCCESS', string: 'Kritischer Erfolg! Du darfst einen Passierschlag ausführen!'} { id: 'PARRY_CRIT_SUCCESS', string: 'Kritischer Erfolg! Du darfst einen Passierschlag ausführen!'}
]; ];
const Declination = ['dem', 'der', 'dem', ''] // Maskulinum, Feminimum, Neutrum, None const Declination = ['dem', 'der', 'dem', '']; // Maskulinum, Feminimum, Neutrum, None
const Articles = ['Der','Die','Das',''] const Articles = ['Der','Die','Das',''];
const MeleeWeapons = [ const MeleeWeapons = [
{ id: 'basiliskenzunge', name: 'Basiliskenzunge', dice: 1, diemodificator: 2, at_mod: 0, pa_mod: -1, article: 1, DmgThreshold: 14, combattechnique: 'dolche' }, { id: 'basiliskenzunge', name: 'Basiliskenzunge', dice: 1, diemodificator: 2, at_mod: 0, pa_mod: -1, article: 1, DmgThreshold: 14, combattechnique: 'dolche' },
{ id: 'dolch', name: 'Dolch', dice: 1, diemodificator: 1, at_mod: 0, pa_mod: 0, article: 0, DmgThreshold: 14, combattechnique: 'dolche' }, { id: 'dolch', name: 'Dolch', dice: 1, diemodificator: 1, at_mod: 0, pa_mod: 0, article: 0, DmgThreshold: 14, combattechnique: 'dolche' },
@ -200,7 +200,7 @@ const MeleeWeapons = [
{ id: 'felsspalter', name: 'Felsspalter', dice: 2, diemodificator: 2, at_mod: 0, pa_mod: -2, article: 0, DmgThreshold: 13, combattechnique: 'zweihandhiebwaffen'}, { id: 'felsspalter', name: 'Felsspalter', dice: 2, diemodificator: 2, at_mod: 0, pa_mod: -2, article: 0, DmgThreshold: 13, combattechnique: 'zweihandhiebwaffen'},
{ id: 'kriegshammer', name: 'Kriegshammer', dice: 2, diemodificator: 3, at_mod: 0, pa_mod: -3, article: 0, DmgThreshold: 13, combattechnique: 'zweihandhiebwaffen'}, { id: 'kriegshammer', name: 'Kriegshammer', dice: 2, diemodificator: 3, at_mod: 0, pa_mod: -3, article: 0, DmgThreshold: 13, combattechnique: 'zweihandhiebwaffen'},
{ id: 'zwergenschlaegel', name: 'Zwergenschlägel', dice: 1, diemodificator: 6, at_mod: 0, pa_mod: -1, article: 0, DmgThreshold: 13, combattechnique: 'zweihandhiebwaffen'}, { id: 'zwergenschlaegel', name: 'Zwergenschlägel', dice: 1, diemodificator: 6, at_mod: 0, pa_mod: -1, article: 0, DmgThreshold: 13, combattechnique: 'zweihandhiebwaffen'},
] ];
const RangedWeapons = [ const RangedWeapons = [
{ id: 'balestrina', name: 'Balestrina', dice: 1, diemodificator: 4, article: 1, combattechnique: 'armbrueste'}, { id: 'balestrina', name: 'Balestrina', dice: 1, diemodificator: 4, article: 1, combattechnique: 'armbrueste'},
@ -221,15 +221,14 @@ const RangedWeapons = [
{ id: 'wurfscheibe', name: 'Wurfscheibe', dice: 1, diemodificator: 1, article: 1, combattechnique: 'wurfwaffen'}, { id: 'wurfscheibe', name: 'Wurfscheibe', dice: 1, diemodificator: 1, article: 1, combattechnique: 'wurfwaffen'},
{ id: 'wurfstern', name: 'Wurfstern', dice: 1, diemodificator: 1, article: 0, combattechnique: 'wurfwaffen'}, { id: 'wurfstern', name: 'Wurfstern', dice: 1, diemodificator: 1, article: 0, combattechnique: 'wurfwaffen'},
{ id: 'wurfspeer', name: 'Wurfspeer', dice: 1, diemodificator: 2, article: 0, combattechnique: 'wurfwaffen'} { id: 'wurfspeer', name: 'Wurfspeer', dice: 1, diemodificator: 2, article: 0, combattechnique: 'wurfwaffen'}
] ];
const Weapons = MeleeWeapons.concat(RangedWeapons) const Weapons = MeleeWeapons.concat(RangedWeapons);
const Advantages = [ const Advantages = [
{} {}
] ];
const Disadvantages = [ const Disadvantages = [
{} {}
] ];
module.exports = { Werte, Talente, Coin, TalentKategorien, DiceRegex, Discord, MessageEmbed, db, Replies, MeleeWeapons, Weapons, RangedWeapons, CombatTechniques, Articles, Declination }; module.exports = { Werte, Talente, Coin, TalentKategorien, DiceRegex, Discord, MessageEmbed, db, Replies, MeleeWeapons, Weapons, RangedWeapons, CombatTechniques, Articles, Declination };

View File

@ -1,8 +1,8 @@
require('dotenv').config(); require('dotenv').config();
const fs = require('fs') const fs = require('fs');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
const globals = require('./globals') const globals = require('./globals');
const db = globals.db const db = globals.db;
const cmdprefix = process.env.CMDPREFIX || '!'; const cmdprefix = process.env.CMDPREFIX || '!';
const Discord = require('discord.js'); const Discord = require('discord.js');
const client = new Discord.Client(); const client = new Discord.Client();
@ -28,7 +28,7 @@ async function commandHandler(message) {
const data = await validateJSON(response); const data = await validateJSON(response);
if (data) await CreateFromFile(message, data); if (data) await CreateFromFile(message, data);
} catch (e) { } catch (e) {
console.log(e) console.log(e);
return message.reply(globals.Replies.find(x => x.id === 'ERROR').string); return message.reply(globals.Replies.find(x => x.id === 'ERROR').string);
} }
} else { } else {
@ -50,10 +50,10 @@ async function commandHandler(message) {
command.exec(message, args); command.exec(message, args);
} }
} catch (e) { } catch (e) {
message.reply(globals.Replies.find(x => x.id === 'ERROR').string) message.reply(globals.Replies.find(x => x.id === 'ERROR').string);
} }
} }
}; }
function validateJSON(body) { function validateJSON(body) {
try { try {
@ -69,7 +69,7 @@ async function CreateFromFile(message, data) {
db.find({ db.find({
user: message.author.tag, user: message.author.tag,
}, function(err, docs) { }, function(err, docs) {
if (!docs.length > 0) { if (docs.length === 0) {
db.insert({ db.insert({
user: message.author.tag, user: message.author.tag,
character: data, character: data,