From 53bff7a4a696799d4b65cebfd26d8f493a48cb85 Mon Sep 17 00:00:00 2001
From: Sven Balzer <4653051+Kyuusokuna@users.noreply.github.com>
Date: Tue, 4 Feb 2025 22:59:44 +0100
Subject: [PATCH] add dialog to select Trefferzone on damage application
---
src/Dialogs/Trefferzone.hbs | 12 ++++++++++++
src/main.mjs | 16 ++++++++++++++--
2 files changed, 26 insertions(+), 2 deletions(-)
create mode 100644 src/Dialogs/Trefferzone.hbs
diff --git a/src/Dialogs/Trefferzone.hbs b/src/Dialogs/Trefferzone.hbs
new file mode 100644
index 0000000..93cf43d
--- /dev/null
+++ b/src/Dialogs/Trefferzone.hbs
@@ -0,0 +1,12 @@
+
+
+
diff --git a/src/main.mjs b/src/main.mjs
index 32fab75..abcde94 100644
--- a/src/main.mjs
+++ b/src/main.mjs
@@ -139,7 +139,7 @@ class DSA41_ChatMessage extends ChatMessage {
}
for (const element of html.querySelectorAll("[data-action]")) {
- element.addEventListener("click", event => {
+ element.addEventListener("click", async event => {
const target = event.target;
const action = target.dataset.action;
if (action === null) return;
@@ -151,7 +151,17 @@ class DSA41_ChatMessage extends ChatMessage {
const target_actor = fromUuidSync(target_actor_id);
if (!target_actor) return;
- target_actor.update({ "system.lebenspunkte.aktuell": target_actor.system.lebenspunkte.aktuell - this.rolls[0].total });
+ const dialog_data = await DSA41_Dialog.wait("Trefferzone", { window: {title: "Trefferzone"} });
+ const trefferzone = dialog_data.trefferzone;
+
+ const rolled_damage = this.rolls[0].total;
+ const target_hp = target_actor.system.lebenspunkte.aktuell;
+ const target_rs = target_actor.system.computed.kampf.ruestungen_gesamt[trefferzone];
+
+ const damage = Math.max(rolled_damage - target_rs, 0);
+ const new_hp = target_hp - damage;
+
+ target_actor.update({ "system.lebenspunkte.aktuell": new_hp });
}
});
}
@@ -747,6 +757,8 @@ class DSA41_Dialog extends DSA41_ApplicationMixin(ApplicationV2) {
FernkampfAttacke: { template: "systems/dsa-4th-edition/src/Dialogs/FernkampfAttacke.hbs" },
FernkampfTrefferpunkte: { template: "systems/dsa-4th-edition/src/Dialogs/FernkampfTrefferpunkte.hbs" },
+ Trefferzone: { template: "systems/dsa-4th-edition/src/Dialogs/Trefferzone.hbs" },
+
footer: { template: "templates/generic/form-footer.hbs" },
};