m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dice.js16
-rw-r--r--src/lexer.js1
-rw-r--r--src/parser.js1
3 files changed, 18 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js
index 9bc53d7..e96aca9 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -73,6 +73,21 @@ const explode = (die1, die2) => {
}
}
+const explodeUnder = (die1, die2) => {
+ return () => {
+ const explodeOn = roll(die1)
+ return die2().map(die => () => {
+ let lastRoll = die()
+ let total = lastRoll
+ while (lastRoll <= explodeOn) {
+ lastRoll = die()
+ total += lastRoll
+ }
+ return total
+ })
+ }
+}
+
const keepHigh = (die1, die2) => {
return () => {
const numberToKeep = roll(die1)
@@ -174,6 +189,7 @@ exports.bonusAdd = bonusAdd
exports.bonusSubtract = bonusSubtract
exports.negative = negative
exports.explode = explode
+exports.explodeUnder = explodeUnder
exports.keepHigh = keepHigh
exports.keepLow = keepLow
exports.again = again
diff --git a/src/lexer.js b/src/lexer.js
index f316147..7eb95b0 100644
--- a/src/lexer.js
+++ b/src/lexer.js
@@ -23,6 +23,7 @@ newLexemeType('minus', '-')
newLexemeType('(', '\\(')
newLexemeType(')', '\\)')
newLexemeType('E', 'E')
+newLexemeType('e', 'e')
newLexemeType('K', 'K')
newLexemeType('k', 'k')
newLexemeType('A', 'A')
diff --git a/src/parser.js b/src/parser.js
index 0201d05..124d686 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -61,6 +61,7 @@ newSymbol('d', (parser) => {
}
})
newDieOperation('E')
+newDieOperation('e')
newDieOperation('K')
newDieOperation('k')
newDieOperation('A')