Fix origin key replacement and prioritize item options

This commit is contained in:
Carlos Fernandez 2026-04-24 19:03:55 -04:00
parent ccb0073cef
commit 479d7e506a
2 changed files with 9 additions and 8 deletions

View file

@ -171,24 +171,25 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
static getChangeValue(model, change, effect) {
let key = change.value.toString();
const isOriginTarget = key.toLowerCase().includes('origin.@');
let parseModel = model;
if (isOriginTarget && effect.origin) {
key = change.key.replaceAll(/origin\.@/gi, '@');
let origin = null;
if (key.toLowerCase().includes('origin.@') && effect.origin) {
key = key.replaceAll(/origin\.@/gi, '@');
try {
const originEffect = foundry.utils.fromUuidSync(effect.origin);
const doc =
origin =
originEffect.parent?.parent instanceof game.system.api.documents.DhpActor
? originEffect.parent
: originEffect.parent.parent;
if (doc) parseModel = doc;
} catch (_) {}
}
// Get the actor and item documents. Note that actor roll data is inclusive of system roll data
const actor = model.parent instanceof Actor ? model.parent : model;
const item = origin ?? null;
const stackingParsedValue = effect.system.stacking
? Roll.replaceFormulaData(key, { stacks: effect.system.stacking.value })
: key;
const evalValue = itemAbleRollParse(stackingParsedValue, parseModel, effect.parent);
const evalValue = itemAbleRollParse(stackingParsedValue, actor, item);
return evalValue ?? key;
}

View file

@ -375,7 +375,7 @@ export const itemAbleRollParse = (value, actor, item) => {
const isItemTarget = value.toLowerCase().includes('item.@');
const slicedValue = isItemTarget ? value.replaceAll(/item\.@/gi, '@') : value;
const model = isItemTarget ? item : actor;
const model = isItemTarget || item instanceof Item ? item : actor;
try {
return Roll.replaceFormulaData(slicedValue, isItemTarget || !model?.getRollData ? model : model.getRollData());