Skip to content

Instantly share code, notes, and snippets.

@kkotaro0111
Last active December 23, 2015 04:09
Show Gist options
  • Save kkotaro0111/6577870 to your computer and use it in GitHub Desktop.
Save kkotaro0111/6577870 to your computer and use it in GitHub Desktop.
cookie clickerを自動化する
//need jQuery
//reference to gist:6577862
var ch = {}; //cookie hacker
ch.onEnterFrame = function(){
ch.clicker();
ch.upgrade();
ch.buyBestProduct();
ch.goldenCookieeeeee();
};
ch.clicker = function(){
$("#bigCookie").trigger("click");
};
ch.goldenCookieeeeee = function(){
if(Game.goldenCookie.delay == 0){
var gc = $("#goldenCookie");
gc.trigger("click");
}
};
ch.betterProductId = 0;
ch.buyBestProduct = function(){
var cursor = Game.ObjectsById[0];
var c_price = Math.floor(cursor.price);
var p_len = Game.ObjectsById.length;
for(var i = p_len - 1; i > 0; i--){
var product = Game.ObjectsById[i];
var p_price = Math.floor(product.price);
if(c_price * 2 > p_price){
ch.betterProductId = i;
break;
}
}
var buyProductList = [];
if(Game.ObjectsById[ch.betterProductId].amount > 0){
buyProductList.push(0);
}
buyProductList.push(ch.betterProductId);
buyProductList = buyProductList.concat(ch.canPayOneSecList());
ch.buyProduct(buyProductList);
};
ch.canPayOneSecList = function(){
var products = Game.ObjectsById;
var len = products.length;
var ary = [];
for(var i = 0; i < len; i++){
var product = products[i];
var price = Math.floor(product.price);
var earnPrice = Game.cookiesPs;
if(price < earnPrice){
ary.push(i);
}
}
return ary;
};
ch.buyProduct = function(pids){
var minPrice = ch.getMinPriceAtProducts(pids);
var minUpgradePrice = ch.getMinPriceAtUpgrade();
if(minPrice[0] == -1){
throw new Error("Product is NONE");
}else{
if(minUpgradePrice[0] == -1 || minPrice[1] < minUpgradePrice[1] / 2){
var product = $("#product"+minPrice[0]);
product.trigger("click");
}
}
};
ch.getMinPriceAtProducts = function(pids){
var price = 0;
var id = -1;
var len = pids.length;
for(var i = 0; i < len; i++){
var product = Game.ObjectsById[pids[i]];
if(price == 0){
price = product.price;
id = pids[i];
}else if(price > product.price){
price = product.price;
id = pids[i];
}
}
return [id, Math.floor(price)];
};
ch.getMinPriceAtUpgrade = function(){
var len = Game.UpgradesInStore.length;
for(var i = 0; i < len; i++){
var upgradeInfo = Game.UpgradesInStore[i];
var order = upgradeInfo.order;
var price = upgradeInfo.basePrice;
if((order >= ((ch.betterProductId + 1) * 100) || order < 200)){
return [i, price];
}
}
return [-1, 0];
};
ch.upgrade = function(){
var upgrades = Game.UpgradesInStore;
var len = upgrades.length;
for(var i = 0; i < len; i++){
var upgradeInfo = Game.UpgradesInStore[i];
var order = upgradeInfo.order;
var price = upgradeInfo.basePrice;
if(price < Game.cookies && (order >= ((ch.betterProductId + 1) * 100) || order < 200 || price < Game.cookiesPs)){
var enabled = $("#upgrade"+i);
enabled.trigger("click");
break;
}
}
};
ch.toInt = function(value){
var nocomma = value.replace(/,/g, "");
var returnvalue = 0;
var sepdigit = 9;
if(nocomma.length > sepdigit){
var frontlen = nocomma.length - sepdigit;
var valuearray = [];
valuearray.push(nocomma.substr(0, frontlen) >>> 0);
valuearray.push(nocomma.substr(frontlen) >>> 0);
returnvalue = (valuearray[0] >> 0) * Math.pow(10, sepdigit) + (valuearray[1] >> 0);
}else{
returnvalue = nocomma >>> 0;
}
return returnvalue;
};
ch.tid = -1;
ch.cookieTrigger = function(){
var ver = $("#versionNumber");
ver.on("click", function(){
if(ch.tid > 0){
clearInterval(ch.tid);
ch.tid = -1;
}else{
// 15/1000(click/sec)でクリックすると、Game.autoclickerDetectedがインクリメントされるので
ch.tid = setInterval(ch.onEnterFrame, 1000/14);
}
});
};
ch.cookieTrigger();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment