Always derive hitPoints.max from the final hitPoints.total
This commit is contained in:
parent
4e2691e19f
commit
624059ef02
1 changed files with 31 additions and 6 deletions
|
@ -18,6 +18,7 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item> {
|
||||||
this.applyActiveEffectsToNonDerivedData();
|
this.applyActiveEffectsToNonDerivedData();
|
||||||
this.prepareDerivedData();
|
this.prepareDerivedData();
|
||||||
this.applyActiveEffectsToDerivedData();
|
this.applyActiveEffectsToDerivedData();
|
||||||
|
this.prepareFinalDerivedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
|
@ -33,11 +34,17 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item> {
|
||||||
}
|
}
|
||||||
|
|
||||||
applyActiveEffectsToNonDerivedData(): void {
|
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 {
|
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;
|
return item ?? undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @override */
|
/**
|
||||||
|
* Apply transformations to the Actor data after effects have been applied to the base data.
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
prepareDerivedData(): void {
|
prepareDerivedData(): void {
|
||||||
this._prepareCombatValues();
|
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> {
|
get derivedDataProperties(): Array<string> {
|
||||||
return Object.keys(DS4.i18n.combatValues)
|
return Object.keys(DS4.i18n.combatValues)
|
||||||
.map((combatValue) => `data.combatValues.${combatValue}.total`)
|
.map((combatValue) => `data.combatValues.${combatValue}.total`)
|
||||||
.concat("data.combatValues.hitPoints.max");
|
.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.
|
* 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(
|
Object.values(data.combatValues).forEach(
|
||||||
(combatValue: ModifiableData<number>) => (combatValue.total = combatValue.base + combatValue.mod),
|
(combatValue: ModifiableData<number>) => (combatValue.total = combatValue.base + combatValue.mod),
|
||||||
);
|
);
|
||||||
|
|
||||||
data.combatValues.hitPoints.max = data.combatValues.hitPoints.total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue