OVA dice done

This commit is contained in:
Ean Milligan (Bastion) 2022-07-04 22:19:09 -04:00
parent 8e84be1656
commit 169ed564ae
1 changed files with 22 additions and 0 deletions

View File

@ -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<number> = 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<number> = 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;
};