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;
}
const reaction = rollCommand.reaction;
const traitValue = rollCommand.trait?.toLowerCase();
const advantage = rollCommand.advantage
? CONFIG.DH.ACTIONS.advantageState.advantage.value
@ -208,7 +209,16 @@ Hooks.on('chatMessage', (_, message) => {
})
: 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;
}
});

View file

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

View file

@ -7,7 +7,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
this.roll = roll;
this.config = config;
this.config.experiences = [];
this.reactionOverride = false;
this.reactionOverride = config.roll.type === 'reaction';
if (config.source?.action) {
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.extraFormula = this.config.extraFormula;
context.formula = this.roll.constructFormula(this.config);
context.showReaction = !context.rollConfig.type && context.rollType === 'DualityRoll';
context.reactionOverride = this.reactionOverride;
}
return context;
@ -152,7 +154,11 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
}
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 });
}

View file

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

View file

@ -1,8 +1,10 @@
<header class="dialog-header">
<h1>
{{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"}}">
<i class="fa-solid fa-reply"></i>
</button>
{{/if}}
</h1>
</header>