/*
* @title クッキーのアレを遊ぶ
* @description 自動クッキー叩き、いくつかの実績取得に合わせた自動購入、そしてチート
* @include http://orteil.dashnet.org/cookieclicker/
* @license MIT License
* @require
*/
(function(){
window.GameX = {};
GameX.Cheats = {};
GameX.Autopilots = {};
var AbstractCheat = function(opt){
opt = opt || {};
this.name = opt.name;
this.enabled = 'enabled' in opt ? opt.enabled : true;
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);
};
};
GameX.Cheat = function(opt){
opt = opt || {};
if(!('enabled' in opt))opt.enabled = false;
AbstractCheat.apply(this, [opt]);
this.Iter = (
function(orig){
return function(){
if(this.enabled && Game.Achievements['Cheated cookies taste awful']){
Game.Win('Cheated cookies taste awful');
}
orig.apply(this, arguments);
};
}
)(this.Iter);
GameX.Cheats[this.name] = this;
};
GameX.Autopilot = function(opt){
AbstractCheat.apply(this, arguments);
GameX.Autopilots[this.name] = this;
};
new GameX.Autopilot(
{
name: 'auto clicking',
logic: function(){
Game.ClickCookie();
}
}
);
new GameX.Cheat(
{
name: 'rapid production of golden cookies',
enabled: false,
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.Autopilot(
{
name: 'auto clicking of golden cookie',
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();
}
}
}
var item = {price: Game.cookies+1, buy: function(){}};
for(var i in Game.ObjectsById)(
function(o){
if(limit[o.name] <= 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(!o.unlocked || o.bought || price > Game.cookies || item.price < price) return;
item = {price: price,
buy: function(){
o.buy();
}};
}
)(Game.UpgradesById[i]);
item.buy();
}
}
);
GameX.Iter = function(){
for(var cheat in GameX.Autopilots){
GameX.Autopilots[cheat].Iter();
}
for(var cheat in GameX.Cheats){
GameX.Cheats[cheat].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
};
for(var section in set){
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);
}
}
}
};
})(Game.UpdateMenu);
Game.Loop = function(){
GameX.Iter();
L();
};
})(Game.Loop);
})();