DualityRollEnrichment can now use reaction

This commit is contained in:
WBHarry 2025-07-30 16:32:42 +02:00
parent 9cb8302bcd
commit b9334447de
5 changed files with 38 additions and 19 deletions

View file

@ -193,6 +193,7 @@ Hooks.on('chatMessage', (_, message) => {
return false; return false;
} }
const reaction = rollCommand.reaction;
const traitValue = rollCommand.trait?.toLowerCase(); const traitValue = rollCommand.trait?.toLowerCase();
const advantage = rollCommand.advantage const advantage = rollCommand.advantage
? CONFIG.DH.ACTIONS.advantageState.advantage.value ? CONFIG.DH.ACTIONS.advantageState.advantage.value
@ -208,7 +209,16 @@ Hooks.on('chatMessage', (_, message) => {
}) })
: game.i18n.localize('DAGGERHEART.GENERAL.duality'); : game.i18n.localize('DAGGERHEART.GENERAL.duality');
enrichedDualityRoll({ traitValue, target, difficulty, title, label: 'test', actionType: null, advantage }); enrichedDualityRoll({
reaction,
traitValue,
target,
difficulty,
title,
label: 'test',
actionType: null,
advantage
});
return false; return false;
} }
}); });

View file

@ -1348,7 +1348,6 @@
"basics": "Basics", "basics": "Basics",
"bonus": "Bonus", "bonus": "Bonus",
"burden": "Burden", "burden": "Burden",
"check": "{check} Check",
"continue": "Continue", "continue": "Continue",
"criticalSuccess": "Critical Success", "criticalSuccess": "Critical Success",
"damage": "Damage", "damage": "Damage",
@ -1401,6 +1400,7 @@
"roll": "Roll", "roll": "Roll",
"rollAll": "Roll All", "rollAll": "Roll All",
"rollDamage": "Roll Damage", "rollDamage": "Roll Damage",
"rollWith": "{roll} Roll",
"save": "Save", "save": "Save",
"scalable": "Scalable", "scalable": "Scalable",
"situationalBonus": "Situational Bonus", "situationalBonus": "Situational Bonus",

View file

@ -7,7 +7,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
this.roll = roll; this.roll = roll;
this.config = config; this.config = config;
this.config.experiences = []; this.config.experiences = [];
this.reactionOverride = false; this.reactionOverride = config.roll.type === 'reaction';
if (config.source?.action) { if (config.source?.action) {
this.item = config.data.parent.items.get(config.source.item) ?? config.data.parent; this.item = config.data.parent.items.get(config.source.item) ?? config.data.parent;
@ -105,6 +105,8 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
context.isLite = this.config.roll?.lite; context.isLite = this.config.roll?.lite;
context.extraFormula = this.config.extraFormula; context.extraFormula = this.config.extraFormula;
context.formula = this.roll.constructFormula(this.config); context.formula = this.roll.constructFormula(this.config);
context.showReaction = !context.rollConfig.type && context.rollType === 'DualityRoll';
context.reactionOverride = this.reactionOverride; context.reactionOverride = this.reactionOverride;
} }
return context; return context;
@ -152,7 +154,11 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
} }
static async submitRoll() { static async submitRoll() {
this.config.roll.type = this.reactionOverride ? CONFIG.DH.ITEM.actionTypes.reaction.id : this.config.roll.type; this.config.roll.type = this.reactionOverride
? CONFIG.DH.ITEM.actionTypes.reaction.id
: this.config.roll.type === CONFIG.DH.ITEM.actionTypes.reaction.id
? null
: this.config.roll.type;
await this.close({ submitted: true }); await this.close({ submitted: true });
} }

View file

