Trimps tools

Trimps tools (visual)

目前为 2017-06-23 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Trimps tools
  3. // @namespace trimps.github.io
  4. // @version 1.245
  5. // @description Trimps tools (visual)
  6. // @author Anton
  7. // @match https://trimps.github.io
  8. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. var tAutoBuy, tStyleFix, tPassiveWatcher, $ = jQuery, isStarted = false,
  15. version = typeof GM_info == 'function' ? GM_info().script.version :
  16. (typeof GM_info == 'object' ? GM_info.script.version : '?');
  17.  
  18. var _isPortal = function () {
  19. return portalWindowOpen;
  20. };
  21.  
  22. var _getJobPrice = function (jobName, resource) {
  23. return game.jobs[jobName].cost[resource][0] * Math.pow(game.jobs[jobName].cost[resource][1], game.jobs[jobName].owned);
  24. };
  25.  
  26. var _hasFormation = function(what) {
  27. if (!game.global.preMapsActive && !game.global.lockTooltip) {
  28. if (game.upgrades.Formations.done && what === 0) return true;
  29. if (game.upgrades.Formations.done && what == 1) return true;
  30. if (game.upgrades.Dominance.done && what == 2) return true;
  31. if (game.upgrades.Barrier.done && what == 3) return true;
  32. if (game.upgrades.Formations.done && game.global.highestLevelCleared >= 180 && what == 4) return true;
  33. }
  34. return false;
  35. };
  36.  
  37. var _getEnemyAttack = function() {
  38. var cellNum, cell;
  39. if (game.global.mapsActive) {
  40. cellNum = game.global.lastClearedMapCell + 1;
  41. cell = game.global.mapGridArray[cellNum];
  42. } else {
  43. cellNum = game.global.lastClearedCell + 1;
  44. cell = game.global.gridArray[cellNum];
  45. }
  46. return calculateDamage(cell.attack, false, false, false, cell);
  47. };
  48.  
  49. var _middleGameStrategy = function() {
  50. if (game.global.world < 60) return;
  51.  
  52. if (game.global.formation === 0) {
  53. if (_hasFormation(1)) setFormation('1');
  54. }
  55.  
  56. var enemy = _getEnemyAttack();
  57. var me = game.global.soldierCurrentBlock + game.global.soldierHealthMax;
  58. if (enemy >= me && game.global.formation != 1) {
  59. if (_hasFormation(1)) setFormation('1');
  60. }
  61.  
  62. if (game.global.formation != 2 && _hasFormation(2)) {
  63. var formation2health = game.global.soldierHealthMax / 8;
  64. var me2 = formation2health + game.global.soldierCurrentBlock;
  65. if (me2 > enemy) {
  66. setFormation('2');
  67. }
  68. }
  69. };
  70.  
  71. var _log = function (mes, type) {
  72. if (typeof type === 'undefined') type = "Story";
  73. message("BOT: " + mes, type);
  74. };
  75.  
  76. var _getBreedingBaseSpeed = function () {
  77. if (game.global.challengeActive == "Trapper") return 0;
  78. var base = 0.0085;
  79. var currentCalc = _getBreeding() * base;
  80. if (game.upgrades.Potency.done > 0) {
  81. currentCalc *= Math.pow(1.1, game.upgrades.Potency.done);
  82. }
  83. return currentCalc;
  84. };
  85.  
  86. var _autoEquipment = function () {
  87. var maxEquipLevel = game.global.challengeActive=='Frugal' ? 10000 : 7;
  88. for (var x in game.equipment) {
  89. if (game.equipment.hasOwnProperty(x) && game.equipment[x].locked === 0) {
  90. var maxLevel = game.equipment[x].prestige > maxEquipLevel ? 1 : (maxEquipLevel + 1 - game.equipment[x].prestige) * 2;
  91. if (game.equipment[x].level < maxLevel && canAffordBuilding(x, null, null, true)) {
  92. buyEquipment(x, true, true);
  93. _log('Upgrading equipment ' + x);
  94. }
  95. }
  96. }
  97. };
  98.  
  99. var _getMinimumBreeding = function () {
  100. if (game.resources.trimps.maxSoldiers < 5) return 5; else return game.resources.trimps.maxSoldiers + 1;
  101. };
  102.  
  103. var _buyStorage = function () {
  104. var packratLevel = (1 + game.portal.Packrat.level * (game.portal.Packrat.modifier * 100) / 100);
  105. var buildingsForResources = {
  106. food: "Barn",
  107. wood: "Shed",
  108. metal: "Forge"
  109. };
  110.  
  111. for (var res in buildingsForResources) {
  112. if (buildingsForResources.hasOwnProperty(res)) {
  113. var bldName = buildingsForResources[res];
  114. if (game.resources[res].owned / (game.resources[res].max * packratLevel) >= 0.8) {
  115. if (canAffordBuilding(bldName, false, false, false, true)) {
  116. buyBuilding(bldName, true, true);
  117. _log('Building ' + bldName);
  118. }
  119. }
  120. }
  121. }
  122. };
  123.  
  124. var _hasInQueue = function (item) {
  125. for (var x in game.global.buildingsQueue) {
  126. var queueItem = game.global.buildingsQueue[x].split('.')[0];
  127. if (queueItem == item) {
  128. return true;
  129. }
  130. }
  131. return false;
  132. };
  133.  
  134. var _getBreeding = function () {
  135. var trimps = game.resources.trimps;
  136. return game.global.challengeActive == "Trapper" ? 0 : trimps.owned - trimps.employed;
  137. };
  138.  
  139. var _earlyGameStrategy = function () {
  140. if (_isPortal()) return;
  141.  
  142. var playerStrength = getPlayerModifier();
  143. var minimumSpeedToHelp = 1 + playerStrength;
  144.  
  145. if (game.global.eggLoc != -1) {
  146. _log('Destroying Easter Egg');
  147. easterEggClicked();
  148. }
  149.  
  150. _buyStorage();
  151. _autoJobs();
  152.  
  153. var breeding = _getBreeding();
  154. var unemployed = Math.ceil(game.resources.trimps.realMax() / 2) - game.resources.trimps.employed;
  155.  
  156. if (game.buildings.Trap.owned >= 1 && game.resources.trimps.owned < game.resources.trimps.realMax() &&
  157. (breeding < _getMinimumBreeding() || unemployed > 0) &&
  158. _getBreedingBaseSpeed() < 1) {
  159. setGather('trimps');
  160. return;
  161. }
  162.  
  163. var canGetScience = game.global.challengeActive != "Scientist";
  164.  
  165. var hasTrap = _hasInQueue('Trap');
  166. var cnt = game.global.challengeActive == "Trapper" ? 100 : (breeding < unemployed ? 25 : 1);
  167. if (!hasTrap && game.buildings.Trap.owned < 1 && game.resources.food.owned >= 10 && game.resources.wood.owned >= 10) {
  168. buyBuilding('Trap', true, true, cnt);
  169. return;
  170. }
  171.  
  172. if ((game.global.buildingsQueue.length > 0 && game.global.autoCraftModifier < 1) || (game.global.buildingsQueue.length > 5)) {
  173. setGather('buildings');
  174. return;
  175. }
  176.  
  177. if (getPsString('food', true) < minimumSpeedToHelp && game.resources.food.owned < 10) {
  178. setGather('food');
  179. return;
  180. }
  181.  
  182. if (getPsString('wood', true) < minimumSpeedToHelp && game.resources.wood.owned < 10) {
  183. setGather('wood');
  184. return;
  185. }
  186.  
  187. if (canGetScience && getPsString('science', true) < minimumSpeedToHelp && game.resources.science.owned < 10) {
  188. setGather('science');
  189. return;
  190. }
  191.  
  192. if (getPsString('metal', true) < minimumSpeedToHelp && game.resources.metal.owned < 100) {
  193. setGather('metal');
  194. return;
  195. }
  196.  
  197. var needScientist = game.upgrades.Scientists.done === 0 && game.upgrades.Scientists.allowed === 1;
  198. if (canGetScience && getPsString('science', true) < minimumSpeedToHelp && (game.resources.science.owned < 60 || needScientist)) {
  199. setGather('science');
  200. return;
  201. }
  202.  
  203. if ((game.global.playerGathering == 'trimps' && (game.buildings.Trap.owned === 0 || _getBreedingBaseSpeed() > 1)) ||
  204. (game.global.playerGathering == 'buildings' && game.global.buildingsQueue.length === 0)) {
  205. _selectAutoJob();
  206. }
  207. };
  208.  
  209. var _selectAutoJob = function () {
  210. var canGetScience = game.global.challengeActive != "Scientist";
  211. var upgradePrice = _getMaximumResourceUpgradePrice();
  212. var scienceNeeded = _getUpgradePriceSumForRes('science');
  213. if (scienceNeeded > game.resources.science.owned && canGetScience) {
  214. setGather('science');
  215. } else {
  216. if (upgradePrice !== false) {
  217. for (var x in upgradePrice) {
  218. if (upgradePrice.hasOwnProperty(x)) {
  219. if (x == 'wood' || x == 'metal' || x == 'science' || x == 'food') {
  220. setGather(x);
  221. } else {
  222. if (canGetScience) {
  223. setGather('science');
  224. } else {
  225. setGather('food');
  226. }
  227. }
  228. break;
  229. }
  230. }
  231. } else {
  232. if (canGetScience) {
  233. setGather('science');
  234. } else {
  235. setGather('food');
  236. }
  237. }
  238. }
  239. };
  240.  
  241. var _passiveWatcher = function () {
  242. if (_isPortal()) return;
  243.  
  244. _earlyGameStrategy();
  245.  
  246. var canAfford = canAffordBuilding("Tribute", false, false, false, true);
  247. if (canAfford && game.buildings.Tribute.locked !== 1) {
  248. buyBuilding("Tribute", true, true);
  249. _log('Building ' + "Tribute");
  250. }
  251.  
  252. canAfford = canAffordBuilding("Gym", false, false, false, true);
  253. if (canAfford && game.buildings.Gym.locked !== 1) {
  254. buyBuilding("Gym", true, true);
  255. _log('Building ' + "Gym");
  256. }
  257.  
  258. _middleGameStrategy();
  259. };
  260.  
  261. var _needAttackCurrentMap = function () {
  262. return (typeof game.mapsAttacked[game.global.world] === 'undefined');
  263. };
  264.  
  265. var _hasMapOfCurrentLevel = function () {
  266. for (var x in game.global.mapsOwnedArray) {
  267. if (game.global.mapsOwnedArray.hasOwnProperty(x)) {
  268. var mapObj = game.global.mapsOwnedArray[x];
  269. if (mapObj.level == game.global.world) return true;
  270. }
  271. }
  272. return false;
  273. };
  274.  
  275. var _mapAttackStrategy = function () {
  276. var x, mapObj;
  277. var breeding = _getBreeding();
  278.  
  279. if (game.global.world < 6) return;
  280. if (game.global.preMapsActive) return;
  281. //if (!game.global.mapsUnlocked) return;
  282. if (game.global.pauseFight) {
  283. _log('Enabling auto attack!');
  284. fightManual();
  285. game.global.pauseFight = false;
  286. pauseFight(true); // update only
  287. } else {
  288. if (_needAttackCurrentMap()) {
  289. document.getElementById("mapLevelInput").value = game.global.world;
  290. var currentMapPrice = updateMapCost(true);
  291. var money = game.resources.fragments.owned;
  292. if (!_hasMapOfCurrentLevel()) {
  293. if (money >= currentMapPrice) {
  294. var result = buyMap();
  295. if (result == 1) {
  296. _log('Bought new map level ' + game.global.world);
  297. } else {
  298. console.log('Buy map result = ' + result);
  299. }
  300. } else {
  301. console.log('No fragments (' + money + ') to buy map for ' + currentMapPrice);
  302. }
  303. }
  304.  
  305. if (_hasMapOfCurrentLevel()) {
  306. game.global.lookingAtMap = '';
  307. for (x in game.global.mapsOwnedArray) {
  308. if (game.global.mapsOwnedArray.hasOwnProperty(x)) {
  309. mapObj = game.global.mapsOwnedArray[x];
  310. if (mapObj.level == game.global.world) {
  311. game.global.lookingAtMap = mapObj.id;
  312. break;
  313. }
  314. }
  315. }
  316.  
  317. if (game.global.lookingAtMap !== '') {
  318. _log('Attacking map ' + game.global.lookingAtMap);
  319. game.options.menu.alwaysAbandon.enabled = 1; // GO TO MAPS!
  320. mapsClicked(true);
  321. game.mapsAttacked[game.global.world] = true;
  322. game.global.repeatMap = true; // REPEAT
  323. repeatClicked(true);
  324. runMap();
  325. if (breeding < (_getMinimumBreeding() + 1)) fightManual();
  326. } else {
  327. console.log('where is my map?');
  328. }
  329. } else {
  330. console.log('no map of current level ' + game.global.world);
  331. }
  332. } else {
  333. if (_hasMapOfCurrentLevel() && game.global.currentMapId === '') {
  334. game.global.lookingAtMap = '';
  335. var map_id, map_name = '';
  336. for (x in game.global.mapsOwnedArray) {
  337. if (game.global.mapsOwnedArray.hasOwnProperty(x)) {
  338. mapObj = game.global.mapsOwnedArray[x];
  339. if (mapObj.level <= game.global.world && mapObj.noRecycle === true && mapObj.clears === 0) {
  340. game.global.lookingAtMap = mapObj.id;
  341. map_id = x;
  342. map_name = mapObj.name;
  343. break;
  344. }
  345. }
  346. }
  347. if (game.global.lookingAtMap !== '' && typeof map_id !== 'undefined') {
  348. _log('Attacking prestige map ' + map_name + ' level (' + game.global.mapsOwnedArray[map_id].level + ')');
  349. game.options.menu.alwaysAbandon.enabled = 1; // GO TO MAPS!
  350. mapsClicked(true);
  351. game.global.repeatMap = true; // REPEAT
  352. repeatClicked(true);
  353. game.global.mapsOwnedArray[map_id].clears = 1;
  354. runMap();
  355. if (breeding < (_getMinimumBreeding() + 1)) fightManual();
  356. }
  357. } else {
  358. if (game.global.currentMapId !== '') {
  359. var lastMapCell = game.global.mapGridArray[game.global.mapGridArray.length - 1];
  360. var specialGift = '';
  361. if (lastMapCell.special !== '') {
  362. specialGift = game.mapUnlocks[lastMapCell.special];
  363. }
  364. var needExitMap = (specialGift === '' || specialGift.prestige !== true) &&
  365. lastMapCell.special !== 'Heirloom' &&
  366. lastMapCell.name !== 'Warden' &&
  367. lastMapCell.name !== 'Robotrimp' &&
  368. specialGift.canRunOnce !== true;
  369. if (needExitMap) {
  370. mapsClicked(true); // go to maps
  371. recycleMap(-1, true);
  372. mapsClicked(); // go to world
  373. }
  374. }
  375. }
  376. }
  377. }
  378. };
  379.  
  380. var _mapDeleter = function() {
  381. if (game.global.currentMapId === '') {
  382. for (var x in game.global.mapsOwnedArray) {
  383. var map = game.global.mapsOwnedArray[x];
  384. if (map.level < (game.global.world - 10) && map.noRecycle !== true) {
  385. game.global.lookingAtMap = map['id'];
  386. _log('Deleting map ' + map.name + ' (' + map.level + ')');
  387. recycleMap(-1, true);
  388. break;
  389. }
  390. }
  391. }
  392. };
  393.  
  394. var _auto = function () {
  395. if (_isPortal()) return;
  396. _earlyGameStrategy();
  397.  
  398. _autoUpgrade();
  399. _autoBuy();
  400. _autoEquipment();
  401. _mapAttackStrategy();
  402.  
  403. _middleGameStrategy();
  404.  
  405. _mapDeleter();
  406. };
  407.  
  408. var _onStartButton = function () {
  409. if (isStarted) {
  410. _stop();
  411. _log('Stop.');
  412. isStarted = false;
  413. } else {
  414. _start();
  415. _log('Started!');
  416. isStarted = true;
  417. }
  418. };
  419.  
  420. var _autoUpgrade = function () {
  421. for (var item in game.upgrades) {
  422. if (game.upgrades.hasOwnProperty(item)) {
  423. var upgrade = game.upgrades[item];
  424. if (upgrade.locked == 1) continue;
  425. var canAfford = canAffordTwoLevel(upgrade);
  426. if (canAfford) {
  427. if (item == "Coordination") {
  428. if (!canAffordCoordinationTrimps()) continue;
  429. }
  430. if (item == "Gigastation") {
  431. var minAddon = Math.floor(game.global.highestLevelCleared / 6);
  432. var minWaprstation = Math.floor(game.global.world / 6) + minAddon + game.upgrades.Gigastation.done * 2;
  433. if (minWaprstation < 6 + minAddon) minWaprstation = 6 + minAddon;
  434. if (game.buildings.Warpstation.owned < minWaprstation) continue;
  435. }
  436. buyUpgrade(item, true, true);
  437. _log('Upgrading ' + item);
  438. _selectAutoJob();
  439. return 1;
  440. }
  441. }
  442. }
  443. return 0;
  444. };
  445.  
  446. var getUpgradePrice = function (upgradeObject) {
  447. var price, result = {};
  448. for (var cost in upgradeObject.cost) {
  449. if (upgradeObject.cost.hasOwnProperty(cost)) {
  450. if (typeof upgradeObject.cost[cost] === 'object' && typeof upgradeObject.cost[cost][1] === 'undefined') {
  451. var costItem = upgradeObject.cost[cost];
  452. for (var item in costItem) {
  453. if (costItem.hasOwnProperty(item)) {
  454. price = costItem[item];
  455. if (upgradeObject.prestiges && (item == "metal" || item == "wood")) {
  456. if (game.global.challengeActive == "Daily" && typeof game.global.dailyChallenge.metallicThumb !== 'undefined') {
  457. price *= dailyModifiers.metallicThumb.getMult(game.global.dailyChallenge.metallicThumb.strength);
  458. }
  459. price *= Math.pow(1 - game.portal.Artisanistry.modifier, game.portal.Artisanistry.level);
  460. }
  461. if (typeof price === 'function') price = price();
  462. if (typeof price[1] !== 'undefined') price = resolvePow(price, upgradeObject);
  463. result[item] = price;
  464. }
  465. }
  466. }
  467. }
  468. }
  469. return result;
  470. };
  471.  
  472. var _getAllUpgradePrice = function () {
  473. var totalPrice = {};
  474. for (var item in game.upgrades) {
  475. if (game.upgrades.hasOwnProperty(item)) {
  476. var upgrade = game.upgrades[item];
  477. if (upgrade.locked == 1) continue;
  478. var price = getUpgradePrice(upgrade);
  479. for (var res in price) {
  480. if (price.hasOwnProperty(res)) {
  481. if (typeof totalPrice[res] === 'undefined') totalPrice[res] = 0;
  482. totalPrice[res] += price[res];
  483. }
  484. }
  485. }
  486. }
  487. return totalPrice;
  488. };
  489.  
  490. var _getUpgradePriceSumForRes = function (res) {
  491. var totalPrice = _getAllUpgradePrice();
  492. if (typeof totalPrice[res] !== 'undefined') {
  493. return totalPrice[res];
  494. } else {
  495. return 0;
  496. }
  497. };
  498.  
  499. var _getMaximumResourceUpgradePrice = function () {
  500. var totalPrice = _getAllUpgradePrice(), maxPriceName = '', maxPrice = 0;
  501. for (var res in totalPrice) {
  502. if (totalPrice.hasOwnProperty(res)) {
  503. if (totalPrice[res] > maxPrice) {
  504. maxPrice = totalPrice[res];
  505. maxPriceName = res;
  506. }
  507. }
  508. }
  509. var result = {};
  510. if (maxPriceName !== '') {
  511. result[maxPriceName] = maxPrice;
  512. return result;
  513. } else {
  514. return false;
  515. }
  516. };
  517.  
  518. var _autoBuy = function () {
  519. var toBuy;
  520. for (var item in game.buildings) {
  521. if (item == 'Barn' || item == 'Shed' || item == 'Forge' || item == 'Wormhole' || item == 'Trap') continue;
  522. if (!game.buildings.Collector.locked &&
  523. (item == 'Mansion' || item == 'Hotel' || item == 'Resort' || item == 'House' || item == 'Hut')) continue;
  524. if (game.upgrades.Gigastation.done >= 10 && item == 'Collector') continue;
  525.  
  526. if (game.buildings.hasOwnProperty(item)) {
  527. if (game.buildings[item].locked == 1) continue;
  528. var canAfford = canAffordBuilding(item, false, false, false, true);
  529. if (canAfford) {
  530. if (item == 'Nursery') {
  531. var isElectro = game.global.challengeActive == "Electricity";
  532. var mult = game.global.brokenPlanet ? (game.global.world >= 80 ? 2 : 1.5) : 1;
  533.  
  534. if (!isElectro && (game.buildings.Nursery.owned >= (game.buildings.Tribute.owned * mult) ||
  535. game.buildings.Nursery.owned >= (game.buildings.Gym.owned * mult)))
  536. {
  537. continue;
  538. } else {
  539. if (!_hasInQueue('Nursery')) {
  540. toBuy = item;
  541. } else {
  542. continue;
  543. }
  544. }
  545. } else {
  546. toBuy = item;
  547. }
  548. }
  549. }
  550. }
  551. if (typeof toBuy !== 'undefined') {
  552. buyBuilding(toBuy, true, true);
  553. _log('Building ' + toBuy);
  554. return 1;
  555. } else {
  556. return 0;
  557. }
  558. };
  559.  
  560. var needFarmer = 25, needLumber = 25, needMiner = 25, needScientist = 1;
  561. var needAllMax = needFarmer + needLumber + needMiner + needScientist;
  562.  
  563. var _buyJobs = function ($obj, unemployed, objName, jobId) {
  564. if ($obj.length > 0) {
  565. var breeding = _getBreeding();
  566. var cnt = 1;
  567. var minBreeding = _getMinimumBreeding();
  568. if (unemployed > needAllMax * 1000000000 && (breeding - 10000000000 > minBreeding)) {
  569. game.global.buyAmt = 10000000000;
  570. cnt = 10000000000;
  571. }
  572. else if (unemployed > needAllMax * 100000000 && (breeding - 1000000000 > minBreeding)) {
  573. game.global.buyAmt = 1000000000;
  574. cnt = 1000000000;
  575. }
  576. else if (unemployed > needAllMax * 10000000 && (breeding - 100000000 > minBreeding)) {
  577. game.global.buyAmt = 100000000;
  578. cnt = 100000000;
  579. }
  580. else if (unemployed > needAllMax * 1000000 && (breeding - 10000000 > minBreeding)) {
  581. game.global.buyAmt = 10000000;
  582. cnt = 10000000;
  583. }
  584. else if (unemployed > needAllMax * 100000 && (breeding - 1000000 > minBreeding)) {
  585. game.global.buyAmt = 1000000;
  586. cnt = 1000000;
  587. }
  588. else if (unemployed > needAllMax * 10000 && (breeding - 100000 > minBreeding)) {
  589. game.global.buyAmt = 100000;
  590. cnt = 100000;
  591. }
  592. else if (unemployed > needAllMax * 1000 && (breeding - 10000 > minBreeding)) {
  593. game.global.buyAmt = 10000;
  594. cnt = 10000;
  595. }
  596. else if (unemployed > needAllMax * 100 && (breeding - 1000 > minBreeding)) {
  597. game.global.buyAmt = 1000;
  598. cnt = 1000;
  599. }
  600. else if (unemployed > needAllMax * 10 && (breeding - 100 > minBreeding)) {
  601. numTab(4);
  602. cnt = 100;
  603. }
  604. else if (unemployed > needAllMax * 2.5 && (breeding - 25 > minBreeding)) {
  605. numTab(3);
  606. cnt = 25;
  607. }
  608. else if (unemployed > needAllMax && (breeding - 10 > minBreeding)) {
  609. numTab(2);
  610. cnt = 10;
  611. }
  612. else {
  613. numTab(1);
  614. cnt = 1;
  615. }
  616. buyJob(jobId, true, true); // confirmed, noTip
  617. numTab(1); // +1
  618. _log('New ' + objName + (cnt > 1 ? " x" + cnt : ''), 'Combat');
  619. return cnt;
  620. } else {
  621. return 0;
  622. }
  623. };
  624.  
  625. var _autoJobs = function () {
  626. var trimps = game.resources.trimps;
  627. var breeding = trimps.owned - trimps.employed;
  628. if (breeding < (_getMinimumBreeding() + 1) && game.global.challengeActive !== 'Trapper') return;
  629.  
  630. var jobsTotal =
  631. game.jobs.Farmer.owned +
  632. game.jobs.Lumberjack.owned +
  633. game.jobs.Miner.owned +
  634. game.jobs.Scientist.owned;
  635.  
  636. var unemployed = Math.ceil(game.resources.trimps.realMax() / 2) - game.resources.trimps.employed;
  637.  
  638. var trainerCost = _getJobPrice('Trainer', 'food');
  639. if ((trainerCost < game.resources.food.owned) && unemployed <= 0 && game.jobs.Farmer.owned > 1 && game.jobs.Trainer.locked === 0) {
  640. _log('Fire farmer, sorry');
  641. game.global.firing = true;
  642. buyJob('Farmer', true, true);
  643. game.global.firing = false;
  644. }
  645.  
  646. if (unemployed <= 0) return;
  647.  
  648. if (trainerCost <= game.resources.food.owned && game.jobs.Trainer.locked === 0) {
  649. buyJob('Trainer', true, true);
  650. _log('New trainer');
  651. return 1;
  652. }
  653.  
  654. var cnt = 0;
  655. var $jobsBlock = $('#jobsHere');
  656.  
  657. var $explorer = $jobsBlock.find('.thingColorCanAfford[id=Explorer]');
  658. if ($explorer.length > 0) {
  659. buyJob('Explorer', true, true);
  660. _log('New explorer');
  661. return ++cnt;
  662. }
  663.  
  664. var hasFarmer = game.jobs.Farmer.locked === 0;
  665. var hasLumber = game.jobs.Lumberjack.locked === 0;
  666. var hasMiner = game.jobs.Miner.locked === 0;
  667. var hasScientist = game.jobs.Scientist.locked === 0;
  668. var needAll =
  669. (hasFarmer ? needFarmer : 0) +
  670. (hasLumber ? needLumber : 0) +
  671. (hasMiner ? needMiner : 0) +
  672. (hasScientist ? needScientist : 0);
  673. if (needAll < 1) needAll = 1;
  674.  
  675. var minOwned = Math.min(
  676. game.jobs.Farmer.owned,
  677. game.jobs.Lumberjack.owned,
  678. game.jobs.Miner.owned);
  679. if (minOwned > 30) minOwned = 30; // for science
  680.  
  681. var $science = $jobsBlock.find('.thingColorCanAfford[id=Scientist]');
  682. var $farmer = $jobsBlock.find('.thingColorCanAfford[id=Farmer]');
  683.  
  684. if (hasScientist && game.jobs.Scientist.owned < minOwned) {
  685. cnt += _buyJobs($science, unemployed, 'scientist', 'Scientist');
  686. } else if (hasFarmer && game.jobs.Farmer.owned < (jobsTotal * needFarmer / needAll)) {
  687. cnt += _buyJobs($farmer, unemployed, 'farmer', 'Farmer');
  688. } else if (hasLumber && game.jobs.Lumberjack.owned < (jobsTotal * needLumber / needAll)) {
  689. var $lumber = $jobsBlock.find('.thingColorCanAfford[id=Lumberjack]');
  690. cnt += _buyJobs($lumber, unemployed, 'lumberjack', 'Lumberjack');
  691. } else if (hasMiner && game.jobs.Miner.owned < (jobsTotal * needMiner / needAll)) {
  692. var $miner = $jobsBlock.find('.thingColorCanAfford[id=Miner]');
  693. cnt += _buyJobs($miner, unemployed, 'miner', 'Miner');
  694. } else if (hasScientist && game.jobs.Scientist.owned < (jobsTotal * needScientist / needAll)) {
  695. cnt += _buyJobs($science, unemployed, 'scientist', 'Scientist');
  696. }
  697.  
  698. if (unemployed > 0 && cnt === 0) {
  699. cnt += _buyJobs($farmer, unemployed, 'farmer', 'Farmer');
  700. }
  701.  
  702. return cnt;
  703. };
  704.  
  705. var _styleUpdate = function () {
  706. // remove counts
  707. //noinspection CssUnusedSymbol
  708. $('head').append($("<style type=\"text/css\">\n" +
  709. "span.thingName{font-size:85%;}\n"+
  710. ".queueItem,.btn{padding:0}\n" +
  711. ".thingColorCanNotAfford.upgradeThing{background-color:#530053;}\n" +
  712. "#battleSideTitle{padding:0}\n" +
  713. ".battleSideBtnContainer{margin-top:0;}\n" +
  714. "#logBtnGroup{display:none}\n" +
  715. "#log{height:100%;}\n" +
  716. ".glyphicon-apple{color:orangered;}\n" +
  717. ".glyphicon-tree-deciduous{color:limegreen;}\n"+
  718. ".icomoon.icon-cubes{color:silver;}\n"+
  719. ".icomoon.icon-diamond{color:white;\n"+
  720. "#buildingsTitleDiv,#upgradesTitleDiv,#equipmentTitleDiv{display:none}\n"+
  721. "#buildingsQueue{height:30px}\n"+
  722. "#buyHere .alert.badge{display:none}\n"+
  723. '</style>'));
  724.  
  725. // remove tabs
  726. $('#buyTabs').hide();
  727. filterTabs('all');
  728. // fix height
  729. $('#topRow,#queueContainer').css('margin-bottom', '0');
  730. $('#jobsTitleDiv').css('padding', '0').css('font-size', 'smaller');
  731. $('#buyHere').css('margin', '0').css('padding', '0').css('overflow-x', 'hidden');
  732. $('#queueContainer').css('height', '70px');
  733. $('#numTabs').css('margin', '0');
  734. $('#buyContainer').css('height', 'calc(99vh - 20vw - 96px)');
  735. // add button
  736. $('#settingsTable').find('tr').append('<td class="btn btn-info" id="botStart" title="' + version + '">Bot start</td>');
  737. $('#botStart').click(_onStartButton);
  738. // add grid
  739. var $grid = $('<table style="width:100%;margin-top:4px;font-size:smaller;"><tr>' +
  740. '<td id="magnimp-cell"><span class="glyphicon glyphicon-magnet"></span><label style="margin-left:4px" title="Magimp">...</label></td>' +
  741. '<td id="venimp-cell"><span class="glyphicon glyphicon-glass"></span><label style="margin-left:4px" title="Venimp">...</label></td>' +
  742. '</tr><tr>' +
  743. '<td id="whipimp-cell"><span class="glyphicon glyphicon-star"></span><label style="margin-left:4px" title="Whipimp">...</label></td>' +
  744. '<td id="titimp-cell"><span class="icomoon icon-hammer"></span><label style="margin-left:4px" title="Titimp">' + prettify(game.global.titimpLeft) + '</label></td>' +
  745. '</tr></table>');
  746. $('#battleBtnsColumn').append($grid);
  747. _updateSuperTrimps();
  748. };
  749.  
  750. var _styleFix = function () {
  751. _disableLog();
  752.  
  753. var $buyBoxThings = $('.buyBox').find('.thing');
  754. $buyBoxThings.find('br').remove();
  755. $buyBoxThings.find('.thingOwned').css('margin-left', '4px');
  756.  
  757. /*for (var x in game.upgrades) {
  758. if (game.upgrades.hasOwnProperty(x)) {
  759. if (game.upgrades[x].alert && game.upgrades[x].locked === 0) game.upgrades[x].alert = false;
  760. }
  761. }
  762. for (x in game.buildings) {
  763. if (game.buildings.hasOwnProperty(x)) {
  764. if (game.buildings[x].alert && game.buildings[x].locked === 0) game.buildings[x].alert = false;
  765. }
  766. }
  767. for (x in game.jobs) {
  768. if (game.jobs.hasOwnProperty(x)) {
  769. if (game.jobs[x].alert && game.jobs[x].locked === 0) game.jobs[x].alert = false;
  770. }
  771. }*/
  772.  
  773. if (typeof game.passedMaps === 'undefined') game.passedMaps = {};
  774. if (typeof game.mapsAttacked === 'undefined') game.mapsAttacked = {};
  775.  
  776. for (var x in game.passedMaps) if (x > game.global.world) {
  777. // Game restart?
  778. game.passedMaps = {};
  779. game.mapsAttacked = {};
  780. $('#venimp-cell').find('label').text('...');
  781. $('#magnimp-cell').find('label').text('...');
  782. $('#whipimp-cell').find('label').text('...');
  783. break;
  784. }
  785.  
  786. var hasItem = false;
  787. if (typeof game.mapUnlocks === 'undefined') {
  788. clearInterval(tStyleFix);
  789. tStyleFix = setInterval(_styleFix, 2000);
  790. } else {
  791. for (x in game.mapUnlocks) {
  792. if (game.mapUnlocks.hasOwnProperty(x)) {
  793. var notPass = game.mapUnlocks[x].startAt <= game.global.world && (typeof game.passedMaps[game.mapUnlocks[x].startAt] === 'undefined' || game.passedMaps[game.mapUnlocks[x].startAt] < 1);
  794. if (notPass) {
  795. $('#battleSideTitle').css('background-color', notPass ? '#A00' : '#600');
  796. hasItem = true;
  797. break;
  798. }
  799. }
  800. }
  801. }
  802. if (!hasItem) {
  803. $('#battleSideTitle').css('background-color', 'transparent');
  804. }
  805. game.passedMaps[game.global.world] = game.global.mapBonus;
  806. if (game.global.mapBonus > 0) {
  807. for (x in game.mapUnlocks) {
  808. if (game.mapUnlocks.hasOwnProperty(x)) {
  809. if (game.mapUnlocks[x].startAt < game.global.world) {
  810. game.passedMaps[game.mapUnlocks[x].startAt] = 1;
  811. }
  812. }
  813. }
  814. }
  815. };
  816.  
  817. var _start = function () {
  818. _log('Passive watcher stop');
  819. clearInterval(tPassiveWatcher);
  820.  
  821. _log('BOT start version ' + version);
  822. tAutoBuy = setInterval(_auto, 1000);
  823.  
  824. $('#botStart').text('Bot stop');
  825. };
  826.  
  827. var _stop = function () {
  828. _log('BOT stop');
  829. clearInterval(tAutoBuy);
  830.  
  831. tPassiveWatcher = setInterval(_passiveWatcher, 1000);
  832. _log('Passive watcher started');
  833.  
  834. $('#botStart').text('Bot start');
  835. };
  836.  
  837. var logEnabled = true, tTitimp;
  838.  
  839. var _updateSuperTrimps = function () {
  840. var whipStrength = Math.pow(1.003, game.unlocks.impCount.Whipimp);
  841. whipStrength = prettify((whipStrength - 1) * 100) + "%";
  842. var magimpStrength = Math.pow(1.003, game.unlocks.impCount.Magnimp);
  843. magimpStrength = prettify((magimpStrength - 1) * 100) + "%";
  844. var venimpStrength = Math.pow(1.003, game.unlocks.impCount.Venimp);
  845. venimpStrength = prettify((venimpStrength - 1) * 100) + "%";
  846.  
  847. var mag = $('#magnimp-cell').find('label');
  848. if (mag.text() != magimpStrength) mag.text(magimpStrength);
  849. var whip = $('#whipimp-cell').find('label');
  850. if (whip.text() != whipStrength) whip.text(whipStrength);
  851. var ven = $('#venimp-cell').find('label');
  852. if (ven.text() != venimpStrength) ven.text(venimpStrength);
  853. };
  854.  
  855. var _disableLog = function () {
  856. if (logEnabled) {
  857. message = function (messageString, type, lootIcon, extraClass, extraTag, htmlPrefix) {
  858. if (type == 'Loot' && lootIcon === null) return;
  859. if (type == 'Combat' && (lootIcon === null || typeof lootIcon === 'undefined')) return;
  860. if (type == 'Loot' &&
  861. (messageString.indexOf('You just found') > -1 ||
  862. messageString.indexOf('You found') > -1 ||
  863. messageString.indexOf('That guy just left') > -1 ||
  864. (messageString.indexOf(' dropped ') > -1 && messageString.indexOf('That ') > -1) ||
  865. messageString.indexOf(' manage to ') > -1 ||
  866. messageString.indexOf('Then he died') > -1 ||
  867. messageString.indexOf(' popped out!') > -1 ||
  868. messageString.indexOf('That Feyimp gave you') > -1 ||
  869. messageString.indexOf('in that dead Tauntimp') > -1 ||
  870. messageString.indexOf('fragments from that Flutimp') > -1 ||
  871. messageString.indexOf('That Jestimp gave you') > -1 ||
  872. messageString.indexOf('That Titimp made your Trimps super strong') > -1 ||
  873. messageString.indexOf('You scored ') > -1
  874. )) return;
  875. if (type == 'Story' && typeof lootIcon === 'undefined' &&
  876. messageString.indexOf('BOT: New ') > -1) return;
  877. if (type == 'Notices' && messageString == 'Game Saved!') {
  878. var t = ((game.options.menu.timestamps.enabled == 1) ? getCurrentTime() : updatePortalTimer(true));
  879. $('#saveIndicator').find('.autosaving').text(t);
  880. return;
  881. }
  882. if (messageString.indexOf('The ground up Venimp now increases your Trimps') > -1) {
  883. _updateSuperTrimps();
  884. return;
  885. }
  886. if (messageString.indexOf('You killed a Magnimp! The strong magnetic forces now increase your loot by') > -1) {
  887. _updateSuperTrimps();
  888. return;
  889. }
  890. if (messageString.indexOf('Seeing the Whipimps fall is causing all of your Trimps to work') > -1) {
  891. _updateSuperTrimps();
  892. return;
  893. }
  894.  
  895. var log = document.getElementById("log");
  896. var displayType = "block";
  897. var prefix = "";
  898. var addId = "";
  899. if (messageString == "Game Saved!" || extraClass == 'save') {
  900. addId = " id='saveGame'";
  901. if (document.getElementById('saveGame') !== null) {
  902. log.removeChild(document.getElementById('saveGame'));
  903. }
  904. }
  905. if (game.options.menu.timestamps.enabled) {
  906. messageString = ((game.options.menu.timestamps.enabled == 1) ? getCurrentTime() : updatePortalTimer(true)) + " " + messageString;
  907. }
  908. if (!htmlPrefix) {
  909. if (lootIcon && lootIcon.charAt(0) == "*") {
  910. lootIcon = lootIcon.replace("*", "");
  911. prefix = "icomoon icon-";
  912. }
  913. else prefix = "glyphicon glyphicon-";
  914. if (type == "Story") messageString = "<span class='glyphicon glyphicon-star'></span> " + messageString;
  915. if (type == "Combat") messageString = "<span class='glyphicon glyphicon-flag'></span> " + messageString;
  916. if (type == "Loot" && lootIcon) messageString = "<span class='" + prefix + lootIcon + "'></span> " + messageString;
  917. if (type == "Notices") {
  918. messageString = "<span class='glyphicon glyphicon-off'></span> " + messageString;
  919. }
  920. } else {
  921. messageString = htmlPrefix + " " + messageString;
  922. }
  923. var messageHTML = "<span" + addId + " class='" + type + "Message message" + " " + extraClass + "' style='display: " + displayType + "'>" + messageString + "</span>";
  924. pendingLogs.all.push(messageHTML);
  925. postMessages();
  926.  
  927. var $allLogs = $('#log').find('span');
  928. $allLogs.slice(0, -30).remove();
  929. };
  930. logEnabled = false;
  931. }
  932. };
  933.  
  934. var _titimpUpdate = function () {
  935. $('#titimp-cell').find('label').text(prettify(game.global.titimpLeft > 0 ? game.global.titimpLeft : 0));
  936. };
  937.  
  938. setTimeout(function () {
  939. _log('Trimps BOT version ' + version);
  940.  
  941. tStyleFix = setInterval(_styleFix, 2000);
  942. tTitimp = setInterval(_titimpUpdate, 500);
  943.  
  944. _styleUpdate();
  945. _styleFix();
  946.  
  947. _disableLog();
  948.  
  949. _stop(); // start passive watcher
  950. }, 1000);
  951.  
  952. })();