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 3.87 KB | None | 0 0
  1. (function(context) {
  2. const pixi = gApp;
  3. const GAME = gGame;
  4. const SetMouse = function SetMouse(x, y) {
  5. pixi.renderer.plugins.interaction.mouse.global.x = x;
  6. pixi.renderer.plugins.interaction.mouse.global.y = y;
  7. }
  8. const EnemyManager = function EnemyManager() {
  9. return GAME.m_State.m_EnemyManager;
  10. }
  11. const AttackManager = function AttackManager() {
  12. return GAME.m_State.m_AttackManager;
  13. }
  14. // Let's challenge ourselves to be human here!
  15. const CLICKS_PER_SECOND = 10;
  16.  
  17. const InGame = function InGame() {
  18. return GAME.m_State.m_bRunning;
  19. }
  20.  
  21. const WORST_SCORE = -1 / 0;
  22. const START_POS = pixi.renderer.width;
  23.  
  24.  
  25. const EnemySpeed = function EnemySpeed(enemy) {
  26. return enemy.m_Sprite.vx;
  27. }
  28. const EnemyDistance = function EnemyDistance(enemy) {
  29. return (enemy.m_Sprite.x - k_nDamagePointx) / (START_POS - k_nDamagePointx);
  30. }
  31.  
  32.  
  33. class Attack {
  34. constructor() {
  35. this.nextAttackDelta = 0;
  36. }
  37. shouldAttack(delta) {
  38. throw new Error("shouldAttack not implemented");
  39. }
  40. process(enemies) {
  41. throw new Error("process not implemented");
  42. }
  43. }
  44.  
  45. // Basic clicking attack, attack closest
  46. class ClickAttack extends Attack {
  47. shouldAttack(delta) {
  48. this.nextAttackDelta -= delta;
  49. return this.nextAttackDelta <= 0;;
  50. }
  51. score(enemy) {
  52. if (enemy.m_bDead)
  53. return WORST_SCORE;
  54. return 1 - EnemyDistance(enemy);
  55. }
  56. process(enemies) {
  57. let target, target_score = WORST_SCORE;
  58.  
  59. enemies.forEach((enemy) => {
  60. if (!enemy.m_Sprite.visible)
  61. return;
  62. let now_score = this.score(enemy);
  63. if (now_score > target_score) {
  64. target = enemy, target_score = now_score;
  65. }
  66. });
  67.  
  68. if (target)
  69. this.attack(target);
  70. }
  71. attack(enemy) {
  72. enemy.m_Sprite.click();
  73. this.nextAttackDelta = 1 / CLICKS_PER_SECOND;
  74. }
  75. }
  76.  
  77. // the '1' button (SlimeAttack PsychicAttack BeastAttack - depends on body type of your salien)
  78. class SpecialAttack extends Attack {
  79. getCurrent() {
  80. if (gSalien.m_BodyType == "slime")
  81. return "slimeattack";
  82. else if (gSalien.m_BodyType == "beast")
  83. return "beastattack";
  84. else
  85. return "psychicattack";
  86. }
  87. getData() {
  88. return AttackManager().m_AttackData[this.getCurrent()];
  89. }
  90. shouldAttack(delta) {
  91. let Manager = AttackManager().m_mapCooldowns.get(this.getCurrent());
  92. let lastUsed = Manager.m_rtAttackLastUsed;
  93. let canAttack = Manager.BAttack();
  94. Manager.m_rtAttackLastUsed = lastUsed;
  95. return canAttack
  96. }
  97. score(enemy) {
  98. if (enemy.m_bDead)
  99. return WORST_SCORE;
  100. return enemy.m_nHealth;
  101. }
  102. process(enemies) {
  103. let target, target_score = WORST_SCORE;
  104.  
  105. enemies.forEach((enemy) => {
  106. if (!enemy.m_Sprite.visible)
  107. return;
  108. let now_score = this.score(enemy);
  109. if (now_score > target_score) {
  110. target = enemy, target_score = now_score;
  111. }
  112. });
  113.  
  114. if (target)
  115. this.attack(target.m_Sprite.x, target.m_Sprite.y);
  116. }
  117. attack(x, y) {
  118. SetMouse(x, y)
  119. AttackManager().m_mapKeyCodeToAttacks.get(this.getData().keycode)()
  120. }
  121. }
  122.  
  123. let attacks = [
  124. new ClickAttack(),
  125. new SpecialAttack()
  126. ]
  127.  
  128. if (context.BOT_FUNCTION) {
  129. pixi.ticker.remove(context.BOT_FUNCTION);
  130. context.BOT_FUNCTION = undefined;
  131. }
  132.  
  133. context.BOT_FUNCTION = function ticker(delta) {
  134. delta /= 100;
  135.  
  136. if (!InGame()) {
  137. return;
  138. }
  139.  
  140. let state = EnemyManager();
  141.  
  142. let enemies = state.m_rgEnemies;
  143.  
  144. for (let attack of attacks)
  145. if (attack.shouldAttack(delta))
  146. attack.process(enemies);
  147.  
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement