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