Pikachuun

randomHCTeam

Aug 26th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. randomHCTeam: function (side) {
  2. var team = [];
  3.  
  4. var itemPool = Object.keys(this.data.Items);
  5. var abilityPool = Object.keys(this.data.Abilities);
  6. var movePool = Object.keys(this.data.Movedex);
  7. var naturePool = Object.keys(this.data.Natures);
  8.  
  9. var hasDexNumber = {};
  10. var formes = [[], [], [], [], [], []];
  11.  
  12. // Pick six random pokemon--no repeats, even among formes
  13. // Also need to either normalize for formes or select formes at random
  14. // Unreleased are okay but no CAP
  15.  
  16. var num;
  17. for (var i = 0; i < 6; i++) {
  18. do {
  19. num = this.random(721) + 1;
  20. } while (num in hasDexNumber);
  21. hasDexNumber[num] = i;
  22. }
  23.  
  24. for (var id in this.data.Pokedex) {
  25. if (!(this.data.Pokedex[id].num in hasDexNumber)) continue;
  26. var template = this.getTemplate(id);
  27. if (template.learnset && template.species !== 'Pichu-Spiky-eared') {
  28. formes[hasDexNumber[template.num]].push(template.species);
  29. }
  30. }
  31.  
  32. for (var i = 0; i < 6; i++) {
  33. // Choose forme
  34. var pokemon = formes[i][this.random(formes[i].length)];
  35. var template = this.getTemplate(pokemon);
  36.  
  37. // Random unique item
  38. var item = '';
  39. do {
  40. item = this.sampleNoReplace(itemPool);
  41. } while (this.data.Items[item].isNonstandard);
  42.  
  43. // Genesect forms are a sprite difference based on its Drives
  44. if (template.species.substr(0, 9) === 'Genesect-' && item !== toId(template.requiredItem)) pokemon = 'Genesect';
  45.  
  46. // Random unique ability
  47. var ability = '';
  48. do {
  49. ability = this.sampleNoReplace(abilityPool);
  50. } while (this.data.Abilities[ability].isNonstandard);
  51.  
  52. // Random unique moves
  53. var m = [];
  54. while (true) {
  55. var moveid = this.sampleNoReplace(movePool);
  56. if (!this.data.Movedex[moveid].isNonstandard && (moveid === 'hiddenpower' || moveid.substr(0, 11) !== 'hiddenpower')) {
  57. if (m.push(moveid) >= 4) break;
  58. }
  59. }
  60.  
  61. // Random EVs
  62. var evs = {hp: 0, atk: 0, def: 0, spa: 0, spd: 0, spe: 0};
  63. var s = ['hp', 'atk', 'def', 'spa', 'spd', 'spe'];
  64. var evpool = 510;
  65. do {
  66. var x = s[this.random(s.length)];
  67. var y = this.random(Math.min(256 - evs[x], evpool + 1));
  68. evs[x] += y;
  69. evpool -= y;
  70. } while (evpool > 0);
  71.  
  72. // Random IVs
  73. var ivs = {hp: this.random(32), atk: this.random(32), def: this.random(32), spa: this.random(32), spd: this.random(32), spe: this.random(32)};
  74.  
  75. // Random nature
  76. var nature = naturePool[this.random(naturePool.length)];
  77.  
  78. // Level balance
  79. var mbstmin = 1307;
  80. var stats = template.baseStats;
  81. var mbst = (stats['hp'] * 2 + 31 + 21 + 100) + 10;
  82. mbst += (stats['atk'] * 2 + 31 + 21 + 100) + 5;
  83. mbst += (stats['def'] * 2 + 31 + 21 + 100) + 5;
  84. mbst += (stats['spa'] * 2 + 31 + 21 + 100) + 5;
  85. mbst += (stats['spd'] * 2 + 31 + 21 + 100) + 5;
  86. mbst += (stats['spe'] * 2 + 31 + 21 + 100) + 5;
  87. var level = Math.floor(100 * mbstmin / mbst);
  88. while (level < 100) {
  89. mbst = Math.floor((stats['hp'] * 2 + 31 + 21 + 100) * level / 100 + 10);
  90. mbst += Math.floor(((stats['atk'] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
  91. mbst += Math.floor((stats['def'] * 2 + 31 + 21 + 100) * level / 100 + 5);
  92. mbst += Math.floor(((stats['spa'] * 2 + 31 + 21 + 100) * level / 100 + 5) * level / 100);
  93. mbst += Math.floor((stats['spd'] * 2 + 31 + 21 + 100) * level / 100 + 5);
  94. mbst += Math.floor((stats['spe'] * 2 + 31 + 21 + 100) * level / 100 + 5);
  95. if (mbst >= mbstmin) break;
  96. level++;
  97. }
  98.  
  99. // Random happiness
  100. var happiness = this.random(256);
  101.  
  102. // Random shininess
  103. var shiny = !this.random(1024);
  104.  
  105. team.push({
  106. name: pokemon,
  107. item: item,
  108. ability: ability,
  109. moves: m,
  110. evs: evs,
  111. ivs: ivs,
  112. nature: nature,
  113. level: level,
  114. happiness: happiness,
  115. shiny: shiny
  116. });
  117. }
  118.  
  119. return team;
  120. },
Advertisement
Add Comment
Please, Sign In to add comment