Browse Source

Add outcome to dice result

Also start sketching out results set for aggregate results
tags/v0.1.3
bertieb 3 years ago
parent
commit
ac0b877685
1 changed files with 33 additions and 0 deletions
  1. +33
    -0
      dice.ts

+ 33
- 0
dice.ts View File

@@ -44,6 +44,15 @@ interface DiceResult {
balance?: number; balance?: number;


} }

interface ItemCount {
item: string | number | Outcomes;
count: number;
}

declare let ItemCountSet: Array<ItemCount>;


/** /**
* Simple d10, implements `roll()` * Simple d10, implements `roll()`
*/ */
@@ -220,6 +229,26 @@ class Asphodice extends D10 {
// PS also good practice to supply initialValue (0) // 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<number>): 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 * Roll an Asphodie or Asphodice
* *
@@ -283,6 +312,10 @@ class Asphodice extends D10 {


results.balance = this.countOutcomeBalance(results.dice); results.balance = this.countOutcomeBalance(results.dice);
results.total = results.dice.reduce((acc: number, curr: number) => acc + curr); 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; return results;
} }
} }


Loading…
Cancel
Save