Guest User

Untitled

a guest
Jun 12th, 2015
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1. var clickRate = 10; // change to number of desired clicks per second
  2.  
  3. var isAlreadyRunning = false;
  4. var myMaxHealth = 0;
  5.  
  6. function doTheThing() {
  7. if (isAlreadyRunning || g_Minigame === undefined) {
  8. return;
  9. }
  10. isAlreadyRunning = true;
  11.  
  12. goToLaneWithLowest();
  13.  
  14. useMedicsIfRelevant();
  15.  
  16. // TODO use abilities if available and a suitable target exists
  17. // - Tactical Nuke on a Spawner if below 50% and above 25% of its health
  18. // - Cluster Bomb and Napalm if the current lane has a spawner and 2+ creeps
  19. // - Good Luck if available
  20. // - Metal Detector if a spawner death is imminent (predicted in > 2 and < 7 seconds)
  21. // - Morale Booster if available and lane has > 2 live enemies
  22. // - Decrease Cooldowns if another player used a long-cooldown ability < 10 seconds ago
  23.  
  24. // TODO purchase abilities and upgrades intelligently
  25.  
  26. // TODO click the current target a few times (<= 10/sec, so as not to cheat)
  27.  
  28. // TODO respawn if dead and respawn button is available
  29.  
  30. attemptRespawn();
  31.  
  32. clickTheThing();
  33.  
  34. isAlreadyRunning = false;
  35. }
  36.  
  37. function goToLaneWithLowest() {
  38. // TODO check if it's a boss level, handle boss levels differently
  39.  
  40. // TODO prefer lane with a dying creep as long as all living spawners have >50% health
  41.  
  42. // determine which living spawner has lowest hp
  43. var spawners = [];
  44. for (var i = 0; i < 3; i++) {
  45. for (var j = 0; j < 4; j++) {
  46. var enemy = g_Minigame.CurrentScene().GetEnemy(i, j);
  47. if (enemy && enemy.GetName() == 'Spawner') {
  48. spawners[spawners.length] = g_Minigame.CurrentScene().GetEnemy(i, j);
  49. }
  50. }
  51. }
  52. var lowHP = 0;
  53. var lowLane = 0;
  54. var lowTarget = 0;
  55. for (var i = 0; i < spawners.length; i++) {
  56. if(spawners[i] && !spawners[i].m_bIsDestroyed) {
  57. if(lowHP < 1 || spawners[i].m_flDisplayedHP < lowHP) {
  58. lowHP = spawners[i].m_flDisplayedHP;
  59. lowLane = spawners[i].m_nLane;
  60. lowTarget = spawners[i].m_nID;
  61. }
  62. }
  63. }
  64.  
  65. // if no spawners remain, determine which lane has a creep with the lowest health
  66. if (lowHP < 1) {
  67. // determine which living creep has the lowest hp
  68. var creeps = [];
  69. for (var i = 0; i < 3; i++) {
  70. for (var j = 0; j < 4; j++) {
  71. var enemy = g_Minigame.CurrentScene().GetEnemy(i, j);
  72. if (enemy && enemy.m_data.type == 1) {
  73. creeps[creeps.length] = g_Minigame.CurrentScene().GetEnemy(i, j);
  74. }
  75. }
  76. }
  77.  
  78. for (var i = 0; i < creeps.length; i++) {
  79. if (creeps[i] && !creeps[i].m_bIsDestroyed) {
  80. if (lowHP < 1 || creeps[i].m_flDisplayedHP < lowHP) {
  81. lowHP = creeps[i];
  82. lowLane = creeps[i].m_nLane;
  83. lowTarget = creeps[i].m_nID;
  84. }
  85. }
  86. }
  87. }
  88.  
  89. // go to the chosen lane
  90. if (g_Minigame.CurrentScene().m_nExpectedLane != lowLane) {
  91. //console.log('switching langes');
  92. g_Minigame.CurrentScene().TryChangeLane(lowLane);
  93. }
  94.  
  95. // target the chosen enemy
  96. if (g_Minigame.CurrentScene().m_nTarget != lowTarget) {
  97. //console.log('switching targets');
  98. g_Minigame.CurrentScene().TryChangeTarget(lowTarget);
  99. }
  100. }
  101.  
  102. function useMedicsIfRelevant() {
  103. // regularly check HP to try to determine max health (I haven't found the variable for it yet)
  104. if (g_Minigame.CurrentScene().m_rgPlayerData.hp > myMaxHealth) {
  105. myMaxHealth = g_Minigame.CurrentScene().m_rgPlayerData.hp
  106. }
  107.  
  108. // check if health is below 50%
  109. var hpPercent = g_Minigame.CurrentScene().m_rgPlayerData.hp / myMaxHealth;
  110. if (hpPercent > 0.5) {
  111. return; // no need to heal - HP is above 50%
  112. }
  113.  
  114. // check if Medics is purchased and cooled down
  115. if ((1 << 7) & g_Minigame.CurrentScene().m_rgPlayerTechTree.unlocked_abilities_bitfield) {
  116. // each bit in unlocked_abilities_bitfield corresponds to an ability. Medics is ability 7.
  117. // the above condition checks if the Medics bit is set or cleared. I.e. it checks if
  118. // the player has the Medics ability.
  119.  
  120. var abilitiesInCooldown = g_Minigame.CurrentScene().m_rgPlayerData.active_abilities;
  121. for (var i = 1; i < abilitiesInCooldown.length; i++) {
  122. if (abilitiesInCooldown[i].ability == 7) {
  123. return; // Medics is in cooldown, can't use it.
  124. }
  125. }
  126.  
  127. // Medics is purchased, cooled down, and needed. Trigger it.
  128. console.log('Medics is purchased, cooled down, and needed. Trigger it.');
  129. if (document.getElementById('ability_7')) {
  130. g_Minigame.CurrentScene().TryAbility(document.getElementById('ability_7').childElements()[0]);
  131. }
  132. }
  133. }
  134.  
  135. function attemptRespawn()
  136. {
  137. //Player health <0
  138. //g_Minigame.CurrentScene().m_rgPlayerData.hp<=0
  139. //Player is Dead
  140. //g_Minigame.CurrentScene().m_bIsDead
  141. //Player died over 5 seconds ago
  142. //((g_Minigame.CurrentScene().m_rgPlayerData.time_died *1000)+5000)<(new Date.getTime())
  143. if((g_Minigame.CurrentScene().m_bIsDead)&&
  144. ((g_Minigame.CurrentScene().m_rgPlayerData.time_died *1000)+5000)<(new Date.getTime()))
  145. {
  146. RespawnPlayer();
  147. }
  148. }
  149.  
  150. function clickTheThing()
  151. {
  152. g_Minigame.m_CurrentScene.DoClick(
  153. {
  154. data: {
  155. getLocalPosition: function() {
  156. var enemy = g_Minigame.m_CurrentScene.GetEnemy(
  157. g_Minigame.m_CurrentScene.m_rgPlayerData.current_lane,
  158. g_Minigame.m_CurrentScene.m_rgPlayerData.target),
  159. laneOffset = enemy.m_nLane * 440;
  160.  
  161. return {
  162. x: enemy.m_Sprite.position.x - laneOffset,
  163. y: enemy.m_Sprite.position.y - 52
  164. }
  165. }
  166. }
  167. }
  168. );
  169. }
  170.  
  171. var thingTimer = window.setInterval(doTheThing, 2000);
  172.  
  173. var clickTimer = window.setInterval(clickTheThing, 1000/clickRate);
  174.  
  175. var spawntimer = window.setInterval(RespawnPlayer, 5000);
  176.  
  177. var changetimer = window.setInterval(goToLaneWithLowest, 1500);
  178.  
  179. var healtimer = window.setInterval(useMedicsIfRelevant, 1250);
Advertisement
Add Comment
Please, Sign In to add comment