From a06042e6d41cc69a27db1072a65777f4ad9f6528 Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Mon, 4 Jul 2022 22:26:14 -0400 Subject: [PATCH] Add OVA Dice documentation Additionally, simplified the ova dropper --- README.md | 3 +++ src/commands/rollHelp.ts | 7 +++++++ src/solver/roller.ts | 19 +++++++++++-------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2edd1ad..a03e938 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,9 @@ The Artificer comes with a few supplemental commands to the main rolling command * CWOD Dice - `[[xcwody]]` * `x` - Number of CWOD dice to roll * `y` - Difficulty to roll at + * OVA Dice - `[[xovady]]` + * `x` - Number of OVA dice to roll + * `y` - Size of the die to roll (defaults to 6 if omitted) * This command also has some useful decorators that can used. These decorators simply need to be placed after all rolls in the message: * `-c` - Count - Shows the Count Embed, containing the count of successful rolls, failed rolls, rerolls, drops, and explosions * `-nd` - No Details - Suppresses all details of the requested roll diff --git a/src/commands/rollHelp.ts b/src/commands/rollHelp.ts index 538afa8..8fdc6d2 100644 --- a/src/commands/rollHelp.ts +++ b/src/commands/rollHelp.ts @@ -178,6 +178,13 @@ The Artificer supports most of the [Roll20 formatting](https://artificer.eanm.de \`y\` - Difficulty to roll at`, inline: true, }, + { + name: 'OVA Rolling', + value: `\`${config.prefix}xovady${config.postfix}\` +\`x\` - Number of OVA dice to roll +\`y\` - Size of the die to roll (defaults to 6 if omitted)`, + inline: true, + }, ], }, { diff --git a/src/solver/roller.ts b/src/solver/roller.ts index 61b4e0d..1760592 100644 --- a/src/solver/roller.ts +++ b/src/solver/roller.ts @@ -561,18 +561,21 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea // Handle OVA dropping/keeping if (rollType === 'ova') { - const rollCounts: Array = new Array(rollConf.dieSize).fill(0); + // Make "empty" vals array to easily sum up which die value is the greatest + const rollVals: Array = new Array(rollConf.dieSize).fill(0); + // Sum up all rolls for (const roll of rollSet) { - loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | incrementing rollCounts for ${roll}`); - rollCounts[roll.roll - 1]++; + loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | incrementing rollVals for ${roll}`); + rollVals[roll.roll - 1] += roll.roll; } - - const rollVals: Array = rollCounts.map((cnt, idx) => (cnt * (idx + 1))); - - const maxRoll = rollVals.indexOf(Math.max(...rollVals)) + 1; - + + // Find max value, using lastIndexOf to use the greatest die size max in case of duplicate maximums + const maxRoll = rollVals.lastIndexOf(Math.max(...rollVals)) + 1; + + // Drop all dice that are not a part of the max for (let i = 0; i < rollSet.length; i++) { + loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | checking if this roll should be dropped ${rollSet[i].roll} | to keep: ${maxRoll}`); if (rollSet[i].roll !== maxRoll) { rollSet[i].dropped = true; rollSet[i].critFail = false;