Trimps tools

Trimps tools (visual)

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

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