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