[Bug] Fix NG crash when ability is reactivated for a Pokemon off the field (#5478)

This commit is contained in:
Dean 2025-03-10 20:20:00 -07:00 committed by GitHub
parent 929392fe8b
commit b298138157
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 3 deletions

View File

@ -1433,7 +1433,7 @@ export class SuppressAbilitiesTag extends ArenaTag {
}), }),
); );
for (const fieldPokemon of globalScene.getField()) { for (const fieldPokemon of globalScene.getField(true)) {
if (fieldPokemon && fieldPokemon.id !== pokemon.id) { if (fieldPokemon && fieldPokemon.id !== pokemon.id) {
[true, false].forEach(passive => applyOnLoseAbAttrs(fieldPokemon, passive)); [true, false].forEach(passive => applyOnLoseAbAttrs(fieldPokemon, passive));
} }
@ -1466,7 +1466,7 @@ export class SuppressAbilitiesTag extends ArenaTag {
globalScene.queueMessage(i18next.t("arenaTag:neutralizingGasOnRemove")); globalScene.queueMessage(i18next.t("arenaTag:neutralizingGasOnRemove"));
} }
for (const pokemon of globalScene.getField()) { for (const pokemon of globalScene.getField(true)) {
// There is only one pokemon with this attr on the field on removal, so its abilities are already active // There is only one pokemon with this attr on the field on removal, so its abilities are already active
if (pokemon && !pokemon.hasAbilityWithAttr(PreLeaveFieldRemoveSuppressAbilitiesSourceAbAttr, false)) { if (pokemon && !pokemon.hasAbilityWithAttr(PreLeaveFieldRemoveSuppressAbilitiesSourceAbAttr, false)) {
[true, false].forEach(passive => applyOnGainAbAttrs(pokemon, passive)); [true, false].forEach(passive => applyOnGainAbAttrs(pokemon, passive));

View File

@ -1,4 +1,5 @@
import { BattlerIndex } from "#app/battle"; import { BattlerIndex } from "#app/battle";
import { PostSummonWeatherChangeAbAttr } from "#app/data/ability";
import { Abilities } from "#enums/abilities"; import { Abilities } from "#enums/abilities";
import { ArenaTagType } from "#enums/arena-tag-type"; import { ArenaTagType } from "#enums/arena-tag-type";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
@ -7,7 +8,7 @@ import { Species } from "#enums/species";
import { Stat } from "#enums/stat"; import { Stat } from "#enums/stat";
import GameManager from "#test/testUtils/gameManager"; import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
describe("Abilities - Neutralizing Gas", () => { describe("Abilities - Neutralizing Gas", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -155,4 +156,25 @@ describe("Abilities - Neutralizing Gas", () => {
expect(game.scene.arena.getTag(ArenaTagType.NEUTRALIZING_GAS)).toBeUndefined(); expect(game.scene.arena.getTag(ArenaTagType.NEUTRALIZING_GAS)).toBeUndefined();
}); });
it("should not activate abilities of pokemon no longer on the field", async () => {
game.override
.battleType("single")
.ability(Abilities.NEUTRALIZING_GAS)
.enemyAbility(Abilities.DELTA_STREAM);
await game.classicMode.startBattle([ Species.MAGIKARP ]);
const enemy = game.scene.getEnemyPokemon()!;
const weatherChangeAttr = enemy.getAbilityAttrs(PostSummonWeatherChangeAbAttr, false)[0];
vi.spyOn(weatherChangeAttr, "applyPostSummon");
expect(game.scene.arena.getTag(ArenaTagType.NEUTRALIZING_GAS)).toBeDefined();
game.move.select(Moves.SPLASH);
await game.killPokemon(enemy);
await game.killPokemon(game.scene.getPlayerPokemon()!);
expect(game.scene.arena.getTag(ArenaTagType.NEUTRALIZING_GAS)).toBeUndefined();
expect(weatherChangeAttr.applyPostSummon).not.toHaveBeenCalled();
});
}); });