Skip to content

Commit

Permalink
fix: Applying Persistent Damage and/or Persistent Healing works again.
Browse files Browse the repository at this point in the history
  • Loading branch information
xdy committed Jul 4, 2024
1 parent a25e3aa commit 137500e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
12 changes: 5 additions & 7 deletions src/module/feature/damageHandler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,18 @@ export async function noOrSuccessfulFlatcheck(message: ChatMessagePF2e): Promise
}

export function persistentDamage(message) {
const flavor = message.flavor;
const persistentFlavor = flavor?.includes("<strong>" + 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("<strong>" + 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)
) {
Expand All @@ -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();
Expand All @@ -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;
Expand Down
12 changes: 5 additions & 7 deletions src/module/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,14 @@ function deprecatedDyingHandlingRenderChatMessageHook(message: ChatMessagePF2e)
export function renderChatMessageHook(message: ChatMessagePF2e, jq: JQuery) {
const html = <HTMLElement>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) {
Expand Down

0 comments on commit 137500e

Please sign in to comment.