Add tests for standard mutli dice rolls.
This commit is contained in:
parent
3526e6ab99
commit
c315742412
2 changed files with 91 additions and 13 deletions
|
@ -30,27 +30,41 @@ export function rollCheckSingleDie(
|
|||
}
|
||||
}
|
||||
|
||||
function rollCheckMultipleDice(testValue: number, rollOptions: RollOptions): RollResult {
|
||||
export function rollCheckMultipleDice(
|
||||
testValue: number,
|
||||
rollOptions: RollOptions,
|
||||
provider: RollProvider = new DS4RollProvider(),
|
||||
): RollResult {
|
||||
const finalCheck = testValue % 20;
|
||||
const numberOfDice = Math.ceil(testValue / 20);
|
||||
const rolls = new Array<Roll>();
|
||||
for (let i = 0; i < numberOfDice; i++) {
|
||||
const roll = new Roll("1d20");
|
||||
roll.roll();
|
||||
rolls.concat(roll);
|
||||
}
|
||||
const dice = rolls.map((r) => r.total);
|
||||
|
||||
const firstResult = dice[1];
|
||||
const dice = provider.getNextRolls(numberOfDice);
|
||||
|
||||
console.log(dice[0]);
|
||||
console.log(rollOptions.minCritFail);
|
||||
|
||||
const firstResult = dice[0];
|
||||
|
||||
if (firstResult >= rollOptions.minCritFail) {
|
||||
return new RollResult(0, RollResultStatus.CRITICAL_FAILURE, dice);
|
||||
}
|
||||
|
||||
const [otherRolls, critSuccesses] = dice
|
||||
.partition((r) => r <= rollOptions.maxCritSucc)
|
||||
const partitionCallback = (prev: [Array<number>, Array<number>], cur: number) => {
|
||||
if (cur <= rollOptions.maxCritSucc) {
|
||||
prev[0].push(cur);
|
||||
} else {
|
||||
prev[1].push(cur);
|
||||
}
|
||||
return prev;
|
||||
};
|
||||
|
||||
const [critSuccesses, otherRolls] = dice
|
||||
.reduce(partitionCallback, [[], []])
|
||||
.map((a) => a.sort((r1, r2) => r2 - r1));
|
||||
|
||||
console.log(critSuccesses);
|
||||
console.log(otherRolls);
|
||||
|
||||
const sortedRollResults: Array<number> = critSuccesses.concat(otherRolls);
|
||||
|
||||
const evaluationResult = sortedRollResults
|
||||
|
@ -59,7 +73,7 @@ function rollCheckMultipleDice(testValue: number, rollOptions: RollOptions): Rol
|
|||
if (value == 1) {
|
||||
return finalCheck;
|
||||
} else {
|
||||
return value >= finalCheck ? value : 0;
|
||||
return value <= finalCheck ? value : 0;
|
||||
}
|
||||
} else {
|
||||
if (value <= rollOptions.maxCritSucc) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue