Fixed advantage/disadvantage reroll counting on d20s

This commit is contained in:
WBHarry 2025-07-24 16:54:52 +02:00
parent 72491891ed
commit d04a43c038

View file

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