diff --git a/data/mods/gen1/random-teams.ts b/data/mods/gen1/random-teams.ts index d5bf256638b1..8a7216c72885 100644 --- a/data/mods/gen1/random-teams.ts +++ b/data/mods/gen1/random-teams.ts @@ -124,7 +124,7 @@ export class RandomGen1Teams extends RandomGen2Teams { const weaknessCount: {[k: string]: number} = {Electric: 0, Psychic: 0, Water: 0, Ice: 0, Ground: 0, Fire: 0}; let numMaxLevelPokemon = 0; - const pokemonPool = this.getPokemonPool(type, pokemon, isMonotype, Object.keys(this.randomData))[0]; + const pokemonPool = Object.keys(this.getPokemonPool(type, pokemon, isMonotype, Object.keys(this.randomData))[0]); while (pokemonPool.length && pokemon.length < this.maxTeamSize) { const species = this.dex.species.get(this.sampleNoReplace(pokemonPool)); if (!species.exists) continue; diff --git a/data/mods/gen3/random-teams.ts b/data/mods/gen3/random-teams.ts index e57b62f6a48d..507cacbae3fb 100644 --- a/data/mods/gen3/random-teams.ts +++ b/data/mods/gen3/random-teams.ts @@ -687,12 +687,7 @@ export class RandomGen3Teams extends RandomGen4Teams { const [pokemonPool, baseSpeciesPool] = this.getPokemonPool(type, pokemon, isMonotype, pokemonList); while (baseSpeciesPool.length && pokemon.length < this.maxTeamSize) { const baseSpecies = this.sampleNoReplace(baseSpeciesPool); - const currentSpeciesPool: Species[] = []; - for (const poke of pokemonPool) { - const species = this.dex.species.get(poke); - if (species.baseSpecies === baseSpecies) currentSpeciesPool.push(species); - } - const species = this.sample(currentSpeciesPool); + const species = this.dex.species.get(this.sample(pokemonPool[baseSpecies])); if (!species.exists) continue; // Limit to one of each species (Species Clause) diff --git a/data/mods/gen5/random-teams.ts b/data/mods/gen5/random-teams.ts index 31a9fe77f032..7e9ed7263904 100644 --- a/data/mods/gen5/random-teams.ts +++ b/data/mods/gen5/random-teams.ts @@ -955,12 +955,7 @@ export class RandomGen5Teams extends RandomGen6Teams { const [pokemonPool, baseSpeciesPool] = this.getPokemonPool(type, pokemon, isMonotype, pokemonList); while (baseSpeciesPool.length && pokemon.length < this.maxTeamSize) { const baseSpecies = this.sampleNoReplace(baseSpeciesPool); - const currentSpeciesPool: Species[] = []; - for (const poke of pokemonPool) { - const species = this.dex.species.get(poke); - if (species.baseSpecies === baseSpecies) currentSpeciesPool.push(species); - } - const species = this.sample(currentSpeciesPool); + const species = this.dex.species.get(this.sample(pokemonPool[baseSpecies])); if (!species.exists) continue; // Limit to one of each species (Species Clause) diff --git a/data/mods/gen7/random-doubles-teams.ts b/data/mods/gen7/random-doubles-teams.ts index 8a6e351f10f5..55e0dc18ef01 100644 --- a/data/mods/gen7/random-doubles-teams.ts +++ b/data/mods/gen7/random-doubles-teams.ts @@ -1373,19 +1373,17 @@ export class RandomGen7DoublesTeams extends RandomGen8Teams { const currentSpeciesPool: Species[] = []; // Check if the base species has a mega forme available let canMega = false; - for (const poke of pokemonPool) { + for (const poke of pokemonPool[baseSpecies]) { const species = this.dex.species.get(poke); - if (!hasMega && species.baseSpecies === baseSpecies && species.isMega) canMega = true; + if (!hasMega && species.isMega) canMega = true; } - for (const poke of pokemonPool) { + for (const poke of pokemonPool[baseSpecies]) { const species = this.dex.species.get(poke); - if (species.baseSpecies === baseSpecies) { - // Prevent multiple megas - if (hasMega && species.isMega) continue; - // Prevent base forme, if a mega is available - if (canMega && !species.isMega) continue; - currentSpeciesPool.push(species); - } + // Prevent multiple megas + if (hasMega && species.isMega) continue; + // Prevent base forme, if a mega is available + if (canMega && !species.isMega) continue; + currentSpeciesPool.push(species); } const species = this.sample(currentSpeciesPool); if (!species.exists) continue; diff --git a/data/mods/gen7/random-teams.ts b/data/mods/gen7/random-teams.ts index 83ec29392b6a..19c8143ece0b 100644 --- a/data/mods/gen7/random-teams.ts +++ b/data/mods/gen7/random-teams.ts @@ -1329,19 +1329,17 @@ export class RandomGen7Teams extends RandomGen8Teams { const currentSpeciesPool: Species[] = []; // Check if the base species has a mega forme available let canMega = false; - for (const poke of pokemonPool) { + for (const poke of pokemonPool[baseSpecies]) { const species = this.dex.species.get(poke); - if (!hasMega && species.baseSpecies === baseSpecies && species.isMega) canMega = true; + if (!hasMega && species.isMega) canMega = true; } - for (const poke of pokemonPool) { + for (const poke of pokemonPool[baseSpecies]) { const species = this.dex.species.get(poke); - if (species.baseSpecies === baseSpecies) { - // Prevent multiple megas - if (hasMega && species.isMega) continue; - // Prevent base forme, if a mega is available - if (canMega && !species.isMega) continue; - currentSpeciesPool.push(species); - } + // Prevent multiple megas + if (hasMega && species.isMega) continue; + // Prevent base forme, if a mega is available + if (canMega && !species.isMega) continue; + currentSpeciesPool.push(species); } const species = this.sample(currentSpeciesPool); diff --git a/data/mods/gen8/random-teams.ts b/data/mods/gen8/random-teams.ts index 529d02fb2ceb..6af307598d9d 100644 --- a/data/mods/gen8/random-teams.ts +++ b/data/mods/gen8/random-teams.ts @@ -2413,11 +2413,10 @@ export class RandomGen8Teams { pokemonToExclude: RandomTeamsTypes.RandomSet[] = [], isMonotype = false, pokemonList: string[] - ) { + ): [{[k: string]: ID[]}, string[]] { const exclude = pokemonToExclude.map(p => toID(p.species)); - const pokemonPool = []; + const pokemonPool: {[k: string]: ID[]} = {}; const baseSpeciesPool = []; - const baseSpeciesCount: {[k: string]: number} = {}; for (const pokemon of pokemonList) { let species = this.dex.species.get(pokemon); if (exclude.includes(species.id)) continue; @@ -2428,14 +2427,18 @@ export class RandomGen8Teams { if (!species.types.includes(type)) continue; } } - pokemonPool.push(pokemon); - baseSpeciesCount[species.baseSpecies] = (baseSpeciesCount[species.baseSpecies] || 0) + 1; + + if (species.baseSpecies in pokemonPool) { + pokemonPool[species.baseSpecies].push(species.id); + } else { + pokemonPool[species.baseSpecies] = [species.id]; + } } // Include base species 1x if 1-3 formes, 2x if 4-6 formes, 3x if 7+ formes - for (const baseSpecies of Object.keys(baseSpeciesCount)) { - for (let i = 0; i < Math.min(Math.ceil(baseSpeciesCount[baseSpecies] / 3), 3); i++) { - baseSpeciesPool.push(baseSpecies); - } + for (const baseSpecies of Object.keys(pokemonPool)) { + // Squawkabilly has 4 formes, but only 2 functionally different formes, so only include it 1x + const weight = (baseSpecies === 'Squawkabilly') ? 1 : Math.min(Math.ceil(pokemonPool[baseSpecies].length / 3), 3); + for (let i = 0; i < weight; i++) baseSpeciesPool.push(baseSpecies); } return [pokemonPool, baseSpeciesPool]; } @@ -2474,12 +2477,7 @@ export class RandomGen8Teams { const [pokemonPool, baseSpeciesPool] = this.getPokemonPool(type, pokemon, isMonotype, pokemonList); while (baseSpeciesPool.length && pokemon.length < this.maxTeamSize) { const baseSpecies = this.sampleNoReplace(baseSpeciesPool); - const currentSpeciesPool: Species[] = []; - for (const poke of pokemonPool) { - const species = this.dex.species.get(poke); - if (species.baseSpecies === baseSpecies) currentSpeciesPool.push(species); - } - let species = this.sample(currentSpeciesPool); + let species = this.dex.species.get(this.sample(pokemonPool[baseSpecies])); if (!species.exists) continue; // Limit to one of each species (Species Clause) diff --git a/data/mods/potd/random-teams.ts b/data/mods/potd/random-teams.ts index 727ba926a3ec..bca2df23e2f9 100644 --- a/data/mods/potd/random-teams.ts +++ b/data/mods/potd/random-teams.ts @@ -33,12 +33,9 @@ export class RandomPOTDTeams extends RandomTeams { const teamDetails: RandomTeamsTypes.TeamDetails = {}; const pokemonList = isDoubles ? Object.keys(this.randomDoublesSets) : Object.keys(this.randomSets); - const [pokemonPool, baseSpeciesPool] = this.getPokemonPool(type, pokemon, isMonotype, pokemonList); - - // Remove PotD from baseSpeciesPool - if (baseSpeciesPool.includes(potd.baseSpecies)) { - this.fastPop(baseSpeciesPool, baseSpeciesPool.indexOf(potd.baseSpecies)); - } + const [pokemonPool, baseSpeciesPool] = this.getPokemonPool( + type, pokemon, isMonotype, pokemonList.filter(m => this.dex.species.get(m).baseSpecies !== potd.baseSpecies) + ); // Add PotD to type counts for (const typeName of potd.types) { @@ -56,12 +53,7 @@ export class RandomPOTDTeams extends RandomTeams { while (baseSpeciesPool.length && pokemon.length < this.maxTeamSize) { const baseSpecies = this.sampleNoReplace(baseSpeciesPool); - const currentSpeciesPool: Species[] = []; - for (const poke of pokemonPool) { - const species = this.dex.species.get(poke); - if (species.baseSpecies === baseSpecies) currentSpeciesPool.push(species); - } - let species = this.sample(currentSpeciesPool); + let species = this.dex.species.get(this.sample(pokemonPool[baseSpecies])); if (!species.exists) continue; // Limit to one of each species (Species Clause) diff --git a/data/random-teams.ts b/data/random-teams.ts index 857f13fe77c8..1fa356891368 100644 --- a/data/random-teams.ts +++ b/data/random-teams.ts @@ -1716,11 +1716,10 @@ export class RandomTeams { pokemonToExclude: RandomTeamsTypes.RandomSet[] = [], isMonotype = false, pokemonList: string[] - ) { + ): [{[k: string]: ID[]}, string[]] { const exclude = pokemonToExclude.map(p => toID(p.species)); - const pokemonPool = []; + const pokemonPool: {[k: string]: ID[]} = {}; const baseSpeciesPool = []; - const baseSpeciesCount: {[k: string]: number} = {}; for (const pokemon of pokemonList) { let species = this.dex.species.get(pokemon); if (exclude.includes(species.id)) continue; @@ -1731,16 +1730,18 @@ export class RandomTeams { if (!species.types.includes(type)) continue; } } - pokemonPool.push(pokemon); - baseSpeciesCount[species.baseSpecies] = (baseSpeciesCount[species.baseSpecies] || 0) + 1; + + if (species.baseSpecies in pokemonPool) { + pokemonPool[species.baseSpecies].push(species.id); + } else { + pokemonPool[species.baseSpecies] = [species.id]; + } } // Include base species 1x if 1-3 formes, 2x if 4-6 formes, 3x if 7+ formes - for (const baseSpecies of Object.keys(baseSpeciesCount)) { - for (let i = 0; i < Math.min(Math.ceil(baseSpeciesCount[baseSpecies] / 3), 3); i++) { - baseSpeciesPool.push(baseSpecies); - // Squawkabilly has 4 formes, but only 2 functionally different formes, so only include it 1x - if (baseSpecies === 'Squawkabilly') break; - } + for (const baseSpecies of Object.keys(pokemonPool)) { + // Squawkabilly has 4 formes, but only 2 functionally different formes, so only include it 1x + const weight = (baseSpecies === 'Squawkabilly') ? 1 : Math.min(Math.ceil(pokemonPool[baseSpecies].length / 3), 3); + for (let i = 0; i < weight; i++) baseSpeciesPool.push(baseSpecies); } return [pokemonPool, baseSpeciesPool]; } @@ -1779,12 +1780,7 @@ export class RandomTeams { let leadsRemaining = this.format.gameType === 'doubles' ? 2 : 1; while (baseSpeciesPool.length && pokemon.length < this.maxTeamSize) { const baseSpecies = this.sampleNoReplace(baseSpeciesPool); - const currentSpeciesPool: Species[] = []; - for (const poke of pokemonPool) { - const species = this.dex.species.get(poke); - if (species.baseSpecies === baseSpecies) currentSpeciesPool.push(species); - } - let species = this.sample(currentSpeciesPool); + let species = this.dex.species.get(this.sample(pokemonPool[baseSpecies])); if (!species.exists) continue; // Limit to one of each species (Species Clause)