Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. (function(context) {
  2. const pixi = gApp;
  3. const GAME = gGame;
  4. const SERVER = gServer;
  5. const SetMouse = function SetMouse(x, y) {
  6. pixi.renderer.plugins.interaction.mouse.global.x = x;
  7. pixi.renderer.plugins.interaction.mouse.global.y = y;
  8. }
  9. const EnemyManager = function EnemyManager() {
  10. return GAME.m_State.m_EnemyManager;
  11. }
  12. const AttackManager = function AttackManager() {
  13. return GAME.m_State.m_AttackManager;
  14. }
  15. const TryContinue = function Continue() {
  16. let continued = false;
  17. if (GAME.m_State.m_VictoryScreen) {
  18. GAME.m_State.m_VictoryScreen.children.forEach(function(child) {
  19. if (child.visible && child.x == 155 && child.y == 300) {// TODO: not this
  20. continued = true;
  21. child.click();
  22. }
  23. })
  24. }
  25. if (GAME.m_State.m_LevelUpScreen) {
  26. continued = false;
  27. GAME.m_State.m_LevelUpScreen.children.forEach(function(child) {
  28. if (child.visible && child.x == 155 && child.y == 300) {// TODO: not this
  29. continued = true;
  30. child.click();
  31. }
  32. })
  33. }
  34. return continued;
  35. }
  36. const CanAttack = function CanAttack(attackname) {
  37. let Manager = AttackManager().m_mapCooldowns.get(attackname);
  38. let lastUsed = Manager.m_rtAttackLastUsed;
  39. let canAttack = Manager.BAttack();
  40. Manager.m_rtAttackLastUsed = lastUsed;
  41. return canAttack;
  42. }
  43.  
  44. // Let's challenge ourselves to be human here!
  45. const CLICKS_PER_SECOND = 10;
  46.  
  47. const InGame = function InGame() {
  48. return GAME.m_State.m_bRunning;
  49. }
  50.  
  51. const InZoneSelect = function InZoneSelect() {
  52. return GAME.m_State instanceof CBattleSelectionState;
  53. }
  54.  
  55. const WORST_SCORE = -1 / 0;
  56. const START_POS = pixi.renderer.width;
  57.  
  58. // context.lastZoneIndex;
  59. let isJoining = false;
  60.  
  61. const EnemySpeed = function EnemySpeed(enemy) {
  62. return enemy.m_Sprite.vx;
  63. }
  64. const EnemyDistance = function EnemyDistance(enemy) {
  65. return (enemy.m_Sprite.x - k_nDamagePointx) / (START_POS - k_nDamagePointx);
  66. }
  67.  
  68.  
  69. class Attack {
  70. constructor() {
  71. this.nextAttackDelta = 0;
  72. }
  73. shouldAttack(delta, enemies) {
  74. throw new Error("shouldAttack not implemented");
  75. }
  76. process(enemies) {
  77. throw new Error("process not implemented");
  78. }
  79. }
  80.  
  81. // Basic clicking attack, attack closest
  82. class ClickAttack extends Attack {
  83. shouldAttack(delta) {
  84. // Can't do basic attack when station is down
  85. if (GAME.m_State.m_PlayerHealth <= 0)
  86. return false;
  87. this.nextAttackDelta -= delta;
  88. return this.nextAttackDelta <= 0;;
  89. }
  90. score(enemy) {
  91. if (enemy.m_bDead)
  92. return WORST_SCORE;
  93. return 1 - EnemyDistance(enemy);
  94. }
  95. process(enemies) {
  96. let target, target_score = WORST_SCORE;
  97.  
  98. enemies.forEach((enemy) => {
  99. if (!enemy.m_Sprite.visible)
  100. return;
  101. let now_score = this.score(enemy);
  102. if (now_score > target_score) {
  103. target = enemy, target_score = now_score;
  104. }
  105. });
  106.  
  107. if (target)
  108. this.attack(target);
  109. }
  110. attack(enemy) {
  111. enemy.m_Sprite.click();
  112. this.nextAttackDelta = 1 / CLICKS_PER_SECOND;
  113. }
  114. }
  115.  
  116. // the '1' button (SlimeAttack PsychicAttack BeastAttack - depends on body type of your salien)
  117. class SpecialAttack extends Attack {
  118. getCurrent() {
  119. if (gSalien.m_BodyType == "slime")
  120. return "slimeattack";
  121. else if (gSalien.m_BodyType == "beast")
  122. return "beastattack";
  123. else
  124. return "psychicattack";
  125. }
  126. getData() {
  127. return AttackManager().m_AttackData[this.getCurrent()];
  128. }
  129. shouldAttack(delta) {
  130. return CanAttack(this.getCurrent());
  131. }
  132. score(enemy) {
  133. if (enemy.m_bDead)
  134. return WORST_SCORE;
  135. return enemy.m_nHealth;
  136. }
  137. process(enemies) {
  138. let target, target_score = WORST_SCORE;
  139.  
  140. enemies.forEach((enemy) => {
  141. if (!enemy.m_Sprite.visible)
  142. return;
  143. let now_score = this.score(enemy);
  144. if (now_score > target_score) {
  145. target = enemy, target_score = now_score;
  146. }
  147. });
  148.  
  149. if (target)
  150. this.attack(target.m_Sprite.x, target.m_Sprite.y);
  151. }
  152. attack(x, y) {
  153. SetMouse(x, y)
  154. AttackManager().m_mapKeyCodeToAttacks.get(this.getData().keycode)()
  155. }
  156. }
  157.  
  158. class BombAttack extends SpecialAttack {
  159. getCurrent() {
  160. return "explosion";
  161. }
  162. }
  163.  
  164. class FreezeAttack extends Attack {
  165. getCurrent() {
  166. return "flashfreeze";
  167. }
  168. shouldAttack(delta, enemies) {
  169. let shouldAttack = false;
  170. if (CanAttack(this.getCurrent())) {
  171. enemies.forEach((enemy) => {
  172. if (EnemyDistance(enemy) <= 0.05) {
  173. shouldAttack = true;
  174. }
  175. });
  176. }
  177. return shouldAttack;
  178. }
  179. getData() {
  180. return AttackManager().m_AttackData[this.getCurrent()];
  181. }
  182. process() {
  183. AttackManager().m_mapKeyCodeToAttacks.get(this.getData().keycode)()
  184. }
  185. }
  186.  
  187. let attacks = [
  188. new ClickAttack(),
  189. new SpecialAttack(),
  190. new FreezeAttack(),
  191. new BombAttack()
  192. ]
  193.  
  194. if (context.BOT_FUNCTION) {
  195. pixi.ticker.remove(context.BOT_FUNCTION);
  196. context.BOT_FUNCTION = undefined;
  197. }
  198.  
  199. context.BOT_FUNCTION = function ticker(delta) {
  200. delta /= 100;
  201.  
  202. if(GAME.m_IsStateLoading) {
  203. return;
  204. }
  205.  
  206. if (InZoneSelect() && context.lastZoneIndex !== undefined && !isJoining) {
  207. isJoining = true;
  208.  
  209. if (GAME.m_State.m_PlanetData.zones[context.lastZoneIndex].captured)
  210. {
  211. context.lastZoneIndex = undefined;
  212. return;
  213. }
  214.  
  215. SERVER.JoinZone(
  216. lastZoneIndex,
  217. function (results) {
  218. GAME.ChangeState(new CBattleState(GAME.m_State.m_PlanetData, context.lastZoneIndex));
  219. },
  220. GameLoadError
  221. );
  222.  
  223. return;
  224. }
  225. 33
  226. if (!InGame()) {
  227. if (TryContinue()) {
  228. console.log("continued!");
  229. }
  230. return;
  231. }
  232.  
  233. isJoining = false;
  234. context.lastZoneIndex = GAME.m_State.m_unZoneIndex;
  235.  
  236. let state = EnemyManager();
  237.  
  238. let enemies = state.m_rgEnemies;
  239.  
  240. for (let attack of attacks)
  241. if (attack.shouldAttack(delta, enemies))
  242. attack.process(enemies);
  243.  
  244. }
  245.  
  246.  
  247. pixi.ticker.add(context.BOT_FUNCTION);
  248.  
  249. })(window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement