Cookie clicker tools

Cookie clicker tools (visual)

当前为 2017-03-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Cookie clicker tools
  3. // @namespace orteil.dashnet.org
  4. // @version 2.088
  5. // @description Cookie clicker tools (visual)
  6. // @author Anton
  7. // @match http://orteil.dashnet.org/cookieclicker/*
  8. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. var log = [], logTitle = '<div class="section">Cookie clicker tools 2.088 is here!</div>', newLogs = 0;
  14.  
  15. var started = false, t2, t3, tClick, tClickFrenzy, oldTitle = '', tLog,
  16. tPriority;
  17.  
  18. var _history = function() {
  19. var hist = [];
  20. hist.push('2.088 - fix');
  21. hist.push('2.087 - fix buy unknown upgrades');
  22. hist.push('2.086 - clear log button');
  23. hist.push('2.085 - fix');
  24. hist.push('2.084 - buy unknown upgrades if their price is 0.1% of cookie storage');
  25. hist.push('2.083 - mouse upgrades is processed as Upgrades');
  26. hist.push('2.082 - start from scratch');
  27. hist.push('2.081 - fix');
  28. hist.push('2.080 - add history, add option "showTimeCompensate"');
  29. hist.push('2.079 - hide donate box');
  30. hist.push('2.078 - Kittens now is processed as Upgrades');
  31. hist.push('');
  32. hist.push('');
  33. return hist;
  34. }
  35.  
  36. var _getKittenPercentByUpgradeName = function(kName) {
  37. if (kName == 'Kitten helpers') return Game.milkProgress*0.1;
  38. if (kName == 'Kitten workers') return Game.milkProgress*0.125;
  39. if (kName == 'Kitten engineers') return Game.milkProgress*0.15;
  40. if (kName == 'Kitten overseers') return Game.milkProgress*0.175;
  41. if (kName == 'Kitten managers') return Game.milkProgress*0.2;
  42. if (kName == 'Kitten accountants') return Game.milkProgress*0.2;
  43. if (kName == 'Kitten specialists') return Game.milkProgress*0.2;
  44. if (kName == 'Kitten experts') return Game.milkProgress*0.2;
  45. if (kName == 'Kitten angels') return Game.milkProgress*0.1;
  46. return 0;
  47. }
  48.  
  49. var options = {
  50. bankStoragePercent: 100,
  51. showTimeCompensate: false
  52. };
  53. var _store = function(name, value) {
  54. if (typeof(Storage) !== "undefined") localStorage.setItem(name, value);
  55. };
  56. var _restore = function(name) {
  57. if (typeof(Storage) !== "undefined") return localStorage.getItem(name);
  58. else return undefined;
  59. };
  60.  
  61. var _getBuffMult = function () {
  62. var buffMult = 1;
  63. for (var buff in Game.buffs) {
  64. if (Game.buffs[buff] !== 0 && typeof Game.buffs[buff].multCpS !== 'undefined') {
  65. buffMult = buffMult * Game.buffs[buff].multCpS;
  66. }
  67. }
  68. return buffMult === 0 ? 1 : buffMult;
  69. };
  70.  
  71. var _getNormalCookiesPs = function () {
  72. return Game.cookiesPs / _getBuffMult();
  73. };
  74.  
  75. var _getMinimalMoney = function () {
  76. return Math.floor(_getNormalCookiesPs() * 42100 * options.bankStoragePercent / 100);
  77. };
  78.  
  79. var _getMoneyCanSpend = function () {
  80. var moneyCanSpend = Game.cookies - _getMinimalMoney();
  81. return moneyCanSpend;
  82. };
  83.  
  84. var priorityListObj = {}, priorityList = [], timeCompensateObj = {}, timeCompensateList = [];
  85. var _createPriorityList = function() {
  86. var moneyCanSpend = _getMoneyCanSpend();
  87. var money = Game.cookies;
  88. priorityList = [];
  89. priorityListObj = {};
  90. for (var g in Game.UpgradesById) {
  91. if (Game.UpgradesById[g].bought === 0 && Game.UpgradesById[g].unlocked == 1) {
  92. var isMultiplier = Game.UpgradesById[g].desc.indexOf('production multiplier') >= 0;
  93. var isDouble = Game.UpgradesById[g].desc.indexOf('<b>twice</b>') >= 0;
  94. var isDoubleGrandma = Game.UpgradesById[g].desc.indexOf('Grandmas are <b>twice</b>') >= 0;
  95. var isKitten = Game.UpgradesById[g].name.indexOf('Kitten ') >= 0;
  96. var isDoubleCursor = Game.UpgradesById[g].desc.indexOf('The mouse and cursors are <b>twice</b>') >= 0;
  97. var increasedMoney = 0;
  98. if (isDoubleCursor) {
  99. increasedMoney = Game.Objects['Cursor'].storedTotalCps;
  100. } else if (isKitten) {
  101. var kittenPercent = _getKittenPercentByUpgradeName(Game.UpgradesById[g].name);
  102. increasedMoney = _getNormalCookiesPs() * kittenPercent;
  103. } else if (isDoubleGrandma) {
  104. increasedMoney = Game.Objects['Grandma'].storedTotalCps;
  105. } else if (isMultiplier) {
  106. increasedMoney = _getNormalCookiesPs() * Game.UpgradesById[g].power / 100;
  107. } else if (isDouble) {
  108. increasedMoney = Game.UpgradesById[g].buildingTie.storedTotalCps;
  109. }
  110. var interest = increasedMoney > 0 ? Game.UpgradesById[g].basePrice / increasedMoney : '-';
  111. if (interest != '-') {
  112. priorityListObj[Math.floor(interest)] = {
  113. name: Game.UpgradesById[g].name,
  114. title: Game.UpgradesById[g].name + ' - ' + Beautify(Game.UpgradesById[g].basePrice),
  115. price: Game.UpgradesById[g].basePrice,
  116. cps: 1,
  117. type: 'upgrade',
  118. id: g
  119. };
  120. } else if (Game.UpgradesById[g].type == 'upgrade' && Game.UpgradesById[g].basePrice < moneyCanSpend) {
  121. interest = Game.UpgradesById[g].basePrice / moneyCanSpend * 1000;
  122. priorityListObj[Math.floor(interest)] = {
  123. name: Game.UpgradesById[g].name,
  124. title: Game.UpgradesById[g].name + ' - ' + Beautify(Game.UpgradesById[g].basePrice),
  125. price: Game.UpgradesById[g].basePrice,
  126. cps: 1,
  127. type: 'upgrade',
  128. id: g
  129. };
  130. }
  131. //priorityList.push(Game.UpgradesById[g].name + ' - ' + Beautify(Game.UpgradesById[g].basePrice) + ' (INTEREST: ' + Beautify(interest) + ')');
  132. }
  133. }
  134. for (var i in Game.ObjectsById) {
  135. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  136. if (Game.ObjectsById[i].locked === 0) {
  137. interest = Game.ObjectsById[i].price / Game.ObjectsById[i].storedCps;
  138. priorityListObj[Math.floor(interest)] = {
  139. name: Game.ObjectsById[i].name,
  140. title: Game.ObjectsById[i].name + ' - ' + Beautify(Game.ObjectsById[i].price),
  141. price: Game.ObjectsById[i].price,
  142. cps: Game.ObjectsById[i].storedCps,
  143. type: 'buy',
  144. id: i
  145. };
  146. //priorityList.push(Game.ObjectsById[i].name + ' - ' + Beautify(Game.ObjectsById[i].price) + ' (INTEREST: ' + Beautify(interest) + ')');
  147. }
  148. }
  149. }
  150. for (i in priorityListObj) {
  151. var prefix = priorityListObj[i].price < moneyCanSpend ? '!!! ' : (priorityListObj[i].price < money ? '! ' : '');
  152. var pp = Math.floor(moneyCanSpend / priorityListObj[i].price * 100);
  153. priorityList.push(prefix + priorityListObj[i].title + ' : ' + i + ' (' + pp + '%)');
  154. }
  155.  
  156. timeCompensateObj = {};
  157. timeCompensateList = [];
  158. for (i in priorityListObj) {
  159. var o = priorityListObj[i];
  160. if (o.type == 'buy') {
  161. var cpsWithPercent = (o.cps / _getNormalCookiesPs() + 1) * o.cps;
  162. var interestNew = o.price / cpsWithPercent;
  163. timeCompensateObj[Math.floor(interestNew)] = {
  164. name: o.name,
  165. title: o.title,
  166. price: o.price,
  167. cps: cpsWithPercent,
  168. type: 'buy',
  169. id: o.id
  170. };
  171. } else {
  172. timeCompensateObj[i] = o;
  173. }
  174. }
  175. for (i in timeCompensateObj) {
  176. prefix = timeCompensateObj[i].price < moneyCanSpend ? '!!! ' : (timeCompensateObj[i].price < money ? '! ' : '');
  177. timeCompensateList.push(prefix + timeCompensateObj[i].title + ' : ' + i);
  178. }
  179. };
  180.  
  181. var _caption = function(txt) {
  182. var $v = jQuery('#versionNumber');
  183. if ($v.text() != txt) $v.text(txt);
  184. };
  185.  
  186. var _title = function(txt) {
  187. var newTitle = (newLogs > 0 ? '(' + newLogs + ') ' : '') + txt;
  188. if (document.title != newTitle) {
  189. oldTitle = txt;
  190. document.title = newTitle;
  191. }
  192. };
  193.  
  194. var _titlePercent = function(have, need, txt) {
  195. var percent = Math.ceil(have / (need !== 0 ? need : 1) * 100);
  196. _title(String(percent) + "% - " + txt);
  197. };
  198.  
  199. var _logSectionTitle = function (text) {
  200. return '<div class="title">' + text + '</div>';
  201. };
  202.  
  203. var _logSection = function (title, items) {
  204. return '<div class="subsection">' + _logSectionTitle(title) +
  205. '<div class="listing">' + items.join('</div><div class="listing">') + '</div>' +
  206. '</div>';
  207. };
  208.  
  209. var _optionsSection = function() {
  210. var content = [];
  211. content.push('<label for="bankStoragePercent" id="bankStoragePercentLabel">Storage (' + Beautify(_getMinimalMoney()) + ') percent: ' + options.bankStoragePercent + '%</label> <input name="bankStoragePercent" id="bankStoragePercent" type="range" min="0" max="100" value="' + options.bankStoragePercent + '" onchange="document.getElementById(\'logButton\').onsliderchange(this)" />');
  212. content.push('<button data-id="showTimeCompensate" onclick="document.getElementById(\'logButton\').onbuttonclick(this,event)">showTimeCompensate: ' + (options.showTimeCompensate ? 'TRUE' : 'FALSE') + '</button>');
  213. content.push('<button data-id="clearLog" onclick="document.getElementById(\'logButton\').onbuttonclick(this,event)">Clear Log</button>');
  214. return content;
  215. };
  216.  
  217. var _updateLog = function () {
  218. Game.updateLog = logTitle +
  219. _logSection('Priority', priorityList) +
  220. (options.showTimeCompensate ? _logSection('Priority (time compensate)', timeCompensateList) : '') +
  221. _logSection('Log', log) +
  222. _logSection('Options', _optionsSection()) +
  223. _logSection('History', _history());
  224. var newButtonText = newLogs > 0 ? 'Log (' + newLogs + ')' : 'Log';
  225. if (jQuery('#logButton').text() != newButtonText) jQuery('#logButton').text(newButtonText);
  226. _title(oldTitle);
  227. };
  228.  
  229. document.getElementById('logButton').onsliderchange = function(el) {
  230. var val = $(el).val();
  231. _store('bankStoragePercent', val);
  232. options.bankStoragePercent = val;
  233. jQuery('#bankStoragePercentLabel').text('Storage (' + Beautify(_getMinimalMoney()) + ') percent: ' + val + '%');
  234. _updateLog();
  235. };
  236. document.getElementById('logButton').onbuttonclick = function(el,e) {
  237. e.preventDefault();
  238. var id = jQuery(el).attr('data-id');
  239. if (id == 'showTimeCompensate') {
  240. options.showTimeCompensate = !options.showTimeCompensate;
  241. } else if (id == 'clearLog') {
  242. log = [];
  243. newLogs = 0;
  244. }
  245. jQuery(el).attr('disabled', 'disabled');
  246. _updateLog();
  247. }
  248.  
  249. tPriority = setInterval(function () {
  250. _createPriorityList();
  251. _updateLog();
  252. }, 1000);
  253.  
  254. var _addLog = function(text) {
  255. var t = new Date();
  256. log.push(t.toUTCString() + ': ' + text);
  257. newLogs++;
  258. _updateLog();
  259. };
  260.  
  261. tLog = setInterval(function () {
  262. _updateLog();
  263. }, 600);
  264.  
  265. jQuery('#logButton').text('Log').on("click", function() {
  266. newLogs = 0;
  267. jQuery('#logButton').text('Log');
  268. });
  269.  
  270. var _getLongTimeUpgrade = function () {
  271. var moneyCanSpend = _getMoneyCanSpend();
  272. var longTime = (Game.cookiesPs < 100) ? 1 : (
  273. (Game.cookiesPs < 1000) ? 2 : (
  274. (Game.cookiesPs < 10000) ? 3 : (
  275. (Game.cookiesPs < 1E5) ? 4 : (
  276. (Game.cookiesPs < 1E6) ? 5 : (
  277. (Game.cookiesPs < 1E9) ? 10 : 15
  278. )
  279. )
  280. )
  281. )
  282. );
  283. return longTime;
  284. };
  285.  
  286. var _getWrinklerCount = function () {
  287. var wrinklersCount = 0;
  288. for (var i in Game.wrinklers) {
  289. if (Game.wrinklers[i].sucked > 0) {
  290. wrinklersCount++;
  291. }
  292. }
  293. return wrinklersCount;
  294. };
  295.  
  296. var _killAllWrinklers = function () {
  297. var wrinklersCount = _getWrinklerCount();
  298. if (wrinklersCount >= 10 || Game.hasBuff('Elder frenzy')) {
  299. var wrinklesIncome = 0;
  300. for (var i in Game.wrinklers) {
  301. wrinklesIncome += Game.wrinklers[i].sucked;
  302. Game.wrinklers[i].hp = 0; // kill ALL
  303. }
  304. if (wrinklesIncome > 0) {
  305. _addLog('Killed all Wrinkles for ' + Beautify(wrinklesIncome) + ' because of ' + (Game.hasBuff('Elder frenzy') ? '"Elder frenzy"' : 'count 10.'));
  306. }
  307. }
  308. };
  309.  
  310. var _getMinimalPriceForNewObject = function () {
  311. var minNewObjectPrice = null;
  312. for (var i in Game.ObjectsById) {
  313. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  314. if (Game.ObjectsById[i].locked === 0 && Game.ObjectsById[i].amount === 0) {
  315. var p = Game.ObjectsById[i].price;
  316. if (minNewObjectPrice === null || p < minNewObjectPrice) minNewObjectPrice = p;
  317. }
  318. }
  319. }
  320. return minNewObjectPrice;
  321. };
  322.  
  323. var startT = function() {
  324. t2 = setInterval(function() {
  325.  
  326. _killAllWrinklers();
  327.  
  328. var moneyCanSpend = _getMoneyCanSpend();
  329.  
  330. if (moneyCanSpend < 0) {
  331. var minimalMoney = _getMinimalMoney();
  332. _caption('Collecting minimum ' + Beautify(minimalMoney));
  333. _titlePercent(Game.cookies, minimalMoney, 'minimum');
  334. return;
  335. }
  336. if (priorityList.length > 0) {
  337. for (var idx in priorityListObj) {
  338. var needToBuy = priorityListObj[idx];
  339. if (needToBuy.type == 'upgrade') {
  340. _caption('Upgrading ' + needToBuy.name + ' for ' + Beautify(needToBuy.price));
  341. if (needToBuy.price < moneyCanSpend) {
  342. if (Game.UpgradesById[needToBuy.id].canBuy()) {
  343. Game.UpgradesById[needToBuy.id].buy();
  344. _addLog('Buy upgrade ' + Game.UpgradesById[needToBuy.id].name + ' for ' + Beautify(needToBuy.price));
  345. _createPriorityList();
  346. }
  347. } else {
  348. _titlePercent(moneyCanSpend, needToBuy.price, Game.UpgradesById[needToBuy.id].name);
  349. }
  350. } else {
  351. _caption('Collecting ' + Beautify(needToBuy.price) + ' for ' + needToBuy.name);
  352. if (Game.ObjectsById[needToBuy.id].price < moneyCanSpend) {
  353. Game.ObjectsById[needToBuy.id].buy(1);
  354. _addLog('Buy object ' + Game.ObjectsById[needToBuy.id].name + ' for ' + Beautify(Game.ObjectsById[needToBuy.id].price));
  355. _createPriorityList();
  356. } else {
  357. _titlePercent(moneyCanSpend, needToBuy.price, Game.ObjectsById[needToBuy.id].name);
  358. }
  359. }
  360. break;
  361. }
  362. return;
  363. }
  364.  
  365. var minNewObjectPrice = _getMinimalPriceForNewObject();
  366.  
  367. var u = null; // upgrade can buy
  368. var minUpgradePrice = null;
  369. for (var g in Game.UpgradesById) {
  370. if (Game.UpgradesById[g].bought === 0 && Game.UpgradesById[g].unlocked == 1) {
  371. //u.push(Game.UpgradesById[g]);
  372. if (minUpgradePrice === null) {
  373. minUpgradePrice = Game.UpgradesById[g].basePrice;
  374. u = g;
  375. } else if (Game.UpgradesById[g].basePrice < minUpgradePrice) {
  376. minUpgradePrice = Game.UpgradesById[g].basePrice;
  377. u = g;
  378. }
  379. }
  380. }
  381.  
  382. var longTime = _getLongTimeUpgrade();
  383. var needUpgrade = (minNewObjectPrice > minUpgradePrice || minUpgradePrice === null) &&
  384. u !== null && typeof Game.UpgradesById[u] !== 'undefined' &&
  385. (moneyCanSpend >= minUpgradePrice || ((minUpgradePrice - moneyCanSpend) / _getNormalCookiesPs()) <= (longTime*60));
  386.  
  387. if (needUpgrade)
  388. {
  389. if (Game.UpgradesById[u].canBuy()) {
  390. Game.UpgradesById[u].buy();
  391. _addLog('Buy upgrade ' + Game.UpgradesById[u].name + ' for ' + Beautify(minUpgradePrice));
  392. } else {
  393. _caption('Upgrading ' + Game.UpgradesById[u].name + ' for ' + Beautify(minUpgradePrice));
  394. _titlePercent(moneyCanSpend, minUpgradePrice, Game.UpgradesById[u].name);
  395. }
  396. } else {
  397. var minInvert = null, minObj = null;
  398. for (var i in Game.ObjectsById) {
  399. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  400. if (Game.ObjectsById[i].locked === 0) {
  401. var interest = Game.ObjectsById[i].price / Game.ObjectsById[i].storedCps;
  402. if (minInvert === null) {
  403. minInvert = interest;
  404. minObj = i;
  405. } else if (interest < minInvert) {
  406. minInvert = interest;
  407. minObj = i;
  408. }
  409. }
  410. }
  411. }
  412. if (minObj !== null) {
  413. if (Game.ObjectsById[minObj].price < moneyCanSpend) {
  414. Game.ObjectsById[minObj].buy(1);
  415. _addLog('Buy object ' + Game.ObjectsById[minObj].name + ' for ' + Beautify(Game.ObjectsById[minObj].price));
  416. } else {
  417. _caption('Collecting ' + Beautify(Game.ObjectsById[minObj].price) + ' for ' + Game.ObjectsById[minObj].name);
  418. _titlePercent(moneyCanSpend, Game.ObjectsById[minObj].price, Game.ObjectsById[minObj].name);
  419. }
  420. }
  421.  
  422. }
  423.  
  424. }, 1000);
  425.  
  426. started = true;
  427. _caption('Started');
  428. _addLog('Autobuy start!');
  429. };
  430.  
  431. var stopT = function() {
  432. clearInterval(t2);
  433. started = false;
  434. _caption('Collecting gold...');
  435. _addLog('Autobuy stop.');
  436. };
  437.  
  438. jQuery('#versionNumber').on("click", function() {
  439. if (!started)
  440. startT();
  441. else
  442. stopT();
  443. });
  444.  
  445. options.bankStoragePercent = _restore('bankStoragePercent');
  446. if (typeof options.bankStoragePercent === 'undefined' || options.bankStoragePercent === null) {
  447. options.bankStoragePercent = 100;
  448. }
  449.  
  450. setTimeout(function() {
  451. jQuery('#donateBox').hide();
  452. t3 = setInterval(function() {
  453. var golden = Game.shimmers;
  454. if (golden.length > 0) {
  455. for (var i in golden) {
  456. golden[i].pop();
  457. }
  458. }
  459. }, 500);
  460.  
  461. tClickFrenzy = setInterval(function() {
  462. if (Game.hasBuff('Click frenzy') || Game.hasBuff('Cursed finger') || Game.cookiesPs < 1000000) {
  463. Game.ClickCookie();
  464. }
  465. }, 75);
  466.  
  467. if (Game.cookiesPs < 1E6) {
  468. tClick = setInterval(function() {
  469. Game.mouseX = jQuery('#bigCookie').width() / 2 + jQuery('#bigCookie').offset().left;
  470. Game.mouseY = jQuery('#bigCookie').height() / 2 + jQuery('#bigCookie').offset().top;
  471. Game.ClickCookie();
  472. if (Game.cookiesPs > 1E8) clearInterval(tClick);
  473. }, 300);
  474. }
  475.  
  476. _caption('Collecting gold...');
  477. }, 5000);
  478. })();