Trimps tools

Trimps tools (visual)

目前为 2017-05-18 提交的版本,查看 最新版本

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