add initial value to reduce

This commit is contained in:
Ean Milligan 2025-05-03 16:49:00 -04:00
parent 9d7aed2773
commit 7808093bc7
1 changed files with 18 additions and 8 deletions

View File

@ -117,14 +117,24 @@ export const runCmd = (fullCmd: string, modifiers: RollModifiers): SolvedRoll =>
returnMsg.line3 = line3;
// Reduce counts to a single object
returnMsg.counts = tempCountDetails.reduce((acc, cnt) => ({
total: acc.total + cnt.total,
successful: acc.successful + cnt.successful,
failed: acc.failed + cnt.failed,
rerolled: acc.rerolled + cnt.rerolled,
dropped: acc.dropped + cnt.dropped,
exploded: acc.exploded + cnt.exploded,
}));
returnMsg.counts = tempCountDetails.reduce(
(acc, cnt) => ({
total: acc.total + cnt.total,
successful: acc.successful + cnt.successful,
failed: acc.failed + cnt.failed,
rerolled: acc.rerolled + cnt.rerolled,
dropped: acc.dropped + cnt.dropped,
exploded: acc.exploded + cnt.exploded,
}),
{
total: 0,
successful: 0,
failed: 0,
rerolled: 0,
dropped: 0,
exploded: 0,
},
);
} catch (e) {
// Fill in the return block
returnMsg.error = true;