refactoring (#4)
This commit is contained in:
@ -2,7 +2,8 @@
|
||||
const Random = require('random');
|
||||
const globals = require('../globals');
|
||||
const Discord = require('discord.js');
|
||||
|
||||
const { roll } = require('@dsabot/Roll');
|
||||
const { findMessage }= require('@dsabot/findMessage');
|
||||
module.exports = {
|
||||
name: 'tp',
|
||||
description: 'Du machst eine Fertigkeitsprobe.\n' +
|
||||
@ -15,11 +16,11 @@ module.exports = {
|
||||
async exec(message, args) {
|
||||
|
||||
if(isNaN(args[0])) {
|
||||
return message.reply(globals.Replies.find(x => x.id === 'WRONG_ARGUMENTS').string);
|
||||
return message.reply(findMessage('WRONG_ARGUMENTS'));
|
||||
}
|
||||
|
||||
Random.use(message.author.tag);
|
||||
const roll = [];
|
||||
//Random.use(message.author.tag);
|
||||
//const dice = [];
|
||||
let bonus = 0;
|
||||
let bonus_orig = 0;
|
||||
let erschwernis = 0;
|
||||
@ -30,50 +31,51 @@ module.exports = {
|
||||
if (args[4]) {
|
||||
erschwernis = parseInt(args[4]);
|
||||
}
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
/*for (let i = 1; i <= 3; i++) {
|
||||
roll.push(Random.int(1, 20));
|
||||
}
|
||||
}*/
|
||||
const dice = roll(3,20,message.author.tag).dice;
|
||||
|
||||
let ok = 0;
|
||||
let patzer = 0;
|
||||
let crit = 0;
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (Math.floor(parseInt(args[i]) + parseInt(erschwernis)) >= roll[i]) {
|
||||
if (Math.floor(parseInt(args[i]) + parseInt(erschwernis)) >= dice[i]) {
|
||||
ok++;
|
||||
} else if (
|
||||
Math.floor(parseInt(args[i]) + parseInt(bonus) + parseInt(erschwernis)) >= roll[i]) {
|
||||
Math.floor(parseInt(args[i]) + parseInt(bonus) + parseInt(erschwernis)) >= dice[i]) {
|
||||
ok++;
|
||||
bonus = bonus - (roll[i] - parseInt(erschwernis) - parseInt(args[i]));
|
||||
bonus = bonus - (dice[i] - parseInt(erschwernis) - parseInt(args[i]));
|
||||
}
|
||||
if (roll[i] == 1) crit++;
|
||||
if (roll[i] == 20) patzer++;
|
||||
if (dice[i] == 1) {crit++;}
|
||||
if (dice[i] == 20) {patzer++;}
|
||||
}
|
||||
|
||||
const Reply = new Discord.MessageEmbed();
|
||||
//Reply.setTitle('Du würfelst auf ' + args[0] + ' ' + args[1] + ' ' + args[2] + ' (Bonus: ' + bonus_orig + ')')
|
||||
Reply.setTitle('Deine 🎲: ' + roll.join(', ') + '.');
|
||||
Reply.setTitle(`${findMessage('ROLL')} ${dice.join(', ')}.`);
|
||||
if (patzer >= 2) {
|
||||
Reply.setColor('#900c3f');
|
||||
Reply.addFields({
|
||||
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_FAILURE').string,
|
||||
value: globals.Replies.find(x => x.id === 'MSG_CRIT_FAILURE').string,
|
||||
name: findMessage('TITLE_CRIT_FAILURE'),
|
||||
value: findMessage('MSG_CRIT_FAILURE'),
|
||||
inline: false
|
||||
});
|
||||
} else if (crit >= 2) {
|
||||
Reply.setColor('#1E8449');
|
||||
Reply.addFields({
|
||||
name: globals.Replies.find(x => x.id === 'TITLE_CRIT_SUCCESS').string,
|
||||
value: globals.Replies.find(x => x.id === 'MSG_CRIT_SUCCESS').string,
|
||||
name: findMessage('TITLE_CRIT_SUCCESS'),
|
||||
value: findMessage('MSG_CRIT_SUCCESS'),
|
||||
inline: false
|
||||
});
|
||||
} else if (ok < 3) {
|
||||
Reply.addFields({
|
||||
name: globals.Replies.find(x => x.id === 'TITLE_FAILURE').string,
|
||||
name: findMessage('TITLE_FAILURE'),
|
||||
value: 'Nur ' + ok + '/3 Proben erfolgreich. 😪',
|
||||
inline: false
|
||||
});
|
||||
} else {
|
||||
Reply.addFields({
|
||||
name: globals.Replies.find(x => x.id === 'TITLE_SUCCESS').string,
|
||||
name: findMessage('TITLE_SUCCESS'),
|
||||
value: ok + '/3 Proben erfolgreich. Dein Bonus: ' + bonus + '/' + bonus_orig + '.',
|
||||
inline: false
|
||||
});
|
||||
|
Reference in New Issue
Block a user