From 8d56fed614a7cc7062a1a13a071453ef14eaac81 Mon Sep 17 00:00:00 2001 From: Lasth31 Date: Mon, 13 Feb 2023 14:38:20 +0100 Subject: [PATCH] fix calculation of furor usage --- modules/yggdrasill-utility.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/yggdrasill-utility.js b/modules/yggdrasill-utility.js index 391a58b..bd4a618 100644 --- a/modules/yggdrasill-utility.js +++ b/modules/yggdrasill-utility.js @@ -87,12 +87,14 @@ export class YggdrasillUtility { /* -------------------------------------------- */ static async specificYggRoll( nbDice ) { + return specificYggRoll(nbDice, false); + } + + static async specificYggRoll( nbDice, isFurorUsage ) { let rawDices = [] let rolls = [] let maxTab = [] - - maxTab[0] = {idx: 0, value: 0} - maxTab[1] = {idx: 0, value: 0} + let maxTabMaxIndex = isFurorUsage ? nbDice : 2; for (let i=0; i maxTab[0].value) { - if ( nbDice > 1 && maxTab[0].value > maxTab[1].value) { - maxTab[1].value = maxTab[0].value - } - maxTab[0].value = rolls[i].total - } else { - if ( nbDice > 1 && rolls[i].total > maxTab[1].value) { - maxTab[1].value = rolls[i].total - } - } } - return { rawDices: rawDices, maxTab: maxTab, rolls: rolls} + + rolls.sort((a,b) => a.total-b.total); + rolls.reverse(); + + for (let i=0; i 0 ) { - results = await this.specificYggRoll( rollData.furorUsage ) + results = await this.specificYggRoll( rollData.furorUsage, true ) rollData.furorRawDices = results.rawDices rollData.furorMaxTab = results.maxTab rollData.furorRolls = results.rolls