Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param {number} [depth]
- * @return {RandomTeamsTypes["RandomFactorySet"][]}
- */
- randomBSSFactoryTeam(depth = 0) {
- let forceResult = (depth >= 4);
- let pokemon = [];
- let pokemonPool = Object.keys(this.randomBSSFactorySets);
- /**@type {TeamData} */
- let teamData = {typeCount: {}, typeComboCount: {}, baseFormes: {}, megaCount: 0, zCount: 0, eeveeLimCount: 0, has: {}, forceResult: forceResult, weaknesses: {}, resistances: {}};
- /**@type {string[]} */
- let requiredMoveFamilies = [];
- /**@type {{[k: string]: string}} */
- let requiredMoves = {};
- /**@type {{[k: string]: string}} */
- let weatherAbilitiesSet = {'drizzle': 'raindance', 'drought': 'sunnyday', 'snowwarning': 'hail', 'sandstream': 'sandstorm'};
- /**@type {{[k: string]: string[]}} */
- let resistanceAbilities = {
- 'waterabsorb': ['Water'],
- 'flashfire': ['Fire'],
- 'lightningrod': ['Electric'], 'voltabsorb': ['Electric'],
- 'thickfat': ['Ice', 'Fire'],
- 'levitate': ['Ground'],
- };
- while (pokemonPool.length && pokemon.length < 6) {
- let template = this.getTemplate(this.sampleNoReplace(pokemonPool));
- if (!template.exists) continue;
- let speciesFlags = this.randomBSSFactorySets[template.speciesid].flags;
- // Limit to one of each species (Species Clause)
- if (teamData.baseFormes[template.baseSpecies]) continue;
- // Limit the number of Megas + Z-moves to 3
- if (teamData.megaCount + teamData.zCount >= 3 && speciesFlags.megaOnly) continue;
- // Limit 2 of any type
- let types = template.types;
- let skip = false;
- for (const type of types) {
- if (teamData.typeCount[type] > 1 && this.randomChance(4, 5)) {
- skip = true;
- break;
- }
- }
- if (skip) continue;
- // Restrict Eevee with certain Pokemon
- if (speciesFlags.limEevee) teamData.eeveeLimCount++;
- if (teamData.eeveeLimCount >= 1 && speciesFlags.limEevee) continue;
- let set = this.randomBSSFactorySet(template, pokemon.length, teamData);
- if (!set) continue;
- // Limit 1 of any type combination
- let typeCombo = types.slice().sort().join();
- if (set.ability === 'Drought' || set.ability === 'Drizzle') {
- // Drought and Drizzle don't count towards the type combo limit
- typeCombo = set.ability;
- }
- if (typeCombo in teamData.typeComboCount) continue;
- // VALIDACAO POKEONE //////////////////////////////////
- if (set.item.megaStone || set.item.zMove) {
- set.item = 'Leftovers';
- }
- // Okay, the set passes, add it to our team
- pokemon.push(set);
- // Now that our Pokemon has passed all checks, we can update team data:
- for (const type of types) {
- if (type in teamData.typeCount) {
- teamData.typeCount[type]++;
- } else {
- teamData.typeCount[type] = 1;
- }
- }
- teamData.typeComboCount[typeCombo] = 1;
- teamData.baseFormes[template.baseSpecies] = 1;
- // Limit Mega and Z-move
- let itemData = this.getItem(set.item);
- if (itemData.megaStone) teamData.megaCount++;
- if (itemData.zMove) teamData.zCount++;
- teamData.has[itemData.id] = 1;
- let abilityData = this.getAbility(set.ability);
- if (abilityData.id in weatherAbilitiesSet) {
- teamData.weather = weatherAbilitiesSet[abilityData.id];
- }
- for (const move of set.moves) {
- let moveId = toId(move);
- if (moveId in teamData.has) {
- teamData.has[moveId]++;
- } else {
- teamData.has[moveId] = 1;
- }
- if (moveId in requiredMoves) {
- teamData.has[requiredMoves[moveId]] = 1;
- }
- }
- for (let typeName in this.data.TypeChart) {
- // Cover any major weakness (3+) with at least one resistance
- if (teamData.resistances[typeName] >= 1) continue;
- if (resistanceAbilities[abilityData.id] && resistanceAbilities[abilityData.id].includes(typeName) || !this.getImmunity(typeName, types)) {
- // Heuristic: assume that Pokémon with these abilities don't have (too) negative typing.
- teamData.resistances[typeName] = (teamData.resistances[typeName] || 0) + 1;
- if (teamData.resistances[typeName] >= 1) teamData.weaknesses[typeName] = 0;
- continue;
- }
- let typeMod = this.getEffectiveness(typeName, types);
- if (typeMod < 0) {
- teamData.resistances[typeName] = (teamData.resistances[typeName] || 0) + 1;
- if (teamData.resistances[typeName] >= 1) teamData.weaknesses[typeName] = 0;
- } else if (typeMod > 0) {
- teamData.weaknesses[typeName] = (teamData.weaknesses[typeName] || 0) + 1;
- }
- }
- }
- if (pokemon.length < 6) return this.randomBSSFactoryTeam(++depth);
- // Quality control
- if (!teamData.forceResult) {
- for (const requiredFamily of requiredMoveFamilies) {
- if (!teamData.has[requiredFamily]) return this.randomBSSFactoryTeam(++depth);
- }
- for (let type in teamData.weaknesses) {
- if (teamData.weaknesses[type] >= 3) return this.randomBSSFactoryTeam(++depth);
- }
- }
- return pokemon;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement