From d04a43c03835950ff2a3e9e4208188dd6d03c126 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Thu, 24 Jul 2025 16:54:52 +0200 Subject: [PATCH] Fixed advantage/disadvantage reroll counting on d20s --- module/dice/d20Roll.mjs | 59 +++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/module/dice/d20Roll.mjs b/module/dice/d20Roll.mjs index 42ce9dde..dcf0143a 100644 --- a/module/dice/d20Roll.mjs +++ b/module/dice/d20Roll.mjs @@ -182,35 +182,9 @@ export default class D20Roll extends DHRoll { return (this._formula = this.constructor.getFormula(this.terms)); } - static async reroll(rollString, target, message) { - let parsedRoll = game.system.api.dice.D20Roll.fromData({ ...rollString, evaluated: false }); - - const term = parsedRoll.terms[0]; - await term.reroll(`/r1=${term.total}`); - - if (game.modules.get('dice-so-nice')?.active) { - const diceSoNiceRoll = { - _evaluated: true, - dice: [ - new foundry.dice.terms.Die({ - ...term, - faces: term._faces, - results: term.results.filter(x => !x.rerolled) - }) - ], - options: { appearance: {} } - }; - - const diceSoNicePresets = getDiceSoNicePresets(); - const type = target.dataset.type; - if (diceSoNicePresets[type]) { - diceSoNiceRoll.dice[0].options = { appearance: diceSoNicePresets[type] }; - } - - await game.dice3d.showForRoll(diceSoNiceRoll, game.user, true); - } - await parsedRoll.evaluate(); - + static async reroll(rollString, _target, message) { + let parsedRoll = game.system.api.dice.D20Roll.fromData(rollString); + parsedRoll = await parsedRoll.reroll(); const newRoll = game.system.api.dice.D20Roll.postEvaluate(parsedRoll, { targets: message.system.targets, roll: { @@ -219,7 +193,30 @@ export default class D20Roll extends DHRoll { } }); - newRoll.extra = newRoll.extra.slice(1); - return { newRoll, parsedRoll }; + if (game.modules.get('dice-so-nice')?.active) { + await game.dice3d.showForRoll(parsedRoll, game.user, true); + } + + const rerolled = { + any: true, + rerolls: [ + ...(message.system.roll.dice[0].rerolled?.rerolls?.length > 0 + ? [message.system.roll.dice[0].rerolled?.rerolls] + : []), + rollString.terms[0].results + ] + }; + return { + newRoll: { + ...newRoll, + dice: [ + { + ...newRoll.dice[0], + rerolled: rerolled + } + ] + }, + parsedRoll + }; } }