From 4b9c3e9b07b0794bf2bd381763f824d61448c659 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Mon, 29 Jul 2024 13:46:04 -0700 Subject: [PATCH] [Test] Remove held item RNG (white herb) from intimidate tests (#3205) Also add a helper function to remove enemy held items --- src/test/abilities/intimidate.test.ts | 16 +++++++++++++--- src/test/utils/gameManagerUtils.ts | 16 ++++++++-------- src/test/utils/testUtils.ts | 9 +++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/test/abilities/intimidate.test.ts b/src/test/abilities/intimidate.test.ts index 2ff909def2e..b0642216630 100644 --- a/src/test/abilities/intimidate.test.ts +++ b/src/test/abilities/intimidate.test.ts @@ -12,6 +12,7 @@ import { GameModes, getGameMode } from "#app/game-mode"; import { Abilities } from "#enums/abilities"; import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; +import { removeEnemyHeldItems } from "../utils/testUtils"; describe("Abilities - Intimidate", () => { let phaserGame: Phaser.Game; @@ -40,6 +41,7 @@ describe("Abilities - Intimidate", () => { it("single - wild with switch", async () => { await game.runToSummon([Species.MIGHTYENA, Species.POOCHYENA]); + removeEnemyHeldItems(game.scene); game.onNextPrompt( "CheckSwitchPhase", Mode.CONFIRM, @@ -70,6 +72,7 @@ describe("Abilities - Intimidate", () => { it("single - boss should only trigger once then switch", async () => { vi.spyOn(Overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(10); await game.runToSummon([Species.MIGHTYENA, Species.POOCHYENA]); + removeEnemyHeldItems(game.scene); game.onNextPrompt( "CheckSwitchPhase", Mode.CONFIRM, @@ -99,6 +102,7 @@ describe("Abilities - Intimidate", () => { it("single - trainer should only trigger once with switch", async () => { vi.spyOn(Overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(5); await game.runToSummon([Species.MIGHTYENA, Species.POOCHYENA]); + removeEnemyHeldItems(game.scene); game.onNextPrompt( "CheckSwitchPhase", Mode.CONFIRM, @@ -129,6 +133,7 @@ describe("Abilities - Intimidate", () => { vi.spyOn(Overrides, "BATTLE_TYPE_OVERRIDE", "get").mockReturnValue("double"); vi.spyOn(Overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(5); await game.runToSummon([Species.MIGHTYENA, Species.POOCHYENA]); + removeEnemyHeldItems(game.scene); game.onNextPrompt( "CheckSwitchPhase", Mode.CONFIRM, @@ -155,6 +160,7 @@ describe("Abilities - Intimidate", () => { vi.spyOn(Overrides, "BATTLE_TYPE_OVERRIDE", "get").mockReturnValue("double"); vi.spyOn(Overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(3); await game.runToSummon([Species.MIGHTYENA, Species.POOCHYENA]); + removeEnemyHeldItems(game.scene); game.onNextPrompt( "CheckSwitchPhase", Mode.CONFIRM, @@ -181,6 +187,7 @@ describe("Abilities - Intimidate", () => { vi.spyOn(Overrides, "BATTLE_TYPE_OVERRIDE", "get").mockReturnValue("double"); vi.spyOn(Overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(10); await game.runToSummon([Species.MIGHTYENA, Species.POOCHYENA]); + removeEnemyHeldItems(game.scene); game.onNextPrompt( "CheckSwitchPhase", Mode.CONFIRM, @@ -207,6 +214,7 @@ describe("Abilities - Intimidate", () => { vi.spyOn(Overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(2); vi.spyOn(Overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.AERIAL_ACE]); await game.startBattle([Species.MIGHTYENA, Species.POOCHYENA]); + removeEnemyHeldItems(game.scene); let battleStatsOpponent = game.scene.currentBattle.enemyParty[0].summonData.battleStats; expect(battleStatsOpponent[BattleStat.ATK]).toBe(-1); let battleStatsPokemon = game.scene.getParty()[0].summonData.battleStats; @@ -233,6 +241,7 @@ describe("Abilities - Intimidate", () => { vi.spyOn(Overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(2); vi.spyOn(Overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH]); await game.startBattle([Species.MIGHTYENA, Species.POOCHYENA]); + removeEnemyHeldItems(game.scene); let battleStatsOpponent = game.scene.currentBattle.enemyParty[0].summonData.battleStats; expect(battleStatsOpponent[BattleStat.ATK]).toBe(-1); let battleStatsPokemon = game.scene.getParty()[0].summonData.battleStats; @@ -258,6 +267,7 @@ describe("Abilities - Intimidate", () => { vi.spyOn(Overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.VOLT_SWITCH, Moves.VOLT_SWITCH, Moves.VOLT_SWITCH, Moves.VOLT_SWITCH]); vi.spyOn(Overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(5); await game.startBattle([Species.MIGHTYENA, Species.POOCHYENA]); + removeEnemyHeldItems(game.scene); let battleStatsOpponent = game.scene.currentBattle.enemyParty[0].summonData.battleStats; expect(battleStatsOpponent[BattleStat.ATK]).toBe(-1); let battleStatsPokemon = game.scene.getParty()[0].summonData.battleStats; @@ -297,6 +307,7 @@ describe("Abilities - Intimidate", () => { vi.spyOn(Overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH]); vi.spyOn(Overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(5); await game.startBattle([Species.MIGHTYENA, Species.POOCHYENA]); + removeEnemyHeldItems(game.scene); let battleStatsOpponent = game.scene.currentBattle.enemyParty[0].summonData.battleStats; expect(battleStatsOpponent[BattleStat.ATK]).toBe(-1); let battleStatsPokemon = game.scene.getParty()[0].summonData.battleStats; @@ -336,9 +347,7 @@ describe("Abilities - Intimidate", () => { vi.spyOn(Overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(3); vi.spyOn(Overrides, "OPP_HELD_ITEMS_OVERRIDE", "get").mockReturnValue([{ name: "COIN_CASE" }]); await game.runToSummon([Species.MIGHTYENA]); - // Get rid of any modifiers that may alter power - game.scene.clearEnemyHeldItemModifiers(); - game.scene.clearEnemyModifiers(); + removeEnemyHeldItems(game.scene); await game.phaseInterceptor.to(CommandPhase, false); const battleStatsOpponent = game.scene.currentBattle.enemyParty[0].summonData.battleStats; expect(battleStatsOpponent[BattleStat.ATK]).toBe(-1); @@ -365,6 +374,7 @@ describe("Abilities - Intimidate", () => { }); await game.phaseInterceptor.run(EncounterPhase); + removeEnemyHeldItems(game.scene); await game.phaseInterceptor.to(CommandPhase, false); const battleStatsOpponent = game.scene.currentBattle.enemyParty[0].summonData.battleStats; diff --git a/src/test/utils/gameManagerUtils.ts b/src/test/utils/gameManagerUtils.ts index d83805e59e8..74a73bb7875 100644 --- a/src/test/utils/gameManagerUtils.ts +++ b/src/test/utils/gameManagerUtils.ts @@ -1,14 +1,14 @@ -// Function to convert Blob to string -import {getDailyRunStarters} from "#app/data/daily-run"; -import {Gender} from "#app/data/gender"; -import {Species} from "#enums/species"; -import {Starter} from "#app/ui/starter-select-ui-handler"; -import {GameModes, getGameMode} from "#app/game-mode"; -import {getPokemonSpecies, getPokemonSpeciesForm} from "#app/data/pokemon-species"; -import {PlayerPokemon} from "#app/field/pokemon"; +import { getDailyRunStarters } from "#app/data/daily-run"; +import { Gender } from "#app/data/gender"; +import { Species } from "#enums/species"; +import { Starter } from "#app/ui/starter-select-ui-handler"; +import { GameModes, getGameMode } from "#app/game-mode"; +import { getPokemonSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species"; +import { PlayerPokemon } from "#app/field/pokemon"; import { Moves } from "#app/enums/moves"; import BattleScene from "#app/battle-scene"; +/** Function to convert Blob to string */ export function blobToString(blob) { return new Promise((resolve, reject) => { const reader = new FileReader(); diff --git a/src/test/utils/testUtils.ts b/src/test/utils/testUtils.ts index 0a9be16a4b5..4a807c7d892 100644 --- a/src/test/utils/testUtils.ts +++ b/src/test/utils/testUtils.ts @@ -1,3 +1,4 @@ +import BattleScene from "#app/battle-scene.js"; import { Moves } from "#app/enums/moves.js"; import i18next, { type ParseKeys } from "i18next"; import { vi } from "vitest"; @@ -26,3 +27,11 @@ export function arrayOfRange(start: integer, end: integer) { return Array.from({ length: end - start }, (_v, k) => k + start); } +/** + * Removes all held items from enemy pokemon + * @param scene `game.scene` + */ +export function removeEnemyHeldItems(scene: BattleScene) { + scene.clearEnemyHeldItemModifiers(); + scene.clearEnemyModifiers(); +}