Corrected Duality rolling from Character

This commit is contained in:
WBHarry 2025-06-08 12:08:13 +02:00
parent 1445baa556
commit 5e0ab9458d
4 changed files with 49 additions and 46 deletions

View file

@ -13,6 +13,7 @@ import { dualityRollEnricher } from './module/enrichers/DualityRollEnricher.mjs'
import { getCommandTarget, rollCommandToJSON, setDiceSoNiceForDualityRoll } from './module/helpers/utils.mjs'; import { getCommandTarget, rollCommandToJSON, setDiceSoNiceForDualityRoll } from './module/helpers/utils.mjs';
import { abilities } from './module/config/actorConfig.mjs'; import { abilities } from './module/config/actorConfig.mjs';
import Resources from './module/applications/resources.mjs'; import Resources from './module/applications/resources.mjs';
import DHDualityRoll from './module/data/chat-message/dualityRoll.mjs';
globalThis.SYSTEM = SYSTEM; globalThis.SYSTEM = SYSTEM;
@ -137,22 +138,28 @@ const renderDualityButton = async event => {
title: button.dataset.label, title: button.dataset.label,
value: rollModifier 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 cls = getDocumentClass('ChatMessage');
const msgData = { const msgData = {
type: 'dualityRoll', type: 'dualityRoll',
sound: CONFIG.sounds.dice, sound: CONFIG.sounds.dice,
system: { system: systemData,
title: button.dataset.label,
origin: target.id,
roll: roll._formula,
modifiers: modifiers,
hope: hope,
fear: fear,
advantage: advantage,
disadvantage: disadvantage
},
user: game.user.id, user: game.user.id,
content: 'systems/daggerheart/templates/chat/duality-roll.hbs', content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/duality-roll.hbs',
systemData
),
rolls: [roll] rolls: [roll]
}; };
@ -226,29 +233,34 @@ Hooks.on('chatMessage', (_, message) => {
: undefined, : undefined,
title title
}); });
}).then(({ roll, attribute, title }) => { }).then(async ({ roll, attribute, title }) => {
const cls = getDocumentClass('ChatMessage'); const cls = getDocumentClass('ChatMessage');
const systemData = new DHDualityRoll({
title: title,
origin: target?.id,
roll: roll._formula,
modifiers: attribute ? [attribute] : [],
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
});
const msgData = { const msgData = {
type: 'dualityRoll', type: 'dualityRoll',
sound: CONFIG.sounds.dice, sound: CONFIG.sounds.dice,
system: { system: systemData,
title: title,
origin: target?.id,
roll: roll._formula,
modifiers: attribute ? [attribute] : [],
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
},
user: game.user.id, user: game.user.id,
content: 'systems/daggerheart/templates/chat/duality-roll.hbs', content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/duality-roll.hbs',
systemData
),
rolls: [roll] rolls: [roll]
}; };

View file

@ -1,12 +1,8 @@
import { DualityRollColor } from '../data/settings/Appearance.mjs'; import { DualityRollColor } from '../data/settings/Appearance.mjs';
import DHDualityRoll from "../data/chat-message/dualityRoll.mjs"; import DHDualityRoll from '../data/chat-message/dualityRoll.mjs';
export default class DhpChatMessage extends foundry.documents.ChatMessage { export default class DhpChatMessage extends foundry.documents.ChatMessage {
async renderHTML() { async renderHTML() {
if (this.type === 'dualityRoll' || this.type === 'adversaryRoll' || this.type === 'abilityUse') {
this.content = await foundry.applications.handlebars.renderTemplate(this.content, this.system);
}
/* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */ /* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */
const html = await super.renderHTML(); const html = await super.renderHTML();

View file

@ -62,12 +62,8 @@ export default class RollSelectionDialog extends HandlebarsApplicationMixin(Appl
context.fear = this.data.fear; context.fear = this.data.fear;
context.advantage = this.data.advantage; context.advantage = this.data.advantage;
context.disadvantage = this.data.disadvantage; context.disadvantage = this.data.disadvantage;
context.experiences = this.experiences.map(x => ({ context.experiences = Object.keys(this.experiences).map(id => ({ id, ...this.experiences[id] }));
...x,
selected: this.selectedExperiences.includes(x.id)
}));
context.hopeResource = this.data.hopeResource + 1; context.hopeResource = this.data.hopeResource + 1;
context.hopeUsed = this.getHopeUsed();
return context; return context;
} }

View file

@ -5,6 +5,7 @@ import AncestrySelectionDialog from '../ancestrySelectionDialog.mjs';
import DaggerheartSheet from './daggerheart-sheet.mjs'; import DaggerheartSheet from './daggerheart-sheet.mjs';
import { abilities } from '../../config/actorConfig.mjs'; import { abilities } from '../../config/actorConfig.mjs';
import DhlevelUp from '../levelup.mjs'; import DhlevelUp from '../levelup.mjs';
import DHDualityRoll from '../../data/chat-message/dualityRoll.mjs';
const { ActorSheetV2 } = foundry.applications.sheets; const { ActorSheetV2 } = foundry.applications.sheets;
const { TextEditor } = foundry.applications.ux; const { TextEditor } = foundry.applications.ux;
@ -286,7 +287,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
const cls = getDocumentClass('ChatMessage'); const cls = getDocumentClass('ChatMessage');
const systemContent = { const systemContent = new DHDualityRoll({
title: game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', { title: game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', {
ability: game.i18n.localize(abilities[button.dataset.attribute].label) ability: game.i18n.localize(abilities[button.dataset.attribute].label)
}), }),
@ -297,9 +298,9 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
fear: fear, fear: fear,
advantage: advantage, advantage: advantage,
disadvantage: disadvantage disadvantage: disadvantage
}; });
const msg = new cls({ await cls.create({
type: 'dualityRoll', type: 'dualityRoll',
sound: CONFIG.sounds.dice, sound: CONFIG.sounds.dice,
system: systemContent, system: systemContent,
@ -310,8 +311,6 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
), ),
rolls: [roll] rolls: [roll]
}); });
await cls.create(msg.toObject());
} }
static async toggleMarks(_, button) { static async toggleMarks(_, button) {
@ -368,7 +367,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
evasion: x.actor.system.evasion evasion: x.actor.system.evasion
})); }));
const systemData = { const systemData = new DHDualityRoll({
title: weapon.name, title: weapon.name,
origin: this.document.id, origin: this.document.id,
roll: roll._formula, roll: roll._formula,
@ -379,7 +378,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
disadvantage: disadvantage, disadvantage: disadvantage,
damage: damage, damage: damage,
targets: targets targets: targets
}; });
const cls = getDocumentClass('ChatMessage'); const cls = getDocumentClass('ChatMessage');
const msg = new cls({ const msg = new cls({