feat: make it possible to affect the armor value spell malus with Active Effects
The corresponding key is `data.armorValueSpellMalus`
This commit is contained in:
parent
880726305d
commit
acf48c4c44
2 changed files with 28 additions and 17 deletions
|
@ -15,6 +15,7 @@ export interface DS4ActorDataPropertiesDataBase {
|
|||
combatValues: DS4ActorDataPropertiesDataCombatValues;
|
||||
rolling: DS4ActorDataPropertiesDataRolling;
|
||||
checks: DS4ActorDataPropertiesDataChecks;
|
||||
armorValueSpellMalus: number;
|
||||
}
|
||||
|
||||
type DS4ActorDataPropertiesDataAttributes = {
|
||||
|
|
|
@ -32,7 +32,7 @@ export class DS4Actor extends Actor {
|
|||
this.data.reset();
|
||||
this.prepareBaseData();
|
||||
this.prepareEmbeddedDocuments();
|
||||
this.applyActiveEffectsToItems();
|
||||
this.prepareIntermediateData();
|
||||
this.applyActiveEffectsToBaseData();
|
||||
this.prepareDerivedData();
|
||||
this.applyActiveEffectsToDerivedData();
|
||||
|
@ -58,7 +58,20 @@ export class DS4Actor extends Actor {
|
|||
);
|
||||
}
|
||||
|
||||
private get actorEffects() {
|
||||
override prepareEmbeddedDocuments() {
|
||||
super.prepareEmbeddedDocuments();
|
||||
this.applyActiveEffectsToItems();
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply transformations to the Actor data after embedded documents have been prepared, but before effects have been
|
||||
* applied to the Actor.
|
||||
*/
|
||||
prepareIntermediateData() {
|
||||
this.data.data.armorValueSpellMalus = this.armorValueSpellMalusOfEquippedItems;
|
||||
}
|
||||
|
||||
protected get actorEffects() {
|
||||
return this.effects.filter((effect) => !effect.data.flags.ds4?.itemEffectConfig?.applyToItems);
|
||||
}
|
||||
|
||||
|
@ -93,7 +106,7 @@ export class DS4Actor extends Actor {
|
|||
});
|
||||
}
|
||||
|
||||
private static replaceFormulaData(formula: string, data: object): string | undefined {
|
||||
protected static replaceFormulaData(formula: string, data: object): string | undefined {
|
||||
const dataRgx = new RegExp(/@([a-z.0-9_\-]+)/gi);
|
||||
try {
|
||||
return formula.replace(dataRgx, (_, term) => {
|
||||
|
@ -163,6 +176,7 @@ export class DS4Actor extends Actor {
|
|||
* Apply transformations to the Actor data after effects have been applied to the base data.
|
||||
*/
|
||||
override prepareDerivedData(): void {
|
||||
this.data.data.armorValueSpellMalus = Math.max(this.data.data.armorValueSpellMalus, 0);
|
||||
this.prepareCombatValues();
|
||||
this.prepareChecks();
|
||||
}
|
||||
|
@ -232,20 +246,18 @@ export class DS4Actor extends Actor {
|
|||
*/
|
||||
protected prepareCombatValues(): void {
|
||||
const data = this.data.data;
|
||||
const armorValueOfEquippedItems = this.calculateArmorValueOfEquippedItems();
|
||||
const spellMalusOfEquippedItems = this.calculateSpellMaluesOfEquippedItems();
|
||||
|
||||
data.combatValues.hitPoints.base = data.attributes.body.total + data.traits.constitution.total + 10;
|
||||
data.combatValues.defense.base =
|
||||
data.attributes.body.total + data.traits.constitution.total + armorValueOfEquippedItems;
|
||||
data.attributes.body.total + data.traits.constitution.total + this.armorValueOfEquippedItems;
|
||||
data.combatValues.initiative.base = data.attributes.mobility.total + data.traits.agility.total;
|
||||
data.combatValues.movement.base = data.attributes.mobility.total / 2 + 1;
|
||||
data.combatValues.meleeAttack.base = data.attributes.body.total + data.traits.strength.total;
|
||||
data.combatValues.rangedAttack.base = data.attributes.mobility.total + data.traits.dexterity.total;
|
||||
data.combatValues.spellcasting.base =
|
||||
data.attributes.mind.total + data.traits.aura.total - spellMalusOfEquippedItems;
|
||||
data.attributes.mind.total + data.traits.aura.total - data.armorValueSpellMalus;
|
||||
data.combatValues.targetedSpellcasting.base =
|
||||
data.attributes.mind.total + data.traits.dexterity.total - spellMalusOfEquippedItems;
|
||||
data.attributes.mind.total + data.traits.dexterity.total - data.armorValueSpellMalus;
|
||||
|
||||
Object.values(data.combatValues).forEach(
|
||||
(combatValue: ModifiableDataBaseTotal<number>) => (combatValue.total = combatValue.base + combatValue.mod),
|
||||
|
@ -253,19 +265,17 @@ export class DS4Actor extends Actor {
|
|||
}
|
||||
|
||||
/**
|
||||
* Calculates the total armor value of the equipped items.
|
||||
* The total armor value of the equipped items.
|
||||
*/
|
||||
protected calculateArmorValueOfEquippedItems(): number {
|
||||
return this.getEquippedItemsWithArmor()
|
||||
.map((item) => item.data.data.armorValue)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
protected get armorValueOfEquippedItems(): number {
|
||||
return this.equippedItemsWithArmor.map((item) => item.data.data.armorValue).reduce((a, b) => a + b, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the spell malus from equipped items.
|
||||
* The armor value spell malus from equipped items.
|
||||
*/
|
||||
protected calculateSpellMaluesOfEquippedItems(): number {
|
||||
return this.getEquippedItemsWithArmor()
|
||||
protected get armorValueSpellMalusOfEquippedItems(): number {
|
||||
return this.equippedItemsWithArmor
|
||||
.filter(
|
||||
(item) =>
|
||||
!(item.data.type === "armor" && ["cloth", "natural"].includes(item.data.data.armorMaterialType)),
|
||||
|
@ -274,7 +284,7 @@ export class DS4Actor extends Actor {
|
|||
.reduce((a, b) => a + b, 0);
|
||||
}
|
||||
|
||||
private getEquippedItemsWithArmor() {
|
||||
protected get equippedItemsWithArmor() {
|
||||
return this.items
|
||||
.filter(
|
||||
(item): item is DS4Item & { data: DS4ArmorDataProperties | DS4ShieldDataProperties } =>
|
||||
|
|
Loading…
Reference in a new issue