pokerogue/test/moves/fusion-flare-bolt.test.ts
Sirz Benjie e5e0835a96
[Misc][Refactor] Add scaffolding for TypedArrays and improve typing on methods related to arrays (#6547)
* make IVs use Uint8Array

* Add many typed array helpers

* Move array utils to its own file

* Add suppression comment

* Adjust type of `getStats`

* Adjust test mocks to use typed arrays

* Adjust signatures of some phases to use ArrayLike<T>

* Adjust signature of src/ui/containers/stats-container#updateIvs

* Remove comment gap to try to satisfy typedoc

* Ensure ivs are always set

* fix: fun-and-games me to use typed array

* Add new tests for array utilities

* Update type of ivs in save-data.ts

* Update part-timer-encounter.test.ts

* Convert uses of StatusEffect[] to Uint8Array

* Update ssui to use uint8array for ivs

* Revert use of typed arrays

* Move `nil` to @types/common

* Make more arrays readonly

* fix: remnant change to immune effects

* Even more array improvements

* Apply kev's suggestions from code review

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* address Bertie's comments from code review

* tests: remove undefined check for bigint array types

* fixup abilities.ts

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
2025-10-06 12:21:58 -05:00

264 lines
12 KiB
TypeScript

import { allMoves } from "#data/data-lists";
import { BattlerIndex } from "#enums/battler-index";
import { MoveId } from "#enums/move-id";
import { SpeciesId } from "#enums/species-id";
import { Stat } from "#enums/stat";
import type { Move } from "#moves/move";
import type { MoveEffectPhase } from "#phases/move-effect-phase";
import { GameManager } from "#test/test-utils/game-manager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
describe("Moves - Fusion Flare and Fusion Bolt", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
let fusionFlare: Move;
let fusionBolt: Move;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
fusionFlare = allMoves[MoveId.FUSION_FLARE];
fusionBolt = allMoves[MoveId.FUSION_BOLT];
game = new GameManager(phaserGame);
game.override
.moveset([fusionFlare.id, fusionBolt.id])
.startingLevel(1)
.enemySpecies(SpeciesId.RESHIRAM)
.enemyMoveset(MoveId.REST)
.battleStyle("double")
.startingWave(97)
.criticalHits(false);
vi.spyOn(fusionFlare, "calculateBattlePower");
vi.spyOn(fusionBolt, "calculateBattlePower");
});
it("FUSION_FLARE should double power of subsequent FUSION_BOLT", async () => {
await game.classicMode.startBattle([SpeciesId.ZEKROM, SpeciesId.ZEKROM]);
game.move.select(fusionFlare.id, 0, BattlerIndex.ENEMY);
game.move.select(fusionBolt.id, 1, BattlerIndex.ENEMY);
// Force user party to act before enemy party
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2]);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionFlare.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionFlare.calculateBattlePower).toHaveLastReturnedWith(100);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionBolt.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionBolt.calculateBattlePower).toHaveLastReturnedWith(200);
});
it("FUSION_BOLT should double power of subsequent FUSION_FLARE", async () => {
await game.classicMode.startBattle([SpeciesId.ZEKROM, SpeciesId.ZEKROM]);
game.move.select(fusionBolt.id, 0, BattlerIndex.ENEMY);
game.move.select(fusionFlare.id, 1, BattlerIndex.ENEMY);
// Force user party to act before enemy party
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2]);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionBolt.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionBolt.calculateBattlePower).toHaveLastReturnedWith(100);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionFlare.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionFlare.calculateBattlePower).toHaveLastReturnedWith(200);
});
it("FUSION_FLARE should double power of subsequent FUSION_BOLT if a move failed in between", async () => {
await game.classicMode.startBattle([SpeciesId.ZEKROM, SpeciesId.ZEKROM]);
game.move.select(fusionFlare.id, 0, BattlerIndex.PLAYER);
game.move.select(fusionBolt.id, 1, BattlerIndex.PLAYER);
// Force first enemy to act (and fail) in between party
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionFlare.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionFlare.calculateBattlePower).toHaveLastReturnedWith(100);
await game.phaseInterceptor.to("MoveEndPhase");
// Skip enemy move; because the enemy is at full HP, Rest should fail
await game.phaseInterceptor.to("MoveEndPhase");
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionBolt.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionBolt.calculateBattlePower).toHaveLastReturnedWith(200);
});
it("FUSION_FLARE should not double power of subsequent FUSION_BOLT if a move succeeded in between", async () => {
game.override.enemyMoveset(MoveId.SPLASH);
await game.classicMode.startBattle([SpeciesId.ZEKROM, SpeciesId.ZEKROM]);
game.move.select(fusionFlare.id, 0, BattlerIndex.ENEMY);
game.move.select(fusionBolt.id, 1, BattlerIndex.ENEMY);
// Force first enemy to act in between party
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionFlare.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionFlare.calculateBattlePower).toHaveLastReturnedWith(100);
await game.phaseInterceptor.to("MoveEndPhase");
// Skip enemy move
await game.phaseInterceptor.to("MoveEndPhase");
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionBolt.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionBolt.calculateBattlePower).toHaveLastReturnedWith(100);
});
it("FUSION_FLARE should double power of subsequent FUSION_BOLT if moves are aimed at allies", async () => {
await game.classicMode.startBattle([SpeciesId.ZEKROM, SpeciesId.RESHIRAM]);
game.move.select(fusionBolt.id, 0, BattlerIndex.PLAYER_2);
game.move.select(fusionFlare.id, 1, BattlerIndex.PLAYER);
// Force user party to act before enemy party
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY, BattlerIndex.ENEMY_2]);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionBolt.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionBolt.calculateBattlePower).toHaveLastReturnedWith(100);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionFlare.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionFlare.calculateBattlePower).toHaveLastReturnedWith(200);
});
it("FUSION_FLARE and FUSION_BOLT alternating throughout turn should double power of subsequent moves", async () => {
game.override.enemyMoveset(fusionFlare.id);
await game.classicMode.startBattle([SpeciesId.ZEKROM, SpeciesId.ZEKROM]);
const party = game.scene.getPlayerParty();
const enemyParty = game.scene.getEnemyParty();
// Get rid of any modifiers that may alter power
game.scene.clearEnemyHeldItemModifiers();
game.scene.clearEnemyModifiers();
// Mock stats by replacing entries in copy with desired values for specific stats
const stats = {
enemy: [enemyParty[0].stats.slice(), enemyParty[1].stats.slice()],
player: [party[0].stats.slice(), party[1].stats.slice()],
};
// Ensure survival by reducing enemy Sp. Atk and boosting party Sp. Def
vi.spyOn(enemyParty[0], "stats", "get").mockReturnValue(
stats.enemy[0].map((val, i) => (i === Stat.SPATK ? 1 : val)),
);
vi.spyOn(enemyParty[1], "stats", "get").mockReturnValue(
stats.enemy[1].map((val, i) => (i === Stat.SPATK ? 1 : val)),
);
vi.spyOn(party[1], "stats", "get").mockReturnValue(stats.player[0].map((val, i) => (i === Stat.SPDEF ? 250 : val)));
vi.spyOn(party[1], "stats", "get").mockReturnValue(stats.player[1].map((val, i) => (i === Stat.SPDEF ? 250 : val)));
game.move.select(fusionBolt.id, 0, BattlerIndex.ENEMY);
game.move.select(fusionBolt.id, 1, BattlerIndex.ENEMY);
// Force first enemy to act in between party
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionBolt.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionBolt.calculateBattlePower).toHaveLastReturnedWith(100);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionFlare.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionFlare.calculateBattlePower).toHaveLastReturnedWith(200);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionBolt.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionBolt.calculateBattlePower).toHaveLastReturnedWith(200);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionFlare.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionFlare.calculateBattlePower).toHaveLastReturnedWith(200);
});
it("FUSION_FLARE and FUSION_BOLT alternating throughout turn should double power of subsequent moves if moves are aimed at allies", async () => {
game.override.enemyMoveset(fusionFlare.id);
await game.classicMode.startBattle([SpeciesId.ZEKROM, SpeciesId.ZEKROM]);
const party = game.scene.getPlayerParty();
const enemyParty = game.scene.getEnemyParty();
// Get rid of any modifiers that may alter power
game.scene.clearEnemyHeldItemModifiers();
game.scene.clearEnemyModifiers();
// Mock stats by replacing entries in copy with desired values for specific stats
const stats = {
enemy: [enemyParty[0].stats.slice(), enemyParty[1].stats.slice()],
player: [party[0].stats.slice(), party[1].stats.slice()],
};
// Ensure survival by reducing enemy Sp. Atk and boosting party Sp. Def
vi.spyOn(enemyParty[0], "stats", "get").mockReturnValue(
stats.enemy[0].map((val, i) => (i === Stat.SPATK ? 1 : val)),
);
vi.spyOn(enemyParty[1], "stats", "get").mockReturnValue(
stats.enemy[1].map((val, i) => (i === Stat.SPATK ? 1 : val)),
);
vi.spyOn(party[1], "stats", "get").mockReturnValue(stats.player[0].map((val, i) => (i === Stat.SPDEF ? 250 : val)));
vi.spyOn(party[1], "stats", "get").mockReturnValue(stats.player[1].map((val, i) => (i === Stat.SPDEF ? 250 : val)));
game.move.select(fusionBolt.id, 0, BattlerIndex.PLAYER_2);
game.move.select(fusionBolt.id, 1, BattlerIndex.PLAYER);
// Force first enemy to act in between party
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY_2, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionBolt.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionBolt.calculateBattlePower).toHaveLastReturnedWith(100);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionFlare.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionFlare.calculateBattlePower).toHaveLastReturnedWith(200);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionBolt.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionBolt.calculateBattlePower).toHaveLastReturnedWith(200);
await game.phaseInterceptor.to("MoveEffectPhase", false);
expect((game.scene.phaseManager.getCurrentPhase() as MoveEffectPhase).move.id).toBe(fusionFlare.id);
await game.phaseInterceptor.to("DamageAnimPhase", false);
expect(fusionFlare.calculateBattlePower).toHaveLastReturnedWith(200);
});
});