Trimps tools

Trimps tools (visual)

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

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