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