various bugfixing in attribute.js
This commit is contained in:
@ -2,23 +2,24 @@ const globals = require('../globals')
|
|||||||
module.exports = async (message, args, db) => {
|
module.exports = async (message, args, db) => {
|
||||||
try {
|
try {
|
||||||
// user calls without arguments.
|
// user calls without arguments.
|
||||||
if (!args) {
|
if (!args[0]) {
|
||||||
message.reply('Bitte gib mir ein Attributswert, oder das Attribut auf welches du würfeln möchtest.')
|
message.reply('Bitte gib mir ein Attributswert, oder das Attribut auf welches du würfeln möchtest.')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let level = 8
|
let level = 8
|
||||||
// user calls with text.
|
let attributename
|
||||||
if (isNaN(args[0])) {
|
|
||||||
db.find({
|
await db.find({
|
||||||
user: message.author.tag,
|
user: message.author.tag,
|
||||||
}, function (err, docs) {
|
}, async function (err, docs) {
|
||||||
|
|
||||||
|
// user calls with text. need to gather info from database
|
||||||
|
if (isNaN(args[0])) {
|
||||||
if (!docs.length > 0) {
|
if (!docs.length > 0) {
|
||||||
message.reply('Sorry, Für dich habe ich keinen Eintrag 😥\n' +
|
message.reply('Sorry, Für dich habe ich keinen Eintrag 😥\n' +
|
||||||
'Bitte gib mir den Attributswert, auf welchen du würfeln möchtest.');
|
'Bitte gib mir den Attributswert, auf welchen du würfeln möchtest.');
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
let attributename
|
|
||||||
// try to get id of short formatted attributes.
|
// try to get id of short formatted attributes.
|
||||||
if (args[0].length == 2) {
|
if (args[0].length == 2) {
|
||||||
for (let i in globals.Werte) {
|
for (let i in globals.Werte) {
|
||||||
@ -27,51 +28,46 @@ module.exports = async (message, args, db) => {
|
|||||||
} else {
|
} else {
|
||||||
attributename = args[0].toLowerCase();
|
attributename = args[0].toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i in docs[0].character.attributes) {
|
for (let i in docs[0].character.attributes) {
|
||||||
if (docs[0].character.attributes[i].id == attributename) level = docs[0].character.attributes[i].level;
|
if (docs[0].character.attributes[i].id == attributename) level = docs[0].character.attributes[i].level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
} else {
|
level = args[0];
|
||||||
level = args[0];
|
}
|
||||||
}
|
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
|
||||||
|
let dice = []
|
||||||
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
|
|
||||||
let dice = []
|
|
||||||
dice.push(Math.floor(Math.random() * 20) + 1);
|
|
||||||
if (dice[0] == 1 || dice[0] == 20) {
|
|
||||||
dice.push(Math.floor(Math.random() * 20) + 1);
|
dice.push(Math.floor(Math.random() * 20) + 1);
|
||||||
}
|
if (dice[0] == 1 || dice[0] == 20) {
|
||||||
|
dice.push(Math.floor(Math.random() * 20) + 1);
|
||||||
// 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[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 {
|
// handle crits
|
||||||
if (attributename) {
|
if (countOccurrences(dice, 1) == 2) {
|
||||||
message.reply('Du hast die Probe auf ' + attributename + ' (Stufe ' + level + ') leider nicht bestanden 😢.\n' +
|
message.reply('Du hast einen kritischen Erfolg erzielt (' + dice.join(', ') + ')! 🎉🥳🎆');
|
||||||
'Deine 🎲: ' + dice.join(', '))
|
return
|
||||||
} else {
|
} else if (countOccurrences(dice, 20) == 2) {
|
||||||
message.reply('Du hast die Probe (Stufe ' + level + ') leider nicht bestanden 😢.\n' +
|
message.reply('Du hast einen Patzer (' + dice.join(', ') + ')! 😭 Viel Erfolg beim nächsten mal!')
|
||||||
'Deine 🎲: ' + dice.join(', '))
|
return
|
||||||
}
|
}
|
||||||
}
|
if ((dice.length == 2 && dice[0] != 20 && dice[1] <= level) || (dice.length == 1 && dice[0] <= level)) {
|
||||||
|
if (attributename) {
|
||||||
} catch (e) {
|
message.reply('Du hast die Probe auf ' + attributename + ' (Stufe ' + level + ') bestanden.\n' +
|
||||||
throw e;
|
'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;
|
||||||
|
}
|
||||||
};
|
};
|
@ -9,8 +9,14 @@ const tp = require('./tp');
|
|||||||
const talent = require('./talent');
|
const talent = require('./talent');
|
||||||
const skill = require('./skill');
|
const skill = require('./skill');
|
||||||
const createFromFile = require('./createFromFile');
|
const createFromFile = require('./createFromFile');
|
||||||
const {kopf, zahl, heads, tails} = require('./HeadsOrTails');
|
const kopf = require('./HeadsOrTails');
|
||||||
const {attribute, eigenschaft, e, a} = require('./attribute')
|
const zahl = require('./HeadsOrTails');
|
||||||
|
const heads = require('./HeadsOrTails');
|
||||||
|
const tails = require('./HeadsOrTails');
|
||||||
|
const e = require('./attribute')
|
||||||
|
const ew = require('./attribute')
|
||||||
|
const a = require('./attribute')
|
||||||
|
const attr = require('./attribute')
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
const cmdprefix = process.env.CMDPREFIX || '!';
|
const cmdprefix = process.env.CMDPREFIX || '!';
|
||||||
@ -30,8 +36,8 @@ const commands = {
|
|||||||
tails,
|
tails,
|
||||||
e,
|
e,
|
||||||
a,
|
a,
|
||||||
attribute,
|
attr,
|
||||||
eigenschaft
|
ew
|
||||||
};
|
};
|
||||||
|
|
||||||
const Datastore = require('nedb'),
|
const Datastore = require('nedb'),
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
module.exports = async (message, args, db) => {
|
module.exports = async (message, args, db) => {
|
||||||
let command = args.join('')
|
let arguments = args.join('')
|
||||||
let regex = /\s?[DdWw]\s?/;
|
let regex = /\s?[DdWw]\s?/;
|
||||||
command = command.split(regex);
|
arguments = arguments.split(regex);
|
||||||
|
|
||||||
if (command.length == 2){
|
if (arguments.length == 2){
|
||||||
let numberOfDice = command[0];
|
let numberOfDice = arguments[0];
|
||||||
let diceValues = command[1];
|
let diceValues = arguments[1];
|
||||||
let roll = [];
|
let roll = [];
|
||||||
for (let i = 0; i<numberOfDice; i++) {
|
for (let i = 0; i<numberOfDice; i++) {
|
||||||
let a = Math.floor(Math.random() * diceValues) + 1;
|
let a = Math.floor(Math.random() * diceValues) + 1;
|
||||||
roll.push(a)
|
roll.push(a)
|
||||||
}
|
}
|
||||||
message.reply('Das waren deine 🎲 für ' + command.join('').toUpperCase() + ':' + roll.join(', ') + '.')
|
if(numberOfDice=1) { let msg = 'n'}
|
||||||
|
else { let msg = ' ' + numberOfDice;}
|
||||||
|
message.reply('Das sind deine Ergebnisse für deine' + msg +' ' + diceValues + '-seitigen 🎲: ' + roll.join(', ') + '.')
|
||||||
}
|
}
|
||||||
else { message.reply('Leider kann ich damit nichts anfangen. Bitte noch einmal so probieren:\n'+
|
else { message.reply('Leider kann ich damit nichts anfangen. Bitte noch einmal so probieren:\n'+
|
||||||
'!roll <Anzahl> W <Augenzahl>')}
|
'!roll <Anzahl> W <Augenzahl>')}
|
||||||
|
Reference in New Issue
Block a user