2024-07-25 15:51:05 -07:00
|
|
|
import { Stat } from "#app/data/pokemon-stat";
|
2024-08-22 06:49:33 -07:00
|
|
|
import { EnemyCommandPhase } from "#app/phases/enemy-command-phase";
|
|
|
|
import { SelectTargetPhase } from "#app/phases/select-target-phase";
|
|
|
|
import { TurnStartPhase } from "#app/phases/turn-start-phase";
|
2024-06-13 18:44:23 -04:00
|
|
|
import { Abilities } from "#enums/abilities";
|
|
|
|
import { Moves } from "#enums/moves";
|
|
|
|
import { Species } from "#enums/species";
|
2024-08-22 06:49:33 -07:00
|
|
|
import GameManager from "#test/utils/gameManager";
|
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
|
|
|
});
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
it("opponent faster than player 50 vs 150", async () => {
|
2024-06-08 00:33:45 +02:00
|
|
|
await game.startBattle([
|
|
|
|
Species.BULBASAUR,
|
|
|
|
]);
|
|
|
|
game.scene.getParty()[0].stats[Stat.SPD] = 50;
|
|
|
|
game.scene.currentBattle.enemyParty[0].stats[Stat.SPD] = 150;
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
game.move.select(Moves.TACKLE);
|
2024-06-08 00:33:45 +02:00
|
|
|
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);
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
it("Player faster than opponent 150 vs 50", async () => {
|
2024-06-08 00:33:45 +02:00
|
|
|
await game.startBattle([
|
|
|
|
Species.BULBASAUR,
|
|
|
|
]);
|
|
|
|
game.scene.getParty()[0].stats[Stat.SPD] = 150;
|
|
|
|
game.scene.currentBattle.enemyParty[0].stats[Stat.SPD] = 50;
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
game.move.select(Moves.TACKLE);
|
2024-06-08 00:33:45 +02:00
|
|
|
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);
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
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;
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
game.move.select(Moves.TACKLE);
|
|
|
|
game.move.select(Moves.TACKLE, 1);
|
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);
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
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;
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
game.move.select(Moves.TACKLE);
|
|
|
|
game.move.select(Moves.TACKLE, 1);
|
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);
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
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;
|
|
|
|
|
2024-08-22 06:49:33 -07:00
|
|
|
game.move.select(Moves.TACKLE);
|
|
|
|
game.move.select(Moves.TACKLE, 1);
|
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);
|
|
|
|
});
|