diff --git a/src/data/abilities/ability.ts b/src/data/abilities/ability.ts index 643b6f4f291..eb553f12186 100644 --- a/src/data/abilities/ability.ts +++ b/src/data/abilities/ability.ts @@ -4453,7 +4453,7 @@ export class PreSetStatusAbAttr extends AbAttr { _pokemon: Pokemon, _passive: boolean, _simulated: boolean, - _effect: StatusEffect | undefined, + _effect: StatusEffect, _cancelled: BooleanHolder, _args: any[], ): boolean { @@ -4464,7 +4464,7 @@ export class PreSetStatusAbAttr extends AbAttr { _pokemon: Pokemon, _passive: boolean, _simulated: boolean, - _effect: StatusEffect | undefined, + _effect: StatusEffect, _cancelled: BooleanHolder, _args: any[], ): void {} diff --git a/src/data/abilities/apply-ab-attrs.ts b/src/data/abilities/apply-ab-attrs.ts index fdbd2652698..c7acced1c83 100644 --- a/src/data/abilities/apply-ab-attrs.ts +++ b/src/data/abilities/apply-ab-attrs.ts @@ -583,7 +583,7 @@ export function applyPostStatStageChangeAbAttrs( export function applyPreSetStatusAbAttrs( attrType: AbAttrMap[K] extends PreSetStatusAbAttr ? K : never, pokemon: Pokemon, - effect: StatusEffect | undefined, + effect: StatusEffect, cancelled: BooleanHolder, simulated = false, ...args: any[] diff --git a/test/abilities/insomnia.test.ts b/test/abilities/insomnia.test.ts deleted file mode 100644 index 418e0ed1345..00000000000 --- a/test/abilities/insomnia.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { AbilityId } from "#enums/ability-id"; -import { MoveId } from "#enums/move-id"; -import { SpeciesId } from "#enums/species-id"; -import { StatusEffect } from "#enums/status-effect"; -import GameManager from "#test/testUtils/gameManager"; -import Phaser from "phaser"; -import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; - -describe("Abilities - Insomnia", () => { - 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([MoveId.SPLASH]) - .ability(AbilityId.BALL_FETCH) - .battleStyle("single") - .disableCrits() - .enemySpecies(SpeciesId.MAGIKARP) - .enemyAbility(AbilityId.BALL_FETCH) - .enemyMoveset(MoveId.SPLASH); - }); - - it("should remove sleep when gained", async () => { - game.override - .ability(AbilityId.INSOMNIA) - .enemyAbility(AbilityId.BALL_FETCH) - .moveset(MoveId.SKILL_SWAP) - .enemyMoveset(MoveId.SPLASH); - await game.classicMode.startBattle([SpeciesId.FEEBAS]); - const enemy = game.scene.getEnemyPokemon(); - enemy?.trySetStatus(StatusEffect.SLEEP); - expect(enemy?.status?.effect).toBe(StatusEffect.SLEEP); - - game.move.select(MoveId.SKILL_SWAP); - await game.phaseInterceptor.to("BerryPhase"); - - expect(enemy?.status).toBeNull(); - }); -}); diff --git a/test/abilities/limber.test.ts b/test/abilities/limber.test.ts deleted file mode 100644 index 2ca469dcaa1..00000000000 --- a/test/abilities/limber.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { AbilityId } from "#enums/ability-id"; -import { MoveId } from "#enums/move-id"; -import { SpeciesId } from "#enums/species-id"; -import { StatusEffect } from "#enums/status-effect"; -import GameManager from "#test/testUtils/gameManager"; -import Phaser from "phaser"; -import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; - -describe("Abilities - Limber", () => { - 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([MoveId.SPLASH]) - .ability(AbilityId.BALL_FETCH) - .battleStyle("single") - .disableCrits() - .enemySpecies(SpeciesId.MAGIKARP) - .enemyAbility(AbilityId.BALL_FETCH) - .enemyMoveset(MoveId.SPLASH); - }); - - it("should remove paralysis when gained", async () => { - game.override - .ability(AbilityId.LIMBER) - .enemyAbility(AbilityId.BALL_FETCH) - .moveset(MoveId.SKILL_SWAP) - .enemyMoveset(MoveId.SPLASH); - await game.classicMode.startBattle([SpeciesId.FEEBAS]); - const enemy = game.scene.getEnemyPokemon(); - enemy?.trySetStatus(StatusEffect.PARALYSIS); - expect(enemy?.status?.effect).toBe(StatusEffect.PARALYSIS); - - game.move.select(MoveId.SKILL_SWAP); - await game.phaseInterceptor.to("BerryPhase"); - - expect(enemy?.status).toBeNull(); - }); -}); diff --git a/test/abilities/magma_armor.test.ts b/test/abilities/magma_armor.test.ts deleted file mode 100644 index 74493fac365..00000000000 --- a/test/abilities/magma_armor.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { AbilityId } from "#enums/ability-id"; -import { MoveId } from "#enums/move-id"; -import { SpeciesId } from "#enums/species-id"; -import { StatusEffect } from "#enums/status-effect"; -import GameManager from "#test/testUtils/gameManager"; -import Phaser from "phaser"; -import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; - -describe("Abilities - Magma Armor", () => { - 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([MoveId.SPLASH]) - .ability(AbilityId.BALL_FETCH) - .battleStyle("single") - .disableCrits() - .enemySpecies(SpeciesId.MAGIKARP) - .enemyAbility(AbilityId.BALL_FETCH) - .enemyMoveset(MoveId.SPLASH); - }); - - it("should remove freeze when gained", async () => { - game.override - .ability(AbilityId.MAGMA_ARMOR) - .enemyAbility(AbilityId.BALL_FETCH) - .moveset(MoveId.SKILL_SWAP) - .enemyMoveset(MoveId.SPLASH); - await game.classicMode.startBattle([SpeciesId.FEEBAS]); - const enemy = game.scene.getEnemyPokemon(); - enemy?.trySetStatus(StatusEffect.FREEZE); - expect(enemy?.status?.effect).toBe(StatusEffect.FREEZE); - - game.move.select(MoveId.SKILL_SWAP); - await game.phaseInterceptor.to("BerryPhase"); - - expect(enemy?.status).toBeNull(); - }); -}); diff --git a/test/abilities/status-immunity-ab-attrs.test.ts b/test/abilities/status-immunity-ab-attrs.test.ts new file mode 100644 index 00000000000..6b5219ecd54 --- /dev/null +++ b/test/abilities/status-immunity-ab-attrs.test.ts @@ -0,0 +1,90 @@ +import { allMoves } from "#app/data/data-lists"; +import { StatusEffectAttr } from "#app/data/moves/move"; +import { toReadableString } from "#app/utils/common"; +import { AbilityId } from "#enums/ability-id"; +import { MoveId } from "#enums/move-id"; +import { MoveResult } from "#enums/move-result"; +import { SpeciesId } from "#enums/species-id"; +import { StatusEffect } from "#enums/status-effect"; +import GameManager from "#test/testUtils/gameManager"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; + +describe.each<{ name: string; ability: AbilityId; status: StatusEffect }>([ + { name: "Vital Spirit", ability: AbilityId.VITAL_SPIRIT, status: StatusEffect.SLEEP }, + { name: "Insomnia", ability: AbilityId.INSOMNIA, status: StatusEffect.SLEEP }, + { name: "Immunity", ability: AbilityId.IMMUNITY, status: StatusEffect.POISON }, + { name: "Magma Armor", ability: AbilityId.MAGMA_ARMOR, status: StatusEffect.FREEZE }, + { name: "Limber", ability: AbilityId.LIMBER, status: StatusEffect.PARALYSIS }, + { name: "Thermal Exchange", ability: AbilityId.THERMAL_EXCHANGE, status: StatusEffect.BURN }, + { name: "Water Veil", ability: AbilityId.WATER_VEIL, status: StatusEffect.BURN }, + { name: "Water Bubble", ability: AbilityId.WATER_BUBBLE, status: StatusEffect.BURN }, +])("Abilities - $name", ({ ability, status }) => { + 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 + .battleStyle("single") + .disableCrits() + .startingLevel(100) + .enemySpecies(SpeciesId.MAGIKARP) + .enemyAbility(ability) + .enemyMoveset(MoveId.SPLASH); + + // Mock Lumina Crash and Spore to be our status-inflicting moves of choice + vi.spyOn(allMoves[MoveId.LUMINA_CRASH], "attrs", "get").mockReturnValue([new StatusEffectAttr(status, false)]); + vi.spyOn(allMoves[MoveId.SPORE], "attrs", "get").mockReturnValue([new StatusEffectAttr(status, false)]); + }); + + const statusStr = toReadableString(StatusEffect[status]); + + it(`should prevent application of ${statusStr} without failing damaging moves`, async () => { + await game.classicMode.startBattle([SpeciesId.FEEBAS]); + + const karp = game.field.getEnemyPokemon(); + expect(karp.canSetStatus(status)).toBe(false); + + game.move.use(MoveId.LUMINA_CRASH); + await game.toEndOfTurn(); + + expect(karp.status?.effect).toBeUndefined(); + expect(game.field.getPlayerPokemon().getLastXMoves()[0].result).toBe(MoveResult.SUCCESS); + }); + + it(`should cure ${statusStr} upon being gained`, async () => { + await game.classicMode.startBattle([SpeciesId.FEEBAS]); + + const feebas = game.field.getPlayerPokemon(); + feebas.doSetStatus(status); + expect(feebas.status?.effect).toBe(status); + + game.move.use(MoveId.SKILL_SWAP); + await game.toEndOfTurn(); + + expect(feebas.status?.effect).toBeUndefined(); + }); + + // TODO: This does not propagate failures currently + it.todo(`should cause status moves inflicting ${statusStr} to count as failed`, async () => { + await game.classicMode.startBattle([SpeciesId.FEEBAS]); + + game.move.use(MoveId.SPORE); + await game.toEndOfTurn(); + + const karp = game.field.getEnemyPokemon(); + expect(karp.status?.effect).toBeUndefined(); + expect(game.field.getPlayerPokemon().getLastXMoves()[0].result).toBe(MoveResult.FAIL); + }); +}); diff --git a/test/abilities/thermal_exchange.test.ts b/test/abilities/thermal_exchange.test.ts deleted file mode 100644 index f27e6da1d3b..00000000000 --- a/test/abilities/thermal_exchange.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { AbilityId } from "#enums/ability-id"; -import { MoveId } from "#enums/move-id"; -import { SpeciesId } from "#enums/species-id"; -import { StatusEffect } from "#enums/status-effect"; -import GameManager from "#test/testUtils/gameManager"; -import Phaser from "phaser"; -import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; - -describe("Abilities - Thermal Exchange", () => { - 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([MoveId.SPLASH]) - .ability(AbilityId.BALL_FETCH) - .battleStyle("single") - .disableCrits() - .enemySpecies(SpeciesId.MAGIKARP) - .enemyAbility(AbilityId.BALL_FETCH) - .enemyMoveset(MoveId.SPLASH); - }); - - it("should remove burn when gained", async () => { - game.override - .ability(AbilityId.THERMAL_EXCHANGE) - .enemyAbility(AbilityId.BALL_FETCH) - .moveset(MoveId.SKILL_SWAP) - .enemyMoveset(MoveId.SPLASH); - await game.classicMode.startBattle([SpeciesId.FEEBAS]); - const enemy = game.scene.getEnemyPokemon(); - enemy?.trySetStatus(StatusEffect.BURN); - expect(enemy?.status?.effect).toBe(StatusEffect.BURN); - - game.move.select(MoveId.SKILL_SWAP); - await game.phaseInterceptor.to("BerryPhase"); - - expect(enemy?.status).toBeNull(); - }); -}); diff --git a/test/abilities/vital_spirit.test.ts b/test/abilities/vital_spirit.test.ts deleted file mode 100644 index c32454e9d31..00000000000 --- a/test/abilities/vital_spirit.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { AbilityId } from "#enums/ability-id"; -import { MoveId } from "#enums/move-id"; -import { SpeciesId } from "#enums/species-id"; -import { StatusEffect } from "#enums/status-effect"; -import GameManager from "#test/testUtils/gameManager"; -import Phaser from "phaser"; -import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; - -describe("Abilities - Vital Spirit", () => { - 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([MoveId.SPLASH]) - .ability(AbilityId.BALL_FETCH) - .battleStyle("single") - .disableCrits() - .enemySpecies(SpeciesId.MAGIKARP) - .enemyAbility(AbilityId.BALL_FETCH) - .enemyMoveset(MoveId.SPLASH); - }); - - it("should remove sleep when gained", async () => { - game.override - .ability(AbilityId.INSOMNIA) - .enemyAbility(AbilityId.BALL_FETCH) - .moveset(MoveId.SKILL_SWAP) - .enemyMoveset(MoveId.SPLASH); - await game.classicMode.startBattle([SpeciesId.FEEBAS]); - const enemy = game.scene.getEnemyPokemon(); - enemy?.trySetStatus(StatusEffect.SLEEP); - expect(enemy?.status?.effect).toBe(StatusEffect.SLEEP); - - game.move.select(MoveId.SKILL_SWAP); - await game.phaseInterceptor.to("BerryPhase"); - - expect(enemy?.status).toBeNull(); - }); -}); diff --git a/test/abilities/water_bubble.test.ts b/test/abilities/water_bubble.test.ts deleted file mode 100644 index 412c4a25035..00000000000 --- a/test/abilities/water_bubble.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { AbilityId } from "#enums/ability-id"; -import { MoveId } from "#enums/move-id"; -import { SpeciesId } from "#enums/species-id"; -import { StatusEffect } from "#enums/status-effect"; -import GameManager from "#test/testUtils/gameManager"; -import Phaser from "phaser"; -import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; - -describe("Abilities - Water Bubble", () => { - 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([MoveId.SPLASH]) - .ability(AbilityId.BALL_FETCH) - .battleStyle("single") - .disableCrits() - .enemySpecies(SpeciesId.MAGIKARP) - .enemyAbility(AbilityId.BALL_FETCH) - .enemyMoveset(MoveId.SPLASH); - }); - - it("should remove burn when gained", async () => { - game.override - .ability(AbilityId.THERMAL_EXCHANGE) - .enemyAbility(AbilityId.BALL_FETCH) - .moveset(MoveId.SKILL_SWAP) - .enemyMoveset(MoveId.SPLASH); - await game.classicMode.startBattle([SpeciesId.FEEBAS]); - const enemy = game.scene.getEnemyPokemon(); - enemy?.trySetStatus(StatusEffect.BURN); - expect(enemy?.status?.effect).toBe(StatusEffect.BURN); - - game.move.select(MoveId.SKILL_SWAP); - await game.phaseInterceptor.to("BerryPhase"); - - expect(enemy?.status).toBeNull(); - }); -}); diff --git a/test/abilities/water_veil.test.ts b/test/abilities/water_veil.test.ts deleted file mode 100644 index e67287d250f..00000000000 --- a/test/abilities/water_veil.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { AbilityId } from "#enums/ability-id"; -import { MoveId } from "#enums/move-id"; -import { SpeciesId } from "#enums/species-id"; -import { StatusEffect } from "#enums/status-effect"; -import GameManager from "#test/testUtils/gameManager"; -import Phaser from "phaser"; -import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; - -describe("Abilities - Water Veil", () => { - 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([MoveId.SPLASH]) - .ability(AbilityId.BALL_FETCH) - .battleStyle("single") - .disableCrits() - .enemySpecies(SpeciesId.MAGIKARP) - .enemyAbility(AbilityId.BALL_FETCH) - .enemyMoveset(MoveId.SPLASH); - }); - - it("should remove burn when gained", async () => { - game.override - .ability(AbilityId.THERMAL_EXCHANGE) - .enemyAbility(AbilityId.BALL_FETCH) - .moveset(MoveId.SKILL_SWAP) - .enemyMoveset(MoveId.SPLASH); - await game.classicMode.startBattle([SpeciesId.FEEBAS]); - const enemy = game.scene.getEnemyPokemon(); - enemy?.trySetStatus(StatusEffect.BURN); - expect(enemy?.status?.effect).toBe(StatusEffect.BURN); - - game.move.select(MoveId.SKILL_SWAP); - await game.phaseInterceptor.to("BerryPhase"); - - expect(enemy?.status).toBeNull(); - }); -}); diff --git a/test/abilities/immunity.test.ts b/test/field/pokemon-funcs.test.ts similarity index 54% rename from test/abilities/immunity.test.ts rename to test/field/pokemon-funcs.test.ts index b6ca34bfaa3..c7edba71a37 100644 --- a/test/abilities/immunity.test.ts +++ b/test/field/pokemon-funcs.test.ts @@ -1,12 +1,11 @@ -import { AbilityId } from "#enums/ability-id"; -import { MoveId } from "#enums/move-id"; import { SpeciesId } from "#enums/species-id"; -import { StatusEffect } from "#enums/status-effect"; -import GameManager from "#test/testUtils/gameManager"; -import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; +import GameManager from "#test/testUtils/gameManager"; +import { MoveId } from "#enums/move-id"; +import { AbilityId } from "#enums/ability-id"; +import { StatusEffect } from "#enums/status-effect"; -describe("Abilities - Immunity", () => { +describe("Spec - Pokemon Functions", () => { let phaserGame: Phaser.Game; let game: GameManager; @@ -23,29 +22,29 @@ describe("Abilities - Immunity", () => { beforeEach(() => { game = new GameManager(phaserGame); game.override - .moveset([MoveId.SPLASH]) - .ability(AbilityId.BALL_FETCH) .battleStyle("single") .disableCrits() + .startingLevel(100) .enemySpecies(SpeciesId.MAGIKARP) .enemyAbility(AbilityId.BALL_FETCH) + .ability(AbilityId.BALL_FETCH) .enemyMoveset(MoveId.SPLASH); }); - it("should remove poison when gained", async () => { - game.override - .ability(AbilityId.IMMUNITY) - .enemyAbility(AbilityId.BALL_FETCH) - .moveset(MoveId.SKILL_SWAP) - .enemyMoveset(MoveId.SPLASH); - await game.classicMode.startBattle([SpeciesId.FEEBAS]); - const enemy = game.scene.getEnemyPokemon(); - enemy?.trySetStatus(StatusEffect.POISON); - expect(enemy?.status?.effect).toBe(StatusEffect.POISON); + describe("doSetStatus", () => { + it("should change the Pokemon's status, ignoring feasibility checks", async () => { + await game.classicMode.startBattle([SpeciesId.ACCELGOR]); - game.move.select(MoveId.SKILL_SWAP); - await game.phaseInterceptor.to("BerryPhase"); + const player = game.field.getPlayerPokemon(); - expect(enemy?.status).toBeNull(); + expect(player.status?.effect).toBeUndefined(); + player.doSetStatus(StatusEffect.BURN); + expect(player.status?.effect).toBe(StatusEffect.BURN); + + expect(player.canSetStatus(StatusEffect.SLEEP)).toBe(false); + player.doSetStatus(StatusEffect.SLEEP, 5); + expect(player.status?.effect).toBe(StatusEffect.SLEEP); + expect(player.status?.sleepTurnsRemaining).toBe(5); + }); }); }); diff --git a/test/moves/beat_up.test.ts b/test/moves/beat_up.test.ts index 184204a91aa..93f1743742f 100644 --- a/test/moves/beat_up.test.ts +++ b/test/moves/beat_up.test.ts @@ -74,7 +74,7 @@ describe("Moves - Beat Up", () => { const playerPokemon = game.scene.getPlayerPokemon()!; - game.scene.getPlayerParty()[1].trySetStatus(StatusEffect.BURN); + game.scene.getPlayerParty()[1].doSetStatus(StatusEffect.BURN); game.move.select(MoveId.BEAT_UP); diff --git a/test/moves/rest.test.ts b/test/moves/rest.test.ts index 8a489ae3d32..9ee118598b9 100644 --- a/test/moves/rest.test.ts +++ b/test/moves/rest.test.ts @@ -9,7 +9,7 @@ import GameManager from "#test/testUtils/gameManager"; import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; -describe("MoveId - Rest", () => { +describe("Move - Rest", () => { let phaserGame: Phaser.Game; let game: GameManager;