Cozza38

Untitled

Jun 13th, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.09 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Monster Minigame AutoScript
  3. // @author /u/mouseasw for creating and maintaining the script, /u/WinneonSword for the Greasemonkey support, and every contributor on the GitHub repo for constant enhancements. /u/wchill and contributors on his repo for MSG2015-specific improvements.
  4. // @version 2.03
  5. // @namespace https://github.com/wchill/steamSummerMinigame
  6. // @description A script that runs the Steam Monster Minigame for you.
  7. // @match http://steamcommunity.com/minigame/towerattack*
  8. // @match http://steamcommunity.com//minigame/towerattack*
  9. // @grant none
  10. // @updateURL https://raw.githubusercontent.com/wchill/steamSummerMinigame/master/autoPlay.js
  11. // @downloadURL https://raw.githubusercontent.com/wchill/steamSummerMinigame/master/autoPlay.js
  12. // ==/UserScript==
  13.  
  14. // IMPORTANT: Update the @version property above to a higher number such as 1.1 and 1.2 when you update the script! Otherwise, Tamper / Greasemonkey users will not update automatically.
  15.  
  16. // OPTIONS
  17. var enableAutoClicker = true; // set to false to disable autoclicker
  18. var clickRate = 2147483647; // change to number of desired clicks per second
  19. var setClickVariable = false; // change to true to improve performance
  20.  
  21. var disableParticleEffects = true; // Set to false to keep particle effects
  22.  
  23. var disableFlinching = true; // Set to true to disable flinching animation for enemies.
  24. var disableCritText = false; // Set to true to disable the crit text.
  25. var disableText = true; // Remove all animated text. This includes damage, crits and gold gain.
  26. // This OVERRIDES all text related options.
  27.  
  28. var lockElements = true; // Set to false to allow upgrading all elements
  29. var slowStartMode = false; // Set to false to run script from beginning instead of lv11
  30.  
  31. var isAlreadyRunning = false;
  32.  
  33. var ABILITIES = {
  34. "MORALE_BOOSTER": 5,
  35. "GOOD_LUCK": 6,
  36. "MEDIC": 7,
  37. "METAL_DETECTOR": 8,
  38. "COOLDOWN": 9,
  39. "NUKE": 10,
  40. "CLUSTER_BOMB": 11,
  41. "NAPALM": 12
  42. };
  43.  
  44. var ITEMS = {
  45. "REVIVE": 13,
  46. "GOLD_RAIN": 17,
  47. "GOD_MODE": 21,
  48. "REFLECT_DAMAGE":24,
  49. "CRIT": 18,
  50. "PUMPED_UP": 19,
  51. "CRIPPLE_MONSTER": 15,
  52. "CRIPPLE_SPAWNER": 14,
  53. "MAXIMIZE_ELEMENT": 16
  54. };
  55.  
  56. var ENEMY_TYPE = {
  57. "SPAWNER":0,
  58. "CREEP":1,
  59. "BOSS":2,
  60. "MINIBOSS":3,
  61. "TREASURE":4
  62. };
  63.  
  64. var rainingGold = false; // Leave on false. Allows for abilities to be temporarily disabled while Raining Gold is active, to maximise Raining Gold's benefit.
  65.  
  66. // Save old functions for toggles.
  67. var trt_oldCrit;
  68. var trt_oldPush;
  69. var trt_critToggle = false;
  70. var trt_textToggle = false;
  71.  
  72. if (thingTimer){
  73. window.clearInterval(thingTimer);
  74. }
  75. if (clickTimer){
  76. window.clearInterval(clickTimer);
  77. }
  78. var clickTimer;
  79.  
  80. function firstRun() {
  81. // disable particle effects - this drastically reduces the game's memory leak
  82. if (disableParticleEffects) {
  83. disableParticles();
  84. }
  85.  
  86. // disable enemy flinching animation when they get hit
  87. if (disableFlinching) {
  88. stopFlinching();
  89. }
  90.  
  91. // Crit toggle.
  92. trt_oldCrit = g_Minigame.CurrentScene().DoCritEffect;
  93. if (disableCritText) {
  94. toggleCritText();
  95. }
  96.  
  97. // Text toggle.
  98. trt_oldPush = g_Minigame.m_CurrentScene.m_rgClickNumbers.push
  99. if (disableText) {
  100. toggleText();
  101. }
  102.  
  103. if(lockElements) {
  104. lockElementToSteamID();
  105. }
  106.  
  107. if(slowStartMode && g_Minigame.m_CurrentScene.m_rgGameData.level < 11) {
  108. var t = setInterval(function() {
  109. if(g_Minigame.m_CurrentScene.m_rgGameData.level >= 11) {
  110. clearInterval(t);
  111. initAutoClicker();
  112. }
  113. }, 1000);
  114. } else {
  115. initAutoClicker();
  116. }
  117.  
  118. var box = document.getElementsByClassName("leave_game_helper")[0];
  119. box.innerHTML = "Autoscript now enabled - your game ID is " + g_GameID +
  120. "<br>Autoclicker: " + (enableAutoClicker?"enabled - "+clickRate+"cps, "+(setClickVariable?"variable":"clicks"):"disabled") +
  121. "<br>Particle effects: " + (disableParticleEffects?"disabled":"enabled") +
  122. "<br>Flinching effect: " + (disableFlinching?"disabled":"enabled") +
  123. "<br>Crit effect: " + (disableCritText?"disabled":"enabled") +
  124. "<br>Text: " + (disableText?"disabled":"enabled")
  125. }
  126.  
  127. function initAutoClicker() {
  128. if(enableAutoClicker) {
  129. if(setClickVariable) {
  130. clickTimer = setInterval( function(){
  131. g_Minigame.m_CurrentScene.m_nClicks = clickRate;
  132. }, 1000);
  133. } else {
  134. clickTimer = window.setInterval(clickTheThing, 1000/clickRate);
  135. }
  136. }
  137. }
  138.  
  139. // Remove most effects from the game. Most of these are irreversible.
  140. // Currently invoked only if specifically called.
  141. function trt_destroyAllEffects() {
  142. stopFlinching();
  143. disableParticles();
  144. if (!trt_textToggle) {
  145. toggleText();
  146. }
  147. }
  148.  
  149. // Callable function to remove particles.
  150. function disableParticles() {
  151. if (g_Minigame) {
  152. g_Minigame.CurrentScene().DoClickEffect = function() {};
  153. g_Minigame.CurrentScene().SpawnEmitter = function(emitter) {
  154. emitter.emit = false;
  155. return emitter;
  156. }
  157. }
  158. }
  159.  
  160. // Callable function to stop the flinching animation.
  161. function stopFlinching() {
  162. if (CEnemy) {
  163. CEnemy.prototype.TakeDamage = function(){};
  164. }
  165. if (CEnemySpawner) {
  166. CEnemySpawner.prototype.TakeDamage = function(){};
  167. }
  168. if (CEnemyBoss) {
  169. CEnemyBoss.prototype.TakeDamage = function(){};
  170. }
  171. }
  172.  
  173. function toggleCritText() {
  174. if (!trt_critToggle) {
  175. // Replaces the entire crit display function.
  176. g_Minigame.CurrentScene().DoCritEffect = function( nDamage, x, y, additionalText ) {};
  177. trt_critToggle = true;
  178. } else {
  179. g_Minigame.CurrentScene().DoCritEffect = trt_oldCrit;
  180. trt_critToggle = false;
  181. }
  182. }
  183.  
  184.  
  185. // Toggles text on and off. We can't explicitly call disable/enable since we need to save the old function.
  186. function toggleText() {
  187. if (!trt_textToggle) {
  188. // Replaces the entire text function.
  189. g_Minigame.m_CurrentScene.m_rgClickNumbers.push = function(elem){
  190. elem.container.removeChild(elem);
  191. };
  192. trt_textToggle = true;
  193. } else {
  194. g_Minigame.m_CurrentScene.m_rgClickNumbers.push = trt_oldPush;
  195. trt_textToggle = false;
  196. }
  197. }
  198.  
  199. function doTheThing() {
  200. if (!isAlreadyRunning){
  201. isAlreadyRunning = true;
  202.  
  203. goToLaneWithBestTarget();
  204. useGoodLuckCharmIfRelevant();
  205. useMedicsIfRelevant();
  206. useMoraleBoosterIfRelevant();
  207. useClusterBombIfRelevant();
  208. useNapalmIfRelevant();
  209. useTacticalNukeIfRelevant();
  210. useCrippleSpawnerIfRelevant();
  211. if(g_Minigame.m_CurrentScene.m_rgGameData.level < 1000 || g_Minigame.m_CurrentScene.m_rgGameData.level % 200 == 0)
  212. useGoldRainIfRelevant();
  213. attemptRespawn();
  214.  
  215. if(enableAutoClicker) {
  216. g_msTickRate = 1000;
  217. }
  218. isAlreadyRunning = false;
  219. }
  220. }
  221.  
  222. function goToLaneWithBestTarget() {
  223. // We can overlook spawners if all spawners are 40% hp or higher and a creep is under 10% hp
  224. var spawnerOKThreshold = 0.4;
  225. var creepSnagThreshold = 0.1;
  226.  
  227. var targetFound = false;
  228. var lowHP = 0;
  229. var lowLane = 0;
  230. var lowTarget = 0;
  231. var lowPercentageHP = 0;
  232. var preferredLane = -1;
  233. var preferredTarget = -1;
  234.  
  235. // determine which lane and enemy is the optimal target
  236. var enemyTypePriority = [
  237. ENEMY_TYPE.TREASURE,
  238. ENEMY_TYPE.BOSS,
  239. ENEMY_TYPE.MINIBOSS,
  240. ENEMY_TYPE.SPAWNER,
  241. ENEMY_TYPE.CREEP
  242. ];
  243.  
  244. var skippingSpawner = false;
  245. var skippedSpawnerLane = 0;
  246. var skippedSpawnerTarget = 0;
  247. var targetIsTreasureOrBoss = false;
  248.  
  249. for (var k = 0; !targetFound && k < enemyTypePriority.length; k++) {
  250.  
  251. if (enemyTypePriority[k] == ENEMY_TYPE.TREASURE || enemyTypePriority[k] == ENEMY_TYPE.BOSS){
  252. targetIsTreasureOrBoss = true;
  253. } else {
  254. targetIsTreasureOrBoss = false;
  255. }
  256.  
  257. var enemies = [];
  258.  
  259. // gather all the enemies of the specified type.
  260. for (var i = 0; i < 3; i++) {
  261. for (var j = 0; j < 4; j++) {
  262. var enemy = g_Minigame.CurrentScene().GetEnemy(i, j);
  263. if (enemy && enemy.m_data.type == enemyTypePriority[k]) {
  264. enemies[enemies.length] = enemy;
  265. }
  266. }
  267. }
  268.  
  269. //Prefer lane with raining gold, unless current enemy target is a treasure or boss.
  270. if(lowTarget != ENEMY_TYPE.TREASURE && lowTarget != ENEMY_TYPE.BOSS ){
  271. var potential = 0;
  272. rainingGold = false;
  273. for(var i = 0; i < g_Minigame.CurrentScene().m_rgGameData.lanes.length; i++){
  274. // ignore if lane is empty
  275. if(g_Minigame.CurrentScene().m_rgGameData.lanes[i].dps == 0)
  276. continue;
  277. var stacks = 0;
  278. if(typeof g_Minigame.m_CurrentScene.m_rgLaneData[i].abilities[17] != 'undefined')
  279. stacks = g_Minigame.m_CurrentScene.m_rgLaneData[i].abilities[17];
  280. rainingGold = true;
  281. //console.log('stacks: ' + stacks);
  282. for(var m = 0; m < g_Minigame.m_CurrentScene.m_rgEnemies.length; m++) {
  283. var enemyGold = g_Minigame.m_CurrentScene.m_rgEnemies[m].m_data.gold;
  284. if (stacks * enemyGold > potential) {
  285. potential = stacks * enemyGold;
  286. preferredTarget = g_Minigame.m_CurrentScene.m_rgEnemies[m].m_nID;
  287. preferredLane = i;
  288. }
  289. }
  290. }
  291. }
  292.  
  293. // target the enemy of the specified type with the lowest hp
  294. var mostHPDone = 0;
  295. for (var i = 0; i < enemies.length; i++) {
  296. if (enemies[i] && !enemies[i].m_bIsDestroyed) {
  297. // Only select enemy and lane if the preferedLane matches the potential enemy lane
  298. if(lowHP < 1 || enemies[i].m_flDisplayedHP < lowHP) {
  299. var element = g_Minigame.CurrentScene().m_rgGameData.lanes[enemies[i].m_nLane].element;
  300.  
  301. var dmg = g_Minigame.CurrentScene().CalculateDamage(
  302. g_Minigame.CurrentScene().m_rgPlayerTechTree.dps,
  303. element
  304. );
  305. if(mostHPDone >= dmg){
  306. continue;
  307. }
  308. mostHPDone = dmg;
  309.  
  310. targetFound = true;
  311. lowHP = enemies[i].m_flDisplayedHP;
  312. lowLane = enemies[i].m_nLane;
  313. lowTarget = enemies[i].m_nID;
  314. }
  315. var percentageHP = enemies[i].m_flDisplayedHP / enemies[i].m_data.max_hp;
  316. if (lowPercentageHP == 0 || percentageHP < lowPercentageHP) {
  317. lowPercentageHP = percentageHP;
  318. }
  319. }
  320. }
  321.  
  322. if(preferredLane != -1 && preferredTarget != -1){
  323. lowLane = preferredLane;
  324. lowTarget = preferredTarget;
  325. console.log('Switching to a lane with best raining gold benefit');
  326. }
  327.  
  328. // If we just finished looking at spawners,
  329. // AND none of them were below our threshold,
  330. // remember them and look for low creeps (so don't quit now)
  331. // Don't skip spawner if lane has raining gold
  332. if ((enemyTypePriority[k] == ENEMY_TYPE.SPAWNER && lowPercentageHP > spawnerOKThreshold) && preferredLane == -1) {
  333. skippedSpawnerLane = lowLane;
  334. skippedSpawnerTarget = lowTarget;
  335. skippingSpawner = true;
  336. targetFound = false;
  337. }
  338.  
  339. // If we skipped a spawner and just finished looking at creeps,
  340. // AND the lowest was above our snag threshold,
  341. // just go back to the spawner!
  342. if (skippingSpawner && enemyTypePriority[k] == ENEMY_TYPE.CREEP && lowPercentageHP > creepSnagThreshold ) {
  343. lowLane = skippedSpawnerLane;
  344. lowTarget = skippedSpawnerTarget;
  345. }
  346. }
  347.  
  348.  
  349. // go to the chosen lane
  350. if (targetFound) {
  351. if (g_Minigame.CurrentScene().m_nExpectedLane != lowLane) {
  352. //console.log('switching lanes');
  353. g_Minigame.CurrentScene().TryChangeLane(lowLane);
  354. }
  355.  
  356. // target the chosen enemy
  357. if (g_Minigame.CurrentScene().m_nTarget != lowTarget) {
  358. //console.log('switching targets');
  359. g_Minigame.CurrentScene().TryChangeTarget(lowTarget);
  360. }
  361.  
  362.  
  363. // Prevent attack abilities and items if up against a boss or treasure minion, or Raining Gold is active.
  364. if ((targetIsTreasureOrBoss) || (rainingGold == true)) {
  365. // Morale
  366. disableAbility(ABILITIES.MORALE_BOOSTER);
  367. // Luck
  368. disableAbility(ABILITIES.GOOD_LUCK);
  369. // Nuke
  370. disableAbility(ABILITIES.NUKE);
  371. // Clusterbomb
  372. disableAbility(ABILITIES.CLUSTER_BOMB);
  373. // Napalm
  374. disableAbility(ABILITIES.NAPALM);
  375. // Crit
  376. disableAbilityItem(ITEMS.CRIT);
  377. // Cripple Spawner
  378. disableAbilityItem(ITEMS.CRIPPLE_SPAWNER);
  379. // Cripple Monster
  380. disableAbilityItem(ITEMS.CRIPPLE_MONSTER);
  381. // Max Elemental Damage
  382. disableAbilityItem(ITEMS.MAXIMIZE_ELEMENT);
  383. // Reflect Damage
  384. disableAbilityItem(ITEMS.REFLECT_DAMAGE);
  385. } else {
  386. // Morale
  387. enableAbility(ABILITIES.MORALE_BOOSTER);
  388. // Luck
  389. enableAbility(ABILITIES.GOOD_LUCK);
  390. // Nuke
  391. enableAbility(ABILITIES.NUKE);
  392. // Clusterbomb
  393. enableAbility(ABILITIES.CLUSTER_BOMB);
  394. // Napalm
  395. enableAbility(ABILITIES.NAPALM);
  396. // Crit
  397. enableAbilityItem(ITEMS.CRIT);
  398. // Cripple Spawner
  399. enableAbilityItem(ITEMS.CRIPPLE_SPAWNER);
  400. // Cripple Monster
  401. enableAbilityItem(ITEMS.CRIPPLE_MONSTER);
  402. // Max Elemental Damage
  403. enableAbilityItem(ITEMS.MAXIMIZE_ELEMENT);
  404. // Reflect Damage
  405. enableAbilityItem(ITEMS.REFLECT_DAMAGE);
  406. }
  407. }
  408. }
  409.  
  410. function usePumpedUp(){
  411. if (hasItem(ITEMS.PUMPED_UP) && !isAbilityCoolingDown(ITEMS.PUMPED_UP)){
  412. // Crits is purchased, cooled down, and needed. Trigger it.
  413. console.log('Pumped up is always good.');
  414. triggerAbility(ITEMS.PUMPED_UP);
  415. return;
  416. }
  417. };
  418.  
  419. function useMedicsIfRelevant() {
  420. usePumpedUp();
  421. var myMaxHealth = g_Minigame.CurrentScene().m_rgPlayerTechTree.max_hp;
  422.  
  423. // check if health is below 50%
  424. var hpPercent = g_Minigame.CurrentScene().m_rgPlayerData.hp / myMaxHealth;
  425. if (hpPercent > 0.5 || g_Minigame.CurrentScene().m_rgPlayerData.hp < 1) {
  426. return; // no need to heal - HP is above 50% or already dead
  427. }
  428.  
  429. // check if Medics is purchased and cooled down
  430. if (hasPurchasedAbility(ABILITIES.MEDIC) && !isAbilityCoolingDown(ABILITIES.MEDIC)) {
  431.  
  432. // Medics is purchased, cooled down, and needed. Trigger it.
  433. console.log('Medics is purchased, cooled down, and needed. Trigger it.');
  434. triggerAbility(ABILITIES.MEDIC);
  435. } else if (hasItem(ITEMS.GOD_MODE) && !isAbilityCoolingDown(ITEMS.GOD_MODE)) {
  436.  
  437. console.log('We have god mode, cooled down, and needed. Trigger it.');
  438. triggerItem(ITEMS.GOD_MODE);
  439. }
  440. };
  441.  
  442. // Use Good Luck Charm if doable
  443. function useGoodLuckCharmIfRelevant() {
  444.  
  445. // check if Crits is purchased and cooled down
  446. if (hasItem(ITEMS.CRIT) && !isAbilityCoolingDown(ITEMS.CRIT)){
  447. if (! isAbilityItemEnabled(ITEMS.CRIT)) {
  448. return;
  449. }
  450. // Crits is purchased, cooled down, and needed. Trigger it.
  451. console.log('Crit chance is always good.');
  452. triggerAbility(ITEMS.CRIT);
  453. return;
  454. }
  455.  
  456. // check if Good Luck Charms is purchased and cooled down
  457. if (hasPurchasedAbility(ABILITIES.GOOD_LUCK)) {
  458. if (isAbilityCoolingDown(ABILITIES.GOOD_LUCK)) {
  459. return;
  460. }
  461.  
  462. if (! isAbilityEnabled(ABILITIES.GOOD_LUCK)) {
  463. return;
  464. }
  465.  
  466. // Good Luck Charms is purchased, cooled down, and needed. Trigger it.
  467. console.log('Good Luck Charms is purchased, cooled down, and needed. Trigger it.');
  468. triggerAbility(ABILITIES.GOOD_LUCK);
  469. }
  470. }
  471.  
  472. function useClusterBombIfRelevant() {
  473. //Check if Cluster Bomb is purchased and cooled down
  474. if (hasPurchasedAbility(ABILITIES.CLUSTER_BOMB)) {
  475. if (isAbilityCoolingDown(ABILITIES.CLUSTER_BOMB)) {
  476. return;
  477. }
  478.  
  479. //Check lane has monsters to explode
  480. var currentLane = g_Minigame.CurrentScene().m_nExpectedLane;
  481. var enemyCount = 0;
  482. var enemySpawnerExists = false;
  483. //Count each slot in lane
  484. for (var i = 0; i < 4; i++) {
  485. var enemy = g_Minigame.CurrentScene().GetEnemy(currentLane, i);
  486. if (enemy) {
  487. enemyCount++;
  488. if (enemy.m_data.type == 0) {
  489. enemySpawnerExists = true;
  490. }
  491. }
  492. }
  493. //Bombs away if spawner and 2+ other monsters
  494. if (enemySpawnerExists && enemyCount >= 3) {
  495. triggerAbility(ABILITIES.CLUSTER_BOMB);
  496. }
  497. }
  498. }
  499.  
  500. function useNapalmIfRelevant() {
  501. //Check if Napalm is purchased and cooled down
  502. if (hasPurchasedAbility(ABILITIES.NAPALM)) {
  503. if (isAbilityCoolingDown(ABILITIES.NAPALM)) {
  504. return;
  505. }
  506.  
  507. //Check lane has monsters to burn
  508. var currentLane = g_Minigame.CurrentScene().m_nExpectedLane;
  509. var enemyCount = 0;
  510. var enemySpawnerExists = false;
  511. //Count each slot in lane
  512. for (var i = 0; i < 4; i++) {
  513. var enemy = g_Minigame.CurrentScene().GetEnemy(currentLane, i);
  514. if (enemy) {
  515. enemyCount++;
  516. if (enemy.m_data.type == 0) {
  517. enemySpawnerExists = true;
  518. }
  519. }
  520. }
  521. //Burn them all if spawner and 2+ other monsters
  522. if (enemySpawnerExists && enemyCount >= 3) {
  523. triggerAbility(ABILITIES.NAPALM);
  524. }
  525. }
  526. }
  527.  
  528. function useMoraleBoosterIfRelevant() {
  529. // Check if Morale Booster is purchased
  530. if(hasPurchasedAbility(5)) {
  531. if (isAbilityCoolingDown(5)) {
  532. return;
  533. }
  534.  
  535. //Check lane has monsters so the hype isn't wasted
  536. var currentLane = g_Minigame.CurrentScene().m_nExpectedLane;
  537. var enemyCount = 0;
  538. var enemySpawnerExists = false;
  539. //Count each slot in lane
  540. for (var i = 0; i < 4; i++) {
  541. var enemy = g_Minigame.CurrentScene().GetEnemy(currentLane, i);
  542. if (enemy) {
  543. enemyCount++;
  544. if (enemy.m_data.type == 0) {
  545. enemySpawnerExists = true;
  546. }
  547. }
  548. }
  549. //Hype everybody up!
  550. if (enemySpawnerExists && enemyCount >= 3) {
  551. triggerAbility(5);
  552. }
  553. }
  554. }
  555.  
  556. // Use Moral Booster if doable
  557. function useMoraleBoosterIfRelevant() {
  558. // check if Good Luck Charms is purchased and cooled down
  559. if (hasPurchasedAbility(5)) {
  560. if (isAbilityCoolingDown(5)) {
  561. return;
  562. }
  563. var numberOfWorthwhileEnemies = 0;
  564. for(i = 0; i < g_Minigame.CurrentScene().m_rgGameData.lanes[g_Minigame.CurrentScene().m_nExpectedLane].enemies.length; i++){
  565. //Worthwhile enemy is when an enamy has a current hp value of at least 1,000,000
  566. if(g_Minigame.CurrentScene().m_rgGameData.lanes[g_Minigame.CurrentScene().m_nExpectedLane].enemies[i].hp > 1000000)
  567. numberOfWorthwhileEnemies++;
  568. }
  569. if(numberOfWorthwhileEnemies >= 2){
  570. // Moral Booster is purchased, cooled down, and needed. Trigger it.
  571. console.log('Moral Booster is purchased, cooled down, and needed. Trigger it.');
  572. triggerAbility(5);
  573. }
  574. }
  575. }
  576.  
  577. function useTacticalNukeIfRelevant() {
  578. // Check if Tactical Nuke is purchased
  579. if(hasPurchasedAbility(ABILITIES.NUKE)) {
  580. if (isAbilityCoolingDown(ABILITIES.NUKE)) {
  581. return;
  582. }
  583. //Check that the lane has a spawner and record it's health percentage
  584. var currentLane = g_Minigame.CurrentScene().m_nExpectedLane;
  585. var enemySpawnerExists = false;
  586. var enemySpawnerHealthPercent = 0.0;
  587. //Count each slot in lane
  588. for (var i = 0; i < 4; i++) {
  589. var enemy = g_Minigame.CurrentScene().GetEnemy(currentLane, i);
  590. if (enemy) {
  591. if (enemy.m_data.type == 0 || (enemy.m_data.type == ENEMY_TYPE.BOSS && g_Minigame.m_CurrentScene.m_rgGameData.level > 1000 && g_Minigame.m_CurrentScene.m_rgGameData.level % 200 != 0)) {
  592. enemySpawnerExists = true;
  593. enemySpawnerHealthPercent = enemy.m_flDisplayedHP / enemy.m_data.max_hp;
  594. }
  595. }
  596. }
  597.  
  598. // If there is a spawner and it's health is between 60% and 30%, nuke it!
  599. if (enemySpawnerExists && enemySpawnerHealthPercent < 0.6 && enemySpawnerHealthPercent > 0.3) {
  600. console.log("Tactical Nuke is purchased, cooled down, and needed. Nuke 'em.");
  601. triggerAbility(ABILITIES.NUKE);
  602. }
  603. }
  604. }
  605.  
  606. function useCrippleSpawnerIfRelevant() {
  607. // Check if Cripple Spawner is available
  608. if(hasItem(ITEMS.CRIPPLE_SPAWNER)) {
  609. if (isAbilityCoolingDown(ITEMS.CRIPPLE_SPAWNER)) {
  610. return;
  611. }
  612.  
  613. //Check that the lane has a spawner and record it's health percentage
  614. var currentLane = g_Minigame.CurrentScene().m_nExpectedLane;
  615. var enemySpawnerExists = false;
  616. var enemySpawnerHealthPercent = 0.0;
  617. //Count each slot in lane
  618. for (var i = 0; i < 4; i++) {
  619. var enemy = g_Minigame.CurrentScene().GetEnemy(currentLane, i);
  620. if (enemy) {
  621. if (enemy.m_data.type == 0) {
  622. enemySpawnerExists = true;
  623. enemySpawnerHealthPercent = enemy.m_flDisplayedHP / enemy.m_data.max_hp;
  624. }
  625. }
  626. }
  627.  
  628. // If there is a spawner and it's health is above 95%, cripple it!
  629. if (enemySpawnerExists && enemySpawnerHealthPercent > 0.95) {
  630. console.log("Cripple Spawner available, and needed. Cripple 'em.");
  631. triggerItem(ITEMS.CRIPPLE_SPAWNER);
  632. }
  633. }
  634. }
  635.  
  636. function useGoldRainIfRelevant() {
  637. // Check if gold rain is purchased
  638. if (hasItem(ITEMS.GOLD_RAIN)) {
  639. if (isAbilityCoolingDown(ITEMS.GOLD_RAIN)) {
  640. return;
  641. }
  642.  
  643. var enemy = g_Minigame.m_CurrentScene.GetEnemy(g_Minigame.m_CurrentScene.m_rgPlayerData.current_lane, g_Minigame.m_CurrentScene.m_rgPlayerData.target);
  644. // check if current target is a boss, otherwise its not worth using the gold rain
  645. if (enemy && enemy.m_data.type == ENEMY_TYPE.BOSS && g_Minigame.m_CurrentScene.m_rgGameData.level % 100 == 0) {
  646. var enemyBossHealthPercent = enemy.m_flDisplayedHP / enemy.m_data.max_hp;
  647.  
  648. if (enemyBossHealthPercent >= 0.6) { // We want sufficient time for the gold rain to be applicable
  649. // Gold Rain is purchased, cooled down, and needed. Trigger it.
  650. console.log('Gold rain is purchased and cooled down, Triggering it on boss');
  651. triggerItem(ITEMS.GOLD_RAIN);
  652. }
  653. }
  654. }
  655. }
  656.  
  657. //If player is dead, call respawn method
  658. function attemptRespawn() {
  659. if ((g_Minigame.CurrentScene().m_bIsDead) &&
  660. ((g_Minigame.CurrentScene().m_rgPlayerData.time_died) + 5) < (g_Minigame.CurrentScene().m_nTime)) {
  661. RespawnPlayer();
  662. }
  663. }
  664.  
  665. function isAbilityActive(abilityId) {
  666. return g_Minigame.CurrentScene().bIsAbilityActive(abilityId);
  667. }
  668.  
  669. function hasItem(itemId) {
  670. return $J('#abilityitem_' + itemId).is(':visible');
  671. }
  672.  
  673. function isAbilityCoolingDown(abilityId) {
  674. return g_Minigame.CurrentScene().GetCooldownForAbility(abilityId) > 0;
  675. }
  676.  
  677. function hasOneUseAbility(abilityId) {
  678. var elem = document.getElementById('abilityitem_' + abilityId);
  679. return elem != null;
  680. }
  681.  
  682. function hasPurchasedAbility(abilityId) {
  683. // each bit in unlocked_abilities_bitfield corresponds to an ability.
  684. // the above condition checks if the ability's bit is set or cleared. I.e. it checks if
  685. // the player has purchased the specified ability.
  686. return (1 << abilityId) & g_Minigame.CurrentScene().m_rgPlayerTechTree.unlocked_abilities_bitfield;
  687. }
  688.  
  689. function triggerItem(itemId) {
  690. triggerAbility(itemId);
  691. }
  692.  
  693. function triggerAbility(abilityId) {
  694. g_Minigame.CurrentScene().m_rgAbilityQueue.push({'ability': abilityId})
  695. }
  696.  
  697. function toggleAbilityVisibility(abilityId, show) {
  698. var vis = show === true ? "visible" : "hidden";
  699.  
  700. var elem = document.getElementById('ability_' + abilityId);
  701. if (elem && elem.childElements() && elem.childElements().length >= 1) {
  702. elem.childElements()[0].style.visibility = vis;
  703. }
  704. }
  705.  
  706. function disableAbility(abilityId) {
  707. toggleAbilityVisibility(abilityId, false);
  708. }
  709.  
  710. function enableAbility(abilityId) {
  711. toggleAbilityVisibility(abilityId, true);
  712. }
  713.  
  714. function isAbilityEnabled(abilityId) {
  715. var elem = document.getElementById('ability_' + abilityId);
  716. if (elem && elem.childElements() && elem.childElements().length >= 1) {
  717. return elem.childElements()[0].style.visibility == "visible";
  718. }
  719. return false;
  720. }
  721.  
  722. function toggleAbilityItemVisibility(abilityId, show) {
  723. var vis = show === true ? "visible" : "hidden";
  724.  
  725. var elem = document.getElementById('abilityitem_' + abilityId);
  726. if (elem && elem.childElements() && elem.childElements().length >= 1) {
  727. elem.childElements()[0].style.visibility = vis;
  728. }
  729. }
  730.  
  731. function disableAbilityItem(abilityId) {
  732. toggleAbilityItemVisibility(abilityId, false);
  733. }
  734.  
  735. function enableAbilityItem(abilityId) {
  736. toggleAbilityItemVisibility(abilityId, true);
  737. }
  738.  
  739. function isAbilityItemEnabled(abilityId) {
  740. var elem = document.getElementById('abilityitem_' + abilityId);
  741. if (elem && elem.childElements() && elem.childElements().length >= 1) {
  742. return elem.childElements()[0].style.visibility == "visible";
  743. }
  744. return false;
  745. }
  746.  
  747. function lockElementToSteamID() {
  748. String.prototype.hashCode=function(){
  749. var t=0;
  750. if(0==this.length)
  751. return t;
  752. for(i=0;i<this.length;i++)
  753. char=this.charCodeAt(i),t=(t<<5)-t+char,t&=t;
  754. return t;
  755. }
  756. var elem = Math.abs(g_steamID.hashCode()%4);
  757. var fire = document.querySelector("a.link.element_upgrade_btn[data-type=\"3\"]")
  758. var water = document.querySelector("a.link.element_upgrade_btn[data-type=\"4\"]")
  759. var earth = document.querySelector("a.link.element_upgrade_btn[data-type=\"6\"]")
  760. var air = document.querySelector("a.link.element_upgrade_btn[data-type=\"5\"]")
  761. var elems = [fire, water, earth, air];
  762. for(i=0; i< elems.length; i++) {
  763. if(i == elem) {
  764. continue;
  765. }
  766. elems[i].style.visibility = "hidden";
  767. console.log('hidden');
  768. }
  769. }
  770.  
  771. var thingTimer = window.setInterval(function(){
  772. if (g_Minigame && g_Minigame.CurrentScene().m_bRunning && g_Minigame.CurrentScene().m_rgPlayerTechTree) {
  773. window.clearInterval(thingTimer);
  774. firstRun();
  775. thingTimer = window.setInterval(doTheThing, 100);
  776. }
  777. }, 1000);
  778. function clickTheThing() {
  779. g_Minigame.m_CurrentScene.DoClick(
  780. {
  781. data: {
  782. getLocalPosition: function() {
  783. var enemy = g_Minigame.m_CurrentScene.GetEnemy(
  784. g_Minigame.m_CurrentScene.m_rgPlayerData.current_lane,
  785. g_Minigame.m_CurrentScene.m_rgPlayerData.target),
  786. laneOffset = enemy.m_nLane * 440;
  787.  
  788. return {
  789. x: enemy.m_Sprite.position.x - laneOffset,
  790. y: enemy.m_Sprite.position.y - 52
  791. }
  792. }
  793. }
  794. }
  795. );
  796. }
Advertisement
Add Comment
Please, Sign In to add comment