Advertisement
Guest User

Untitled

a guest
Jan 29th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.91 KB | None | 0 0
  1. 'use strict';
  2.  
  3. exports.BattleScripts = {
  4. nextTurn: function () {
  5. this.turn++;
  6. if (this.turn % 12 === 1) {
  7. //this.clearWeather();
  8. this.setWeather('hail');
  9. }
  10. else if (this.turn % 12 === 4) {
  11. //this.clearWeather();
  12. this.setWeather('sunnyday');
  13. }
  14. else if (this.turn % 12 === 7) {
  15. //this.clearWeather();
  16. this.setWeather('sandstorm');
  17. }
  18. else if (this.turn % 12 === 10) {
  19. //this.clearWeather();
  20. this.setWeather('raindance');
  21. }
  22. let allStale = true;
  23. let oneStale = false;
  24. for (let i = 0; i < this.sides.length; i++) {
  25. for (let j = 0; j < this.sides[i].active.length; j++) {
  26. let pokemon = this.sides[i].active[j];
  27. if (!pokemon) continue;
  28. pokemon.moveThisTurn = '';
  29. pokemon.usedItemThisTurn = false;
  30. pokemon.newlySwitched = false;
  31. pokemon.disabledMoves = {};
  32. this.runEvent('DisableMove', pokemon);
  33. if (!pokemon.ateBerry) pokemon.disableMove('belch');
  34. if (pokemon.lastAttackedBy) {
  35. if (pokemon.lastAttackedBy.pokemon.isActive) {
  36. pokemon.lastAttackedBy.thisTurn = false;
  37. } else {
  38. pokemon.lastAttackedBy = null;
  39. }
  40. }
  41.  
  42. pokemon.trapped = pokemon.maybeTrapped = false;
  43. this.runEvent('TrapPokemon', pokemon);
  44. if (pokemon.runImmunity('trapped')) {
  45. this.runEvent('MaybeTrapPokemon', pokemon);
  46. }
  47. // Disable the faculty to cancel switches if a foe may have a trapping ability
  48. for (let i = 0; i < this.sides.length; ++i) {
  49. let side = this.sides[i];
  50. if (side === pokemon.side) continue;
  51. for (let j = 0; j < side.active.length; ++j) {
  52. let source = side.active[j];
  53. if (!source || source.fainted) continue;
  54. let template = (source.illusion || source).template;
  55. if (!template.abilities) continue;
  56. for (let k in template.abilities) {
  57. let ability = template.abilities[k];
  58. if (ability === source.ability) {
  59. // pokemon event was already run above so we don't need
  60. // to run it again.
  61. continue;
  62. }
  63. if (k === 'H' && template.unreleasedHidden) {
  64. // unreleased hidden ability
  65. continue;
  66. }
  67. if (pokemon.runImmunity('trapped')) {
  68. this.singleEvent('FoeMaybeTrapPokemon',
  69. this.getAbility(ability), {}, pokemon, source);
  70. }
  71. }
  72. }
  73. }
  74.  
  75. if (pokemon.fainted) continue;
  76. if (pokemon.isStale < 2) {
  77. if (pokemon.isStaleCon >= 2) {
  78. if (pokemon.hp >= pokemon.isStaleHP - pokemon.maxhp / 100) {
  79. pokemon.isStale++;
  80. if (this.firstStaleWarned && pokemon.isStale < 2) {
  81. switch (pokemon.isStaleSource) {
  82. case 'struggle':
  83. this.add('html', '<div class="broadcast-red">' + this.escapeHTML(pokemon.name) + ' isn\'t losing HP from Struggle. If this continues, it will be classified as being in an endless loop.</div>');
  84. break;
  85. case 'drag':
  86. this.add('html', '<div class="broadcast-red">' + this.escapeHTML(pokemon.name) + ' isn\'t losing PP or HP from being forced to switch. If this continues, it will be classified as being in an endless loop.</div>');
  87. break;
  88. case 'switch':
  89. this.add('html', '<div class="broadcast-red">' + this.escapeHTML(pokemon.name) + ' isn\'t losing PP or HP from repeatedly switching. If this continues, it will be classified as being in an endless loop.</div>');
  90. break;
  91. }
  92. }
  93. }
  94. pokemon.isStaleCon = 0;
  95. pokemon.isStalePPTurns = 0;
  96. pokemon.isStaleHP = pokemon.hp;
  97. }
  98. if (pokemon.isStalePPTurns >= 5) {
  99. if (pokemon.hp >= pokemon.isStaleHP - pokemon.maxhp / 100) {
  100. pokemon.isStale++;
  101. pokemon.isStaleSource = 'ppstall';
  102. if (this.firstStaleWarned && pokemon.isStale < 2) {
  103. this.add('html', '<div class="broadcast-red">' + this.escapeHTML(pokemon.name) + ' isn\'t losing PP or HP. If it keeps on not losing PP or HP, it will be classified as being in an endless loop.</div>');
  104. }
  105. }
  106. pokemon.isStaleCon = 0;
  107. pokemon.isStalePPTurns = 0;
  108. pokemon.isStaleHP = pokemon.hp;
  109. }
  110. }
  111. if (pokemon.getMoves().length === 0) {
  112. pokemon.isStaleCon++;
  113. pokemon.isStaleSource = 'struggle';
  114. }
  115. if (pokemon.isStale < 2) {
  116. allStale = false;
  117. } else if (pokemon.isStale && !pokemon.staleWarned) {
  118. oneStale = pokemon;
  119. }
  120. if (!pokemon.isStalePPTurns) {
  121. pokemon.isStaleHP = pokemon.hp;
  122. if (pokemon.activeTurns) pokemon.isStaleCon = 0;
  123. }
  124. if (pokemon.activeTurns) {
  125. pokemon.isStalePPTurns++;
  126. }
  127. pokemon.activeTurns++;
  128. }
  129. this.sides[i].faintedLastTurn = this.sides[i].faintedThisTurn;
  130. this.sides[i].faintedThisTurn = false;
  131. }
  132. let banlistTable = this.getFormat().banlistTable;
  133. if (banlistTable && 'Rule:endlessbattleclause' in banlistTable) {
  134. if (oneStale) {
  135. let activationWarning = '<br />If all active Pok&eacute;mon go in an endless loop, Endless Battle Clause will activate.';
  136. if (allStale) activationWarning = '';
  137. let loopReason = '';
  138. switch (oneStale.isStaleSource) {
  139. case 'struggle':
  140. loopReason = ": it isn't losing HP from Struggle";
  141. break;
  142. case 'drag':
  143. loopReason = ": it isn't losing PP or HP from being forced to switch";
  144. break;
  145. case 'switch':
  146. loopReason = ": it isn't losing PP or HP from repeatedly switching";
  147. break;
  148. case 'getleppa':
  149. loopReason = ": it got a Leppa Berry it didn't start with";
  150. break;
  151. case 'useleppa':
  152. loopReason = ": it used a Leppa Berry it didn't start with";
  153. break;
  154. case 'ppstall':
  155. loopReason = ": it isn't losing PP or HP";
  156. break;
  157. case 'ppoverflow':
  158. loopReason = ": its PP overflowed";
  159. break;
  160. }
  161. this.add('html', '<div class="broadcast-red">' + this.escapeHTML(oneStale.name) + ' is in an endless loop' + loopReason + '.' + activationWarning + '</div>');
  162. oneStale.staleWarned = true;
  163. this.firstStaleWarned = true;
  164. }
  165. if (allStale) {
  166. this.add('message', "All active Pok\u00e9mon are in an endless loop. Endless Battle Clause activated!");
  167. let leppaPokemon = null;
  168. for (let i = 0; i < this.sides.length; i++) {
  169. for (let j = 0; j < this.sides[i].pokemon.length; j++) {
  170. let pokemon = this.sides[i].pokemon[j];
  171. if (toId(pokemon.set.item) === 'leppaberry') {
  172. if (leppaPokemon) {
  173. leppaPokemon = null; // both sides have Leppa
  174. this.add('-message', "Both sides started with a Leppa Berry.");
  175. } else {
  176. leppaPokemon = pokemon;
  177. }
  178. break;
  179. }
  180. }
  181. }
  182. if (leppaPokemon) {
  183. this.add('-message', "" + leppaPokemon.side.name + "'s " + leppaPokemon.name + " started with a Leppa Berry and loses.");
  184. this.win(leppaPokemon.side.foe);
  185. return;
  186. }
  187. this.win();
  188. return;
  189. }
  190. } else {
  191. if (allStale && !this.staleWarned) {
  192. this.staleWarned = true;
  193. this.add('html', '<div class="broadcast-red">If this format had Endless Battle Clause, it would have activated.</div>');
  194. } else if (oneStale) {
  195. this.add('html', '<div class="broadcast-red">' + this.escapeHTML(oneStale.name) + ' is in an endless loop.</div>');
  196. oneStale.staleWarned = true;
  197. }
  198. }
  199.  
  200. if (this.gameType === 'triples' && this.sides.map('pokemonLeft').count(1) === this.sides.length) {
  201. // If both sides have one Pokemon left in triples and they are not adjacent, they are both moved to the center.
  202. let center = false;
  203. for (let i = 0; i < this.sides.length; i++) {
  204. for (let j = 0; j < this.sides[i].active.length; j++) {
  205. if (!this.sides[i].active[j] || this.sides[i].active[j].fainted) continue;
  206. if (this.sides[i].active[j].position === 1) break;
  207. this.swapPosition(this.sides[i].active[j], 1, '[silent]');
  208. center = true;
  209. break;
  210. }
  211. }
  212. if (center) this.add('-center');
  213. }
  214.  
  215. this.add('turn', this.turn);
  216.  
  217. this.makeRequest('move');
  218. }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement