Trimps tools

Trimps tools (visual)

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

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