first fruitful attempts of managing actions based on SF requirements
parent
9352a418a8
commit
a7164eab53
|
|
@ -1,6 +1,7 @@
|
||||||
import BaseItem from "./base-item.mjs";
|
import BaseItem from "./base-item.mjs";
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
AnyField,
|
||||||
BooleanField,
|
BooleanField,
|
||||||
NumberField,
|
NumberField,
|
||||||
SchemaField,
|
SchemaField,
|
||||||
|
|
@ -15,14 +16,85 @@ export class SpecialAbilityDataModel extends BaseItem {
|
||||||
static defineSchema() {
|
static defineSchema() {
|
||||||
return {
|
return {
|
||||||
name: new StringField(),
|
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(),
|
seite: new NumberField(),
|
||||||
aktionsText: new HTMLField(),
|
aktionsText: new HTMLField(),
|
||||||
text: 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(
|
waffenLimit: new ArrayField(
|
||||||
new StringField(),
|
new StringField(),
|
||||||
),
|
),
|
||||||
|
mod: new ArrayField(new SchemaField({
|
||||||
|
name: new StringField(),
|
||||||
|
value: new NumberField(),
|
||||||
|
})),
|
||||||
mehrereAktionen: new BooleanField(),
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,18 @@ export class SpecialAbility extends Item {
|
||||||
super.prepareData();
|
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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ export class ActionManager {
|
||||||
cost: ActionManager.FREE,
|
cost: ActionManager.FREE,
|
||||||
type: ActionManager.INTERACTION,
|
type: ActionManager.INTERACTION,
|
||||||
source: ActionManager.SF,
|
source: ActionManager.SF,
|
||||||
eval: () => this.#hatSonderfertigkeit("Schnellziehen")
|
eval: () => this.#hatSonderfertigkeit("Schnellziehen") && this.#evalSonderfertigkeitRequirements("Schnellziehen")
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -82,7 +82,7 @@ export class ActionManager {
|
||||||
type: ActionManager.INTERACTION,
|
type: ActionManager.INTERACTION,
|
||||||
cost: ActionManager.CONTINUING,
|
cost: ActionManager.CONTINUING,
|
||||||
source: ActionManager.SF,
|
source: ActionManager.SF,
|
||||||
eval: () => this.#hatFernkampfWaffeinHand() && this.#hatSonderfertigkeit("Scharfschütze")
|
eval: () => this.#hatFernkampfWaffeinHand() && this.#hatSonderfertigkeit("Scharfschütze") && this.#evalSonderfertigkeitRequirements("Scharfschütze")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Abwehraktion",
|
name: "Abwehraktion",
|
||||||
|
|
@ -110,7 +110,11 @@ export class ActionManager {
|
||||||
type: ActionManager.ATTACK,
|
type: ActionManager.ATTACK,
|
||||||
cost: ActionManager.REGULAR,
|
cost: ActionManager.REGULAR,
|
||||||
source: ActionManager.SF,
|
source: ActionManager.SF,
|
||||||
eval: () => this.#hatFernkampfWaffeinHand() && this.#hatSonderfertigkeit("Finte")
|
eval: () =>
|
||||||
|
this.#hatWaffeinHand() &&
|
||||||
|
this.#hatSonderfertigkeit("Finte") &&
|
||||||
|
this.#evalSonderfertigkeitRequirements("Finte")
|
||||||
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Wuchtschlag",
|
name: "Wuchtschlag",
|
||||||
|
|
@ -125,6 +129,7 @@ export class ActionManager {
|
||||||
cost: ActionManager.REGULAR,
|
cost: ActionManager.REGULAR,
|
||||||
source: ActionManager.SF,
|
source: ActionManager.SF,
|
||||||
eval: () => this.#hatSonderfertigkeit("Wuchtschlag")
|
eval: () => this.#hatSonderfertigkeit("Wuchtschlag")
|
||||||
|
&& this.#evalSonderfertigkeitRequirements("Wuchtschlag")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Betäubungsschlag",
|
name: "Betäubungsschlag",
|
||||||
|
|
@ -132,6 +137,7 @@ export class ActionManager {
|
||||||
cost: ActionManager.REGULAR,
|
cost: ActionManager.REGULAR,
|
||||||
source: ActionManager.SF,
|
source: ActionManager.SF,
|
||||||
eval: () => this.#hatSonderfertigkeit("Betäubungsschlag")
|
eval: () => this.#hatSonderfertigkeit("Betäubungsschlag")
|
||||||
|
&& this.#evalSonderfertigkeitRequirements("Betäubungsschlag")
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -169,14 +175,20 @@ export class ActionManager {
|
||||||
type: ActionManager.INTERACTION,
|
type: ActionManager.INTERACTION,
|
||||||
cost: ActionManager.CONTINUING,
|
cost: ActionManager.CONTINUING,
|
||||||
source: ActionManager.SF,
|
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)",
|
name: "Schnellladen (Armbrust)",
|
||||||
type: ActionManager.INTERACTION,
|
type: ActionManager.INTERACTION,
|
||||||
cost: ActionManager.CONTINUING,
|
cost: ActionManager.CONTINUING,
|
||||||
source: ActionManager.SF,
|
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",
|
name: "Nachladen",
|
||||||
|
|
@ -211,31 +223,42 @@ export class ActionManager {
|
||||||
|
|
||||||
#hatWaffeinHand() {
|
#hatWaffeinHand() {
|
||||||
const item = this.actor.findEquipmentOnSlot("links") ?? this.actor.findEquipmentOnSlot("rechts")
|
const item = this.actor.findEquipmentOnSlot("links") ?? this.actor.findEquipmentOnSlot("rechts")
|
||||||
return item
|
return item != null
|
||||||
}
|
}
|
||||||
|
|
||||||
#hatMunition() {
|
#hatMunition() {
|
||||||
const item = this.actor.findEquipmentOnSlot("munition")
|
const item = this.actor.findEquipmentOnSlot("munition")
|
||||||
const weapon = this.actor.findEquipmentOnSlot("fernkampf")
|
return item != null
|
||||||
return item
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#hatFernkampfWaffeinHand(art) {
|
#hatFernkampfWaffeinHand(art) {
|
||||||
const item = this.actor.findEquipmentOnSlot("fernkampf")
|
const item = this.actor.findEquipmentOnSlot("fernkampf")
|
||||||
return item
|
return item != null
|
||||||
}
|
}
|
||||||
|
|
||||||
#hatSonderfertigkeitBeginnendMit(name) {
|
#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) {
|
#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() {
|
evaluate() {
|
||||||
let actionArray = [...this.#freeActions, ...this.#regularActions, ...this.#continuingActions]
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue