var interval = 250;
var autoBuy = true;
var autoBuyTxt = "on";
document.addEventListener('keydown', function(event) {
if(event.keyCode == 65) {
autoBuy = !autoBuy;
if(autoBuy) {autoBuyTxt = "on";}else{autoBuyTxt = "off";}
}
});
var cookieBot = setInterval(function() {
if(autoBuy == true) {
Game.ObjectsById[optimalBuilding()].buy();
}
else {
optimalBuilding();
}
}, interval);
function optimalBuilding() {
cpc = Number.MAX_VALUE;
var x = 0;
cps = 0
for(i = Game.ObjectsById.length-1; i >= 0; i--){
var me = Game.ObjectsById[i];
CpSlower = 0;
for(j = Game.ObjectsById.length-1; j >= 0; j--){ CpSlower += Game.ObjectsById[j].cps()*Game.ObjectsById[j].amount; }
me.amount++;
CpSupper=0;
for(j = Game.ObjectsById.length-1; j >= 0; j--){ CpSupper += Game.ObjectsById[j].cps()*Game.ObjectsById[j].amount; }
me.amount--;
var myCpS = (CpSupper - CpSlower)*Game.globalCpsMult;
var cpc2 = me.price *(Game.cookiesPs + myCpS) / myCpS;
if (cpc2 < cpc) {
cpc = cpc2;
x = i;
cps=myCpS
}
}
var time = (Math.round(Game.ObjectsById[x].price) - Game.cookies) / Game.cookiesPs;
time = time < 0 ? 0 : Beautify(time);
var numb = (Math.abs(Game.computedMouseCps / Game.cookiesPs));
numb = numb.toFixed(3);
var txt = "Buying " + Game.ObjectsById[x].name + " for " +
Beautify(Math.round(Game.ObjectsById[x].price)) + " at " + Beautify(Math.round(Game.ObjectsById[x].price / (cps*Game.globalCpsMult))) +
" cookies per CPS!" + "
This will take " + time + " seconds without manually clicking." +
"
Each click would save you " + numb + " seconds." + "
Click A to toggle auto-buy. Auto-buy is currently " + autoBuyTxt;
Game.Ticker = txt;
Game.TickerAge = interval;
return x;
}