Advertisement
Guest User

PiC Moves

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