import type { BattleScene } from "#app/battle-scene"; import { RARE_CANDY_FRIENDSHIP_CAP } from "#app/constants"; import { globalScene } from "#app/global-scene"; import { getStarterValueFriendshipCap, speciesStarterCosts } from "#balance/starters"; import { CustomPokemonData } from "#data/pokemon-data"; import { MoveId } from "#enums/move-id"; import { PokeballType } from "#enums/pokeball"; import { PokemonType } from "#enums/pokemon-type"; import { SpeciesId } from "#enums/species-id"; import { GameManager } from "#test/test-utils/game-manager"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; describe("Spec - Pokemon", () => { let phaserGame: Phaser.Game; let game: GameManager; beforeAll(() => { phaserGame = new Phaser.Game({ type: Phaser.HEADLESS, }); }); afterEach(() => { game.phaseInterceptor.restoreOg(); }); beforeEach(() => { game = new GameManager(phaserGame); }); describe("Add To Party", () => { let scene: BattleScene; beforeEach(async () => { game.override.enemySpecies(SpeciesId.ZUBAT); await game.classicMode.runToSummon([ SpeciesId.ABRA, SpeciesId.ABRA, SpeciesId.ABRA, SpeciesId.ABRA, SpeciesId.ABRA, ]); // 5 Abra, only 1 slot left scene = game.scene; }); it("should append a new pokemon by default", async () => { const zubat = game.field.getEnemyPokemon(); zubat.addToParty(PokeballType.LUXURY_BALL); const party = scene.getPlayerParty(); expect(party).toHaveLength(6); party.forEach((pkm, index) => { expect(pkm.species.speciesId).toBe(index === 5 ? SpeciesId.ZUBAT : SpeciesId.ABRA); }); }); it("should put a new pokemon into the passed slotIndex", async () => { const slotIndex = 1; const zubat = game.field.getEnemyPokemon(); zubat.addToParty(PokeballType.LUXURY_BALL, slotIndex); const party = scene.getPlayerParty(); expect(party).toHaveLength(6); party.forEach((pkm, index) => { expect(pkm.species.speciesId).toBe(index === slotIndex ? SpeciesId.ZUBAT : SpeciesId.ABRA); }); }); }); it("should not share tms between different forms", async () => { game.override.starterForms({ [SpeciesId.ROTOM]: 4 }); await game.classicMode.startBattle([SpeciesId.ROTOM]); const fanRotom = game.field.getPlayerPokemon(); expect(fanRotom.compatibleTms).not.toContain(MoveId.BLIZZARD); expect(fanRotom.compatibleTms).toContain(MoveId.AIR_SLASH); }); describe("Get correct fusion type", () => { beforeEach(async () => { game.override.enemySpecies(SpeciesId.ZUBAT).starterSpecies(SpeciesId.ABRA).enableStarterFusion(); }); it("Fusing two mons with a single type", async () => { game.override.starterFusionSpecies(SpeciesId.CHARMANDER); await game.classicMode.startBattle(); const pokemon = game.field.getPlayerPokemon(); let types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.PSYCHIC); expect(types[1]).toBe(PokemonType.FIRE); pokemon.customPokemonData.types = [PokemonType.UNKNOWN, PokemonType.NORMAL]; types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.PSYCHIC); expect(types[1]).toBe(PokemonType.FIRE); pokemon.customPokemonData.types = [PokemonType.NORMAL, PokemonType.UNKNOWN]; types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.NORMAL); expect(types[1]).toBe(PokemonType.FIRE); if (!pokemon.fusionCustomPokemonData) { pokemon.fusionCustomPokemonData = new CustomPokemonData(); } pokemon.customPokemonData.types = []; pokemon.fusionCustomPokemonData.types = [PokemonType.UNKNOWN, PokemonType.NORMAL]; types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.PSYCHIC); expect(types[1]).toBe(PokemonType.NORMAL); pokemon.fusionCustomPokemonData.types = [PokemonType.NORMAL, PokemonType.UNKNOWN]; types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.PSYCHIC); expect(types[1]).toBe(PokemonType.NORMAL); pokemon.customPokemonData.types = [PokemonType.NORMAL, PokemonType.UNKNOWN]; pokemon.fusionCustomPokemonData.types = [PokemonType.UNKNOWN, PokemonType.NORMAL]; types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.NORMAL); expect(types[1]).toBe(PokemonType.FIRE); }); it("Fusing two mons with same single type", async () => { game.override.starterFusionSpecies(SpeciesId.DROWZEE); await game.classicMode.startBattle(); const pokemon = game.field.getPlayerPokemon(); const types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.PSYCHIC); expect(types.length).toBe(1); }); it("Fusing mons with one and two types", async () => { game.override.starterSpecies(SpeciesId.CHARMANDER).starterFusionSpecies(SpeciesId.HOUNDOUR); await game.classicMode.startBattle(); const pokemon = game.field.getPlayerPokemon(); const types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.FIRE); expect(types[1]).toBe(PokemonType.DARK); }); it("Fusing mons with two and one types", async () => { game.override.starterSpecies(SpeciesId.NUMEL).starterFusionSpecies(SpeciesId.CHARMANDER); await game.classicMode.startBattle(); const pokemon = game.field.getPlayerPokemon(); const types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.FIRE); expect(types[1]).toBe(PokemonType.GROUND); }); it("Fusing two mons with two types", async () => { game.override.starterSpecies(SpeciesId.NATU).starterFusionSpecies(SpeciesId.HOUNDOUR); await game.classicMode.startBattle(); const pokemon = game.field.getPlayerPokemon(); let types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.PSYCHIC); expect(types[1]).toBe(PokemonType.FIRE); // Natu Psychic/Grass pokemon.customPokemonData.types = [PokemonType.UNKNOWN, PokemonType.GRASS]; types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.PSYCHIC); expect(types[1]).toBe(PokemonType.FIRE); // Natu Grass/Flying pokemon.customPokemonData.types = [PokemonType.GRASS, PokemonType.UNKNOWN]; types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.GRASS); expect(types[1]).toBe(PokemonType.FIRE); if (!pokemon.fusionCustomPokemonData) { pokemon.fusionCustomPokemonData = new CustomPokemonData(); } pokemon.customPokemonData.types = []; // Houndour Dark/Grass pokemon.fusionCustomPokemonData.types = [PokemonType.UNKNOWN, PokemonType.GRASS]; types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.PSYCHIC); expect(types[1]).toBe(PokemonType.GRASS); // Houndour Grass/Fire pokemon.fusionCustomPokemonData.types = [PokemonType.GRASS, PokemonType.UNKNOWN]; types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.PSYCHIC); expect(types[1]).toBe(PokemonType.FIRE); // Natu Grass/Flying // Houndour Dark/Grass pokemon.customPokemonData.types = [PokemonType.GRASS, PokemonType.UNKNOWN]; pokemon.fusionCustomPokemonData.types = [PokemonType.UNKNOWN, PokemonType.GRASS]; types = pokemon.getTypes(); expect(types[0]).toBe(PokemonType.GRASS); expect(types[1]).toBe(PokemonType.DARK); }); }); it.each([5, 25, 55, 95, 145, 195])(// "should set minimum IVs for enemy trainer pokemon based on wave (%i)", async wave => { game.override.startingWave(wave); await game.classicMode.runToSummon([SpeciesId.FEEBAS]); for (const pokemon of game.field.getEnemyParty()) { for (const iv of pokemon.ivs) { expect(iv).toBeGreaterThanOrEqual(Math.floor(wave / 10)); } } }); it.each([ { wave: 5, friendship: 6 }, { wave: 25, friendship: 32 }, { wave: 55, friendship: 70 }, { wave: 95, friendship: 121 }, { wave: 145, friendship: 185 }, { wave: 195, friendship: 249 }, ])("should set friendship for enemy trainer pokemon based on wave ($wave)", async ({ wave, friendship }) => { game.override.startingWave(wave); await game.classicMode.runToSummon([SpeciesId.FEEBAS]); for (const pokemon of game.field.getEnemyParty()) { expect(pokemon.friendship).toBe(friendship); } }); describe("Friendship", () => { it("should cap friendship at 255", async () => { await game.classicMode.runToSummon([SpeciesId.FEEBAS]); const feebas = game.field.getPlayerPokemon(); feebas.addFriendship(999); expect(feebas.friendship).toBe(255); }); it("should not go below 0 friendship", async () => { await game.classicMode.runToSummon([SpeciesId.FEEBAS]); const feebas = game.field.getPlayerPokemon(); feebas.addFriendship(-999); expect(feebas.friendship).toBe(0); }); it("should respect Rare Candy friendship gain cap", async () => { await game.classicMode.runToSummon([SpeciesId.FEEBAS]); const feebas = game.field.getPlayerPokemon(); feebas.addFriendship(999, true); expect(feebas.friendship).toBe(RARE_CANDY_FRIENDSHIP_CAP); }); it("should get 3x candy friendship in classic mode", async () => { await game.classicMode.runToSummon([SpeciesId.FEEBAS]); const feebas = game.field.getPlayerPokemon(); const pokemonData = globalScene.gameData.starterData[SpeciesId.FEEBAS]; feebas.friendship = 0; pokemonData.friendship = 0; feebas.addFriendship(10); expect(feebas.friendship).toBe(10); expect(pokemonData.friendship).toBe(30); }); it("should carry over excess friendship into next candy, even if capped", async () => { await game.classicMode.runToSummon([SpeciesId.FEEBAS]); const feebas = game.field.getPlayerPokemon(); const pokemonData = globalScene.gameData.starterData[SpeciesId.FEEBAS]; feebas.friendship = 0; pokemonData.friendship = 15; pokemonData.candyCount = 0; const cap = getStarterValueFriendshipCap(speciesStarterCosts[SpeciesId.FEEBAS]); expect(cap).toBeLessThan(2015); feebas.addFriendship(2000, true); // Friendship gain was capped, but candy friendship overflowed several times over expect(feebas.friendship).toBe(RARE_CANDY_FRIENDSHIP_CAP); expect(pokemonData.friendship).toBe(6015 % cap); expect(pokemonData.candyCount).toBe(Math.floor(6015 / cap)); }); }); it("should allow gaining candy for uncaught Pokémon", async () => { await game.classicMode.runToSummon([SpeciesId.FEEBAS]); const feebas = game.field.getPlayerPokemon(); const pokemonData = globalScene.gameData.starterData[SpeciesId.FEEBAS]; feebas.friendship = 0; pokemonData.candyCount = 0; // mark feebas as uncaught const dexEntry = globalScene.gameData.dexData[SpeciesId.FEEBAS]; dexEntry.caughtAttr = 0n; feebas.addFriendship(2000); expect(dexEntry.caughtAttr).toBe(0n); expect(pokemonData.candyCount).toBeGreaterThan(0); }); });