mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 15:39:02 +01:00
Fixed /dr chat command
This commit is contained in:
parent
2616ff59be
commit
1996d2a4cc
2 changed files with 55 additions and 49 deletions
|
|
@ -8,7 +8,7 @@ import { getCommandTarget, rollCommandToJSON } from './module/helpers/utils.mjs'
|
||||||
import { NarrativeCountdowns } from './module/applications/ui/countdowns.mjs';
|
import { NarrativeCountdowns } from './module/applications/ui/countdowns.mjs';
|
||||||
import { DualityRollColor } from './module/data/settings/Appearance.mjs';
|
import { DualityRollColor } from './module/data/settings/Appearance.mjs';
|
||||||
import { DHRoll, DualityRoll, D20Roll, DamageRoll, DualityDie } from './module/dice/_module.mjs';
|
import { DHRoll, DualityRoll, D20Roll, DamageRoll, DualityDie } from './module/dice/_module.mjs';
|
||||||
import { renderDualityButton } from './module/enrichers/DualityRollEnricher.mjs';
|
import { enrichedDualityRoll, renderDualityButton } from './module/enrichers/DualityRollEnricher.mjs';
|
||||||
import { renderMeasuredTemplate } from './module/enrichers/TemplateEnricher.mjs';
|
import { renderMeasuredTemplate } from './module/enrichers/TemplateEnricher.mjs';
|
||||||
import { registerCountdownHooks } from './module/data/countdowns.mjs';
|
import { registerCountdownHooks } from './module/data/countdowns.mjs';
|
||||||
import {
|
import {
|
||||||
|
|
@ -216,49 +216,21 @@ Hooks.on('chatMessage', (_, message) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const traitValue = rollCommand.trait?.toLowerCase();
|
const traitValue = rollCommand.trait?.toLowerCase();
|
||||||
const advantageState = rollCommand.advantage ? true : rollCommand.disadvantage ? false : null;
|
const advantage = rollCommand.advantage
|
||||||
|
? CONFIG.DH.ACTIONS.advandtageState.advantage.value
|
||||||
|
: rollCommand.disadvantage
|
||||||
|
? CONFIG.DH.ACTIONS.advandtageState.disadvantage.value
|
||||||
|
: undefined;
|
||||||
|
const difficulty = rollCommand.difficulty;
|
||||||
|
|
||||||
// Target not required if an attribute is not used.
|
const target = getCommandTarget();
|
||||||
const target = traitValue ? getCommandTarget() : undefined;
|
const title = traitValue
|
||||||
if (target || !traitValue) {
|
? game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilityCheckTitle', {
|
||||||
new Promise(async (resolve, reject) => {
|
ability: game.i18n.localize(SYSTEM.ACTOR.abilities[traitValue].label)
|
||||||
const trait = target ? target.system.traits[traitValue] : undefined;
|
})
|
||||||
if (traitValue && !trait) {
|
: game.i18n.localize('DAGGERHEART.GENERAL.duality');
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.attributeFaulty'));
|
|
||||||
reject();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const title = traitValue
|
|
||||||
? game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilityCheckTitle', {
|
|
||||||
ability: game.i18n.localize(SYSTEM.ACTOR.abilities[traitValue].label)
|
|
||||||
})
|
|
||||||
: game.i18n.localize('DAGGERHEART.GENERAL.duality');
|
|
||||||
|
|
||||||
const config = {
|
|
||||||
title: title,
|
|
||||||
roll: {
|
|
||||||
trait: traitValue
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
traits: {
|
|
||||||
[traitValue]: trait
|
|
||||||
}
|
|
||||||
},
|
|
||||||
source: target,
|
|
||||||
hasSave: false,
|
|
||||||
dialog: { configure: false },
|
|
||||||
evaluate: true,
|
|
||||||
advantage: rollCommand.advantage == true,
|
|
||||||
disadvantage: rollCommand.disadvantage == true
|
|
||||||
};
|
|
||||||
|
|
||||||
await CONFIG.Dice.daggerheart['DualityRoll'].build(config);
|
|
||||||
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
enrichedDualityRoll({ traitValue, target, difficulty, title, label: 'test', actionType: null, advantage });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,18 @@ export function getDualityMessage(roll) {
|
||||||
? 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');
|
||||||
|
|
||||||
|
const advantage = roll.advantage
|
||||||
|
? CONFIG.DH.ACTIONS.advandtageState.advantage.value
|
||||||
|
: roll.disadvantage
|
||||||
|
? CONFIG.DH.ACTIONS.advandtageState.disadvantage.value
|
||||||
|
: undefined;
|
||||||
|
const advantageLabel =
|
||||||
|
advantage === CONFIG.DH.ACTIONS.advandtageState.advantage.value
|
||||||
|
? 'Advantage'
|
||||||
|
: advantage === CONFIG.DH.ACTIONS.advandtageState.disadvantage.value
|
||||||
|
? 'Disadvantage'
|
||||||
|
: undefined;
|
||||||
|
|
||||||
const dualityElement = document.createElement('span');
|
const dualityElement = document.createElement('span');
|
||||||
dualityElement.innerHTML = `
|
dualityElement.innerHTML = `
|
||||||
<button class="duality-roll-button"
|
<button class="duality-roll-button"
|
||||||
|
|
@ -28,14 +40,15 @@ export function getDualityMessage(roll) {
|
||||||
data-label="${dataLabel}"
|
data-label="${dataLabel}"
|
||||||
data-hope="${roll.hope ?? 'd12'}"
|
data-hope="${roll.hope ?? 'd12'}"
|
||||||
data-fear="${roll.fear ?? 'd12'}"
|
data-fear="${roll.fear ?? 'd12'}"
|
||||||
${roll.difficulty ? `data-difficulty="${roll.difficulty}"` : ''}
|
${advantage ? `data-advantage="${advantage}"` : ''}
|
||||||
|
${roll.difficulty !== undefined ? `data-difficulty="${roll.difficulty}"` : ''}
|
||||||
${roll.trait && abilities[roll.trait] ? `data-trait="${roll.trait}"` : ''}
|
${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"' : ''}
|
||||||
>
|
>
|
||||||
<i class="fa-solid fa-circle-half-stroke"></i>
|
<i class="fa-solid fa-circle-half-stroke"></i>
|
||||||
${label}
|
${label}
|
||||||
${roll.difficulty ? `(${roll.difficulty})` : ''}
|
${roll.difficulty || advantageLabel ? `(${[roll.difficulty, game.i18n.localize(`DAGGERHEART.GENERAL.${advantageLabel}.short`)].filter(x => x).join(' ')})` : ''}
|
||||||
</button>
|
</button>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
@ -46,17 +59,38 @@ export const renderDualityButton = async event => {
|
||||||
const button = event.currentTarget,
|
const button = event.currentTarget,
|
||||||
traitValue = button.dataset.trait?.toLowerCase(),
|
traitValue = button.dataset.trait?.toLowerCase(),
|
||||||
target = getCommandTarget(),
|
target = getCommandTarget(),
|
||||||
difficulty = button.dataset.difficulty;
|
difficulty = button.dataset.difficulty,
|
||||||
|
advantage = button.dataset.advantage ? Number(button.dataset.advantage) : undefined;
|
||||||
|
|
||||||
|
await enrichedDualityRoll(
|
||||||
|
{
|
||||||
|
traitValue,
|
||||||
|
target,
|
||||||
|
difficulty,
|
||||||
|
title: button.dataset.title,
|
||||||
|
label: button.dataset.label,
|
||||||
|
actionType: button.dataset.actionType,
|
||||||
|
advantage
|
||||||
|
},
|
||||||
|
event
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const enrichedDualityRoll = async (
|
||||||
|
{ traitValue, target, difficulty, title, label, actionType, advantage },
|
||||||
|
event
|
||||||
|
) => {
|
||||||
if (!target) return;
|
if (!target) return;
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
event: event,
|
event: event ?? {},
|
||||||
title: button.dataset.title,
|
title: title,
|
||||||
roll: {
|
roll: {
|
||||||
modifier: traitValue ? target.system.traits[traitValue].value : null,
|
modifier: traitValue ? target.system.traits[traitValue].value : null,
|
||||||
label: button.dataset.label,
|
label: label,
|
||||||
difficulty: difficulty,
|
difficulty: difficulty,
|
||||||
type: button.dataset.actionType ?? null // Need check
|
advantage,
|
||||||
|
type: actionType ?? null // Need check,
|
||||||
},
|
},
|
||||||
chatMessage: {
|
chatMessage: {
|
||||||
template: 'systems/daggerheart/templates/ui/chat/duality-roll.hbs'
|
template: 'systems/daggerheart/templates/ui/chat/duality-roll.hbs'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue