m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dice.js10
-rw-r--r--src/parser.js1
2 files changed, 11 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js
index becf7dc..58467c4 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -102,6 +102,15 @@ const bonusAdd = (die1, die2) => {
}
}
+const bonusSubtract = (die1, die2) => {
+ const negative2 = negative(die2)
+ return () => {
+ return die1().map(die => {
+ return () => die() + roll(negative2)
+ })
+ }
+}
+
exports.pool = pool
exports.roll = roll
exports.constant = constant
@@ -113,3 +122,4 @@ exports.explode = explode
exports.keepHigh = keepHigh
exports.keepLow = keepLow
exports.bonusAdd = bonusAdd
+exports.bonusSubtract = bonusSubtract
diff --git a/src/parser.js b/src/parser.js
index 48de2ab..244cdd1 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -66,6 +66,7 @@ newDieOperation('k')
newInfix('bigPlus', 20, { type: 'add' })
newInfix('plus', 20, { type: 'bonusAdd' })
+newInfix('minus', 20, { type: 'bonusSubtract' })
newInfix('bigMinus', 20, { type: 'subtract' })
newSymbol('minus', (parser) => {
return {