Merged with data-models-structure branch

This commit is contained in:
WBHarry 2025-06-13 13:45:52 +02:00
commit d1c968d0a2
62 changed files with 1760 additions and 956 deletions

View file

@ -135,43 +135,24 @@ Hooks.on(socketEvent.GMUpdate, async (action, uuid, update) => {
});
const renderDualityButton = async event => {
const button = event.currentTarget;
const attributeValue = button.dataset.attribute?.toLowerCase();
const target = getCommandTarget();
const button = event.currentTarget,
traitValue = button.dataset.trait?.toLowerCase(),
target = getCommandTarget();
if (!target) return;
const rollModifier = attributeValue ? target.system.attributes[attributeValue].data.value : null;
const { roll, hope, fear, advantage, disadvantage, modifiers } = await target.diceRoll({
title: button.dataset.label,
value: rollModifier
});
const systemData = new DHDualityRoll({
title: button.dataset.label,
origin: target.id,
roll: roll._formula,
modifiers: modifiers,
hope: hope,
fear: fear,
advantage: advantage,
disadvantage: disadvantage
});
const cls = getDocumentClass('ChatMessage');
const msgData = {
type: 'dualityRoll',
sound: CONFIG.sounds.dice,
system: systemData,
user: game.user.id,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/duality-roll.hbs',
systemData
),
rolls: [roll]
const config = {
event: event,
title: button.dataset.title,
roll: {
modifier: traitValue ? target.system.traits[traitValue].value : null,
label: button.dataset.label,
type: button.dataset.actionType ?? null // Need check
},
chatMessage: {
template: 'systems/daggerheart/templates/chat/duality-roll.hbs'
}
};
await cls.create(msgData);
await target.diceRoll(config);
};
Hooks.on('renderChatMessageHTML', (_, element) => {
@ -200,64 +181,54 @@ Hooks.on('chatMessage', (_, message) => {
return false;
}
const attributeValue = rollCommand.attribute?.toLowerCase();
const traitValue = rollCommand.trait?.toLowerCase();
const advantageState = rollCommand.advantage ? true : rollCommand.disadvantage ? false : null;
// Target not required if an attribute is not used.
const target = attributeValue ? getCommandTarget() : undefined;
if (target || !attributeValue) {
const target = traitValue ? getCommandTarget() : undefined;
if (target || !traitValue) {
new Promise(async (resolve, reject) => {
const attribute = target ? target.system.attributes[attributeValue] : undefined;
if (attributeValue && !attribute) {
const trait = target ? target.system.traits[traitValue] : undefined;
if (traitValue && !trait) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.Notification.Error.AttributeFaulty'));
reject();
return;
}
const title = attributeValue
const title = traitValue
? game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', {
ability: game.i18n.localize(abilities[attributeValue].label)
ability: game.i18n.localize(abilities[traitValue].label)
})
: game.i18n.localize('DAGGERHEART.General.Duality');
const hopeAndFearRoll = `1${rollCommand.hope ?? 'd12'}+1${rollCommand.fear ?? 'd12'}`;
const advantageRoll = `${rollCommand.advantage && !rollCommand.disadvantage ? '+d6' : rollCommand.disadvantage && !rollCommand.advantage ? '-d6' : ''}`;
const attributeRoll = `${attribute?.data?.value ? `${attribute.data.value > 0 ? `+${attribute.data.value}` : `${attribute.data.value}`}` : ''}`;
const roll = new Roll(`${hopeAndFearRoll}${advantageRoll}${attributeRoll}`);
await roll.evaluate();
const advantageRoll = `${advantageState === true ? '+d6' : advantageState === false ? '-d6' : ''}`;
const attributeRoll = `${trait?.value ? `${trait.value > 0 ? `+${trait.value}` : `${trait.value}`}` : ''}`;
const roll = await Roll.create(`${hopeAndFearRoll}${advantageRoll}${attributeRoll}`).evaluate();
setDiceSoNiceForDualityRoll(
roll,
rollCommand.advantage && !rollCommand.disadvantage,
rollCommand.disadvantage && !rollCommand.advantage
);
setDiceSoNiceForDualityRoll(roll, advantageState);
resolve({
roll,
attribute: attribute
trait: trait
? {
value: attribute.data.value,
label: `${game.i18n.localize(abilities[attributeValue].label)} ${attribute.data.value >= 0 ? `+` : ``}${attribute.data.value}`
value: trait.value,
label: `${game.i18n.localize(abilities[traitValue].label)} ${trait.value >= 0 ? `+` : ``}${trait.value}`
}
: undefined,
title
});
}).then(async ({ roll, attribute, title }) => {
}).then(async ({ roll, trait, title }) => {
const cls = getDocumentClass('ChatMessage');
const systemData = new DHDualityRoll({
title: title,
origin: target?.id,
roll: roll._formula,
modifiers: attribute ? [attribute] : [],
roll: roll,
modifiers: trait ? [trait] : [],
hope: { dice: rollCommand.hope ?? 'd12', value: roll.dice[0].total },
fear: { dice: rollCommand.fear ?? 'd12', value: roll.dice[1].total },
advantage:
rollCommand.advantage && !rollCommand.disadvantage
? { dice: 'd6', value: roll.dice[2].total }
: undefined,
disadvantage:
rollCommand.disadvantage && !rollCommand.advantage
? { dice: 'd6', value: roll.dice[2].total }
: undefined
advantage: advantageState !== null ? { dice: 'd6', value: roll.dice[2].total } : undefined,
advantageState
});
const msgData = {
@ -265,10 +236,7 @@ Hooks.on('chatMessage', (_, message) => {
sound: CONFIG.sounds.dice,
system: systemData,
user: game.user.id,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/duality-roll.hbs',
systemData
),
content: 'systems/daggerheart/templates/chat/duality-roll.hbs',
rolls: [roll]
};
@ -302,6 +270,15 @@ const preloadHandlebarsTemplates = async function () {
'systems/daggerheart/templates/components/card-preview.hbs',
'systems/daggerheart/templates/views/levelup/parts/selectable-card-preview.hbs',
'systems/daggerheart/templates/sheets/global/partials/feature-section-item.hbs',
'systems/daggerheart/templates/ui/combat/combatTrackerSection.hbs'
'systems/daggerheart/templates/ui/combat/combatTrackerSection.hbs',
'systems/daggerheart/templates/views/actionTypes/damage.hbs',
'systems/daggerheart/templates/views/actionTypes/healing.hbs',
'systems/daggerheart/templates/views/actionTypes/resource.hbs',
'systems/daggerheart/templates/views/actionTypes/uuid.hbs',
'systems/daggerheart/templates/views/actionTypes/uses.hbs',
'systems/daggerheart/templates/views/actionTypes/roll.hbs',
'systems/daggerheart/templates/views/actionTypes/cost.hbs',
'systems/daggerheart/templates/views/actionTypes/range-target.hbs',
'systems/daggerheart/templates/views/actionTypes/effect.hbs'
]);
};