Advertisement
Guest User

Untitled

a guest
Oct 12th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     /**
  2.      * @param {number} [depth]
  3.      * @return {RandomTeamsTypes["RandomFactorySet"][]}
  4.      */
  5.     randomBSSFactoryTeam(depth = 0) {
  6.         let forceResult = (depth >= 4);
  7.         let pokemon = [];
  8.         let pokemonPool = Object.keys(this.randomBSSFactorySets);
  9.         /**@type {TeamData} */
  10.         let teamData = {typeCount: {}, typeComboCount: {}, baseFormes: {}, megaCount: 0, zCount: 0, eeveeLimCount: 0, has: {}, forceResult: forceResult, weaknesses: {}, resistances: {}};
  11.         /**@type {string[]} */
  12.         let requiredMoveFamilies = [];
  13.         /**@type {{[k: string]: string}} */
  14.         let requiredMoves = {};
  15.         /**@type {{[k: string]: string}} */
  16.         let weatherAbilitiesSet = {'drizzle': 'raindance', 'drought': 'sunnyday', 'snowwarning': 'hail', 'sandstream': 'sandstorm'};
  17.         /**@type {{[k: string]: string[]}} */
  18.         let resistanceAbilities = {
  19.             'waterabsorb': ['Water'],
  20.             'flashfire': ['Fire'],
  21.             'lightningrod': ['Electric'], 'voltabsorb': ['Electric'],
  22.             'thickfat': ['Ice', 'Fire'],
  23.             'levitate': ['Ground'],
  24.         };
  25.  
  26.         while (pokemonPool.length && pokemon.length < 6) {
  27.             let template = this.getTemplate(this.sampleNoReplace(pokemonPool));
  28.             if (!template.exists) continue;
  29.             let speciesFlags = this.randomBSSFactorySets[template.speciesid].flags;
  30.             // Limit to one of each species (Species Clause)
  31.             if (teamData.baseFormes[template.baseSpecies]) continue;
  32.             // Limit the number of Megas + Z-moves to 3
  33.             if (teamData.megaCount + teamData.zCount >= 3 && speciesFlags.megaOnly) continue;
  34.             // Limit 2 of any type
  35.             let types = template.types;
  36.             let skip = false;
  37.             for (const type of types) {
  38.                 if (teamData.typeCount[type] > 1 && this.randomChance(4, 5)) {
  39.                     skip = true;
  40.                     break;
  41.                 }
  42.             }
  43.             if (skip) continue;
  44.             // Restrict Eevee with certain Pokemon
  45.             if (speciesFlags.limEevee) teamData.eeveeLimCount++;
  46.             if (teamData.eeveeLimCount >= 1 && speciesFlags.limEevee) continue;
  47.             let set = this.randomBSSFactorySet(template, pokemon.length, teamData);
  48.             if (!set) continue;
  49.             // Limit 1 of any type combination
  50.             let typeCombo = types.slice().sort().join();
  51.             if (set.ability === 'Drought' || set.ability === 'Drizzle') {
  52.                 // Drought and Drizzle don't count towards the type combo limit
  53.                 typeCombo = set.ability;
  54.             }
  55.             if (typeCombo in teamData.typeComboCount) continue;
  56.            
  57.         // VALIDACAO POKEONE //////////////////////////////////
  58.         if (set.item.megaStone || set.item.zMove) {
  59.             set.item = 'Leftovers';
  60.         }
  61.        
  62.             // Okay, the set passes, add it to our team
  63.             pokemon.push(set);
  64.  
  65.             // Now that our Pokemon has passed all checks, we can update team data:
  66.             for (const type of types) {
  67.                 if (type in teamData.typeCount) {
  68.                     teamData.typeCount[type]++;
  69.                 } else {
  70.                     teamData.typeCount[type] = 1;
  71.                 }
  72.             }
  73.             teamData.typeComboCount[typeCombo] = 1;
  74.  
  75.             teamData.baseFormes[template.baseSpecies] = 1;
  76.  
  77.             // Limit Mega and Z-move
  78.             let itemData = this.getItem(set.item);
  79.             if (itemData.megaStone) teamData.megaCount++;
  80.             if (itemData.zMove) teamData.zCount++;
  81.             teamData.has[itemData.id] = 1;
  82.  
  83.             let abilityData = this.getAbility(set.ability);
  84.             if (abilityData.id in weatherAbilitiesSet) {
  85.                 teamData.weather = weatherAbilitiesSet[abilityData.id];
  86.             }
  87.  
  88.             for (const move of set.moves) {
  89.                 let moveId = toId(move);
  90.                 if (moveId in teamData.has) {
  91.                     teamData.has[moveId]++;
  92.                 } else {
  93.                     teamData.has[moveId] = 1;
  94.                 }
  95.                 if (moveId in requiredMoves) {
  96.                     teamData.has[requiredMoves[moveId]] = 1;
  97.                 }
  98.             }
  99.  
  100.             for (let typeName in this.data.TypeChart) {
  101.                 // Cover any major weakness (3+) with at least one resistance
  102.                 if (teamData.resistances[typeName] >= 1) continue;
  103.                 if (resistanceAbilities[abilityData.id] && resistanceAbilities[abilityData.id].includes(typeName) || !this.getImmunity(typeName, types)) {
  104.                     // Heuristic: assume that Pokémon with these abilities don't have (too) negative typing.
  105.                     teamData.resistances[typeName] = (teamData.resistances[typeName] || 0) + 1;
  106.                     if (teamData.resistances[typeName] >= 1) teamData.weaknesses[typeName] = 0;
  107.                     continue;
  108.                 }
  109.                 let typeMod = this.getEffectiveness(typeName, types);
  110.                 if (typeMod < 0) {
  111.                     teamData.resistances[typeName] = (teamData.resistances[typeName] || 0) + 1;
  112.                     if (teamData.resistances[typeName] >= 1) teamData.weaknesses[typeName] = 0;
  113.                 } else if (typeMod > 0) {
  114.                     teamData.weaknesses[typeName] = (teamData.weaknesses[typeName] || 0) + 1;
  115.                 }
  116.             }
  117.         }
  118.         if (pokemon.length < 6) return this.randomBSSFactoryTeam(++depth);
  119.  
  120.         // Quality control
  121.         if (!teamData.forceResult) {
  122.             for (const requiredFamily of requiredMoveFamilies) {
  123.                 if (!teamData.has[requiredFamily]) return this.randomBSSFactoryTeam(++depth);
  124.             }
  125.             for (let type in teamData.weaknesses) {
  126.                 if (teamData.weaknesses[type] >= 3) return this.randomBSSFactoryTeam(++depth);
  127.             }
  128.         }
  129.  
  130.         return pokemon;
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement