adds combat-awareness to attacks/defenses/spells/liturgies

main
macniel 2026-02-07 10:32:48 +01:00
parent f8d101bfe3
commit 469025ca05
10 changed files with 110 additions and 86 deletions

View File

@ -59,6 +59,9 @@ export class CombatActionDialog extends HandlebarsApplicationMixin(ApplicationV2
this._defenseManeuverId = null this._defenseManeuverId = null
this._actionManager = new ActionManager(this._actor) this._actionManager = new ActionManager(this._actor)
CombatActionDialog._instance = this CombatActionDialog._instance = this
if (!game.scenes.current?.grid.units) {
this._targetId = actor._id
}
} }
static _instance = null static _instance = null
@ -106,7 +109,7 @@ export class CombatActionDialog extends HandlebarsApplicationMixin(ApplicationV2
const maneuver = CombatActionDialog._instance.#evaluateManeuvers().find(p => p.id === this._defenseManeuverId) const maneuver = CombatActionDialog._instance.#evaluateManeuvers().find(p => p.id === this._defenseManeuverId)
const weapon = this._actor.itemTypes["Equipment"].find(p => p._id === this._weaponId) 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 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 target = game.actors.get(game.scenes.current.tokens.find(p => p._id === this._targetId)?.actorId) ?? this._actor
if (maneuver.cost !== ActionManager.CONTINUING) { if (maneuver.cost !== ActionManager.CONTINUING) {
this._actor.rollAttack({ this._actor.rollAttack({
weapon: this._weaponId, weapon: this._weaponId,
@ -123,10 +126,15 @@ export class CombatActionDialog extends HandlebarsApplicationMixin(ApplicationV2
return true return true
} else { // push into cooldown queue } else { // push into cooldown queue
const cooldowns = this._actor.system.cooldowns const cooldowns = this._actor.system.cooldowns
let currentCooldown = 0
if (game.combats.size === 0) { // no combat started
currentCooldown = maneuver.cooldown({weapon, skill, target, mod: this._mod})
}
/** @type Cooldown */ /** @type Cooldown */
const newCooldown = { const newCooldown = {
start: maneuver.cooldown({weapon, skill, target, mod: this._mod}), start: maneuver.cooldown({weapon, skill, target, mod: this._mod}),
current: 0, current: currentCooldown,
data: { data: {
cssClass: "Kampf", cssClass: "Kampf",
weapon: this._weaponId, weapon: this._weaponId,
@ -138,6 +146,7 @@ export class CombatActionDialog extends HandlebarsApplicationMixin(ApplicationV2
circumstance: this._circumstance, circumstance: this._circumstance,
penalty: this._penalty, penalty: this._penalty,
targetNumber: this._targetNumber, targetNumber: this._targetNumber,
castingTime: maneuver.cooldown({weapon, skill, target, mod: this._mod}),
modDescription: maneuver?.modDescription?.replace("{}", "" + this._mod) ?? "" modDescription: maneuver?.modDescription?.replace("{}", "" + this._mod) ?? ""
} }
} }
@ -261,7 +270,7 @@ export class CombatActionDialog extends HandlebarsApplicationMixin(ApplicationV2
const manager = this._actionManager const manager = this._actionManager
const weapon = this._actor.itemTypes["Equipment"].find(p => p._id === this._weaponId) 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 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 target = game.actors.get(game.scenes.current.tokens.find(p => p._id === this._targetId)?.actorId) ?? this._actor
this._maneuvers = manager.evaluate({ this._maneuvers = manager.evaluate({
target, target,
weapon, weapon,
@ -293,9 +302,14 @@ export class CombatActionDialog extends HandlebarsApplicationMixin(ApplicationV2
if (context.distanceUnit && this._actor.getActiveTokens()[0]?.id) { if (context.distanceUnit && this._actor.getActiveTokens()[0]?.id) {
context.tokenDistances = this.#evaluateDistances() context.tokenDistances = this.#evaluateDistances()
context.hasTokens = true
} else {
context.tokenDistances = []
context.hasTokens = false
}
context.weapons = this.#evaluateWeapons() context.weapons = this.#evaluateWeapons()
if (this._targetId && this._weaponId && this._skillId) { if ( (this._targetId || !context.hasTokens) && this._weaponId && this._skillId) {
context.maneuver = this.#evaluateManeuvers() context.maneuver = this.#evaluateManeuvers()
} }
const maneuver = this._maneuvers?.find(p => p.id === this._defenseManeuverId) const maneuver = this._maneuvers?.find(p => p.id === this._defenseManeuverId)
@ -330,10 +344,6 @@ export class CombatActionDialog extends HandlebarsApplicationMixin(ApplicationV2
context.ready = false context.ready = false
} }
return context return context
} else {
ui.notifications.error(`Feature funktioniert nur wenn der Akteur ein Token auf der aktuellen Szene hat`);
}
} }
#update(context) { #update(context) {

View File

@ -236,9 +236,6 @@ export class DefenseActionDialog extends HandlebarsApplicationMixin(ApplicationV
const context = await super._prepareContext(options) const context = await super._prepareContext(options)
context.actor = this._actor context.actor = this._actor
context.distanceUnit = game.scenes.current.grid.units
if (this._actor.getActiveTokens()[0]?.id) {
context.weapons = this.#evaluateWeapons() context.weapons = this.#evaluateWeapons()
@ -275,10 +272,6 @@ export class DefenseActionDialog extends HandlebarsApplicationMixin(ApplicationV
} }
return context return context
} else {
ui.notifications.error(`Feature funktioniert nur wenn der Akteur ein Token auf der aktuellen Szene hat`);
}
} }
#update(context) { #update(context) {

View File

@ -157,6 +157,7 @@ export class LiturgyDialog extends HandlebarsApplicationMixin(ApplicationV2) {
eigenschaft3: "ch" eigenschaft3: "ch"
}).evaluate("publicroll").then(result => { }).evaluate("publicroll").then(result => {
const context = { const context = {
...data,
liturgy: data.title, liturgy: data.title,
lkw: data.taw, lkw: data.taw,
mod: data.mod, mod: data.mod,
@ -185,9 +186,14 @@ export class LiturgyDialog extends HandlebarsApplicationMixin(ApplicationV2) {
}) })
} }
let currentCooldown = 0
if (game.combats.size === 0) { // no combat started
currentCooldown = castingTime
}
cooldowns.push({ cooldowns.push({
start: castingTime, start: castingTime,
current: 0, current: currentCooldown,
data: { data: {
cssClass: "Karmal", cssClass: "Karmal",
title: this._liturgy.name, title: this._liturgy.name,
@ -205,6 +211,7 @@ export class LiturgyDialog extends HandlebarsApplicationMixin(ApplicationV2) {
eigenschaft2: "in", eigenschaft2: "in",
eigenschaft3: "ch", eigenschaft3: "ch",
circumstance: circumstance, circumstance: circumstance,
castingTime: castingTime,
maneuver: m.toString() maneuver: m.toString()
} }

View File

@ -209,7 +209,7 @@ export class SpellDialog extends HandlebarsApplicationMixin(ApplicationV2) {
} }
let message = this._spell.system.wirkung let message = this._spell.system.wirkung
if (this._activeVariants.length > 0) { if (this._activeVariants?.length > 0 ?? false) {
message += "<hr/>" message += "<hr/>"
message += this._activeVariants.map(v => v.name).join(", ") message += this._activeVariants.map(v => v.name).join(", ")
} }
@ -231,9 +231,14 @@ export class SpellDialog extends HandlebarsApplicationMixin(ApplicationV2) {
message += "<hr/>" + this.zfp + " ZfP*<br/>" + this._spell.system.zfw + " ZfW" message += "<hr/>" + this.zfp + " ZfP*<br/>" + this._spell.system.zfw + " ZfW"
let currentCooldown = 0
if (game.combats.size === 0) { // no combat started
currentCooldown = this.castingTime
}
cooldowns.push({ cooldowns.push({
start: this.castingTime, start: this.castingTime,
current: 0, current: currentCooldown,
data: { data: {
cssClass: "Magisch", cssClass: "Magisch",
title: this._spell.name, title: this._spell.name,
@ -242,6 +247,7 @@ export class SpellDialog extends HandlebarsApplicationMixin(ApplicationV2) {
actorId: this._actor._id, actorId: this._actor._id,
spellId: this._spell._id, spellId: this._spell._id,
message, message,
castingTime: this.castingTime,
maneuver: m.toString() maneuver: m.toString()
} }
@ -270,6 +276,7 @@ export class SpellDialog extends HandlebarsApplicationMixin(ApplicationV2) {
const context = { const context = {
spell: this._spell, spell: this._spell,
castingTime : this.castingTime,
zfp: result.tap, zfp: result.tap,
ergebnis: [ ergebnis: [

View File

@ -493,6 +493,7 @@ export class Character extends Actor {
}) })
const context = { const context = {
...data,
weapon: weapon.name, weapon: weapon.name,
maneuver, maneuver,
target: this.name, target: this.name,
@ -539,6 +540,7 @@ export class Character extends Actor {
}) })
const context = { const context = {
...data,
weapon: weapon.name, weapon: weapon.name,
maneuver, maneuver,
target: target.name, target: target.name,

View File

@ -595,7 +595,7 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
weapon = this.document.itemTypes["Equipment"].find(p => p._id === cooldown.data.weapon) weapon = this.document.itemTypes["Equipment"].find(p => p._id === cooldown.data.weapon)
tooltip += `<br/>Waffe: ${weapon.name}` tooltip += `<br/>Waffe: ${weapon.name}`
} }
if (cooldown.data.target) { if (cooldown.data.target && game.scenes.current.tokens.length > 0) {
target = game.actors.get(game.scenes.current.tokens.find(p => p._id === cooldown.data.target).actorId) target = game.actors.get(game.scenes.current.tokens.find(p => p._id === cooldown.data.target).actorId)
tooltip += `<br/>Ziel: ${target.name}` tooltip += `<br/>Ziel: ${target.name}`
} }

View File

@ -5,6 +5,7 @@
<div>Gewürfelt: {{die}}</div> <div>Gewürfelt: {{die}}</div>
<div>Erschwernis: {{circumstance}}</div> <div>Erschwernis: {{circumstance}}</div>
<div>Modifikation: {{mod}}</div> <div>Modifikation: {{mod}}</div>
<div>Dauer in Aktionen: {{castingTime}}</div>
<hr> <hr>
{{#if missing}} {{#if missing}}
<div>Gefehlt: {{missing}} {{#if fumble}}Patzer{{/if}}</div> <div>Gefehlt: {{missing}} {{#if fumble}}Patzer{{/if}}</div>

View File

@ -3,6 +3,7 @@
<div> <div>
<div>{{liturgy}} (LkP*: {{lkp}})</div> <div>{{liturgy}} (LkP*: {{lkp}})</div>
<div>Modifiziert: {{mod}}</div> <div>Modifiziert: {{mod}}</div>
<div>Dauer in Aktionen: {{castingTime}}</div>
<div>Gewürfelt:</div> <div>Gewürfelt:</div>
<hr> <hr>
{{#if missing}} {{#if missing}}

View File

@ -3,6 +3,7 @@
<div> <div>
<div>{{spell.name}} (ZfP*: {{zfp}})</div> <div>{{spell.name}} (ZfP*: {{zfp}})</div>
<div>Modifiziert: {{mod}}</div> <div>Modifiziert: {{mod}}</div>
<div>Zauberdauer: {{castingTime}}</div>
<div>Gewürfelt:</div> <div>Gewürfelt:</div>
<section class="die"> <section class="die">
{{#each ergebnis}} {{#each ergebnis}}

View File

@ -1,6 +1,8 @@
<section> <section>
{{#if hasTokens}}
<fieldset> <fieldset>
<legend>Ziel auswählen</legend> <legend>Ziel auswählen</legend>
<ul> <ul>
@ -13,7 +15,7 @@
</ul> </ul>
</fieldset> </fieldset>
{{/if}}
<fieldset> <fieldset>
<legend>Waffe auswählen</legend> <legend>Waffe auswählen</legend>
<ul> <ul>