From 285ad9043ae4117b5aafc4a07d7ba04446a98cd7 Mon Sep 17 00:00:00 2001 From: frutescens Date: Thu, 22 Aug 2024 10:11:24 -0700 Subject: [PATCH] Updating battle-order.test.ts --- src/test/battle/battle-order.test.ts | 95 ++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 28 deletions(-) diff --git a/src/test/battle/battle-order.test.ts b/src/test/battle/battle-order.test.ts index 5ed3fa52e61..ab6a173bafd 100644 --- a/src/test/battle/battle-order.test.ts +++ b/src/test/battle/battle-order.test.ts @@ -10,7 +10,7 @@ import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; -import { CommandPhase } from "#app/phases/command-phase.js"; +import { CommandPhase } from "#app/phases/command-phase"; import { EnemyCommandPhase } from "#app/phases/enemy-command-phase"; import { SelectTargetPhase } from "#app/phases/select-target-phase"; import { TurnStartPhase } from "#app/phases/turn-start-phase"; @@ -43,6 +43,7 @@ describe("Battle order", () => { await game.startBattle([ Species.BULBASAUR, ]); + game.scene.getParty()[0].stats[Stat.SPD] = 50; game.scene.currentBattle.enemyParty[0].stats[Stat.SPD] = 150; @@ -54,10 +55,13 @@ describe("Battle order", () => { (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); }); await game.phaseInterceptor.run(EnemyCommandPhase); + + const playerPokemonIndex = game.scene.getPlayerPokemon()?.getBattlerIndex(); + const enemyPokemonIndex = game.scene.getEnemyPokemon()?.getBattlerIndex(); const phase = game.scene.getCurrentPhase() as TurnStartPhase; const order = phase.getCommandOrder(); - expect(order[0]).toBe(2); - expect(order[1]).toBe(0); + expect(order[0]).toBe(enemyPokemonIndex); + expect(order[1]).toBe(playerPokemonIndex); }, 20000); it("Player faster than opponent 150 vs 50", async() => { @@ -75,10 +79,13 @@ describe("Battle order", () => { (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); }); await game.phaseInterceptor.run(EnemyCommandPhase); + + const playerPokemonIndex = game.scene.getPlayerPokemon()?.getBattlerIndex(); + const enemyPokemonIndex = game.scene.getEnemyPokemon()?.getBattlerIndex(); const phase = game.scene.getCurrentPhase() as TurnStartPhase; const order = phase.getCommandOrder(); - expect(order[0]).toBe(0); - expect(order[1]).toBe(2); + expect(order[0]).toBe(playerPokemonIndex); + expect(order[1]).toBe(enemyPokemonIndex); }, 20000); it("double - both opponents faster than player 50/50 vs 150/150", async() => { @@ -87,10 +94,16 @@ describe("Battle order", () => { 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; + + const playerParty = game.scene.getParty(); + const playerPokemon1 = playerParty[0]; + const playerPokemon2 = playerParty[1]; + const enemyPokemon1 = game.scene.currentBattle.enemyParty[0]; + const enemyPokemon2 = game.scene.currentBattle.enemyParty[1]; + playerPokemon1.stats[Stat.SPD] = 50; + playerPokemon2.stats[Stat.SPD] = 50; + enemyPokemon1.stats[Stat.SPD] = 150; + enemyPokemon2.stats[Stat.SPD] = 150; game.onNextPrompt("CommandPhase", Mode.COMMAND, () => { game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex()); @@ -115,12 +128,17 @@ describe("Battle order", () => { handler.processInput(Button.ACTION); }); await game.phaseInterceptor.runFrom(SelectTargetPhase).to(TurnStartPhase, false); + + const pp1Index = playerPokemon1?.getBattlerIndex(); + const pp2Index = playerPokemon2?.getBattlerIndex(); + const ep1Index = enemyPokemon1?.getBattlerIndex(); + const ep2Index = enemyPokemon2?.getBattlerIndex(); const phase = game.scene.getCurrentPhase() as TurnStartPhase; const order = phase.getCommandOrder(); - 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)); + expect(order.slice(0,2).includes(ep1Index)).toBe(true); + expect(order.slice(0,2).includes(ep2Index)).toBe(true); + expect(order.slice(2,4).includes(pp1Index)).toBe(true); + expect(order.slice(2,4).includes(pp2Index)).toBe(true); }, 20000); it("double - speed tie except 1 - 100/100 vs 100/150", async() => { @@ -129,10 +147,15 @@ describe("Battle order", () => { 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; + const playerParty = game.scene.getParty(); + const playerPokemon1 = playerParty[0]; + const playerPokemon2 = playerParty[1]; + const enemyPokemon1 = game.scene.currentBattle.enemyParty[0]; + const enemyPokemon2 = game.scene.currentBattle.enemyParty[1]; + playerPokemon1.stats[Stat.SPD] = 100; + playerPokemon2.stats[Stat.SPD] = 100; + enemyPokemon1.stats[Stat.SPD] = 100; + enemyPokemon2.stats[Stat.SPD] = 150; game.onNextPrompt("CommandPhase", Mode.COMMAND, () => { game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex()); @@ -157,11 +180,17 @@ describe("Battle order", () => { handler.processInput(Button.ACTION); }); await game.phaseInterceptor.runFrom(SelectTargetPhase).to(TurnStartPhase, false); + + const pp1Index = playerPokemon1?.getBattlerIndex(); + const pp2Index = playerPokemon2?.getBattlerIndex(); + const ep1Index = enemyPokemon1?.getBattlerIndex(); + const ep2Index = enemyPokemon2?.getBattlerIndex(); const phase = game.scene.getCurrentPhase() as TurnStartPhase; const order = phase.getCommandOrder(); - expect(order.indexOf(3)).toBeLessThan(order.indexOf(0)); - expect(order.indexOf(3)).toBeLessThan(order.indexOf(1)); - expect(order.indexOf(3)).toBeLessThan(order.indexOf(2)); + expect(order[0]).toBe(ep2Index); + expect(order.slice(1,4).includes(ep1Index)).toBe(true); + expect(order.slice(1,4).includes(pp2Index)).toBe(true); + expect(order.slice(1,4).includes(pp1Index)).toBe(true); }, 20000); it("double - speed tie 100/150 vs 100/150", async() => { @@ -170,10 +199,15 @@ describe("Battle order", () => { 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; + const playerParty = game.scene.getParty(); + const playerPokemon1 = playerParty[0]; + const playerPokemon2 = playerParty[1]; + const enemyPokemon1 = game.scene.currentBattle.enemyParty[0]; + const enemyPokemon2 = game.scene.currentBattle.enemyParty[1]; + playerPokemon1.stats[Stat.SPD] = 100; + playerPokemon2.stats[Stat.SPD] = 150; + enemyPokemon1.stats[Stat.SPD] = 100; + enemyPokemon2.stats[Stat.SPD] = 150; game.onNextPrompt("CommandPhase", Mode.COMMAND, () => { game.scene.ui.setMode(Mode.FIGHT, (game.scene.getCurrentPhase() as CommandPhase).getFieldIndex()); @@ -198,11 +232,16 @@ describe("Battle order", () => { handler.processInput(Button.ACTION); }); await game.phaseInterceptor.runFrom(SelectTargetPhase).to(TurnStartPhase, false); + + const pp1Index = playerPokemon1?.getBattlerIndex(); + const pp2Index = playerPokemon2?.getBattlerIndex(); + const ep1Index = enemyPokemon1?.getBattlerIndex(); + const ep2Index = enemyPokemon2?.getBattlerIndex(); const phase = game.scene.getCurrentPhase() as TurnStartPhase; const order = phase.getCommandOrder(); - 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)); + expect(order.slice(0,2).includes(pp2Index)).toBe(true); + expect(order.slice(0,2).includes(ep2Index)).toBe(true); + expect(order.slice(2,4).includes(ep1Index)).toBe(true); + expect(order.slice(2,4).includes(pp1Index)).toBe(true); }, 20000); });