feat: don't count armor from material type cloth or natural as spell malus

This commit is contained in:
Johannes Loher 2021-09-22 02:36:49 +02:00
parent af7ebb1b91
commit 75366ea354

View file

@ -6,6 +6,7 @@
import { ModifiableDataBaseTotal } from "../common/common-data"; import { ModifiableDataBaseTotal } from "../common/common-data";
import { DS4 } from "../config"; import { DS4 } from "../config";
import { getGame } from "../helpers"; import { getGame } from "../helpers";
import { DS4Item } from "../item/item";
import { DS4ArmorDataProperties, DS4ShieldDataProperties } from "../item/item-data-properties"; import { DS4ArmorDataProperties, DS4ShieldDataProperties } from "../item/item-data-properties";
import { ItemType } from "../item/item-data-source"; import { ItemType } from "../item/item-data-source";
import { createCheckRoll } from "../rolls/check-factory"; import { createCheckRoll } from "../rolls/check-factory";
@ -117,8 +118,8 @@ export class DS4Actor extends Actor {
* @override * @override
*/ */
prepareDerivedData(): void { prepareDerivedData(): void {
this._prepareCombatValues(); this.prepareCombatValues();
this._prepareChecks(); this.prepareChecks();
} }
/** /**
@ -189,9 +190,10 @@ export class DS4Actor extends Actor {
/** /**
* Prepares the combat values of the actor. * Prepares the combat values of the actor.
*/ */
protected _prepareCombatValues(): void { protected prepareCombatValues(): void {
const data = this.data.data; 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.hitPoints.base = data.attributes.body.total + data.traits.constitution.total + 10;
data.combatValues.defense.base = 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.meleeAttack.base = data.attributes.body.total + data.traits.strength.total;
data.combatValues.rangedAttack.base = data.attributes.mobility.total + data.traits.dexterity.total; data.combatValues.rangedAttack.base = data.attributes.mobility.total + data.traits.dexterity.total;
data.combatValues.spellcasting.base = 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.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( Object.values(data.combatValues).forEach(
(combatValue: ModifiableDataBaseTotal<number>) => (combatValue.total = combatValue.base + combatValue.mod), (combatValue: ModifiableDataBaseTotal<number>) => (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 { protected calculateArmorValueOfEquippedItems(): number {
return this.items return this.getEquippedItemsWithArmor()
.map((item) => item.data) .map((item) => item.data.data.armorValue)
.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)
.reduce((a, b) => a + b, 0); .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. * Prepares the check target numbers of checks for the actor.
*/ */
protected _prepareChecks(): void { protected prepareChecks(): void {
const data = this.data.data; const data = this.data.data;
data.checks = { data.checks = {
appraise: data.attributes.mind.total + data.traits.intellect.total, appraise: data.attributes.mind.total + data.traits.intellect.total,