Cleanup (#19)
* reformatting of skill checks table * Including own Random "generator", more refactoring
This commit is contained in:
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;
|
||||
};
|
||||
|
||||
module.exports = { CountOccurences };
|
||||
|
||||
//console.log(countOccurrences([1,2,3,4,3,2,3,3,2],2));
|
||||
module.exports = { CountOccurences };
|
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) => {
|
||||
let dice = [];
|
||||
let sum = 0;
|
||||
@ -13,3 +15,4 @@ const roll = (numberOfDice, numberOfEyes, tag) => {
|
||||
return { dice, sum };
|
||||
};
|
||||
module.exports = { roll };
|
||||
|
||||
|
Reference in New Issue
Block a user