Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions module/documents/active-effect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import MappingField from "../data/fields/mapping-field.mjs";
import { parseOrString, simplifyBonus, staticID } from "../utils.mjs";
import Item5e from "./item.mjs";
import DependentDocumentMixin from "./mixins/dependent.mjs";
import Scaling from "./scaling.mjs";

const TextEditor = foundry.applications.ux.TextEditor.implementation;
const { NumberField, ObjectField, SchemaField, SetField, StringField } = foundry.data.fields;
Expand Down Expand Up @@ -323,9 +324,6 @@ export default class ActiveEffect5e extends DependentDocumentMixin(ActiveEffect)
// Apply shims to moved fields
change = change.effect._applyChangeShim(change);

if ( (model instanceof foundry.abstract.Document)
&& !change.effect._checkCondition(change, options.replacementData) ) return {};

// Handle special actor flags
if ( change.key.startsWith("flags.dnd5e.") ) change = change.effect._prepareFlagChange(model, change);

Expand Down Expand Up @@ -590,14 +588,10 @@ export default class ActiveEffect5e extends DependentDocumentMixin(ActiveEffect)

/* -------------------------------------------- */

/**
* Determine whether a specific change should be applied during this phase, setting `applied` if approved.
* @param {object} change Change that might be applied.
* @param {object} [conditionData] Data used to evaluate conditions.
* @returns {boolean}
* @internal
*/
_checkCondition(change, conditionData) {
/** @inheritDoc */
shouldApplyChange(change, options) {
if ( !super.shouldApplyChange(change, options) ) return false;
const conditionData = options?.replacementData;
if ( conditionData && !CONFIG.ActiveEffect.changeTypes[change.type]?.skipConditions ) {
if ( this.system.conditions?.check(conditionData) === false ) return false;
if ( change.conditions?.check(conditionData) === false ) return false;
Expand All @@ -609,6 +603,22 @@ export default class ActiveEffect5e extends DependentDocumentMixin(ActiveEffect)
return true;
}

/* -------------------------------------------- */

/** @inheritDoc */
getReplacementData(baseData) {
baseData = { ...super.getReplacementData(baseData) };
if ( this.item ) {
baseData.item = {
...this.item.system,
flags: this.item.flags,
name: this.item.name
};
baseData.scaling = new Scaling(this.item.scalingIncrease);
}
return baseData;
}

/* -------------------------------------------- */
/* Lifecycle */
/* -------------------------------------------- */
Expand Down
17 changes: 6 additions & 11 deletions module/documents/actor/actor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,6 @@ export default class Actor5e extends SystemDocumentMixin(Actor) {
return type;
}

/* -------------------------------------------- */

/** @inheritDoc */
prepareData() {
super.prepareData();
if ( this.system.modelProvider === dnd5e ) {
this.items.forEach(item => item.prepareFinalAttributes());
this._prepareSpellcasting();
}
}

/* --------------------------------------------- */

/** @inheritDoc */
Expand Down Expand Up @@ -399,6 +388,12 @@ export default class Actor5e extends SystemDocumentMixin(Actor) {
}
}

// Prepare final attributes & spellcasting so that they can be used/modified in "final" phase
if ( phase === "final" ) {
this.items.forEach(item => item.prepareFinalAttributes());
this._prepareSpellcasting();
}

return super.applyActiveEffects(phase);
}

Expand Down