finalises calculation for SpoMods

pull/67/head
macniel 2025-11-28 14:50:47 +01:00
parent 94a80eb321
commit cc60f9e57f
2 changed files with 62 additions and 31 deletions

View File

@ -18,66 +18,68 @@ export const leadingAttribute = {
"Zaubertänzer": "IN" "Zaubertänzer": "IN"
} }
/**
*
* @type {[String: {name: string, description: string, modFn: string, castTimeModFn: string, costModFn: string}]}
*/
export const spoModData = { export const spoModData = {
"Veränderte Technik": { "Veränderte Technik": {
name: "Veränderte Technik", name: "Veränderte Technik",
description: "Verändert die Technik", description: "Verändert die Technik",
mod: -7, modFn: "mod -7",
castTimeMod: 3, castTimeModFn: "castTime +3",
castTimeMode: "Addition" costModFn: "cost",
}, },
"Veränderte Technik, zentral": { "Veränderte Technik, zentral": {
name: "Veränderte Technik, zentral", name: "Veränderte Technik, zentral",
description: "Verändert die Technik", description: "Verändert die Technik",
mod: -12, modFn: "mod -12",
castTimeMod: 3, castTimeModFn: "castTime +3",
castTimeMode: "Addition" costModFn: "cost",
}, },
"Halbierte Zauberdauer": { "Halbierte Zauberdauer": {
name: "Halbierte Zauberdauer", name: "Halbierte Zauberdauer",
description: "Halbiert die Zauberdauer für eine Erschwernis von 5", description: "Halbiert die Zauberdauer für eine Erschwernis von 5",
mod: -5, modFn: "mod -5",
castTimeMod: 0.5, castTimeModFn: "castTime / 2",
castTimeMode: "Multiply" costModFn: "cost",
}, },
"Verdoppelte Zauberdauer": { "Verdoppelte Zauberdauer": {
name: "Verdoppelte Zauberdauer", name: "Verdoppelte Zauberdauer",
description: "Verdoppelt die Zauberdauer für eine Erleichterung von 3", description: "Verdoppelt die Zauberdauer für eine Erleichterung von 3",
mod: 3, modFn: "mod +3",
castTimeMod: 2, castTimeModFn: "castTime *2",
castTimeMode: "Multiply" costModFn: "cost",
}, },
"Erzwingen": { "Erzwingen": {
name: "Erzwingen", name: "Erzwingen",
description: "Verringert Erschwernis um 1 je quadrierten AsP Punkt", description: "Verringert Erschwernis um 1 je quadrierten AsP Punkt",
mod: -1, modFn: "mod +1",
castTimeMod: 1, castTimeModFn: "castTime +1",
castTimeMode: "Addition" costModFn: "cost ** cost",
}, },
"Kosten einsparen": { "Kosten einsparen": {
name: "Kosten einsparen", name: "Kosten einsparen",
description: "Reduziert die Kosten des Zaubers um 10% für jede zusätzlich aufgewendete Aktion", description: "Reduziert die Kosten des Zaubers um 10% für jede zusätzlich aufgewendete Aktion",
mod: -3, modFn: "mod -3",
castingCosts: 0.1, castTimeModFn: "castTime +1",
castingCostsMode: "Multiply", costModFn: "cost * 0.1",
castTimeMod: 1,
castTimeMode: "Addition"
}, },
// more to come // more to come
"Vergrößerung von Reichweite oder Wirkungsradius": { "Vergrößerung von Reichweite oder Wirkungsradius": {
name: "Vergrößerung von Reichweite oder Wirkungsradius", name: "Vergrößerung von Reichweite oder Wirkungsradius",
description: "Vergrößert die Reichweite oder wenn möglich den Wirkungsradius auf kosten von Aktionen", description: "Vergrößert die Reichweite oder wenn möglich den Wirkungsradius auf kosten von Aktionen",
mod: -5, modFn: "mod -5",
castTimeMod: 1, castTimeModFn: "castTime +1",
castTimeMode: "Addition" costModFn: "cost",
}, },
"Verkleinerung von Reichweite oder Wirkungsradius": { "Verkleinerung von Reichweite oder Wirkungsradius": {
name: "Verkleinerung von Reichweite oder Wirkungsradius", name: "Verkleinerung von Reichweite oder Wirkungsradius",
description: "Verkleinert die Reichweite oder wenn möglich den Wirkungsradius auf kosten von Aktionen", description: "Verkleinert die Reichweite oder wenn möglich den Wirkungsradius auf kosten von Aktionen",
mod: -3, modFn: "mod -3",
castTimeMod: 1, castTimeModFn: "castTime +1",
castTimeMode: "Addition" costModFn: "cost",
}, },

View File

@ -72,6 +72,7 @@ export class SpellDialog extends HandlebarsApplicationMixin(ApplicationV2) {
this._costModel.variables.forEach(v => this._costMutators[v] = 0) this._costModel.variables.forEach(v => this._costMutators[v] = 0)
this._castTimeModel.variables.forEach(v => this._castTimeMutators[v] = 0) this._castTimeModel.variables.forEach(v => this._castTimeMutators[v] = 0)
this.cost = this.normalizeCastingCost() ?? 0 this.cost = this.normalizeCastingCost() ?? 0
this.castingTime = this.#normalizeCastingTime(this._spell)
} }
/** /**
@ -127,9 +128,8 @@ export class SpellDialog extends HandlebarsApplicationMixin(ApplicationV2) {
let castTimeMutators = foundry.utils.expandObject(formData.object)["castTimeMutators"] let castTimeMutators = foundry.utils.expandObject(formData.object)["castTimeMutators"]
if (castTimeMutators) { this._castTimeMutators = castTimeMutators ?? {}
this._castTimeMutators = castTimeMutators
}
this.mod = 0 this.mod = 0
this._activeVariants = Object.entries(this._variants) this._activeVariants = Object.entries(this._variants)
@ -143,8 +143,37 @@ export class SpellDialog extends HandlebarsApplicationMixin(ApplicationV2) {
}) })
this.castingTime = this.#normalizeCastingTime(this._spell, this._castTimeMutators)
this._spomods = foundry.utils.expandObject(formData.object)["spoMods"] this._spomods = foundry.utils.expandObject(formData.object)["spoMods"]
// eval spomods
let totalMod = this.mod
let totalCost = this.cost
let totalCastingTime = Number(this.castingTime)
Object.entries(this._spomods).forEach(([modName, times]) => {
const actualMod = spoModData[modName]
for (let i = 0; i < times; i++) {
const ctfn = new Function("castTime", "return " + actualMod.castTimeModFn)
totalCastingTime = ctfn(totalCastingTime)
const cfn = new Function("cost", "return " + actualMod.costModFn)
totalCost = cfn(totalCost)
const zmfn = new Function("mod", "return " + actualMod.modFn)
totalMod = zmfn(totalMod)
}
})
this.mod = totalMod
this.cost = totalCost
this.castingTime = totalCastingTime
this.render({parts: ["form"]}) this.render({parts: ["form"]})
} }
@ -205,7 +234,7 @@ export class SpellDialog extends HandlebarsApplicationMixin(ApplicationV2) {
let actualCastingTime = 0 let actualCastingTime = 0
let formula = spell.system.zauberdauer.additionalFormula let formula = spell.system.zauberdauer.additionalFormula
if (formula) { if (formula) {
Object.entries(this._castTimeMutators).forEach(([variableName, variableValue]) => { Object.entries(additionalFormulaData).forEach(([variableName, variableValue]) => {
console.log(variableName, variableValue) console.log(variableName, variableValue)
formula = formula.replaceAll(variableName, variableValue) formula = formula.replaceAll(variableName, variableValue)
}) })
@ -253,7 +282,7 @@ export class SpellDialog extends HandlebarsApplicationMixin(ApplicationV2) {
context.modResult = this._spell.system.zfw + this.mod context.modResult = this._spell.system.zfw + this.mod
context.penalty = (this.mod > 0 ? "+" : "") + this.mod context.penalty = (this.mod > 0 ? "+" : "") + this.mod
context.displayModResult = (context.modResult > 0 ? "+" : "") + context.modResult context.displayModResult = (context.modResult > 0 ? "+" : "") + context.modResult
context.castingTime = this.#normalizeCastingTime(this._spell) context.castingTime = this.castingTime
context.ready = true context.ready = true
// variable probe (should consider Achaz as they can replace one KL in a KL/KL/* spell with IN // variable probe (should consider Achaz as they can replace one KL in a KL/KL/* spell with IN