diff --git a/dice.ts b/dice.ts index d337b01..28eab93 100644 --- a/dice.ts +++ b/dice.ts @@ -306,15 +306,18 @@ export class Asphodice extends D10 { * - all below cutoff */ rerollNeeded(resultDice: Array): boolean{ + // 'Cancel out' matching re-roll dice + let cancelledDice = this.cancelRerollDice(resultDice); + // 1. if no re-rolls we can finish here - if (!(resultDice.includes(this.passCrit) || resultDice.includes(this.failCrit))) { + if (!(cancelledDice.includes(this.passCrit) || resultDice.includes(this.failCrit))) { // results.total = results.dice.reduce((acc: number, curr: number) => acc + curr); return false; } // count successes and fails - let rerollGood = countOccurrencesOfNumber(resultDice, this.passCrit); - let rerollBad = countOccurrencesOfNumber(resultDice, this.failCrit); + let rerollGood = countOccurrencesOfNumber(cancelledDice, this.passCrit); + let rerollBad = countOccurrencesOfNumber(cancelledDice, this.failCrit); // 2. only reroll if they don't cancel each other out if (rerollGood == rerollBad) { @@ -324,11 +327,11 @@ export class Asphodice extends D10 { } // 3. If all dice are above/below cutoff we don't need to reroll - if (this.allAboveCutOff(resultDice)) { - console.log("All above cutoff, auto-success", resultDice); + if (this.allAboveCutOff(cancelledDice)) { + console.log("All above cutoff, auto-success", cancelledDice); return false; - } else if (this.allBelowCutOff(resultDice)) { - console.log("All below cutoff, auto-fail", resultDice); + } else if (this.allBelowCutOff(cancelledDice)) { + console.log("All below cutoff, auto-fail", cancelledDice); return false; }