From fa277d288882e885ef88a89e86b8a91fa464e6b7 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Tue, 3 Mar 2026 21:31:43 +0100 Subject: [PATCH] Fixed reroll --- module/applications/dialogs/tagTeamDialog.mjs | 30 ++++++++++++++- .../applications/sheets/actors/character.mjs | 4 +- module/applications/ui/chatLog.mjs | 6 ++- module/data/tagTeamData.mjs | 38 ++++++++++--------- module/dice/dhRoll.mjs | 3 +- module/dice/dualityRoll.mjs | 32 ++++++++-------- styles/less/dialog/tag-team-dialog/sheet.less | 3 +- .../dialogs/tagTeamDialog/tagTeamRoll.hbs | 12 +++--- 8 files changed, 83 insertions(+), 45 deletions(-) diff --git a/module/applications/dialogs/tagTeamDialog.mjs b/module/applications/dialogs/tagTeamDialog.mjs index 25016127..9c76302a 100644 --- a/module/applications/dialogs/tagTeamDialog.mjs +++ b/module/applications/dialogs/tagTeamDialog.mjs @@ -33,7 +33,8 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio toggleSelectMember: TagTeamDialog.#toggleSelectMember, startTagTeamRoll: TagTeamDialog.#startTagTeamRoll, makeRoll: TagTeamDialog.#makeRoll, - removeRoll: TagTeamDialog.#removeRoll + removeRoll: TagTeamDialog.#removeRoll, + rerollDice: TagTeamDialog.#rerollDice }, form: { handler: this.updateData, submitOnChange: true, closeOnSubmit: false } }; @@ -105,6 +106,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio acc[actorId] = { ...data, + key: actorId, readyToRoll: Boolean(data.rollChoice), hasRolled: Boolean(data.rollData), rollOptions @@ -192,6 +194,8 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio if (!result) return; + if (!game.modules.get('dice-so-nice')?.active) foundry.audio.AudioHelper.play({ src: CONFIG.sounds.dice }); + const rollData = result.messageRoll.toJSON(); delete rollData.options.messageRoll; await this.party.update({ @@ -230,5 +234,29 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio }); } + static async #rerollDice(_, button) { + const { member, diceType } = button.dataset; + const memberData = this.party.system.tagTeam.members[member]; + + const dieIndex = diceType === 'hope' ? 0 : diceType === 'fear' ? 2 : 4; + + const { parsedRoll, newRoll } = await game.system.api.dice.DualityRoll.reroll( + memberData.rollData, + dieIndex, + diceType + ); + const rollData = parsedRoll.toJSON(); + await this.party.update({ + [`system.tagTeam.members.${member}.rollData`]: { + ...rollData, + options: { + ...rollData.options, + roll: newRoll + } + } + }); + this.render(); + } + //#endregion } diff --git a/module/applications/sheets/actors/character.mjs b/module/applications/sheets/actors/character.mjs index 74d3af0b..8cddd948 100644 --- a/module/applications/sheets/actors/character.mjs +++ b/module/applications/sheets/actors/character.mjs @@ -717,8 +717,8 @@ export default class CharacterSheet extends DHBaseActorSheet { const costResources = result.costs?.filter(x => x.enabled).map(cost => ({ ...cost, value: -cost.value, total: -cost.total })) || {}; - config.resourceUpdates.addResources(costResources); - await config.resourceUpdates.updateResources(); + result.resourceUpdates.addResources(costResources); + await result.resourceUpdates.updateResources(); } //TODO: redo toggleEquipItem method diff --git a/module/applications/ui/chatLog.mjs b/module/applications/ui/chatLog.mjs index 2b489f58..7367c222 100644 --- a/module/applications/ui/chatLog.mjs +++ b/module/applications/ui/chatLog.mjs @@ -204,7 +204,11 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo if (!game.modules.get('dice-so-nice')?.active) foundry.audio.AudioHelper.play({ src: CONFIG.sounds.dice }); - const { newRoll, parsedRoll } = await rollClass.reroll(originalRoll_parsed, target, message); + const { newRoll, parsedRoll } = await rollClass.reroll( + originalRoll_parsed, + target.dataset.dieIndex, + target.dataset.type + ); await game.messages.get(message._id).update({ 'system.roll': newRoll, diff --git a/module/data/tagTeamData.mjs b/module/data/tagTeamData.mjs index d37e7b97..e7e32ad7 100644 --- a/module/data/tagTeamData.mjs +++ b/module/data/tagTeamData.mjs @@ -3,26 +3,30 @@ export default class TagTeamData extends foundry.abstract.DataModel { const fields = foundry.data.fields; return { - members: new fields.TypedObjectField( - new fields.SchemaField({ - name: new fields.StringField({ required: true }), - img: new fields.StringField({ required: true }), - rollType: new fields.StringField({ - required: true, - choices: CONFIG.DH.GENERAL.tagTeamRollTypes, - initial: CONFIG.DH.GENERAL.tagTeamRollTypes.trait.id, - label: 'Roll Type' - }), - rollChoice: new fields.StringField({ nullable: true, initial: null }), - rollData: new fields.JSONField({ nullable: true, initial: null }) - }) - ) + members: new fields.TypedObjectField(new fields.EmbeddedDataField(MemberData)) + }; + } +} + +class MemberData extends foundry.abstract.DataModel { + static defineSchema() { + const fields = foundry.data.fields; + + return { + name: new fields.StringField({ required: true }), + img: new fields.StringField({ required: true }), + rollType: new fields.StringField({ + required: true, + choices: CONFIG.DH.GENERAL.tagTeamRollTypes, + initial: CONFIG.DH.GENERAL.tagTeamRollTypes.trait.id, + label: 'Roll Type' + }), + rollChoice: new fields.StringField({ nullable: true, initial: null }), + rollData: new fields.JSONField({ nullable: true, initial: null }) }; } get roll() { - const roll = CONFIG.Dice.daggerheart.DualityRoll(JSON.parse(this.rollData)); - - return this.rollData ? CONFIG.Dice.daggerheart.DualityRoll(JSON.parse(this.rollData)) : null; + return this.rollData ? CONFIG.Dice.daggerheart.DualityRoll.fromData(this.rollData) : null; } } diff --git a/module/dice/dhRoll.mjs b/module/dice/dhRoll.mjs index 465c5557..05ebe81f 100644 --- a/module/dice/dhRoll.mjs +++ b/module/dice/dhRoll.mjs @@ -22,7 +22,8 @@ export default class DHRoll extends Roll { const roll = await this.buildConfigure(config, message); if (!roll) return; - config.messageRoll = roll; + if (config.skips?.createMessage) config.messageRoll = roll; + await this.buildEvaluate(roll, config, (message = {})); await this.buildPost(roll, config, (message = {})); return config; diff --git a/module/dice/dualityRoll.mjs b/module/dice/dualityRoll.mjs index cafe0cff..6433ab94 100644 --- a/module/dice/dualityRoll.mjs +++ b/module/dice/dualityRoll.mjs @@ -374,9 +374,9 @@ export default class DualityRoll extends D20Roll { } } - static async reroll(rollString, target, message) { - let parsedRoll = game.system.api.dice.DualityRoll.fromData({ ...rollString, evaluated: false }); - const term = parsedRoll.terms[target.dataset.dieIndex]; + static async reroll(rollBase, dieIndex, diceType) { + let parsedRoll = game.system.api.dice.DualityRoll.fromData({ ...rollBase, evaluated: false }); + const term = parsedRoll.terms[dieIndex]; await term.reroll(`/r1=${term.total}`); if (game.modules.get('dice-so-nice')?.active) { const diceSoNiceRoll = { @@ -392,36 +392,36 @@ export default class DualityRoll extends D20Roll { }; const diceSoNicePresets = await getDiceSoNicePresets(`d${term._faces}`, `d${term._faces}`); - const type = target.dataset.type; - if (diceSoNicePresets[type]) { - diceSoNiceRoll.dice[0].options = diceSoNicePresets[type]; + if (diceSoNicePresets[diceType]) { + diceSoNiceRoll.dice[0].options = diceSoNicePresets[diceType]; } await game.dice3d.showForRoll(diceSoNiceRoll, game.user, true); + } else { + foundry.audio.AudioHelper.play({ src: CONFIG.sounds.dice }); } await parsedRoll.evaluate(); const newRoll = game.system.api.dice.DualityRoll.postEvaluate(parsedRoll, { - targets: message.system.targets, + targets: parsedRoll.options.targets ?? [], roll: { - advantage: message.system.roll.advantage?.type, - difficulty: message.system.roll.difficulty ? Number(message.system.roll.difficulty) : null + advantage: parsedRoll.options.roll.advantage?.type, + difficulty: parsedRoll.options.roll.difficulty ? Number(parsedRoll.options.roll.difficulty) : null } }); const extraIndex = newRoll.advantage ? 3 : 2; newRoll.extra = newRoll.extra.slice(extraIndex); - const tagTeamSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.TagTeamRoll); - - const actor = message.system.source.actor ? await foundry.utils.fromUuid(message.system.source.actor) : null; + const actor = parsedRoll.options.source.actor + ? await foundry.utils.fromUuid(parsedRoll.options.source.actor) + : null; const config = { - source: { actor: message.system.source.actor ?? '' }, - targets: message.system.targets, - tagTeamSelected: Object.values(tagTeamSettings.members).some(x => x.messageId === message._id), + source: { actor: parsedRoll.options.source.actor ?? '' }, + targets: parsedRoll.targets, roll: newRoll, - rerolledRoll: message.system.roll, + rerolledRoll: parsedRoll.roll, resourceUpdates: new ResourceUpdateMap(actor) }; diff --git a/styles/less/dialog/tag-team-dialog/sheet.less b/styles/less/dialog/tag-team-dialog/sheet.less index af035d7b..06db0335 100644 --- a/styles/less/dialog/tag-team-dialog/sheet.less +++ b/styles/less/dialog/tag-team-dialog/sheet.less @@ -69,6 +69,7 @@ .roll-data { display: flex; flex-direction: column; + align-items: center; gap: 4px; &.hope { @@ -88,7 +89,7 @@ .duality-label { color: var(--text-color); - font-size: var(--font-size-24); + font-size: var(--font-size-20); font-weight: bold; text-align: center; } diff --git a/templates/dialogs/tagTeamDialog/tagTeamRoll.hbs b/templates/dialogs/tagTeamDialog/tagTeamRoll.hbs index 5a288384..e5931a08 100644 --- a/templates/dialogs/tagTeamDialog/tagTeamRoll.hbs +++ b/templates/dialogs/tagTeamDialog/tagTeamRoll.hbs @@ -51,19 +51,19 @@
-
{{localize "DAGGERHEART.GENERAL.withThing" thing=this.result.label}}
+
{{this.total}} {{localize "DAGGERHEART.GENERAL.withThing" thing=this.result.label}}
-
{{../rollData.formula}}
+
{{this.formula}}
{{/with}} {{/if}}