Feature/416 reaction roll query (#445)

* Create files

* before fixing damage roll on main

* g

* Player query for Roll All Save

* Exec Save message as GM for players

* Fix DsN bug
This commit is contained in:
Dapoulp 2025-07-28 17:44:11 +02:00 committed by GitHub
parent 2fbbf98f88
commit 2be4ee8857
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 91 additions and 38 deletions

View file

@ -19,7 +19,6 @@ import {
} from './module/systemRegistration/_module.mjs'; } from './module/systemRegistration/_module.mjs';
import { placeables } from './module/canvas/_module.mjs'; import { placeables } from './module/canvas/_module.mjs';
import { registerRollDiceHooks } from './module/dice/dhRoll.mjs'; import { registerRollDiceHooks } from './module/dice/dhRoll.mjs';
import { registerDHActorHooks } from './module/documents/actor.mjs';
import './node_modules/@yaireo/tagify/dist/tagify.css'; import './node_modules/@yaireo/tagify/dist/tagify.css';
Hooks.once('init', () => { Hooks.once('init', () => {
@ -169,7 +168,7 @@ Hooks.on('ready', () => {
registerCountdownHooks(); registerCountdownHooks();
socketRegistration.registerSocketHooks(); socketRegistration.registerSocketHooks();
registerRollDiceHooks(); registerRollDiceHooks();
registerDHActorHooks(); socketRegistration.registerUserQueries();
}); });
Hooks.once('dicesoniceready', () => {}); Hooks.once('dicesoniceready', () => {});

View file

@ -453,6 +453,9 @@
"title": "Ownership Selection - {name}", "title": "Ownership Selection - {name}",
"default": "Default Ownership" "default": "Default Ownership"
}, },
"ReactionRoll": {
"title": "Reaction Roll: {trait}"
},
"ResourceDice": { "ResourceDice": {
"title": "{name} Resource", "title": "{name} Resource",
"rerollDice": "Reroll Dice" "rerollDice": "Reroll Dice"

View file

@ -1,6 +1,6 @@
import { damageKeyToNumber, getDamageLabel } from '../../helpers/utils.mjs'; import { damageKeyToNumber, getDamageLabel } from '../../helpers/utils.mjs';
const { DialogV2, ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api; const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
export default class DamageReductionDialog extends HandlebarsApplicationMixin(ApplicationV2) { export default class DamageReductionDialog extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(resolve, reject, actor, damage, damageType) { constructor(resolve, reject, actor, damage, damageType) {
@ -53,10 +53,6 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap
); );
} }
get title() {
return game.i18n.localize('DAGGERHEART.APPLICATIONS.DamageReduction.title');
}
static DEFAULT_OPTIONS = { static DEFAULT_OPTIONS = {
tag: 'form', tag: 'form',
classes: ['daggerheart', 'views', 'damage-reduction'], classes: ['daggerheart', 'views', 'damage-reduction'],

View file

@ -1,3 +1,5 @@
import { emitAsGM, GMUpdateEvent } from "../../systemRegistration/socket.mjs";
export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLog { export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLog {
constructor(options) { constructor(options) {
super(options); super(options);
@ -98,17 +100,41 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
if (message.system.source.item && message.system.source.action) { if (message.system.source.item && message.system.source.action) {
const action = this.getAction(actor, 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; if (!action || !action?.hasSave) return;
action.rollSave(token, event, message); action.rollSave(token.actor, event, message).then(result => emitAsGM(
GMUpdateEvent.UpdateSaveMessage,
action.updateSaveMessage.bind(action, result, message, token.id),
{
action: action.uuid,
message: message._id,
token: token.id,
result
}
));
} }
} }
onRollAllSave(event, _message) { async onRollAllSave(event, message) {
event.stopPropagation(); event.stopPropagation();
if(!game.user.isGM) return;
const targets = event.target.parentElement.querySelectorAll( const targets = event.target.parentElement.querySelectorAll(
'.target-section > [data-token] .target-save-container' '.target-section > [data-token] .target-save-container'
); );
targets.forEach(el => { const actor = await this.getActor(message.system.source.actor),
el.dispatchEvent(new PointerEvent('click', { shiftKey: true })); 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 {
token.actor.owner.query('reactionRoll', {
actionId: action.uuid,
actorId: token.actor.uuid,
event,
message
}).then(result => action.updateSaveMessage(result, message, token.id));
}
}); });
} }

View file

@ -299,9 +299,9 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
/* EFFECTS */ /* EFFECTS */
/* SAVE */ /* SAVE */
async rollSave(target, event, message) { async rollSave(actor, event, message) {
if (!target?.actor) return; if (!actor) return;
return target.actor return actor
.diceRoll({ .diceRoll({
event, event,
title: 'Roll Save', title: 'Roll Save',
@ -310,16 +310,28 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
difficulty: this.save.difficulty ?? this.actor?.baseSaveDifficulty, difficulty: this.save.difficulty ?? this.actor?.baseSaveDifficulty,
type: 'reaction' type: 'reaction'
}, },
data: target.actor.getRollData() data: actor.getRollData()
})
.then(async result => {
if (result)
this.updateChatMessage(message, target.id, {
result: result.roll.total,
success: result.roll.success
});
}); });
} }
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 ?? result.message._id).then(() => updateMsg());
else updateMsg();
}
static rollSaveQuery({ actionId, actorId, event, message }) {
return new Promise(async (resolve, reject) => {
const actor = await fromUuid(actorId),
action = await fromUuid(actionId);
if (!actor || !actor?.isOwner) reject();
action.rollSave(actor, event, message).then(result => resolve(result));
});
}
/* SAVE */ /* SAVE */
async updateChatMessage(message, targetId, changes, chain = true) { async updateChatMessage(message, targetId, changes, chain = true) {
@ -333,7 +345,7 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
if (chain) { if (chain) {
if (message.system.source.message) if (message.system.source.message)
this.updateChatMessage(ui.chat.collection.get(message.system.source.message), targetId, changes, false); 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 => { relatedChatMessages.forEach(c => {
this.updateChatMessage(c, targetId, changes, false); this.updateChatMessage(c, targetId, changes, false);
}); });

View file

@ -5,12 +5,14 @@ const resistanceField = (resistanceLabel, immunityLabel, reductionLabel) =>
resistance: new foundry.data.fields.BooleanField({ resistance: new foundry.data.fields.BooleanField({
initial: false, initial: false,
label: `${resistanceLabel}.label`, label: `${resistanceLabel}.label`,
hint: `${resistanceLabel}.hint` hint: `${resistanceLabel}.hint`,
isAttributeChoice: true
}), }),
immunity: new foundry.data.fields.BooleanField({ immunity: new foundry.data.fields.BooleanField({
initial: false, initial: false,
label: `${immunityLabel}.label`, label: `${immunityLabel}.label`,
hint: `${immunityLabel}.hint` hint: `${immunityLabel}.hint`,
isAttributeChoice: true
}), }),
reduction: new foundry.data.fields.NumberField({ reduction: new foundry.data.fields.NumberField({
integer: true, integer: true,

View file

@ -12,7 +12,7 @@ export default class DamageRoll extends DHRoll {
static async buildEvaluate(roll, config = {}, message = {}) { static async buildEvaluate(roll, config = {}, message = {}) {
if (config.evaluate !== false) { if (config.evaluate !== false) {
if (config.dialog.configure === false) roll.constructFormula(config); // if (config.dialog.configure === false) roll.constructFormula(config);
for (const roll of config.roll) await roll.roll.evaluate(); for (const roll of config.roll) await roll.roll.evaluate();
} }
roll._evaluated = true; roll._evaluated = true;

View file

@ -1,5 +1,4 @@
import { emitAsGM, GMUpdateEvent } from '../systemRegistration/socket.mjs'; import { emitAsGM, GMUpdateEvent } from '../systemRegistration/socket.mjs';
import DamageReductionDialog from '../applications/dialogs/damageReductionDialog.mjs';
import { LevelOptionType } from '../data/levelTier.mjs'; import { LevelOptionType } from '../data/levelTier.mjs';
import DHFeature from '../data/item/feature.mjs'; import DHFeature from '../data/item/feature.mjs';
import { damageKeyToNumber } from '../helpers/utils.mjs'; import { damageKeyToNumber } from '../helpers/utils.mjs';
@ -483,10 +482,14 @@ export default class DhpActor extends Actor {
this.#canReduceDamage(hpDamage.value, hpDamage.damageTypes) this.#canReduceDamage(hpDamage.value, hpDamage.damageTypes)
) { ) {
const armorStackResult = await this.owner.query('armorStack', { const armorStackResult = await this.owner.query('armorStack', {
actorId: this.uuid, actorId: this.uuid,
damage: hpDamage.value, damage: hpDamage.value,
type: [...hpDamage.damageTypes] type: [...hpDamage.damageTypes]
}); },
{
timeout: 30000
}
);
if (armorStackResult) { if (armorStackResult) {
const { modifiedDamage, armorSpent, stressSpent } = armorStackResult; const { modifiedDamage, armorSpent, stressSpent } = armorStackResult;
updates.find(u => u.key === 'hitPoints').value = modifiedDamage; updates.find(u => u.key === 'hitPoints').value = modifiedDamage;
@ -638,7 +641,3 @@ export default class DhpActor extends Actor {
}); });
} }
} }
export const registerDHActorHooks = () => {
CONFIG.queries.armorStack = DamageReductionDialog.armorStackQuery;
};

View file

@ -52,6 +52,7 @@ export default class DHToken extends TokenDocument {
for (const [name, field] of Object.entries(schema.fields)) { for (const [name, field] of Object.entries(schema.fields)) {
const p = _path.concat([name]); const p = _path.concat([name]);
if (field instanceof foundry.data.fields.NumberField) attributes.value.push(p); if (field instanceof foundry.data.fields.NumberField) attributes.value.push(p);
if (field instanceof foundry.data.fields.BooleanField && field.options.isAttributeChoice) attributes.value.push(p);
if (field instanceof foundry.data.fields.StringField) attributes.value.push(p); if (field instanceof foundry.data.fields.StringField) attributes.value.push(p);
if (field instanceof foundry.data.fields.ArrayField) attributes.value.push(p); if (field instanceof foundry.data.fields.ArrayField) attributes.value.push(p);
const isSchema = field instanceof foundry.data.fields.SchemaField; const isSchema = field instanceof foundry.data.fields.SchemaField;

View file

@ -1,3 +1,5 @@
import DamageReductionDialog from '../applications/dialogs/damageReductionDialog.mjs';
export function handleSocketEvent({ action = null, data = {} } = {}) { export function handleSocketEvent({ action = null, data = {} } = {}) {
switch (action) { switch (action) {
case socketEvent.GMUpdate: case socketEvent.GMUpdate:
@ -21,7 +23,8 @@ export const socketEvent = {
export const GMUpdateEvent = { export const GMUpdateEvent = {
UpdateDocument: 'DhGMUpdateDocument', UpdateDocument: 'DhGMUpdateDocument',
UpdateSetting: 'DhGMUpdateSetting', UpdateSetting: 'DhGMUpdateSetting',
UpdateFear: 'DhGMUpdateFear' UpdateFear: 'DhGMUpdateFear',
UpdateSaveMessage: 'DhGMUpdateSaveMessage'
}; };
export const RefreshType = { export const RefreshType = {
@ -53,8 +56,12 @@ export const registerSocketHooks = () => {
) )
) )
); );
/* Hooks.callAll(socketEvent.DhpFearUpdate); break;
await game.socket.emit(`system.${CONFIG.DH.id}`, { action: socketEvent.DhpFearUpdate }); */ case GMUpdateEvent.UpdateSaveMessage:
const action = await fromUuid(data.update.action),
message = game.messages.get(data.update.message);
if(!action || !message) return;
action.updateSaveMessage(data.update.result, message, data.update.token);
break; break;
} }
@ -69,6 +76,11 @@ export const registerSocketHooks = () => {
}); });
}; };
export const registerUserQueries = () => {
CONFIG.queries.armorStack = DamageReductionDialog.armorStackQuery;
CONFIG.queries.reactionRoll = game.system.api.models.actions.actionsTypes.base.rollSaveQuery;
}
export const emitAsGM = async (eventName, callback, update, uuid = null) => { export const emitAsGM = async (eventName, callback, update, uuid = null) => {
if (!game.user.isGM) { if (!game.user.isGM) {
return await game.socket.emit(`system.${CONFIG.DH.id}`, { return await game.socket.emit(`system.${CONFIG.DH.id}`, {

View file

@ -0,0 +1,3 @@
<div>
Reaction Roll
</div>