Instantly share code, notes, and snippets.
Last active
October 5, 2016 12:04
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save azugxi7374/5bff5c48f4b4d93cb44c4e4ab05937f7 to your computer and use it in GitHub Desktop.
Auto Cookie Clicker (bookmarklet)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: | |
var ACC = new function(){ | |
var self = this; | |
var sto=setTimeout; | |
var prevNextBuy; | |
var nextBuy; | |
var maxLossTime = 60*60*24*10; | |
this.setMaxLossTime = function(t){maxLossTime = t}; | |
var flg0 = "g"; | |
var flg1 = "bgc"; | |
var allFlg = "abcfgw"; | |
var flg = ""; | |
var funcs = { | |
a: forceAscend, | |
b: tryBuy, | |
c: click, | |
f: buyUpgForce, | |
g: goldenClick, | |
p: pledge, | |
w: killWrinklers | |
}; | |
var pUpg = []; | |
/* ??? */ | |
var func2 = function(){}; | |
this.init = function(){ | |
var gameLoop = Game.Loop; | |
Game.Loop = function(){ | |
gameLoop(); | |
setStatus(); | |
for(var i= 0; i< flg.length; i++){ | |
funcs[flg.charAt(i)](); | |
} | |
if(prevNextBuy != nextBuy){ | |
logNextBuy(); | |
prevNextBuy = nextBuy; | |
} | |
/* func2(); */ | |
}; | |
this.clear(); | |
}; | |
this.clear = function(){ | |
this.set(flg0); | |
this.setPrior([]); | |
this.setFunc(function(){}); | |
this.status(); | |
}; | |
this.status = function(){ | |
console.log("flg : " + flg + " (allFlg = "+ allFlg + ")"); | |
console.log("prior upgrades : " + pUpg); | |
logNextBuy(); | |
}; | |
this.set = function(flgs){ | |
flg= flgs; | |
prevNextBuy = -1; | |
nextBuy = -1; | |
}; | |
this.all = function(){this.set(allFlg);}; | |
this.start = function(){this.set(flg1);}; | |
this.stop = function(){this.set("");}; | |
this.setPrior = function(a){ | |
if(a[0] != undefined){ | |
pUpg = a; | |
} | |
}; | |
this.setFunc = function(f){ | |
if(typeof f == "function"){ | |
func2 = f; | |
} | |
}; | |
this.speed = function(s,s2){ | |
Game.fps=30.0/s*s2; | |
setTimeout = function(f,t){ return sto(f,t/s)}; | |
}; | |
this.allCookies = function(){ | |
var sum=0; | |
for (var i in Game.wrinklers){ | |
sum += Game.wrinklers[i].sucked; | |
} | |
return sum + Game.cookies; | |
}; | |
function forceAscend(){ | |
/* xmas */ | |
var upg = Game.UpgradesById[182]; | |
if(upg.unlocked && upg.bought==0 && upg.getPrice() < Game.cookies){ | |
upg.buy(); | |
} | |
if(Game.specialTabs.indexOf("santa")>=0){ | |
Game.UpgradeSanta(); | |
} | |
/* speed */ | |
if(Game.prestige > 0 && Game.UpgradesById[133].bought == 0){/* key */ | |
self.speed(1,1); | |
}else{ | |
self.speed(1000,1); | |
} | |
var containsClass = function(str){ | |
return document.getElementById("game").getAttribute("class").split(" ").indexOf(str) >=0}; | |
var ascendIntro = containsClass("ascendIntro"); | |
var ascending = containsClass("ascending"); | |
var reincarnating = containsClass("reincarnating"); | |
if(!ascendIntro && !ascending && !reincarnating && ascendToGet() > 0){ | |
killWrinklers(); | |
Game.Ascend(1); | |
}else if(ascending){ | |
var buyflg = false; | |
for(i in Game.UpgradesById){ | |
var upg = Game.UpgradesById[i]; | |
if(upg.pool == "prestige" && upg.canBePurchased && upg.bought == 0 && upg.getPrice() <= Game.heavenlyChips){ | |
Game.PurchaseHeavenlyUpgrade(i); | |
buyflg = true; | |
break; | |
} | |
} | |
if(!buyflg){ | |
Game.Reincarnate(1); | |
} | |
} | |
}; | |
this.killBestWrinkler = function(){ | |
var best = -1; | |
var max = 10; | |
for (var i in Game.wrinklers){ | |
var v = Game.wrinklers[i].sucked; | |
if(max < v){ | |
max = v; | |
best = i; | |
} | |
} | |
if(best != -1){ | |
Game.wrinklers[best].hp=0; | |
} | |
}; | |
/* inBank: true or false */ | |
this.timeUntil = function(c, inBank){ | |
if(inBank == undefined){ inBank = true;} | |
if(inBank){ | |
c = c - Game.cookies; | |
}else{ | |
c = c - Game.cookiesEarned; | |
} | |
return Math.max(0, Math.ceil(c / Game.cookiesPs)); | |
}; | |
this.calcPrice = function(obji, n){ | |
var p = Game.ObjectsById[obji].getPrice(); | |
var ret = 0; | |
while(n > 0){ | |
ret += p; | |
p*=1.15; | |
n-=1; | |
} | |
return Math.floor(ret); | |
}; | |
function pledge(){ | |
var upg = Game.UpgradesById[74]; | |
if(upg.unlocked && !upg.bought){ | |
upg.buy(); | |
} | |
}; | |
function killWrinklers(){ | |
for (var i in Game.wrinklers){ | |
if(Game.wrinklers[i].sucked>0){ | |
Game.wrinklers[i].hp=0; | |
} | |
} | |
}; | |
function setStatus(){ | |
setNextBuy(); | |
}; | |
function setNextBuy(){ | |
var best = -1; | |
var bestT = maxLossTime; | |
var ltcps = -1; | |
for(var i=0; Game.ObjectsById[i]!=undefined; i++){ | |
var obj = Game.ObjectsById[i]; | |
var time = losstime(obj)[0]; | |
if(obj.price < Game.cookiesPs / Game.fps){ | |
ltcps = i; | |
} | |
if(bestT > time){ | |
bestT = time; | |
best = i; | |
} | |
} | |
nextBuy = best; | |
}; | |
function buyPriorUpg(){ | |
if(pUpg.length > 0 && Game.cookies > Game.UpgradesById[pUpg[0]].getPrice()){ | |
var upg = Game.UpgradesById[pUpg[0]]; | |
upg.buy(); | |
__log__("buy " + upg.name); | |
pUpg.shift(); | |
buyPriorUpg(); | |
} | |
}; | |
function goldenClick(){ | |
var s = document.getElementsByClassName("shimmer"); | |
if(s.length > 0){ | |
for(var i=0; i<s.length; i++){ | |
s[i].click(); | |
} | |
__log__("click golden cookie"); | |
} | |
}; | |
function click(){ | |
document.getElementById("bigCookie").click(); | |
}; | |
function losstime(obj){ | |
var c = Game.cookies; | |
var cps = Game.cookiesPs; | |
var p = obj.price; | |
var baseCps = obj.id==0? obj.baseCps() : obj.baseCps; | |
var earn = (obj.amount == 0? baseCps : obj.storedTotalCps / obj.amount ) * Game.globalCpsMult; | |
var timeUntilBuy = (c > p)? 0 : (p -c) / cps; | |
var recoveringTime = p / earn; | |
return [timeUntilBuy + recoveringTime, timeUntilBuy, recoveringTime]; | |
}; | |
function tryBuy(){ | |
if(pUpg.length > 0){ | |
buyPriorUpg(); | |
}else if(Game.buyMode == 1){ | |
var obj = Game.ObjectsById[nextBuy]; | |
if(obj != undefined && obj.price < Game.cookies){ | |
obj.buy(); | |
/* document.getElementById("product"+nextBuy).click();*/ | |
__log__("buy " + obj.name); | |
setNextBuy(); | |
tryBuy(); | |
} | |
} | |
}; | |
function logNextBuy(){ | |
var ls = nextBuy>=0 ? losstime(Game.ObjectsById[nextBuy]) : [0, 0, 0]; | |
var name = nextBuy>=0 ? Game.ObjectsById[nextBuy].name : "Nothing"; | |
console.log("next : " + name + " (lossTime= "+ ~~ls[1] +" + " + ~~ls[2] +")"); | |
}; | |
function buyUpgForce(){ | |
for(var i=0; Game.UpgradesById[i] != undefined; i++){ | |
var upg = Game.UpgradesById[i]; | |
if(upg.unlocked==1 && upg.bought==0 && ["", "cookie","tech"].indexOf(upg.pool)>=0 && Game.cookies > upg.getPrice()){ | |
upg.buy(); | |
__log__("buy " + upg.name); | |
} | |
} | |
}; | |
function __log__(str){ | |
console.log("[" + (new Date()) + "]: " + str); | |
}; | |
function ascendToGet(){ | |
return Math.floor(Game.HowMuchPrestige(Game.cookiesReset+Game.cookiesEarned)-Game.HowMuchPrestige(Game.cookiesReset)); | |
}; | |
}; | |
ACC.init(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment