Trimps tools

Trimps tools (visual)

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

  1. // ==UserScript==
  2. // @name Trimps tools
  3. // @namespace trimps.github.io
  4. // @version 1.236
  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. specialGift.canRunOnce !== true;
  372. if (needExitMap) {
  373. mapsClicked(true); // go to maps
  374. recycleMap(-1, true);
  375. mapsClicked(); // go to world
  376. }
  377. }
  378. }
  379. }
  380. }
  381. };
  382.  
  383. var _mapDeleter = function() {
  384. if (game.global.currentMapId === '') {
  385. for (var x in game.global.mapsOwnedArray) {
  386. var map = game.global.mapsOwnedArray[x];
  387. if (map.level < (game.global.world - 10) && map.noRecycle !== true) {
  388. game.global.lookingAtMap = map['id'];
  389. _log('Deleting map ' + map.name + ' (' + map.level + ')');
  390. recycleMap(-1, true);
  391. break;
  392. }
  393. }
  394. }
  395. }
  396.  
  397. var _auto = function () {
  398. if (_isPortal()) return;
  399. _earlyGameStrategy();
  400. _autoUpgrade();
  401. _autoBuy();
  402. _autoEquipment();
  403. _mapAttackStrategy();
  404. _middleGameStrategy();
  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 _styleUpdate = function () {
  421. // remove counts
  422. $('head').append('<style type="text/css">' +
  423. 'span.thingName{font-size:85%;}.queueItem,.btn{padding:0}' +
  424. '.thingColorCanNotAfford.upgradeThing{background-color:#530053;}' +
  425. '#battleSideTitle{padding:0}' +
  426. '.battleSideBtnContainer{margin-top:0;}' +
  427. '#logBtnGroup{display:none}' +
  428. '#log{height:100%;}' +
  429. '.glyphicon-apple{color:orangered;}' +
  430. '.glyphicon-tree-deciduous{color:limegreen;}'+
  431. '.icomoon.icon-cubes{color:silver;}'+
  432. '.icomoon.icon-diamond{color:white;'+
  433. '</style>');
  434. // remove tabs
  435. $('#buyTabs').hide();
  436. filterTabs('all');
  437. // remove captions
  438. $('#buildingsTitleDiv,#upgradesTitleDiv,#equipmentTitleDiv').hide();
  439. // fix height
  440. $('#topRow,#queueContainer').css('margin-bottom', '0');
  441. $('#jobsTitleDiv').css('padding', '0').css('font-size', 'smaller');
  442. $('#buyHere').css('margin', '0').css('padding', '0').css('overflow-x', 'hidden');
  443. $('#queueContainer').css('height', '70px');
  444. $('#numTabs').css('margin', '0');
  445. $('#buyContainer').css('height', 'calc(99vh - 20vw - 96px)');
  446. // add button
  447. $('#settingsTable tr').append('<td class="btn btn-info" id="botStart" title="' + version + '">Bot start</td>');
  448. $('#botStart').click(_onStartButton);
  449. // add grid
  450. var $grid = $('<table style="width:100%;margin-top:4px;font-size:smaller;"><tr>' +
  451. '<td id="magnimp-cell"><span class="glyphicon glyphicon-magnet"></span><label style="margin-left:4px" title="Magimp">...</label></td>' +
  452. '<td id="venimp-cell"><span class="glyphicon glyphicon-glass"></span><label style="margin-left:4px" title="Venimp">...</label></td>' +
  453. '</tr><tr>' +
  454. '<td id="whipimp-cell"><span class="glyphicon glyphicon-star"></span><label style="margin-left:4px" title="Whipimp">...</label></td>' +
  455. '<td id="titimp-cell"><span class="icomoon icon-hammer"></span><label style="margin-left:4px" title="Titimp">' + prettify(game.global.titimpLeft) + '</label></td>' +
  456. '</tr></table>');
  457. $('#battleBtnsColumn').append($grid);
  458. _updateSuperTrimps();
  459. }
  460.  
  461. var _autoUpgrade = function () {
  462. for (var item in game.upgrades) {
  463. var upgrade = game.upgrades[item];
  464. if (upgrade.locked == 1) continue;
  465. var canAfford = canAffordTwoLevel(upgrade);
  466. if (canAfford) {
  467. if (item == "Coordination") {
  468. if (!canAffordCoordinationTrimps()) continue;
  469. }
  470. if (item == "Gigastation") {
  471. var minAddon = Math.floor(game.global.highestLevelCleared / 6);
  472. var minWaprstation = Math.floor(game.global.world / 6) + minAddon;
  473. if (minWaprstation < 6 + minAddon) minWaprstation = 6 + minAddon;
  474. if (game.buildings.Warpstation.owned < minWaprstation) continue;
  475. }
  476. buyUpgrade(item, true, true);
  477. _log('Upgrading ' + item);
  478. _selectAutoJob();
  479. return 1;
  480. }
  481. }
  482. return 0;
  483. };
  484.  
  485. var getUpgradePrice = function (upgradeObject) {
  486. var price, result = {};
  487. for (var cost in upgradeObject.cost) {
  488. if (typeof upgradeObject.cost[cost] === 'object' && typeof upgradeObject.cost[cost][1] === 'undefined') {
  489. var costItem = upgradeObject.cost[cost];
  490. for (var item in costItem) {
  491. price = costItem[item];
  492. if (upgradeObject.prestiges && (item == "metal" || item == "wood")) {
  493. if (game.global.challengeActive == "Daily" && typeof game.global.dailyChallenge.metallicThumb !== 'undefined') {
  494. price *= dailyModifiers.metallicThumb.getMult(game.global.dailyChallenge.metallicThumb.strength);
  495. }
  496. price *= Math.pow(1 - game.portal.Artisanistry.modifier, game.portal.Artisanistry.level);
  497. }
  498. if (typeof price === 'function') price = price();
  499. if (typeof price[1] !== 'undefined') price = resolvePow(price, upgradeObject);
  500. result[item] = price;
  501. }
  502. }
  503. }
  504. return result;
  505. };
  506.  
  507. var _getAllUpgradePrice = function () {
  508. var totalPrice = {};
  509. for (var item in game.upgrades) {
  510. var upgrade = game.upgrades[item];
  511. if (upgrade.locked == 1) continue;
  512. var price = getUpgradePrice(upgrade);
  513. for (var res in price) {
  514. if (price.hasOwnProperty(res)) {
  515. if (typeof totalPrice[res] === 'undefined') totalPrice[res] = 0;
  516. totalPrice[res] += price[res];
  517. }
  518. }
  519. }
  520. return totalPrice;
  521. };
  522.  
  523. var _getUpgradePriceSumForRes = function (res) {
  524. var totalPrice = _getAllUpgradePrice();
  525. if (typeof totalPrice[res] !== 'undefined') {
  526. return totalPrice[res];
  527. } else {
  528. return 0;
  529. }
  530. };
  531.  
  532. var _getMaximumResourceUpgradePrice = function () {
  533. var totalPrice = _getAllUpgradePrice(), maxPriceName = '', maxPrice = 0;
  534. for (var res in totalPrice) {
  535. if (totalPrice.hasOwnProperty(res)) {
  536. if (totalPrice[res] > maxPrice) {
  537. maxPrice = totalPrice[res];
  538. maxPriceName = res;
  539. }
  540. }
  541. }
  542. var result = {};
  543. if (maxPriceName !== '') {
  544. result[maxPriceName] = maxPrice;
  545. return result;
  546. } else {
  547. return false;
  548. }
  549. };
  550.  
  551. var _autoBuy = function () {
  552. var toBuy;
  553. for (var item in game.buildings) {
  554. if (item == 'Barn' || item == 'Shed' || item == 'Forge' || item == 'Wormhole' || item == 'Trap') continue;
  555. if (!game.buildings.Collector.locked &&
  556. (item == 'Mansion' || item == 'Hotel' || item == 'Resort' || item == 'House' || item == 'Hut')) continue;
  557. if (game.upgrades.Gigastation.done >= 10 && item == 'Collector') continue;
  558. building = game.buildings[item];
  559. if (building.locked == 1) continue;
  560. var canAfford = canAffordBuilding(item, false, false, false, true);
  561. if (canAfford) {
  562. if (item == 'Nursery') {
  563. var isElectro = game.global.challengeActive == "Electricity";
  564. var mult = game.global.brokenPlanet ? (game.global.world >= 80 ? 2 : 1.5) : 1;
  565. if (!isElectro && (game.buildings.Nursery.owned >= (game.buildings.Tribute.owned * mult) ||
  566. game.buildings.Nursery.owned >= (game.buildings.Gym.owned * mult)))
  567. {
  568. continue;
  569. } else {
  570. if (!_hasInQueue('Nursery')) {
  571. toBuy = item;
  572. } else {
  573. continue;
  574. }
  575. }
  576. } else {
  577. toBuy = item;
  578. }
  579. }
  580. }
  581. if (typeof toBuy !== 'undefined') {
  582. buyBuilding(toBuy, true, true);
  583. _log('Building ' + toBuy);
  584. return 1;
  585. } else {
  586. return 0;
  587. }
  588. }
  589.  
  590. var needFarmer = 25, needLumber = 25, needMiner = 25, needScientist = 1;
  591. var needAllMax = needFarmer + needLumber + needMiner + needScientist;
  592.  
  593. var _buyJobs = function ($obj, unemployed, objName, jobId) {
  594. if ($obj.length > 0) {
  595. var trimps = game.resources.trimps;
  596. var breeding = game.global.challengeActive == "Trapper" ? unemployed : trimps.owned - trimps.employed;
  597. var cnt = 1;
  598. var minBreeding = _getMinimumBreeding();
  599. if (unemployed > needAllMax * 100000 && (breeding - 1000000 > minBreeding)) {
  600. game.global.buyAmt = 1000000;
  601. cnt = 1000000;
  602. }
  603. else if (unemployed > needAllMax * 10000 && (breeding - 100000 > minBreeding)) {
  604. game.global.buyAmt = 100000;
  605. cnt = 100000;
  606. }
  607. else if (unemployed > needAllMax * 1000 && (breeding - 10000 > minBreeding)) {
  608. game.global.buyAmt = 10000;
  609. cnt = 10000;
  610. }
  611. else if (unemployed > needAllMax * 100 && (breeding - 1000 > minBreeding)) {
  612. game.global.buyAmt = 1000;
  613. cnt = 1000;
  614. }
  615. else if (unemployed > needAllMax * 10 && (breeding - 100 > minBreeding)) {
  616. numTab(4);
  617. cnt = 100;
  618. }
  619. else if (unemployed > needAllMax * 2.5 && (breeding - 25 > minBreeding)) {
  620. numTab(3);
  621. cnt = 25;
  622. }
  623. else if (unemployed > needAllMax && (breeding - 10 > minBreeding)) {
  624. numTab(2);
  625. cnt = 10;
  626. }
  627. else {
  628. numTab(1);
  629. cnt = 1;
  630. }
  631. buyJob(jobId, true, true); // confirmed, noTip
  632. numTab(1); // +1
  633. _log('New ' + objName + (cnt > 1 ? " x" + cnt : ''), 'Combat');
  634. return cnt;
  635. } else {
  636. return 0;
  637. }
  638. };
  639.  
  640. var _autoJobs = function () {
  641. var trimps = game.resources.trimps;
  642. var breeding = trimps.owned - trimps.employed;
  643. if (breeding < (_getMinimumBreeding() + 1) && game.global.challengeActive !== 'Trapper') return;
  644.  
  645. var jobsTotal =
  646. game.jobs.Farmer.owned +
  647. game.jobs.Lumberjack.owned +
  648. game.jobs.Miner.owned +
  649. game.jobs.Scientist.owned;
  650.  
  651. var unemployed = Math.ceil(game.resources.trimps.realMax() / 2) - game.resources.trimps.employed;
  652.  
  653. var trainerCost = _getJobPrice('Trainer', 'food');
  654. if ((trainerCost < game.resources.food.owned) && unemployed <= 0 && game.jobs.Farmer.owned > 1 && game.jobs.Trainer.locked === 0) {
  655. game.global.firing = true;
  656. _log('Fire farmer, sorry');
  657. buyJob('Farmer', true, true);
  658. game.global.firing = false;
  659. }
  660.  
  661. if (unemployed <= 0) return;
  662.  
  663. if (trainerCost <= game.resources.food.owned && game.jobs.Trainer.locked === 0) {
  664. buyJob('Trainer', true, true);
  665. _log('New trainer');
  666. return 1;
  667. }
  668.  
  669. var cnt = 0;
  670.  
  671. var $explorer = $('#jobsHere').find('.thingColorCanAfford[id=Explorer]');
  672. if ($explorer.length > 0) {
  673. buyJob('Explorer', true, true);
  674. _log('New explorer');
  675. return ++cnt;
  676. }
  677.  
  678. var hasFarmer = game.jobs.Farmer.locked === 0;
  679. var hasLumber = game.jobs.Lumberjack.locked === 0;
  680. var hasMiner = game.jobs.Miner.locked === 0;
  681. var hasScientist = game.jobs.Scientist.locked === 0;
  682. var needAll =
  683. (hasFarmer ? needFarmer : 0) +
  684. (hasLumber ? needLumber : 0) +
  685. (hasMiner ? needMiner : 0) +
  686. (hasScientist ? needScientist : 0);
  687. if (needAll < 1) needAll = 1;
  688.  
  689. var minOwned = Math.min(
  690. game.jobs.Farmer.owned,
  691. game.jobs.Lumberjack.owned,
  692. game.jobs.Miner.owned);
  693. if (minOwned > 30) minOwned = 30; // for science
  694.  
  695. if (hasScientist && game.jobs.Scientist.owned < minOwned) {
  696. var $science = $('#jobsHere').find('.thingColorCanAfford[id=Scientist]');
  697. cnt += _buyJobs($science, unemployed, 'scientist', 'Scientist');
  698. } else if (hasFarmer && game.jobs.Farmer.owned < (jobsTotal * needFarmer / needAll)) {
  699. var $farmer = $('#jobsHere').find('.thingColorCanAfford[id=Farmer]');
  700. cnt += _buyJobs($farmer, unemployed, 'farmer', 'Farmer');
  701. } else if (hasLumber && game.jobs.Lumberjack.owned < (jobsTotal * needLumber / needAll)) {
  702. var $lumber = $('#jobsHere').find('.thingColorCanAfford[id=Lumberjack]');
  703. cnt += _buyJobs($lumber, unemployed, 'lumberjack', 'Lumberjack');
  704. } else if (hasMiner && game.jobs.Miner.owned < (jobsTotal * needMiner / needAll)) {
  705. var $miner = $('#jobsHere').find('.thingColorCanAfford[id=Miner]');
  706. cnt += _buyJobs($miner, unemployed, 'miner', 'Miner');
  707. } else if (hasScientist && game.jobs.Scientist.owned < (jobsTotal * needScientist / needAll)) {
  708. var $science = $('#jobsHere').find('.thingColorCanAfford[id=Scientist]');
  709. cnt += _buyJobs($science, unemployed, 'scientist', 'Scientist');
  710. }
  711.  
  712. if (unemployed > 0 && cnt === 0) {
  713. var $farmer = $('#jobsHere').find('.thingColorCanAfford[id=Farmer]');
  714. cnt += _buyJobs($farmer, unemployed, 'farmer', 'Farmer');
  715. }
  716.  
  717. return cnt;
  718. };
  719.  
  720. var _styleFix = function () {
  721. _disableLog();
  722.  
  723. $('.buyBox').find('.thing').find('br').remove();
  724. $('.buyBox').find('.thing').find('.thingOwned').css('margin-left', '4px');
  725. $('#buyHere').find('.alert.badge').text('');
  726. $('#buildingsQueue').css('height', '30px');
  727. for (var x in game.upgrades) if (game.upgrades[x].alert && game.upgrades[x].locked === 0) game.upgrades[x].alert = false;
  728. for (x in game.buildings) if (game.buildings[x].alert && game.buildings[x].locked === 0) game.buildings[x].alert = false;
  729. for (x in game.jobs) if (game.jobs[x].alert && game.jobs[x].locked === 0) game.jobs[x].alert = false;
  730.  
  731. if (typeof game.passedMaps === 'undefined') game.passedMaps = {};
  732. if (typeof game.mapsAttacked === 'undefined') game.mapsAttacked = {};
  733.  
  734. for (x in game.passedMaps) if (x > game.global.world) {
  735. // Game restart?
  736. game.passedMaps = {};
  737. game.mapsAttacked = {};
  738. $('#venimp-cell').find('label').text('...');
  739. $('#magnimp-cell').find('label').text('...');
  740. $('#whipimp-cell').find('label').text('...');
  741. $('#buildingsTitleDiv,#upgradesTitleDiv,#equipmentTitleDiv').hide(); // remove captions
  742. break;
  743. }
  744.  
  745. var hasItem = false;
  746. if (typeof game.mapUnlocks === 'undefined') {
  747. clearInterval(tStyleFix);
  748. tStyleFix = setInterval(_styleFix, 2000);
  749. } else {
  750. for (x in game.mapUnlocks) {
  751. var notPass = game.mapUnlocks[x].startAt <= game.global.world && (typeof game.passedMaps[game.mapUnlocks[x].startAt] === 'undefined' || game.passedMaps[game.mapUnlocks[x].startAt] < 1);
  752. if (notPass) {
  753. $('#battleSideTitle').css('background-color', notPass ? '#A00' : '#600');
  754. hasItem = true;
  755. break;
  756. }
  757. }
  758. }
  759. if (!hasItem) {
  760. $('#battleSideTitle').css('background-color', 'transparent');
  761. }
  762. game.passedMaps[game.global.world] = game.global.mapBonus;
  763. if (game.global.mapBonus > 0) {
  764. for (x in game.mapUnlocks) {
  765. if (game.mapUnlocks[x].startAt < game.global.world) {
  766. game.passedMaps[game.mapUnlocks[x].startAt] = 1;
  767. }
  768. }
  769. }
  770. };
  771.  
  772. var _start = function () {
  773. _log('Passive watcher stop');
  774. clearInterval(tPassiveWatcher);
  775.  
  776. _log('BOT start version ' + version);
  777. tAutoBuy = setInterval(_auto, 1000);
  778.  
  779. $('#botStart').text('Bot stop');
  780. };
  781.  
  782. var _stop = function () {
  783. _log('BOT stop');
  784. clearInterval(tAutoBuy);
  785.  
  786. tPassiveWatcher = setInterval(_passiveWatcher, 1000);
  787. _log('Passive watcher started');
  788.  
  789. $('#botStart').text('Bot start');
  790. };
  791.  
  792. var logEnabled = true, $oldLog, tTitimp;
  793.  
  794. var _updateSuperTrimps = function () {
  795. var whipStrength = Math.pow(1.003, game.unlocks.impCount.Whipimp);
  796. whipStrength = prettify((whipStrength - 1) * 100) + "%";
  797. var magimpStrength = Math.pow(1.003, game.unlocks.impCount.Magnimp);
  798. magimpStrength = prettify((magimpStrength - 1) * 100) + "%";
  799. var venimpStrength = Math.pow(1.003, game.unlocks.impCount.Venimp);
  800. venimpStrength = prettify((venimpStrength - 1) * 100) + "%";
  801.  
  802. var mag = $('#magnimp-cell').find('label');
  803. if (mag.text() != magimpStrength) mag.text(magimpStrength);
  804. var whip = $('#whipimp-cell').find('label');
  805. if (whip.text() != whipStrength) whip.text(whipStrength);
  806. var ven = $('#venimp-cell').find('label');
  807. if (ven.text() != venimpStrength) ven.text(venimpStrength);
  808. };
  809.  
  810. var _disableLog = function () {
  811. if (logEnabled) {
  812. message = function (messageString, type, lootIcon, extraClass, extraTag, htmlPrefix) {
  813. if (type == 'Loot' && lootIcon === null) return;
  814. if (type == 'Combat' && (lootIcon === null || typeof lootIcon === 'undefined')) return;
  815. if (type == 'Loot' &&
  816. (messageString.indexOf('You just found') > -1 ||
  817. messageString.indexOf('You found') > -1 ||
  818. messageString.indexOf('That guy just left') > -1 ||
  819. (messageString.indexOf(' dropped ') > -1 && messageString.indexOf('That ') > -1) ||
  820. messageString.indexOf(' manage to ') > -1 ||
  821. messageString.indexOf('Then he died') > -1 ||
  822. messageString.indexOf(' popped out!') > -1 ||
  823. messageString.indexOf('That Feyimp gave you') > -1 ||
  824. messageString.indexOf('in that dead Tauntimp') > -1 ||
  825. messageString.indexOf('fragments from that Flutimp') > -1 ||
  826. messageString.indexOf('That Jestimp gave you') > -1 ||
  827. messageString.indexOf('That Titimp made your Trimps super strong') > -1 ||
  828. messageString.indexOf('You scored ') > -1
  829. )) return;
  830. if (type == 'Story' && typeof lootIcon === 'undefined' &&
  831. messageString.indexOf('BOT: New ') > -1) return;
  832. if (type == 'Notices' && messageString == 'Game Saved!') {
  833. var t = ((game.options.menu.timestamps.enabled == 1) ? getCurrentTime() : updatePortalTimer(true));
  834. $('#saveIndicator').find('.autosaving').text(t);
  835. return;
  836. }
  837. if (messageString.indexOf('The ground up Venimp now increases your Trimps') > -1) {
  838. _updateSuperTrimps();
  839. return;
  840. }
  841. if (messageString.indexOf('You killed a Magnimp! The strong magnetic forces now increase your loot by') > -1) {
  842. _updateSuperTrimps();
  843. return;
  844. }
  845. if (messageString.indexOf('Seeing the Whipimps fall is causing all of your Trimps to work') > -1) {
  846. _updateSuperTrimps();
  847. return;
  848. }
  849.  
  850. var log = document.getElementById("log");
  851. var displayType = "block";
  852. var prefix = "";
  853. var addId = "";
  854. if (messageString == "Game Saved!" || extraClass == 'save') {
  855. addId = " id='saveGame'";
  856. if (document.getElementById('saveGame') !== null) {
  857. log.removeChild(document.getElementById('saveGame'));
  858. }
  859. }
  860. if (game.options.menu.timestamps.enabled) {
  861. messageString = ((game.options.menu.timestamps.enabled == 1) ? getCurrentTime() : updatePortalTimer(true)) + " " + messageString;
  862. }
  863. if (!htmlPrefix) {
  864. if (lootIcon && lootIcon.charAt(0) == "*") {
  865. lootIcon = lootIcon.replace("*", "");
  866. prefix = "icomoon icon-";
  867. }
  868. else prefix = "glyphicon glyphicon-";
  869. if (type == "Story") messageString = "<span class='glyphicon glyphicon-star'></span> " + messageString;
  870. if (type == "Combat") messageString = "<span class='glyphicon glyphicon-flag'></span> " + messageString;
  871. if (type == "Loot" && lootIcon) messageString = "<span class='" + prefix + lootIcon + "'></span> " + messageString;
  872. if (type == "Notices") {
  873. messageString = "<span class='glyphicon glyphicon-off'></span> " + messageString;
  874. }
  875. } else {
  876. messageString = htmlPrefix + " " + messageString;
  877. }
  878. var messageHTML = "<span" + addId + " class='" + type + "Message message" + " " + extraClass + "' style='display: " + displayType + "'>" + messageString + "</span>";
  879. pendingLogs.all.push(messageHTML);
  880. postMessages();
  881.  
  882. var $allLogs = $('#log').find('span');
  883. $allLogs.slice(0, -30).remove();
  884. };
  885. logEnabled = false;
  886. }
  887. };
  888.  
  889. var _titimpUpdate = function () {
  890. $('#titimp-cell').find('label').text(prettify(game.global.titimpLeft > 0 ? game.global.titimpLeft : 0));
  891. };
  892.  
  893. setTimeout(function () {
  894.  
  895. _log('Trimps BOT version ' + version);
  896.  
  897. tStyleFix = setInterval(_styleFix, 2000);
  898. tTitimp = setInterval(_titimpUpdate, 500);
  899.  
  900. _styleUpdate();
  901. _styleFix();
  902.  
  903. _disableLog();
  904.  
  905. _stop(); // start passive watcher
  906.  
  907. }, 1000);
  908.  
  909. })();