MikrySoft

BuildScriptYx

Feb 24th, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var interval = 250;
  2. var autoBuy = true;
  3. var autoBuyTxt = "on";
  4. var name;
  5. var price;
  6. var cpsItem;
  7. var selected=0;
  8. var currentCps=Game.cookiesPs;
  9. var selectedItem                       
  10.  
  11. document.addEventListener('keydown', function(event) {
  12.     if(event.keyCode == 65) {
  13.         autoBuy = !autoBuy;
  14.         autoBuyTxt = autoBuy ? "on" : "off";
  15.     }
  16. });
  17.  
  18. function OptimalItem()
  19. {
  20.     var cpc = Number.MAX_VALUE;
  21.    
  22.     var sel;
  23.  
  24.     for(i = Game.UpgradesInStore.length-1; i >= 0; i--)
  25.     {
  26.         var cps1 = 0;
  27.         var me = Game.UpgradesInStore[i];
  28.         var x = Game.UpgradesInStore[i].id;
  29.         if (x != 64 && x != 74 && x != 84 && x != 85 && x != 181 && x != 182 && x != 183 && x != 184)
  30.         {
  31.             Game.UpgradesById[x].toggle();
  32.             Game.CalculateGains();
  33.             for(j = Game.ObjectsById.length-1; j >= 0; j--){ cps1 += Game.ObjectsById[j].cps()*Game.ObjectsById[j].amount; }
  34.             var cps2 = cps1 * Game.globalCpsMult;
  35.             Game.UpgradesById[x].toggle();
  36.             Game.CalculateGains();
  37.             var myCps = cps2 - currentCps;
  38.             var cpsUpgrade = me.basePrice *(Game.cookiesPs + myCps) / myCps;
  39.             if (cpsUpgrade < cpc && myCps >= 0.1)
  40.             {
  41.                 cpc = cpsUpgrade;
  42.                 sel = me;
  43.                 cpsItem = myCps;
  44.                 name = me.name;
  45.                 price = Math.round(me.basePrice);
  46.             }
  47.         }
  48.     }
  49.  
  50.     for(i = Game.ObjectsById.length-1; i >= 0; i--){
  51.         var cps1=0;
  52.         var me = Game.ObjectsById[i];
  53.         me.amount++;
  54.         Game.CalculateGains();
  55.         for(j = Game.ObjectsById.length-1; j >= 0; j--){ cps1 += Game.ObjectsById[j].cps()*Game.ObjectsById[j].amount;}
  56.         var cps2 = cps1 * Game.globalCpsMult;
  57.         me.amount--;
  58.         Game.CalculateGains();
  59.         var myCps = cps2 - currentCps;
  60.         var cpsBuilding = me.price *(Game.cookiesPs + myCps) / myCps;
  61.         if (cpsBuilding < cpc && myCps >= 0.1)
  62.         {  
  63.             cpc = cpsBuilding;
  64.             sel = me;
  65.             cpsItem = myCps;
  66.             name = me.name;
  67.             price = Math.round(me.price);
  68.         }
  69.     }
  70.     currentCps = Game.cookiesPs;
  71.     selected=1;
  72.     selectedItem=sel;
  73. }
  74.  
  75. function Display()
  76. {
  77.         var time = (price - Game.cookies) / Game.cookiesPs;
  78.     time = time < 0 ? 0 : Beautify(time);
  79.  
  80.     var numb = (Math.abs(Game.computedMouseCps / Game.cookiesPs));
  81.     numb = numb.toFixed(3);
  82.    
  83.     Game.Ticker = "Buying " + name + " for " + Beautify(price) + " at " + Beautify(Math.round(price / (cpsItem*Game.globalCpsMult))) + " cookies per CPS!" + "<br>This will take " + time + " seconds without manually clicking." + "<br>Each click would save you " + numb + " seconds." + "<br>Click A to toggle auto-buy. Auto-buy is currently " + autoBuyTxt;
  84.     Game.TickerAge = interval;
  85. }
  86.  
  87. var cookieBot = setInterval(function () {
  88.     if(autoBuy && Game.cookies >= price && selected==1){selectedItem.buy(); Display; selected=0;}
  89.     else if(selected==0 || currentCps!=Game.cookiesPs){OptimalItem(); Display();}
  90.     else if(selected==1){Display();}}, interval
  91. );
Advertisement
Add Comment
Please, Sign In to add comment