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