From a7164eab530bfbff0f9f3e3d8878bea355b088b4 Mon Sep 17 00:00:00 2001 From: macniel Date: Tue, 21 Oct 2025 17:04:09 +0200 Subject: [PATCH] first fruitful attempts of managing actions based on SF requirements --- src/module/data/specialAbility.mjs | 74 +++++++++++++++++++- src/module/documents/specialAbility.mjs | 14 ++++ src/module/sheets/actions/action-manager.mjs | 47 +++++++++---- 3 files changed, 122 insertions(+), 13 deletions(-) diff --git a/src/module/data/specialAbility.mjs b/src/module/data/specialAbility.mjs index 76c3768e..f26024cb 100644 --- a/src/module/data/specialAbility.mjs +++ b/src/module/data/specialAbility.mjs @@ -1,6 +1,7 @@ import BaseItem from "./base-item.mjs"; const { + AnyField, BooleanField, NumberField, SchemaField, @@ -15,14 +16,85 @@ export class SpecialAbilityDataModel extends BaseItem { static defineSchema() { return { name: new StringField(), + value: new StringField(), + auswahl: new ArrayField( + new SchemaField({ + name: new StringField(), + requirement: new ArrayField( + new SchemaField({ + attribute: new StringField(), + minValue: new NumberField(), + maxValue: new NumberField(), + sonderfertigkeit: new StringField(), + talent: new StringField(), + }) + ), + mod: new ArrayField(new SchemaField({ + name: new StringField(), + value: new NumberField(), + })) + }), + ), seite: new NumberField(), aktionsText: new HTMLField(), text: new HTMLField(), - requirements: new ObjectField(), // TODO something more meaningful with this data + requirement: new ArrayField( + new SchemaField({ + attribute: new StringField(), + minValue: new NumberField(), + maxValue: new NumberField(), + sonderfertigkeit: new StringField(), + talent: new StringField(), + }) + ), waffenLimit: new ArrayField( new StringField(), ), + mod: new ArrayField(new SchemaField({ + name: new StringField(), + value: new NumberField(), + })), mehrereAktionen: new BooleanField(), } } + + #getRequirements() { + if (this.value && this.auswahl.find(p => p.name === this.value)) { + const auswahl = this.auswahl.find(p => p.name === this.value) + return auswahl.requirement + } else { + return this.requirement + } + } + + isActive() { // TODO also handle Waffenlimit + + const requirements = this.#getRequirements() + + let passes = false + const flatActor = foundry.utils.flattenObject(this.parent.actor.system) + for (let requirement of requirements) { + + let targetField = null + + if (requirement.attribute) { + targetField = flatActor?.[requirement.attribute.toLocaleLowerCase()] + } + if (requirement.talent) { + targetField = this.parent.actor.itemTypes["Skill"].find(p => p.name.toLocaleLowerCase() === requirement.talent.toLocaleLowerCase()).taw + } + + if (requirement.minValue) { + passes = targetField >= requirement.minValue + } else if (requirement.maxValue) { + passes = targetField <= requirement.maxValue + } + + if (!passes) { + break + } + } + + return passes + } } diff --git a/src/module/documents/specialAbility.mjs b/src/module/documents/specialAbility.mjs index f3d30692..e60847e5 100644 --- a/src/module/documents/specialAbility.mjs +++ b/src/module/documents/specialAbility.mjs @@ -6,4 +6,18 @@ export class SpecialAbility extends Item { super.prepareData(); } + getRequirements() { + let requirements = [] + if (this.system.value && this.system.auswahl.find(p => p.name === this.system.value)) { + requirements = this.system.auswahl[this.system.value].requirement + } else { + requirements = this.system.requirement + return requirements + } + } + + isActive() { + return true + } + } diff --git a/src/module/sheets/actions/action-manager.mjs b/src/module/sheets/actions/action-manager.mjs index 05205b5e..b4ffc765 100644 --- a/src/module/sheets/actions/action-manager.mjs +++ b/src/module/sheets/actions/action-manager.mjs @@ -58,7 +58,7 @@ export class ActionManager { cost: ActionManager.FREE, type: ActionManager.INTERACTION, source: ActionManager.SF, - eval: () => this.#hatSonderfertigkeit("Schnellziehen") + eval: () => this.#hatSonderfertigkeit("Schnellziehen") && this.#evalSonderfertigkeitRequirements("Schnellziehen") } ] @@ -82,7 +82,7 @@ export class ActionManager { type: ActionManager.INTERACTION, cost: ActionManager.CONTINUING, source: ActionManager.SF, - eval: () => this.#hatFernkampfWaffeinHand() && this.#hatSonderfertigkeit("Scharfschütze") + eval: () => this.#hatFernkampfWaffeinHand() && this.#hatSonderfertigkeit("Scharfschütze") && this.#evalSonderfertigkeitRequirements("Scharfschütze") }, { name: "Abwehraktion", @@ -110,7 +110,11 @@ export class ActionManager { type: ActionManager.ATTACK, cost: ActionManager.REGULAR, source: ActionManager.SF, - eval: () => this.#hatFernkampfWaffeinHand() && this.#hatSonderfertigkeit("Finte") + eval: () => + this.#hatWaffeinHand() && + this.#hatSonderfertigkeit("Finte") && + this.#evalSonderfertigkeitRequirements("Finte") + }, { name: "Wuchtschlag", @@ -125,6 +129,7 @@ export class ActionManager { cost: ActionManager.REGULAR, source: ActionManager.SF, eval: () => this.#hatSonderfertigkeit("Wuchtschlag") + && this.#evalSonderfertigkeitRequirements("Wuchtschlag") }, { name: "Betäubungsschlag", @@ -132,6 +137,7 @@ export class ActionManager { cost: ActionManager.REGULAR, source: ActionManager.SF, eval: () => this.#hatSonderfertigkeit("Betäubungsschlag") + && this.#evalSonderfertigkeitRequirements("Betäubungsschlag") } ] @@ -169,14 +175,20 @@ export class ActionManager { type: ActionManager.INTERACTION, cost: ActionManager.CONTINUING, source: ActionManager.SF, - eval: () => this.#hatMunition() && this.#hatFernkampfWaffeinHand("Bogen") && this.#hatSonderfertigkeit("Schnellladen (Bogen)") + eval: () => this.#hatMunition() + && this.#hatFernkampfWaffeinHand("Bogen") + && this.#hatSonderfertigkeit("Schnellladen (Bogen)") + && this.#evalSonderfertigkeitRequirements("Schnellladen (Bogen)") }, { name: "Schnellladen (Armbrust)", type: ActionManager.INTERACTION, cost: ActionManager.CONTINUING, source: ActionManager.SF, - eval: () => this.#hatMunition() && this.#hatFernkampfWaffeinHand("Armbrust") && this.#hatSonderfertigkeit("Schnellladen (Armbrust)") + eval: () => this.#hatMunition() + && this.#hatFernkampfWaffeinHand("Armbrust") + && this.#hatSonderfertigkeit("Schnellladen (Armbrust)") + && this.#evalSonderfertigkeitRequirements("Schnellladen (Armbrust)") }, { name: "Nachladen", @@ -211,31 +223,42 @@ export class ActionManager { #hatWaffeinHand() { const item = this.actor.findEquipmentOnSlot("links") ?? this.actor.findEquipmentOnSlot("rechts") - return item + return item != null } #hatMunition() { const item = this.actor.findEquipmentOnSlot("munition") - const weapon = this.actor.findEquipmentOnSlot("fernkampf") - return item + return item != null } #hatFernkampfWaffeinHand(art) { const item = this.actor.findEquipmentOnSlot("fernkampf") - return item + return item != null } #hatSonderfertigkeitBeginnendMit(name) { - return this.actor.system.sonderfertigkeiten?.find(p => p.name.startsWith(name)) != null + return this.actor.itemTypes["SpecialAbility"]?.find(p => p.name.startsWith(name)) != null } #hatSonderfertigkeit(name) { - return this.actor.system.sonderfertigkeiten?.find(p => p.name === name) != null + return this.actor.itemTypes["SpecialAbility"]?.find(p => p.name === name) != null + } + + #evalSonderfertigkeitRequirements(nameOfSF) { + const sf = this.actor.itemTypes["SpecialAbility"].find(p => p.name === nameOfSF) + return sf.system.isActive() } evaluate() { let actionArray = [...this.#freeActions, ...this.#regularActions, ...this.#continuingActions] - return actionArray.filter(action => action.eval()); + console.log(this.actor, actionArray.map((action) => { + return { + ...action, + eval: action.eval() + } + })) + const validActions = actionArray.filter(action => action.eval()) + return validActions } }