From 4715de956556bd6421e58fe6a85bec0afc112d6d Mon Sep 17 00:00:00 2001 From: Moka Date: Thu, 14 Nov 2024 20:52:37 +0100 Subject: [PATCH] Make 'getSpeciesFilterRandomPartyMemberFunc' more readable --- src/data/trainer-config.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/data/trainer-config.ts b/src/data/trainer-config.ts index 8364214d088..acc6957a026 100644 --- a/src/data/trainer-config.ts +++ b/src/data/trainer-config.ts @@ -1177,12 +1177,24 @@ export function getRandomPartyMemberFunc(speciesPool: Species[], trainerSlot: Tr }; } -function getSpeciesFilterRandomPartyMemberFunc(speciesFilter: PokemonSpeciesFilter, trainerSlot: TrainerSlot = TrainerSlot.TRAINER, allowLegendaries?: boolean, postProcess?: (EnemyPokemon: EnemyPokemon) => void): PartyMemberFunc { - const originalSpeciesFilter = speciesFilter; - speciesFilter = (species: PokemonSpecies) => (allowLegendaries || (!species.legendary && !species.subLegendary && !species.mythical)) && !species.isTrainerForbidden() && originalSpeciesFilter(species); - return (scene: BattleScene, level: integer, strength: PartyMemberStrength) => { - const ret = scene.addEnemyPokemon(getPokemonSpecies(scene.randomSpecies(scene.currentBattle.waveIndex, level, false, speciesFilter).getTrainerSpeciesForLevel(level, true, strength, scene.currentBattle.waveIndex)), level, trainerSlot, undefined, false, undefined, postProcess); - return ret; +function getSpeciesFilterRandomPartyMemberFunc( + originalSpeciesFilter: PokemonSpeciesFilter, + trainerSlot: TrainerSlot = TrainerSlot.TRAINER, + allowLegendaries?: boolean, + postProcess?: (EnemyPokemon: EnemyPokemon) => void +): PartyMemberFunc { + + const speciesFilter = (species: PokemonSpecies): boolean => { + const notLegendary = !species.legendary && !species.subLegendary && !species.mythical; + return (allowLegendaries || notLegendary) && !species.isTrainerForbidden() && originalSpeciesFilter(species); + }; + + return (scene: BattleScene, level: number, strength: PartyMemberStrength) => { + const waveIndex = scene.currentBattle.waveIndex; + const species = getPokemonSpecies(scene.randomSpecies(waveIndex, level, false, speciesFilter) + .getTrainerSpeciesForLevel(level, true, strength, waveIndex)); + + return scene.addEnemyPokemon(species, level, trainerSlot, undefined, false, undefined, postProcess); }; }