mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-08 05:38:10 +02:00
Fix origin key replacement and prioritize item options
This commit is contained in:
parent
ccb0073cef
commit
479d7e506a
2 changed files with 9 additions and 8 deletions
|
|
@ -171,24 +171,25 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
|
||||||
|
|
||||||
static getChangeValue(model, change, effect) {
|
static getChangeValue(model, change, effect) {
|
||||||
let key = change.value.toString();
|
let key = change.value.toString();
|
||||||
const isOriginTarget = key.toLowerCase().includes('origin.@');
|
let origin = null;
|
||||||
let parseModel = model;
|
if (key.toLowerCase().includes('origin.@') && effect.origin) {
|
||||||
if (isOriginTarget && effect.origin) {
|
key = key.replaceAll(/origin\.@/gi, '@');
|
||||||
key = change.key.replaceAll(/origin\.@/gi, '@');
|
|
||||||
try {
|
try {
|
||||||
const originEffect = foundry.utils.fromUuidSync(effect.origin);
|
const originEffect = foundry.utils.fromUuidSync(effect.origin);
|
||||||
const doc =
|
origin =
|
||||||
originEffect.parent?.parent instanceof game.system.api.documents.DhpActor
|
originEffect.parent?.parent instanceof game.system.api.documents.DhpActor
|
||||||
? originEffect.parent
|
? originEffect.parent
|
||||||
: originEffect.parent.parent;
|
: originEffect.parent.parent;
|
||||||
if (doc) parseModel = doc;
|
|
||||||
} catch (_) {}
|
} 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
|
const stackingParsedValue = effect.system.stacking
|
||||||
? Roll.replaceFormulaData(key, { stacks: effect.system.stacking.value })
|
? Roll.replaceFormulaData(key, { stacks: effect.system.stacking.value })
|
||||||
: key;
|
: key;
|
||||||
const evalValue = itemAbleRollParse(stackingParsedValue, parseModel, effect.parent);
|
const evalValue = itemAbleRollParse(stackingParsedValue, actor, item);
|
||||||
return evalValue ?? key;
|
return evalValue ?? key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,7 @@ export const itemAbleRollParse = (value, actor, item) => {
|
||||||
|
|
||||||
const isItemTarget = value.toLowerCase().includes('item.@');
|
const isItemTarget = value.toLowerCase().includes('item.@');
|
||||||
const slicedValue = isItemTarget ? value.replaceAll(/item\.@/gi, '@') : value;
|
const slicedValue = isItemTarget ? value.replaceAll(/item\.@/gi, '@') : value;
|
||||||
const model = isItemTarget ? item : actor;
|
const model = isItemTarget || item instanceof Item ? item : actor;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return Roll.replaceFormulaData(slicedValue, isItemTarget || !model?.getRollData ? model : model.getRollData());
|
return Roll.replaceFormulaData(slicedValue, isItemTarget || !model?.getRollData ? model : model.getRollData());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue