/*
* @title クッキーのアレを遊ぶ
* @description 自動クッキー叩き、いくつかの実績取得に合わせた自動購入、そしてチート
* @include http://orteil.dashnet.org/cookieclicker/
* @license MIT License
* @require
*/
(function(){
window.GameX = {};
GameX.Cheats = {};
GameX.CheatCommands = {};
GameX.Autopilots = {};
var AbstractCheat = function(opt){
opt = opt || {};
this.name = opt.name;
this.enabled = 'enabled' in opt ? opt.enabled : false;
this.Init = opt.init || function(){};
this.Logic = opt.logic || function(){};
this.Init();
var self = this;
var onToggle = opt.onToggle || function(){};
this.Toggle = function(e){
self.enabled = !self.enabled;
onToggle.apply(self, [self.enabled]);
};
this.Iter = function(){
if(!self.enabled) return;
self.Logic();
};
this.UpdateButton = function(button){
button.innerHTML = '';
button.className = 'option' + (self.enabled ? ' enabled' : '');
button.appendChild(document.createTextNode(self.name + ' ' + (self.enabled ? 'ON' : 'OFF')));
};
this.MakeButton =function(list){
var button = document.createElement('a');
list.appendChild(button);
button.onclick=function(e){
self.Toggle();
self.UpdateButton(button);
};
self.UpdateButton(button);
};
};
var GetCheatedCookie = function(){
if(!this.enabled && Game.Achievements['Cheated cookies taste awful']) return;
Game.Win('Cheated cookies taste awful');
};
GameX.Cheat = function(opt){
opt = opt || {};
if(!('enabled' in opt))opt.enabled = false;
AbstractCheat.apply(this, [opt]);
this.Iter = (
function(orig){
return function(){
GetCheatedCookie();
orig.apply(this, arguments);
};
}
)(this.Iter);
GameX.Cheats[this.name] = this;
};
GameX.Autopilot = function(opt){
AbstractCheat.apply(this, arguments);
GameX.Autopilots[this.name] = this;
};
GameX.CheatCommand = function(opt){
opt = opt || {};
this.name = opt.name;
this.action = opt.action;
GameX.CheatCommands[this.name]=this;
var self = this;
this.MakeButton = function(list){
var button = document.createElement('a');
list.appendChild(button);
button.className = 'option';
button.appendChild(document.createTextNode(self.name));
button.onclick = function(){
GetCheatedCookie();
self.action();
};
};
};
new GameX.Autopilot(
{
name: 'auto clicking',
logic: function(){
Game.ClickCookie();
}
}
);
new GameX.Cheat(
{
name: 'rapid production of golden cookies',
init: function(){
var self = this;
var R = null;
var g = Game.goldenCookie;
(function(c){
c=g.choose;
g.choose=function(){
if(!self.enabled) return c();
R = g.wraith<=0 ? c() : choose(['chain cookie',
'blood frenzy']);
return R;
};
})(g.choose);
(function(C){
g.click=function(){
C();
if(!self.enabled) return;
setTimeout(function(){g.delay=0;},
{'frenzy': 77000,
'blood frenzy': 6000,
'click frenzy': 6000}[R]||0);
};
})(g.click);
},
onToggle: function(flag){
if(!flag) return;
Game.goldenCookie.life=0;
Game.goldenCookie.delay=0;
},
logic: function(){
}
}
);
new GameX.Cheat(
{
name: 'rapid research',
init: function(){
},
logic: function(){
Game.researchT=0;
}
}
);
new GameX.Autopilot(
{
name: 'auto clicking of golden cookies',
logic: function(){
var g = Game.goldenCookie;
if(g.delay == 0)g.click();
}
}
);
new GameX.Autopilot(
{
name: 'auto purchase',
logic: function(){
if(!Game.Achievements['Just wrong'].won &&
Game.Objects['Grandma'].amount > 0)
Game.Objects['Grandma'].sell();
var limit = {
'Cursor':200,
'Grandma': 100,
'Farm':100,
'Factory':100,
'Mine':100,
'Shipment':100,
'Alchemy lab':100,
'Portal':100,
'Time machine':100,
'Antimatter condenser':100
};
if(!Game.Achievements['Mathematician'].won){
limit = {
'Cursor':128,
'Grandma':128,
'Farm':128,
'Factory':64,
'Mine':32,
'Shipment':16,
'Alchemy lab':8,
'Portal':4,
'Time machine':2,
'Antimatter condenser':1
};
for(var name in limit){
var o = Game.Objects[name];
var sell = o.amount - limit[name];
for(var i=0;i<sell;i++){
o.sell();
}
}
}else{
var flag = true;
for(var obj in limit){
if(limit[obj] <= Game.Objects[obj].amount) continue;
flag = false;
break;
}
if(flag){
limit['Cursor'] = 0;
limit['Grandma'] = 0;
limit['Portal'] = 0;
limit['Antimatter condenser'] = 0;
}
}
var item = {price: Game.cookies+1, buy: function(){}};
for(var i in Game.ObjectsById)(
function(o){
var max = limit[o.name];
if(max > 0 && max <= o.amount) return;
if(o.price <= Game.cookies && o.price < item.price){
item = {
price: o.price,
buy: function(){
o.buy();
}
};
}
}
)(Game.ObjectsById[i]);
for(var i in Game.UpgradesById)(
function(o){
var price = o.basePrice;
if({
'One mind': true,
'Communal brainsweep': true,
'Elder Pact': true,
'Elder Pledge': true,
'Revoke Elder Covenant':true
}[o.name]) return;
if(!o.unlocked || o.bought || price > Game.cookies || item.price < price) return;
item = {price: price,
buy: function(){
o.buy();
}};
}
)(Game.UpgradesById[i]);
item.buy();
}
}
);
new GameX.CheatCommand(
{
name: "earn heavenly chips",
action: function(){
if(Game.prestige['Heavenly chips'] < 1){
Game.prestige['Heavenly chips'] = 1;
}else{
Game.prestige['Heavenly chips'] *= 10;
}
}
}
);
GameX.Iter = function(){
var name;
for(name in GameX.Autopilots){
GameX.Autopilots[name].Iter();
}
for(name in GameX.Cheats){
GameX.Cheats[name].Iter();
}
};
(function(L){
if(Game._cheat_installed_) return;
Game._cheat_installed_ = true;
(function(orig){
Game.UpdateMenu = function(){
orig();
if(Game.onMenu == 'prefs'){
var subs = document.querySelector('#menu > .subsection');
var set = {
Autopilot: GameX.Autopilots,
Cheat: GameX.Cheats,
'Cheat Command': GameX.CheatCommands
};
for(var section in set) (
function(section){
var title = document.createElement('div');
subs.appendChild(title);
title.className = 'title';
title.appendChild(document.createTextNode(section));
var list = document.createElement('div');
list.className = 'listing';
subs.appendChild(list);
for(var name in set[section]){
set[section][name].MakeButton(list);
}
}
)(section);
}
};
})(Game.UpdateMenu);
Game.Loop = function(){
GameX.Iter();
L();
};
Game.Popup('Bookmarklet is installed.<br>Show the [Menu] screen.<br>');
})(Game.Loop);
})();