From 9e771059f1d0c8e26c70f3085e4566f6e902fdf2 Mon Sep 17 00:00:00 2001 From: Dapoolp Date: Sun, 27 Jul 2025 12:39:47 +0200 Subject: [PATCH] g --- .../dialogs/reactionRollDialog.mjs | 9 ++-- module/applications/ui/chatLog.mjs | 50 +++++++++++++++++-- module/data/action/baseAction.mjs | 32 ++++++++---- module/documents/actor.mjs | 12 +++-- module/systemRegistration/socket.mjs | 13 ++++- 5 files changed, 95 insertions(+), 21 deletions(-) diff --git a/module/applications/dialogs/reactionRollDialog.mjs b/module/applications/dialogs/reactionRollDialog.mjs index b1765317..658ab810 100644 --- a/module/applications/dialogs/reactionRollDialog.mjs +++ b/module/applications/dialogs/reactionRollDialog.mjs @@ -57,11 +57,12 @@ export default class ReactionRollDialog extends HandlebarsApplicationMixin(Appli this.render(true); } - static async reactionRollQuery({ actorId, trait }) { + static async reactionRollQuery({ action, token, event, message }) { return new Promise(async (resolve, reject) => { - const actor = await fromUuid(actorId); - if (!actor || !actor?.isOwner) reject(); - new ReactionRollDialog(resolve, reject, actor, trait).render({ force: true }); + // const actor = await fromUuid(actorId); + // if (!actor || !actor?.isOwner) reject(); + action.rollSave(token, event, message).then(result => resolve(result)); + // new ReactionRollDialog(resolve, reject, actor, trait).render({ force: true }); }); } diff --git a/module/applications/ui/chatLog.mjs b/module/applications/ui/chatLog.mjs index 2547a47c..8455ea49 100644 --- a/module/applications/ui/chatLog.mjs +++ b/module/applications/ui/chatLog.mjs @@ -112,11 +112,55 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo if (message.system.source.item && message.system.source.action) { const action = this.getAction(actor, message.system.source.item, message.system.source.action); if (!action || !action?.hasSave) return; - action.rollSave(token, event, message); + action.rollSave(token.actor, event, message).then(result => action.updateSaveMessage(result, message, token.id)); } } - onRollAllSave(event, _message) { + async onRollAllSave(event, message) { + event.stopPropagation(); + if(!game.user.isGM) return; + const targets = event.target.parentElement.querySelectorAll( + '.target-section > [data-token] .target-save-container' + ); + const promises = [], + actor = await this.getActor(message.system.source.actor), + action = this.getAction(actor, message.system.source.item, message.system.source.action); + targets.forEach(async el => { + const tokenId = el.closest('[data-token]')?.dataset.token, + token = game.canvas.tokens.get(tokenId); + if(!token.actor) return; + if(game.user === token.actor.owner) { + el.dispatchEvent(new PointerEvent('click', { shiftKey: true })); + } else { + // console.log(action, + // token, + // event, + // message) + const reactionRoll = await token.actor.owner.query('reactionRoll', { + actionId: action.uuid, + actorId: token.actor.uuid, + event, + message + }); + if(reactionRoll) { + console.log(reactionRoll) + } + // const armorStackResult = await token.actor.owner.query('armorStack', { + // actorId: token.actor.uuid, + // damage: 3, + // type: ['physical'] + // }, + // { + // timeout: 30000 + // } + // ); + } + + // el.dispatchEvent(new PointerEvent('click', { shiftKey: true })); + }); + } + + /* onRollAllSave(event, _message) { event.stopPropagation(); const targets = event.target.parentElement.querySelectorAll( '.target-section > [data-token] .target-save-container' @@ -124,7 +168,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo targets.forEach(el => { el.dispatchEvent(new PointerEvent('click', { shiftKey: true })); }); - } + } */ async onApplyEffect(event, message) { event.stopPropagation(); diff --git a/module/data/action/baseAction.mjs b/module/data/action/baseAction.mjs index 89d0caeb..f1f46eed 100644 --- a/module/data/action/baseAction.mjs +++ b/module/data/action/baseAction.mjs @@ -297,9 +297,9 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel /* EFFECTS */ /* SAVE */ - async rollSave(target, event, message) { - if (!target?.actor) return; - return target.actor + async rollSave(actor, event, message) { + if (!actor) return; + return actor .diceRoll({ event, title: 'Roll Save', @@ -308,15 +308,29 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel difficulty: this.save.difficulty, type: 'reaction' }, - data: target.actor.getRollData() + data: actor.getRollData() }) - .then(async result => { - if (result) - this.updateChatMessage(message, target.id, { + /* .then(async result => { + if (result) { + const updateMsg = this.updateChatMessage.bind(this, message, target.id, { result: result.roll.total, success: result.roll.success }); - }); + if (game.modules.get('dice-so-nice')?.active) + game.dice3d.waitFor3DAnimationByMessageID(result.message.id).then(()=> updateMsg()); + else updateMsg(); + } + }) */; + } + + updateSaveMessage(result, message, targetId) { + const updateMsg = this.updateChatMessage.bind(this, message, targetId, { + result: result.roll.total, + success: result.roll.success + }); + if (game.modules.get('dice-so-nice')?.active) + game.dice3d.waitFor3DAnimationByMessageID(result.message.id).then(()=> updateMsg()); + else updateMsg(); } /* SAVE */ @@ -331,7 +345,7 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel if (chain) { if (message.system.source.message) this.updateChatMessage(ui.chat.collection.get(message.system.source.message), targetId, changes, false); - const relatedChatMessages = ui.chat.collection.filter(c => c.system.source.message === message._id); + const relatedChatMessages = ui.chat.collection.filter(c => c.system.source?.message === message._id); relatedChatMessages.forEach(c => { this.updateChatMessage(c, targetId, changes, false); }); diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index caee8d23..2a1477b4 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -443,10 +443,14 @@ export default class DhpActor extends Actor { this.#canReduceDamage(hpDamage.value, hpDamage.damageTypes) ) { const armorStackResult = await this.owner.query('armorStack', { - actorId: this.uuid, - damage: hpDamage.value, - type: [...hpDamage.damageTypes] - }); + actorId: this.uuid, + damage: hpDamage.value, + type: [...hpDamage.damageTypes] + }, + { + timeout: 30000 + } + ); if (armorStackResult) { const { modifiedDamage, armorSpent, stressSpent } = armorStackResult; updates.find(u => u.key === 'hitPoints').value = modifiedDamage; diff --git a/module/systemRegistration/socket.mjs b/module/systemRegistration/socket.mjs index d23ff8a7..914ea938 100644 --- a/module/systemRegistration/socket.mjs +++ b/module/systemRegistration/socket.mjs @@ -74,7 +74,18 @@ export const registerSocketHooks = () => { export const registerUserQueries = () => { CONFIG.queries.armorStack = DamageReductionDialog.armorStackQuery; - CONFIG.queries.reactionRoll = ReactionRollDialog.reactionRollQuery; + // CONFIG.queries.reactionRoll = ReactionRollDialog.reactionRollQuery; + CONFIG.queries.reactionRoll = ({ actionId, actorId, event, message }) => { + // console.log('reactionRoll') + return new Promise(async (resolve, reject) => { + // resolve() + const actor = await fromUuid(actorId), + action = await fromUuid(actionId); + if (!actor || !actor?.isOwner) reject(); + action.rollSave(actor, event, message).then(result => resolve(result)); + // new ReactionRollDialog(resolve, reject, actor, trait).render({ force: true }); + }); + } } export const emitAsGM = async (eventName, callback, update, uuid = null) => {