From 8badfe7d6de6b0db097199285d398d00341f5298 Mon Sep 17 00:00:00 2001 From: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Date: Fri, 31 Jan 2025 12:04:04 -0600 Subject: [PATCH] Add more magic bounce tests --- src/test/abilities/magic_bounce.test.ts | 120 ++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 9 deletions(-) diff --git a/src/test/abilities/magic_bounce.test.ts b/src/test/abilities/magic_bounce.test.ts index 1668878e032..bd0c639e446 100644 --- a/src/test/abilities/magic_bounce.test.ts +++ b/src/test/abilities/magic_bounce.test.ts @@ -1,13 +1,15 @@ import { BattlerIndex } from "#app/battle"; import { ArenaTagSide } from "#app/data/arena-tag"; +import { allMoves } from "#app/data/move"; import { ArenaTagType } from "#app/enums/arena-tag-type"; +import { BattlerTagType } from "#app/enums/battler-tag-type"; import { Stat } from "#app/enums/stat"; 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, expect, it } from "vitest"; +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; describe("Abilities - Magic Bounce", () => { let phaserGame: Phaser.Game; @@ -28,7 +30,7 @@ describe("Abilities - Magic Bounce", () => { game.override .ability(Abilities.BALL_FETCH) .battleType("single") - .moveset( [ Moves.GROWL ]) + .moveset( [ Moves.GROWL, Moves.SPLASH ]) .disableCrits() .enemySpecies(Species.MAGIKARP) .enemyAbility(Abilities.MAGIC_BOUNCE) @@ -40,7 +42,7 @@ describe("Abilities - Magic Bounce", () => { game.move.select(Moves.GROWL); await game.phaseInterceptor.to("BerryPhase"); - expect(game.scene.getPlayerPokemon()?.getStatStage(Stat.ATK)).toBe(-1); + expect(game.scene.getPlayerPokemon()!.getStatStage(Stat.ATK)).toBe(-1); }); it("should not bounce moves while the target is in the semi-invulnerable state", async () => { @@ -53,7 +55,7 @@ describe("Abilities - Magic Bounce", () => { await game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER ]); await game.phaseInterceptor.to("BerryPhase"); - expect(game.scene.getPlayerPokemon()?.getStatStage(Stat.ATK)).toBe(0); + expect(game.scene.getPlayerPokemon()!.getStatStage(Stat.ATK)).toBe(0); }); it("should individually bounce back multi-target moves", async () => { @@ -77,7 +79,7 @@ describe("Abilities - Magic Bounce", () => { game.move.select(Moves.GROWL); await game.phaseInterceptor.to("BerryPhase"); - expect(game.scene.getPlayerPokemon()?.getStatStage(Stat.ATK)).toBe(-1); + expect(game.scene.getPlayerPokemon()!.getStatStage(Stat.ATK)).toBe(-1); }); it("should not bounce back a move that was just bounced", async () => { @@ -87,7 +89,7 @@ describe("Abilities - Magic Bounce", () => { game.move.select(Moves.GROWL); await game.phaseInterceptor.to("BerryPhase"); - expect(game.scene.getPlayerPokemon()?.getStatStage(Stat.ATK)).toBe(-1); + expect(game.scene.getPlayerPokemon()!.getStatStage(Stat.ATK)).toBe(-1); }); // todo while Mirror Armor is not implemented @@ -98,7 +100,7 @@ describe("Abilities - Magic Bounce", () => { game.move.select(Moves.GROWL); await game.phaseInterceptor.to("BerryPhase"); - expect(game.scene.getEnemyPokemon()?.getStatStage(Stat.ATK)).toBe(-1); + expect(game.scene.getEnemyPokemon()!.getStatStage(Stat.ATK)).toBe(-1); }); it("should not bounce back a move from a mold breaker user", async () => { @@ -108,10 +110,10 @@ describe("Abilities - Magic Bounce", () => { game.move.select(Moves.GROWL); await game.phaseInterceptor.to("BerryPhase"); - expect(game.scene.getEnemyPokemon()?.getStatStage(Stat.ATK)).toBe(-1); + expect(game.scene.getEnemyPokemon()!.getStatStage(Stat.ATK)).toBe(-1); }); - it("should bounce back a spread status against both pokemon", async () => { + it("should bounce back a spread status move against both pokemon", async () => { game.override.battleType("double"); game.override.moveset([ Moves.GROWL, Moves.SPLASH ]); game.override.enemyMoveset([ Moves.SPLASH ]); @@ -135,4 +137,104 @@ describe("Abilities - Magic Bounce", () => { expect(game.scene.arena.getTagOnSide(ArenaTagType.SPIKES, ArenaTagSide.PLAYER)).toBe(1); expect(game.scene.arena.getTagOnSide(ArenaTagType.SPIKES, ArenaTagSide.ENEMY)).toBe(0); }); + + it("should not bounce back curse", async() => { + await game.classicMode.startBattle([ Species.GASTLY ]); + game.override.moveset([ Moves.CURSE ]); + + game.move.select(Moves.CURSE); + await game.phaseInterceptor.to("BerryPhase"); + + expect(game.scene.getEnemyPokemon()!.getTag(BattlerTagType.CURSED)).toBeDefined(); + }); + + // todo: a move reflected by magic bounce counts as though it failed. + + it("should not count the bounced move as the last move used", async () => { + game.override.enemyMoveset([ Moves.INSTRUCT, Moves.GROWL, Moves.SPLASH ]); + game.override.battleType("double"); + await game.classicMode.startBattle([ Species.MAGIKARP, Species.MAGIKARP ]); + + game.move.select(Moves.GROWL, 0); + game.move.select(Moves.SPLASH, 1); + game.forceEnemyMove(Moves.SPLASH); + game.forceEnemyMove(Moves.INSTRUCT); + game.setTurnOrder([ BattlerIndex.ENEMY, BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY_2 ]); + await game.phaseInterceptor.to("BerryPhase"); + expect(game.scene.getEnemyPokemon()!.getLastXMoves(1)[0].move).toEqual([ Moves.SPLASH ]); + }); + + it("should cause stomping tantrum to double in power if the bounced move fails", async () => { + game.override.moveset([ Moves.SPLASH ]); + await game.classicMode.startBattle([ Species.MAGIKARP ]); + + game.move.select(Moves.SPLASH); + await game.phaseInterceptor.to("BerryPhase"); + + expect(game.scene.getPlayerPokemon()!.getStatStage(Stat.ATK)).toBe(-1); + }); + + it("should properly cause the enemy's stomping tantrum to be doubled in power after bouncing", async () => { + game.override.battleType("double"); + game.override.enemyMoveset([ Moves.GROWL, Moves.STOMPING_TANTRUM, Moves.CHARM, Moves.SPLASH ]); + game.override.enemyLevel(50); + await game.classicMode.startBattle([ Species.MAGIKARP ]); + + const stomping_tantrum = allMoves[Moves.STOMPING_TANTRUM]; + vi.spyOn(stomping_tantrum, "calculateBattlePower"); + + game.move.select(Moves.CHARM, 0, BattlerIndex.ENEMY); + game.move.select(Moves.SPLASH, 1); + await game.phaseInterceptor.to("TurnEndPhase"); + + game.move.select(Moves.STOMPING_TANTRUM, 0, BattlerIndex.ENEMY_2); + await game.phaseInterceptor.to("BerryPhase"); + expect(stomping_tantrum.calculateBattlePower).toHaveReturnedWith(150); + + await game.toNextTurn(); + game.move.select(Moves.GROWL, 0); + game.move.select(Moves.SPLASH, 1); + await game.phaseInterceptor.to("BerryPhase"); + expect(stomping_tantrum.calculateBattlePower).toHaveReturnedWith(75); + }); + + it("should respect immunities when bouncing a move", async () => { + vi.spyOn(allMoves[Moves.THUNDER_WAVE], "accuracy", "get").mockReturnValue(100); + game.override.moveset([ Moves.THUNDER_WAVE, Moves.GROWL ]); + game.override.ability(Abilities.SOUNDPROOF); + await game.classicMode.startBattle([ Species.PHANPY ]); + + // Turn 1 - thunder wave immunity test + game.move.select(Moves.THUNDER_WAVE); + await game.phaseInterceptor.to("BerryPhase"); + expect(game.scene.getPlayerPokemon()!.status).toBeNull(); + + // Turn 2 - soundproof immunity test + game.move.select(Moves.GROWL); + await game.phaseInterceptor.to("BerryPhase"); + expect(game.scene.getPlayerPokemon()!.getStatStage(Stat.ATK)).toBe(0); + }); + + it("should bounce back a move before the accuracy check", async () => { + game.override.moveset([ Moves.SPLASH ]); + await game.classicMode.startBattle([ Species.MAGIKARP ]); + + const attacker = game.scene.getPlayerPokemon()!; + + vi.spyOn(attacker, "getAccuracyMultiplier").mockReturnValue(0.0); + game.move.select(Moves.SPLASH); + await game.phaseInterceptor.to("BerryPhase"); + expect(game.scene.getPlayerPokemon()!.getStatStage(Stat.ATK)).toBe(-1); + }); + + it("should take the accuracy of the magic bounce user into account", async () => { + game.override.moveset([ Moves.SPORE ]); + const opponent = game.scene.getEnemyPokemon()!; + await game.classicMode.startBattle([ Species.MAGIKARP ]); + + vi.spyOn(opponent, "getAccuracyMultiplier").mockReturnValue(0); + game.move.select(Moves.SPORE); + await game.phaseInterceptor.to("BerryPhase"); + expect(game.scene.getPlayerPokemon()!.status).toBeNull(); + }); });