From b9a853ed2e61c7dddfb786e2b7249e81ca481422 Mon Sep 17 00:00:00 2001 From: Dean <69436131+emdeann@users.noreply.github.com> Date: Tue, 25 Feb 2025 21:48:44 -0800 Subject: [PATCH] [Bug] Fix canApplyAbility check but for real this time (#5418) * Move canApplyAbility check * Fix suppressed abilities not activated properly * Move canApplyAbility to applySingleAbAttrs --------- Co-authored-by: damocleas --- src/data/ability.ts | 12 +++++++----- src/data/arena-tag.ts | 7 +++++++ src/field/pokemon.ts | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index 5f19af8cea4..dcbaa4026f4 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -5152,6 +5152,10 @@ function applySingleAbAttrs( showAbilityInstant: boolean = false, messages: string[] = [] ) { + if (!pokemon?.canApplyAbility(passive) || (passive && (pokemon.getPassiveAbility().id === pokemon.getAbility().id))) { + return; + } + const ability = passive ? pokemon.getPassiveAbility() : pokemon.getAbility(); if (gainedMidTurn && ability.getAttrs(attrType).some(attr => attr instanceof PostSummonAbAttr && !attr.shouldActivateOnGain())) { return; @@ -5445,12 +5449,10 @@ function applyAbAttrsInternal( gainedMidTurn: boolean = false ) { for (const passive of [ false, true ]) { - if (!pokemon?.canApplyAbility(passive) || (passive && (pokemon.getPassiveAbility().id === pokemon.getAbility().id))) { - continue; + if (pokemon) { + applySingleAbAttrs(pokemon, passive, attrType, applyFunc, args, gainedMidTurn, simulated, showAbilityInstant, messages); + globalScene.clearPhaseQueueSplice(); } - - applySingleAbAttrs(pokemon, passive, attrType, applyFunc, args, gainedMidTurn, simulated, showAbilityInstant, messages); - globalScene.clearPhaseQueueSplice(); } } diff --git a/src/data/arena-tag.ts b/src/data/arena-tag.ts index d034ccf83b8..580ede9596c 100644 --- a/src/data/arena-tag.ts +++ b/src/data/arena-tag.ts @@ -1230,10 +1230,12 @@ export class FairyLockTag extends ArenaTag { */ export class SuppressAbilitiesTag extends ArenaTag { private sourceCount: number; + private beingRemoved: boolean; constructor(sourceId: number) { super(ArenaTagType.NEUTRALIZING_GAS, 0, undefined, sourceId); this.sourceCount = 1; + this.beingRemoved = false; } public override onAdd(arena: Arena): void { @@ -1267,6 +1269,7 @@ export class SuppressAbilitiesTag extends ArenaTag { } public override onRemove(arena: Arena, quiet: boolean = false) { + this.beingRemoved = true; if (!quiet) { globalScene.queueMessage(i18next.t("arenaTag:neutralizingGasOnRemove")); } @@ -1282,6 +1285,10 @@ export class SuppressAbilitiesTag extends ArenaTag { public shouldApplyToSelf(): boolean { return this.sourceCount > 1; } + + public isBeingRemoved() { + return this.beingRemoved; + } } // TODO: swap `sourceMove` and `sourceId` and make `sourceMove` an optional parameter diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index bc3b9b1403f..f0486a8f111 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1501,8 +1501,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * Suppresses an ability and calls its onlose attributes */ public suppressAbility() { - this.summonData.abilitySuppressed = true; [ true, false ].forEach((passive) => applyOnLoseAbAttrs(this, passive)); + this.summonData.abilitySuppressed = true; } /** @@ -1563,7 +1563,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return false; } const suppressAbilitiesTag = arena.getTag(ArenaTagType.NEUTRALIZING_GAS) as SuppressAbilitiesTag; - if (this.isOnField() && suppressAbilitiesTag) { + if (this.isOnField() && suppressAbilitiesTag && !suppressAbilitiesTag.isBeingRemoved()) { const thisAbilitySuppressing = ability.hasAttr(PreLeaveFieldRemoveSuppressAbilitiesSourceAbAttr); const hasSuppressingAbility = this.hasAbilityWithAttr(PreLeaveFieldRemoveSuppressAbilitiesSourceAbAttr, false); // Neutralizing gas is up - suppress abilities unless they are unsuppressable or this pokemon is responsible for the gas