Trimps tools

Trimps tools (visual)

当前为 2018-12-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Trimps tools
  3. // @namespace trimps.github.io
  4. // @version 1.255
  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. what = parseInt(what);
  28. if (!game.global.preMapsActive && !game.global.lockTooltip) {
  29. if (game.upgrades.Formations.done && what === 0) return true;
  30. if (game.upgrades.Formations.done && what === 1) return true;
  31. if (game.upgrades.Dominance.done && what === 2) return true;
  32. if (game.upgrades.Barrier.done && what === 3) return true;
  33. if (game.upgrades.Formations.done && game.global.highestLevelCleared >= 180 && what === 4) return true;
  34. }
  35. return false;
  36. };
  37.  
  38. var _getEnemyAttack = function() {
  39. var cellNum, cell;
  40. if (game.global.mapsActive) {
  41. cellNum = game.global.lastClearedMapCell + 1;
  42. cell = game.global.mapGridArray[cellNum];
  43. } else {
  44. cellNum = game.global.lastClearedCell + 1;
  45. cell = game.global.gridArray[cellNum];
  46. }
  47. return calculateDamage(cell.attack, false, false, false, cell);
  48. };
  49.  
  50. var _middleGameStrategy = function() {
  51. if (game.global.world < 60) return;
  52.  
  53. if (game.global.formation === 0) {
  54. if (_hasFormation(1)) setFormation('1');
  55. }
  56.  
  57. var enemy = _getEnemyAttack();
  58. var me = game.global.soldierCurrentBlock + game.global.soldierHealthMax;
  59. if (enemy >= me && parseInt(game.global.formation) !== 1) {
  60. if (_hasFormation(1)) setFormation('1');
  61. }
  62.  
  63. if (parseInt(game.global.formation) !== 2 && _hasFormation(2)) {
  64. var formation2health = game.global.soldierHealthMax / 8;
  65. var me2 = formation2health + game.global.soldierCurrentBlock;
  66. if (me2 > enemy) {
  67. setFormation('2');
  68. }
  69. }
  70. };
  71.  
  72. var _log = function (mes, type) {
  73. if (typeof type === 'undefined') type = "Story";
  74. message("BOT: " + mes, type);
  75. };
  76.  
  77. var _getBreedingBaseSpeed = function () {
  78. if (game.global.challengeActive === "Trapper") return 0;
  79. var base = 0.0085;
  80. var currentCalc = _getBreeding() * base;
  81. if (game.upgrades.Potency.done > 0) {
  82. currentCalc *= Math.pow(1.1, game.upgrades.Potency.done);
  83. }
  84. return currentCalc;
  85. };
  86.  
  87. var _getBreedingTotalSpeed = function () {
  88. if (game.global.challengeActive === "Trapper") return 0;
  89. var trimps = game.resources.trimps;
  90. var base = 0.0085;
  91. //Add job count
  92. var breeding = trimps.owned - trimps.employed;
  93. var currentCalc = breeding * base;
  94. //Add Potency
  95. if (game.upgrades.Potency.done > 0){
  96. currentCalc *= Math.pow(1.1, game.upgrades.Potency.done);
  97. }
  98. //Add Nurseries
  99. if (game.buildings.Nursery.owned > 0){
  100. currentCalc *= Math.pow(1.01, game.buildings.Nursery.owned);
  101. }
  102. //Add Venimp
  103. if (game.unlocks.impCount.Venimp > 0){
  104. var venimpStrength = Math.pow(1.003, game.unlocks.impCount.Venimp);
  105. currentCalc *= (venimpStrength);
  106. }
  107. if (game.global.brokenPlanet){
  108. currentCalc /= 10;
  109. }
  110. //Add pheromones
  111. if (game.portal.Pheromones.level > 0){
  112. var PheromonesStrength = (game.portal.Pheromones.level * game.portal.Pheromones.modifier);
  113. currentCalc *= (PheromonesStrength + 1);
  114. }
  115. //Add Geneticist
  116. if (game.jobs.Geneticist.owned > 0) {
  117. currentCalc *= Math.pow(.98, game.jobs.Geneticist.owned);
  118. }
  119. //Add quick trimps
  120. if (game.unlocks.quickTrimps){
  121. currentCalc *= 2;
  122. }
  123. if (game.global.challengeActive === "Daily"){
  124. var mult = 0;
  125. if (typeof game.global.dailyChallenge.dysfunctional !== 'undefined'){
  126. mult = dailyModifiers.dysfunctional.getMult(game.global.dailyChallenge.dysfunctional.strength);
  127. currentCalc *= mult;
  128. }
  129. if (typeof game.global.dailyChallenge.toxic !== 'undefined'){
  130. mult = dailyModifiers.toxic.getMult(game.global.dailyChallenge.toxic.strength, game.global.dailyChallenge.toxic.stacks);
  131. currentCalc *= mult;
  132. }
  133. }
  134. if (game.global.challengeActive === "Toxicity" && game.challenges.Toxicity.stacks > 0){
  135. currentCalc *= Math.pow(game.challenges.Toxicity.stackMult, game.challenges.Toxicity.stacks);
  136. }
  137. if (game.global.voidBuff === "slowBreed"){
  138. currentCalc *= 0.2;
  139. }
  140. var heirloomBonus = calcHeirloomBonus("Shield", "breedSpeed", 0, true);
  141. if (heirloomBonus > 0){
  142. currentCalc *= ((heirloomBonus / 100) + 1);
  143. }
  144. return currentCalc;
  145. };
  146.  
  147. var _autoEquipment = function () {
  148. var maxEquipLevel = game.global.challengeActive === 'Frugal' ? 10000 : 7;
  149. for (var x in game.equipment) {
  150. if (game.equipment.hasOwnProperty(x) && game.equipment[x].locked === 0) {
  151. var maxLevel = game.equipment[x].prestige > maxEquipLevel ? 1 : (maxEquipLevel + 1 - game.equipment[x].prestige) * 2;
  152. if (x === 'Shield' && !game.equipment['Shield'].blockNow) {
  153. maxLevel = 1;
  154. }
  155. if (game.equipment[x].level < maxLevel && canAffordBuilding(x, null, null, true)) {
  156. buyEquipment(x, true, true);
  157. _log('Upgrading equipment ' + x);
  158. }
  159. }
  160. }
  161. };
  162.  
  163. var _getMinimumBreeding = function () {
  164. var battleTrimps = (game.portal.Coordinated.level) ? game.portal.Coordinated.currentSend : game.resources.trimps.maxSoldiers;
  165. if (battleTrimps < 5) return 5; else return battleTrimps + 1;
  166. };
  167.  
  168. var _buyStorage = function () {
  169. var packratLevel = (1 + game.portal.Packrat.level * (game.portal.Packrat.modifier * 100) / 100);
  170. var buildingsForResources = {
  171. food: "Barn",
  172. wood: "Shed",
  173. metal: "Forge"
  174. };
  175.  
  176. for (var res in buildingsForResources) {
  177. if (buildingsForResources.hasOwnProperty(res)) {
  178. var bldName = buildingsForResources[res];
  179. if (game.resources[res].owned / (game.resources[res].max * packratLevel) >= 0.8) {
  180. if (canAffordBuilding(bldName, false, false, false, true)) {
  181. buyBuilding(bldName, true, true);
  182. _log('Building ' + bldName);
  183. }
  184. }
  185. }
  186. }
  187. };
  188.  
  189. var _hasInQueue = function (item) {
  190. for (var x in game.global.buildingsQueue) {
  191. var queueItem = game.global.buildingsQueue[x].split('.')[0];
  192. if (queueItem === item) {
  193. return true;
  194. }
  195. }
  196. return false;
  197. };
  198.  
  199. var _getBreeding = function () {
  200. var trimps = game.resources.trimps;
  201. return game.global.challengeActive === "Trapper" ? 0 : trimps.owned - trimps.employed;
  202. };
  203.  
  204. var _earlyGameStrategy = function (isPassive) {
  205. if (_isPortal()) return;
  206.  
  207. var playerStrength = getPlayerModifier();
  208. var minimumSpeedToHelp = 1 + playerStrength;
  209.  
  210. if (parseInt(game.global.eggLoc) !== -1) {
  211. _log('Destroying Easter Egg');
  212. easterEggClicked();
  213. }
  214.  
  215. _buyStorage();
  216. if (isPassive === false) {
  217. _autoJobs();
  218. }
  219.  
  220. var breeding = _getBreeding();
  221. var unemployed = Math.ceil(game.resources.trimps.realMax() / 2) - game.resources.trimps.employed;
  222.  
  223. if (game.buildings.Trap.owned >= 1 && game.resources.trimps.owned < game.resources.trimps.realMax() &&
  224. (breeding < _getMinimumBreeding() || unemployed > 0) &&
  225. _getBreedingBaseSpeed() < 1) {
  226. setGather('trimps');
  227. return;
  228. }
  229.  
  230. var canGetScience = game.global.challengeActive !== "Scientist";
  231.  
  232. var hasTrap = _hasInQueue('Trap');
  233. var cnt = game.global.challengeActive === "Trapper" ? 100 : (breeding < unemployed ? 25 : 1);
  234. if (!hasTrap && game.buildings.Trap.owned < 1 && game.resources.food.owned >= 10 && game.resources.wood.owned >= 10) {
  235. buyBuilding('Trap', true, true, cnt);
  236. return;
  237. }
  238.  
  239. if ((game.global.buildingsQueue.length > 0 && game.global.autoCraftModifier < 1) || (game.global.buildingsQueue.length > 5)) {
  240. setGather('buildings');
  241. return;
  242. }
  243.  
  244. if (getPsString('food', true) < minimumSpeedToHelp && game.resources.food.owned < 10) {
  245. setGather('food');
  246. return;
  247. }
  248.  
  249. if (getPsString('wood', true) < minimumSpeedToHelp && game.resources.wood.owned < 10) {
  250. setGather('wood');
  251. return;
  252. }
  253.  
  254. if (canGetScience && getPsString('science', true) < minimumSpeedToHelp && game.resources.science.owned < 10) {
  255. setGather('science');
  256. return;
  257. }
  258.  
  259. if (getPsString('metal', true) < minimumSpeedToHelp && game.resources.metal.owned < 100) {
  260. setGather('metal');
  261. return;
  262. }
  263.  
  264. var needScientist = game.upgrades.Scientists.done === 0 && game.upgrades.Scientists.allowed === 1;
  265. if (canGetScience && getPsString('science', true) < minimumSpeedToHelp && (game.resources.science.owned < 60 || needScientist)) {
  266. setGather('science');
  267. return;
  268. }
  269.  
  270. if ((game.global.playerGathering === 'trimps' && (game.buildings.Trap.owned === 0 || _getBreedingBaseSpeed() > 1)) ||
  271. (game.global.playerGathering === 'buildings' && game.global.buildingsQueue.length === 0)) {
  272. _selectAutoJob();
  273. }
  274. };
  275.  
  276. var _selectAutoJob = function () {
  277. var canGetScience = game.global.challengeActive !== "Scientist";
  278. var upgradePrice = _getMaximumResourceUpgradePrice();
  279. var scienceNeeded = _getUpgradePriceSumForRes('science');
  280. if (scienceNeeded > game.resources.science.owned && canGetScience) {
  281. setGather('science');
  282. } else {
  283. if (upgradePrice !== false) {
  284. for (var x in upgradePrice) {
  285. if (upgradePrice.hasOwnProperty(x)) {
  286. if (x === 'wood' || x === 'metal' || x === 'science' || x === 'food') {
  287. setGather(x);
  288. } else {
  289. if (canGetScience) {
  290. setGather('science');
  291. } else {
  292. setGather('food');
  293. }
  294. }
  295. break;
  296. }
  297. }
  298. } else {
  299. if (canGetScience) {
  300. setGather('science');
  301. } else {
  302. setGather('food');
  303. }
  304. }
  305. }
  306. };
  307.  
  308. var _passiveWatcher = function () {
  309. if (_isPortal()) return;
  310.  
  311. _earlyGameStrategy(true);
  312.  
  313. var canAfford = canAffordBuilding("Tribute", false, false, false, true);
  314. if (canAfford && game.buildings.Tribute.locked !== 1) {
  315. buyBuilding("Tribute", true, true);
  316. _log('Building ' + "Tribute");
  317. }
  318.  
  319. canAfford = canAffordBuilding("Gym", false, false, false, true);
  320. if (canAfford && game.buildings.Gym.locked !== 1) {
  321. buyBuilding("Gym", true, true);
  322. _log('Building ' + "Gym");
  323. }
  324.  
  325. _middleGameStrategy();
  326. };
  327.  
  328. var _needAttackCurrentMap = function () {
  329. return (typeof game.mapsAttacked[game.global.world] === 'undefined');
  330. };
  331.  
  332. var _hasMapOfCurrentLevel = function () {
  333. for (var x in game.global.mapsOwnedArray) {
  334. if (game.global.mapsOwnedArray.hasOwnProperty(x)) {
  335. var mapObj = game.global.mapsOwnedArray[x];
  336. if (parseInt(mapObj.level) === parseInt(game.global.world)) return true;
  337. }
  338. }
  339. return false;
  340. };
  341.  
  342. var _mapAttackStrategy = function () {
  343. var x, mapObj;
  344. var breeding = _getBreeding();
  345.  
  346. if (game.global.world < 6) return;
  347. if (game.global.preMapsActive) return;
  348. //if (!game.global.mapsUnlocked) return;
  349. if (game.global.pauseFight) {
  350. _log('Enabling auto attack!');
  351. fightManual();
  352. game.global.pauseFight = false;
  353. pauseFight(true); // update only
  354. } else {
  355. if (_needAttackCurrentMap()) {
  356. document.getElementById("mapLevelInput").value = game.global.world;
  357. var currentMapPrice = updateMapCost(true);
  358. var money = game.resources.fragments.owned;
  359. if (!_hasMapOfCurrentLevel()) {
  360. if (money >= currentMapPrice) {
  361. var result = buyMap();
  362. if (result === 1) {
  363. _log('Bought new map level ' + game.global.world);
  364. } else {
  365. console.log('Buy map result = ' + result);
  366. }
  367. } else {
  368. console.log('No fragments (' + money + ') to buy map for ' + currentMapPrice);
  369. }
  370. }
  371.  
  372. if (_hasMapOfCurrentLevel()) {
  373. game.global.lookingAtMap = '';
  374. for (x in game.global.mapsOwnedArray) {
  375. if (game.global.mapsOwnedArray.hasOwnProperty(x)) {
  376. mapObj = game.global.mapsOwnedArray[x];
  377. if (parseInt(mapObj.level) === parseInt(game.global.world)) {
  378. game.global.lookingAtMap = mapObj.id;
  379. break;
  380. }
  381. }
  382. }
  383.  
  384. if (game.global.lookingAtMap !== '') {
  385. _log('Attacking map ' + game.global.lookingAtMap);
  386. game.options.menu.alwaysAbandon.enabled = 1; // GO TO MAPS!
  387. mapsClicked(true);
  388. game.mapsAttacked[game.global.world] = true;
  389. game.global.repeatMap = true; // REPEAT
  390. repeatClicked(true);
  391. runMap();
  392. if (breeding < (_getMinimumBreeding() + 1)) fightManual();
  393. } else {
  394. console.log('where is my map?');
  395. }
  396. } else {
  397. console.log('no map of current level ' + game.global.world);
  398. }
  399. } else {
  400. if (_hasMapOfCurrentLevel() && game.global.currentMapId === '') {
  401. game.global.lookingAtMap = '';
  402. var map_id, map_name = '';
  403. for (x in game.global.mapsOwnedArray) {
  404. if (game.global.mapsOwnedArray.hasOwnProperty(x)) {
  405. mapObj = game.global.mapsOwnedArray[x];
  406. if (mapObj.level <= game.global.world && mapObj.noRecycle === true && mapObj.clears === 0) {
  407. game.global.lookingAtMap = mapObj.id;
  408. map_id = x;
  409. map_name = mapObj.name;
  410. break;
  411. }
  412. }
  413. }
  414. if (game.global.lookingAtMap !== '' && typeof map_id !== 'undefined') {
  415. _log('Attacking prestige map ' + map_name + ' level (' + game.global.mapsOwnedArray[map_id].level + ')');
  416. game.options.menu.alwaysAbandon.enabled = 1; // GO TO MAPS!
  417. mapsClicked(true);
  418. game.global.repeatMap = true; // REPEAT
  419. repeatClicked(true);
  420. game.global.mapsOwnedArray[map_id].clears = 1;
  421. runMap();
  422. if (breeding < (_getMinimumBreeding() + 1)) fightManual();
  423. }
  424. } else {
  425. if (game.global.currentMapId !== '') {
  426. var lastMapCell = game.global.mapGridArray[game.global.mapGridArray.length - 1];
  427. var specialGift = '';
  428. if (lastMapCell.special !== '') {
  429. specialGift = game.mapUnlocks[lastMapCell.special];
  430. }
  431. var needExitMap = (specialGift === '' || specialGift.prestige !== true) &&
  432. lastMapCell.special !== 'Heirloom' &&
  433. lastMapCell.name !== 'Warden' &&
  434. lastMapCell.name !== 'Robotrimp' &&
  435. specialGift.canRunOnce !== true;
  436. if (needExitMap) {
  437. mapsClicked(true); // go to maps
  438. recycleMap(-1, true);
  439. mapsClicked(); // go to world
  440. }
  441. }
  442. }
  443. }
  444. }
  445. };
  446.  
  447. var _mapDeleter = function() {
  448. if (game.global.currentMapId === '') {
  449. for (var x in game.global.mapsOwnedArray) {
  450. var map = game.global.mapsOwnedArray[x];
  451. if (map.level < (game.global.world - 10) && map.noRecycle !== true) {
  452. game.global.lookingAtMap = map['id'];
  453. _log('Deleting map ' + map.name + ' (' + map.level + ')');
  454. recycleMap(-1, true);
  455. break;
  456. }
  457. }
  458. }
  459. };
  460.  
  461. var _auto = function () {
  462. if (_isPortal()) return;
  463. _earlyGameStrategy(false);
  464.  
  465. _autoUpgrade();
  466. _autoBuy();
  467. _autoEquipment();
  468. _mapAttackStrategy();
  469.  
  470. _middleGameStrategy();
  471.  
  472. _mapDeleter();
  473. };
  474.  
  475. var _onStartButton = function () {
  476. if (isStarted) {
  477. _stop();
  478. _log('Stop.');
  479. isStarted = false;
  480. } else {
  481. _start();
  482. _log('Started!');
  483. isStarted = true;
  484. }
  485. };
  486.  
  487. var _autoUpgrade = function () {
  488. for (var item in game.upgrades) {
  489. if (game.upgrades.hasOwnProperty(item)) {
  490. var upgrade = game.upgrades[item];
  491. if (parseInt(upgrade.locked) === 1) continue;
  492. var canAfford = canAffordTwoLevel(upgrade);
  493. if (canAfford) {
  494. if (item === "Coordination") {
  495. if (!canAffordCoordinationTrimps()) continue;
  496. }
  497. if (item === "Gigastation") {
  498. var minAddon = Math.floor(game.global.highestLevelCleared / 6);
  499. var minWaprstation = Math.floor(game.global.world / 6) + minAddon + game.upgrades.Gigastation.done * 2;
  500. if (minWaprstation < 6 + minAddon) minWaprstation = 6 + minAddon;
  501. if (game.buildings.Warpstation.owned < minWaprstation) continue;
  502. }
  503. buyUpgrade(item, true, true);
  504. _log('Upgrading ' + item);
  505. _selectAutoJob();
  506. return 1;
  507. }
  508. }
  509. }
  510. return 0;
  511. };
  512.  
  513. var getUpgradePrice = function (upgradeObject) {
  514. var price, result = {};
  515. for (var cost in upgradeObject.cost) {
  516. if (upgradeObject.cost.hasOwnProperty(cost)) {
  517. if (typeof upgradeObject.cost[cost] === 'object' && typeof upgradeObject.cost[cost][1] === 'undefined') {
  518. var costItem = upgradeObject.cost[cost];
  519. for (var item in costItem) {
  520. if (costItem.hasOwnProperty(item)) {
  521. price = costItem[item];
  522. if (upgradeObject.prestiges && (item === "metal" || item === "wood")) {
  523. if (game.global.challengeActive === "Daily" && typeof game.global.dailyChallenge.metallicThumb !== 'undefined') {
  524. price *= dailyModifiers.metallicThumb.getMult(game.global.dailyChallenge.metallicThumb.strength);
  525. }
  526. price *= Math.pow(1 - game.portal.Artisanistry.modifier, game.portal.Artisanistry.level);
  527. }
  528. if (typeof price === 'function') price = price();
  529. if (typeof price[1] !== 'undefined') price = resolvePow(price, upgradeObject);
  530. result[item] = price;
  531. }
  532. }
  533. }
  534. }
  535. }
  536. return result;
  537. };
  538.  
  539. var _getAllUpgradePrice = function () {
  540. var totalPrice = {};
  541. for (var item in game.upgrades) {
  542. if (game.upgrades.hasOwnProperty(item)) {
  543. var upgrade = game.upgrades[item];
  544. if (parseInt(upgrade.locked) === 1) continue;
  545. var price = getUpgradePrice(upgrade);
  546. for (var res in price) {
  547. if (price.hasOwnProperty(res)) {
  548. if (typeof totalPrice[res] === 'undefined') totalPrice[res] = 0;
  549. totalPrice[res] += price[res];
  550. }
  551. }
  552. }
  553. }
  554. return totalPrice;
  555. };
  556.  
  557. var _getUpgradePriceSumForRes = function (res) {
  558. var totalPrice = _getAllUpgradePrice();
  559. if (typeof totalPrice[res] !== 'undefined') {
  560. return totalPrice[res];
  561. } else {
  562. return 0;
  563. }
  564. };
  565.  
  566. var _getMaximumResourceUpgradePrice = function () {
  567. var totalPrice = _getAllUpgradePrice(), maxPriceName = '', maxPrice = 0;
  568. for (var res in totalPrice) {
  569. if (totalPrice.hasOwnProperty(res)) {
  570. if (totalPrice[res] > maxPrice) {
  571. maxPrice = totalPrice[res];
  572. maxPriceName = res;
  573. }
  574. }
  575. }
  576. var result = {};
  577. if (maxPriceName !== '') {
  578. result[maxPriceName] = maxPrice;
  579. return result;
  580. } else {
  581. return false;
  582. }
  583. };
  584.  
  585. var _autoBuy = function () {
  586. var toBuy;
  587. for (var item in game.buildings) {
  588. if (item === 'Barn' || item === 'Shed' || item === 'Forge' || item === 'Wormhole' || item === 'Trap') continue;
  589. if (!game.buildings.Collector.locked &&
  590. (item === 'Mansion' || item === 'Hotel' || item === 'Resort' || item === 'House' || item === 'Hut')) continue;
  591. if (game.upgrades.Gigastation.done >= 10 && item === 'Collector') continue;
  592.  
  593. if (game.buildings.hasOwnProperty(item)) {
  594. if (parseInt(game.buildings[item].locked) === 1) continue;
  595. var canAfford = canAffordBuilding(item, false, false, false, true);
  596. if (canAfford) {
  597. if (item === 'Nursery') {
  598. var isElectro = game.global.challengeActive === "Electricity";
  599. var mult = game.global.brokenPlanet ? (game.global.world >= 80 ? 2 : 1.5) : 1;
  600. var enoughNursery = (game.buildings.Nursery.owned >= (game.buildings.Tribute.owned * mult) ||
  601. game.buildings.Nursery.owned >= (game.buildings.Gym.owned * mult));
  602.  
  603. if ((isElectro || !enoughNursery) && !_hasInQueue('Nursery'))
  604. {
  605. toBuy = item;
  606. }
  607. } else {
  608. toBuy = item;
  609. }
  610. }
  611. }
  612. }
  613. if (typeof toBuy !== 'undefined') {
  614. buyBuilding(toBuy, true, true);
  615. _log('Building ' + toBuy);
  616. return 1;
  617. } else {
  618. return 0;
  619. }
  620. };
  621.  
  622. var needFarmer = 25, needLumber = 25, needMiner = 25, needScientist = 1;
  623. var needAllMax = needFarmer + needLumber + needMiner + needScientist;
  624.  
  625. var _buyJobs = function ($obj, unemployed, objName, jobId) {
  626. if ($obj.length > 0) {
  627. var breeding = _getBreeding();
  628. var cnt = 1;
  629. var minBreeding = _getMinimumBreeding();
  630. if (unemployed > needAllMax * 1000000000 && (breeding - 10000000000 > minBreeding)) {
  631. game.global.buyAmt = 10000000000;
  632. cnt = 10000000000;
  633. }
  634. else if (unemployed > needAllMax * 100000000 && (breeding - 1000000000 > minBreeding)) {
  635. game.global.buyAmt = 1000000000;
  636. cnt = 1000000000;
  637. }
  638. else if (unemployed > needAllMax * 10000000 && (breeding - 100000000 > minBreeding)) {
  639. game.global.buyAmt = 100000000;
  640. cnt = 100000000;
  641. }
  642. else if (unemployed > needAllMax * 1000000 && (breeding - 10000000 > minBreeding)) {
  643. game.global.buyAmt = 10000000;
  644. cnt = 10000000;
  645. }
  646. else if (unemployed > needAllMax * 100000 && (breeding - 1000000 > minBreeding)) {
  647. game.global.buyAmt = 1000000;
  648. cnt = 1000000;
  649. }
  650. else if (unemployed > needAllMax * 10000 && (breeding - 100000 > minBreeding)) {
  651. game.global.buyAmt = 100000;
  652. cnt = 100000;
  653. }
  654. else if (unemployed > needAllMax * 1000 && (breeding - 10000 > minBreeding)) {
  655. game.global.buyAmt = 10000;
  656. cnt = 10000;
  657. }
  658. else if (unemployed > needAllMax * 100 && (breeding - 1000 > minBreeding)) {
  659. game.global.buyAmt = 1000;
  660. cnt = 1000;
  661. }
  662. else if (unemployed > needAllMax * 10 && (breeding - 100 > minBreeding)) {
  663. numTab(4);
  664. cnt = 100;
  665. }
  666. else if (unemployed > needAllMax * 2.5 && (breeding - 25 > minBreeding)) {
  667. numTab(3);
  668. cnt = 25;
  669. }
  670. else if (unemployed > needAllMax && (breeding - 10 > minBreeding)) {
  671. numTab(2);
  672. cnt = 10;
  673. }
  674. else {
  675. numTab(1);
  676. cnt = 1;
  677. }
  678. buyJob(jobId, true, true); // confirmed, noTip
  679. numTab(1); // +1
  680. _log('New ' + objName + (cnt > 1 ? " x" + cnt : ''), 'Combat');
  681. return cnt;
  682. } else {
  683. return 0;
  684. }
  685. };
  686.  
  687. var _autoJobs = function () {
  688. var breeding = game.resources.trimps.owned - game.resources.trimps.employed;
  689. if (breeding < (_getMinimumBreeding() + 1) && game.global.challengeActive !== 'Trapper') return;
  690.  
  691. var jobsTotal =
  692. game.jobs.Farmer.owned +
  693. game.jobs.Lumberjack.owned +
  694. game.jobs.Miner.owned +
  695. game.jobs.Scientist.owned;
  696.  
  697. var maxTrimps = game.resources.trimps.realMax();
  698. var unemployed = Math.ceil(maxTrimps / 2) - game.resources.trimps.employed;
  699.  
  700. var trainerCost = _getJobPrice('Trainer', 'food');
  701. if ((trainerCost < game.resources.food.owned) && unemployed <= 0 && game.jobs.Farmer.owned > 1 && game.jobs.Trainer.locked === 0) {
  702. _log('Fire farmer, sorry');
  703. game.global.firing = true;
  704. buyJob('Farmer', true, true);
  705. game.global.firing = false;
  706. }
  707.  
  708. if (unemployed <= 0) return;
  709.  
  710. if (trainerCost <= game.resources.food.owned && game.jobs.Trainer.locked === 0) {
  711. buyJob('Trainer', true, true);
  712. _log('New trainer');
  713. return 1;
  714. }
  715.  
  716. if (game.jobs.Geneticist.locked === 0 && _getBreedingTotalSpeed() > maxTrimps * 2) {
  717. buyJob('Geneticist', true, true);
  718. _log('New geneticist');
  719. return 1;
  720. }
  721.  
  722. var cnt = 0;
  723. var $jobsBlock = $('#jobsHere');
  724.  
  725. var $explorer = $jobsBlock.find('.thingColorCanAfford[id=Explorer]');
  726. if ($explorer.length > 0) {
  727. buyJob('Explorer', true, true);
  728. _log('New explorer');
  729. return ++cnt;
  730. }
  731.  
  732. var hasFarmer = game.jobs.Farmer.locked === 0;
  733. var hasLumber = game.jobs.Lumberjack.locked === 0;
  734. var hasMiner = game.jobs.Miner.locked === 0;
  735. var hasScientist = game.jobs.Scientist.locked === 0;
  736. var needAll =
  737. (hasFarmer ? needFarmer : 0) +
  738. (hasLumber ? needLumber : 0) +
  739. (hasMiner ? needMiner : 0) +
  740. (hasScientist ? needScientist : 0);
  741. if (needAll < 1) needAll = 1;
  742.  
  743. var minOwned = Math.min(
  744. game.jobs.Farmer.owned,
  745. game.jobs.Lumberjack.owned,
  746. game.jobs.Miner.owned);
  747. if (minOwned > 30) minOwned = 30; // for science
  748.  
  749. var $science = $jobsBlock.find('.thingColorCanAfford[id=Scientist]');
  750. var $farmer = $jobsBlock.find('.thingColorCanAfford[id=Farmer]');
  751.  
  752. if (hasScientist && game.jobs.Scientist.owned < minOwned) {
  753. cnt += _buyJobs($science, unemployed, 'scientist', 'Scientist');
  754. } else if (hasFarmer && game.jobs.Farmer.owned < Math.floor(jobsTotal * needFarmer / needAll)) {
  755. cnt += _buyJobs($farmer, unemployed, 'farmer', 'Farmer');
  756. } else if (hasLumber && game.jobs.Lumberjack.owned < Math.floor(jobsTotal * needLumber / needAll)) {
  757. var $lumber = $jobsBlock.find('.thingColorCanAfford[id=Lumberjack]');
  758. cnt += _buyJobs($lumber, unemployed, 'lumberjack', 'Lumberjack');
  759. } else if (hasMiner && game.jobs.Miner.owned < Math.floor(jobsTotal * needMiner / needAll)) {
  760. var $miner = $jobsBlock.find('.thingColorCanAfford[id=Miner]');
  761. cnt += _buyJobs($miner, unemployed, 'miner', 'Miner');
  762. } else if (hasScientist && game.jobs.Scientist.owned < Math.floor(jobsTotal * needScientist / needAll)) {
  763. cnt += _buyJobs($science, unemployed, 'scientist', 'Scientist');
  764. }
  765.  
  766. if (unemployed > 0 && cnt === 0) {
  767. cnt += _buyJobs($farmer, unemployed, 'farmer', 'Farmer');
  768. }
  769.  
  770. return cnt;
  771. };
  772.  
  773. var _styleUpdate = function () {
  774. // remove counts
  775. //noinspection CssUnusedSymbol
  776. $('head').append($("<style type=\"text/css\">\n" +
  777. "span.thingName{font-size:85%;}\n"+
  778. ".queueItem,.btn{padding:0}\n" +
  779. ".thingColorCanNotAfford.upgradeThing{background-color:#530053;}\n" +
  780. "#battleSideTitle{padding:0}\n" +
  781. ".battleSideBtnContainer{margin-top:0;}\n" +
  782. "#logBtnGroup{display:none}\n" +
  783. "#log{height:100%;}\n" +
  784. ".glyphicon-apple{color:orangered;}\n" +
  785. ".glyphicon-tree-deciduous{color:limegreen;}\n"+
  786. ".icomoon.icon-cubes{color:silver;}\n"+
  787. ".icomoon.icon-diamond{color:white;}\n"+
  788. "#buildingsTitleDiv,#upgradesTitleDiv,#equipmentTitleDiv{display:none}\n"+
  789. "#buildingsQueue{height:30px}\n"+
  790. "#buyHere .alert.badge{display:none}\n"+
  791. '</style>'));
  792.  
  793. // remove tabs
  794. $('#buyTabs').hide();
  795. filterTabs('all');
  796. // fix height
  797. $('#topRow,#queueContainer').css('margin-bottom', '0');
  798. $('#jobsTitleDiv').css('padding', '0').css('font-size', 'smaller');
  799. $('#buyHere').css('margin', '0').css('padding', '0').css('overflow-x', 'hidden');
  800. $('#queueContainer').css('height', '70px');
  801. $('#numTabs').css('margin', '0');
  802. $('#buyContainer').css('height', 'calc(99vh - 20vw - 96px)');
  803. // add button
  804. $('#settingsTable').find('tr').append('<td class="btn btn-info" id="botStart" title="' + version + '">Bot start</td>');
  805. $('#botStart').on('click', _onStartButton);
  806. // add grid
  807. var $grid = $('<table style="width:100%;margin-top:4px;font-size:smaller;"><tr>' +
  808. '<td id="magnimp-cell"><span class="glyphicon glyphicon-magnet"></span><label style="margin-left:4px" title="Magimp">...</label></td>' +
  809. '<td id="venimp-cell"><span class="glyphicon glyphicon-glass"></span><label style="margin-left:4px" title="Venimp">...</label></td>' +
  810. '</tr><tr>' +
  811. '<td id="whipimp-cell"><span class="glyphicon glyphicon-star"></span><label style="margin-left:4px" title="Whipimp">...</label></td>' +
  812. '<td id="titimp-cell"><span class="icomoon icon-hammer"></span><label style="margin-left:4px" title="Titimp">' + prettify(game.global.titimpLeft) + '</label></td>' +
  813. '</tr></table>');
  814. $('#battleBtnsColumn').append($grid);
  815. _updateSuperTrimps();
  816. };
  817.  
  818. var _styleFix = function () {
  819. _disableLog();
  820.  
  821. var $buyBoxThings = $('.buyBox').find('.thing');
  822. $buyBoxThings.find('br').remove();
  823. $buyBoxThings.find('.thingOwned').css('margin-left', '4px');
  824.  
  825. /*for (var x in game.upgrades) {
  826. if (game.upgrades.hasOwnProperty(x)) {
  827. if (game.upgrades[x].alert && game.upgrades[x].locked === 0) game.upgrades[x].alert = false;
  828. }
  829. }
  830. for (x in game.buildings) {
  831. if (game.buildings.hasOwnProperty(x)) {
  832. if (game.buildings[x].alert && game.buildings[x].locked === 0) game.buildings[x].alert = false;
  833. }
  834. }
  835. for (x in game.jobs) {
  836. if (game.jobs.hasOwnProperty(x)) {
  837. if (game.jobs[x].alert && game.jobs[x].locked === 0) game.jobs[x].alert = false;
  838. }
  839. }*/
  840.  
  841. $('#buildingsTitleDiv,#upgradesTitleDiv,#equipmentTitleDiv').css('display', 'none');
  842.  
  843. if (typeof game.passedMaps === 'undefined') game.passedMaps = {};
  844. if (typeof game.mapsAttacked === 'undefined') game.mapsAttacked = {};
  845.  
  846. for (var x in game.passedMaps) if (x > game.global.world) {
  847. // Game restart?
  848. game.passedMaps = {};
  849. game.mapsAttacked = {};
  850. $('#venimp-cell').find('label').text('...');
  851. $('#magnimp-cell').find('label').text('...');
  852. $('#whipimp-cell').find('label').text('...');
  853. break;
  854. }
  855.  
  856. var hasItem = false;
  857. if (typeof game.mapUnlocks === 'undefined') {
  858. clearInterval(tStyleFix);
  859. tStyleFix = setInterval(_styleFix, 2000);
  860. } else {
  861. for (x in game.mapUnlocks) {
  862. if (game.mapUnlocks.hasOwnProperty(x)) {
  863. var notPass = game.mapUnlocks[x].startAt <= game.global.world && (typeof game.passedMaps[game.mapUnlocks[x].startAt] === 'undefined' || game.passedMaps[game.mapUnlocks[x].startAt] < 1);
  864. if (notPass) {
  865. $('#battleSideTitle').css('background-color', notPass ? '#A00' : '#600');
  866. hasItem = true;
  867. break;
  868. }
  869. }
  870. }
  871. }
  872. if (!hasItem) {
  873. $('#battleSideTitle').css('background-color', 'transparent');
  874. }
  875. game.passedMaps[game.global.world] = game.global.mapBonus;
  876. if (game.global.mapBonus > 0) {
  877. for (x in game.mapUnlocks) {
  878. if (game.mapUnlocks.hasOwnProperty(x)) {
  879. if (game.mapUnlocks[x].startAt < game.global.world) {
  880. game.passedMaps[game.mapUnlocks[x].startAt] = 1;
  881. }
  882. }
  883. }
  884. }
  885. };
  886.  
  887. var _start = function () {
  888. _log('Passive watcher stop');
  889. clearInterval(tPassiveWatcher);
  890.  
  891. _log('BOT start version ' + version);
  892. tAutoBuy = setInterval(_auto, 1000);
  893.  
  894. $('#botStart').text('Bot stop');
  895. };
  896.  
  897. var _stop = function () {
  898. _log('BOT stop');
  899. clearInterval(tAutoBuy);
  900.  
  901. tPassiveWatcher = setInterval(_passiveWatcher, 1000);
  902. _log('Passive watcher started');
  903.  
  904. $('#botStart').text('Bot start');
  905. };
  906.  
  907. var logEnabled = true, tTitimp;
  908.  
  909. var _updateSuperTrimps = function () {
  910. var whipStrength = Math.pow(1.003, game.unlocks.impCount.Whipimp);
  911. whipStrength = prettify((whipStrength - 1) * 100) + "%";
  912. var magimpStrength = Math.pow(1.003, game.unlocks.impCount.Magnimp);
  913. magimpStrength = prettify((magimpStrength - 1) * 100) + "%";
  914. var venimpStrength = Math.pow(1.003, game.unlocks.impCount.Venimp);
  915. venimpStrength = prettify((venimpStrength - 1) * 100) + "%";
  916.  
  917. var mag = $('#magnimp-cell').find('label');
  918. if (mag.text() !== magimpStrength) mag.text(magimpStrength);
  919. var whip = $('#whipimp-cell').find('label');
  920. if (whip.text() !== whipStrength) whip.text(whipStrength);
  921. var ven = $('#venimp-cell').find('label');
  922. if (ven.text() !== venimpStrength) ven.text(venimpStrength);
  923. };
  924.  
  925. var _disableLog = function () {
  926. if (logEnabled) {
  927. message = function (messageString, type, lootIcon, extraClass, extraTag, htmlPrefix) {
  928. if (type === 'Loot' && lootIcon === null) return;
  929. if (type === 'Combat' && (lootIcon === null || typeof lootIcon === 'undefined')) return;
  930. if (type === 'Loot' &&
  931. (messageString.indexOf('You just found') > -1 ||
  932. messageString.indexOf('You found') > -1 ||
  933. messageString.indexOf('That guy just left') > -1 ||
  934. (messageString.indexOf(' dropped ') > -1 && messageString.indexOf('That ') > -1) ||
  935. messageString.indexOf(' manage to ') > -1 ||
  936. messageString.indexOf('Then he died') > -1 ||
  937. messageString.indexOf(' popped out!') > -1 ||
  938. messageString.indexOf('That Feyimp gave you') > -1 ||
  939. messageString.indexOf('in that dead Tauntimp') > -1 ||
  940. messageString.indexOf('fragments from that Flutimp') > -1 ||
  941. messageString.indexOf('That Jestimp gave you') > -1 ||
  942. messageString.indexOf('That Titimp made your Trimps super strong') > -1 ||
  943. messageString.indexOf('You scored ') > -1 ||
  944. messageString.indexOf('Hulking Mutimp ') > -1 ||
  945. messageString.indexOf('Cubist art is your favorite!') > -1 ||
  946. messageString.indexOf('Reward encountered: ') > -1 ||
  947. messageString.indexOf('Findings: ') > -1 ||
  948. messageString.indexOf('Salvage results: ') > -1 ||
  949. messageString.indexOf('You hear nearby Kittimps ') > -1
  950. )) return;
  951. if (type === 'Story' && typeof lootIcon === 'undefined' &&
  952. messageString.indexOf('BOT: New ') > -1) return;
  953. var showTimestamps = parseInt(game.options.menu.timestamps.enabled) === 1;
  954. if (type === 'Notices' && messageString === 'Game Saved!') {
  955. var t = showTimestamps ? getCurrentTime() : updatePortalTimer(true);
  956. $('#saveIndicator').find('.autosaving').text(t);
  957. return;
  958. }
  959. if (messageString.indexOf('The ground up Venimp now increases your Trimps') > -1) {
  960. _updateSuperTrimps();
  961. return;
  962. }
  963. if (messageString.indexOf('You killed a Magnimp! The strong magnetic forces now increase your loot by') > -1) {
  964. _updateSuperTrimps();
  965. return;
  966. }
  967. if (messageString.indexOf('Seeing the Whipimps fall is causing all of your Trimps to work') > -1) {
  968. _updateSuperTrimps();
  969. return;
  970. }
  971.  
  972. var log = document.getElementById("log");
  973. var displayType = "block";
  974. var prefix = "";
  975. var addId = "";
  976. if (messageString === "Game Saved!" || extraClass === 'save') {
  977. addId = " id='saveGame'";
  978. if (document.getElementById('saveGame') !== null) {
  979. log.removeChild(document.getElementById('saveGame'));
  980. }
  981. }
  982. if (game.options.menu.timestamps.enabled) {
  983. messageString = (showTimestamps ? getCurrentTime() : updatePortalTimer(true)) + " " + messageString;
  984. }
  985. if (!htmlPrefix) {
  986. if (lootIcon && lootIcon.charAt(0) === "*") {
  987. lootIcon = lootIcon.replace("*", "");
  988. prefix = "icomoon icon-";
  989. }
  990. else prefix = "glyphicon glyphicon-";
  991. if (type === "Story") messageString = "<span class='glyphicon glyphicon-star'></span> " + messageString;
  992. if (type === "Combat") messageString = "<span class='glyphicon glyphicon-flag'></span> " + messageString;
  993. if (type === "Loot" && lootIcon) messageString = "<span class='" + prefix + lootIcon + "'></span> " + messageString;
  994. if (type === "Notices") {
  995. messageString = "<span class='glyphicon glyphicon-off'></span> " + messageString;
  996. }
  997. } else {
  998. messageString = htmlPrefix + " " + messageString;
  999. }
  1000. var messageHTML = "<span" + addId + " class='" + type + "Message message" + " " + extraClass + "' style='display: " + displayType + "'>" + messageString + "</span>";
  1001. pendingLogs.all.push(messageHTML);
  1002. postMessages();
  1003.  
  1004. var $allLogs = $('#log').find('span');
  1005. $allLogs.slice(0, -30).remove();
  1006. };
  1007. logEnabled = false;
  1008. }
  1009. };
  1010.  
  1011. var _titimpUpdate = function () {
  1012. $('#titimp-cell').find('label').text(prettify(game.global.titimpLeft > 0 ? game.global.titimpLeft : 0));
  1013. };
  1014.  
  1015. setTimeout(function () {
  1016. _log('Trimps BOT version ' + version);
  1017.  
  1018. tStyleFix = setInterval(_styleFix, 2000);
  1019. tTitimp = setInterval(_titimpUpdate, 500);
  1020.  
  1021. _styleUpdate();
  1022. _styleFix();
  1023.  
  1024. _disableLog();
  1025.  
  1026. _stop(); // start passive watcher
  1027. }, 1000);
  1028.  
  1029. })();