Cookie clicker tools

Cookie clicker tools (visual)

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

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