Trimps tools

Trimps tools (visual)

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

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