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