* reformatting of skill checks table

* Including own Random "generator", more refactoring
This commit is contained in:
2021-04-22 17:36:10 +02:00
committed by GitHub
parent cc8387256a
commit 126dce828d
14 changed files with 127 additions and 208 deletions

View 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 };

View 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 };

View File

@ -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
View 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 };

View File

@ -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 };