Instantly share code, notes, and snippets.
-
Star
(3)
3
You must be signed in to star a gist -
Fork
(1)
1
You must be signed in to fork a gist
-
Save dieseltravis/6723905 to your computer and use it in GitHub Desktop.
cookie clicker bot, you're too much fun
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
CookieBot = { | |
click: function clicker() { | |
clearInterval(this.clickInterval); | |
this.clickInterval = setInterval(function clickIntervaller() { | |
// Click the large cook as fast as possible! | |
$("#bigCookie").click(); | |
}, 1); | |
// limit this to 15 for hidden achievement? | |
//TODO: test for achievement or clicks >= 15 use above, otherwise use below | |
//for (var c = 15; c--;) { | |
// setTimeout(function () { | |
// $("#bigCookie").click(); | |
// }, 10 * c); | |
//} | |
}, | |
season: function seasoner() { | |
clearInterval(this.seasonInterval); | |
this.seasonInterval = setInterval(function seasonIntervaller() { | |
var s = document.getElementById("seasonPopup"); | |
// Don't click angry grandmas' wrath cookies | |
if (s && s.style && !/wrath/.test(s.style.background)) { | |
s.click(); | |
} | |
}, 750); | |
}, | |
gold: function golder() { | |
clearInterval(this.goldInterval); | |
this.goldInterval = setInterval(function goldIntervaller() { | |
var g = document.getElementById("goldenCookie"); | |
// Don't click angry grandmas' wrath cookies | |
if (g && g.style && !/wrath/.test(g.style.background)) { | |
g.click(); | |
} | |
}, 750); | |
}, | |
buy: function buyer() { | |
clearInterval(this.buyInterval); | |
this.buyInterval = setInterval(function buyIntervaller() { | |
//// Start by trying to buy the most-expensive item | |
////TODO: base buying item on delta cps | |
//var last = [].slice.call($$(".product.enabled")).reverse()[0]; | |
//if (last) { | |
// // don't buy more than needed for achievements | |
// var max = /product[01]/.test(last.id) ? 200 : /product2/.test(last.id) ? 128: 100, | |
// owned = $$(".owned", last), | |
// ownedAmount = (owned && owned.length && owned.length > 0) ? parseInt(owned[0].innerText, 10) : 0; | |
// | |
// //TODO: if max is hit, check next lowest product | |
// if (ownedAmount < max) { | |
// last.click(); | |
// } | |
//} | |
// experimental rate-based buying logic: | |
var $$info = $$(".infoContent"), | |
$$prices = $$(".product .price"), | |
stats = {}, | |
lowest = { | |
cpcps: Number.MAX_VALUE, | |
// default to the highest enabled item until 1 of each are bought? | |
index: ($$(".product.enabled").length - 1) | |
}, | |
isChecked = false; | |
if (!$$info || $$info.length === 0) { | |
$$info = $$(".product"); | |
} | |
for (var x = $$info.length; x--;) { | |
var m = $$info[x].innerHTML.replace(/,/g,"").match(/([\d,]+)\s+(?:\w|\s)(?:.|\n)*producing\s+([\d,]+)\s+cookie/); | |
if ((!m || !m[1]) && Game && Game.ObjectsById && Game.ObjectsById[x] && Game.ObjectsById[x].tooltip) { | |
m = Game.ObjectsById[x].tooltip().replace(/,/g,"").match(/•\s+([\d,]+)\s+(?:\w|\s)(?:.|\n)*producing\s+\<b\>([\d,]+)\<\/b\>\s+cookie/); | |
} | |
if (m && m[1]) { | |
//console.log(m); | |
isChecked = true; | |
var total = parseFloat(m[1], 10), | |
producing = parseFloat(m[2], 10), | |
price = parseFloat($$prices[x].innerHTML.replace(/,/g, ""), 10), | |
rate = (producing / total), | |
cpcps = (price / rate); | |
stats[$$info[x].id] = { | |
index: x, | |
total: total, | |
producing: producing, | |
rate: rate, | |
price: price, | |
cpcps: cpcps | |
}; | |
if (!lowest || lowest.cpcps > cpcps) { | |
lowest = stats[$$info[x].id]; | |
} | |
} | |
} | |
if ($$(".product") && $$(".product")[lowest.index] && isChecked) { | |
$$(".product")[lowest.index].click(); | |
} | |
}, 500); | |
}, | |
upgrade: function upgrader() { | |
clearInterval(this.upgradeInterval); | |
this.upgradeInterval = setInterval(function upgradeIntervaller(){ | |
// Then try to buy the most expensive upgrade | |
//TODO: base upgrades on cps | |
var upgrade = [].slice.call($$(".upgrade.enabled")).reverse()[0]; | |
// skip #84 & #85: Elder Covenant switches, #182 - #184: Seasonal switches | |
if (upgrade && !/Game\.UpgradesById\[(84|85|182|183|184|185|209)\]/g.test("" + upgrade.onclick)) { | |
upgrade.click(); | |
} | |
// appease grandmatriarchs | |
var pact = $$("#upgrade0.enabled[onclick*='[74]']"); | |
if (pact && pact.length > 0) { | |
pact[0].click(); | |
} | |
}, 1000); | |
}, | |
start: function starter() { | |
this.click(); | |
this.gold(); | |
this.season(); | |
this.buy(); | |
this.upgrade(); | |
//TODO: auto-reset after ~200 quadrillion made? 50 hours? | |
}, | |
stop: function stopper(interval) { | |
if (interval && this[interval]) { | |
clearInterval(this[interval]); | |
} else { | |
clearInterval(this.clickInterval); | |
clearInterval(this.goldInterval); | |
clearInterval(this.seasonInterval); | |
clearInterval(this.buyInterval); | |
clearInterval(this.upgradeInterval); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@obi-ivan cool, thanks! Great idea stopping the interval before starting too!