Added a toggle in D20RollDialog for ReactionRolls

This commit is contained in:
WBHarry 2025-07-30 15:22:35 +02:00
parent 8e516df7cb
commit 9cb8302bcd
6 changed files with 54 additions and 7 deletions

View file

@ -7,6 +7,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
this.roll = roll;
this.config = config;
this.config.experiences = [];
this.reactionOverride = false;
if (config.source?.action) {
this.item = config.data.parent.items.get(config.source.item) ?? config.data.parent;
@ -30,6 +31,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
actions: {
updateIsAdvantage: this.updateIsAdvantage,
selectExperience: this.selectExperience,
toggleReaction: this.toggleReaction,
submitRoll: this.submitRoll
},
form: {
@ -103,6 +105,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
context.isLite = this.config.roll?.lite;
context.extraFormula = this.config.extraFormula;
context.formula = this.roll.constructFormula(this.config);
context.reactionOverride = this.reactionOverride;
}
return context;
}
@ -141,7 +144,15 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
this.render();
}
static toggleReaction() {
if (this.config.roll) {
this.reactionOverride = !this.reactionOverride;
this.render();
}
}
static async submitRoll() {
this.config.roll.type = this.reactionOverride ? CONFIG.DH.ITEM.actionTypes.reaction.id : this.config.roll.type;
await this.close({ submitted: true });
}

View file

@ -69,6 +69,7 @@ export default class DHRoll extends Roll {
static postEvaluate(roll, config = {}) {
return {
type: config.roll.type,
total: roll.total,
formula: roll.formula,
dice: roll.dice.map(d => ({
@ -194,11 +195,12 @@ export const registerRollDiceHooks = () => {
if (config.roll.result.duality === -1) updates.push({ key: 'fear', value: 1 });
if (config.rerolledRoll) {
if (config.rerolledRoll.isCritical || config.rerolledRoll.result.duality === 1) updates.push({ key: 'hope', value: -1 });
if (config.rerolledRoll.isCritical || config.rerolledRoll.result.duality === 1)
updates.push({ key: 'hope', value: -1 });
if (config.rerolledRoll.isCritical) updates.push({ key: 'stress', value: 1 });
if (config.rerolledRoll.result.duality === -1) updates.push({ key: 'fear', value: -1 });
}
if (updates.length) {
const target = actor.system.partner ?? actor;
if (!['dead', 'unconcious'].some(x => actor.statuses.has(x))) {