From ac0b87768535862ff0544e63cc5ac1f47cb4fb2c Mon Sep 17 00:00:00 2001 From: bertieb Date: Wed, 10 Feb 2021 11:29:36 +0000 Subject: [PATCH] Add outcome to dice result Also start sketching out results set for aggregate results --- dice.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/dice.ts b/dice.ts index d0f9c31..3ccf59b 100644 --- a/dice.ts +++ b/dice.ts @@ -44,6 +44,15 @@ interface DiceResult { balance?: number; } + +interface ItemCount { + item: string | number | Outcomes; + count: number; +} + +declare let ItemCountSet: Array; + + /** * Simple d10, implements `roll()` */ @@ -220,6 +229,26 @@ class Asphodice extends D10 { // PS also good practice to supply initialValue (0) } + /** + * Determine and return outcome of roll + * + * @remarks + * + * Determines outcome as in "Success", "Failure", etc. Assumes that `resultDice` is + * the 'final' result after any rerolls. + * + * @see {@link:countOutcomeBalance} + */ + checkOutcome (resultDice: Array): Outcomes{ + // Note: currently, one success = Success, regardless of number of failures + // TODO: Critical failures, once decided with Mao + if (this.allBelowCutOff(resultDice)) { + return Outcomes.Fail; + } else { + return Outcomes.Success; + } + } + /** * Roll an Asphodie or Asphodice * @@ -283,6 +312,10 @@ class Asphodice extends D10 { results.balance = this.countOutcomeBalance(results.dice); results.total = results.dice.reduce((acc: number, curr: number) => acc + curr); + + // Finally, once we're done with rerolls etc, determine outcome + results.outcome = this.checkOutcome(results.dice); + return results; } }