From 86f73a96d0d8205f0a6f0814d07f65e34ce035d0 Mon Sep 17 00:00:00 2001 From: Putty Date: Fri, 5 Sep 2025 08:34:20 +0000 Subject: [PATCH] Automated exhausted condition --- system/scripts/actor.js | 15 +++++++++++++++ system/scripts/gm/gm-toolbox.js | 4 +++- system/scripts/types.js | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 system/scripts/types.js diff --git a/system/scripts/actor.js b/system/scripts/actor.js index e6da4a9..05e842a 100644 --- a/system/scripts/actor.js +++ b/system/scripts/actor.js @@ -188,6 +188,21 @@ export class ActorL5r5e extends Actor { return this._updateActorFromAdvancement(item, false); } + /** + * @type {import("./types").Condition} + * + * Remove conditions by known string ids + * @param conditions {Set} + * @returns {Promise} + */ + async removeConditions(conditions) { + const effectsToRemove = this.statuses.intersection(conditions); + const idsToRemove = this.effects.contents + .filter(effect => effect.statuses.isSubsetOf(effectsToRemove)) + .map(effect => effect.id); + await this.deleteEmbeddedDocuments("ActiveEffect", idsToRemove); + } + /** * Alter Actor skill/ring from a advancement * @param {Item} item diff --git a/system/scripts/gm/gm-toolbox.js b/system/scripts/gm/gm-toolbox.js index d08d904..8201799 100644 --- a/system/scripts/gm/gm-toolbox.js +++ b/system/scripts/gm/gm-toolbox.js @@ -205,6 +205,7 @@ export class GmToolbox extends HandlebarsApplicationMixin(ApplicationV2) { } }, }); + await actor.removeConditions(new Set(["exhausted"])); } GmToolbox.#uiNotification(allActors, "sleep"); @@ -216,7 +217,8 @@ export class GmToolbox extends HandlebarsApplicationMixin(ApplicationV2) { static async #onSceneEnd(event) { const allActors = event.button !== 0; for await (const actor of game.actors.contents) { - if (!GmToolbox.#updatableCharacter(allActors, actor)) { + if (!GmToolbox.#updatableCharacter(allActors, actor) + || actor.statuses.has("exhausted")) { continue; } diff --git a/system/scripts/types.js b/system/scripts/types.js new file mode 100644 index 0000000..76ffe04 --- /dev/null +++ b/system/scripts/types.js @@ -0,0 +1,3 @@ +/** + * @typedef {"afflicted" | "bleeding" | "burning" | "compromised" | "dazed" | "disoriented" | "dying" | "enraged" | "exhausted" | "immobilized" | "incapacitated" | "intoxicated" | "prone" | "silenced" | "unconscious" | "lightlyWoundedFire" | "lightlyWoundedWater" | "lightlyWoundedAir" | "lightlyWoundedEarth" | "lightlyWoundedVoid" | "severelyWoundedFire" | "severelyWoundedWater" | "severelyWoundedAir" | "severelyWoundedEarth" | "severelyWoundedVoid"} Condition + */ \ No newline at end of file