From 75366ea354fd91829189f544e10a1f0ef0145d24 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Wed, 22 Sep 2021 02:36:49 +0200 Subject: [PATCH] feat: don't count armor from material type cloth or natural as spell malus --- src/module/actor/actor.ts | 52 ++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/src/module/actor/actor.ts b/src/module/actor/actor.ts index 15291e38..1b3a7900 100644 --- a/src/module/actor/actor.ts +++ b/src/module/actor/actor.ts @@ -6,6 +6,7 @@ import { ModifiableDataBaseTotal } from "../common/common-data"; import { DS4 } from "../config"; import { getGame } from "../helpers"; +import { DS4Item } from "../item/item"; import { DS4ArmorDataProperties, DS4ShieldDataProperties } from "../item/item-data-properties"; import { ItemType } from "../item/item-data-source"; import { createCheckRoll } from "../rolls/check-factory"; @@ -117,8 +118,8 @@ export class DS4Actor extends Actor { * @override */ prepareDerivedData(): void { - this._prepareCombatValues(); - this._prepareChecks(); + this.prepareCombatValues(); + this.prepareChecks(); } /** @@ -189,9 +190,10 @@ export class DS4Actor extends Actor { /** * Prepares the combat values of the actor. */ - protected _prepareCombatValues(): void { + protected prepareCombatValues(): void { const data = this.data.data; - const armorValueOfEquippedItems = this._calculateArmorValueOfEquippedItems(); + 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 = @@ -201,9 +203,9 @@ export class DS4Actor extends Actor { 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 - armorValueOfEquippedItems; + data.attributes.mind.total + data.traits.aura.total - spellMalusOfEquippedItems; data.combatValues.targetedSpellcasting.base = - data.attributes.mind.total + data.traits.dexterity.total - armorValueOfEquippedItems; + data.attributes.mind.total + data.traits.dexterity.total - spellMalusOfEquippedItems; Object.values(data.combatValues).forEach( (combatValue: ModifiableDataBaseTotal) => (combatValue.total = combatValue.base + combatValue.mod), @@ -211,24 +213,40 @@ export class DS4Actor extends Actor { } /** - * Calculates the total armor value of all equipped items. + * Calculates the total armor value of the equipped items. */ - protected _calculateArmorValueOfEquippedItems(): number { - return this.items - .map((item) => item.data) - .filter( - (data): data is foundry.data.ItemData & (DS4ArmorDataProperties | DS4ShieldDataProperties) => - data.type === "armor" || data.type === "shield", - ) - .filter((data) => data.data.equipped) - .map((data) => data.data.armorValue) + protected calculateArmorValueOfEquippedItems(): number { + return this.getEquippedItemsWithArmor() + .map((item) => item.data.data.armorValue) .reduce((a, b) => a + b, 0); } + /** + * Calculates the spell malus from equipped items. + */ + protected calculateSpellMaluesOfEquippedItems(): number { + return this.getEquippedItemsWithArmor() + .filter( + (item) => + !(item.data.type === "armor" && ["cloth", "natural"].includes(item.data.data.armorMaterialType)), + ) + .map((item) => item.data.data.armorValue) + .reduce((a, b) => a + b, 0); + } + + private getEquippedItemsWithArmor() { + return this.items + .filter( + (item): item is DS4Item & { data: DS4ArmorDataProperties | DS4ShieldDataProperties } => + item.data.type === "armor" || item.data.type === "shield", + ) + .filter((item) => item.data.data.equipped); + } + /** * Prepares the check target numbers of checks for the actor. */ - protected _prepareChecks(): void { + protected prepareChecks(): void { const data = this.data.data; data.checks = { appraise: data.attributes.mind.total + data.traits.intellect.total,