From 169ed564ae144878b9ca711a47f5a5d0139d4c07 Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Mon, 4 Jul 2022 22:19:09 -0400 Subject: [PATCH] OVA dice done --- src/solver/roller.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/solver/roller.ts b/src/solver/roller.ts index 373133b..61b4e0d 100644 --- a/src/solver/roller.ts +++ b/src/solver/roller.ts @@ -559,5 +559,27 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea rollSet.sort(compareOrigidx); } + // Handle OVA dropping/keeping + if (rollType === 'ova') { + const rollCounts: Array = new Array(rollConf.dieSize).fill(0); + + for (const roll of rollSet) { + loggingEnabled && log(LT.LOG, `handling ${rollType} ${rollStr} | incrementing rollCounts for ${roll}`); + rollCounts[roll.roll - 1]++; + } + + const rollVals: Array = rollCounts.map((cnt, idx) => (cnt * (idx + 1))); + + const maxRoll = rollVals.indexOf(Math.max(...rollVals)) + 1; + + for (let i = 0; i < rollSet.length; i++) { + if (rollSet[i].roll !== maxRoll) { + rollSet[i].dropped = true; + rollSet[i].critFail = false; + rollSet[i].critHit = false; + } + } + } + return rollSet; };