From c342d8d3663fb9485cc87e8b933c10bbec1accd0 Mon Sep 17 00:00:00 2001 From: macniel Date: Wed, 29 Oct 2025 00:51:28 +0100 Subject: [PATCH] fixes some glitches in display logic and also enables rolling the regeneration dice, closes the dialog afterwards. --- src/module/dialog/restingDialog.mjs | 93 ++++++++++++++++++------- src/templates/dialog/resting-dialog.hbs | 12 ++-- 2 files changed, 74 insertions(+), 31 deletions(-) diff --git a/src/module/dialog/restingDialog.mjs b/src/module/dialog/restingDialog.mjs index d73e4234..370ddf09 100644 --- a/src/module/dialog/restingDialog.mjs +++ b/src/module/dialog/restingDialog.mjs @@ -20,7 +20,9 @@ export class RestingDialog extends HandlebarsApplicationMixin(ApplicationV2) { closeOnSubmit: false, handler: RestingDialog.#onSubmitForm }, - actions: {} + actions: { + regenerate: RestingDialog.#regenerate + } } static PARTS = { @@ -159,11 +161,47 @@ export class RestingDialog extends HandlebarsApplicationMixin(ApplicationV2) { this.watch = false this.interrupted = false + this.lepModifier = this._actor.system.regeneration.lep.split("d6")[1] + this.aspModifier = this._actor.system.regeneration.asp.split("d6")[1] + + + this.regKoMod = this._actor.system.regeneration.ko + this.regInMod = this._actor.system.regeneration.in + + + } + + static async #regenerate() { + const context = this.#updateData() + const rollData = this._actor.getRollData() + + // regenerate LeP + + const targetBonusLep = rollData.attribute.ko.aktuell + context.koRoll + const targetBonusAsp = rollData.attribute.in.aktuell + context.inRoll + + const regenerationRoll = await new Roll("1d20[Konstitution]+1d20[Intuition]+1d20[Konstitution] + 2d6").evaluate() + + const [koRoll, _, inRoll, __, woundRoll, ___, lepAndAsp] = regenerationRoll.terms // the 3d20s + const plusLep = koRoll.results[0].result <= targetBonusLep ? 1 : 0 + const plusAsp = inRoll.results[0].result <= targetBonusAsp ? 1 : 0 + const woundHealed = woundRoll.results[0].result <= rollData.attribute.ko.aktuell + (context.woundMod * -1) + const [regLep, regAsp] = lepAndAsp.results // the 2d6s + + await regenerationRoll.toMessage({ + speaker: ChatMessage.getSpeaker({actor: this.actor}), + flavor: + `Regeneration in der Nacht:
+ LE: ${regLep.result} ${context.lepMod > 0 ? ("+" + context.lepMod) : ""} ${plusLep > 0 ? "+1" : ""}
+ AE: ${regAsp.result} ${context.aspMod > 0 ? ("+" + context.aspMod) : ""} ${plusAsp > 0 ? "+1" : ""}
+ Wunde: ${woundHealed ? "geheilt" : "nicht geheilt"}`, + rollMode: game.settings.get('core', 'rollMode'), + }) + this.close() } static async #onSubmitForm(event, form, formData) { event.preventDefault() - console.log(formData) this.restDuration = formData.object.length this.restingType = formData.object.type this.badWeather = formData.object.bad_weather @@ -182,11 +220,11 @@ export class RestingDialog extends HandlebarsApplicationMixin(ApplicationV2) { const elementWoundMod = this.element.querySelector('output[name="woundMod"]') const context = this.#updateData() - elementLepMod.value = context.lepMod - elementKoMod.value = context.koRoll - elementAspMod.value = context.aspMod - elementInMod.value = context.inRoll - elementWoundMod.value = context.woundMod + elementLepMod.value = context.lepModDisplay + elementKoMod.value = context.koRollDisplay + elementAspMod.value = context.aspModDisplay + elementInMod.value = context.inRollDisplay + elementWoundMod.value = context.woundModDisplay } #updateData(context = {}) { @@ -225,10 +263,12 @@ export class RestingDialog extends HandlebarsApplicationMixin(ApplicationV2) { } if (this.woundTreated) { - context.woundMod = `1w20-${this.woundRegenerationModifier ?? 0}` + context.woundModDisplay = `1w20-${this.woundRegenerationModifier ?? 0}` + context.woundMod = this.woundRegenerationModifier ?? 0 } else { if (context.hasWounds) { - context.woundMod = `1w20+${context.wounds * 3}` + context.woundModDisplay = `1w20+${context.wounds * 3}` + context.woundMod = context.wounds * 3 } } @@ -256,38 +296,41 @@ export class RestingDialog extends HandlebarsApplicationMixin(ApplicationV2) { } } - const [lepDieAmount, lepModifier] = this._actor.system.regeneration.lep.split("d6") - const [aspDieAmount, aspModifier] = this._actor.system.regeneration.asp.split("d6") + const lepMod = (Number(this.lepModifier) + (lepRestModifier)) ?? 0 + const aspMod = (Number(this.aspModifier) + (aspRestModifier)) ?? 0 - const lepMod = (Number(lepModifier) + (lepRestModifier ?? "")) - const aspMod = (Number(aspModifier) + (aspRestModifier ?? "")) + context.lepMod = lepMod if (lepMod == 0) { - context.lepMod = lepDieAmount + "d6" + context.lepModDisplay = "1w6" } else if (lepMod > 0) { - context.lepMod = lepDieAmount + "d6+" + lepMod + context.lepModDisplay = "1w6+" + lepMod } else { - context.lepMod = lepDieAmount + "d6" + lepMod + context.lepModDisplay = "1w6" + lepMod } + context.aspMod = aspMod if (aspMod == 0) { - context.aspMod = aspDieAmount + "d6" + context.aspModDisplay = "1w6" } else if (lepMod > 0) { - context.aspMod = aspDieAmount + "d6+" + aspMod + context.aspModDisplay = "1w6+" + aspMod } else { - context.aspMod = aspDieAmount + "d6" + aspMod + context.aspModDisplay = "1w6" + aspMod + } - if (this._actor.system.regeneration.ko < 0) { - context.koRoll = `1w20${this._actor.system.regeneration.ko}` + context.koRoll = this.regKoMod + if (this.regKoMod < 0) { + context.koRollDisplay = `1w20${this.regKoMod}` } else { - context.koRoll = `1w20+${this._actor.system.regeneration.ko}` + context.koRollDisplay = `1w20+${this.regKoMod}` } - if (this._actor.system.regeneration.in < 0) { - context.inRoll = `1w20${this._actor.system.regeneration.in}` + context.inRoll = this.regInMod + if (this.regInMod < 0) { + context.inRollDisplay = `1w20${this.regInMod}` } else { - context.inRoll = `1w20+${this._actor.system.regeneration.in}` + context.inRollDisplay = `1w20+${this.regInMod}` } console.log(this, context) diff --git a/src/templates/dialog/resting-dialog.hbs b/src/templates/dialog/resting-dialog.hbs index 4cfdc476..87cb1b60 100644 --- a/src/templates/dialog/resting-dialog.hbs +++ b/src/templates/dialog/resting-dialog.hbs @@ -53,23 +53,23 @@ Modifikatoren
LeP-Regeneration - {{lepMod}} + {{lepModDisplay}} KO Wurf - {{koRoll}} + {{koRollDisplay}} {{#if hasAsP}} AsP-Regeneration - {{aspMod}} + {{aspModDisplay}} IN Wurf - {{inRoll}} + {{inRollDisplay}} {{/if}} {{#if hasWounds}} Wunden-Heilung - {{woundMod}} + {{woundModDisplay}} {{/if}}
- + \ No newline at end of file