Always derive hitPoints.max from the final hitPoints.total

This commit is contained in:
Johannes Loher 2021-02-16 15:39:18 +01:00
parent 4e2691e19f
commit 624059ef02

View file

@ -18,6 +18,7 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item> {
this.applyActiveEffectsToNonDerivedData();
this.prepareDerivedData();
this.applyActiveEffectsToDerivedData();
this.prepareFinalDerivedData();
}
/** @override */
@ -33,11 +34,17 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item> {
}
applyActiveEffectsToNonDerivedData(): void {
this.applyActiveEffectsFiltered((change) => !this.derivedDataProperties.includes(change.key));
this.applyActiveEffectsFiltered(
(change) =>
!this.derivedDataProperties.includes(change.key) && !this.finalDerivedProperties.includes(change.key),
);
}
applyActiveEffectsToDerivedData(): void {
this.applyActiveEffectsFiltered((change) => this.derivedDataProperties.includes(change.key));
this.applyActiveEffectsFiltered(
(change) =>
this.derivedDataProperties.includes(change.key) && !this.finalDerivedProperties.includes(change.key),
);
}
/**
@ -87,18 +94,38 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item> {
return item ?? undefined;
}
/** @override */
/**
* Apply transformations to the Actor data after effects have been applied to the base data.
* @override
*/
prepareDerivedData(): void {
this._prepareCombatValues();
}
/** The list of properties that are derived from others, given in dot notation */
/**
* The list of properties that are derived from others, given in dot notation.
*/
get derivedDataProperties(): Array<string> {
return Object.keys(DS4.i18n.combatValues)
.map((combatValue) => `data.combatValues.${combatValue}.total`)
.concat("data.combatValues.hitPoints.max");
}
/**
* Apply final transformations to the Actor data after all effects have been applied.
*/
prepareFinalDerivedData(): void {
this.data.data.combatValues.hitPoints.max = this.data.data.combatValues.hitPoints.total;
}
/**
* The list of properties that are completely derived (i.e. {@link ActiveEffect}s cannot be applied to them), given in dot
* notation.
*/
get finalDerivedProperties(): string[] {
return ["data.combatValues.hitPoints.max"];
}
/**
* The list of item types that can be owned by this actor.
*/
@ -156,8 +183,6 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item> {
Object.values(data.combatValues).forEach(
(combatValue: ModifiableData<number>) => (combatValue.total = combatValue.base + combatValue.mod),
);
data.combatValues.hitPoints.max = data.combatValues.hitPoints.total;
}
/**