[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 <damocleas25@gmail.com>
This commit is contained in:
Dean 2025-02-25 21:48:44 -08:00 committed by GitHub
parent 92ee9d06ca
commit b9a853ed2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 7 deletions

View File

@ -5152,6 +5152,10 @@ function applySingleAbAttrs<TAttr extends AbAttr>(
showAbilityInstant: boolean = false, showAbilityInstant: boolean = false,
messages: string[] = [] messages: string[] = []
) { ) {
if (!pokemon?.canApplyAbility(passive) || (passive && (pokemon.getPassiveAbility().id === pokemon.getAbility().id))) {
return;
}
const ability = passive ? pokemon.getPassiveAbility() : pokemon.getAbility(); const ability = passive ? pokemon.getPassiveAbility() : pokemon.getAbility();
if (gainedMidTurn && ability.getAttrs(attrType).some(attr => attr instanceof PostSummonAbAttr && !attr.shouldActivateOnGain())) { if (gainedMidTurn && ability.getAttrs(attrType).some(attr => attr instanceof PostSummonAbAttr && !attr.shouldActivateOnGain())) {
return; return;
@ -5445,14 +5449,12 @@ function applyAbAttrsInternal<TAttr extends AbAttr>(
gainedMidTurn: boolean = false gainedMidTurn: boolean = false
) { ) {
for (const passive of [ false, true ]) { for (const passive of [ false, true ]) {
if (!pokemon?.canApplyAbility(passive) || (passive && (pokemon.getPassiveAbility().id === pokemon.getAbility().id))) { if (pokemon) {
continue;
}
applySingleAbAttrs(pokemon, passive, attrType, applyFunc, args, gainedMidTurn, simulated, showAbilityInstant, messages); applySingleAbAttrs(pokemon, passive, attrType, applyFunc, args, gainedMidTurn, simulated, showAbilityInstant, messages);
globalScene.clearPhaseQueueSplice(); globalScene.clearPhaseQueueSplice();
} }
} }
}
export function applyAbAttrs( export function applyAbAttrs(
attrType: Constructor<AbAttr>, attrType: Constructor<AbAttr>,

View File

@ -1230,10 +1230,12 @@ export class FairyLockTag extends ArenaTag {
*/ */
export class SuppressAbilitiesTag extends ArenaTag { export class SuppressAbilitiesTag extends ArenaTag {
private sourceCount: number; private sourceCount: number;
private beingRemoved: boolean;
constructor(sourceId: number) { constructor(sourceId: number) {
super(ArenaTagType.NEUTRALIZING_GAS, 0, undefined, sourceId); super(ArenaTagType.NEUTRALIZING_GAS, 0, undefined, sourceId);
this.sourceCount = 1; this.sourceCount = 1;
this.beingRemoved = false;
} }
public override onAdd(arena: Arena): void { public override onAdd(arena: Arena): void {
@ -1267,6 +1269,7 @@ export class SuppressAbilitiesTag extends ArenaTag {
} }
public override onRemove(arena: Arena, quiet: boolean = false) { public override onRemove(arena: Arena, quiet: boolean = false) {
this.beingRemoved = true;
if (!quiet) { if (!quiet) {
globalScene.queueMessage(i18next.t("arenaTag:neutralizingGasOnRemove")); globalScene.queueMessage(i18next.t("arenaTag:neutralizingGasOnRemove"));
} }
@ -1282,6 +1285,10 @@ export class SuppressAbilitiesTag extends ArenaTag {
public shouldApplyToSelf(): boolean { public shouldApplyToSelf(): boolean {
return this.sourceCount > 1; return this.sourceCount > 1;
} }
public isBeingRemoved() {
return this.beingRemoved;
}
} }
// TODO: swap `sourceMove` and `sourceId` and make `sourceMove` an optional parameter // TODO: swap `sourceMove` and `sourceId` and make `sourceMove` an optional parameter

View File

@ -1501,8 +1501,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
* Suppresses an ability and calls its onlose attributes * Suppresses an ability and calls its onlose attributes
*/ */
public suppressAbility() { public suppressAbility() {
this.summonData.abilitySuppressed = true;
[ true, false ].forEach((passive) => applyOnLoseAbAttrs(this, passive)); [ 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; return false;
} }
const suppressAbilitiesTag = arena.getTag(ArenaTagType.NEUTRALIZING_GAS) as SuppressAbilitiesTag; 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 thisAbilitySuppressing = ability.hasAttr(PreLeaveFieldRemoveSuppressAbilitiesSourceAbAttr);
const hasSuppressingAbility = this.hasAbilityWithAttr(PreLeaveFieldRemoveSuppressAbilitiesSourceAbAttr, false); const hasSuppressingAbility = this.hasAbilityWithAttr(PreLeaveFieldRemoveSuppressAbilitiesSourceAbAttr, false);
// Neutralizing gas is up - suppress abilities unless they are unsuppressable or this pokemon is responsible for the gas // Neutralizing gas is up - suppress abilities unless they are unsuppressable or this pokemon is responsible for the gas