Make 'getSpeciesFilterRandomPartyMemberFunc' more readable

This commit is contained in:
Moka 2024-11-14 20:52:37 +01:00
parent 026f934d5a
commit 4715de9565
1 changed files with 18 additions and 6 deletions

View File

@ -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);
};
}