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 + }; } }