|
@@ -32,6 +32,7 @@ interface DiceResult { |
|
|
olddice?: Array<number>; |
|
|
olddice?: Array<number>; |
|
|
reroll?: boolean; |
|
|
reroll?: boolean; |
|
|
outcome?: Outcomes; |
|
|
outcome?: Outcomes; |
|
|
|
|
|
balance?: number; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -121,6 +122,18 @@ class Asphodice extends D10 { |
|
|
return ((checkDice.filter(die => die >= this.successCutOff).length == 0)); |
|
|
return ((checkDice.filter(die => die >= this.successCutOff).length == 0)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
countOutcomeBalance (resultDice: Array<number>): number{ |
|
|
|
|
|
// Return a positive / negative number representing |
|
|
|
|
|
// the overall outcomes: each failure (eg < 6) is -1 |
|
|
|
|
|
// while each success (eg >= 6) is +1 |
|
|
|
|
|
|
|
|
|
|
|
// fun with ternary operators |
|
|
|
|
|
return resultDice.reduce( |
|
|
|
|
|
(acc: number, curr: number) => |
|
|
|
|
|
{ return (curr < this.successCutOff) ? acc - 1 : acc + 1 }, |
|
|
|
|
|
0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
roll (numToRoll: number): DiceResult { |
|
|
roll (numToRoll: number): DiceResult { |
|
|
let results: DiceResult = { total: 0, dice: [] }; |
|
|
let results: DiceResult = { total: 0, dice: [] }; |
|
|
|
|
|
|
|
@@ -172,6 +185,7 @@ class Asphodice extends D10 { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
return results; |
|
|
return results; |
|
|
} |
|
|
} |
|
|