Files
dsabot/functions/CompareResults.js
TobenderZephyr 23418bbc60 Add Skillchecks for Magical Talents (#25)
* initial implementation of spells

* added return list of spells. Moved them into seperate json

* added _some_ chants, restructuring data from spells

* added more chants, added command for getting info

* added related messages, added skillcheck for spells (cast)

* better error handling, added chant command

* (fix) Chants were referring to spells

* cleanup testing variables and code

* updated README

* fixed storage location issues and minor bugs

* removed db storage location

* rc1

* (fix) chants_title

* (fix) Uncaught ReferenceError: Discord is not defined

* (fix) more reference errors

Co-authored-by: Marcus Netz <marcus.netz@godyo.com>
2021-04-28 19:33:30 +02:00

52 lines
1.4 KiB
JavaScript

/**
* Compares each item inside an array Throws
* with corresponding AttributeLevels (With added bonus)
*
* @param {Array} Throws=[]
* @param {Array} AttributeLevels=[8,8,8]
* @param {BigInt} Bonus=0
* @param {BigInt} PointsRemaining=0
*/
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 };