Trimps tools

Trimps tools (visual)

目前为 2017-04-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Trimps tools
  3. // @namespace trimps.github.io
  4. // @version 1.153
  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. var trimps = game.resources.trimps;
  33. var base = 0.0085;
  34. var breeding = trimps.owned - trimps.employed;
  35. var currentCalc = breeding * base;
  36. if (game.upgrades.Potency.done > 0) {
  37. var potencyStrength = Math.pow(1.1, game.upgrades.Potency.done);
  38. currentCalc *= potencyStrength;
  39. }
  40. return currentCalc;
  41. }
  42.  
  43. var _autoEquipment = function() {
  44. for (var x in game.equipment) {
  45. if (game.equipment.hasOwnProperty(x) && game.equipment[x].locked === 0) {
  46. var maxLevel = game.equipment[x].prestige > 5 ? 1 : (6 - game.equipment[x].prestige) * 2;
  47. if (game.equipment[x].level < maxLevel && canAffordBuilding(x, null, null, true)) {
  48. buyEquipment(x, true, true);
  49. _log('Upgrading equipment ' + x);
  50. }
  51. }
  52. }
  53. }
  54.  
  55. var _buyStorage = function() {
  56. var barnThreshold = 0.9; /*percentage at which minimum*/
  57. var shedThreshold = 0.9; /*to buy storage*/
  58. var forgeThreshold = 0.9; /*from 0 (min) to 1 (max)*/
  59.  
  60. if(game.resources.food.owned / (game.resources.food.max * (1 + game.portal.Packrat.level * (game.portal.Packrat.modifier * 100) / 100)) >= barnThreshold) {
  61. buyBuilding("Barn", true, true);
  62. _log('Building Barn');
  63. }
  64. if(game.resources.wood.owned / (game.resources.wood.max * (1 + game.portal.Packrat.level * (game.portal.Packrat.modifier * 100) / 100)) >= shedThreshold) {
  65. buyBuilding("Shed", true, true);
  66. _log('Building Shed');
  67. }
  68. if(game.resources.metal.owned / (game.resources.metal.max * (1 + game.portal.Packrat.level * (game.portal.Packrat.modifier * 100) / 100)) >= forgeThreshold) {
  69. buyBuilding("Forge", true, true);
  70. _log('Building Forge');
  71. }
  72. }
  73.  
  74. var _earlyGameStrategy = function() {
  75. if (_isPortal()) return;
  76.  
  77. var playerStrength = getPlayerModifier();
  78. var minimumSpeedToHelp = 1 + playerStrength;
  79. if (game.global.eggLoc != -1) {
  80. _log('Destroying Easter Egg');
  81. easterEggClicked();
  82. }
  83.  
  84. _buyStorage();
  85. _autoJobs();
  86.  
  87. var trimps = game.resources.trimps;
  88. var breeding = trimps.owned - trimps.employed;
  89. var unemployed = Math.ceil(game.resources.trimps.realMax() / 2) - game.resources.trimps.employed;
  90.  
  91. if (game.buildings.Trap.owned >= 1 && game.resources.trimps.owned < game.resources.trimps.realMax() &&
  92. (breeding < 5 || unemployed > 0) &&
  93. _getBreedingBaseSpeed() < 1)
  94. {
  95. setGather('trimps');
  96. return;
  97. }
  98.  
  99. if ((game.global.buildingsQueue.length > 0 && game.global.autoCraftModifier < 1) || (game.global.buildingsQueue.length > 5)) {
  100. setGather('buildings');
  101. return;
  102. }
  103.  
  104. if (getPsString('food', true) < minimumSpeedToHelp && game.resources.food.owned < 10) {
  105. setGather('food');
  106. return;
  107. }
  108.  
  109. if (getPsString('wood', true) < minimumSpeedToHelp && game.resources.wood.owned < 10) {
  110. setGather('wood');
  111. return;
  112. }
  113.  
  114. if (game.buildings.Trap.owned < 1 && game.resources.food.owned >= 10 && game.resources.wood.owned >= 10) {
  115. buyBuilding('Trap', true, true);
  116. return;
  117. }
  118.  
  119. if (getPsString('science', true) < minimumSpeedToHelp && game.resources.science.owned < 10) {
  120. setGather('science');
  121. return;
  122. }
  123.  
  124. if (getPsString('metal', true) < minimumSpeedToHelp && game.resources.metal.owned < 100) {
  125. setGather('metal');
  126. return;
  127. }
  128.  
  129. var needScientist = game.upgrades.Scientists.done === 0 && game.upgrades.Scientists.allowed === 1;
  130. if (getPsString('science', true) < minimumSpeedToHelp && (game.resources.science.owned < 60 || needScientist)) {
  131. setGather('science');
  132. return;
  133. }
  134.  
  135. if ((game.global.playerGathering == 'trimps' && (game.buildings.Trap.owned === 0 || _getBreedingBaseSpeed() > 1)) ||
  136. (game.global.playerGathering == 'buildings' && (game.global.buildingsQueue.length === 0 || game.global.autoCraftModifier >= 1)))
  137. {
  138. setGather('science');
  139. }
  140. }
  141.  
  142. var _passiveWatcher = function() {
  143. if (_isPortal()) return;
  144.  
  145. _earlyGameStrategy();
  146. }
  147.  
  148. var mapsAttacked = {};
  149. var _needAttackCurrentMap = function() {
  150. return (typeof mapsAttacked[game.global.world] === 'undefined');
  151. }
  152. var _hasMapOfCurrentLevel = function() {
  153. for (var x in game.global.mapsOwnedArray) {
  154. if (game.global.mapsOwnedArray.hasOwnProperty(x)) {
  155. var mapObj = game.global.mapsOwnedArray[x];
  156. if (mapObj.level == game.global.world) return true;
  157. }
  158. }
  159. return false;
  160. }
  161.  
  162. var _mapAttackStrategy = function() {
  163. if (game.global.world < 6) return;
  164. if (game.global.preMapsActive) return;
  165. //if (!game.global.mapsUnlocked) return;
  166. if (game.global.pauseFight) {
  167. _log('Enabling auto attack!');
  168. fightManual();
  169. game.global.pauseFight = false;
  170. pauseFight(true); // update only
  171. } else {
  172. if (_needAttackCurrentMap()) {
  173. var currentMapPrice = updateMapCost(true);
  174. var money = game.resources.fragments.owned;
  175. if (!_hasMapOfCurrentLevel()) {
  176. if (money >= currentMapPrice) {
  177. var result = buyMap();
  178. if (result == 1) {
  179. _log('Bought new map level ' + game.global.world);
  180. }
  181. }
  182. }
  183. if (_hasMapOfCurrentLevel()) {
  184. console.log('need attack');
  185. } else {
  186. console.log('no map');
  187. }
  188. }
  189. //addSpecials(true, true, map) - возвращает количество вещей которые можно собрать на этой карте
  190. /*var mapFound = false, hasNotPass = false;
  191. var currentMap = game.global.currentMapId;
  192. for (var x in game.mapUnlocks) {
  193. var notPass = game.mapUnlocks[x].startAt <= game.global.world &&
  194. (typeof game.passedMaps[game.mapUnlocks[x].startAt] === 'undefined' || game.passedMaps[game.mapUnlocks[x].startAt] < 1);
  195. if (notPass) {
  196. hasNotPass = true;
  197. for (var map_id in game.global.mapsOwnedArray) {
  198. var map = game.global.mapsOwnedArray[map_id];
  199. if (map.clears === 0 && map.level <= game.global.world) {
  200. console.log('attacking ' + map.id + ' "' + map.name + '"');
  201. map.clears = 1;
  202. mapsClicked(true); // go to maps
  203. selectMap(map.id);
  204. mapFound = true;
  205. currentMap = '';
  206. break;
  207. } else if (map.clears > 0 && map.level >= game.global.world) {
  208. hasNotPass = false;
  209. mapFound = true;
  210. break;
  211. }
  212. }
  213. if (typeof game.passedMaps[game.mapUnlocks[x].startAt] === 'undefined' || game.passedMaps[game.mapUnlocks[x].startAt] === 0) {
  214. // need to clear map
  215. console.log('Need to clear map level ' + game.mapUnlocks[x].startAt);
  216. }
  217. }
  218. if (mapFound) break;
  219. }
  220. if (!mapFound && hasNotPass) {
  221. mapsClicked(true);
  222. buyMap(); // new map
  223. } else if (mapFound && hasNotPass) {
  224. setTimeout(function() {
  225. runMap();
  226. }, 500);
  227. }*/
  228. }
  229. }
  230.  
  231. var _auto = function() {
  232. if (_isPortal()) return;
  233. _earlyGameStrategy();
  234. _autoUpgrade();
  235. _autoBuy();
  236. _autoEquipment();
  237. _mapAttackStrategy();
  238. }
  239.  
  240. var _onStartButton = function() {
  241. if (isStarted) {
  242. _stop();
  243. _log('Stop.');
  244. isStarted = false;
  245. } else {
  246. _start();
  247. _log('Started!');
  248. isStarted = true;
  249. }
  250. }
  251.  
  252. var _styleUpdate = function() {
  253. // remove counts
  254. $('head').append('<style type="text/css">span.thingName{font-size:85%;}.queueItem,.btn{padding:0}.thingColorCanNotAfford.upgradeThing{background-color:#530053;}</style>');
  255. // remove tabs
  256. $('#buyTabs').hide();
  257. filterTabs('all');
  258. // remove captions
  259. $('#buildingsTitleDiv,#upgradesTitleDiv,#equipmentTitleDiv').hide();
  260. // fix height
  261. $('#topRow,#queueContainer').css('margin-bottom', '0');
  262. $('#jobsTitleDiv').css('padding', '0').css('font-size', 'smaller');
  263. $('#buyHere').css('margin', '0').css('padding', '0').css('overflow-x', 'hidden');
  264. $('#queueContainer').css('height', '70px');
  265. $('#numTabs').css('margin', '0');
  266. $('#buyContainer').css('height', 'calc(99vh - 20vw - 96px)');
  267. // add button
  268. $('#settingsTable tr').append('<td class="btn btn-info" id="botStart">Bot start</td>');
  269. $('#botStart').click(_onStartButton);
  270. }
  271.  
  272. var _autoUpgrade = function() {
  273. for (var item in game.upgrades){
  274. var upgrade = game.upgrades[item];
  275. if (upgrade.locked == 1) continue;
  276. var canAfford = canAffordTwoLevel(upgrade);
  277. if (canAfford) {
  278. if (item == "Coordination") {
  279. if (!canAffordCoordinationTrimps()) continue;
  280. }
  281. buyUpgrade(item, true, true);
  282. _log('Upgrading ' + item);
  283. return 1;
  284. }
  285. }
  286. return 0;
  287. }
  288.  
  289. var _autoBuy = function() {
  290. var toBuy;
  291. for (var item in game.buildings) {
  292. if (item == 'Barn' || item == 'Shed' || item == 'Forge' || item == 'Wormhole' || item == 'Trap') continue;
  293. building = game.buildings[item];
  294. if (building.locked == 1) continue;
  295. var canAfford = canAffordBuilding(item, false, false, false, true);
  296. if (canAfford) {
  297. if (item == 'Nursery') {
  298. if (game.buildings.Nursery.owned >= game.buildings.Tribute.owned ||
  299. game.buildings.Nursery.owned >= game.buildings.Gym.owned) continue;
  300. else toBuy = item;
  301. } else {
  302. toBuy = item;
  303. }
  304. }
  305. }
  306. if (typeof toBuy !== 'undefined') {
  307. buyBuilding(toBuy, true, true);
  308. _log('Building ' + toBuy);
  309. return 1;
  310. } else {
  311. return 0;
  312. }
  313. }
  314.  
  315. var needFarmer = 25, needLumber = 25, needMiner = 25, needScientist = 1;
  316. var needAllMax = needFarmer + needLumber + needMiner + needScientist;
  317.  
  318. var _buyJobs = function($obj, unemployed, objName, jobId) {
  319. if ($obj.length > 0) {
  320. var trimps = game.resources.trimps;
  321. var breeding = trimps.owned - trimps.employed;
  322. var cnt = 1;
  323. if (unemployed > needAllMax * 10 && (breeding - 100 > 5)) {numTab(4);cnt=100;}
  324. else if (unemployed > needAllMax * 2.5 && (breeding - 25 > 5)) {numTab(3);cnt=25;}
  325. else if (unemployed > needAllMax && (breeding - 10 > 5)) {numTab(2);cnt=10;}
  326. else {numTab(1);cnt=1;}
  327. buyJob(jobId, true, true); // confirmed, noTip
  328. numTab(1); // +1
  329. _log('New ' + objName + (cnt > 1 ? " x" + cnt : ''), 'Combat');
  330. return cnt;
  331. } else {
  332. return 0;
  333. }
  334. }
  335.  
  336. var _autoJobs = function() {
  337. var trimps = game.resources.trimps;
  338. var breeding = trimps.owned - trimps.employed;
  339. if (breeding < 6) return;
  340.  
  341. var jobsTotal =
  342. game.jobs.Farmer.owned +
  343. game.jobs.Lumberjack.owned +
  344. game.jobs.Miner.owned +
  345. game.jobs.Scientist.owned;
  346.  
  347. var unemployed = Math.ceil(game.resources.trimps.realMax() / 2) - game.resources.trimps.employed;
  348.  
  349. var trainerCost = _getJobPrice('Trainer', 'food');
  350. if ((trainerCost < game.resources.food.owned) && unemployed <= 0 && game.jobs.Farmer.owned > 1 && game.jobs.Trainer.locked === 0) {
  351. game.global.firing = true;
  352. _log('Fire farmer, sorry');
  353. buyJob('Farmer', true, true);
  354. game.global.firing = false;
  355. }
  356.  
  357. if (unemployed <= 0) return;
  358.  
  359. if (trainerCost <= game.resources.food.owned && game.jobs.Trainer.locked === 0) {
  360. buyJob('Trainer', true, true);
  361. _log('New trainer');
  362. return 1;
  363. }
  364.  
  365. var cnt = 0;
  366.  
  367. var $explorer = $('#jobsHere').find('.thingColorCanAfford[id=Explorer]');
  368. if ($explorer.length > 0) {
  369. buyJob('Explorer', true, true);
  370. _log('New explorer');
  371. return ++cnt;
  372. }
  373.  
  374. var hasFarmer = game.jobs.Farmer.locked === 0;
  375. var hasLumber = game.jobs.Lumberjack.locked === 0;
  376. var hasMiner = game.jobs.Miner.locked === 0;
  377. var hasScientist = game.jobs.Scientist.locked === 0;
  378. var needAll =
  379. (hasFarmer ? needFarmer : 0) +
  380. (hasLumber ? needLumber : 0) +
  381. (hasMiner ? needMiner : 0) +
  382. (hasScientist ? needScientist : 0);
  383. if (needAll < 1) needAll = 1;
  384.  
  385. var minOwned = Math.min(
  386. game.jobs.Farmer.owned,
  387. game.jobs.Lumberjack.owned,
  388. game.jobs.Miner.owned);
  389. if (minOwned > 30) minOwned = 30; // for science
  390.  
  391. if (hasScientist && game.jobs.Scientist.owned < minOwned) {
  392. var $science = $('#jobsHere').find('.thingColorCanAfford[id=Scientist]');
  393. cnt += _buyJobs($science, unemployed, 'scientist', 'Scientist');
  394. } else if (hasFarmer && game.jobs.Farmer.owned < (jobsTotal * needFarmer / needAll)) {
  395. var $farmer = $('#jobsHere').find('.thingColorCanAfford[id=Farmer]');
  396. cnt += _buyJobs($farmer, unemployed, 'farmer', 'Farmer');
  397. } else if (hasLumber && game.jobs.Lumberjack.owned < (jobsTotal * needLumber / needAll)) {
  398. var $lumber = $('#jobsHere').find('.thingColorCanAfford[id=Lumberjack]');
  399. cnt += _buyJobs($lumber, unemployed, 'lumberjack', 'Lumberjack');
  400. } else if (hasMiner && game.jobs.Miner.owned < (jobsTotal * needMiner / needAll)) {
  401. var $miner = $('#jobsHere').find('.thingColorCanAfford[id=Miner]');
  402. cnt += _buyJobs($miner, unemployed, 'miner', 'Miner');
  403. } else if (hasScientist && game.jobs.Scientist.owned < (jobsTotal * needScientist / needAll)) {
  404. var $science = $('#jobsHere').find('.thingColorCanAfford[id=Scientist]');
  405. cnt += _buyJobs($science, unemployed, 'scientist', 'Scientist');
  406. }
  407.  
  408. if (unemployed > 0 && cnt === 0) {
  409. $farmer = $('#jobsHere').find('.thingColorCanAfford[id=Farmer]');
  410. cnt += _buyJobs($farmer, unemployed, 'farmer', 'Farmer');
  411. }
  412.  
  413. return cnt;
  414. }
  415.  
  416. var _styleFix = function() {
  417. _disableLog();
  418. $('.buyBox').find('.thing').find('br').remove();
  419. $('.buyBox').find('.thing').find('.thingOwned').css('margin-left','4px');
  420. $('#buyHere').find('.alert.badge').text('');
  421. $('#buildingsQueue').css('height', '30px');
  422. for (var x in game.upgrades) if (game.upgrades[x].alert && game.upgrades[x].locked === 0) game.upgrades[x].alert = false;
  423. for (x in game.buildings) if (game.buildings[x].alert && game.buildings[x].locked === 0) game.buildings[x].alert = false;
  424. for (x in game.jobs) if (game.jobs[x].alert && game.jobs[x].locked === 0) game.jobs[x].alert = false;
  425.  
  426. var hasItem = false;
  427. if (typeof game.passedMaps === 'undefined') game.passedMaps = {};
  428. if (typeof game.mapUnlocks === 'undefined') {
  429. console.log('Waiting for game.mapUnlocks...');
  430. clearInterval(tStyleFix);
  431. tStyleFix = setInterval(_styleFix, 2000);
  432. } else {
  433. for (x in game.mapUnlocks) {
  434. var notPass = game.mapUnlocks[x].startAt <= game.global.world && (typeof game.passedMaps[game.mapUnlocks[x].startAt] === 'undefined' || game.passedMaps[game.mapUnlocks[x].startAt] < 1);
  435. if (notPass) {
  436. $('#battleSideTitle').css('background-color', notPass ? '#A00' : '#600');
  437. hasItem = true;
  438. break;
  439. }
  440. }
  441. }
  442. if (!hasItem) {
  443. $('#battleSideTitle').css('background-color', 'transparent');
  444. }
  445. game.passedMaps[game.global.world] = game.global.mapBonus;
  446. if (game.global.mapBonus > 0) {
  447. for (x in game.mapUnlocks) {
  448. if (game.mapUnlocks[x].startAt < game.global.world) {
  449. game.passedMaps[game.mapUnlocks[x].startAt] = 1;
  450. }
  451. }
  452. }
  453. }
  454.  
  455. var _start = function() {
  456. _log('Passive watcher stop');
  457. clearInterval(tPassiveWatcher);
  458.  
  459. _log('BOT start version ' + version);
  460. tAutoBuy = setInterval(_auto, 1000);
  461.  
  462. $('#botStart').text('Bot stop');
  463. }
  464.  
  465. var _stop = function() {
  466. _log('BOT stop');
  467. clearInterval(tAutoBuy);
  468.  
  469. tPassiveWatcher = setInterval(_passiveWatcher, 1000);
  470. _log('Passive watcher started');
  471.  
  472. $('#botStart').text('Bot start');
  473. }
  474.  
  475. var logEnabled = true, $oldLog;
  476.  
  477. var _disableLog = function() {
  478. if (logEnabled) {
  479. message = function(messageString, type, lootIcon, extraClass, extraTag, htmlPrefix) {
  480. if (type == 'Loot' && lootIcon === null) return;
  481. if (type == 'Combat' && (lootIcon === null || typeof lootIcon === 'undefined')) return;
  482. if (type == 'Loot' &&
  483. (messageString.indexOf('You just found') > -1 ||
  484. messageString.indexOf('You found') > -1 ||
  485. messageString.indexOf('That guy just left') > -1 ||
  486. (messageString.indexOf(' dropped ') > -1 && messageString.indexOf('That ') > -1) ||
  487. messageString.indexOf(' manage to ') > -1 ||
  488. messageString.indexOf('Then he died') > -1 ||
  489. messageString.indexOf('You scored ') > -1
  490. )) return;
  491. if (type == 'Story' && typeof lootIcon === 'undefined' &&
  492. messageString.indexOf('BOT: New ') > -1) return;
  493. if (type == 'Notices' && messageString == 'Game Saved!') {
  494. var t = ((game.options.menu.timestamps.enabled == 1) ? getCurrentTime() : updatePortalTimer(true));
  495. $('#saveIndicator').find('.autosaving').text(t);
  496. return;
  497. }
  498. if (console) console.log(type, lootIcon, messageString);
  499. var log = document.getElementById("log");
  500. var displayType = "block";
  501. var prefix = "";
  502. var addId = "";
  503. if (messageString == "Game Saved!" || extraClass == 'save') {
  504. addId = " id='saveGame'";
  505. if (document.getElementById('saveGame') !== null) {
  506. log.removeChild(document.getElementById('saveGame'));
  507. }
  508. }
  509. if (game.options.menu.timestamps.enabled){
  510. messageString = ((game.options.menu.timestamps.enabled == 1) ? getCurrentTime() : updatePortalTimer(true)) + " " + messageString;
  511. }
  512. if (!htmlPrefix) {
  513. if (lootIcon && lootIcon.charAt(0) == "*") {
  514. lootIcon = lootIcon.replace("*", "");
  515. prefix = "icomoon icon-";
  516. }
  517. else prefix = "glyphicon glyphicon-";
  518. if (type == "Story") messageString = "<span class='glyphicon glyphicon-star'></span> " + messageString;
  519. if (type == "Combat") messageString = "<span class='glyphicon glyphicon-flag'></span> " + messageString;
  520. if (type == "Loot" && lootIcon) messageString = "<span class='" + prefix + lootIcon + "'></span> " + messageString;
  521. if (type == "Notices"){
  522. messageString = "<span class='glyphicon glyphicon-off'></span> " + messageString;
  523. }
  524. } else {
  525. messageString = htmlPrefix + " " + messageString;
  526. }
  527. var messageHTML = "<span" + addId + " class='" + type + "Message message" + " " + extraClass + "' style='display: " + displayType + "'>" + messageString + "</span>";
  528. pendingLogs.all.push(messageHTML);
  529. postMessages();
  530. var $allLogs = $('#log').find('span');
  531. $allLogs.slice(0, -30).remove();
  532. };
  533. logEnabled = false;
  534. }
  535. }
  536.  
  537. setTimeout(function() {
  538.  
  539. _log('Trimps BOT version ' + version);
  540.  
  541. tStyleFix = setInterval(_styleFix, 2000);
  542.  
  543. _styleUpdate();
  544. _styleFix();
  545. _disableLog();
  546.  
  547. _stop(); // start passive watcher
  548.  
  549. }, 1000);
  550.  
  551. })();