Fixed duality roll buttons

This commit is contained in:
WBHarry 2025-06-13 01:12:01 +02:00
parent 75ee44af52
commit 01aa1b4bdd
3 changed files with 11 additions and 10 deletions

View file

@ -135,7 +135,7 @@ Hooks.on(socketEvent.GMUpdate, async (action, uuid, update) => {
const renderDualityButton = async event => { const renderDualityButton = async event => {
const button = event.currentTarget, const button = event.currentTarget,
attributeValue = button.dataset.attribute?.toLowerCase(), traitValue = button.dataset.trait?.toLowerCase(),
target = getCommandTarget(); target = getCommandTarget();
if (!target) return; if (!target) return;
@ -143,7 +143,8 @@ const renderDualityButton = async event => {
event: event, event: event,
title: button.dataset.label, title: button.dataset.label,
roll: { roll: {
modifier: attributeValue ? target.system.attributes[attributeValue].data.value : null, modifier: traitValue ? target.system.traits[traitValue].value : null,
label: button.dataset.label,
type: button.dataset.actionType ?? null // Need check type: button.dataset.actionType ?? null // Need check
}, },
chatMessage: { chatMessage: {
@ -239,7 +240,7 @@ Hooks.on('chatMessage', (_, message) => {
const hopeAndFearRoll = `1${rollCommand.hope ?? 'd12'}+1${rollCommand.fear ?? 'd12'}`; const hopeAndFearRoll = `1${rollCommand.hope ?? 'd12'}+1${rollCommand.fear ?? 'd12'}`;
const advantageRoll = `${rollCommand.advantage && !rollCommand.disadvantage ? '+d6' : rollCommand.disadvantage && !rollCommand.advantage ? '-d6' : ''}`; const advantageRoll = `${rollCommand.advantage && !rollCommand.disadvantage ? '+d6' : rollCommand.disadvantage && !rollCommand.advantage ? '-d6' : ''}`;
const attributeRoll = `${trait?.data?.value ? `${trait.data.value > 0 ? `+${trait.data.value}` : `${trait.data.value}`}` : ''}`; const attributeRoll = `${trait?.value ? `${trait.value > 0 ? `+${trait.value}` : `${trait.value}`}` : ''}`;
const roll = await Roll.create(`${hopeAndFearRoll}${advantageRoll}${attributeRoll}`).evaluate(); const roll = await Roll.create(`${hopeAndFearRoll}${advantageRoll}${attributeRoll}`).evaluate();
setDiceSoNiceForDualityRoll( setDiceSoNiceForDualityRoll(

View file

@ -271,8 +271,8 @@ export default class DhpActor extends Actor {
} }
formatRollModifier(roll) { formatRollModifier(roll) {
const modifier = roll.modifier ? Number.parseInt(roll.modifier) : null; const modifier = roll.modifier !== null ? Number.parseInt(roll.modifier) : null;
return roll.modifier !== null return modifier !== null
? [ ? [
{ {
value: modifier, value: modifier,

View file

@ -9,13 +9,13 @@ export function dualityRollEnricher(match, _options) {
} }
export function getDualityMessage(roll) { export function getDualityMessage(roll) {
const attributeLabel = const traitLabel =
roll.attribute && abilities[roll.attribute] roll.trait && abilities[roll.trait]
? game.i18n.format('DAGGERHEART.General.Check', { ? game.i18n.format('DAGGERHEART.General.Check', {
check: game.i18n.localize(abilities[roll.attribute].label) check: game.i18n.localize(abilities[roll.trait].label)
}) })
: null; : null;
const label = attributeLabel ?? game.i18n.localize('DAGGERHEART.General.Duality'); const label = traitLabel ?? game.i18n.localize('DAGGERHEART.General.Duality');
const dualityElement = document.createElement('span'); const dualityElement = document.createElement('span');
dualityElement.innerHTML = ` dualityElement.innerHTML = `
@ -23,7 +23,7 @@ export function getDualityMessage(roll) {
data-label="${label}" data-label="${label}"
data-hope="${roll.hope ?? 'd12'}" data-hope="${roll.hope ?? 'd12'}"
data-fear="${roll.fear ?? 'd12'}" data-fear="${roll.fear ?? 'd12'}"
${roll.attribute && abilities[roll.attribute] ? `data-attribute="${roll.attribute}"` : ''} ${roll.trait && abilities[roll.trait] ? `data-trait="${roll.trait}"` : ''}
${roll.advantage ? 'data-advantage="true"' : ''} ${roll.advantage ? 'data-advantage="true"' : ''}
${roll.disadvantage ? 'data-disadvantage="true"' : ''} ${roll.disadvantage ? 'data-disadvantage="true"' : ''}
> >