Advertisement
Guest User

Trimpz

a guest
Jan 31st, 2016
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 60.65 KB | None | 0 0
  1. /*global game,tooltip,resolvePow,getNextPrestigeCost,adjustMap,updateMapCost,addSpecials*/
  2. /*jslint plusplus: true */
  3. var openTrapsForDefault; //Open traps as default action?
  4. var trimpz = 0; //"Trimpz" running indicator
  5. var autoFighting = false; //Autofight on?
  6. var workersFocused = false;
  7. var workersFocusedOn;
  8. var workersMoved = [];
  9. var skipShieldBlock = true;
  10. var mapsWithDesiredUniqueDrops = [8,10,14,15,18,23,25,29,30,34,40,47,50,80,125]; //removed from array when done, reset on portal or refresh
  11. var uniqueMaps = ["The Block", "The Wall", "Dimension of Anger", "Trimple Of Doom", "The Prison", "Bionic Wonderland"];
  12. var minimumUpgradesOnHand = 4; //0 will run maps only when no equipment upgrades left, 10 will run maps if any equipment upgrade is missing
  13. var helium = -1;
  14. var minBreedingSpeed = 100;
  15. var heliumHistory = [];
  16. var portalAt = 155;
  17. var targetBreedTime = 30;
  18. var targetBreedTimeHysteresis = 5;
  19. var portalObtained = false;
  20. var pauseTrimpz = false;
  21. var bionicDone = false;
  22. var doElectricChallenge = false; //don't portal before 81
  23. var doCrushedChallenge = false; //don't portal before 126
  24. var doNomChallenge = true; //don't portal before 126
  25. var doToxicChallenge = false; //don't portal before 166
  26. var doRunMapsForBonus = true;
  27. var doRunMapsForEquipment = true;
  28. var numberOfDeathsAllowedToKillBoss = 3; //minimum of just under one
  29. var formationDone = false;
  30. var heliumLog = [];
  31. const CheapEquipmentRatio = 0.01;
  32. const CheapEqUpgradeRatio = 0.2;
  33.  
  34. var constantsEarlyGame = (function () {
  35. "use strict";
  36. var zoneToStartAt = 0,
  37. runInterval = 1500,
  38. minerMultiplier = 2,
  39. trainerCostRatio = 0.2,
  40. explorerCostRatio = 0.2,
  41. minFoodOwned = 15,
  42. minWoodOwned = 15,
  43. minTrimpsOwned = 10,
  44. minScienceOwned = 10,
  45. housingCostRatio = 0.3,
  46. gymCostRatio = 0.6,
  47. maxGyms = 10000,
  48. tributeCostRatio = 0.5,
  49. nurseryCostRatio = 0.5,
  50. maxLevel = 10,
  51. equipmentCostRatio = 0.5,
  52. otherWorkersFocusRatio = 0.5,
  53. numTrapsForAutoTrapping = 10000,
  54. shieldCostRatio = 1,
  55. lumberjackMultiplier = 1,
  56. maxWormholes = 0,
  57. shouldSkipHpEquipment = false,
  58. minimumWarpStations = 20,
  59. minimumEquipmentLevel = 5;
  60. return {
  61. getZoneToStartAt: function () { return zoneToStartAt; },
  62. getRunInterval: function () { return runInterval; },
  63. getTrainerCostRatio: function () { return trainerCostRatio; },
  64. getMinerMultiplier: function () { return minerMultiplier; },
  65. getExplorerCostRatio: function () { return explorerCostRatio; },
  66. getMinFoodOwned: function () { return minFoodOwned; },
  67. getMinWoodOwned: function () { return minWoodOwned; },
  68. getMinTrimpsOwned: function () { return minTrimpsOwned; },
  69. getMinScienceOwned: function () { return minScienceOwned; },
  70. getGymCostRatio: function () { return gymCostRatio; },
  71. getMaxGyms : function () { return maxGyms; },
  72. getHousingCostRatio: function () { return housingCostRatio; },
  73. getTributeCostRatio: function () { return tributeCostRatio; },
  74. getNurseryCostRatio: function () { return nurseryCostRatio; },
  75. getMaxLevel: function () {return maxLevel;},
  76. getEquipmentCostRatio: function () {return equipmentCostRatio;},
  77. getOtherWorkersFocusRatio: function () {return otherWorkersFocusRatio;},
  78. getNumTrapsForAutoTrapping: function () {return numTrapsForAutoTrapping;},
  79. getShieldCostRatio: function () {return shieldCostRatio;},
  80. getLumberjackMultiplier: function () {return lumberjackMultiplier;},
  81. getMaxWormholes: function () {return maxWormholes;},
  82. getShouldSkipHpEquipment: function () {return shouldSkipHpEquipment;},
  83. getMinimumWarpStations: function () {return minimumWarpStations;},
  84. getMinimumEquipmentLevel: function () {return minimumEquipmentLevel;}
  85. };
  86. })();
  87. var constantsLateGame = (function () {
  88. "use strict";
  89. var zoneToStartAt = 45,
  90. runInterval = 1500,
  91. minerMultiplier = 0.5,
  92. trainerCostRatio = 0.2,
  93. explorerCostRatio = 0.2,
  94. minFoodOwned = 15,
  95. minWoodOwned = 15,
  96. minTrimpsOwned = 10,
  97. minScienceOwned = 10,
  98. housingCostRatio = 0.1,
  99. gymCostRatio = 0.95,
  100. maxGyms = 170,
  101. tributeCostRatio = 0.8,
  102. nurseryCostRatio = 0.15,
  103. maxLevel = 5,
  104. equipmentCostRatio = 0.8,
  105. otherWorkersFocusRatio = 0.5,
  106. numTrapsForAutoTrapping = 10000,
  107. shieldCostRatio = 0.05,
  108. lumberjackMultiplier = 0.5,
  109. maxWormholes = 0,
  110. shouldSkipHpEquipment = false,
  111. minimumWarpStations = 20,
  112. minimumEquipmentLevel = 5;
  113. return {
  114. getZoneToStartAt: function () { return zoneToStartAt; },
  115. getRunInterval: function () { return runInterval; },
  116. getTrainerCostRatio: function () { return trainerCostRatio; },
  117. getMinerMultiplier: function () { return minerMultiplier; },
  118. getExplorerCostRatio: function () { return explorerCostRatio; },
  119. getMinFoodOwned: function () { return minFoodOwned; },
  120. getMinWoodOwned: function () { return minWoodOwned; },
  121. getMinTrimpsOwned: function () { return minTrimpsOwned; },
  122. getMinScienceOwned: function () { return minScienceOwned; },
  123. getGymCostRatio: function () { return gymCostRatio; },
  124. getMaxGyms : function () { return maxGyms; },
  125. getHousingCostRatio: function () { return housingCostRatio; },
  126. getTributeCostRatio: function () { return tributeCostRatio; },
  127. getNurseryCostRatio: function () { return nurseryCostRatio; },
  128. getMaxLevel: function () {return maxLevel;},
  129. getEquipmentCostRatio: function () {return equipmentCostRatio;},
  130. getOtherWorkersFocusRatio: function () {return otherWorkersFocusRatio;},
  131. getNumTrapsForAutoTrapping: function () {return numTrapsForAutoTrapping;},
  132. getShieldCostRatio: function () {
  133. if (skipShieldBlock === false) {
  134. return shieldCostRatio;
  135. }
  136. return 0.6;
  137. },
  138. getLumberjackMultiplier: function () {return lumberjackMultiplier;},
  139. getMaxWormholes: function () {return maxWormholes;},
  140. getShouldSkipHpEquipment: function () {return shouldSkipHpEquipment;},
  141. getMinimumWarpStations: function () {return minimumWarpStations;},
  142. getMinimumEquipmentLevel: function () {return minimumEquipmentLevel;}
  143. };
  144. })();
  145. var constantsLateLateGame = (function () {
  146. "use strict";
  147. var zoneToStartAt = 55,
  148. runInterval = 1500,
  149. minerMultiplier = 1,
  150. trainerCostRatio = 0.01,
  151. explorerCostRatio = 0.01,
  152. minFoodOwned = 15,
  153. minWoodOwned = 15,
  154. minTrimpsOwned = 10,
  155. minScienceOwned = 10,
  156. housingCostRatio = 0.05,
  157. gymCostRatio = 0.8,
  158. maxGyms = 170,
  159. tributeCostRatio = 0.9,
  160. nurseryCostRatio = 0.01,
  161. maxLevel = 4,
  162. equipmentCostRatio = 0.9,
  163. otherWorkersFocusRatio = 0.5,
  164. numTrapsForAutoTrapping = 10000,
  165. shieldCostRatio = 0.01,
  166. lumberjackMultiplier = 1,
  167. maxWormholes = 0,
  168. shouldSkipHpEquipment = true,
  169. minimumWarpStations = 20,
  170. minimumEquipmentLevel = 5;
  171. return {
  172. getZoneToStartAt: function () { //don't start until enough block since last constants should be getting gyms
  173. if (game.global.soldierCurrentBlock > 750 * 1000000000000000) { //need about 750Qa to beat 59 boss
  174. return zoneToStartAt; //enough block, begin!
  175. }
  176. return constantsEndGame.getZoneToStartAt(); //not enough block, but need to start next constants if too late
  177. },
  178. getRunInterval: function () { return runInterval; },
  179. getTrainerCostRatio: function () { return trainerCostRatio; },
  180. getMinerMultiplier: function () { return minerMultiplier; },
  181. getExplorerCostRatio: function () { return explorerCostRatio; },
  182. getMinFoodOwned: function () { return minFoodOwned; },
  183. getMinWoodOwned: function () { return minWoodOwned; },
  184. getMinTrimpsOwned: function () { return minTrimpsOwned; },
  185. getMinScienceOwned: function () { return minScienceOwned; },
  186. getGymCostRatio: function () { return gymCostRatio; },
  187. getMaxGyms : function () { return maxGyms; },
  188. getHousingCostRatio: function () { return housingCostRatio; },
  189. getTributeCostRatio: function () { return tributeCostRatio; },
  190. getNurseryCostRatio: function () { return nurseryCostRatio; },
  191. getMaxLevel: function () {return maxLevel;},
  192. getEquipmentCostRatio: function () {return equipmentCostRatio;},
  193. getOtherWorkersFocusRatio: function () {return otherWorkersFocusRatio;},
  194. getNumTrapsForAutoTrapping: function () {return numTrapsForAutoTrapping;},
  195. getShieldCostRatio: function () {
  196. if (skipShieldBlock === false) {
  197. return shieldCostRatio;
  198. }
  199. return 0.6;
  200. },
  201. getLumberjackMultiplier: function () {return lumberjackMultiplier;},
  202. getMaxWormholes: function () {return maxWormholes;},
  203. getShouldSkipHpEquipment: function () {return shouldSkipHpEquipment;},
  204. getMinimumWarpStations: function () {return minimumWarpStations;},
  205. getMinimumEquipmentLevel: function () {return minimumEquipmentLevel;}
  206. };
  207. })();
  208. var constantsEndGame = (function () {
  209. "use strict";
  210. var zoneToStartAt = 60,
  211. runInterval = 1500,
  212. minerMultiplier = 1,
  213. trainerCostRatio = 0,
  214. explorerCostRatio = 0,
  215. minFoodOwned = 15,
  216. minWoodOwned = 15,
  217. minTrimpsOwned = 10,
  218. minScienceOwned = 10,
  219. housingCostRatio = 0,
  220. gymCostRatio = 0,
  221. maxGyms = 10000,
  222. tributeCostRatio = 0.7,
  223. nurseryCostRatio = 0.20,
  224. maxLevel = 4,
  225. equipmentCostRatio = 0.9,
  226. otherWorkersFocusRatio = 0.5,
  227. numTrapsForAutoTrapping = 10000,
  228. shieldCostRatio = 0.01,
  229. lumberjackMultiplier = 0.3,
  230. maxWormholes = 0,
  231. shouldSkipHpEquipment = false,
  232. minimumWarpStations = 5,
  233. minimumEquipmentLevel = 5;
  234. return {
  235. getZoneToStartAt: function () { return zoneToStartAt; },
  236. getRunInterval: function () { return runInterval; },
  237. getTrainerCostRatio: function () { return trainerCostRatio; },
  238. getMinerMultiplier: function () { return minerMultiplier; },
  239. getExplorerCostRatio: function () { return explorerCostRatio; },
  240. getMinFoodOwned: function () { return minFoodOwned; },
  241. getMinWoodOwned: function () { return minWoodOwned; },
  242. getMinTrimpsOwned: function () { return minTrimpsOwned; },
  243. getMinScienceOwned: function () { return minScienceOwned; },
  244. getGymCostRatio: function () { return gymCostRatio; },
  245. getMaxGyms : function () { return maxGyms; },
  246. getHousingCostRatio: function () { return housingCostRatio; },
  247. getTributeCostRatio: function () { return tributeCostRatio; },
  248. getNurseryCostRatio: function () { return nurseryCostRatio; },
  249. getMaxLevel: function () {return maxLevel;},
  250. getEquipmentCostRatio: function () {return equipmentCostRatio;},
  251. getOtherWorkersFocusRatio: function () {return otherWorkersFocusRatio;},
  252. getNumTrapsForAutoTrapping: function () {return numTrapsForAutoTrapping;},
  253. getShieldCostRatio: function () {
  254. if (skipShieldBlock === false) {
  255. return shieldCostRatio;
  256. }
  257. return 0.6;
  258. },
  259. getLumberjackMultiplier: function () {
  260. if (skipShieldBlock === false) {
  261. return lumberjackMultiplier;
  262. }
  263. return 1;
  264. },
  265. getMaxWormholes: function () {return maxWormholes;},
  266. getShouldSkipHpEquipment: function () {return shouldSkipHpEquipment;},
  267. getMinimumWarpStations: function () {return minimumWarpStations;},
  268. getMinimumEquipmentLevel: function () {return minimumEquipmentLevel;}
  269. };
  270. })();
  271. var constantsSets = [constantsEarlyGame, constantsLateGame, constantsLateLateGame, constantsEndGame];
  272. var constantsIndex;
  273. var constants;
  274.  
  275. /**
  276. * @return {boolean} return.canAfford affordable respecting the ratio?
  277. */
  278. function CanBuyNonUpgrade(nonUpgradeItem, ratio) {
  279. "use strict";
  280. var aResource; //JSLint insisted I move declaration to top...
  281. var needed;
  282. for (aResource in nonUpgradeItem.cost) {
  283. needed = nonUpgradeItem.cost[aResource];
  284. if (typeof needed[1] !== 'undefined') {
  285. needed = resolvePow(needed, nonUpgradeItem);
  286. }
  287. if (typeof nonUpgradeItem.prestige !== 'undefined') {//Discount equipment
  288. needed = Math.ceil(needed * (Math.pow(1 - game.portal.Artisanistry.modifier, game.portal.Artisanistry.level)));
  289. } else if (game.portal.Resourceful.level)
  290. {
  291. needed = Math.ceil(needed * (Math.pow(1 - game.portal.Resourceful.modifier, game.portal.Resourceful.level)));
  292. }
  293. if (game.resources[aResource].owned * ratio < needed) {
  294. return false;
  295. }
  296. }
  297. return true;
  298. }
  299.  
  300. function GetNonUpgradePrice(nonUpgradeItem) {
  301. "use strict";
  302. var aResource;
  303. var needed;
  304. for (aResource in nonUpgradeItem.cost) {
  305. needed = nonUpgradeItem.cost[aResource];
  306. if (typeof needed[1] !== 'undefined') {
  307. needed = resolvePow(needed, nonUpgradeItem);
  308. }
  309. if (typeof nonUpgradeItem.prestige !== 'undefined') {//Discount equipment
  310. needed = Math.ceil(needed * (Math.pow(1 - game.portal.Artisanistry.modifier, game.portal.Artisanistry.level)));
  311. }
  312. if (aResource === "gems" && nonUpgradeItem === game.buildings.Warpstation)
  313. {
  314. return needed;
  315. }
  316. }
  317. return needed;
  318. }
  319.  
  320. /**
  321. * @return {number}
  322. */
  323. function CanBuyWorkerWithResource(job, ratio, food, extraWorkers){
  324. var cost = job.cost.food;
  325. var price = 0;
  326. if (typeof cost[1] !== 'undefined')
  327. price = Math.floor((cost[0] * Math.pow(cost[1], job.owned + extraWorkers)) * ((Math.pow(cost[1], 1) - 1) / (cost[1] - 1)));
  328. else
  329. price = cost;
  330. if ( food * ratio >= price)
  331. return price;
  332. else{
  333. return -1;
  334. }
  335. }
  336.  
  337. function getTotalTimeForBreeding(almostOwnedGeneticists) {
  338. "use strict";
  339. var trimps = game.resources.trimps;
  340. var trimpsMax = trimps.realMax();
  341. var potencyMod = trimps.potency;
  342.  
  343. //Broken Planet
  344. if (game.global.brokenPlanet) potencyMod /= 10;
  345. //Pheromones
  346. potencyMod *= 1+ (game.portal.Pheromones.level * game.portal.Pheromones.modifier);
  347. //Geneticist
  348. if (game.jobs.Geneticist.owned + almostOwnedGeneticists > 0) potencyMod *= Math.pow(.98, game.jobs.Geneticist.owned + almostOwnedGeneticists);
  349. //Quick Trimps
  350. if (game.unlocks.quickTrimps) potencyMod *= 2;
  351. if (game.global.challengeActive == "Toxicity" && game.challenges.Toxicity.stacks > 0){
  352. potencyMod *= Math.pow(game.challenges.Toxicity.stackMult, game.challenges.Toxicity.stacks);
  353. }
  354. potencyMod = (1 + (potencyMod / 10));
  355. var adjustedMax = (game.portal.Coordinated.level) ? game.portal.Coordinated.currentSend : trimps.maxSoldiers;
  356. var totalTime;
  357. if (game.options.menu.showFullBreed.enabled == 1) totalTime = log10((trimpsMax - trimps.employed) / (trimpsMax - adjustedMax - trimps.employed)) / log10(potencyMod);
  358. else {
  359. var threshold = Math.ceil((trimpsMax - trimps.employed) * 0.95);
  360. totalTime = log10(threshold / (threshold - adjustedMax)) / log10(potencyMod);
  361. }
  362. totalTime /= 10;
  363. return totalTime;
  364. }
  365.  
  366. function getRemainingTimeForBreeding() {
  367. "use strict";
  368. var trimps = game.resources.trimps;
  369. var trimpsMax = trimps.realMax();
  370. var potencyMod = trimps.potency;
  371.  
  372. //Broken Planet
  373. if (game.global.brokenPlanet) potencyMod /= 10;
  374. //Pheromones
  375. potencyMod *= 1+ (game.portal.Pheromones.level * game.portal.Pheromones.modifier);
  376. //Geneticist
  377. if (game.jobs.Geneticist.owned > 0) potencyMod *= Math.pow(.98, game.jobs.Geneticist.owned);
  378. //Quick Trimps
  379. if (game.unlocks.quickTrimps) potencyMod *= 2;
  380. if (game.global.challengeActive == "Toxicity" && game.challenges.Toxicity.stacks > 0){
  381. potencyMod *= Math.pow(game.challenges.Toxicity.stackMult, game.challenges.Toxicity.stacks);
  382. }
  383. potencyMod = (1 + (potencyMod / 10));
  384. var timeRemaining = log10((trimpsMax - trimps.employed) / (trimps.owned - trimps.employed)) / log10(potencyMod);
  385. timeRemaining /= 10;
  386. return timeRemaining;
  387. }
  388.  
  389. function AssignFreeWorkers() {
  390. "use strict";
  391. var trimps = game.resources.trimps;
  392. var food = game.resources.food.owned;
  393. var buy = {
  394. "Geneticist" : 0,
  395. "Trainer" : 0,
  396. "Explorer" : 0,
  397. "Scientist" : 0,
  398. "Miner" : 0,
  399. "Lumberjack" : 0,
  400. "Farmer" : 0
  401. };
  402. if (trimps.owned === 0 || game.global.firing) {
  403. return;
  404. }
  405. var free = (Math.ceil(trimps.realMax() / 2) - trimps.employed);
  406. if (free > 0){
  407. document.getElementById("tab1").click(); //hire 1 at a time
  408. } else
  409. {
  410. return;
  411. }
  412. var breedCount = (trimps.owned - trimps.employed > 2) ? Math.floor(trimps.owned - trimps.employed) : 0;
  413. if (free > game.resources.trimps.owned){
  414. free = Math.floor(game.resources.trimps.owned / 3);
  415. }
  416. if (autoFighting === false){
  417. if (breedCount - trimps.employed > 0){
  418. free = Math.min(free,Math.floor((breedCount - trimps.employed)/2));
  419. } else {
  420. return;
  421. }
  422. }
  423. var cost;
  424. var maxFreeForAssignOneAtATime = 1000;
  425. var totalMultipliers;
  426. var assignThisMany;
  427. while (free > 0) {
  428. if (free > maxFreeForAssignOneAtATime){
  429. totalMultipliers = constants.getMinerMultiplier() + constants.getLumberjackMultiplier() + 1; //1 for default/reference farmer
  430. assignThisMany = constants.getMinerMultiplier() / totalMultipliers * (free - maxFreeForAssignOneAtATime);
  431. buy.Miner += Math.floor(assignThisMany);
  432. assignThisMany = constants.getLumberjackMultiplier() / totalMultipliers * (free - maxFreeForAssignOneAtATime);
  433. buy.Lumberjack += Math.floor(assignThisMany);
  434. assignThisMany = free - maxFreeForAssignOneAtATime - buy.Miner - buy.Lumberjack;
  435. buy.Farmer += assignThisMany;
  436.  
  437. free = free - (buy.Miner + buy.Lumberjack + buy.Farmer);
  438. }
  439. if (game.jobs.Geneticist.locked === 0 &&
  440. game.global.challengeActive !== "Electricity" &&
  441. (cost = CanBuyWorkerWithResource(game.jobs.Geneticist, 1, food , buy.Geneticist)) !== -1 &&
  442. getTotalTimeForBreeding(buy.Geneticist) < targetBreedTime &&
  443. getRemainingTimeForBreeding() < targetBreedTime &&
  444. (game.global.lastBreedTime / 1000 < targetBreedTime - getRemainingTimeForBreeding() + targetBreedTimeHysteresis
  445. || game.resources.trimps.owned === game.resources.trimps.realMax()) ){
  446. food -= cost;
  447. buy.Geneticist += 1;
  448. free--;
  449. } else if (game.jobs.Trainer.locked === 0 &&
  450. (cost = CanBuyWorkerWithResource(game.jobs.Trainer, constants.getTrainerCostRatio(), food , buy.Trainer)) !== -1){
  451. food -= cost;
  452. buy.Trainer += 1;
  453. free--;
  454. } else if (game.jobs.Explorer.locked === 0 &&
  455. (cost = CanBuyWorkerWithResource(game.jobs.Explorer, constants.getExplorerCostRatio(), food, buy.Explorer)) !== -1){
  456. food -= cost;
  457. buy.Explorer += 1;
  458. free--;
  459. } else if (game.jobs.Scientist.locked === 0 && game.jobs.Scientist.owned + buy.Scientist < game.global.world + 1 &&
  460. (cost = CanBuyWorkerWithResource(game.jobs.Scientist, 1, food, buy.Scientist)) !== -1) {
  461. food -= cost;
  462. buy.Scientist += 1;
  463. free--;
  464. } else if (game.jobs.Miner.locked === 0 && game.jobs.Miner.owned + buy.Miner < (game.jobs.Farmer.owned + buy.Farmer) * constants.getMinerMultiplier() &&
  465. (cost = CanBuyWorkerWithResource(game.jobs.Miner, 1, food, buy.Miner)) !== -1) {
  466. food -= cost;
  467. buy.Miner += 1;
  468. free--;
  469. } else if (game.jobs.Lumberjack.locked === 0 && game.jobs.Lumberjack.owned + buy.Lumberjack < (game.jobs.Farmer.owned + buy.Farmer) * constants.getLumberjackMultiplier() &&
  470. (cost = CanBuyWorkerWithResource(game.jobs.Lumberjack, 1, food, buy.Lumberjack)) !== -1){
  471. food -= cost;
  472. buy.Lumberjack += 1;
  473. free--;
  474. } else if ((cost = CanBuyWorkerWithResource(game.jobs.Farmer, 1, food, buy.Farmer)) !== -1){
  475. food -= cost;
  476. buy.Farmer += 1;
  477. free--;
  478. } else {
  479. break; //Can't afford anything!
  480. }
  481. }
  482. var jobName;
  483. var numberToBuy;
  484. var element;
  485. for (jobName in buy){
  486. numberToBuy = buy[jobName];
  487. if (numberToBuy > 0){
  488. game.global.buyAmt = numberToBuy;
  489. element = document.getElementById(jobName);
  490. if (element !== 'undefined')
  491. element.click();
  492. }
  493. }
  494. game.global.buyAmt = 1;
  495. tooltip('hide');
  496. }
  497. function Fight() {
  498. "use strict";
  499. if (autoFighting === true && game.resources.trimps.owned > 25) { //>25 should reset autoFighting on portal
  500. return;
  501. }
  502. autoFighting = false;
  503. var pauseFightButton = document.getElementById("pauseFight");
  504. if (pauseFightButton.offsetHeight > 0 && game.resources.trimps.owned === game.resources.trimps.realMax() || game.resources.trimps.owned > 5000000) {
  505. if (pauseFightButton.innerHTML !== "AutoFight On") {
  506. pauseFightButton.click();
  507. }
  508. autoFighting = true;
  509. } else if (document.getElementById("battleContainer").style.visibility !== "hidden") {
  510. document.getElementById("fightBtn").click();
  511. }
  512. }
  513. function ShowRunningIndicator() {
  514. "use strict";
  515. var rotater = ["|", "/", "-", "\\"][trimpz];
  516. trimpz += 1;
  517. if (trimpz > 3) {
  518. trimpz = 0;
  519. }
  520. document.getElementById("trimpTitle").innerHTML = "Trimpz " + rotater;
  521. }
  522. function UpgradeStorage() {
  523. "use strict";
  524. if (game.resources.food.owned > game.buildings.Barn.cost.food()) {
  525. if (game.buildings.Barn.locked === 0) {
  526. document.getElementById("Barn").click();
  527. }
  528. }
  529. if (game.resources.wood.owned > game.buildings.Shed.cost.wood()) {
  530. if (game.buildings.Shed.locked === 0) {
  531. document.getElementById("Shed").click();
  532. }
  533. }
  534. if (game.resources.metal.owned > game.buildings.Forge.cost.metal()) {
  535. if (game.buildings.Forge.locked === 0) {
  536. document.getElementById("Forge").click();
  537. }
  538. }
  539. }
  540. function ClickAllNonEquipmentUpgrades() {
  541. "use strict";
  542. var upgrade;
  543. for (upgrade in game.upgrades) {
  544. if (upgrade === "Gigastation" && game.buildings.Warpstation.owned < constants.getMinimumWarpStations()){
  545. continue;
  546. }
  547. if (skipShieldBlock === true && upgrade === "Shieldblock"){
  548. continue;
  549. }
  550. if (typeof game.upgrades[upgrade].prestiges === 'undefined' && game.upgrades[upgrade].locked === 0) {
  551. document.getElementById(upgrade).click(); //Upgrade!
  552. }
  553. }
  554. tooltip('hide');
  555. }
  556. function FocusWorkersOn(jobToFocusOn) {
  557. "use strict";
  558. var jobObj;
  559. var workersToMove;
  560. var jobsToMoveFrom = ["Farmer", "Lumberjack", "Miner"];
  561. var fromJobButton;
  562. var job;
  563.  
  564. if (game.jobs[jobToFocusOn].locked) {
  565. return;
  566. }
  567. if (workersFocused === true && jobToFocusOn === workersFocusedOn) {
  568. return;
  569. }
  570. if (workersFocused === true){ //focused on the wrong thing!
  571. RestoreWorkerFocus();
  572. if (workersFocused === true){
  573. return;
  574. }
  575. }
  576. workersMoved = [];
  577. for (job in jobsToMoveFrom) {
  578. jobObj = game.jobs[jobsToMoveFrom[job]];
  579. if (jobObj.locked === true || jobObj.owned < 2 || jobsToMoveFrom[job] === jobToFocusOn) {
  580. continue;
  581. }
  582. workersToMove = Math.floor(jobObj.owned * constants.getOtherWorkersFocusRatio());
  583. if (game.resources.food.owned < workersToMove * game.jobs[jobToFocusOn].cost.food) {
  584. continue;
  585. }
  586. game.global.buyAmt = workersToMove;
  587. game.global.firing = true;
  588. fromJobButton = document.getElementById(jobsToMoveFrom[job]);
  589. fromJobButton.click();
  590. game.global.firing = false;
  591. document.getElementById(jobToFocusOn).click();
  592. game.global.buyAmt = 1;
  593. workersMoved.push([jobsToMoveFrom[job], workersToMove, jobToFocusOn]);
  594. }
  595. if (workersMoved.length !== 0) {
  596. workersFocused = true;
  597. workersFocusedOn = jobToFocusOn;
  598. }
  599. }
  600. function RestoreWorkerFocus() {
  601. "use strict";
  602. var workersToMove;
  603. var job;
  604. var workersLeft = 0;
  605. var jobMoved;
  606.  
  607. if (workersFocused === false){
  608. return;
  609. }
  610. for (jobMoved in workersMoved)
  611. {
  612. workersToMove = workersMoved[jobMoved][1];
  613. job = workersMoved[jobMoved][0];
  614. if (game.resources.food.owned < workersToMove * game.jobs[job].cost.food || workersToMove === 0){
  615. workersLeft += workersToMove;
  616. continue;
  617. }
  618. game.global.buyAmt = workersToMove;
  619. game.global.firing = true;
  620. document.getElementById(workersMoved[jobMoved][2]).click();
  621. game.global.firing = false;
  622. document.getElementById(job).click();
  623. game.global.buyAmt = 1;
  624. workersMoved[jobMoved][1] = 0;
  625. }
  626. if (workersLeft === 0) {
  627. workersFocused = false;
  628. workersFocusedOn = "";
  629. }
  630. }
  631. /**
  632. * @return {boolean} return.collectingForNonEquipment Is it collecting for upgrade?
  633. */
  634. function UpgradeNonEquipment() {
  635. "use strict";
  636. var upgrade;
  637. var aResource;
  638. var needed;
  639. ClickAllNonEquipmentUpgrades();
  640. for (upgrade in game.upgrades) {
  641. if (typeof game.upgrades[upgrade].prestiges === 'undefined' && game.upgrades[upgrade].locked === 0) {
  642. if (upgrade === "Gigastation" && game.buildings.Warpstation.owned < constants.getMinimumWarpStations() || CanBuyNonUpgrade(game.buildings.Warpstation, 2) === true){ //ratio 2 for "can buy soon"
  643. continue;
  644. }
  645. if (skipShieldBlock === true && upgrade === "Shieldblock"){
  646. continue;
  647. }
  648. for (aResource in game.upgrades[upgrade].cost.resources) {
  649. needed = game.upgrades[upgrade].cost.resources[aResource];
  650. if (typeof needed[1] !== 'undefined') {
  651. needed = resolvePow(needed, game.upgrades[upgrade]);
  652. }
  653. if (aResource === "food" && needed > game.resources.food.owned) {
  654. document.getElementById("foodCollectBtn").click();
  655. FocusWorkersOn("Farmer");
  656. return true;
  657. }
  658. if (aResource === "metal" && needed > game.resources.metal.owned) {
  659. document.getElementById("metalCollectBtn").click();
  660. FocusWorkersOn("Miner");
  661. return true;
  662. }
  663. if (aResource === "science" && needed > game.resources.science.owned) {
  664. document.getElementById("scienceCollectBtn").click();
  665. FocusWorkersOn("Scientist");
  666. return true;
  667. }
  668. if (aResource === "wood" && needed > game.resources.wood.owned) {
  669. document.getElementById("woodCollectBtn").click();
  670. FocusWorkersOn("Lumberjack");
  671. return true;
  672. }
  673. }
  674. document.getElementById(upgrade).click(); //Upgrade!
  675. }
  676. }
  677. RestoreWorkerFocus();
  678. return false;
  679. }
  680. /**
  681. * @return {boolean} return.collectingForNonEquipment Is it collecting for upgrade?
  682. */
  683. function UpgradeAndGather() {
  684. "use strict";
  685. var collectingForNonEquipment = UpgradeNonEquipment();
  686. if (openTrapsForDefault === true && game.buildings.Trap.owned < 10){ //traps exhausted, turn off "Trapping"
  687. openTrapsForDefault = false;
  688. }
  689. if (openTrapsForDefault === false && game.buildings.Trap.owned > constants.getNumTrapsForAutoTrapping()){ //traps overflowing, use them
  690. openTrapsForDefault = true;
  691. }
  692. if (collectingForNonEquipment === false) {
  693. //Collect trimps if breeding speed is low
  694. if ((game.resources.trimps.owned < game.resources.trimps.realMax() &&
  695. document.getElementById("trimpsPs").innerHTML.match(/\d+/)[0] < minBreedingSpeed) ||
  696. openTrapsForDefault === true) {
  697. document.getElementById("trimpsCollectBtn").click();
  698. // } else if (game.global.buildingsQueue.length > 0) {
  699. // document.getElementById("buildingsCollectBtn").click();
  700. } else { //nothing to build
  701. document.getElementById("metalCollectBtn").click();
  702. }
  703. tooltip('hide');
  704. }
  705. return collectingForNonEquipment;
  706. }
  707. /**
  708. * @return {boolean} return.shouldReturn Was priority found (stop further processing)?
  709. */
  710. function BeginPriorityAction() { //this is really just for the beginning (after a portal)
  711. "use strict";
  712. if (game.global.buildingsQueue.length > 0) {//Build queue
  713. if (document.getElementById("autoTrapBtn").innerHTML !== "Traps On" ||
  714. game.global.buildingsQueue[0] !== "Trap.1") {
  715. document.getElementById("buildingsCollectBtn").click();
  716. return true;
  717. }
  718. }
  719. if (game.resources.food.owned < constants.getMinFoodOwned()) {//Collect food
  720. document.getElementById("foodCollectBtn").click();
  721. return true;
  722. }
  723. if (game.resources.wood.owned < constants.getMinWoodOwned()) {//Collect wood
  724. document.getElementById("woodCollectBtn").click();
  725. return true;
  726. }
  727. if (game.buildings.Trap.owned < 1) {//Enqueue trap
  728. document.getElementById("Trap").click();
  729. document.getElementById("buildingsCollectBtn").click();
  730. return true;
  731. }
  732. if (game.resources.trimps.owned < constants.getMinTrimpsOwned() &&
  733. game.resources.trimps.owned < game.resources.trimps.realMax()/2) {//Open trap
  734. document.getElementById("trimpsCollectBtn").click();
  735. return true;
  736. }
  737. if (game.resources.science.owned < constants.getMinScienceOwned()) {//Collect science
  738. document.getElementById("scienceCollectBtn").click();
  739. return true;
  740. }
  741. return false;
  742. }
  743.  
  744. /**
  745. * @return {boolean}
  746. */
  747. function BuyBuilding(buildingName, ratio, max){
  748. "use strict";
  749. var useMax;
  750. if (typeof max === 'undefined'){
  751. useMax = 999999999999999999999999999999;
  752. } else {
  753. useMax = max;
  754. }
  755. var theBuilding = game.buildings[buildingName];
  756. if (theBuilding.locked === 0 && theBuilding.owned < useMax &&
  757. CanBuyNonUpgrade(theBuilding, ratio) === true) {
  758. document.getElementById(buildingName).click();
  759. return true;
  760. }
  761. return false;
  762. }
  763.  
  764. function BuyBuildings() {
  765. "use strict";
  766. BuyBuilding("Gym", constants.getGymCostRatio(), constants.getMaxGyms());
  767. BuyBuilding("Nursery", constants.getNurseryCostRatio());
  768. BuyBuilding("Tribute", constants.getTributeCostRatio());
  769. BuyBuilding("Hut", constants.getHousingCostRatio());
  770. BuyBuilding("House", constants.getHousingCostRatio());
  771. BuyBuilding("Mansion", constants.getHousingCostRatio());
  772. BuyBuilding("Hotel", constants.getHousingCostRatio());
  773. BuyBuilding("Resort", constants.getHousingCostRatio());
  774. BuyBuilding("Gateway", constants.getHousingCostRatio());
  775. BuyBuilding("Wormhole", 1, constants.getMaxWormholes());
  776. if (game.buildings.Warpstation.locked === 1 || GetNonUpgradePrice(game.buildings.Warpstation) > GetNonUpgradePrice(game.buildings.Collector) * game.buildings.Warpstation.increase.by / game.buildings.Collector.increase.by) {
  777. BuyBuilding("Collector", 1);
  778. }
  779. while (BuyBuilding("Warpstation", 1));
  780. tooltip('hide');
  781. }
  782.  
  783. function TurnOnAutoBuildTraps() {
  784. "use strict";
  785. if (document.getElementById("autoTrapBtn").getAttribute("style") !== "display: none" &&
  786. document.getElementById("autoTrapBtn").innerHTML === "Traps Off") {
  787. document.getElementById("autoTrapBtn").click();
  788. }
  789. }
  790.  
  791.  
  792. function BuyShield() {
  793. "use strict";
  794. var shieldUpgrade = game.upgrades.Supershield;
  795. if (shieldUpgrade.locked === 0 && CanAffordEquipmentUpgrade("Supershield") === true) {
  796. var costOfNextLevel = Math.ceil(getNextPrestigeCost("Supershield") * (Math.pow(1 - game.portal.Artisanistry.modifier, game.portal.Artisanistry.level)));
  797. var costOfTwoLevels = costOfNextLevel * (1 + game.equipment.Shield.cost.wood[1]);
  798. if (game.resources.wood.owned * constants.getShieldCostRatio() > costOfTwoLevels) {
  799. document.getElementById("Supershield").click(); //Upgrade!
  800. document.getElementById("Shield").click(); //Buy a level!
  801. document.getElementById("Shield").click(); //Buy another!
  802. tooltip('hide');
  803. }
  804. }
  805. var shield = game.equipment.Shield;
  806. if (shield.locked === 0 && CanBuyNonUpgrade(shield, constants.getShieldCostRatio()) === true &&
  807. shield.level < constants.getMaxLevel()) {
  808. document.getElementById("Shield").click();
  809. tooltip('hide');
  810. }
  811. }
  812. function FindBestEquipmentToLevel(debugHpToAtkRatio) {
  813. "use strict";
  814. var anEquipment;
  815. var bestEquipGainPerMetal = 0;
  816. var bestEquipment;
  817. var gainPerMetal;
  818. var cost;
  819. var currentEquip;
  820. var multiplier;
  821. for (anEquipment in game.equipment) {
  822. currentEquip = game.equipment[anEquipment];
  823. if (currentEquip.locked === 1 || anEquipment === "Shield" || (constants.getShouldSkipHpEquipment() === true && typeof currentEquip.health !== 'undefined')) {
  824. continue;
  825. }
  826. if (currentEquip.level >= constants.getMaxLevel()) {
  827. continue;
  828. }
  829. cost = GetNonUpgradePrice(currentEquip);
  830. multiplier = currentEquip.healthCalculated ? 1 / 8 : 1;
  831. gainPerMetal = (currentEquip.healthCalculated || currentEquip.attackCalculated) * multiplier / cost;
  832. debugHpToAtkRatio.push([anEquipment, gainPerMetal * 1000000]);
  833. if (gainPerMetal > bestEquipGainPerMetal) {
  834. bestEquipGainPerMetal = gainPerMetal;
  835. bestEquipment = anEquipment;
  836. }
  837. }
  838. return {
  839. bestEquipGainPerMetal: bestEquipGainPerMetal,
  840. bestEquipment: bestEquipment
  841. };
  842. }
  843. function FindBestEquipmentUpgrade(debugHpToAtkRatio) {
  844. "use strict";
  845. var gainPerMetal;
  846. var cost;
  847. var currentEquip;
  848. var multiplier;
  849. var upgrade;
  850. var currentUpgrade;
  851. var bestUpgradeGainPerMetal = 0;
  852. var bestUpgrade;
  853. var bestUpgradeCost;
  854. var stat;
  855. var gain;
  856. for (upgrade in game.upgrades) {
  857. currentUpgrade = game.upgrades[upgrade];
  858. currentEquip = game.equipment[game.upgrades[upgrade].prestiges];
  859. if (typeof currentUpgrade.prestiges !== 'undefined' && currentUpgrade.locked === 0 && upgrade !== "Supershield") {
  860. if (constants.getShouldSkipHpEquipment() === true && typeof currentEquip.health !== 'undefined') { //don't buy hp equips in late late game
  861. continue;
  862. }
  863. cost = Math.ceil(getNextPrestigeCost(upgrade) * (Math.pow(1 - game.portal.Artisanistry.modifier, game.portal.Artisanistry.level)));
  864. multiplier = currentEquip.healthCalculated ? 1 / 8 : 1;
  865. stat = (typeof currentEquip.health !== 'undefined') ? "health" : "attack";
  866. gain = Math.round(currentEquip[stat] * Math.pow(1.19, ((currentEquip.prestige) * game.global.prestige[stat]) + 1));
  867. gainPerMetal = gain * multiplier / cost;
  868. debugHpToAtkRatio.push([upgrade, gainPerMetal * 1000000]);
  869. if (gainPerMetal > bestUpgradeGainPerMetal) {
  870. bestUpgradeGainPerMetal = gainPerMetal;
  871. bestUpgrade = upgrade;
  872. bestUpgradeCost = cost;
  873. }
  874. }
  875. }
  876. return {
  877. bestUpgradeGainPerMetal: bestUpgradeGainPerMetal,
  878. bestUpgrade: bestUpgrade,
  879. bestUpgradeCost: bestUpgradeCost
  880. };
  881. }
  882. function BuyEquipmentOrUpgrade(bestEquipGainPerMetal, bestUpgradeGainPerMetal, bestEquipment, timeStr, bestUpgrade, bestUpgradeCost, debugHpToAtkRatio) {
  883. "use strict";
  884. var boughtSomething = false;
  885. if (bestEquipGainPerMetal > bestUpgradeGainPerMetal) {
  886. if (CanBuyNonUpgrade(game.equipment[bestEquipment], constants.getEquipmentCostRatio()) === true) {
  887. document.getElementById(bestEquipment).click();
  888. console.debug("Best buy " + bestEquipment + timeStr);
  889. boughtSomething = true;
  890. }
  891. } else {
  892. if (CanAffordEquipmentUpgrade(bestUpgrade) === true && bestUpgradeCost < game.resources.metal.owned * constants.getEquipmentCostRatio()) {
  893. document.getElementById(bestUpgrade).click();
  894. console.debug("Best buy " + bestUpgrade + timeStr);
  895. boughtSomething = true;
  896. }
  897. }
  898. var entry;
  899. if (boughtSomething === true) {
  900. for (entry in debugHpToAtkRatio) {
  901. console.debug(debugHpToAtkRatio[entry][0] + ":" + debugHpToAtkRatio[entry][1]);
  902. }
  903. console.debug("****End of Best Buy****");
  904. }
  905. }
  906. function BuyCheapEquipment(timeStr) {
  907. "use strict";
  908. var anEquipment;
  909. var currentEquip;
  910. for (anEquipment in game.equipment) {
  911. currentEquip = game.equipment[anEquipment];
  912. if (currentEquip.locked === 1 || anEquipment === "Shield" || (constants.getShouldSkipHpEquipment() === true && typeof currentEquip.health !== 'undefined')) {
  913. continue;
  914. }
  915. if (CanBuyNonUpgrade(game.equipment[anEquipment], CheapEquipmentRatio) === true) {
  916. document.getElementById(anEquipment).click();
  917. console.debug("Low cost buy for " + anEquipment + timeStr);
  918. }
  919. }
  920. return currentEquip;
  921. }
  922. function BuyCheapEquipmentUpgrades(timeStr) {
  923. "use strict";
  924. var currentEquip;
  925. var upgrade;
  926. var cost;
  927. var currentUpgrade;
  928. for (upgrade in game.upgrades) {
  929. currentUpgrade = game.upgrades[upgrade];
  930. currentEquip = game.equipment[game.upgrades[upgrade].prestiges];
  931. if (typeof currentUpgrade.prestiges !== 'undefined' && currentUpgrade.locked === 0 && upgrade !== "Supershield") {
  932. if (constants.getShouldSkipHpEquipment() === true && typeof currentEquip.health !== 'undefined') { //don't buy hp equips in late late game
  933. continue;
  934. }
  935. cost = Math.ceil(getNextPrestigeCost(upgrade) * (Math.pow(1 - game.portal.Artisanistry.modifier, game.portal.Artisanistry.level)));
  936. if (CanAffordEquipmentUpgrade(upgrade) === true && cost < game.resources.metal.owned * CheapEqUpgradeRatio) {
  937. document.getElementById(upgrade).click();
  938. console.debug("Low cost buy for " + upgrade + timeStr);
  939. }
  940. }
  941. }
  942. }
  943. function BuyMetalEquipment() { //ignoring max level, ignoring min level, buying cheap stuff
  944. "use strict";
  945. var debugHpToAtkRatio = [];
  946. var time = new Date();
  947. var timeStr = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
  948.  
  949. var retFBETL = FindBestEquipmentToLevel(debugHpToAtkRatio);
  950. var bestEquipGainPerMetal = retFBETL.bestEquipGainPerMetal;
  951. var bestEquipment = retFBETL.bestEquipment;
  952.  
  953. var retFBEU = FindBestEquipmentUpgrade(debugHpToAtkRatio);
  954. var bestUpgradeGainPerMetal = retFBEU.bestUpgradeGainPerMetal;
  955. var bestUpgrade = retFBEU.bestUpgrade;
  956. var bestUpgradeCost = retFBEU.bestUpgradeCost;
  957.  
  958. if (bestEquipGainPerMetal === 0 && bestUpgradeGainPerMetal === 0) { //nothing to buy
  959. return;
  960. }
  961. BuyEquipmentOrUpgrade(bestEquipGainPerMetal, bestUpgradeGainPerMetal, bestEquipment, timeStr, bestUpgrade, bestUpgradeCost, debugHpToAtkRatio);
  962. BuyCheapEquipment(timeStr);
  963. BuyCheapEquipmentUpgrades(timeStr);
  964. tooltip('hide');
  965. }
  966.  
  967. /**
  968. * @return {boolean} return.canAfford affordable upgrade?
  969. */
  970. function CanAffordEquipmentUpgrade(upgrade) {
  971. "use strict";
  972. var canBuyUpgrade = true;
  973. var aResource;
  974. var needed;
  975. for (aResource in game.upgrades[upgrade].cost.resources) {
  976. if (aResource === "metal" || aResource === "wood") {
  977. continue;
  978. }
  979. needed = game.upgrades[upgrade].cost.resources[aResource];
  980. if (typeof needed[1] !== 'undefined') {
  981. needed = resolvePow(needed, game.upgrades[upgrade]);
  982. }
  983. if (needed > game.resources[aResource].owned) {
  984. canBuyUpgrade = false;
  985. break;
  986. }
  987. }
  988. return canBuyUpgrade;
  989. }
  990.  
  991. function unprettify(splitArray) {
  992. "use strict";
  993. var suffices = [
  994. 'K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'Oc', 'No', 'Dc', 'Ud',
  995. 'Dd', 'Td', 'Qad', 'Qid', 'Sxd', 'Spd', 'Od', 'Nd', 'V', 'Uv', 'Dv',
  996. 'Tv', 'Qav', 'Qiv', 'Sxv', 'Spv', 'Ov', 'Nv', 'Tt'
  997. ];
  998. var suffixIndex = suffices.indexOf(splitArray[2]);
  999. var base = suffixIndex + 1;
  1000. var number = splitArray[1] * Math.pow(1000,base);
  1001. return number;
  1002. }
  1003.  
  1004. function getAverageOfPrettifiedString(attackString) {
  1005. "use strict";
  1006. var splitArray = attackString.split("-");
  1007. var minArray = splitArray[0].match(/(\d+(?:\.\d+)?)(\D+)/); //[1] is number, [2] is unit
  1008. var maxArray= splitArray[1].match(/(\d+(?:\.\d+)?)(\D+)/); //[1] is number, [2] is unit
  1009.  
  1010. var min;
  1011. var max;
  1012. if (minArray === null){
  1013. min = splitArray[0];
  1014. } else{
  1015. min = unprettify(minArray);
  1016. }
  1017. if (maxArray === null){
  1018. max = splitArray[0];
  1019. } else{
  1020. max = unprettify(maxArray);
  1021. }
  1022. return (max + min)/2
  1023. }
  1024.  
  1025. function getBossAttack() {
  1026. "use strict";
  1027. var cell = game.global.gridArray[99];
  1028. var baseAttack = game.global.getEnemyAttack(cell.level, cell.name);
  1029. if (game.global.challengeActive == "Toxicity"){
  1030. baseAttack *= 5;
  1031. }
  1032. var attackString = calculateDamage(baseAttack, true);
  1033. var finalAttack = getAverageOfPrettifiedString(attackString);
  1034. return finalAttack;
  1035. }
  1036.  
  1037. function getBossHealth() {
  1038. "use strict";
  1039. var cell = game.global.gridArray[99];
  1040. var health = game.global.getEnemyHealth(cell.level, cell.name);
  1041. if (game.global.challengeActive == "Toxicity"){
  1042. health *= 2;
  1043. }
  1044. return health;
  1045. }
  1046.  
  1047. function getSoldierAttack(){
  1048. "use strict";
  1049. var attackString = document.getElementById("goodGuyAttack").innerHTML;
  1050. var finalAttack = getAverageOfPrettifiedString(attackString);
  1051. return finalAttack;
  1052. }
  1053.  
  1054. function canTakeOnBoss(){
  1055. "use strict";
  1056. var bossAttack = getBossAttack();
  1057. var bossHealth = getBossHealth();
  1058. var soldierAttack = getSoldierAttack();
  1059. var soldierHealth = game.global.soldierHealthMax;
  1060.  
  1061. if (game.global.challengeActive == "Toxicity" || game.global.challengeActive == "Nom") {
  1062. bossAttack += game.global.soldierHealthMax * 0.05;
  1063. }
  1064.  
  1065. var attacksToKillBoss = bossHealth/soldierAttack;
  1066. var attacksToKillSoldiers = soldierHealth/bossAttack;
  1067. var numberOfDeaths = attacksToKillBoss/attacksToKillSoldiers;
  1068.  
  1069. if (attacksToKillSoldiers < 1)
  1070. return false;
  1071. if (numberOfDeaths > numberOfDeathsAllowedToKillBoss)
  1072. return false;
  1073.  
  1074. if (game.global.challengeActive == "Nom" && numberOfDeaths > 1){
  1075. var cbossAttack = bossAttack;
  1076. var cbossHealth = bossHealth;
  1077. var csoldierAttack = soldierAttack;
  1078. var cattacksToKillSoldiers = attacksToKillSoldiers;
  1079.  
  1080. for (var i = 0; i < numberOfDeaths; i++){
  1081. cbossHealth -= (cattacksToKillSoldiers - 1) * csoldierAttack;
  1082. cbossHealth += 0.05 * bossHealth;
  1083. if (cbossHealth <= 0){
  1084. return true;
  1085. }
  1086. cbossAttack = (cbossAttack-(game.global.soldierHealthMax * 0.05) * 1.25) + game.global.soldierHealthMax * 0.05;
  1087. cattacksToKillSoldiers = soldierHealth/cbossAttack;
  1088. if (cattacksToKillSoldiers < 1)
  1089. return false;
  1090. }
  1091. return false;
  1092. }
  1093.  
  1094. return true;
  1095. }
  1096.  
  1097.  
  1098.  
  1099. function GotoMapsScreen() {
  1100. "use strict";
  1101. if (game.global.preMapsActive === true) {
  1102. return;
  1103. }
  1104. document.getElementById("mapsBtn").click(); //mapsClicked();
  1105. if (document.getElementById("mapsBtn").innerHTML === "Abandon Soldiers"){
  1106. document.getElementById("mapsBtn").click();
  1107. }
  1108. }
  1109.  
  1110. function RunNewMap(zoneToCreate) {
  1111. "use strict";
  1112. var newMap;
  1113. var size = 9; //0-9
  1114. var difficulty = 9; //0-9
  1115. var loot = 0; //0-9
  1116. var biome = "Random";
  1117.  
  1118. GotoMapsScreen();
  1119. document.getElementById("difficultyAdvMapsRange").value = difficulty;
  1120. adjustMap('difficulty', difficulty);
  1121. document.getElementById("sizeAdvMapsRange").value = size;
  1122. adjustMap('size', size);
  1123. document.getElementById("lootAdvMapsRange").value = loot;
  1124. adjustMap('loot', loot);
  1125. document.getElementById("biomeAdvMapsSelect").value = biome;
  1126. if (typeof zoneToCreate !== 'undefined') {
  1127. document.getElementById("mapLevelInput").value = zoneToCreate;
  1128. }
  1129. var cost = updateMapCost(true);
  1130. while (cost > game.resources.fragments.owned){
  1131. if (size === 1){
  1132. difficulty--;
  1133. if (difficulty === 1) {
  1134. return; //need more fragments!
  1135. }
  1136. } else {
  1137. size--;
  1138. }
  1139. document.getElementById("sizeAdvMapsRange").value = size;
  1140. adjustMap('size', size);
  1141. document.getElementById("difficultyAdvMapsRange").value = difficulty;
  1142. adjustMap('difficulty', difficulty);
  1143. cost = updateMapCost(true);
  1144. }
  1145. document.getElementById("mapCreateBtn").click();
  1146. newMap = game.global.mapsOwnedArray[game.global.mapsOwnedArray.length - 1];
  1147. RunMap(newMap);
  1148. }
  1149.  
  1150. function RunNewMapForLoot(zoneToCreate) {
  1151. "use strict";
  1152. var newMap;
  1153. var size = 0; //0-9
  1154. var difficulty = 9; //0-9
  1155. var loot = 9; //0-9
  1156. var biome = "Mountain";
  1157.  
  1158. GotoMapsScreen();
  1159. document.getElementById("difficultyAdvMapsRange").value = difficulty;
  1160. adjustMap('difficulty', difficulty);
  1161. document.getElementById("sizeAdvMapsRange").value = size;
  1162. adjustMap('size', size);
  1163. document.getElementById("lootAdvMapsRange").value = loot;
  1164. adjustMap('loot', loot);
  1165. document.getElementById("biomeAdvMapsSelect").value = biome;
  1166. if (typeof zoneToCreate !== 'undefined') {
  1167. document.getElementById("mapLevelInput").value = zoneToCreate;
  1168. }
  1169. var cost = updateMapCost(true);
  1170. while (cost > game.resources.fragments.owned){
  1171. if (loot === 1){
  1172. difficulty--;
  1173. if (difficulty === 1) {
  1174. return; //need more fragments!
  1175. }
  1176. } else {
  1177. loot--;
  1178. }
  1179. document.getElementById("lootAdvMapsRange").value = loot;
  1180. adjustMap('loot', loot);
  1181. document.getElementById("difficultyAdvMapsRange").value = difficulty;
  1182. adjustMap('difficulty', difficulty);
  1183. cost = updateMapCost(true);
  1184. }
  1185. document.getElementById("mapCreateBtn").click();
  1186. newMap = game.global.mapsOwnedArray[game.global.mapsOwnedArray.length - 1];
  1187. RunMap(newMap);
  1188. }
  1189.  
  1190. function RunMap(map) {
  1191. "use strict";
  1192. GotoMapsScreen();
  1193. document.getElementById(map.id).click();
  1194. document.getElementById("selectMapBtn").click();
  1195. }
  1196.  
  1197. function RunWorld() {
  1198. "use strict";
  1199. document.getElementById("mapsBtn").click(); //mapsClicked();
  1200. }
  1201.  
  1202. function RunMaps() {
  1203. "use strict";
  1204. var map;
  1205. var theMap;
  1206. var itemsAvailable;
  1207.  
  1208. if (game.global.world < 7 || (game.global.mapsActive === true && game.global.preMapsActive === false)){ //no map ability(wait one) or already running a map(repeat should be off)
  1209. return;
  1210. }
  1211.  
  1212. if (game.global.preMapsActive === false)
  1213. {
  1214. if (game.resources.trimps.owned < game.resources.trimps.realMax()) {
  1215. return;
  1216. }
  1217. }
  1218.  
  1219. if (game.upgrades.Bounty.done === 0 && game.upgrades.Bounty.locked === 1) { //Look for Bounty upgrade
  1220. for (map in game.global.mapsOwnedArray) {
  1221. theMap = game.global.mapsOwnedArray[map];
  1222. if (theMap.name === "The Wall" && addSpecials(true, true, theMap) > 0){
  1223. RunMap(theMap);
  1224. return;
  1225. }
  1226. }
  1227. }
  1228.  
  1229. if (game.global.challengeActive === "Electricity" && game.global.world > 80) { //Do Prison to turn off elec challenge
  1230. for (map in game.global.mapsOwnedArray) {
  1231. theMap = game.global.mapsOwnedArray[map];
  1232. if (theMap.name === "The Prison" && addSpecials(true, true, theMap) > 0){
  1233. RunMap(theMap);
  1234. return;
  1235. }
  1236. }
  1237. }
  1238.  
  1239. if (bionicDone === false && game.global.world >= 125) { //For Bionic speed run achieve
  1240. for (map in game.global.mapsOwnedArray) {
  1241. theMap = game.global.mapsOwnedArray[map];
  1242. if (theMap.name === "Bionic Wonderland"){
  1243. bionicDone = true;
  1244. RunMap(theMap);
  1245. return;
  1246. }
  1247. }
  1248. }
  1249.  
  1250. if (doRunMapsForBonus && game.global.lastClearedCell < 98){
  1251. if (!canTakeOnBoss()){
  1252. console.debug("Can't take on Boss!");
  1253. var mapLevel = game.global.world - game.portal.Siphonology.level;
  1254. if (game.global.mapBonus < 10){
  1255. console.debug("Let's increase bonus.");
  1256. for (map in game.global.mapsOwnedArray) {
  1257. theMap = game.global.mapsOwnedArray[map];
  1258. if (theMap.level === mapLevel && theMap.size <= 40){
  1259. console.debug("Found map to increase bonus on.");
  1260. RunMap(theMap);
  1261. return;
  1262. }
  1263. }
  1264. console.debug("Need a new map to increase bonus.");
  1265. RunNewMap(mapLevel);
  1266. return;
  1267. }
  1268. if (doRunMapsForEquipment){
  1269. console.debug("Bonus maxed. Let's level equipment.");
  1270. for (map in game.global.mapsOwnedArray) {
  1271. theMap = game.global.mapsOwnedArray[map];
  1272. if (theMap.level === mapLevel && theMap.loot >= 1.40){
  1273. console.debug("Found a loot map to run for equipment.");
  1274. RunMap(theMap);
  1275. return;
  1276. }
  1277. }
  1278. console.debug("Making a new loot map.");
  1279. RunNewMapForLoot(mapLevel);
  1280. return;
  1281. }
  1282. }
  1283. }
  1284.  
  1285.  
  1286. var itemsAvailableInNewMap = addSpecials(true,true,{ id: "map999", name: "My Map", location: "Sea", clears: 0, level: game.global.world, difficulty: 1.11, size: 40, loot: 1.2, noRecycle: false });
  1287. if (game.global.preMapsActive === true && itemsAvailableInNewMap === 0){
  1288. RunWorld();
  1289. return;
  1290. }
  1291. if (itemsAvailableInNewMap === 0){
  1292. return;
  1293. }
  1294.  
  1295. var uniqueMapIndex = mapsWithDesiredUniqueDrops.indexOf(game.global.world); //Run new map if on zone with unique map drop then remove
  1296. if (uniqueMapIndex > -1 && itemsAvailableInNewMap > 0){
  1297. mapsWithDesiredUniqueDrops.splice(uniqueMapIndex,1);
  1298. RunNewMap(game.global.world);
  1299. return;
  1300. }
  1301.  
  1302. //Any equipment upgrades available?
  1303. var upgrade;
  1304. var currentUpgrade;
  1305. var currentEquip;
  1306. var totalUpgrades = 0;
  1307. for (upgrade in game.upgrades) {
  1308. currentUpgrade = game.upgrades[upgrade];
  1309. currentEquip = game.equipment[game.upgrades[upgrade].prestiges];
  1310. if (typeof currentUpgrade.prestiges !== 'undefined' && currentUpgrade.locked === 0 && upgrade !== "Supershield") {
  1311. if (constants.getShouldSkipHpEquipment() === true && typeof currentEquip.health !== 'undefined') { //don't buy hp equips in late late game
  1312. continue;
  1313. }
  1314. totalUpgrades++;
  1315. }
  1316. }
  1317.  
  1318. if (totalUpgrades < minimumUpgradesOnHand){//=== 0){ //if not equipment upgrades, go get some! (can make this a "< constant" later if desired)
  1319. //what's the lowest zone map I can create and get items?
  1320. var zoneToTry;
  1321. for (zoneToTry = 6; zoneToTry <= game.global.world; zoneToTry++){
  1322. itemsAvailableInNewMap = addSpecials(true,true,{ id: "map999", name: "My Map", location: "Sea", clears: 0, level: zoneToTry, difficulty: 1.11, size: 40, loot: 1.2, noRecycle: false });
  1323. if (itemsAvailableInNewMap > 0)
  1324. {
  1325. break;
  1326. }
  1327. }
  1328.  
  1329. for (map in game.global.mapsOwnedArray){ //look for an existing map first
  1330. theMap = game.global.mapsOwnedArray[map];
  1331. if (uniqueMaps.indexOf(theMap.name) > -1){
  1332. continue;
  1333. }
  1334. itemsAvailable = addSpecials(true,true,game.global.mapsOwnedArray[map]);
  1335. if (itemsAvailable > 0 && theMap.level === zoneToTry) {
  1336. RunMap(game.global.mapsOwnedArray[map]);
  1337. return;
  1338. }
  1339. }
  1340. RunNewMap(zoneToTry);
  1341. }
  1342. if (game.global.preMapsActive === true){
  1343. RunWorld();
  1344. return;
  1345. }
  1346. }
  1347.  
  1348.  
  1349. function ReallocateWorkers() {
  1350. "use strict";
  1351. var jobObj;
  1352. var workersToFire;
  1353. var jobsToFire = ["Farmer", "Lumberjack", "Miner"];
  1354. var jobButton;
  1355. var job;
  1356.  
  1357. workersFocused = false;
  1358. workersFocusedOn = "";
  1359. game.global.firing = true;
  1360. for (job in jobsToFire) {
  1361. jobObj = game.jobs[jobsToFire[job]];
  1362. if (jobObj.locked === true) {
  1363. continue;
  1364. }
  1365. workersToFire = Math.floor(jobObj.owned);
  1366. game.global.buyAmt = workersToFire;
  1367. jobButton = document.getElementById(jobsToFire[job]);
  1368. jobButton.click();
  1369. }
  1370. game.global.buyAmt = 1;
  1371. game.global.firing = false;
  1372. AssignFreeWorkers();
  1373. }
  1374.  
  1375. function CheckLateGame() {
  1376. "use strict";
  1377. if (game.resources.trimps.owned < 1000) {
  1378. constants = constantsSets[0];
  1379. constantsIndex = 0;
  1380. mapsWithDesiredUniqueDrops = [8,10,14,15,18,23,25,29,30,34,40,47,50,80,125];
  1381. heliumHistory = [];
  1382. formationDone = false;
  1383. autoFighting = false;
  1384. helium = -1;
  1385. portalObtained = false;
  1386. bionicDone = false;
  1387. return;
  1388. }
  1389. if (constantsIndex === constantsSets.length - 1){ //check for last element
  1390. return;
  1391. }
  1392. var nextSet = constantsIndex + 1;
  1393. if (game.global.world >= constantsSets[nextSet].getZoneToStartAt())
  1394. {
  1395. constants = constantsSets[nextSet];
  1396. constantsIndex = nextSet;
  1397. ReallocateWorkers();
  1398. }
  1399. }
  1400.  
  1401.  
  1402. function CheckHelium() {
  1403. var date;
  1404. var oldHelium;
  1405. var rate;
  1406. var totalHelium;
  1407. var totalTime;
  1408. var cumulativeRate;
  1409. if (helium === -1){
  1410. helium = game.resources.helium.owned;
  1411. heliumHistory.push([
  1412. helium,
  1413. Date.now(),
  1414. 0,
  1415. 0,
  1416. 0,
  1417. game.global.world
  1418. ])
  1419. } else if (game.resources.helium.owned < helium){ //must have spent some helium
  1420. helium = game.resources.helium.owned;
  1421. } else if (game.resources.helium.owned > helium) {
  1422. date = Date.now();
  1423. oldHelium = helium;
  1424. helium = game.resources.helium.owned;
  1425. rate = (helium - oldHelium)/((date - heliumHistory[heliumHistory.length - 1][1])/(1000*60*60));
  1426. totalTime = (date - heliumHistory[0][1])/(1000*60*60);
  1427. totalHelium = helium - heliumHistory[0][0];
  1428. cumulativeRate = totalHelium / totalTime;
  1429. heliumHistory.push([
  1430. helium,
  1431. date,
  1432. rate,
  1433. totalTime,
  1434. cumulativeRate,
  1435. game.global.world
  1436. ])
  1437. }
  1438. }
  1439.  
  1440.  
  1441. /**
  1442. * @return {boolean}
  1443. */
  1444. function CheckPortal() {
  1445. var map;
  1446. var theMap;
  1447. var itemsAvailable;
  1448. if (game.global.world >= portalAt - 2 && portalObtained === false)
  1449. {
  1450. for (map in game.global.mapsOwnedArray){
  1451. theMap = game.global.mapsOwnedArray[map];
  1452. if (theMap.name !== "Dimension of Anger"){
  1453. continue;
  1454. }
  1455. itemsAvailable = addSpecials(true,true,game.global.mapsOwnedArray[map]);
  1456. if (itemsAvailable > 0) {
  1457. portalObtained = true;
  1458. RunMap(game.global.mapsOwnedArray[map]);
  1459. }
  1460. }
  1461. }
  1462. if (game.global.world >= portalAt && game.global.challengeActive !== "Electricity") {
  1463. heliumLog.push(heliumHistory);
  1464. document.getElementById("portalBtn").click();
  1465. if (doElectricChallenge)
  1466. {
  1467. document.getElementById("challengeElectricity").click();
  1468. } else if (doCrushedChallenge)
  1469. {
  1470. document.getElementById("challengeCrushed").click();
  1471. } else if (doToxicChallenge)
  1472. {
  1473. document.getElementById("challengeToxicity").click();
  1474. } else if (doNomChallenge)
  1475. {
  1476. document.getElementById("challengeNom").click();
  1477. }
  1478. document.getElementById("activatePortalBtn").click();
  1479. document.getElementsByClassName("activatePortalBtn")[0].click();
  1480. return true;
  1481. }
  1482. return false;
  1483. }
  1484.  
  1485. function CheckFormation() {
  1486. if (game.global.world < 70 || formationDone === true)
  1487. {
  1488. return;
  1489. }
  1490. if (document.getElementById("formation2").style.display === "block")
  1491. {
  1492. document.getElementById("formation2").click();
  1493. formationDone = true;
  1494. }
  1495. }
  1496.  
  1497. function FireGeneticists() {
  1498. "use strict";
  1499. var jobButton;
  1500. var job = "Geneticist";
  1501.  
  1502. if (game.jobs.Geneticist.locked !== 0 ||
  1503. game.global.challengeActive === "Electricity" ||
  1504. game.jobs.Geneticist.owned === 0) {
  1505. return;
  1506. }
  1507.  
  1508. while(getTotalTimeForBreeding(0) >= targetBreedTime + targetBreedTimeHysteresis ||
  1509. getRemainingTimeForBreeding() >= targetBreedTime + targetBreedTimeHysteresis) {
  1510. game.global.firing = true;
  1511. game.global.buyAmt = 1;
  1512. jobButton = document.getElementById(job);
  1513. jobButton.click();
  1514. game.global.firing = false;
  1515. }
  1516. }
  1517.  
  1518. //Main
  1519. (function () {
  1520. "use strict";
  1521. CreateButtonForPausing();
  1522. var i;
  1523. for(i = 0; i < constantsSets.length; ++i){
  1524. if (game.global.world >= constantsSets[i].getZoneToStartAt()) {
  1525. constants = constantsSets[i];
  1526. constantsIndex = i;
  1527. }
  1528. }
  1529. setInterval(function () {
  1530. //Main loop code
  1531. if (pauseTrimpz === true){
  1532. return;
  1533. }
  1534. ShowRunningIndicator();
  1535. CheckLateGame();
  1536. CheckHelium();
  1537. CheckFormation();
  1538. if (CheckPortal() === true){
  1539. return;
  1540. }
  1541. TurnOnAutoBuildTraps();
  1542. AssignFreeWorkers();
  1543. FireGeneticists();
  1544. Fight();
  1545. UpgradeStorage();
  1546. var shouldReturn = BeginPriorityAction();
  1547. if (shouldReturn === true) {
  1548. tooltip('hide');
  1549. return;
  1550. }
  1551. var collectingForUpgrade = UpgradeAndGather();
  1552. if (collectingForUpgrade === false) { //allow resources to accumulate for upgrades if true
  1553. BuyBuildings();
  1554. BuyShield();
  1555. BuyMetalEquipment();
  1556. }
  1557. RunMaps();
  1558. //End Main loop code
  1559. }, constants.getRunInterval());
  1560. })();
  1561.  
  1562. function CreateButtonForPausing() {
  1563. "use strict";
  1564. var addElementsHere = document.getElementById("battleBtnsColumn");
  1565. var newDiv = document.createElement("DIV");
  1566. newDiv.className = "battleSideBtnContainer";
  1567. addElementsHere.appendChild(newDiv);
  1568.  
  1569. var newSpan = document.createElement("SPAN");
  1570. newSpan.className = "btn btn-primary fightBtn";
  1571. pauseTrimpz = false;
  1572. newSpan.innerHTML = "Running";
  1573. newSpan.onclick = function () {
  1574. pauseTrimpz = ! pauseTrimpz;
  1575. if (pauseTrimpz === true){
  1576. newSpan.innerHTML = "Paused";
  1577. } else{
  1578. newSpan.innerHTML = "Running";
  1579. }
  1580. };
  1581. newDiv.appendChild(newSpan);
  1582. return newSpan;
  1583. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement