Advertisement
shameless_inc

Cookie Clicker Automation Script v2.1.1

Apr 12th, 2015
2,068
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>shameless_inc's Cookie Miner v2.1.1<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  2. //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>A Cookie Clicker automation script<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  3.  
  4. //Paste this JavaScript code into the Cookie Clicker's JavaScript console.
  5. //You can access the console by opening the web browser'.s dev tools with F12
  6. //This script will click the cookie as fast as possible.
  7. //If a golden cookie spawns, it will be automatically clicked within a second.
  8. //Upgrades will be automatically bought when you have enough cookies.
  9. //There's a known bug that causes the grandmapocalypse to result in a loop
  10. //opening the prompt so many times that you will not be able to close it.
  11.  
  12. //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>RELOADING THE PAGE WILL STOP THE SCRIPT.<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  13.  
  14. //This script will intelligently select which objects to buy to get CPS efficiently
  15. //by evaluating how much Time (t) you will need to be able to afford the item.
  16. //Also, it will consider how much CPS you will actually get from the object and how much it costs (c).
  17. //The formula used to evaluate the items is CPS/(c*t).
  18. //The script will wait until you have enough cookies and buy it as soon you can afford it.
  19.  
  20. //The script will every second make a report in the console.
  21. //The report consists of the values Cookies (you have in your bank), CPS (without clicks),
  22. //the delta from the last second (how many cookies you gained since the last report, think of this as CPS including mouse clicks),
  23. //which item is going to be bought next and an estimation on how long you will have to wait until that.
  24. //The values are not perfectly precise and may be inconsistent at times, but they are mostly right
  25. //and give you an idea how much cookies you will get and what this script is doing. The time estimation is based on the
  26. //delta value and might be bogus at times (e.g. when something was bought in the last second) but it should eventually correct itself.
  27.  
  28. //If you have any feedback, please feel free to contact me on Reddit:
  29. //https://www.reddit.com/r/CookieClicker/comments/32d6ht/automation_script_v21_even_faster_smart_selection/
  30. //Turning off some effects can make it run faster in the later game.
  31. //I hope you like my work! :)
  32.  
  33. var runGoldenCookieLoop = false;
  34. var runUpgradeloop = false;
  35.  
  36. function ClickService(interval){
  37.     var self = this;
  38.    
  39.     self.interval = interval;
  40.     self.clickLoop;
  41.    
  42.     self.start = function(){
  43.         self.clickLoop = setInterval(function(){
  44.             setTimeout(function(){
  45.                 Game.ClickCookie();
  46.             }, self.interval);
  47.         });
  48.     }
  49.    
  50.     self.stop = function(){
  51.         if(self.clickLoop != undefined){
  52.             clearInterval(self.clickLoop);
  53.         }
  54.     }
  55. }
  56.  
  57. function goldenCookieLoop () {
  58.     setTimeout(function () {
  59.         Game.goldenCookie.click();
  60.         if(runGoldenCookieLoop) {
  61.             goldenCookieLoop();
  62.         }
  63.     }, 1000);
  64. }
  65.  
  66. function upgradeLoop () {
  67.     setTimeout(function () {
  68.         for(var i = 0; i < Game.UpgradesInStore.length; i++){
  69.             Game.UpgradesInStore[i].buy()
  70.         }
  71.         if(runUpgradeloop) {
  72.             upgradeLoop();
  73.         }
  74.     }, 5);
  75. }
  76.  
  77. function runAllLoops(){
  78.     runGoldenCookieLoop = true;
  79.     runUpgradeloop = true;
  80.    
  81.     goldenCookieLoop();
  82.     upgradeLoop();
  83. }
  84. function stopAllLoops(){
  85.     runGoldenCookieLoop = false;
  86.     runUpgradeloop = false;
  87. }
  88.  
  89. function showCookieDisplay (bool){
  90.     if(bool)
  91.         l('cookies').style.display = 'block';
  92.     else
  93.         l('cookies').style.display = 'none'
  94. }
  95.  
  96. //Handles data reporting for other services and provides ticks via notifications
  97. function ReportService () {
  98.     var self = this;
  99.    
  100.     self.timing = 50;
  101.    
  102.     self.count = Game.cookiesd;
  103.     self.cps = Game.cps;
  104.     self.delta = 0;
  105.     self.deltaBySecond = 0;
  106.     self.index = 0;
  107.     self.lastCount = 0;
  108.     self.lastDelta = 0;
  109.     self.lastCountBySecond = 0;
  110.    
  111.     self.subscribers = Array();
  112.     self.reports = Array();
  113.    
  114.     self.tick = function() {
  115.         setTimeout(function(){
  116.             self.refreshData();
  117.             self.notifySubscribers();
  118.             self.consoleReport();
  119.             self.tick();
  120.         }, self.timing);
  121.     }
  122.    
  123.     self.subscribe = function(fn) {
  124.         self.subscribers.push(fn);
  125.     }
  126.    
  127.     self.addReport = function(fn) {
  128.         self.reports.push(fn);
  129.     }
  130.    
  131.     self.refreshData = function() {
  132.         self.lastCount = self.count;
  133.         self.count = Game.cookiesd;
  134.         self.cps = Game.cookiesPs*(1-Game.cpsSucked);
  135.         self.lastDelta = self.delta;
  136.         self.delta = self.count - self.lastCount;
  137.         self.index++;
  138.     }
  139.    
  140.     self.notifySubscribers = function() {
  141.         for(var i = 0; i < self.subscribers.length; i++){
  142.             self.subscribers[i]();
  143.         }
  144.     }
  145.    
  146.     self.getReports = function() {
  147.         var report = '';
  148.         for(var i = 0; i < self.reports.length; i++){
  149.             var curReport = self.reports[i]();
  150.             if(curReport != ''){
  151.                 report = report + curReport;
  152.                 if(i < self.reports.length){
  153.                     report = report + '\n';
  154.                 }
  155.             }
  156.         }
  157.        
  158.         return report;
  159.     }
  160.    
  161.     self.consoleReport = function() {
  162.         //Report every second
  163.         if(self.index * self.timing % 1000 === 0){
  164.             self.deltaBySecond = self.count - self.lastCountBySecond;
  165.             self.lastCountBySecond = self.count;
  166.             var report = self.getReports();
  167.             if(report != ''){
  168.                 report = '\n' + report;
  169.             }
  170.             console.log('Cookies:\t' + Beautify(self.count) + '\nCPS:\t\t' + Beautify(self.cps) + '\nDelta:\t\t' + Beautify(self.deltaBySecond) + report);
  171.         }
  172.     }
  173.    
  174.     self.tick();
  175. }
  176.  
  177. //Handles buying objects
  178. function ObjectService(reportService){
  179.     var self = this;
  180.    
  181.     //Next object being bought
  182.     self.target;
  183.    
  184.     //Find best object to buy next
  185.     self.findBestObject = function(){
  186.         //TODO: don't operate on first delta values
  187.         var bestValue = 0;
  188.         var bestIndex = -1;
  189.         for(var i = 0; i < Game.ObjectsById.length; i++){
  190.             var obj = Game.ObjectsById[i];
  191.             var value = 0;
  192.             if(obj.locked === 0){
  193.                 value = obj.cps() / (obj.getPrice() / reportService.delta);
  194.             }
  195.             if(value > bestValue){
  196.                 bestValue = value;
  197.                 bestIndex = i;
  198.             }
  199.         }
  200.         //Set target to most efficient buy
  201.         self.target = Game.ObjectsById[bestIndex];
  202.     }
  203.    
  204.     self.buyTarget = function(){
  205.         self.target.buy();
  206.         self.target = undefined;
  207.     }
  208.    
  209.     self.onTick = function(){
  210.         if(self.target != undefined){
  211.             if(reportService.count >= self.target.getPrice()){
  212.                 self.buyTarget();
  213.             }
  214.         }
  215.         else{
  216.             self.findBestObject();
  217.         }
  218.     }
  219.    
  220.     self.report = function(){
  221.         if(self.target != undefined){
  222.             var estimation = Math.round(((self.target.getPrice() - reportService.count) / reportService.deltaBySecond));
  223.             return 'Next buy:\t' + self.target.name + '\t|\tEstimated waiting time:\t' + estimation + ' seconds';
  224.         }
  225.         else
  226.             return '';
  227.     }
  228.    
  229.     reportService.subscribe(self.onTick);
  230.     reportService.addReport(self.report);
  231. }
  232.  
  233. var Clicker = new ClickService(1);
  234. Clicker.start();
  235. var Report = new ReportService();
  236. var ObjectService = new ObjectService(Report);
  237. runAllLoops();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement