Przeglądaj źródła

Add outcome to dice result

Also start sketching out results set for aggregate results
tags/v0.1.3
bertieb 3 lat temu
rodzic
commit
ac0b877685
1 zmienionych plików z 33 dodań i 0 usunięć
  1. +33
    -0
      dice.ts

+ 33
- 0
dice.ts Wyświetl plik

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

}

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

declare let ItemCountSet: Array<ItemCount>;


/**
* 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<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
*
@@ -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;
}
}


Ładowanie…
Anuluj
Zapisz