diff --git a/commands/HeadsOrTails.js b/commands/HeadsOrTails.js index 898792e..71e8729 100644 --- a/commands/HeadsOrTails.js +++ b/commands/HeadsOrTails.js @@ -1,5 +1,4 @@ const globals = require('../globals'); -//const Random = require('random'); const { roll } = require('@dsabot/Roll'); const { findMessage }= require('@dsabot/findMessage'); @@ -11,9 +10,7 @@ module.exports = { needs_args: false, async exec(message, args) { - //Random.use(message.author.tag); - const coin = roll(1,2,message.author.tag).dice; //Random.int(0, 1); -// message.reply('Die Münze bleibt auf **' + globals.Coin[coin] + '** liegen.'); + const coin = roll(1,2,message.author.tag).dice; message.reply(`${findMessage('HEADS_OR_TAILS')} **${globals.Coin[(coin-1)]}**.`); }, }; \ No newline at end of file diff --git a/commands/Talents.js b/commands/Talents.js index 60c2f6b..feb9833 100644 --- a/commands/Talents.js +++ b/commands/Talents.js @@ -1,6 +1,6 @@ const globals = require('../globals'); const Discord = require('discord.js'); - +const { Capitalize } = require('@dsabot/Capitalize'); module.exports = { name: 'talents', @@ -10,27 +10,33 @@ module.exports = { needs_args: false, async exec(message, args) { - const fields = []; - for (const i in globals.TalentKategorien) { - const ability = []; - for (const a in globals.Talente) { - if (globals.Talente[a].categoryid == i) { - ability.push(globals.Talente[a].id.charAt(0).toUpperCase() + globals.Talente[a].id.slice(1)); - } - } - ability.sort(); - fields.push(ability); - } const Embed = new Discord.MessageEmbed() .setColor('#0099ff') .setTitle('Talentübersicht') .setDescription('Das sind die Talente, die ich kenne:'); - for (const i in fields) { - Embed.addField(globals.TalentKategorien[i], fields[i].join('\n'), true); + for (let Talent of GenerateTalentList()) { + Embed.addField(Talent.Category, Talent.Talents.join('\n'), true); } message.author.send( Embed, ); }, +}; + +const GenerateTalentList = () => { + const Categories = globals.TalentKategorien; + const Talents = globals.Talente; + const TalentList = []; + + Categories.forEach(Category => { + TalentList.push({ + Category: Category, + Talents: Talents.filter(Talent => Talent.categoryid === Categories.indexOf(Category)) + .map(Talent => Capitalize(Talent.id)) + .sort() + }); + }); + + return TalentList.sort(); }; \ No newline at end of file diff --git a/commands/Weapons.js b/commands/Weapons.js index 3f753f7..cbcdfa2 100644 --- a/commands/Weapons.js +++ b/commands/Weapons.js @@ -1,5 +1,6 @@ const globals = require('../globals'); const Discord = require('discord.js'); +const { Capitalize } = require('@dsabot/Capitalize'); module.exports = { @@ -10,27 +11,31 @@ module.exports = { needs_args: false, async exec(message, args) { - let fields = []; - for (let CombatTechnique in globals.CombatTechniques) { - let Weapons = []; - for (let Weapon in globals.Weapons) { - if (globals.Weapons[Weapon].combattechnique == globals.CombatTechniques[CombatTechnique].id) { - Weapons.push(globals.Weapons[Weapon].id.charAt(0).toUpperCase() + globals.Weapons[Weapon].id.slice(1)); - } - } - Weapons.sort(); - fields.push(Weapons); - } - const Embed = new Discord.MessageEmbed() .setColor('#0099ff') .setTitle('Waffenübersicht') .setDescription('Folgende Waffen können für einen Angriff genutzt werden:'); - for (let i in fields) { - Embed.addField(globals.CombatTechniques[i].name, fields[i].join('\n'), true); + for (let Technique of GenerateWeaponList()) { + Embed.addField(Technique.Technique_Name, Technique.Weapons.join('\n'), true); } message.author.send( Embed, ); }, -}; \ No newline at end of file +}; + +const GenerateWeaponList = () => { + let WeaponList = []; + const Techniques = globals.CombatTechniques; + const Weapons = globals.Weapons; + + Techniques.forEach(Technique => { + WeaponList.push({ + Technique_Name: Technique.name, + Weapons: Weapons.filter(Weapon => Weapon.combattechnique === Technique.id) + .map(Weapon => Capitalize(Weapon.id)) + }); + }); + return WeaponList.sort(); +}; + diff --git a/functions/Capitalize.js b/functions/Capitalize.js new file mode 100644 index 0000000..91360c3 --- /dev/null +++ b/functions/Capitalize.js @@ -0,0 +1,5 @@ +const Capitalize = (Word = 'none') => { + return Word[0].toUpperCase() + Word.substring(1); +}; + +module.exports = { Capitalize }; diff --git a/globals.js b/globals.js index 80b3931..1232dde 100644 --- a/globals.js +++ b/globals.js @@ -176,7 +176,7 @@ const MeleeWeapons = [ { id: 'thorwalerschild', name: 'Thorwalerschild', dice: 1, diemodificator: 1, at_mod: -5, pa_mod: 2, article: 2, DmgThreshold: 16, combattechnique: 'schilde'}, { id: 'grossschild', name: 'Großschild', dice: 1, diemodificator: 1, at_mod: -6, pa_mod: 3, article: 2, DmgThreshold: 16, combattechnique: 'schilde'}, { id: 'barbarenschwert', name: 'Barbarenschwert', dice: 1, diemodificator: 5, at_mod: -1, pa_mod: -1, article: 2, DmgThreshold: 15, combattechnique: 'schwerter'}, - { id: 'entermesser', name: 'Entermesser', dice: 1, diemodificator: 3, at_mod: 0, pa_mod: -1, article: 2, DmgThreshold: 15, ombattechnique: 'schwerter'}, + { id: 'entermesser', name: 'Entermesser', dice: 1, diemodificator: 3, at_mod: 0, pa_mod: -1, article: 2, DmgThreshold: 15, combattechnique: 'schwerter'}, { id: 'haumesser', name: 'Haumesser', dice: 1, diemodificator: 3, at_mod: 0, pa_mod: -1, article: 2, DmgThreshold: 15, combattechnique: 'schwerter'}, { id: 'khunchomer', name: 'Khunchomer', dice: 1, diemodificator: 4, at_mod: 0, pa_mod: 0, article: 3, DmgThreshold: 15, combattechnique: 'schwerter'}, { id: 'kurzschwert', name: 'Kurzschwert', dice: 1, diemodificator: 2, at_mod: 0, pa_mod: 0, article: 2, DmgThreshold: 15, combattechnique: 'schwerter'}, @@ -191,7 +191,7 @@ const MeleeWeapons = [ { id: 'kampfstab', name: 'Kampfstab', dice: 1, diemodificator: 2, at_mod: 0, pa_mod: 2, article: 0, DmgThreshold: 15, combattechnique: 'stangenwaffen'}, { id: 'magierstablang', name: 'Magierstab: Lang', dice: 1, diemodificator: 2, at_mod: -1, pa_mod: 2, article: 0, DmgThreshold: 16, combattechnique: 'stangenwaffen'}, { id: 'speer', name: 'Speer', dice: 1, diemodificator: 4, at_mod: 0, pa_mod: 0, article: 0, DmgThreshold: 15, combattechnique: 'stangenwaffen'}, - { id: 'zweililien', name: 'Zweililien', dice: 1, diemodificator: 4, at_mod: 0, pa_mod: 0, article: 3, DmgThreshold: 15, ombattechnique: 'stangenwaffen'}, + { id: 'zweililien', name: 'Zweililien', dice: 1, diemodificator: 4, at_mod: 0, pa_mod: 0, article: 3, DmgThreshold: 15, combattechnique: 'stangenwaffen'}, { id: 'anderthalbhaender', name: 'Anderthalbhänder', dice: 1, diemodificator: 6, at_mod: 0, pa_mod: 0, article: 0, DmgThreshold: 14, combattechnique: 'zweihandschwerter'}, { id: 'doppelkhunchomer', name: 'Doppelkhunchomer', dice: 2, diemodificator: 3, at_mod: 0, pa_mod: -2, article: 3, DmgThreshold: 14, combattechnique: 'zweihandschwerter'}, { id: 'grossersklaventod', name: 'Großer Sklaventod', dice: 2, diemodificator: 6, at_mod: 0, pa_mod: -2, article: 3, DmgThreshold: 14, combattechnique: 'zweihandschwerter'},