From 0cafda573f91c1fef813c09b6910e22b32716537 Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Tue, 17 May 2022 01:09:01 -0400 Subject: [PATCH] Added Reroll Once option, which cannot be used with the standard reroll option --- README.md | 39 +++++++++++++++++++++------------------ src/constantCmds.ts | 18 +++++++++++++++--- src/solver/roller.ts | 16 ++++++++++++++-- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 228b6e9..f731ba5 100644 --- a/README.md +++ b/README.md @@ -61,24 +61,27 @@ The Artificer comes with a few supplemental commands to the main rolling command * PI and e are available for use. * Parameters for rolling: - | Paramater | Required? | Repeatable? | Description | - |---------------|-------------|---------------|------------------------------------------------------------------------------------------------------------------------------------| - | x | Optional | No | number of dice to roll, if omitted, 1 is used | - | dy | Required | No | size of dice to roll, d20 = 20 sided die | - | dz or dlz | Optional | No | drops the lowest z dice, cannot be used any other drop or keep options | - | kz or khz | Optional | No | keeps the highest z dice, cannot be used any other drop or keep options | - | dhz | Optional | No | drops the highest z dice, cannot be used any other drop or keep options | - | klz | Optional | No | keeps the lowest z dice, cannot be used any other drop or keep options | - | ra | Optional | Yes | rerolls any rolls that match a, r3 will reroll any dice that land on 3, throwing out old rolls | - | ra | Optional | Yes | rerolls any rolls that are greater than or equal to a, r3 will reroll any dice that land on 3 or greater, throwing out old rolls | - | csq or cs=q | Optional | Yes | changes crit score to q | - | csq | Optional | Yes | changes crit score to be greater than or equal to q | - | cfq or cf=q | Optional | Yes | changes crit fail to q | - | cfq | Optional | Yes | changes crit fail to be greater than or equal to q | - | ! | Optional | No | exploding, rolls another dy for every crit roll | + | Paramater | Required? | Repeatable? | Description | + |---------------|-------------|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------| + | x | Optional | No | number of dice to roll, if omitted, 1 is used | + | dy | Required | No | size of dice to roll, d20 = 20 sided die | + | dz or dlz | Optional | No | drops the lowest z dice, cannot be used with any other drop or keep options | + | kz or khz | Optional | No | keeps the highest z dice, cannot be used with any other drop or keep options | + | dhz | Optional | No | drops the highest z dice, cannot be used with any other drop or keep options | + | klz | Optional | No | keeps the lowest z dice, cannot be used with any other drop or keep options | + | ra or r=a | Optional | Yes | rerolls any rolls that match a, r3 will reroll every die that land on 3, throwing out old rolls, cannot be used with ro | + | ra | Optional | Yes | rerolls any rolls that are greater than or equal to a, r3 will reroll every die that land on 3 or greater, throwing out old rolls, cannot be used with ro | + | roa or ro=a | Optional | Yes | rerolls any rolls that match a, r3 will reroll each die that lands on 3 ONLY ONE TIME, throwing out old rolls, cannot be used with r | + | roa | Optional | Yes | rerolls any rolls that are greater than or equal to a, r3 will reroll each die that lands on 3 or greater ONLY ONE TIME, throwing out old rolls, cannot be used with r | + | csq or cs=q | Optional | Yes | changes crit score to q | + | csq | Optional | Yes | changes crit score to be greater than or equal to q | + | cfq or cf=q | Optional | Yes | changes crit fail to q | + | cfq | Optional | Yes | changes crit fail to be greater than or equal to q | + | ! | Optional | No | exploding, rolls another dy for every crit roll | * If the parameter is Required, it must be provided at all times. * If the parameter is Repeatable, it may occur multiple times in the roll configuration. diff --git a/src/constantCmds.ts b/src/constantCmds.ts index 0b8b07a..b5057ee 100644 --- a/src/constantCmds.ts +++ b/src/constantCmds.ts @@ -249,15 +249,27 @@ export const constantCmds = { inline: true }, { name: "`ra` or `r=q` [Optional]", - value: "Rerolls any rolls that match `a`, `r3` will reroll any dice that land on 3, throwing out old rolls", + value: "Rerolls any rolls that match `a`, `r3` will reroll every die that land on 3, throwing out old rolls, cannot be used with `ro`", inline: true }, { name: "`rq` [Optional]", - value: "Rerolls any rolls that are greater than or equal to `a`, `r3` will reroll any dice that land on 3 or greater, throwing out old rolls", + value: "Rerolls any rolls that are greater than or equal to `a`, `r3` will reroll every die that land on 3 or greater, throwing out old rolls, cannot be used with `ro`", + inline: true + }, { + name: "`roa` or `ro=q` [Optional]", + value: "Rerolls any rolls that match `a`, `ro3` will reroll each die that lands on 3 ONLY ONE TIME, throwing out old rolls, cannot be used with `r`", + inline: true + }, { + name: "`roq` [Optional]", + value: "Rerolls any rolls that are greater than or equal to `a`, `ro3` will reroll each die that lands on 3 or greater ONLY ONE TIME, throwing out old rolls, cannot be used with `r`", inline: true }, { name: "`csq` or `cs=q` [Optional]", diff --git a/src/solver/roller.ts b/src/solver/roller.ts index 99c5d60..823a8d5 100644 --- a/src/solver/roller.ts +++ b/src/solver/roller.ts @@ -59,6 +59,7 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea }, reroll: { on: false, + once: false, nums: [] }, critScore: { @@ -146,12 +147,19 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea rollConf.keepLow.on = true; rollConf.keepLow.count = tNum; break; + case "ro": + case "ro=": + rollConf.reroll.once = true; + // falls through as ro/ro= functions the same as r case "r": case "r=": // Configure Reroll (this can happen multiple times) rollConf.reroll.on = true; rollConf.reroll.nums.push(tNum); break; + case "ro>": + rollConf.reroll.once = true; + // falls through as ro> functions the same as r case "r>": // Configure reroll for all numbers greater than or equal to tNum (this could happen multiple times, but why) rollConf.reroll.on = true; @@ -160,8 +168,11 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea rollConf.reroll.nums.push(i); } break; + case "ro<": + rollConf.reroll.once = true; + // falls through as ro< functions the same as r case "r<": - // Configure CritScore for all numbers less than or equal to tNum (this could happen multiple times, but why) + // Configure reroll for all numbers less than or equal to tNum (this could happen multiple times, but why) rollConf.reroll.on = true; for (let i = 1; i <= tNum; i++) { log(LT.LOG, `Handling roll ${rollStr} | Parsing r< ${i}`); @@ -342,7 +353,8 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea } // If we need to reroll this roll, flag its been replaced and... - if (rollConf.reroll.on && rollConf.reroll.nums.indexOf(rollSet[i].roll) >= 0) { + // This big boolean statement first checks if reroll is on, if the roll is within the reroll range, and finally if ro is ON, make sure we haven't already rerolled the roll + if (rollConf.reroll.on && rollConf.reroll.nums.indexOf(rollSet[i].roll) >= 0 && (!rollConf.reroll.once || rollConf.reroll.once && !rollSet[i ? (i - 1) : i].rerolled)) { rollSet[i].rerolled = true; // Copy the template to fill out for this iteration