fix calculation of furor usage #5

Merged
uberwald merged 1 commits from Lasth31/fvtt-yggdrasill:fix/v10-furor-calculation into v10 2023-02-13 15:54:39 +01:00

View File

@ -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<nbDice; i++) {
rolls[i] = new Roll("1d10x10").roll( {async: false}) //+sumDice+"+"+rollData.furorUsage+"d10+"+niveauCompetence+"+"+rollData.finalBM).roll( { async: false} );
@ -102,18 +104,16 @@ export class YggdrasillUtility {
this.showDiceSoNice(rolls[i], game.settings.get("core", "rollMode") );
}
rawDices.push({ 'result': rolls[i].total});
}
if ( rolls[i].total > 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
}
}
rolls.sort((a,b) => a.total-b.total);
rolls.reverse();
for (let i=0; i<maxTabMaxIndex; i++) {
maxTab[i] = {idx: 0, value: 0};
if (rolls[i].total != undefined) maxTab[i].value = rolls[i].total;
}
return { rawDices: rawDices, maxTab: maxTab, rolls: rolls }
}
@ -218,7 +218,7 @@ export class YggdrasillUtility {
console.log("RES", results, nbDice, sumDice)
if ( rollData.furorUsage > 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