From 3c7426bf56adb25e6b15d596e5bfa8c8e1b4dc9c Mon Sep 17 00:00:00 2001 From: macniel Date: Wed, 22 Oct 2025 23:57:40 +0200 Subject: [PATCH] adds benefit display of mod value --- src/module/dialog/combatAction.mjs | 41 +++++++++++++++-- src/module/sheets/actions/action-manager.mjs | 48 ++++++++++++-------- src/templates/dialog/combat-action.hbs | 1 + 3 files changed, 65 insertions(+), 25 deletions(-) diff --git a/src/module/dialog/combatAction.mjs b/src/module/dialog/combatAction.mjs index 45c44925..8e07001c 100644 --- a/src/module/dialog/combatAction.mjs +++ b/src/module/dialog/combatAction.mjs @@ -81,6 +81,19 @@ export class CombatActionDialog extends HandlebarsApplicationMixin(ApplicationV2 static async #onSubmitForm(event, form, formData) { event.preventDefault() + const weapon = this._actor.itemTypes["Equipment"].find(p => p._id === this._weaponId) + const skill = this._actor.itemTypes["Skill"].find(p => p._id === this._skillId) + const target = game.actors.get(game.scenes.current.tokens.find(p => p._id === this._targetId).actorId) + + const roll = new Roll("1d20cs<" + this._targetNumber) + const evaluated1 = (await roll.evaluate()) + + await evaluated1.toMessage({ + speaker: ChatMessage.getSpeaker({actor: this._actor}), + flavor: `Attackiert ${target.name} mit ${weapon.name} (${skill.name})
${this._modDescription}`, + rollMode: "publicroll", + }) + return true } _configureRenderOptions(options) { @@ -186,7 +199,7 @@ export class CombatActionDialog extends HandlebarsApplicationMixin(ApplicationV2 const manager = this._actionManager const weapon = this._actor.itemTypes["Equipment"].find(p => p._id === this._weaponId) const skill = this._actor.itemTypes["Skill"].find(p => p._id === this._skillId) - const target = game.actors.get(this._targetId) + const target = game.actors.get(game.scenes.current.tokens.find(p => p._id === this._targetId).actorId) this._maneuvers = manager.evaluate({ target, weapon, @@ -201,6 +214,7 @@ export class CombatActionDialog extends HandlebarsApplicationMixin(ApplicationV2 cost: action.cost, penalty: action.eval?.mod ?? 0, mod: action.mod, + modDescription: action.modDescription } }).sort((a, b) => (a.isSelected ? 0 : 1) - (b.isSelected ? 0 : 1)) return this._maneuvers @@ -239,15 +253,32 @@ export class CombatActionDialog extends HandlebarsApplicationMixin(ApplicationV2 #update(context) { const target = this.element.querySelector(".actions button .value") + const targetDescription = this.element.querySelector(".modResult") const at = Number(context.targetNumber) const maneuver = this._maneuvers?.find(p => p.id === this._combatManeuverId) const mod = Number(this.element.querySelector('[name="mod"]').value) - const penalty = (maneuver?.penalty ?? 0) + (maneuver?.mod?.(mod) ?? 0) ?? 0 + const penalty = 0 - (maneuver?.penalty ?? 0) + (maneuver?.mod?.(mod) ?? 0) ?? 0 const circumstance = Number(this.element.querySelector('[name="circumstance"]').value) this.element.querySelector('[name="penalty"]').value = penalty + circumstance - const result = (at + circumstance + penalty) ?? false - if (result) { - target.textContent = `(${result})` + const result = (at + circumstance + penalty) + + this._circumstance = circumstance + this._penalty = penalty + this._targetNumber = result + this._mod = mod + this._modDescription = maneuver?.modDescription?.replace("{}", "" + mod) ?? "" + + target.textContent = `(${result})` + targetDescription.textContent = this._modDescription + + if (result <= 0) { + context.ready = false + this.element.querySelector(".actions button").classList.remove("ready") + this.element.querySelector(".actions button").setAttribute("disabled", true) + } else { + context.ready = true + this.element.querySelector(".actions button").classList.add("ready") + this.element.querySelector(".actions button").removeAttribute("disabled") } } diff --git a/src/module/sheets/actions/action-manager.mjs b/src/module/sheets/actions/action-manager.mjs index c5bf6e16..d418236c 100644 --- a/src/module/sheets/actions/action-manager.mjs +++ b/src/module/sheets/actions/action-manager.mjs @@ -75,14 +75,14 @@ export class ActionManager { type: ActionManager.ATTACK, cost: ActionManager.REGULAR, source: ActionManager.DEFAULT, - eval: (options) => this.#hatWaffeinHand() && !this.#hatFernkampfWaffeinHand() + eval: (options) => this.#hatWaffeinHand(options) }, { name: "Fernkampfangriff", type: ActionManager.ATTACK, cost: ActionManager.REGULAR, source: ActionManager.DEFAULT, - eval: (options) => this.#hatFernkampfWaffeinHand(), + eval: (options) => this.#hatFernkampfWaffeinHand(options), }, { name: "Angesagter Fernkampfangriff", // wird durch Scharfer Schuss aus SF ersetzt @@ -90,7 +90,7 @@ export class ActionManager { cost: ActionManager.CONTINUING, source: ActionManager.DEFAULT, eval: (options) => { - const step1 = this.#hatFernkampfWaffeinHand() + const step1 = this.#hatFernkampfWaffeinHand(options) const step2 = !this.#hatSonderfertigkeit("Scharfschütze", options) const step3 = this.#hatSonderfertigkeit("Scharfschütze", options) && !this.#evalSonderfertigkeitRequirements("Scharfschütze", options) if (step1 && (step2 || step3)) { @@ -107,7 +107,7 @@ export class ActionManager { cost: ActionManager.CONTINUING, source: ActionManager.SF, eval: (options) => { - const step1 = this.#hatFernkampfWaffeinHand() && this.#hatSonderfertigkeit("Scharfschütze", options) + const step1 = this.#hatFernkampfWaffeinHand(options) && this.#hatSonderfertigkeit("Scharfschütze", options) const step2WithBenefits = this.#evalSonderfertigkeitRequirements("Scharfschütze", options) if (step1 && step2WithBenefits ? step2WithBenefits.passes : false) { return step2WithBenefits @@ -122,7 +122,7 @@ export class ActionManager { type: ActionManager.INTERACTION, cost: ActionManager.CONTINUING, source: ActionManager.DEFAULT, - eval: (options) => this.#hatFernkampfWaffeinHand() + eval: (options) => this.#hatFernkampfWaffeinHand(options) }, { name: "Schnellschuss (Scharfschütze)", @@ -130,7 +130,7 @@ export class ActionManager { cost: ActionManager.CONTINUING, source: ActionManager.SF, eval: (options) => { - const step1 = this.#hatFernkampfWaffeinHand() && this.#hatSonderfertigkeit("Scharfschütze", options) + const step1 = this.#hatFernkampfWaffeinHand(options) && this.#hatSonderfertigkeit("Scharfschütze", options) const step2WithBenefits = this.#evalSonderfertigkeitRequirements("Scharfschütze", options) if (step1 && step2WithBenefits ? step2WithBenefits.passes : false) { return step2WithBenefits @@ -153,7 +153,7 @@ export class ActionManager { modDescription: "erschwert nächste AT vom Ziel um {}", mod: (value) => value, eval: (options) => { - const step1 = this.#hatWaffeinHand() && this.#hatSonderfertigkeit("Meisterparade", options) + const step1 = this.#hatWaffeinHand(options) && this.#hatSonderfertigkeit("Meisterparade", options) const step2WithBenefits = this.#evalSonderfertigkeitRequirements("Meisterparade", options) if (step1 && step2WithBenefits ? step2WithBenefits.passes : false) { return step2WithBenefits @@ -183,7 +183,7 @@ export class ActionManager { modDescription: "verringert PA des Ziels um {}", mod: (value) => value, eval: (options) => { - const step1 = this.#hatWaffeinHand() && this.#hatSonderfertigkeit("Finte", options) + const step1 = this.#hatWaffeinHand(options) && this.#hatSonderfertigkeit("Finte", options) const step2WithBenefits = this.#evalSonderfertigkeitRequirements("Finte", options) if (step1 && step2WithBenefits ? step2WithBenefits.passes : false) { return step2WithBenefits @@ -197,9 +197,9 @@ export class ActionManager { cost: ActionManager.REGULAR, source: ActionManager.DEFAULT, modDescription: "erhöht TP vom Angriff um {}", - mod: (value) => -(value), + mod: (value) => -(value * 2), eval: (options) => { - const step1 = !this.#hatFernkampfWaffeinHand() + const step1 = !this.#hatFernkampfWaffeinHand(options) const step2 = !this.#hatSonderfertigkeit("Wuchtschlag", options) const step3 = this.#hatSonderfertigkeit("Wuchtschlag", options) && !this.#evalSonderfertigkeitRequirements("Wuchtschlag", options) if (step1 && (step2 || step3)) { @@ -216,7 +216,7 @@ export class ActionManager { modDescription: "erhöht TP vom Angriff um {}", mod: (value) => -(value), eval: (options) => { - const step1 = !this.#hatFernkampfWaffeinHand() && this.#hatSonderfertigkeit("Wuchtschlag", options) + const step1 = !this.#hatFernkampfWaffeinHand(options) && this.#hatSonderfertigkeit("Wuchtschlag", options) const step2WithBenefits = this.#evalSonderfertigkeitRequirements("Wuchtschlag", options) if (step1 && step2WithBenefits ? step2WithBenefits.passes : false) { return step2WithBenefits @@ -230,7 +230,7 @@ export class ActionManager { cost: ActionManager.REGULAR, source: ActionManager.SF, eval: (options) => { - const step1 = !this.#hatFernkampfWaffeinHand() && this.#hatSonderfertigkeit("Betäubungsschlag", options) + const step1 = !this.#hatFernkampfWaffeinHand(options) && this.#hatSonderfertigkeit("Betäubungsschlag", options) const step2WithBenefits = this.#evalSonderfertigkeitRequirements("Betäubungsschlag", options) if (step1 && step2WithBenefits ? step2WithBenefits.passes : false) { return step2WithBenefits @@ -276,7 +276,7 @@ export class ActionManager { source: ActionManager.SF, eval: (options) => { const step1 = this.#hatMunition() - && this.#hatFernkampfWaffeinHand("Bogen", options) + && this.#hatFernkampfWaffeinHand(options) && this.#hatSonderfertigkeit("Schnellladen (Bogen)", options) const step2WithBenefits = this.#evalSonderfertigkeitRequirements("Schnellladen (Bogen)", options) if (step1 && step2WithBenefits ? step2WithBenefits.passes : false) { @@ -292,7 +292,7 @@ export class ActionManager { source: ActionManager.SF, eval: (options) => { const step1 = this.#hatMunition() - && this.#hatFernkampfWaffeinHand("Armbrust", options) + && this.#hatFernkampfWaffeinHand(options) && this.#hatSonderfertigkeit("Schnellladen (Armbrust)", options) const step2WithBenefits = this.#evalSonderfertigkeitRequirements("Schnellladen (Armbrust)", options) if (step1 && step2WithBenefits ? step2WithBenefits.passes : false) { @@ -332,9 +332,13 @@ export class ActionManager { ] - #hatWaffeinHand() { - const item = this.actor.findEquipmentOnSlot("links") ?? this.actor.findEquipmentOnSlot("rechts") - return item != null + #hatWaffeinHand(options) { + if (options) { + const item = this.actor.findEquipmentOnSlot("links") ?? this.actor.findEquipmentOnSlot("rechts") + return item == options.weapon + } else { + return this.actor.findEquipmentOnSlot("links") != null || this.actor.findEquipmentOnSlot("rechts") != null + } } #hatMunition() { @@ -342,9 +346,13 @@ export class ActionManager { return item != null } - #hatFernkampfWaffeinHand(art) { - const item = this.actor.findEquipmentOnSlot("fernkampf") - return item != null + #hatFernkampfWaffeinHand(options) { + if (options) { + const item = this.actor.findEquipmentOnSlot("fernkampf") + return item == options.weapon + } else { + return this.actor.findEquipmentOnSlot("fernkampf") != null + } } #hatSonderfertigkeitBeginnendMit(name, options) { diff --git a/src/templates/dialog/combat-action.hbs b/src/templates/dialog/combat-action.hbs index 0e39ef4c..e39875e7 100644 --- a/src/templates/dialog/combat-action.hbs +++ b/src/templates/dialog/combat-action.hbs @@ -50,6 +50,7 @@ +