pokerogue/test/field/pokemon-id-checks.test.ts
Bertie690 36c79a9a69
[Bug] Reworked BattlerTag/ArenaTag code to prevent breakage on 0 PIDs
https://github.com/pagefaultgames/pokerogue/pull/5932

* Fixed modifier code, removed instances of "0 ID = no mon"

* corrected casing + dejanked seed tag

* Added test file, added overload to `findModifier` if given type predicate

* fixed test

* Revert predicate stuff for now

going in separate PR

* Fix id check syrup bomb test

Wasn't running phase due to being a turn end effect

* [WIP] Changed test to use destiny bond as proper regression

* Removed `instant` and `ignoreUpdate` parameters from `tryTransferHeldItemModifier`; fixed post-battle loot code to _not_ break type safety

* Fixed up tests

* Reverted unneeded changes

* Removed outdated modifier test

* Fix import

* Apply Biome

* Update battler-tags.ts

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

* Update battler-tags.ts

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

* Update arena-tag.ts

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

* Update arena-tag.ts

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

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
2025-06-22 17:29:37 -07:00

80 lines
2.7 KiB
TypeScript

import type Pokemon from "#app/field/pokemon";
import { MoveId } from "#enums/move-id";
import { AbilityId } from "#enums/ability-id";
import { SpeciesId } from "#enums/species-id";
import { BattleType } from "#enums/battle-type";
import { BattlerTagType } from "#enums/battler-tag-type";
import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { BattlerIndex } from "#enums/battler-index";
describe("Field - Pokemon ID Checks", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.ability(AbilityId.NO_GUARD)
.battleStyle("single")
.battleType(BattleType.TRAINER)
.criticalHits(false)
.enemyLevel(100)
.enemySpecies(SpeciesId.ARCANINE)
.enemyAbility(AbilityId.BALL_FETCH)
.enemyMoveset(MoveId.SPLASH);
});
function onlyUnique<T>(array: T[]): T[] {
return [...new Set<T>(array)];
}
// TODO: We currently generate IDs as a pure random integer; enable once unique UUIDs are added
it.todo("2 Pokemon should not be able to generate with the same ID during 1 encounter", async () => {
game.override.battleType(BattleType.TRAINER); // enemy generates 2 mons
await game.classicMode.startBattle([SpeciesId.FEEBAS, SpeciesId.ABRA]);
const ids = (game.scene.getPlayerParty() as Pokemon[]).concat(game.scene.getEnemyParty()).map((p: Pokemon) => p.id);
const uniqueIds = onlyUnique(ids);
expect(ids).toHaveLength(uniqueIds.length);
});
it("should not prevent Battler Tags from triggering if user has PID of 0", async () => {
await game.classicMode.startBattle([SpeciesId.TREECKO, SpeciesId.AERODACTYL]);
const player = game.field.getPlayerPokemon();
const enemy = game.field.getEnemyPokemon();
// Override player pokemon PID to be 0
player.id = 0;
expect(player.getTag(BattlerTagType.DESTINY_BOND)).toBeUndefined();
game.move.use(MoveId.DESTINY_BOND);
game.doSelectPartyPokemon(1);
await game.move.forceEnemyMove(MoveId.FLAME_WHEEL);
await game.setTurnOrder([BattlerIndex.PLAYER, BattlerIndex.ENEMY]);
await game.phaseInterceptor.to("MoveEndPhase");
const dBondTag = player.getTag(BattlerTagType.DESTINY_BOND)!;
expect(dBondTag).toBeDefined();
expect(dBondTag.sourceId).toBe(0);
expect(dBondTag.getSourcePokemon()).toBe(player);
await game.phaseInterceptor.to("MoveEndPhase");
expect(player.isFainted()).toBe(true);
expect(enemy.isFainted()).toBe(true);
});
});