mirror of
				https://github.com/pagefaultgames/pokerogue.git
				synced 2025-10-25 06:25:52 +02:00 
			
		
		
		
	* Move game-mode to its own file Reduces circular imports to 325 * Move battler-index to own file Reduces circular deps to 314 * Move trainer-variant to own file Reduces circ deps to 313 * Move enums in pokemon to their own file * Move arena-tag-type to its own file * Move pokemon-moves to its own file * Move command to own file * Move learnMoveType to own file * Move form change item to own file * Move battlerTagLapseType to own file * Move anim enums to own shared file * Move enums out of challenges * Move species form change triggers to own file Reduces circ imports to 291 * Update test importing pokemon move * Replace move attribute imports with string names * Untangle circular deps from game data * Fix missing string call in switch summon phase * Apply kev's suggestions from code review Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * Ensure ChargeMove's is method calls super * Use InstanceType for proper narrowing * Apply kev's suggestions from code review Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
		
			
				
	
	
		
			103 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			103 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import type BattleScene from "#app/battle-scene";
 | |
| import { allMoves } from "#app/data/data-lists";
 | |
| import { MoveCategory } from "#enums/MoveCategory";
 | |
| import { AbilityId } from "#enums/ability-id";
 | |
| import { MoveId } from "#enums/move-id";
 | |
| import { SpeciesId } from "#enums/species-id";
 | |
| import type { EnemyPokemon } from "#app/field/pokemon";
 | |
| import { AiType } from "#enums/ai-type";
 | |
| import { randSeedInt } from "#app/utils/common";
 | |
| import GameManager from "#test/testUtils/gameManager";
 | |
| import Phaser from "phaser";
 | |
| import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
 | |
| 
 | |
| let globalScene: BattleScene;
 | |
| const NUM_TRIALS = 300;
 | |
| 
 | |
| type MoveChoiceSet = { [key: number]: number };
 | |
| 
 | |
| function getEnemyMoveChoices(pokemon: EnemyPokemon, moveChoices: MoveChoiceSet): void {
 | |
|   // Use an unseeded random number generator in place of the mocked-out randBattleSeedInt
 | |
|   vi.spyOn(globalScene, "randBattleSeedInt").mockImplementation((range, min?) => {
 | |
|     return randSeedInt(range, min);
 | |
|   });
 | |
|   for (let i = 0; i < NUM_TRIALS; i++) {
 | |
|     const queuedMove = pokemon.getNextMove();
 | |
|     moveChoices[queuedMove.move]++;
 | |
|   }
 | |
| 
 | |
|   for (const [moveId, count] of Object.entries(moveChoices)) {
 | |
|     console.log(`Move: ${allMoves[moveId].name}   Count: ${count} (${(count / NUM_TRIALS) * 100}%)`);
 | |
|   }
 | |
| }
 | |
| 
 | |
| describe("Enemy Commands - Move Selection", () => {
 | |
|   let phaserGame: Phaser.Game;
 | |
|   let game: GameManager;
 | |
| 
 | |
|   beforeAll(() => {
 | |
|     phaserGame = new Phaser.Game({
 | |
|       type: Phaser.HEADLESS,
 | |
|     });
 | |
|   });
 | |
| 
 | |
|   afterEach(() => {
 | |
|     game.phaseInterceptor.restoreOg();
 | |
|   });
 | |
| 
 | |
|   beforeEach(() => {
 | |
|     game = new GameManager(phaserGame);
 | |
|     globalScene = game.scene;
 | |
| 
 | |
|     game.override.ability(AbilityId.BALL_FETCH).enemyAbility(AbilityId.BALL_FETCH);
 | |
|   });
 | |
| 
 | |
|   it("should never use Status moves if an attack can KO", async () => {
 | |
|     game.override
 | |
|       .enemySpecies(SpeciesId.ETERNATUS)
 | |
|       .enemyMoveset([MoveId.ETERNABEAM, MoveId.SLUDGE_BOMB, MoveId.DRAGON_DANCE, MoveId.COSMIC_POWER])
 | |
|       .startingLevel(1)
 | |
|       .enemyLevel(100);
 | |
| 
 | |
|     await game.classicMode.startBattle([SpeciesId.MAGIKARP]);
 | |
| 
 | |
|     const enemyPokemon = game.scene.getEnemyPokemon()!;
 | |
|     enemyPokemon.aiType = AiType.SMART_RANDOM;
 | |
| 
 | |
|     const moveChoices: MoveChoiceSet = {};
 | |
|     const enemyMoveset = enemyPokemon.getMoveset();
 | |
|     enemyMoveset.forEach(mv => (moveChoices[mv!.moveId] = 0));
 | |
|     getEnemyMoveChoices(enemyPokemon, moveChoices);
 | |
| 
 | |
|     enemyMoveset.forEach(mv => {
 | |
|       if (mv?.getMove().category === MoveCategory.STATUS) {
 | |
|         expect(moveChoices[mv.moveId]).toBe(0);
 | |
|       }
 | |
|     });
 | |
|   });
 | |
| 
 | |
|   it("should not select Last Resort if it would fail, even if the move KOs otherwise", async () => {
 | |
|     game.override
 | |
|       .enemySpecies(SpeciesId.KANGASKHAN)
 | |
|       .enemyMoveset([MoveId.LAST_RESORT, MoveId.GIGA_IMPACT, MoveId.SPLASH, MoveId.SWORDS_DANCE])
 | |
|       .startingLevel(1)
 | |
|       .enemyLevel(100);
 | |
| 
 | |
|     await game.classicMode.startBattle([SpeciesId.MAGIKARP]);
 | |
| 
 | |
|     const enemyPokemon = game.scene.getEnemyPokemon()!;
 | |
|     enemyPokemon.aiType = AiType.SMART_RANDOM;
 | |
| 
 | |
|     const moveChoices: MoveChoiceSet = {};
 | |
|     const enemyMoveset = enemyPokemon.getMoveset();
 | |
|     enemyMoveset.forEach(mv => (moveChoices[mv!.moveId] = 0));
 | |
|     getEnemyMoveChoices(enemyPokemon, moveChoices);
 | |
| 
 | |
|     enemyMoveset.forEach(mv => {
 | |
|       if (mv?.getMove().category === MoveCategory.STATUS || mv?.moveId === MoveId.LAST_RESORT) {
 | |
|         expect(moveChoices[mv.moveId]).toBe(0);
 | |
|       }
 | |
|     });
 | |
|   });
 | |
| });
 |