2024-07-25 15:51:05 -07:00
|
|
|
import { Stat } from "#app/data/pokemon-stat";
|
2024-06-08 00:33:45 +02:00
|
|
|
import {
|
2024-06-08 21:54:20 +02:00
|
|
|
CommandPhase, EnemyCommandPhase, SelectTargetPhase,
|
2024-06-08 00:33:45 +02:00
|
|
|
TurnStartPhase
|
|
|
|
} from "#app/phases";
|
2024-07-25 15:51:05 -07:00
|
|
|
import GameManager from "#app/test/utils/gameManager";
|
|
|
|
import { getMovePosition } from "#app/test/utils/gameManagerUtils";
|
|
|
|
import { Command } from "#app/ui/command-ui-handler";
|
2024-06-08 00:33:45 +02:00
|
|
|
import TargetSelectUiHandler from "#app/ui/target-select-ui-handler";
|
2024-07-25 15:51:05 -07:00
|
|
|
import { Mode } from "#app/ui/ui";
|
2024-06-13 18:44:23 -04:00
|
|
|
import { Abilities } from "#enums/abilities";
|
2024-07-25 15:51:05 -07:00
|
|
|
import { Button } from "#enums/buttons";
|
2024-06-13 18:44:23 -04:00
|
|
|
import { Moves } from "#enums/moves";
|
|
|
|
import { Species } from "#enums/species";
|
2024-07-25 15:51:05 -07:00
|
|
|
import Phaser from "phaser";
|
|
|
|
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
2024-06-08 00:33:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
describe("Battle order", () => {
|
|
|
|
let phaserGame: Phaser.Game;
|
|
|
|
let game: GameManager;
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
phaserGame = new Phaser.Game({
|
|
|
|
type: Phaser.HEADLESS,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
game.phaseInterceptor.restoreOg();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
game = new GameManager(phaserGame);
|
2024-07-25 14:48:48 -07:00
|
|
|
game.override.battleType("single");
|
2024-07-25 14:57:47 -07:00
|
|
|
game.override.enemySpecies(Species.MEWTWO);
|
2024-07-25 15:05:32 -07:00
|
|
|
game.override.enemyAbility(Abilities.INSOMNIA);
|
2024-07-25 15:35:20 -07:00
|
|
|
game.override.ability(Abilities.INSOMNIA);
|
2024-07-25 15:51:05 -07:00
|
|
|
game.override.moveset([Moves.TACKLE]);
|
2024-06-08 00:33:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("opponent faster than player 50 vs 150", async() => {
|
|
|
|
await game.startBattle([
|
|
|
|
Species.BULBASAUR,
|
|
|
|
]);
|
|
|
|
game.scene.getParty()[0].stats[Stat.SPD] = 50;
|
|
|
|
game.scene.currentBattle.enemyParty[0].stats[Stat.SPD] = 150;
|
|
|
|
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
|
|
|
|
game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex());
|
|
|
|
});
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.FIGHT, () => {
|
|
|
|
const movePosition = getMovePosition(game.scene, 0, Moves.TACKLE);
|
|
|
|
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
|
|
|
|
});
|
|
|
|
await game.phaseInterceptor.run(EnemyCommandPhase);
|
|
|
|
const phase = game.scene.getCurrentPhase() as TurnStartPhase;
|
|
|
|
const order = phase.getOrder();
|
|
|
|
expect(order[0]).toBe(2);
|
|
|
|
expect(order[1]).toBe(0);
|
|
|
|
}, 20000);
|
|
|
|
|
|
|
|
it("Player faster than opponent 150 vs 50", async() => {
|
|
|
|
await game.startBattle([
|
|
|
|
Species.BULBASAUR,
|
|
|
|
]);
|
|
|
|
game.scene.getParty()[0].stats[Stat.SPD] = 150;
|
|
|
|
game.scene.currentBattle.enemyParty[0].stats[Stat.SPD] = 50;
|
|
|
|
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
|
|
|
|
game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex());
|
|
|
|
});
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.FIGHT, () => {
|
|
|
|
const movePosition = getMovePosition(game.scene, 0, Moves.TACKLE);
|
|
|
|
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
|
|
|
|
});
|
|
|
|
await game.phaseInterceptor.run(EnemyCommandPhase);
|
|
|
|
const phase = game.scene.getCurrentPhase() as TurnStartPhase;
|
|
|
|
const order = phase.getOrder();
|
|
|
|
expect(order[0]).toBe(0);
|
|
|
|
expect(order[1]).toBe(2);
|
|
|
|
}, 20000);
|
|
|
|
|
|
|
|
it("double - both opponents faster than player 50/50 vs 150/150", async() => {
|
2024-07-25 14:48:48 -07:00
|
|
|
game.override.battleType("double");
|
2024-06-08 00:33:45 +02:00
|
|
|
await game.startBattle([
|
|
|
|
Species.BULBASAUR,
|
|
|
|
Species.BLASTOISE,
|
|
|
|
]);
|
|
|
|
game.scene.getParty()[0].stats[Stat.SPD] = 50;
|
|
|
|
game.scene.getParty()[1].stats[Stat.SPD] = 50;
|
|
|
|
game.scene.currentBattle.enemyParty[0].stats[Stat.SPD] = 150;
|
|
|
|
game.scene.currentBattle.enemyParty[1].stats[Stat.SPD] = 150;
|
|
|
|
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
|
|
|
|
game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex());
|
|
|
|
});
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.FIGHT, () => {
|
|
|
|
const movePosition = getMovePosition(game.scene, 0, Moves.TACKLE);
|
|
|
|
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
|
|
|
|
});
|
|
|
|
game.onNextPrompt("SelectTargetPhase", Mode.TARGET_SELECT, () => {
|
|
|
|
const handler = game.scene.ui.getHandler() as TargetSelectUiHandler;
|
|
|
|
handler.processInput(Button.ACTION);
|
|
|
|
});
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
|
|
|
|
game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex());
|
|
|
|
});
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.FIGHT, () => {
|
|
|
|
const movePosition = getMovePosition(game.scene, 0, Moves.TACKLE);
|
|
|
|
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
|
|
|
|
});
|
|
|
|
game.onNextPrompt("SelectTargetPhase", Mode.TARGET_SELECT, () => {
|
|
|
|
const handler = game.scene.ui.getHandler() as TargetSelectUiHandler;
|
|
|
|
handler.processInput(Button.ACTION);
|
|
|
|
});
|
2024-06-08 21:54:20 +02:00
|
|
|
await game.phaseInterceptor.runFrom(SelectTargetPhase).to(TurnStartPhase, false);
|
2024-06-08 00:33:45 +02:00
|
|
|
const phase = game.scene.getCurrentPhase() as TurnStartPhase;
|
|
|
|
const order = phase.getOrder();
|
|
|
|
expect(order.indexOf(0)).toBeGreaterThan(order.indexOf(2));
|
|
|
|
expect(order.indexOf(0)).toBeGreaterThan(order.indexOf(3));
|
|
|
|
expect(order.indexOf(1)).toBeGreaterThan(order.indexOf(2));
|
|
|
|
expect(order.indexOf(1)).toBeGreaterThan(order.indexOf(3));
|
|
|
|
}, 20000);
|
|
|
|
|
|
|
|
it("double - speed tie except 1 - 100/100 vs 100/150", async() => {
|
2024-07-25 14:48:48 -07:00
|
|
|
game.override.battleType("double");
|
2024-06-08 00:33:45 +02:00
|
|
|
await game.startBattle([
|
|
|
|
Species.BULBASAUR,
|
|
|
|
Species.BLASTOISE,
|
|
|
|
]);
|
|
|
|
game.scene.getParty()[0].stats[Stat.SPD] = 100;
|
|
|
|
game.scene.getParty()[1].stats[Stat.SPD] = 100;
|
|
|
|
game.scene.currentBattle.enemyParty[0].stats[Stat.SPD] = 100;
|
|
|
|
game.scene.currentBattle.enemyParty[1].stats[Stat.SPD] = 150;
|
|
|
|
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
|
|
|
|
game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex());
|
|
|
|
});
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.FIGHT, () => {
|
|
|
|
const movePosition = getMovePosition(game.scene, 0, Moves.TACKLE);
|
|
|
|
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
|
|
|
|
});
|
|
|
|
game.onNextPrompt("SelectTargetPhase", Mode.TARGET_SELECT, () => {
|
|
|
|
const handler = game.scene.ui.getHandler() as TargetSelectUiHandler;
|
|
|
|
handler.processInput(Button.ACTION);
|
|
|
|
});
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
|
|
|
|
game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex());
|
|
|
|
});
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.FIGHT, () => {
|
|
|
|
const movePosition = getMovePosition(game.scene, 0, Moves.TACKLE);
|
|
|
|
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
|
|
|
|
});
|
|
|
|
game.onNextPrompt("SelectTargetPhase", Mode.TARGET_SELECT, () => {
|
|
|
|
const handler = game.scene.ui.getHandler() as TargetSelectUiHandler;
|
|
|
|
handler.processInput(Button.ACTION);
|
|
|
|
});
|
2024-06-08 21:54:20 +02:00
|
|
|
await game.phaseInterceptor.runFrom(SelectTargetPhase).to(TurnStartPhase, false);
|
2024-06-08 00:33:45 +02:00
|
|
|
const phase = game.scene.getCurrentPhase() as TurnStartPhase;
|
|
|
|
const order = phase.getOrder();
|
|
|
|
expect(order.indexOf(3)).toBeLessThan(order.indexOf(0));
|
|
|
|
expect(order.indexOf(3)).toBeLessThan(order.indexOf(1));
|
|
|
|
expect(order.indexOf(3)).toBeLessThan(order.indexOf(2));
|
|
|
|
}, 20000);
|
|
|
|
|
|
|
|
it("double - speed tie 100/150 vs 100/150", async() => {
|
2024-07-25 14:48:48 -07:00
|
|
|
game.override.battleType("double");
|
2024-06-08 00:33:45 +02:00
|
|
|
await game.startBattle([
|
|
|
|
Species.BULBASAUR,
|
|
|
|
Species.BLASTOISE,
|
|
|
|
]);
|
|
|
|
game.scene.getParty()[0].stats[Stat.SPD] = 100;
|
|
|
|
game.scene.getParty()[1].stats[Stat.SPD] = 150;
|
|
|
|
game.scene.currentBattle.enemyParty[0].stats[Stat.SPD] = 100;
|
|
|
|
game.scene.currentBattle.enemyParty[1].stats[Stat.SPD] = 150;
|
|
|
|
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
|
|
|
|
game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex());
|
|
|
|
});
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.FIGHT, () => {
|
|
|
|
const movePosition = getMovePosition(game.scene, 0, Moves.TACKLE);
|
|
|
|
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
|
|
|
|
});
|
|
|
|
game.onNextPrompt("SelectTargetPhase", Mode.TARGET_SELECT, () => {
|
|
|
|
const handler = game.scene.ui.getHandler() as TargetSelectUiHandler;
|
|
|
|
handler.processInput(Button.ACTION);
|
|
|
|
});
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
|
|
|
|
game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex());
|
|
|
|
});
|
|
|
|
game.onNextPrompt("CommandPhase", Mode.FIGHT, () => {
|
|
|
|
const movePosition = getMovePosition(game.scene, 0, Moves.TACKLE);
|
|
|
|
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
|
|
|
|
});
|
|
|
|
game.onNextPrompt("SelectTargetPhase", Mode.TARGET_SELECT, () => {
|
|
|
|
const handler = game.scene.ui.getHandler() as TargetSelectUiHandler;
|
|
|
|
handler.processInput(Button.ACTION);
|
|
|
|
});
|
2024-06-08 21:54:20 +02:00
|
|
|
await game.phaseInterceptor.runFrom(SelectTargetPhase).to(TurnStartPhase, false);
|
2024-06-08 00:33:45 +02:00
|
|
|
const phase = game.scene.getCurrentPhase() as TurnStartPhase;
|
|
|
|
const order = phase.getOrder();
|
|
|
|
expect(order.indexOf(1)).toBeLessThan(order.indexOf(0));
|
|
|
|
expect(order.indexOf(1)).toBeLessThan(order.indexOf(2));
|
|
|
|
expect(order.indexOf(3)).toBeLessThan(order.indexOf(0));
|
|
|
|
expect(order.indexOf(3)).toBeLessThan(order.indexOf(2));
|
|
|
|
}, 20000);
|
|
|
|
});
|