diff --git a/README.md b/README.md index 917023f..761674b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,22 @@ # Risk Dice -An implementation of Risk Dice as found for example in the Splittermond game system. +An implementation of risk dice as found for example in the Splittermond game +system. + +This module provides a new dice type which represents a risk die. Rolling a risk +die ist just rolling 4 10 sided dice. The total result is calculated by: +- If there are either two `1`s or a `1` and a `2` in the results, the total sum + is `1 + 1` or `1 + 2` respectively. +- Otherwise, the total result is the sum of the 2 highest results. + + +``` +/roll dr # Roll a risk die. +``` + +![Risk Dice](./risk-dice.png) + + ## Installation diff --git a/risk-dice.png b/risk-dice.png new file mode 100644 index 0000000..d5e57b5 Binary files /dev/null and b/risk-dice.png differ diff --git a/src/module/risk-dice.ts b/src/module/risk-dice.ts new file mode 100644 index 0000000..88985fe --- /dev/null +++ b/src/module/risk-dice.ts @@ -0,0 +1,30 @@ +class RiskDie extends DiceTerm { + constructor() { + super({ number: 4, faces: 10 }); + } + + get total() { + if (!this._evaluated) return null; + let total; + if (this.values.includes(1) && this.values.includes(2)) { + total = 3; + } else if (this.values.filter((res) => res === 1).length > 1) { + total = 2; + } else { + total = this.values + .sort((a, b) => b - a) + .slice(0, 2) + .reduce((acc, e) => acc + e, 0); + } + return total; + } +} + +function registerRiskDie() { + CONFIG.Dice.types.push(RiskDie); + CONFIG.Dice.terms.r = RiskDie; +} + +Hooks.once('init', () => { + registerRiskDie(); +}); diff --git a/src/module/risk-die.ts b/src/module/risk-die.ts deleted file mode 100644 index e69de29..0000000