Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/data/arena-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
[true, false].forEach(passive => applyOnLoseAbAttrs(fieldPokemon, passive));
}
Expand Down Expand Up @@ -1466,7 +1466,7 @@ export class SuppressAbilitiesTag extends ArenaTag {
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
if (pokemon && !pokemon.hasAbilityWithAttr(PreLeaveFieldRemoveSuppressAbilitiesSourceAbAttr, false)) {
[true, false].forEach(passive => applyOnGainAbAttrs(pokemon, passive));
Expand Down
24 changes: 23 additions & 1 deletion test/abilities/neutralizing_gas.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BattlerIndex } from "#app/battle";
import { PostSummonWeatherChangeAbAttr } from "#app/data/ability";
import { Abilities } from "#enums/abilities";
import { ArenaTagType } from "#enums/arena-tag-type";
import { Moves } from "#enums/moves";
Expand All @@ -7,7 +8,7 @@ import { Species } from "#enums/species";
import { Stat } from "#enums/stat";
import GameManager from "#test/testUtils/gameManager";
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", () => {
let phaserGame: Phaser.Game;
Expand Down Expand Up @@ -155,4 +156,25 @@ describe("Abilities - Neutralizing Gas", () => {

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();
});
});