Advertisement
Guest User

top percentage

a guest
Mar 22nd, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.89 KB | None | 0 0
  1. //config/formats.js
  2.  
  3. {
  4. name: "Top Percentage",
  5. section: "Other Metagames",
  6. mod: 'toppercentage',
  7.  
  8. ruleset: ['OU'],
  9. onBegin: function () {
  10. console.log("ok");
  11. for (var i = 0; i < this.sides.length; i++) {
  12. this.sides[i].metaCount = 400;
  13. console.log("done once!");
  14.  
  15. }
  16. },
  17. onDamage: function (damage, target) {
  18. //only should work if does not make target faint
  19. let percentage = 100 * damage / target.maxhp;
  20. if (damage >= target.hp) {
  21. percentage = 100 * target.hp / target.maxhp;
  22. }
  23. target.side.metaCount -= percentage;
  24. console.log(target.id + ": " + target.side.metaCount);
  25. this.add('-message', target.id.slice(4) + ": " + Math.round(target.side.metaCount));
  26. if (target.side.metaCount <= 0.1) {
  27. //note: making this 0.1 because I got 1.10 times 10^-15 once
  28. //something silly with rounding
  29. //this works well enough
  30. this.win(target.side.foe);
  31. }
  32.  
  33. }
  34. },
  35.  
  36. //mods/toppercentage/moves.js
  37. 'use strict';
  38.  
  39. exports.BattleMovedex = {
  40. perishsong: {
  41. inherit: true,
  42. effect: {
  43. duration: 4,
  44. onEnd: function (target) {
  45. target.side.metaCount -= (100 * target.hp / target.maxhp);
  46. this.add('-start', target, 'perish0');
  47. console.log(target.id + ": " + target.side.metaCount);
  48. this.add('-message', target.id.slice(4) + ": " + Math.round(target.side.metaCount));
  49. target.faint();
  50. if (target.side.metaCount <= 0.1) {
  51. this.win(target.side.foe);
  52. }
  53. },
  54. onResidual: function (pokemon) {
  55. let duration = pokemon.volatiles['perishsong'].duration;
  56. this.add('-start', pokemon, 'perish' + duration);
  57. }
  58. }
  59. },
  60. destinybond: {
  61. inherit: true,
  62. effect: {
  63. onFaint: function (target, source, effect) {
  64. if (!source || !effect) return;
  65. if (effect.effectType === 'Move' && !effect.isFutureMove) {
  66. this.add('-activate', target, 'Destiny Bond');
  67. source.faint();
  68. console.log(source.id + ": " + source.side.metaCount);
  69. this.add('-message', source.id.slice(4) + ": " + Math.round(source.side.metaCount));
  70.  
  71. if (source.side.metaCount <= 0.1) {
  72. this.win(source.side.foe);
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }
  79.  
  80. //mods/toppercentage/scripts.js
  81. 'use strict';
  82.  
  83. exports.BattleScripts = {
  84. useMove: function (move, pokemon, target, sourceEffect) {
  85.  
  86. //addition
  87. if (move.selfdestruct) {
  88. pokemon.side.metaCount -= 100 * (pokemon.hp / pokemon.maxhp);
  89. console.log(pokemon.id + ": " + pokemon.side.metaCount);
  90. this.add('-message', pokemon.id.slice(4) + ": " + Math.round(pokemon.side.metaCount));
  91. if (pokemon.side.metaCount <= 0.1) {
  92. this.win(pokemon.side.foe);
  93. }
  94. }
  95.  
  96. if (!sourceEffect && this.effect.id) sourceEffect = this.effect;
  97. move = this.getMoveCopy(move);
  98. if (this.activeMove) move.priority = this.activeMove.priority;
  99. let baseTarget = move.target;
  100. if (!target && target !== false) target = this.resolveTarget(pokemon, move);
  101. if (move.target === 'self' || move.target === 'allies') {
  102. target = pokemon;
  103. }
  104. if (sourceEffect) move.sourceEffect = sourceEffect.id;
  105. let moveResult = false;
  106.  
  107. this.setActiveMove(move, pokemon, target);
  108.  
  109. this.singleEvent('ModifyMove', move, null, pokemon, target, move, move);
  110. if (baseTarget !== move.target) {
  111. // Target changed in ModifyMove, so we must adjust it here
  112. // Adjust before the next event so the correct target is passed to the
  113. // event
  114. target = this.resolveTarget(pokemon, move);
  115. }
  116. move = this.runEvent('ModifyMove', pokemon, target, move, move);
  117. if (baseTarget !== move.target) {
  118. // Adjust again
  119. target = this.resolveTarget(pokemon, move);
  120. }
  121. if (!move) return false;
  122.  
  123. let attrs = '';
  124. if (pokemon.fainted) {
  125. return false;
  126. }
  127.  
  128. if (move.flags['charge'] && !pokemon.volatiles[move.id]) {
  129. attrs = '|[still]'; // suppress the default move animation
  130. }
  131.  
  132. let movename = move.name;
  133. if (move.id === 'hiddenpower') movename = 'Hidden Power';
  134. if (sourceEffect) attrs += '|[from]' + this.getEffect(sourceEffect);
  135. this.addMove('move', pokemon, movename, target + attrs);
  136.  
  137. if (target === false) {
  138. this.attrLastMove('[notarget]');
  139. this.add('-notarget');
  140. if (move.target === 'normal') pokemon.isStaleCon = 0;
  141. return true;
  142. }
  143.  
  144. let targets = pokemon.getMoveTargets(move, target);
  145.  
  146. if (!sourceEffect) {
  147. let extraPP = 0;
  148. for (let i = 0; i < targets.length; i++) {
  149. let ppDrop = this.singleEvent('DeductPP', targets[i].getAbility(), targets[i].abilityData, targets[i], pokemon, move);
  150. if (ppDrop !== true) {
  151. extraPP += ppDrop || 0;
  152. }
  153. }
  154. if (extraPP > 0) {
  155. pokemon.deductPP(move, extraPP);
  156. }
  157. }
  158.  
  159. if (!this.runEvent('TryMove', pokemon, target, move)) {
  160. return true;
  161. }
  162.  
  163. this.singleEvent('UseMoveMessage', move, null, pokemon, target, move);
  164.  
  165. if (move.ignoreImmunity === undefined) {
  166. move.ignoreImmunity = (move.category === 'Status');
  167. }
  168.  
  169. let damage = false;
  170. if (move.target === 'all' || move.target === 'foeSide' || move.target === 'allySide' || move.target === 'allyTeam') {
  171. damage = this.tryMoveHit(target, pokemon, move);
  172. if (damage || damage === 0 || damage === undefined) moveResult = true;
  173. } else if (move.target === 'allAdjacent' || move.target === 'allAdjacentFoes') {
  174. if (move.selfdestruct) {
  175. this.faint(pokemon, pokemon, move);
  176. }
  177. if (!targets.length) {
  178. this.attrLastMove('[notarget]');
  179. this.add('-notarget');
  180. return true;
  181. }
  182. if (targets.length > 1) move.spreadHit = true;
  183. damage = 0;
  184. for (let i = 0; i < targets.length; i++) {
  185. let hitResult = this.tryMoveHit(targets[i], pokemon, move, true);
  186. if (hitResult || hitResult === 0 || hitResult === undefined) moveResult = true;
  187. damage += hitResult || 0;
  188. }
  189. if (!pokemon.hp) pokemon.faint();
  190. } else {
  191. target = targets[0];
  192. let lacksTarget = target.fainted;
  193. if (!lacksTarget) {
  194. if (move.target === 'adjacentFoe' || move.target === 'adjacentAlly' || move.target === 'normal' || move.target === 'randomNormal') {
  195. lacksTarget = !this.isAdjacent(target, pokemon);
  196. }
  197. }
  198. if (lacksTarget) {
  199. this.attrLastMove('[notarget]');
  200. this.add('-notarget');
  201. if (move.target === 'normal') pokemon.isStaleCon = 0;
  202. return true;
  203. }
  204. damage = this.tryMoveHit(target, pokemon, move);
  205. if (damage || damage === 0 || damage === undefined) moveResult = true;
  206. }
  207. if (!pokemon.hp) {
  208. this.faint(pokemon, pokemon, move);
  209. }
  210.  
  211. if (!moveResult) {
  212. this.singleEvent('MoveFail', move, null, target, pokemon, move);
  213. return true;
  214. }
  215.  
  216. if (move.selfdestruct) {
  217. this.faint(pokemon, pokemon, move);
  218. }
  219.  
  220. if (!move.negateSecondary && !(pokemon.hasAbility('sheerforce') && pokemon.volatiles['sheerforce'])) {
  221. this.singleEvent('AfterMoveSecondarySelf', move, null, pokemon, target, move);
  222. this.runEvent('AfterMoveSecondarySelf', pokemon, target, move);
  223. }
  224. return true;
  225. }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement