Cleanup (#19)
* reformatting of skill checks table * Including own Random "generator", more refactoring
This commit is contained in:
12
__tests__/functions/CalculateQuality.js
Normal file
12
__tests__/functions/CalculateQuality.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
const {CalculateQuality} = require('@dsabot/CalculateQuality');
|
||||||
|
|
||||||
|
const TestValues = [
|
||||||
|
[1,1], [2,1], [3,1],
|
||||||
|
[4,2], [5,2], [6,2],
|
||||||
|
[7,3], [8,3], [9,3],
|
||||||
|
[10,4],[11,4],[12,4],
|
||||||
|
[13,5],[14,5],[15,5]
|
||||||
|
];
|
||||||
|
test.each(TestValues)('Retrieving Quality for %s', (input, output) => {
|
||||||
|
expect(CalculateQuality(input)).toBe(output);
|
||||||
|
});
|
@ -1,14 +1,8 @@
|
|||||||
const {
|
const { roll } = require('@dsabot/Roll');
|
||||||
roll
|
|
||||||
} = require('../../functions/Roll');
|
|
||||||
|
|
||||||
describe('rolling dice', () => {
|
describe('rolling dice', () => {
|
||||||
const expected = [1, 2, 3, 4, 5, 6];
|
const expected = [1, 2, 3, 4, 5, 6];
|
||||||
it('contain only numbers from 1 to 6', () => {
|
test.each(expected)('contains only numbers from 1 to 6', (value) => {
|
||||||
expect(roll(100, 6).dice).toEqual(
|
expect(roll(200, 6).dice).toContain(value);
|
||||||
expect.arrayContaining(expected),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//todo: return sum
|
|
@ -1,61 +0,0 @@
|
|||||||
const globals = require('../globals');
|
|
||||||
const db = globals.db;
|
|
||||||
const Random = require('random');
|
|
||||||
/*
|
|
||||||
"meleeweapons": [{
|
|
||||||
"amount": 1,
|
|
||||||
"equipped": true,
|
|
||||||
"handling": [],
|
|
||||||
"ruleelement": {
|
|
||||||
"id": "dolch",
|
|
||||||
"type": "meleeweapon"
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
"amount": 1,
|
|
||||||
"equipped": true,
|
|
||||||
"handling": [],
|
|
||||||
"ruleelement": {
|
|
||||||
"id": "waqqif",
|
|
||||||
"type": "meleeweapon"
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
*/
|
|
||||||
module.exports = {
|
|
||||||
name: 'melee',
|
|
||||||
description: 'Würfelt den Attackewert auf eine Nahkampfwaffe.',
|
|
||||||
aliases: ['nahkampf'],
|
|
||||||
usage: '<Waffe>',
|
|
||||||
needs_args: true,
|
|
||||||
|
|
||||||
async exec(message, args) {
|
|
||||||
try {
|
|
||||||
db.find({
|
|
||||||
user: message.author.tag,
|
|
||||||
}, function(err, docs) {
|
|
||||||
if (docs.length === 0) {
|
|
||||||
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
Random.use(message.author.tag);
|
|
||||||
let dice = [];
|
|
||||||
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);}
|
|
||||||
const DieModificator = Weapon.diemodificator;
|
|
||||||
let sum = DieModificator;
|
|
||||||
for (let i = 0; i < Weapon.dice; i++) {
|
|
||||||
dice.push(Random.int(1,6));
|
|
||||||
}
|
|
||||||
dice.forEach(result => {
|
|
||||||
sum += result;
|
|
||||||
});
|
|
||||||
message.reply('Deine 🎲: ' + dice.join(',') + '.\n' + Weapon.name + ' richtet ` ' + sum + ' ` Schaden an. (' + Weapon.dice + 'W6+' + Weapon.diemodificator +')');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
@ -1,64 +0,0 @@
|
|||||||
const globals = require('../globals');
|
|
||||||
const db = globals.db;
|
|
||||||
const Random = require('random');
|
|
||||||
/*
|
|
||||||
"meleeweapons": [{
|
|
||||||
"amount": 1,
|
|
||||||
"equipped": true,
|
|
||||||
"handling": [],
|
|
||||||
"ruleelement": {
|
|
||||||
"id": "dolch",
|
|
||||||
"type": "meleeweapon"
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
"amount": 1,
|
|
||||||
"equipped": true,
|
|
||||||
"handling": [],
|
|
||||||
"ruleelement": {
|
|
||||||
"id": "waqqif",
|
|
||||||
"type": "meleeweapon"
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
*/
|
|
||||||
module.exports = {
|
|
||||||
name: 'ranged',
|
|
||||||
description: 'Würfelt den Attackewert auf eine Nahkampfwaffe.',
|
|
||||||
aliases: ['fernkampf'],
|
|
||||||
usage: '<Waffe>',
|
|
||||||
needs_args: true,
|
|
||||||
|
|
||||||
async exec(message, args) {
|
|
||||||
try {
|
|
||||||
db.find({
|
|
||||||
user: message.author.tag,
|
|
||||||
}, function(err, docs) {
|
|
||||||
if (docs.length === 0) {
|
|
||||||
return message.reply(globals.Replies.find(r => r.id === 'NOENTRY').string);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
Random.use(message.author.tag);
|
|
||||||
let dice = [];
|
|
||||||
/*for (i in docs[0].character.skills) {
|
|
||||||
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]);
|
|
||||||
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++) {
|
|
||||||
dice.push(Random.int(1,6));
|
|
||||||
}
|
|
||||||
dice.forEach(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.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
@ -12,15 +12,11 @@ module.exports = {
|
|||||||
async exec(message, args) {
|
async exec(message, args) {
|
||||||
let params = args.join('').split(globals.DiceRegex);
|
let params = args.join('').split(globals.DiceRegex);
|
||||||
if ( params.length >= 2 ) {
|
if ( params.length >= 2 ) {
|
||||||
let bonus = 0;
|
const Bonus = params[2] || 0;
|
||||||
const numberOfDice = parseInt( params[0] );
|
const numberOfDice = parseInt( params[0] );
|
||||||
const diceValues = parseInt( params[1] );
|
const diceValues = parseInt( params[1] );
|
||||||
if ( params.length == 3 ) {
|
|
||||||
bonus = parseInt( params[2] );
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = roll( numberOfDice, diceValues, message.author.tag );
|
const result = roll( numberOfDice, diceValues, message.author.tag );
|
||||||
message.reply(`${findMessage('ROLL')} ${result.dice.join(', ')} (Gesamt: ${result.sum} + ${bonus} = ${result.sum + bonus})` );
|
message.reply(`${findMessage('ROLL')} ${result.dice.join(', ')} (Gesamt: ${result.sum} + ${Bonus} = ${result.sum + Bonus})` );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
@ -20,14 +20,15 @@ module.exports = {
|
|||||||
return message.reply(findMessage('NOENTRY'));
|
return message.reply(findMessage('NOENTRY'));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let gender;
|
const Character = docs[0].character;
|
||||||
if (docs[0].character.sex == 'female') { gender = '♀️'; }
|
let Gender;
|
||||||
else { gender = '♂️'; }
|
if (Character.sex == 'female') { 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} ${Character.name}`);
|
||||||
Reply.setDescription(docs[0].character.age + ' Jahre, ' + docs[0].character.race + '/' + docs[0].character.culture);
|
Reply.setDescription(`${Character.age} Jahre, ${Character.race}/${Character.culture}`);
|
||||||
Reply.addField(docs[0].character.professionname, docs[0].character.xp.startinglevel);
|
Reply.addField(Character.professionname, Character.xp.startinglevel);
|
||||||
|
|
||||||
message.reply( Reply );
|
message.reply( Reply );
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ const Discord = require('discord.js');
|
|||||||
const db = globals.db;
|
const db = globals.db;
|
||||||
const { roll } = require('@dsabot/Roll');
|
const { roll } = require('@dsabot/Roll');
|
||||||
const { findMessage } = require('@dsabot/findMessage');
|
const { findMessage } = require('@dsabot/findMessage');
|
||||||
const { getSkill } = require('@dsabot/getSkill')
|
const { getSkill } = require('@dsabot/getSkill');
|
||||||
|
const { CalculateQuality } = require('@dsabot/CalculateQuality');
|
||||||
|
const { CompareResults } = require('@dsabot/CompareResults');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'talent',
|
name: 'talent',
|
||||||
description: ' Du machst eine Fertigkeitsprobe.\n' +
|
description: ' Du machst eine Fertigkeitsprobe.\n' +
|
||||||
@ -42,10 +44,7 @@ module.exports = {
|
|||||||
const Reply = new Discord.MessageEmbed();
|
const Reply = new Discord.MessageEmbed();
|
||||||
Reply.addFields({
|
Reply.addFields({
|
||||||
name: `Du würfelst auf das Talent **${Skill.Name}** (Stufe ${Skill.Level} + ${Bonus})`,
|
name: `Du würfelst auf das Talent **${Skill.Name}** (Stufe ${Skill.Level} + ${Bonus})`,
|
||||||
value:`\`\`\`\u200B\u2003\u2003\u2003\u2003${Attributes.map(a => a.Name).join('\u2003\u2003')}\n` +
|
value: CreateTable({Attributes: Attributes, Throws: DiceThrow, PointsUsed: PointsUsed}),
|
||||||
`\u200B✊🏻\u2003\u2003${Attributes.map(a => a.Level).join('\u2003\u2003')}\n` +
|
|
||||||
`\u200B🎲\u2003\u2003${DiceThrow.join('\u2003\u2003')}\n` +
|
|
||||||
`\u200B-\u2003\u2003\u2003${PointsUsed.join('\u2003\u2003')}\`\`\``,
|
|
||||||
inline: false
|
inline: false
|
||||||
});
|
});
|
||||||
if (Fumbles >= 2) {
|
if (Fumbles >= 2) {
|
||||||
@ -65,13 +64,13 @@ module.exports = {
|
|||||||
} else if (Passed < 3) {
|
} else if (Passed < 3) {
|
||||||
Reply.addFields({
|
Reply.addFields({
|
||||||
name: findMessage('TITLE_FAILURE'),
|
name: findMessage('TITLE_FAILURE'),
|
||||||
value: `nur ${Passed}/3 Proben erfolgreich. 😪`,
|
value: `${(Passed === 0) ? 'Keine Probe' : `nur ${Passed}/3 Proben`} erfolgreich. 😪`,
|
||||||
inline: false
|
inline: false
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Reply.addFields({
|
Reply.addFields({
|
||||||
name: findMessage('TITLE_SUCCESS'),
|
name: findMessage('TITLE_SUCCESS'),
|
||||||
value: `Dein Bonus: ${PointsRemaining}/${Skill.Level} (QS${CalculateQuality(PointsRemaining)})`,
|
value: `Dein verbleibender Bonus: ${PointsRemaining}/${Skill.Level} (QS${CalculateQuality(PointsRemaining)})`,
|
||||||
inline: false
|
inline: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -85,49 +84,18 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const CalculateQuality = (PointsAvailable = 0) => {
|
|
||||||
if (PointsAvailable<=3) return 1;
|
|
||||||
else if (PointsAvailable>3&&PointsAvailable<=6) return 2;
|
|
||||||
else if (PointsAvailable>6&&PointsAvailable<=9) return 3;
|
|
||||||
else if (PointsAvailable>9&&PointsAvailable<=12) return 4;
|
|
||||||
else if (PointsAvailable>12&&PointsAvailable<=15) return 5;
|
|
||||||
else if (PointsAvailable>15) return 6;
|
|
||||||
};
|
|
||||||
|
|
||||||
const CompareResults = (Throws = [], AttributeLevels = [8,8,8], Bonus = 0, PointsRemaining= 0) => {
|
|
||||||
|
|
||||||
let Passed = 0;
|
|
||||||
let Fumbles = 0;
|
|
||||||
let CriticalHit = 0;
|
|
||||||
let AllPointsUsed = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < Throws.length; i++) {
|
|
||||||
let PointsUsed = 0;
|
|
||||||
if (Math.floor(AttributeLevels[i] + Bonus) >= Throws[i]) {
|
|
||||||
Passed++;
|
|
||||||
} else if (Math.floor(AttributeLevels[i] + PointsRemaining + Bonus) >= Throws[i]) {
|
|
||||||
Passed++;
|
|
||||||
PointsUsed = (Throws[i] - Bonus - AttributeLevels[i]);
|
|
||||||
PointsRemaining -= PointsUsed;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// We need to use all our points, so that next die/dice
|
|
||||||
// would not return a 'Passed'.
|
|
||||||
PointsUsed = PointsRemaining;
|
|
||||||
PointsRemaining -= PointsUsed;
|
|
||||||
}
|
|
||||||
if(Throws[i] == 1) {CriticalHit++;}
|
|
||||||
if(Throws[i] == 20) {Fumbles++;}
|
|
||||||
AllPointsUsed.push(PointsUsed);
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
Passed: Passed,
|
|
||||||
CriticalHit: CriticalHit,
|
|
||||||
Fumbles: Fumbles,
|
|
||||||
PointsUsed: AllPointsUsed,
|
|
||||||
PointsRemaining: PointsRemaining };
|
|
||||||
};
|
|
||||||
|
|
||||||
function Pad(Number = 0) {
|
function Pad(Number = 0) {
|
||||||
return Number.toString().padStart(2, '0');
|
return Number.toString().padStart(1, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CreateTable = ({Attributes: Attributes, Throws: Throws, PointsUsed: PointsUsed}) => {
|
||||||
|
return `
|
||||||
|
\`\`\`
|
||||||
|
${' '.padEnd(15)} ${Attributes.map(attr => `${attr.Name}`.padStart(5)).join('\t|\t')}\t|
|
||||||
|
${'Dein Wert'.padEnd(15)} ${Attributes.map(attr => `${attr.Level}`.padStart(5)).join('\t|\t')}\t|
|
||||||
|
${'Dein Wurf'.padEnd(15)} ${Throws.map(Throw => `${Throw}`.padStart(5)).join('\t|\t')}\t|
|
||||||
|
${'Abzüge'.padEnd(15)} ${PointsUsed.map(Points => `${Points}`.replace(0,'--').padStart(5)).join('\t|\t')}\t|
|
||||||
|
${'Gesamt'.padEnd(15)} ${PointsUsed.reduce((acc,cur) => acc+cur).toString().padStart(5)}
|
||||||
|
\`\`\`
|
||||||
|
`;
|
||||||
|
};
|
15
functions/CalculateQuality.js
Normal file
15
functions/CalculateQuality.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
const CalculateQuality = (PointsAvailable = 0) => {
|
||||||
|
if (PointsAvailable <= 3)
|
||||||
|
return 1;
|
||||||
|
else if (PointsAvailable > 3 && PointsAvailable <= 6)
|
||||||
|
return 2;
|
||||||
|
else if (PointsAvailable > 6 && PointsAvailable <= 9)
|
||||||
|
return 3;
|
||||||
|
else if (PointsAvailable > 9 && PointsAvailable <= 12)
|
||||||
|
return 4;
|
||||||
|
else if (PointsAvailable > 12 && PointsAvailable <= 15)
|
||||||
|
return 5;
|
||||||
|
else if (PointsAvailable > 15)
|
||||||
|
return 6;
|
||||||
|
};
|
||||||
|
module.exports = { CalculateQuality };
|
35
functions/CompareResults.js
Normal file
35
functions/CompareResults.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
const CompareResults = (Throws = [], AttributeLevels = [8, 8, 8], Bonus = 0, PointsRemaining = 0) => {
|
||||||
|
|
||||||
|
let Passed = 0;
|
||||||
|
let Fumbles = 0;
|
||||||
|
let CriticalHit = 0;
|
||||||
|
let AllPointsUsed = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < Throws.length; i++) {
|
||||||
|
let PointsUsed = 0;
|
||||||
|
if (Math.floor(AttributeLevels[i] + Bonus) >= Throws[i]) {
|
||||||
|
Passed++;
|
||||||
|
} else if (Math.floor(AttributeLevels[i] + PointsRemaining + Bonus) >= Throws[i]) {
|
||||||
|
Passed++;
|
||||||
|
PointsUsed = (Throws[i] - Bonus - AttributeLevels[i]);
|
||||||
|
PointsRemaining -= PointsUsed;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// We need to use all our points, so that next die/dice
|
||||||
|
// would not return a 'Passed'.
|
||||||
|
PointsUsed = PointsRemaining;
|
||||||
|
PointsRemaining -= PointsUsed;
|
||||||
|
}
|
||||||
|
if (Throws[i] == 1) { CriticalHit++; }
|
||||||
|
if (Throws[i] == 20) { Fumbles++; }
|
||||||
|
AllPointsUsed.push(PointsUsed);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
Passed: Passed,
|
||||||
|
CriticalHit: CriticalHit,
|
||||||
|
Fumbles: Fumbles,
|
||||||
|
PointsUsed: AllPointsUsed,
|
||||||
|
PointsRemaining: PointsRemaining
|
||||||
|
};
|
||||||
|
};
|
||||||
|
module.exports = { CompareResults };
|
@ -2,6 +2,4 @@ const CountOccurences = (arr, value) => {
|
|||||||
return arr.filter((v) => (v === value)).length;
|
return arr.filter((v) => (v === value)).length;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = { CountOccurences };
|
module.exports = { CountOccurences };
|
||||||
|
|
||||||
//console.log(countOccurrences([1,2,3,4,3,2,3,3,2],2));
|
|
13
functions/Random.js
Normal file
13
functions/Random.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const Random = {int, use};
|
||||||
|
|
||||||
|
function int (min, max) {
|
||||||
|
if (!min || !max) { return; }
|
||||||
|
//return Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min))) + min;
|
||||||
|
return Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min) + 1)) + min;
|
||||||
|
}
|
||||||
|
|
||||||
|
function use (str) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { Random };
|
@ -1,4 +1,6 @@
|
|||||||
const Random = require('random');
|
const { Random } = require("@dsabot/Random");
|
||||||
|
//const Random = require('random');
|
||||||
|
|
||||||
const roll = (numberOfDice, numberOfEyes, tag) => {
|
const roll = (numberOfDice, numberOfEyes, tag) => {
|
||||||
let dice = [];
|
let dice = [];
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
@ -13,3 +15,4 @@ const roll = (numberOfDice, numberOfEyes, tag) => {
|
|||||||
return { dice, sum };
|
return { dice, sum };
|
||||||
};
|
};
|
||||||
module.exports = { roll };
|
module.exports = { roll };
|
||||||
|
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
testEnvironment: 'node'
|
testEnvironment: 'node',
|
||||||
|
moduleNameMapper: {
|
||||||
|
"@dsabot/(.*)": "<rootDir>/functions/$1",
|
||||||
|
"@Commands/(.*)": "<rootDir>/commands/$1",
|
||||||
|
"@Root/(.*)": "<rootDir>/$1",
|
||||||
|
}
|
||||||
};
|
};
|
@ -1,9 +1,13 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": "./",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@dsabot/*": ["functions/*"],
|
"@dsabot/*": ["./functions/*"],
|
||||||
"@globals": ["./globals"]
|
"@globals": ["./globals"]
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
|
"exclude": ["node_modules"],
|
||||||
|
"typeAcquisition": {
|
||||||
|
"exclude": [ "dotenv" ]
|
||||||
|
},
|
||||||
}
|
}
|
Reference in New Issue
Block a user