Fix resolving formulas in weapon change effects

This commit is contained in:
Carlos Fernandez 2026-06-23 00:55:38 -04:00
parent 329d820aab
commit bf1cc504dc

View file

@ -348,29 +348,31 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
'system.bonuses.roll.spellcast.bonus' 'system.bonuses.roll.spellcast.bonus'
]; ];
return Array.from(await actor.allApplicableEffects({ noTransferArmor: true, noSelfArmor: true })).reduce( const results = [];
(acc, effect) => { const applicableEffects = await actor.allApplicableEffects({ noTransferArmor: true, noSelfArmor: true });
const effectData = effect.toObject(); for (const effect of [...applicableEffects].filter(e => !e.isSuppressed)) {
/* Effects on weapons only ever apply for the weapon itself, with a few defined exceptions */ if (effect.parent.type === 'weapon') {
if (effect.parent.type === 'weapon') { // Effects on weapons only ever apply for the weapon itself (with a few exceptions)
/* Unless they're secondary - then they apply only to other primary weapons */ const restricted =
if (effect.parent.system.secondary) { effect.parent.system.secondary
if (effectParent?.type !== 'weapon' || effectParent?.system.secondary) { // Secondary applies only to other primary weapons
effectData.system.changes = ? effectParent?.type !== 'weapon' || effectParent?.system.secondary
effectData.system.changes.filter(x => weaponTransferredEffectKeys.includes(x.key)); // Primary only applies to itself
} : effectParent?.id !== effect.parent.id;
} else if (effectParent?.id !== effect.parent.id) { if (restricted) {
effectData.system.changes = const sourceChanges = effect._source.system.changes;
effectData.system.changes.filter(x => weaponTransferredEffectKeys.includes(x.key)); 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) { return results;
acc.push(effectData);
}
return acc;
}, []);
} }
/** /**