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.028
  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. if (console) console.log('Cookies 2.0.26.');
  14. var log = [], logTitle = '<div class="section">Cookies 2.0.26 is here!</div>';
  15.  
  16. var started = false;
  17. var t2, t3, tClick, tClickFrenzy;
  18. var _caption = function(txt) {
  19. var $v = jQuery('#versionNumber');
  20. if ($v.text() != txt) $v.text(txt);
  21. }
  22. var _title = function(txt) {
  23. document.title = txt;
  24. }
  25. var _titlePercent = function(have, need, txt) {
  26. var percent = Math.ceil(have / (need !== 0 ? need : 1) * 100);
  27. _title((percent < 10 ? '00' : (percent < 100 ? '0' : '')) + String(percent) + "% - " + txt);
  28. }
  29. var _addLog = function(text) {
  30. log.push(text);
  31. Game.updateLog = logTitle + '<div class="subsection"><div class="listing">' +
  32. join('</div><div class="listing">', log) + '</div></div>';
  33. }
  34. var startT = function() {
  35. t2 = setInterval(function() {
  36. var wrinklersCount = 0, maxWrinkler = -1, maxSucked = 0;
  37. for (i in Game.wrinklers) {
  38. if (Game.wrinklers[i].sucked > 0) {
  39. wrinklersCount++;
  40. }
  41. }
  42. if (wrinklersCount >= 10 || Game.hasBuff('Elder frenzy')) {
  43. var wrinklesIncome = 0;
  44. for (i in Game.wrinklers) {
  45. wrinklesIncome += Game.wrinklers[i].sucked;
  46. Game.wrinklers[i].hp = 0; // kill ALL
  47. }
  48. _addLog('Killed all Wrinkles for ' + Beautify(wrinklesIncome) + ' because of ' + (Game.hasBuff('Elder frenzy') ? '"Elder frenzy"' : 'count 10.'));
  49. }
  50.  
  51. var buffMult = 1;
  52. for (var buff in Game.buffs) {
  53. if (Game.buffs[buff] !== 0 && typeof Game.buffs[buff].multCpS !== 'undefined') {
  54. buffMult = buffMult * Game.buffs[buff].multCpS;
  55. }
  56. }
  57. var normalCookiesPs = Game.cookiesPs / (buffMult !== 0 ? buffMult : 1);
  58. var minimalMoney = normalCookiesPs * 42100;
  59. var moneyCanSpend = Game.cookies - minimalMoney;
  60. if (moneyCanSpend < 0) {
  61. _caption('Collecting minimum ' + Beautify(minimalMoney));
  62. _titlePercent(Game.cookies, minimalMoney, 'minimum');
  63. return;
  64. }
  65. var minNewObjectPrice = null;
  66. for (var i in Game.ObjectsById) {
  67. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  68. if (Game.ObjectsById[i].locked === 0 && Game.ObjectsById[i].amount === 0) {
  69. var p = Game.ObjectsById[i].price;
  70. if (minNewObjectPrice === null || p < minNewObjectPrice) minNewObjectPrice = p;
  71. }
  72. }
  73. }
  74. var u = null; // upgrade can buy
  75. var minUpgradePrice = null;
  76. for (var g in Game.UpgradesById) {
  77. if (Game.UpgradesById[g].bought === 0 && Game.UpgradesById[g].unlocked == 1) {
  78. //u.push(Game.UpgradesById[g]);
  79. if (minUpgradePrice === null) {
  80. minUpgradePrice = Game.UpgradesById[g].basePrice;
  81. u = g;
  82. } else if (Game.UpgradesById[g].basePrice < minUpgradePrice) {
  83. minUpgradePrice = Game.UpgradesById[g].basePrice;
  84. u = g;
  85. }
  86. }
  87. }
  88. var longTime = (Game.cookiesPs < 100) ? 1 : (
  89. (Game.cookiesPs < 1000) ? 2 : (
  90. (Game.cookiesPs < 10000) ? 3 : (
  91. (Game.cookiesPs < 1E5) ? 4 : (
  92. (Game.cookiesPs < 1E6) ? 5 : (
  93. (Game.cookiesPs < 1E9) ? 10 : 15
  94. )
  95. )
  96. )
  97. )
  98. );
  99. var needUpgrade = (minNewObjectPrice > minUpgradePrice || minUpgradePrice === null) &&
  100. u !== null && typeof Game.UpgradesById[u] !== 'undefined' &&
  101. (moneyCanSpend >= minUpgradePrice || ((minUpgradePrice - moneyCanSpend) / Game.cookiesPs) <= (longTime*60));
  102. if (needUpgrade)
  103. {
  104. if (Game.UpgradesById[u].canBuy()) {
  105. Game.UpgradesById[u].buy();
  106. _addLog('Buy upgrade ' + Game.UpgradesById[u].name + ' for ' + Beautify(minUpgradePrice));
  107. } else {
  108. _caption('Upgrading ' + Game.UpgradesById[u].name + ' for ' + Beautify(minUpgradePrice));
  109. _titlePercent(moneyCanSpend, minUpgradePrice, Game.UpgradesById[u].name);
  110. }
  111. } else {
  112. var minInvert = null, minObj = null;
  113. for (i in Game.ObjectsById) {
  114. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  115. if (Game.ObjectsById[i].locked === 0) {
  116. var interest = Game.ObjectsById[i].price / Game.ObjectsById[i].storedCps;
  117. if (minInvert === null) {
  118. minInvert = interest;
  119. minObj = i;
  120. } else if (interest < minInvert) {
  121. minInvert = interest;
  122. minObj = i;
  123. }
  124. }
  125. }
  126. }
  127. if (minObj !== null) {
  128. if (Game.ObjectsById[minObj].canBuy()) {
  129. Game.ObjectsById[minObj].buy(1);
  130. _addLog('Buy object ' + Game.ObjectsById[minObj].name + ' for ' + Beautify(Game.ObjectsById[minObj].price));
  131. } else {
  132. _caption('Collecting ' + Beautify(Game.ObjectsById[minObj].price) + ' for ' + Game.ObjectsById[minObj].name);
  133. _titlePercent(moneyCanSpend, Game.ObjectsById[minObj].price, Game.ObjectsById[minObj].name);
  134. }
  135. }
  136. }
  137.  
  138. }, 1000);
  139. started = true;
  140. _caption('Started');
  141. _addLog('Autobuy start!');
  142. }
  143. var stopT = function() {
  144. clearInterval(t2);
  145. started = false;
  146. _caption('Collecting gold...');
  147. _addLog('Autobuy stop.');
  148. }
  149. jQuery('#versionNumber').on("click", function() {
  150. if (!started)
  151. startT();
  152. else
  153. stopT();
  154. });
  155. setTimeout(function() {
  156. t3 = setInterval(function() {
  157. var golden = Game.shimmers;
  158. if (golden.length > 0) {
  159. for (var i in golden) {
  160. golden[i].pop();
  161. }
  162. }
  163. }, 1000);
  164. tClickFrenzy = setInterval(function() {
  165. if (Game.hasBuff('Click frenzy') || Game.hasBuff('Cursed finger')) {
  166. Game.ClickCookie();
  167. }
  168. }, 75);
  169. if (Game.cookiesPs < 1E6) {
  170. tClick = setInterval(function() {
  171. Game.mouseX = jQuery('#bigCookie').width() / 2 + jQuery('#bigCookie').offset().left;
  172. Game.mouseY = jQuery('#bigCookie').height() / 2 + jQuery('#bigCookie').offset().top;
  173. Game.ClickCookie();
  174. if (Game.cookiesPs > 1E8) clearInterval(tClick);
  175. }, 300);
  176. }
  177. _caption('Collecting gold...');
  178. }, 5000);
  179. })();