From 22b7f94b0b70213652567bf02c3054830859d193 Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Tue, 28 Jan 2025 23:22:49 +0100 Subject: [PATCH] Attempts to make new overrides for testing --- src/field/pokemon.ts | 4 +- src/test/abilities/desolate-land.test.ts | 110 ++++++++++++++++++++++ src/test/utils/gameManager.ts | 19 ++++ src/test/utils/helpers/overridesHelper.ts | 11 +++ 4 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 src/test/abilities/desolate-land.test.ts diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index a0ec5abac9e..99c261f5aa0 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1439,8 +1439,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { */ public hasPassive(): boolean { // returns override if valid for current case - if ((Overrides.PASSIVE_ABILITY_OVERRIDE !== Abilities.NONE && this.isPlayer()) - || (Overrides.OPP_PASSIVE_ABILITY_OVERRIDE !== Abilities.NONE && !this.isPlayer())) { + if (((Overrides.PASSIVE_ABILITY_OVERRIDE !== Abilities.NONE || Overrides.HAS_PASSIVE_ABILITY_OVERRIDE) && this.isPlayer()) + || ((Overrides.OPP_PASSIVE_ABILITY_OVERRIDE !== Abilities.NONE || Overrides.OPP_HAS_PASSIVE_ABILITY_OVERRIDE) && !this.isPlayer())) { return true; } diff --git a/src/test/abilities/desolate-land.test.ts b/src/test/abilities/desolate-land.test.ts new file mode 100644 index 00000000000..df268d332ba --- /dev/null +++ b/src/test/abilities/desolate-land.test.ts @@ -0,0 +1,110 @@ +import { WeatherType } from "#app/enums/weather-type"; +import { Abilities } from "#enums/abilities"; +import { Moves } from "#enums/moves"; +import { Species } from "#enums/species"; +import GameManager from "#test/utils/gameManager"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, it, expect, vi } from "vitest"; + +describe("Abilities - Desolate Land", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + game.override + .moveset(Moves.SPLASH) + .hasPassiveAbility(true) + .enemySpecies(Species.RALTS) + .enemyAbility(Abilities.BALL_FETCH) + .enemyMoveset(Moves.SPLASH); + }); + + /** + * This checks that the weather has changed after the Enemy Pokemon with {@linkcode Abilities.DESOLATE_LAND} + * is forcefully moved out of the field from moves such as Roar {@linkcode Moves.ROAR} + */ + it("should lift when all pokemon with this ability leave the field", async () => { + game.override + .battleType("double") + .enemyMoveset([ Moves.SPLASH, Moves.ROAR ]); + await game.classicMode.startBattle([ Species.MAGCARGO, Species.MAGCARGO, Species.MAGIKARP, Species.MAGIKARP ]); + + expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.HARSH_SUN); + + vi.spyOn(game.scene, "randBattleSeedInt").mockImplementation((range, min: number = 0) => { + return min; + }); + + game.move.select(Moves.SPLASH, 0, 2); + game.move.select(Moves.SPLASH, 1, 2); + + await game.forceEnemyMove(Moves.ROAR, 0); + + await game.phaseInterceptor.to("TurnEndPhase"); + + expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.HARSH_SUN); + + await game.toNextTurn(); + + vi.spyOn(game.scene, "randBattleSeedInt").mockImplementation((range, min: number = 0) => { + return min + 1; + }); + + game.move.select(Moves.SPLASH, 0, 2); + game.move.select(Moves.SPLASH, 1, 2); + + await game.forceEnemyMove(Moves.ROAR, 1); + + await game.phaseInterceptor.to("TurnEndPhase"); + + expect(game.scene.arena.weather?.weatherType).not.toBe(WeatherType.HARSH_SUN); + }); + + it("should lift when enemy faints", async () => { + game.override + .battleType("single") + .moveset([ Moves.SHEER_COLD ]) + .ability(Abilities.NO_GUARD) + .startingLevel(100) + .enemyLevel(1) + .enemyMoveset([ Moves.SPLASH ]) + .enemySpecies(Species.MAGCARGO) + .enemyHasPassiveAbility(true); + await game.classicMode.startBattle([ Species.MAGIKARP ]); + + expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.HARSH_SUN); + + game.move.select(Moves.SHEER_COLD); + + await game.phaseInterceptor.to("TurnEndPhase"); + + expect(game.scene.arena.weather?.weatherType).not.toBe(WeatherType.HARSH_SUN); + }); + + it("should lift when enemy is captured", async () => { + game.override + .battleType("single") + .enemyMoveset([ Moves.SPLASH ]) + .enemySpecies(Species.MAGCARGO) + .enemyHasPassiveAbility(true); + await game.classicMode.startBattle([ Species.MAGIKARP ]); + + expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.HARSH_SUN); + + + await game.phaseInterceptor.to("TurnEndPhase"); + + expect(game.scene.arena.weather?.weatherType).not.toBe(WeatherType.HARSH_SUN); + }); +}); diff --git a/src/test/utils/gameManager.ts b/src/test/utils/gameManager.ts index 9fda3afa56e..f43dddf0f05 100644 --- a/src/test/utils/gameManager.ts +++ b/src/test/utils/gameManager.ts @@ -452,6 +452,25 @@ export default class GameManager { }); } + doThrowPokeball(ballIndex: number) { + this.onNextPrompt("CommandPhase", Mode.COMMAND, () => { + (this.scene.ui.getHandler() as CommandUiHandler).setCursor(1); + (this.scene.ui.getHandler() as CommandUiHandler).processInput(Button.ACTION); + }); + + this.doSelectPokeball(ballIndex, "CommandPhase"); + } + // ??? + doSelectPokeball(slot: number, inPhase = "SwitchPhase") { + this.onNextPrompt(inPhase, Mode.PARTY, () => { + const partyHandler = this.scene.ui.getHandler() as PartyUiHandler; + + partyHandler.setCursor(slot); + partyHandler.processInput(Button.ACTION); // select party slot + partyHandler.processInput(Button.ACTION); // send out (or whatever option is at the top) + }); + } + /** * Intercepts `TurnStartPhase` and mocks the getSpeedOrder's return value {@linkcode TurnStartPhase.getSpeedOrder} * Used to modify the turn order. diff --git a/src/test/utils/helpers/overridesHelper.ts b/src/test/utils/helpers/overridesHelper.ts index 9af811561b7..00842fdda6f 100644 --- a/src/test/utils/helpers/overridesHelper.ts +++ b/src/test/utils/helpers/overridesHelper.ts @@ -161,6 +161,11 @@ export class OverridesHelper extends GameManagerHelper { return this; } + public hasPassiveAbility(hasPassiveAbility: boolean): this { + vi.spyOn(Overrides, "HAS_PASSIVE_ABILITY_OVERRIDE", "get").mockReturnValue(hasPassiveAbility); + this.log("Player Pokemon PASSIVE ability is active!"); + return this; + } /** * Override the player (pokemon) {@linkcode Moves | moves}set * @param moveset the {@linkcode Moves | moves}set to set @@ -305,6 +310,12 @@ export class OverridesHelper extends GameManagerHelper { return this; } + public enemyHasPassiveAbility(hasPassiveAbility: boolean): this { + vi.spyOn(Overrides, "OPP_HAS_PASSIVE_ABILITY_OVERRIDE", "get").mockReturnValue(hasPassiveAbility); + this.log("Enemy Pokemon PASSIVE ability is active!"); + return this; + } + /** * Override the enemy (pokemon) {@linkcode Moves | moves}set * @param moveset the {@linkcode Moves | moves}set to set