From 137500e6c8886a599763cb3f883ce0637ca804ed Mon Sep 17 00:00:00 2001 From: Jonas Karlsson Date: Thu, 4 Jul 2024 22:00:27 +0200 Subject: [PATCH] fix: Applying Persistent Damage and/or Persistent Healing works again. --- src/module/feature/damageHandler/index.ts | 12 +++++------- src/module/hooks.ts | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/module/feature/damageHandler/index.ts b/src/module/feature/damageHandler/index.ts index 6b945f2b5..6f7a14ffc 100644 --- a/src/module/feature/damageHandler/index.ts +++ b/src/module/feature/damageHandler/index.ts @@ -139,20 +139,18 @@ export async function noOrSuccessfulFlatcheck(message: ChatMessagePF2e): Promise } export function persistentDamage(message) { - const flavor = message.flavor; - const persistentFlavor = flavor?.includes("" + game.i18n.localize("PF2E.ConditionTypePersistent")); if ( shouldIHandleThisMessage( message, ["all", "players"].includes(String(game.settings.get(MODULENAME, "applyPersistentAllow"))), ["all", "gm"].includes(String(game.settings.get(MODULENAME, "applyPersistentAllow"))), ) && - flavor && - persistentFlavor && + message.flavor && + message.flavor?.includes("" + game.i18n.localize("PF2E.ConditionTypePersistent")) && message.speaker.token && message.rolls && message.rolls.length > 0 && - message.id === game.messages.contents.pop()?.id && + message.id === game.messages.contents.slice(-1, game.messages.size)[0].id && game.actors && (message.getFlag(MODULENAME, "persistentHandled") ?? true) ) { @@ -170,7 +168,7 @@ export function persistentDamage(message) { if (actor && game.settings.get(MODULENAME, "applyPersistentDamageRecoveryRoll")) { const condition = actor.conditions .filter((condition) => condition.slug === "persistent-damage") - .find((condition) => flavor.includes(condition.name)); + .find((condition) => message.flavor.includes(condition.name)); if (condition) { // TODO Update the message to remove the recovery roll button, instead include the result in the message (and remove the message the following line creates.) condition.rollRecovery().then(); @@ -193,7 +191,7 @@ export function persistentHealing(message, enabled: boolean) { game.combats.active && game.combats.active.combatant && game.combats.active.combatant.actor && - message.id === game.messages.contents.pop()?.id && + message.id === game.messages.contents.slice(-1, game.messages.size)[0].id && (message.getFlag(MODULENAME, "persistentHandled") ?? true) ) { const token = game.combats.active.combatant.token; diff --git a/src/module/hooks.ts b/src/module/hooks.ts index 68e3e8947..377d377ac 100644 --- a/src/module/hooks.ts +++ b/src/module/hooks.ts @@ -115,16 +115,14 @@ function deprecatedDyingHandlingRenderChatMessageHook(message: ChatMessagePF2e) export function renderChatMessageHook(message: ChatMessagePF2e, jq: JQuery) { const html = jq.get(0); // Only acts on latest message, but can't be in createChatMessageHook as that doesn't get triggered for some reason. - if (!game.messages.contents.slice(-Math.min(1, game.messages.size)).filter((x) => x._id === message.id)) { - persistentHealing(message, Boolean(game.settings.get(MODULENAME, "applyPersistentHealing"))); + persistentHealing(message, Boolean(game.settings.get(MODULENAME, "applyPersistentHealing"))); - if (game.settings.get(MODULENAME, "applyPersistentDamage")) { - persistentDamage(message); - } - - deprecatedDyingHandlingRenderChatMessageHook(message); + if (game.settings.get(MODULENAME, "applyPersistentDamage")) { + persistentDamage(message); } + deprecatedDyingHandlingRenderChatMessageHook(message); + // Affects all messages const minimumUserRoleFlag: any = message.getFlag(MODULENAME, "minimumUserRole"); if (!isNaN(minimumUserRoleFlag) && minimumUserRoleFlag > game.user.role) {