fix: apply effects to embedded items after all embedded items have been prepared
This commit is contained in:
parent
ebb2421952
commit
bdb17cfac7
2 changed files with 27 additions and 22 deletions
|
@ -28,13 +28,11 @@ declare global {
|
|||
* The Actor class for DS4
|
||||
*/
|
||||
export class DS4Actor extends Actor {
|
||||
initialized: boolean | undefined;
|
||||
|
||||
override prepareData(): void {
|
||||
this.initialized = true;
|
||||
this.data.reset();
|
||||
this.prepareBaseData();
|
||||
this.prepareEmbeddedDocuments();
|
||||
this.applyActiveEffectsToItems();
|
||||
this.applyActiveEffectsToBaseData();
|
||||
this.prepareDerivedData();
|
||||
this.applyActiveEffectsToDerivedData();
|
||||
|
@ -118,8 +116,33 @@ export class DS4Actor extends Actor {
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply active effects to items.
|
||||
*
|
||||
* @remarks
|
||||
* Talents are handled before all other item types, because if the total rank of a talent is affected by any
|
||||
* effects, that affects how many times effects provided by this talent need to be applied. At the moment, there is
|
||||
* no special ordering among talents. This means that having a talents that provide effects that adjust the total
|
||||
* rank of talents can lead to nondeterministic behavior and thus must be avoided.
|
||||
*/
|
||||
applyActiveEffectsToItems(): void {
|
||||
/* Handle talents before all other item types, because their rank might be affected, which in turn affects how
|
||||
many times effects provided by that talent are applied */
|
||||
for (const item of this.itemTypes.talent) {
|
||||
this.applyActiveEffectsToItem(item);
|
||||
}
|
||||
for (const item of this.items) {
|
||||
if (item.type === "talent") continue;
|
||||
this.applyActiveEffectsToItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
protected applyActiveEffectsToItem(item: DS4Item) {
|
||||
item.overrides = {};
|
||||
DS4ActiveEffect.applyEffetcs(item, this.itemEffects(item));
|
||||
}
|
||||
|
||||
applyActiveEffectsToBaseData(): void {
|
||||
// reset overrides because our variant of applying active effects does not set them, it only adds overrides
|
||||
this.overrides = {};
|
||||
DS4ActiveEffect.applyEffetcs(
|
||||
this,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue