2024-08-22 06:49:33 -07:00
|
|
|
import { BerryPhase } from "#app/phases/berry-phase";
|
|
|
|
import { MessagePhase } from "#app/phases/message-phase";
|
|
|
|
import { MoveHeaderPhase } from "#app/phases/move-header-phase";
|
|
|
|
import { SwitchSummonPhase } from "#app/phases/switch-summon-phase";
|
|
|
|
import { TurnStartPhase } from "#app/phases/turn-start-phase";
|
2024-08-07 11:32:56 -07:00
|
|
|
import { Abilities } from "#enums/abilities";
|
|
|
|
import { Moves } from "#enums/moves";
|
2024-08-22 06:49:33 -07:00
|
|
|
import { Species } from "#enums/species";
|
2025-02-22 22:52:07 -06:00
|
|
|
import GameManager from "#test/testUtils/gameManager";
|
2025-02-22 12:33:32 -06:00
|
|
|
import i18next from "i18next";
|
2024-08-22 06:49:33 -07:00
|
|
|
import Phaser from "phaser";
|
2025-02-22 12:33:32 -06:00
|
|
|
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
2024-08-07 11:32:56 -07:00
|
|
|
|
2024-09-20 14:05:45 -07:00
|
|
|
|
2024-08-07 11:32:56 -07:00
|
|
|
describe("Moves - Focus Punch", () => {
|
|
|
|
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
|
|
|
|
.battleType("single")
|
|
|
|
.ability(Abilities.UNNERVE)
|
2024-10-04 13:08:31 +08:00
|
|
|
.moveset([ Moves.FOCUS_PUNCH ])
|
2024-08-07 11:32:56 -07:00
|
|
|
.enemySpecies(Species.GROUDON)
|
|
|
|
.enemyAbility(Abilities.INSOMNIA)
|
2024-09-09 09:55:11 -07:00
|
|
|
.enemyMoveset(Moves.SPLASH)
|
2024-08-07 11:32:56 -07:00
|
|
|
.startingLevel(100)
|
|
|
|
.enemyLevel(100);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(
|
|
|
|
"should deal damage at the end of turn if uninterrupted",
|
|
|
|
async () => {
|
2025-02-22 12:33:32 -06:00
|
|
|
await game.classicMode.startBattle([ Species.CHARIZARD ]);
|
2024-08-07 11:32:56 -07:00
|
|
|
|
|
|
|
const leadPokemon = game.scene.getPlayerPokemon()!;
|
|
|
|
const enemyPokemon = game.scene.getEnemyPokemon()!;
|
|
|
|
|
|
|
|
const enemyStartingHp = enemyPokemon.hp;
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
game.move.select(Moves.FOCUS_PUNCH);
|
2024-08-07 11:32:56 -07:00
|
|
|
|
|
|
|
await game.phaseInterceptor.to(MessagePhase);
|
|
|
|
|
|
|
|
expect(enemyPokemon.hp).toBe(enemyStartingHp);
|
|
|
|
expect(leadPokemon.getMoveHistory().length).toBe(0);
|
|
|
|
|
|
|
|
await game.phaseInterceptor.to(BerryPhase, false);
|
|
|
|
|
|
|
|
expect(enemyPokemon.hp).toBeLessThan(enemyStartingHp);
|
|
|
|
expect(leadPokemon.getMoveHistory().length).toBe(1);
|
2024-11-03 14:09:28 -08:00
|
|
|
expect(leadPokemon.turnData.totalDamageDealt).toBe(enemyStartingHp - enemyPokemon.hp);
|
2024-09-20 14:05:45 -07:00
|
|
|
}
|
2024-08-07 11:32:56 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
it(
|
|
|
|
"should fail if the user is hit",
|
|
|
|
async () => {
|
2024-10-04 13:08:31 +08:00
|
|
|
game.override.enemyMoveset([ Moves.TACKLE ]);
|
2024-08-07 11:32:56 -07:00
|
|
|
|
2025-02-22 12:33:32 -06:00
|
|
|
await game.classicMode.startBattle([ Species.CHARIZARD ]);
|
2024-08-07 11:32:56 -07:00
|
|
|
|
|
|
|
const leadPokemon = game.scene.getPlayerPokemon()!;
|
|
|
|
const enemyPokemon = game.scene.getEnemyPokemon()!;
|
|
|
|
|
|
|
|
const enemyStartingHp = enemyPokemon.hp;
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
game.move.select(Moves.FOCUS_PUNCH);
|
2024-08-07 11:32:56 -07:00
|
|
|
|
|
|
|
await game.phaseInterceptor.to(MessagePhase);
|
|
|
|
|
|
|
|
expect(enemyPokemon.hp).toBe(enemyStartingHp);
|
|
|
|
expect(leadPokemon.getMoveHistory().length).toBe(0);
|
|
|
|
|
|
|
|
await game.phaseInterceptor.to(BerryPhase, false);
|
|
|
|
|
|
|
|
expect(enemyPokemon.hp).toBe(enemyStartingHp);
|
|
|
|
expect(leadPokemon.getMoveHistory().length).toBe(1);
|
2024-11-03 14:09:28 -08:00
|
|
|
expect(leadPokemon.turnData.totalDamageDealt).toBe(0);
|
2024-09-20 14:05:45 -07:00
|
|
|
}
|
2024-08-07 11:32:56 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
it(
|
|
|
|
"should be cancelled if the user falls asleep mid-turn",
|
|
|
|
async () => {
|
2024-10-04 13:08:31 +08:00
|
|
|
game.override.enemyMoveset([ Moves.SPORE ]);
|
2024-08-07 11:32:56 -07:00
|
|
|
|
2025-02-22 12:33:32 -06:00
|
|
|
await game.classicMode.startBattle([ Species.CHARIZARD ]);
|
2024-08-07 11:32:56 -07:00
|
|
|
|
|
|
|
const leadPokemon = game.scene.getPlayerPokemon()!;
|
|
|
|
const enemyPokemon = game.scene.getEnemyPokemon()!;
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
game.move.select(Moves.FOCUS_PUNCH);
|
2024-08-07 11:32:56 -07:00
|
|
|
|
|
|
|
await game.phaseInterceptor.to(MessagePhase); // Header message
|
|
|
|
|
|
|
|
expect(leadPokemon.getMoveHistory().length).toBe(0);
|
|
|
|
|
|
|
|
await game.phaseInterceptor.to(BerryPhase, false);
|
|
|
|
|
|
|
|
expect(leadPokemon.getMoveHistory().length).toBe(1);
|
|
|
|
expect(enemyPokemon.hp).toBe(enemyPokemon.getMaxHp());
|
2024-09-20 14:05:45 -07:00
|
|
|
}
|
2024-08-07 11:32:56 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
it(
|
|
|
|
"should not queue its pre-move message before an enemy switches",
|
|
|
|
async () => {
|
|
|
|
/** Guarantee a Trainer battle with multiple enemy Pokemon */
|
|
|
|
game.override.startingWave(25);
|
|
|
|
|
2025-02-22 12:33:32 -06:00
|
|
|
await game.classicMode.startBattle([ Species.CHARIZARD ]);
|
2024-08-07 11:32:56 -07:00
|
|
|
|
2024-09-04 10:56:57 -07:00
|
|
|
game.forceEnemyToSwitch();
|
2024-08-22 06:49:33 -07:00
|
|
|
game.move.select(Moves.FOCUS_PUNCH);
|
2024-08-07 11:32:56 -07:00
|
|
|
|
|
|
|
await game.phaseInterceptor.to(TurnStartPhase);
|
|
|
|
|
|
|
|
expect(game.scene.getCurrentPhase() instanceof SwitchSummonPhase).toBeTruthy();
|
|
|
|
expect(game.scene.phaseQueue.find(phase => phase instanceof MoveHeaderPhase)).toBeDefined();
|
2024-09-20 14:05:45 -07:00
|
|
|
}
|
2024-08-07 11:32:56 -07:00
|
|
|
);
|
2025-02-22 12:33:32 -06:00
|
|
|
it("should replace the 'but it failed' text when the user gets hit", async () => {
|
|
|
|
game.override.enemyMoveset([ Moves.TACKLE ]);
|
|
|
|
await game.classicMode.startBattle([ Species.CHARIZARD ]);
|
|
|
|
|
|
|
|
game.move.select(Moves.FOCUS_PUNCH);
|
|
|
|
await game.phaseInterceptor.to("MoveEndPhase", true);
|
|
|
|
await game.phaseInterceptor.to("MessagePhase", false);
|
|
|
|
const consoleSpy = vi.spyOn(console, "log");
|
|
|
|
await game.phaseInterceptor.to("MoveEndPhase", true);
|
2025-03-01 05:22:51 +01:00
|
|
|
expect(consoleSpy).nthCalledWith(1, i18next.t("moveTriggers:lostFocus", { pokemonName: "Charizard" }));
|
2025-02-22 12:33:32 -06:00
|
|
|
});
|
2024-08-07 11:32:56 -07:00
|
|
|
});
|