From 45f6b2330978fc616e5c442522665641426e5576 Mon Sep 17 00:00:00 2001 From: DustinLin <39450497+DustinLin@users.noreply.github.com> Date: Mon, 30 Sep 2024 20:23:29 -0700 Subject: [PATCH] [P2] Chilly Reception's Snow is called during Enemy AI Move Selection (#4528) * fixing weather check in getCondition() * adding enemy tests --- src/data/move.ts | 2 +- src/test/moves/chilly_reception.test.ts | 55 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/data/move.ts b/src/data/move.ts index d4b2b2f0e75..748f81cdd8b 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -5333,7 +5333,7 @@ export class ChillyReceptionAttr extends ForceSwitchOutAttr { getCondition(): MoveConditionFunc { // chilly reception move will go through if the weather is change-able to snow, or the user can switch out, else move will fail - return (user, target, move) => user.scene.arena.trySetWeather(WeatherType.SNOW, true) || super.getSwitchOutCondition()(user, target, move); + return (user, target, move) => user.scene.arena.weather?.weatherType !== WeatherType.SNOW || super.getSwitchOutCondition()(user, target, move); } } export class RemoveTypeAttr extends MoveEffectAttr { diff --git a/src/test/moves/chilly_reception.test.ts b/src/test/moves/chilly_reception.test.ts index 1b5b5cecb4a..6c8e8172670 100644 --- a/src/test/moves/chilly_reception.test.ts +++ b/src/test/moves/chilly_reception.test.ts @@ -4,6 +4,7 @@ import { Species } from "#enums/species"; import { WeatherType } from "#enums/weather-type"; import GameManager from "#test/utils/gameManager"; import Phaser from "phaser"; +//import { TurnInitPhase } from "#app/phases/turn-init-phase"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; describe("Moves - Chilly Reception", () => { @@ -66,4 +67,58 @@ describe("Moves - Chilly Reception", () => { expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW); expect(game.scene.getPlayerField()[0].species.speciesId).toBe(Species.MEOWTH); }); + + // enemy uses another move and weather doesn't change + it("check case - enemy not selecting chilly reception doesn't change weather ", async () => { + game.override.battleType("single") + .enemyMoveset([Moves.CHILLY_RECEPTION, Moves.TACKLE]) + .enemyAbility(Abilities.NONE) + .moveset(Array(4).fill(Moves.SPLASH)); + + await game.classicMode.startBattle([Species.SLOWKING, Species.MEOWTH]); + + game.move.select(Moves.SPLASH); + await game.forceEnemyMove(Moves.TACKLE); + + await game.phaseInterceptor.to("BerryPhase", false); + expect(game.scene.arena.weather?.weatherType).toBe(undefined); + }); + + it("enemy trainer - expected behavior ", async () => { + game.override.battleType("single") + .startingWave(8) + .enemyMoveset(Array(4).fill(Moves.CHILLY_RECEPTION)) + .enemyAbility(Abilities.NONE) + .enemySpecies(Species.MAGIKARP) + .moveset([Moves.SPLASH, Moves.THUNDERBOLT]); + + await game.classicMode.startBattle([Species.JOLTEON]); + const RIVAL_MAGIKARP1 = game.scene.getEnemyPokemon()?.id; + + game.move.select(Moves.SPLASH); + await game.phaseInterceptor.to("BerryPhase", false); + expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW); + expect(game.scene.getEnemyPokemon()?.id !== RIVAL_MAGIKARP1); + + await game.phaseInterceptor.to("TurnInitPhase", false); + game.move.select(Moves.SPLASH); + + // second chilly reception should still switch out + await game.phaseInterceptor.to("BerryPhase", false); + expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW); + await game.phaseInterceptor.to("TurnInitPhase", false); + expect(game.scene.getEnemyPokemon()?.id === RIVAL_MAGIKARP1); + game.move.select(Moves.THUNDERBOLT); + + // enemy chilly recep move should fail: it's snowing and no option to switch out + // no crashing + await game.phaseInterceptor.to("BerryPhase", false); + expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW); + await game.phaseInterceptor.to("TurnInitPhase", false); + expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW); + game.move.select(Moves.SPLASH); + await game.phaseInterceptor.to("BerryPhase", false); + expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.SNOW); + + }); });