Last active
December 23, 2015 11:19
-
-
Save chrisruffalo/6627490 to your computer and use it in GitHub Desktop.
Cookie Clicker cheating. This script REQUIRES cookie monster (and JQUERY) to be loaded first!Install Cookie Monster from here: http://cookieclicker.wikia.com/wiki/Cookie_Monster_(JavaScript_Add-on)
This file contains hidden or 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
// create variable | |
function ClickerCheat() { | |
// external settings | |
this.enabled = false; // enabled at all | |
this.build = true; // should it build things? | |
this.click = true; // should it click on the big cookie? | |
this.golden = true; // should it auto-click golden cookies? | |
this.upgrade = true; // should it upgrade when available? | |
this.interval = 1; // ms between 'clicks' | |
this.grandmapocalypse = true; // optimally work with the grandmapocalypse by default | |
this.wrinklers = true; // auto-kill wrinkly things | |
this.debug = false; // debug logging | |
// cheating with health! | |
this.healthratio = 0.05; | |
// safe logging | |
var log = function(message) { | |
if(console.log) { | |
console.log("[cookie bot] " + message); | |
} | |
}; | |
// safe debug logging | |
var dlog = function(message) { | |
if (!this.debug) { | |
return; | |
} | |
if(console.log) { | |
console.log("[cookie debug] " + message); | |
} | |
} | |
// safe way to log a purchase when given the element | |
// that was clicked to make the purchase | |
var plog = function(purchase) { | |
// early out beacuse this | |
// is fairly intensive | |
if(!console.log) { | |
return; | |
} | |
if(!purchase) { | |
return; | |
} | |
try { | |
var element = purchase.parent().first().find(".title:not('.owned')"); | |
var title = element.html(); | |
if(title.indexOf("<span") >= 0) { | |
title = element.children().first().html(); | |
} | |
log("buying '" + title + "'"); | |
} catch(e) { | |
// do nothing, no log | |
} | |
}; | |
// cache the big cookie | |
var big = null; | |
// automatic click | |
this.autoClick = function() { | |
if (this.click) { | |
if (!big) { | |
big = $("#bigCookie"); | |
} | |
// create a random chance | |
var random = Math.random(); | |
// if the random number is under the | |
// ratio that we want to cheat the | |
// big cookie, then set the last | |
// click time to 0 which will cause | |
// another click to be allowed to happen | |
if(random <= this.healthratio) { | |
dlog("hacking the last click time!"); | |
Game.lastClick = 0; | |
} | |
// click on the big cookie | |
big.click(); | |
} | |
}; | |
this.autoGoldenClick = function() { | |
if (!this.enabled) { | |
log("disabled, stopping special clicker"); | |
return; | |
} | |
if(this.golden) { | |
dlog("checking for golden cookie..."); | |
var cookie = $('#goldenCookie:not([style*="background-image: url(http://orteil.dashnet.org/cookieclicker/img/wrathCookie.png)"]):visible'); | |
if(cookie.size() > 0) { | |
cookie.click(); | |
log("clicked golden cookie!"); | |
} | |
} | |
if(this.wrinklers) { | |
// also handle wrinklers | |
$.each(Game.wrinklers, function(index, item){ | |
if(item.close > 0 && item.sucked > 500) { | |
item.hp--; | |
item.hurt = 1; | |
if(item.hp == 0) { | |
dlog("destroyed wrinkler #" + index); | |
} | |
} | |
}); | |
} | |
// schedule next attempt | |
var _this = this; | |
window.setTimeout(function(){_this.autoGoldenClick();}, (_this.interval*500)); | |
}; | |
this.autoBuild = function() { | |
dlog("in auto build"); | |
if (!this.enabled) { | |
log("disabled, stopping auto-build"); | |
return; | |
} | |
// upgrade most obvious part that is enabled | |
if(this.build) { | |
dlog("checking for auto build..."); | |
// select last green | |
var bestBuild = $(".product.enabled").find("span[style*='color: rgb(0, 255, 0)']:last"); | |
// if a green is available, click it | |
if(bestBuild.size() > 0) { | |
bestBuild.click(); | |
plog(bestBuild, true); | |
} | |
} | |
// set upgrade timeout | |
var _this = this; | |
window.setTimeout(function(){_this.autoBuild();}, (_this.interval*1500)); | |
}; | |
this.autoUpgrade = function() { | |
dlog("in auto upgrade"); | |
if (!this.enabled) { | |
log("disabled, stopping auto-upgrade"); | |
return; | |
} | |
// select the first available upgrade and try | |
// to click it if the cycle is more than half over | |
if(this.upgrade) { | |
dlog("checking for auto upgrade..."); | |
// click the first available upgrade | |
// (read: cheapest) | |
var upgrades = Game.UpgradesInStore; | |
for (var i = 0; i < upgrades.length; i++) { | |
var instance = upgrades[i]; | |
// require a valid upgrade name | |
if (!instance.name) { | |
continue; | |
} | |
// names | |
var name = instance.name.toLowerCase(); | |
// special case for grandmapocalypse | |
// if not handling it then don't buy | |
// those related upgrades | |
if (this.grandmapocalypse) { | |
if ("revoke elder covenant" == name) { | |
dlog("Declining to revoke 'Elder Covenant'") | |
continue; | |
} else if("elder covenant" == name) { | |
dlog("Declining to buy 'Elder Covenant'"); | |
continue; | |
} else if ("elder pledge" == name) { | |
dlog("Declining to buy 'Elder Pledge'"); | |
continue; | |
} | |
} else { | |
// never buy one mind if | |
// the apoc is not enabled | |
if("one mind" == name) { | |
dlog("Skipping 'One Mind'") | |
continue; | |
} | |
} | |
// upgrade cheapest one and quit loop | |
if (Game.cookies >= instance.basePrice) { | |
// grab upgrade and click through UI | |
//$("#upgrade" + i).click(); | |
instance.buy(); | |
// log | |
log("purchasing upgrade '" + instance.name + "'"); | |
// no more upgrades | |
break; | |
} | |
} | |
} | |
// set upgrade timeout | |
var _this = this; | |
window.setTimeout(function(){_this.autoUpgrade();}, (_this.interval*750)); | |
}; | |
// interlock | |
var running = false; | |
// timers | |
var clickTimer = null; | |
// timer | |
this.start = function() { | |
if (running) { | |
return; | |
} | |
// start running | |
running = true; | |
// enable | |
this.enabled = true; | |
// alias variable | |
var _this = this; | |
// start autoclick | |
clickTimer = window.setInterval(function(){_this.autoClick();}, _this.interval); | |
// start auto-clicker for special things | |
_this.autoGoldenClick(); | |
// start auto build engine | |
_this.autoBuild(); | |
// start auto upgrade engine | |
_this.autoUpgrade(); | |
// started! | |
log("started"); | |
} | |
// stop running | |
this.stop = function() { | |
// don't do anything if not running | |
if (!running) { | |
return; | |
} | |
// turn off running status | |
running = false; | |
// update enabled flag | |
this.enabled = false; | |
// set check value to -1 | |
lastCheck = -1; | |
// stop click timer | |
if (clickTimer) { | |
window.clearInterval(clickTimer); | |
log("stopped auto-click timer"); | |
} | |
// stopped bot | |
log("stopped"); | |
} | |
}; | |
clicker = new ClickerCheat(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment