m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dice.js9
-rw-r--r--src/lexer.js1
-rw-r--r--src/parser.js1
3 files changed, 11 insertions, 0 deletions
diff --git a/src/dice.js b/src/dice.js
index 5a484b0..6351929 100644
--- a/src/dice.js
+++ b/src/dice.js
@@ -73,6 +73,14 @@ const bonusSubtract = (die1, die2) => {
}
}
+const bonusMultiply = (die1, die2) => {
+ return () => {
+ return die1().map(die => {
+ return () => die() * roll(die2)
+ })
+ }
+}
+
const explode = (comparison, die1, die2) => {
return () => {
const explodeOn = roll(die1)
@@ -216,6 +224,7 @@ exports.multiply = multiply
exports.divide = divide
exports.bonusAdd = bonusAdd
exports.bonusSubtract = bonusSubtract
+exports.bonusMultiply = bonusMultiply
exports.negative = negative
exports.explodeAbove = explodeAbove
exports.explodeUnder = explodeUnder
diff --git a/src/lexer.js b/src/lexer.js
index 248a9b2..e700f87 100644
--- a/src/lexer.js
+++ b/src/lexer.js
@@ -22,6 +22,7 @@ newLexemeType('bigTimes', ' \\* ')
newLexemeType('bigDivide', ' / ')
newLexemeType('plus', '\\+')
newLexemeType('minus', '-')
+newLexemeType('times', '\\*')
newLexemeType('(', '\\(')
newLexemeType(')', '\\)')
newLexemeType('E', 'E')
diff --git a/src/parser.js b/src/parser.js
index b1f6ebb..54dc0ae 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -75,6 +75,7 @@ newInfix('bigTimes', 23, { type: 'multiply' })
newInfix('bigDivide', 23, { type: 'divide' })
newInfix('plus', 25, { type: 'bonusAdd' })
newInfix('minus', 25, { type: 'bonusSubtract' })
+newInfix('times', 26, { type: 'bonusMultiply' })
newSymbol('minus', (parser) => {
return {
type: 'negative',