Trimps tools

Trimps tools (visual)

目前为 2017-05-22 提交的版本。查看 最新版本

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