[Test] Add helper function to modify the turn order for tests (#3374)

* Add helper function to modify the turn order for tests

* Replace manual speed modification with new helper function

* Replace `vi.spyOn()` instances with helper function
This commit is contained in:
NightKev 2024-08-07 05:52:20 -07:00 committed by GitHub
parent df9596a9dc
commit 0ef329e8eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 62 additions and 56 deletions

View File

@ -11,6 +11,8 @@ import { Moves } from "#enums/moves";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { changeTurnOrder } from "../utils/testUtils";
import { BattlerIndex } from "#app/battle.js";
describe("Abilities - Serene Grace", () => { describe("Abilities - Serene Grace", () => {
@ -45,7 +47,6 @@ describe("Abilities - Serene Grace", () => {
game.scene.getEnemyParty()[0].stats[Stat.SPDEF] = 10000; game.scene.getEnemyParty()[0].stats[Stat.SPDEF] = 10000;
game.scene.getEnemyParty()[0].stats[Stat.SPD] = 1;
expect(game.scene.getParty()[0].formIndex).toBe(0); expect(game.scene.getParty()[0].formIndex).toBe(0);
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => { game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
@ -56,6 +57,7 @@ describe("Abilities - Serene Grace", () => {
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
}); });
await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
// Check chance of Air Slash without Serene Grace // Check chance of Air Slash without Serene Grace
@ -78,7 +80,6 @@ describe("Abilities - Serene Grace", () => {
]); ]);
game.scene.getEnemyParty()[0].stats[Stat.SPDEF] = 10000; game.scene.getEnemyParty()[0].stats[Stat.SPDEF] = 10000;
game.scene.getEnemyParty()[0].stats[Stat.SPD] = 1;
expect(game.scene.getParty()[0].formIndex).toBe(0); expect(game.scene.getParty()[0].formIndex).toBe(0);
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => { game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
@ -89,6 +90,7 @@ describe("Abilities - Serene Grace", () => {
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
}); });
await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
// Check chance of Air Slash with Serene Grace // Check chance of Air Slash with Serene Grace

View File

@ -11,6 +11,8 @@ import { Moves } from "#enums/moves";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { changeTurnOrder } from "../utils/testUtils";
import { BattlerIndex } from "#app/battle.js";
describe("Abilities - Sheer Force", () => { describe("Abilities - Sheer Force", () => {
@ -46,7 +48,6 @@ describe("Abilities - Sheer Force", () => {
game.scene.getEnemyParty()[0].stats[Stat.SPDEF] = 10000; game.scene.getEnemyParty()[0].stats[Stat.SPDEF] = 10000;
game.scene.getEnemyParty()[0].stats[Stat.SPD] = 1;
expect(game.scene.getParty()[0].formIndex).toBe(0); expect(game.scene.getParty()[0].formIndex).toBe(0);
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => { game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
@ -57,6 +58,7 @@ describe("Abilities - Sheer Force", () => {
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
}); });
await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
const phase = game.scene.getCurrentPhase() as MoveEffectPhase; const phase = game.scene.getCurrentPhase() as MoveEffectPhase;
@ -85,7 +87,6 @@ describe("Abilities - Sheer Force", () => {
game.scene.getEnemyParty()[0].stats[Stat.DEF] = 10000; game.scene.getEnemyParty()[0].stats[Stat.DEF] = 10000;
game.scene.getEnemyParty()[0].stats[Stat.SPD] = 1;
expect(game.scene.getParty()[0].formIndex).toBe(0); expect(game.scene.getParty()[0].formIndex).toBe(0);
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => { game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
@ -96,6 +97,7 @@ describe("Abilities - Sheer Force", () => {
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
}); });
await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
const phase = game.scene.getCurrentPhase() as MoveEffectPhase; const phase = game.scene.getCurrentPhase() as MoveEffectPhase;
@ -124,7 +126,6 @@ describe("Abilities - Sheer Force", () => {
game.scene.getEnemyParty()[0].stats[Stat.DEF] = 10000; game.scene.getEnemyParty()[0].stats[Stat.DEF] = 10000;
game.scene.getEnemyParty()[0].stats[Stat.SPD] = 1;
expect(game.scene.getParty()[0].formIndex).toBe(0); expect(game.scene.getParty()[0].formIndex).toBe(0);
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => { game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
@ -135,6 +136,7 @@ describe("Abilities - Sheer Force", () => {
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
}); });
await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
const phase = game.scene.getCurrentPhase() as MoveEffectPhase; const phase = game.scene.getCurrentPhase() as MoveEffectPhase;
@ -165,7 +167,6 @@ describe("Abilities - Sheer Force", () => {
game.scene.getEnemyParty()[0].stats[Stat.DEF] = 10000; game.scene.getEnemyParty()[0].stats[Stat.DEF] = 10000;
game.scene.getEnemyParty()[0].stats[Stat.SPD] = 1;
expect(game.scene.getParty()[0].formIndex).toBe(0); expect(game.scene.getParty()[0].formIndex).toBe(0);
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => { game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
@ -176,6 +177,7 @@ describe("Abilities - Sheer Force", () => {
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
}); });
await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
const phase = game.scene.getCurrentPhase() as MoveEffectPhase; const phase = game.scene.getCurrentPhase() as MoveEffectPhase;

View File

@ -11,6 +11,8 @@ import { Moves } from "#enums/moves";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { BattlerIndex } from "#app/battle.js";
import { changeTurnOrder } from "../utils/testUtils";
describe("Abilities - Shield Dust", () => { describe("Abilities - Shield Dust", () => {
@ -46,7 +48,6 @@ describe("Abilities - Shield Dust", () => {
game.scene.getEnemyParty()[0].stats[Stat.SPDEF] = 10000; game.scene.getEnemyParty()[0].stats[Stat.SPDEF] = 10000;
game.scene.getEnemyParty()[0].stats[Stat.SPD] = 1;
expect(game.scene.getParty()[0].formIndex).toBe(0); expect(game.scene.getParty()[0].formIndex).toBe(0);
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => { game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
@ -57,6 +58,7 @@ describe("Abilities - Shield Dust", () => {
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
}); });
await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
// Shield Dust negates secondary effect // Shield Dust negates secondary effect

View File

@ -11,6 +11,8 @@ import { Moves } from "#enums/moves";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, test } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, test } from "vitest";
import { BattlerIndex } from "#app/battle.js";
import { changeTurnOrder } from "../utils/testUtils";
const TIMEOUT = 20 * 1000; const TIMEOUT = 20 * 1000;
@ -45,7 +47,6 @@ describe("Abilities - ZEN MODE", () => {
async () => { async () => {
const moveToUse = Moves.SPLASH; const moveToUse = Moves.SPLASH;
await game.startBattle([Species.DARMANITAN]); await game.startBattle([Species.DARMANITAN]);
game.scene.getParty()[0].stats[Stat.SPD] = 1;
game.scene.getParty()[0].stats[Stat.HP] = 100; game.scene.getParty()[0].stats[Stat.HP] = 100;
game.scene.getParty()[0].hp = 100; game.scene.getParty()[0].hp = 100;
expect(game.scene.getParty()[0].formIndex).toBe(0); expect(game.scene.getParty()[0].formIndex).toBe(0);
@ -57,7 +58,8 @@ describe("Abilities - ZEN MODE", () => {
const movePosition = getMovePosition(game.scene, 0, moveToUse); const movePosition = getMovePosition(game.scene, 0, moveToUse);
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
}); });
await game.phaseInterceptor.runFrom(EnemyCommandPhase).to(DamagePhase, false); await changeTurnOrder(game, [BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
await game.phaseInterceptor.to(DamagePhase, false);
// await game.phaseInterceptor.runFrom(DamagePhase).to(DamagePhase, false); // await game.phaseInterceptor.runFrom(DamagePhase).to(DamagePhase, false);
const damagePhase = game.scene.getCurrentPhase() as DamagePhase; const damagePhase = game.scene.getCurrentPhase() as DamagePhase;
damagePhase.updateAmount(40); damagePhase.updateAmount(40);
@ -73,7 +75,6 @@ describe("Abilities - ZEN MODE", () => {
async () => { async () => {
const moveToUse = Moves.SPLASH; const moveToUse = Moves.SPLASH;
await game.startBattle([Species.DARMANITAN]); await game.startBattle([Species.DARMANITAN]);
game.scene.getParty()[0].stats[Stat.SPD] = 1;
game.scene.getParty()[0].stats[Stat.HP] = 1000; game.scene.getParty()[0].stats[Stat.HP] = 1000;
game.scene.getParty()[0].hp = 100; game.scene.getParty()[0].hp = 100;
expect(game.scene.getParty()[0].formIndex).toBe(0); expect(game.scene.getParty()[0].formIndex).toBe(0);
@ -85,7 +86,8 @@ describe("Abilities - ZEN MODE", () => {
const movePosition = getMovePosition(game.scene, 0, moveToUse); const movePosition = getMovePosition(game.scene, 0, moveToUse);
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
}); });
await game.phaseInterceptor.runFrom(EnemyCommandPhase).to(QuietFormChangePhase); await changeTurnOrder(game, [BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
await game.phaseInterceptor.to(QuietFormChangePhase);
await game.phaseInterceptor.to(TurnInitPhase, false); await game.phaseInterceptor.to(TurnInitPhase, false);
expect(game.scene.getParty()[0].hp).not.toBe(100); expect(game.scene.getParty()[0].hp).not.toBe(100);
expect(game.scene.getParty()[0].formIndex).not.toBe(0); expect(game.scene.getParty()[0].formIndex).not.toBe(0);
@ -98,7 +100,6 @@ describe("Abilities - ZEN MODE", () => {
async () => { async () => {
const moveToUse = Moves.SPLASH; const moveToUse = Moves.SPLASH;
await game.startBattle([Species.DARMANITAN, Species.CHARIZARD]); await game.startBattle([Species.DARMANITAN, Species.CHARIZARD]);
game.scene.getParty()[0].stats[Stat.SPD] = 1;
game.scene.getParty()[0].stats[Stat.HP] = 1000; game.scene.getParty()[0].stats[Stat.HP] = 1000;
game.scene.getParty()[0].hp = 100; game.scene.getParty()[0].hp = 100;
expect(game.scene.getParty()[0].formIndex).toBe(0); expect(game.scene.getParty()[0].formIndex).toBe(0);
@ -110,7 +111,8 @@ describe("Abilities - ZEN MODE", () => {
const movePosition = getMovePosition(game.scene, 0, moveToUse); const movePosition = getMovePosition(game.scene, 0, moveToUse);
(game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false); (game.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, movePosition, false);
}); });
await game.phaseInterceptor.runFrom(EnemyCommandPhase).to(DamagePhase, false); await changeTurnOrder(game, [BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
await game.phaseInterceptor.to(DamagePhase, false);
// await game.phaseInterceptor.runFrom(DamagePhase).to(DamagePhase, false); // await game.phaseInterceptor.runFrom(DamagePhase).to(DamagePhase, false);
const damagePhase = game.scene.getCurrentPhase() as DamagePhase; const damagePhase = game.scene.getCurrentPhase() as DamagePhase;
damagePhase.updateAmount(80); damagePhase.updateAmount(80);

View File

@ -1,13 +1,14 @@
import { BattlerIndex } from "#app/battle"; import { BattlerIndex } from "#app/battle";
import { CritBoosterModifier } from "#app/modifier/modifier"; import { CritBoosterModifier } from "#app/modifier/modifier";
import { modifierTypes } from "#app/modifier/modifier-type"; import { modifierTypes } from "#app/modifier/modifier-type";
import { MoveEffectPhase, TurnStartPhase } from "#app/phases"; import { MoveEffectPhase } from "#app/phases";
import GameManager from "#test/utils/gameManager"; import GameManager from "#test/utils/gameManager";
import * as Utils from "#app/utils"; import * as Utils from "#app/utils";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import Phase from "phaser"; import Phase from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { changeTurnOrder } from "#test/utils/testUtils";
describe("Items - Leek", () => { describe("Items - Leek", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -43,9 +44,7 @@ describe("Items - Leek", () => {
game.doAttack(0); game.doAttack(0);
await game.phaseInterceptor.to(TurnStartPhase, false); await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
vi.spyOn(game.scene.getCurrentPhase() as TurnStartPhase, "getOrder").mockReturnValue([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
await game.phaseInterceptor.to(MoveEffectPhase); await game.phaseInterceptor.to(MoveEffectPhase);

View File

@ -1,13 +1,14 @@
import { BattlerIndex } from "#app/battle"; import { BattlerIndex } from "#app/battle";
import { CritBoosterModifier } from "#app/modifier/modifier"; import { CritBoosterModifier } from "#app/modifier/modifier";
import { modifierTypes } from "#app/modifier/modifier-type"; import { modifierTypes } from "#app/modifier/modifier-type";
import { MoveEffectPhase, TurnStartPhase } from "#app/phases"; import { MoveEffectPhase } from "#app/phases";
import GameManager from "#test/utils/gameManager"; import GameManager from "#test/utils/gameManager";
import * as Utils from "#app/utils"; import * as Utils from "#app/utils";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import Phase from "phaser"; import Phase from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { changeTurnOrder } from "#test/utils/testUtils";
describe("Items - Scope Lens", () => { describe("Items - Scope Lens", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -42,10 +43,7 @@ describe("Items - Scope Lens", () => {
]); ]);
game.doAttack(0); game.doAttack(0);
await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
await game.phaseInterceptor.to(TurnStartPhase, false);
vi.spyOn(game.scene.getCurrentPhase() as TurnStartPhase, "getOrder").mockReturnValue([ BattlerIndex.PLAYER, BattlerIndex.ENEMY ]);
await game.phaseInterceptor.to(MoveEffectPhase); await game.phaseInterceptor.to(MoveEffectPhase);

View File

@ -1,13 +1,14 @@
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import Phaser from "phaser"; import Phaser from "phaser";
import GameManager from "#test/utils/gameManager"; import GameManager from "#test/utils/gameManager";
import { MoveEffectPhase, MovePhase, MoveEndPhase, TurnStartPhase, DamagePhase } from "#app/phases"; import { MoveEffectPhase, MovePhase, MoveEndPhase, DamagePhase } from "#app/phases";
import { getMovePosition } from "#test/utils/gameManagerUtils"; import { getMovePosition } from "#test/utils/gameManagerUtils";
import { Stat } from "#app/data/pokemon-stat"; import { Stat } from "#app/data/pokemon-stat";
import { allMoves } from "#app/data/move"; import { allMoves } from "#app/data/move";
import { BattlerIndex } from "#app/battle"; import { BattlerIndex } from "#app/battle";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import { changeTurnOrder } from "#test/utils/testUtils";
describe("Moves - Fusion Flare and Fusion Bolt", () => { describe("Moves - Fusion Flare and Fusion Bolt", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -54,10 +55,8 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => {
game.doAttack(getMovePosition(game.scene, 0, fusionBolt.id)); game.doAttack(getMovePosition(game.scene, 0, fusionBolt.id));
game.doSelectTarget(BattlerIndex.ENEMY); game.doSelectTarget(BattlerIndex.ENEMY);
await game.phaseInterceptor.to(TurnStartPhase, false);
// Force user party to act before enemy party // Force user party to act before enemy party
vi.spyOn(game.scene.getCurrentPhase() as TurnStartPhase, "getOrder").mockReturnValue([ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]); await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionFlare.id); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionFlare.id);
@ -82,10 +81,8 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => {
game.doAttack(getMovePosition(game.scene, 0, fusionFlare.id)); game.doAttack(getMovePosition(game.scene, 0, fusionFlare.id));
game.doSelectTarget(BattlerIndex.ENEMY); game.doSelectTarget(BattlerIndex.ENEMY);
await game.phaseInterceptor.to(TurnStartPhase, false);
// Force user party to act before enemy party // Force user party to act before enemy party
vi.spyOn(game.scene.getCurrentPhase() as TurnStartPhase, "getOrder").mockReturnValue([ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]); await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionBolt.id); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionBolt.id);
@ -110,10 +107,8 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => {
game.doAttack(getMovePosition(game.scene, 0, fusionBolt.id)); game.doAttack(getMovePosition(game.scene, 0, fusionBolt.id));
game.doSelectTarget(0); game.doSelectTarget(0);
await game.phaseInterceptor.to(TurnStartPhase, false);
// Force first enemy to act (and fail) in between party // Force first enemy to act (and fail) in between party
vi.spyOn(game.scene.getCurrentPhase() as TurnStartPhase, "getOrder").mockReturnValue([ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]); await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionFlare.id); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionFlare.id);
@ -144,10 +139,8 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => {
game.doAttack(getMovePosition(game.scene, 0, fusionBolt.id)); game.doAttack(getMovePosition(game.scene, 0, fusionBolt.id));
game.doSelectTarget(BattlerIndex.ENEMY); game.doSelectTarget(BattlerIndex.ENEMY);
await game.phaseInterceptor.to(TurnStartPhase, false);
// Force first enemy to act in between party // Force first enemy to act in between party
vi.spyOn(game.scene.getCurrentPhase() as TurnStartPhase, "getOrder").mockReturnValue([ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]); await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionFlare.id); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionFlare.id);
@ -176,10 +169,8 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => {
game.doAttack(getMovePosition(game.scene, 0, fusionFlare.id)); game.doAttack(getMovePosition(game.scene, 0, fusionFlare.id));
game.doSelectTarget(BattlerIndex.PLAYER); game.doSelectTarget(BattlerIndex.PLAYER);
await game.phaseInterceptor.to(TurnStartPhase, false);
// Force user party to act before enemy party // Force user party to act before enemy party
vi.spyOn(game.scene.getCurrentPhase() as TurnStartPhase, "getOrder").mockReturnValue([ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]); await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2 ]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionBolt.id); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionBolt.id);
@ -230,10 +221,8 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => {
game.doAttack(getMovePosition(game.scene, 0, fusionBolt.id)); game.doAttack(getMovePosition(game.scene, 0, fusionBolt.id));
game.doSelectTarget(BattlerIndex.ENEMY); game.doSelectTarget(BattlerIndex.ENEMY);
await game.phaseInterceptor.to(TurnStartPhase, false);
// Force first enemy to act in between party // Force first enemy to act in between party
vi.spyOn(game.scene.getCurrentPhase() as TurnStartPhase, "getOrder").mockReturnValue([ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]); await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionBolt.id); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionBolt.id);
@ -294,10 +283,8 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => {
game.doAttack(getMovePosition(game.scene, 0, fusionBolt.id)); game.doAttack(getMovePosition(game.scene, 0, fusionBolt.id));
game.doSelectTarget(BattlerIndex.PLAYER); game.doSelectTarget(BattlerIndex.PLAYER);
await game.phaseInterceptor.to(TurnStartPhase, false);
// Force first enemy to act in between party // Force first enemy to act in between party
vi.spyOn(game.scene.getCurrentPhase() as TurnStartPhase, "getOrder").mockReturnValue([ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]); await changeTurnOrder(game, [ BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY ]);
await game.phaseInterceptor.to(MoveEffectPhase, false); await game.phaseInterceptor.to(MoveEffectPhase, false);
expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionBolt.id); expect((game.scene.getCurrentPhase() as MoveEffectPhase).move.moveId).toBe(fusionBolt.id);

View File

@ -1,5 +1,4 @@
import { BattlerIndex } from "#app/battle.js"; import { BattlerIndex } from "#app/battle.js";
import { Stat } from "#app/data/pokemon-stat.js";
import { Abilities } from "#app/enums/abilities.js"; import { Abilities } from "#app/enums/abilities.js";
import { Moves } from "#app/enums/moves.js"; import { Moves } from "#app/enums/moves.js";
import { Species } from "#app/enums/species.js"; import { Species } from "#app/enums/species.js";
@ -7,7 +6,7 @@ import { MoveResult } from "#app/field/pokemon.js";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import GameManager from "#test/utils/gameManager"; import GameManager from "#test/utils/gameManager";
import { getMovePosition } from "#test/utils/gameManagerUtils"; import { getMovePosition } from "#test/utils/gameManagerUtils";
import { SPLASH_ONLY } from "#test/utils/testUtils"; import { changeTurnOrder, SPLASH_ONLY } from "#test/utils/testUtils";
const TIMEOUT = 20 * 1000; const TIMEOUT = 20 * 1000;
@ -74,11 +73,9 @@ describe("Moves - Gastro Acid", () => {
await game.startBattle(); await game.startBattle();
// Force player to be slower to enable Core Enforcer to proc its suppression effect
game.scene.getPlayerPokemon().stats[Stat.SPD] = 1;
game.scene.getEnemyPokemon().stats[Stat.SPD] = 2;
game.doAttack(getMovePosition(game.scene, 0, Moves.CORE_ENFORCER)); game.doAttack(getMovePosition(game.scene, 0, Moves.CORE_ENFORCER));
// Force player to be slower to enable Core Enforcer to proc its suppression effect
await changeTurnOrder(game, [BattlerIndex.ENEMY, BattlerIndex.PLAYER]);
await game.phaseInterceptor.to("TurnInitPhase"); await game.phaseInterceptor.to("TurnInitPhase");

View File

@ -133,7 +133,7 @@ export default class GameManager {
await this.phaseInterceptor.run(EncounterPhase); await this.phaseInterceptor.run(EncounterPhase);
if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0) { if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0) {
removeEnemyHeldItems(this.scene); removeEnemyHeldItems(this);
} }
} }

View File

@ -1,7 +1,9 @@
import BattleScene from "#app/battle-scene.js";
import { Moves } from "#app/enums/moves.js"; import { Moves } from "#app/enums/moves.js";
import i18next, { type ParseKeys } from "i18next"; import i18next, { type ParseKeys } from "i18next";
import { vi } from "vitest"; import { vi } from "vitest";
import GameManager from "./gameManager";
import { BattlerIndex } from "#app/battle.js";
import { TurnStartPhase } from "#app/phases.js";
/** Ready to use array of Moves.SPLASH x4 */ /** Ready to use array of Moves.SPLASH x4 */
export const SPLASH_ONLY = [Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH]; export const SPLASH_ONLY = [Moves.SPLASH, Moves.SPLASH, Moves.SPLASH, Moves.SPLASH];
@ -29,10 +31,25 @@ export function arrayOfRange(start: integer, end: integer) {
/** /**
* Removes all held items from enemy pokemon * Removes all held items from enemy pokemon
* @param scene `game.scene` * @param game The {@link GameManager} instance
*/ */
export function removeEnemyHeldItems(scene: BattleScene) { export function removeEnemyHeldItems(game: GameManager): void {
scene.clearEnemyHeldItemModifiers(); game.scene.clearEnemyHeldItemModifiers();
scene.clearEnemyModifiers(); game.scene.clearEnemyModifiers();
console.log("Enemy held items removed"); console.log("Enemy held items removed");
} }
/**
* Used to modify the turn order. Will advance the turn to {@link TurnStartPhase}
* @param game The {@link GameManager} instance
* @param order The turn order to set
* @example
* ```ts
* await changeTurnOrder(game, [BattlerIndex.PLAYER, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2]);
* ```
*/
export async function changeTurnOrder(game: GameManager, order: BattlerIndex[]): Promise<void> {
await game.phaseInterceptor.to(TurnStartPhase, false);
vi.spyOn(game.scene.getCurrentPhase() as TurnStartPhase, "getOrder").mockReturnValue(order);
}