Update random team generators

- Remove `randomMonotypeTeam` and use `randomTeam` for Monotype Random
Battle. This prevents having to maintain two functions, in addition to
removing duplicate code.
- Improve Monotype teams by preventing more than one of the same type
combination.
- Remove no longer needed Pichu-Spiky-eared check from
`randomDoublesTeam`.
This commit is contained in:
The Immortal 2016-05-17 00:30:23 +04:00
parent a653bb813b
commit a876232d33
2 changed files with 28 additions and 126 deletions

View File

@ -2088,7 +2088,7 @@ exports.Formats = [
name: "Monotype Random Battle",
section: "Other Metagames",
team: 'randomMonotype',
team: 'random',
searchShow: false,
ruleset: ['Pokemon', 'Same Type Clause', 'Sleep Clause Mod', 'HP Percentage Mod', 'Cancel Mod'],
},

View File

@ -718,7 +718,7 @@ exports.BattleScripts = {
if (!teamGenerator && team) return team;
// Reinitialize the RNG seed to create random teams.
this.startingSeed = this.startingSeed.concat(this.generateSeed());
team = this[teamGenerator || 'randomTeam'](side);
team = this[teamGenerator || 'randomTeam'](side, format.id);
// Restore the default seed
this.seed = this.startingSeed.slice(0, 4);
return team;
@ -2085,16 +2085,25 @@ exports.BattleScripts = {
shiny: !this.random(1024),
};
},
randomTeam: function (side) {
randomTeam: function (side, format) {
let pokemonLeft = 0;
let pokemon = [];
let excludedTiers = {'LC':1, 'LC Uber':1, 'NFE':1};
let excludedTiers = {'NFE':1, 'LC Uber':1, 'LC':1};
let allowedNFE = {'Chansey':1, 'Doublade':1, 'Gligar':1, 'Porygon2':1, 'Scyther':1};
// For Monotype
let typePool = Object.keys(this.data.TypeChart);
let type = typePool[this.random(typePool.length)];
let pokemonPool = [];
for (let id in this.data.FormatsData) {
let template = this.getTemplate(id);
if (format === 'monotyperandombattle') {
let types = template.types;
if (template.battleOnly) types = this.getTemplate(template.baseSpecies).types;
if (types.indexOf(type) < 0) continue;
}
if (!excludedTiers[template.tier] && !template.isMega && !template.isPrimal && !template.isNonstandard && template.randomBattleMoves) {
pokemonPool.push(id);
}
@ -2179,17 +2188,6 @@ exports.BattleScripts = {
continue;
}
// Limit 2 of any type
let types = template.types;
let skip = false;
for (let t = 0; t < types.length; t++) {
if (typeCount[types[t]] > 1 && this.random(5) >= 1) {
skip = true;
break;
}
}
if (skip) continue;
if (potd && potd.exists) {
// The Pokemon of the Day belongs in slot 2
if (pokemon.length === 1) {
@ -2204,6 +2202,20 @@ exports.BattleScripts = {
}
}
let types = template.types;
if (format !== 'monotyperandombattle') {
// Limit 2 of any type
let skip = false;
for (let t = 0; t < types.length; t++) {
if (typeCount[types[t]] > 1 && this.random(5) >= 1) {
skip = true;
break;
}
}
if (skip) continue;
}
let set = this.randomSet(template, pokemon.length, teamDetails);
// Illusion shouldn't be the last Pokemon of the team
@ -2256,7 +2268,7 @@ exports.BattleScripts = {
let pokemonLeft = 0;
let pokemon = [];
let excludedTiers = {'LC':1, 'LC Uber':1, 'NFE':1};
let excludedTiers = {'NFE':1, 'LC Uber':1, 'LC':1};
let allowedNFE = {'Chansey':1, 'Doublade':1, 'Porygon2':1, 'Scyther':1};
let pokemonPool = [];
@ -2287,9 +2299,6 @@ exports.BattleScripts = {
// Limit to one of each species (Species Clause)
if (baseFormes[template.baseSpecies]) continue;
// Not available on ORAS
if (template.species === 'Pichu-Spiky-eared') continue;
// Only certain NFE Pokemon are allowed
if (template.evos.length && !allowedNFE[template.species]) continue;
@ -3476,111 +3485,4 @@ exports.BattleScripts = {
return pokemon;
},
randomMonotypeTeam: function (side) {
let pokemonLeft = 0;
let pokemon = [];
let excludedTiers = {'LC':1, 'LC Uber':1, 'NFE':1};
let allowedNFE = {'Chansey':1, 'Doublade':1, 'Pikachu':1, 'Porygon2':1, 'Scyther':1};
let typePool = Object.keys(this.data.TypeChart);
let type = typePool[this.random(typePool.length)];
let pokemonPool = [];
for (let id in this.data.FormatsData) {
let template = this.getTemplate(id);
let types = template.types;
if (template.baseSpecies === 'Castform') types = ['Normal'];
if (template.speciesid === 'meloettapirouette') types = ['Normal', 'Psychic'];
if (!excludedTiers[template.tier] && types.indexOf(type) >= 0 && !template.isMega && !template.isPrimal && !template.isNonstandard && template.randomBattleMoves) {
pokemonPool.push(id);
}
}
let baseFormes = {};
let uberCount = 0;
let puCount = 0;
let megaCount = 0;
while (pokemonPool.length && pokemonLeft < 6) {
let template = this.getTemplate(this.sampleNoReplace(pokemonPool));
if (!template.exists) continue;
// Limit to one of each species (Species Clause)
if (baseFormes[template.baseSpecies]) continue;
// Not available on ORAS
if (template.species === 'Pichu-Spiky-eared') continue;
// Only certain NFE Pokemon are allowed
if (template.evos.length && !allowedNFE[template.species]) continue;
let tier = template.tier;
switch (tier) {
case 'PU':
// PUs are limited to 2 but have a 20% chance of being added anyway.
if (puCount > 1 && this.random(5) >= 1) continue;
break;
case 'Uber':
// Ubers are limited to 2 but have a 20% chance of being added anyway.
if (uberCount > 1 && this.random(5) >= 1) continue;
break;
case 'CAP':
// CAPs have 20% the normal rate
if (this.random(5) >= 1) continue;
break;
case 'Unreleased':
// Unreleased Pokémon have 20% the normal rate
if (this.random(5) >= 1) continue;
}
// Adjust rate for species with multiple formes
switch (template.baseSpecies) {
case 'Arceus':
if (this.random(18) >= 1) continue;
break;
case 'Basculin':
if (this.random(2) >= 1) continue;
break;
case 'Genesect':
if (this.random(5) >= 1) continue;
break;
case 'Gourgeist':
if (this.random(4) >= 1) continue;
break;
case 'Meloetta':
if (this.random(2) >= 1) continue;
break;
case 'Pikachu':
// Cosplay Pikachu formes have 20% the normal rate (1/30 the normal rate each)
if (template.species !== 'Pikachu' && this.random(30) >= 1) continue;
}
let set = this.randomSet(template, pokemon.length, megaCount);
// Illusion shouldn't be on the last pokemon of the team
if (set.ability === 'Illusion' && pokemonLeft > 4) continue;
// Limit the number of Megas to one
let forme = template.otherFormes && this.getTemplate(template.otherFormes[0]);
let isMegaSet = this.getItem(set.item).megaStone || (forme && forme.isMega && forme.requiredMove && set.moves.indexOf(toId(forme.requiredMove)) >= 0);
if (isMegaSet && megaCount > 0) continue;
// Okay, the set passes, add it to our team
pokemon.push(set);
// Now that our Pokemon has passed all checks, we can increment our counters
pokemonLeft++;
// Increment Uber/NU counters
if (tier === 'Uber') {
uberCount++;
} else if (tier === 'PU') {
puCount++;
}
// Increment mega and base species counters
if (isMegaSet) megaCount++;
baseFormes[template.baseSpecies] = 1;
}
return pokemon;
},
};