From 7823227f6e0e6794b0cf9a1202db4d3b8d249315 Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Tue, 5 Jul 2022 22:19:10 -0400 Subject: [PATCH] Penetrating explosions are now functional, added formatting for explosions --- src/commands/rollHelp.ts | 5 +++++ src/solver/rollFormatter.ts | 4 ++++ src/solver/roller.ts | 17 +++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/commands/rollHelp.ts b/src/commands/rollHelp.ts index f114dd4..23b6802 100644 --- a/src/commands/rollHelp.ts +++ b/src/commands/rollHelp.ts @@ -250,6 +250,11 @@ Additionally, replace \`x\` with \`F\` to roll Fate dice`, value: 'Rolls that were dropped or rerolled ~~crossed out~~.', inline: true, }, + { + name: 'Exclamation mark (`!`)', + value: 'Rolls that were caused by an explosion have an exclamation mark (`!`) after them.', + inline: true, + }, ], }, ], diff --git a/src/solver/rollFormatter.ts b/src/solver/rollFormatter.ts index b905db2..42fe837 100644 --- a/src/solver/rollFormatter.ts +++ b/src/solver/rollFormatter.ts @@ -61,6 +61,10 @@ export const formatRoll = (rollConf: string, maximiseRoll: boolean, nominalRoll: preFormat = `~~${preFormat}`; postFormat = `${postFormat}~~`; } + if (e.exploding) { + // Add ! to indicate the roll came from an explosion + postFormat = `!${postFormat}`; + } // Finally add this to the roll's details tempDetails += `${preFormat}${e.roll}${postFormat} + `; diff --git a/src/solver/roller.ts b/src/solver/roller.ts index f520831..fc52e0d 100644 --- a/src/solver/roller.ts +++ b/src/solver/roller.ts @@ -519,6 +519,23 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea } } + // If penetrating is on, do the decrements + if (rollConf.exploding.penetrating) { + for (const penRoll of rollSet) { + // If loopCount gets too high, stop trying to calculate infinity + if (loopCount > config.limits.maxLoops) { + throw new Error('MaxLoopsExceeded'); + } + + // If the die was from an explosion, decrement it by one + if (penRoll.exploding) { + penRoll.roll--; + } + + loopCount++; + } + } + // If we need to handle the drop/keep flags if (dkdkCnt > 0) { // Count how many rerolled dice there are if the reroll flag was on