Trimps tools

Trimps tools (visual)

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

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