@ -9,15 +9,14 @@ export default function DhDualityRollEnricher(match, _options) {
} }
function getDualityMessage(roll) { function getDualityMessage(roll) {
const traitLabel = const trait = roll.trait && abilities[roll.trait] ? game.i18n.localize(abilities[roll.trait].label) : null;
roll.trait && abilities[roll.trait] const label = roll.trait
? game.i18n.format('DAGGERHEART.GENERAL.check', { ? game.i18n.format('DAGGERHEART.GENERAL.rollWith', { roll: trait })
check: game.i18n.localize(abilities[roll.trait].label) : roll.reaction
}) ? game.i18n.localize('DAGGERHEART.GENERAL.reactionRoll')
: null; : game.i18n.localize('DAGGERHEART.GENERAL.duality');
const label = traitLabel ?? game.i18n.localize('DAGGERHEART.GENERAL.duality'); const dataLabel = trait
const dataLabel = traitLabel
? game.i18n.localize(abilities[roll.trait].label) ? game.i18n.localize(abilities[roll.trait].label)
: game.i18n.localize('DAGGERHEART.GENERAL.duality'); : game.i18n.localize('DAGGERHEART.GENERAL.duality');
@ -38,6 +37,7 @@ function getDualityMessage(roll) {
<button class="duality-roll-button" <button class="duality-roll-button"
data-title="${label}" data-title="${label}"
data-label="${dataLabel}" data-label="${dataLabel}"
data-reaction="${roll.reaction ? 'true' : 'false'}"
data-hope="${roll.hope ?? 'd12'}" data-hope="${roll.hope ?? 'd12'}"
data-fear="${roll.fear ?? 'd12'}" data-fear="${roll.fear ?? 'd12'}"
${advantage ? `data-advantage="${advantage}"` : ''} ${advantage ? `data-advantage="${advantage}"` : ''}
@ -46,7 +46,7 @@ function getDualityMessage(roll) {
${roll.advantage ? 'data-advantage="true"' : ''} ${roll.advantage ? 'data-advantage="true"' : ''}
${roll.disadvantage ? 'data-disadvantage="true"' : ''} ${roll.disadvantage ? 'data-disadvantage="true"' : ''}
> >
<i class="fa-solid fa-circle-half-stroke"></i> ${roll.reaction ? '<i class="fa-solid fa-reply"></i>' : '<i class="fa-solid fa-circle-half-stroke"></i>'}
${label} ${label}
${roll.difficulty || advantageLabel ? `(${[roll.difficulty, advantageLabel ? game.i18n.localize(`DAGGERHEART.GENERAL.${advantageLabel}.short`) : null].filter(x => x).join(' ')})` : ''} ${roll.difficulty || advantageLabel ? `(${[roll.difficulty, advantageLabel ? game.i18n.localize(`DAGGERHEART.GENERAL.${advantageLabel}.short`) : null].filter(x => x).join(' ')})` : ''}
</button> </button>
@ -57,6 +57,7 @@ function getDualityMessage(roll) {
export const renderDualityButton = async event => { export const renderDualityButton = async event => {
const button = event.currentTarget, const button = event.currentTarget,
reaction = button.dataset.reaction === 'true',
traitValue = button.dataset.trait?.toLowerCase(), traitValue = button.dataset.trait?.toLowerCase(),
target = getCommandTarget({ allowNull: true }), target = getCommandTarget({ allowNull: true }),
difficulty = button.dataset.difficulty, difficulty = button.dataset.difficulty,
@ -64,12 +65,12 @@ export const renderDualityButton = async event => {
await enrichedDualityRoll( await enrichedDualityRoll(
{ {
reaction,
traitValue, traitValue,
target, target,
difficulty, difficulty,
title: button.dataset.title, title: button.dataset.title,
label: button.dataset.label, label: button.dataset.label,
actionType: button.dataset.actionType,
advantage advantage
}, },
event event
@ -77,7 +78,7 @@ export const renderDualityButton = async event => {
}; };
export const enrichedDualityRoll = async ( export const enrichedDualityRoll = async (
{ traitValue, target, difficulty, title, label, actionType, advantage }, { reaction, traitValue, target, difficulty, title, label, advantage },
event event
) => { ) => {
const config = { const config = {
@ -88,7 +89,7 @@ export const enrichedDualityRoll = async (
label: label, label: label,
difficulty: difficulty, difficulty: difficulty,
advantage, advantage,
type: actionType ?? null // Need check, type: reaction ? 'reaction' : null
}, },
chatMessage: { chatMessage: {
template: 'systems/daggerheart/templates/ui/chat/duality-roll.hbs' template: 'systems/daggerheart/templates/ui/chat/duality-roll.hbs'

View file

@ -1,8 +1,10 @@
<header class="dialog-header"> <header class="dialog-header">
<h1> <h1>
{{ifThen rollConfig.headerTitle rollConfig.headerTitle rollConfig.title}} {{ifThen rollConfig.headerTitle rollConfig.headerTitle rollConfig.title}}
{{#if showReaction}}
<button class="reaction-roll-controller {{#if reactionOverride}}active{{/if}}" data-action="toggleReaction" data-tooltip-text="{{localize "DAGGERHEART.GENERAL.reactionRoll"}}"> <button class="reaction-roll-controller {{#if reactionOverride}}active{{/if}}" data-action="toggleReaction" data-tooltip-text="{{localize "DAGGERHEART.GENERAL.reactionRoll"}}">
<i class="fa-solid fa-reply"></i> <i class="fa-solid fa-reply"></i>
</button> </button>
{{/if}}
</h1> </h1>
</header> </header>