Cleanup (#19)
* reformatting of skill checks table * Including own Random "generator", more refactoring
This commit is contained in:
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 };
|
Reference in New Issue
Block a user