From 1426322eb4898cd49310c1dc30cdfc8ad8e73402 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Tue, 22 Aug 2017 18:01:48 -0400 Subject: Parse negative bonuses --- src/dice.js | 10 ++++++++++ src/parser.js | 1 + 2 files changed, 11 insertions(+) (limited to 'src') 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 { -- cgit v1.2.3