From bf1cc504dcfef9e865fd2a66d20b2c4c53df56bb Mon Sep 17 00:00:00 2001 From: Carlos Fernandez Date: Tue, 23 Jun 2026 00:55:38 -0400 Subject: [PATCH] Fix resolving formulas in weapon change effects --- module/data/action/baseAction.mjs | 42 ++++++++++++++++--------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/module/data/action/baseAction.mjs b/module/data/action/baseAction.mjs index f568436e..27383b7a 100644 --- a/module/data/action/baseAction.mjs +++ b/module/data/action/baseAction.mjs @@ -348,29 +348,31 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel 'system.bonuses.roll.spellcast.bonus' ]; - return Array.from(await actor.allApplicableEffects({ noTransferArmor: true, noSelfArmor: true })).reduce( - (acc, effect) => { - const effectData = effect.toObject(); - /* Effects on weapons only ever apply for the weapon itself, with a few defined exceptions */ - if (effect.parent.type === 'weapon') { - /* Unless they're secondary - then they apply only to other primary weapons */ - if (effect.parent.system.secondary) { - if (effectParent?.type !== 'weapon' || effectParent?.system.secondary) { - effectData.system.changes = - effectData.system.changes.filter(x => weaponTransferredEffectKeys.includes(x.key)); - } - } else if (effectParent?.id !== effect.parent.id) { - effectData.system.changes = - effectData.system.changes.filter(x => weaponTransferredEffectKeys.includes(x.key)); + const results = []; + const applicableEffects = await actor.allApplicableEffects({ noTransferArmor: true, noSelfArmor: true }); + for (const effect of [...applicableEffects].filter(e => !e.isSuppressed)) { + if (effect.parent.type === 'weapon') { + // Effects on weapons only ever apply for the weapon itself (with a few exceptions) + const restricted = + effect.parent.system.secondary + // Secondary applies only to other primary weapons + ? effectParent?.type !== 'weapon' || effectParent?.system.secondary + // Primary only applies to itself + : effectParent?.id !== effect.parent.id; + if (restricted) { + const sourceChanges = effect._source.system.changes; + const changes = sourceChanges.filter(x => weaponTransferredEffectKeys.includes(x.key)); + if (changes.length) { + results.push(effect.clone({ 'system.changes': changes })); } + continue; } + } + + results.push(effect); + } - if (!effect.isSuppressed) { - acc.push(effectData); - } - - return acc; - }, []); + return results; } /**