Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // by toby hinloopen - toby at kutcomputers dot nl
- // Remove existing API, if present
- if(window.CCAPI) {
- window.CCAPI.destroy();
- window.CCAPI = undefined;
- }
- // API
- var CCAPI = (function() {
- var CCAPI = this;
- var objects = {};
- var upgrades = {};
- var stepCallbacks = [];
- var stepActionPerformed = null;
- var performAction = function(desc) {
- if(stepActionPerformed) {
- console.warn("Ignoring '"+stepActionPerformed+"': already performed '"+desc+"'");
- return false;
- }
- stepActionPerformed = desc || true;
- return true;
- };
- var runApiLogic = function() {
- if(!stepCallbacks.length) { return; }
- stepActionPerformed = null;
- for(var i=0; i<stepCallbacks.length; i++) {
- stepCallbacks[i](CCAPI);
- }
- if(!stepActionPerformed) console.log("No action performed.");
- };
- var runGameLogic = Game.Logic;
- Game.Logic = function() {
- runApiLogic();
- runGameLogic.call(Game);
- }
- var Obj = this.Obj = function(id) { this.id = id; };
- Obj.prototype.sell = function() { return this.sellable() && performAction("sell "+this.name()) && (Game.ObjectsById[this.id].sell() && true || true); };
- Obj.prototype.buy = function() { return this.buyable() && performAction("buy "+this.name()) && (Game.ObjectsById[this.id].buy() && true || true); };
- Obj.prototype.name = function() { return Game.ObjectsById[this.id].name; };
- Obj.prototype.cps = function() { try { return Game.ObjectsById[this.id].cps(); } catch(e) { console.error(e); return 1; } };
- Obj.prototype.amount = function() { return Game.ObjectsById[this.id].amount; };
- Obj.prototype.bought = function() { return Game.ObjectsById[this.id].bought; };
- Obj.prototype.price = function() { return Game.ObjectsById[this.id].price; };
- Obj.prototype.sellable = function(){ return this.amount() > 0; };
- Obj.prototype.buyable = function(){ return this.price() <= CCAPI.cookies(); };
- for(var i=0; i<Game.ObjectsN; i++) {
- var gameObj = Game.ObjectsById[i];
- objects[gameObj.id] = objects[gameObj.name] = new this.Obj(gameObj.id);
- }
- var Upgrade = this.Upgrade = function(id){ this.id = id; };
- Upgrade.prototype.buy = function(){ return this.buyable() && performAction("buy "+this.name()) && (Game.UpgradesById[this.id].buy() && true || true); };
- Upgrade.prototype.buyable = function(){ return this.unlocked() && !this.bought() && this.price() <= CCAPI.cookies(); };
- Upgrade.prototype.unlocked = function(){ return Game.UpgradesById[this.id].unlocked > 0; };
- Upgrade.prototype.price = function(){ return Game.UpgradesById[this.id].basePrice; };
- Upgrade.prototype.bought = function(){ return Game.UpgradesById[this.id].bought > 0; };
- Upgrade.prototype.name = function(){ return Game.UpgradesById[this.id].name; };
- for(var i=0; i<Game.UpgradesN; i++) {
- var gameUpgrade = Game.UpgradesById[i];
- upgrades[gameUpgrade.id] = upgrades[gameUpgrade.name] = new this.Upgrade(gameUpgrade.id);
- }
- this.goldenCookieLife = function() { return Game.goldenCookie.life; }
- this.clickGoldenCookie = function() { return CCAPI.goldenCookieLife() > 0 && performAction("click golden cookie") && (Game.goldenCookie.click() && true || true) }
- this.clickCookie = function() { return performAction("click cookie") && (Game.ClickCookie() && true || true); };
- this.cps = function() { return Game.cookiesPs; }
- this.cookies = function() { return Game.cookies; };
- this.step = function(fn) { stepCallbacks.push(fn); };
- this.obj = function(idOrName) { return objects[idOrName]; };
- this.objlen = function() { return Game.ObjectsN; };
- this.upgrade = function(idOrName) { return upgrades[idOrName]; };
- this.upgradelen = function() { return Game.UpgradesN; };
- this.destroy = function() { Game.Logic = runGameLogic; };
- this.reset = function() { Game.Reset(true); Game.T = 0; };
- this.multiplier = 1;
- return this;
- }).call({});
- // BOT LOGIC
- var infoContainer = document.createElement("div");
- infoContainer.style.background = "black";
- infoContainer.style.width = "300px";
- infoContainer.style.position = "fixed";
- infoContainer.style.bottom = "0px";
- infoContainer.style.left = "0px";
- infoContainer.style.padding = "3px";
- infoContainer.style.zIndex = "100000001";
- document.body.appendChild(infoContainer);
- var buyingInfo = document.createElement("div");
- infoContainer.appendChild(buyingInfo);
- var timeInfo = document.createElement("div");
- infoContainer.appendChild(timeInfo);
- CCAPI.Obj.prototype.paybackPeriod = CCAPI.Upgrade.prototype.paybackPeriod = function() {
- return this.price() / this.cps();
- };
- CCAPI.Obj.prototype.buyableDelay = CCAPI.Upgrade.prototype.buyableDelay = function() {
- return this.buyable() ? 0 : (this.price() - CCAPI.cookies()) / CCAPI.cps();
- };
- CCAPI.reset();
- var mreached = false;
- CCAPI.step(function(api) {
- if(!mreached && api.cookies() >= 1000000) {
- var secs = (Game.T / Game.fps).toFixed();
- var timeStr = "Time: "+Math.floor(secs/60)+"m "+(secs%60)+"s";
- alert("1M cookies reached @ "+timeStr);
- mreached = true;
- }
- });
- CCAPI.step(function(api) {
- var secs = (Game.T / Game.fps).toFixed();
- timeInfo.textContent = "Time: "+Math.floor(secs/60)+"m "+(secs%60)+"s";
- if(api.clickGoldenCookie())
- return;
- var cheapestUpgrade = null;
- for(var j=0; j<api.upgradelen(); j++) {
- var upgrade = api.upgrade(j);
- if(!upgrade.bought() && upgrade.unlocked() && (cheapestUpgrade == null || cheapestUpgrade.price() > upgrade.price())) {
- cheapestUpgrade = upgrade;
- }
- }
- var targetObj = null;
- for(var i=0; i<api.objlen(); i++) {
- var obj = api.obj(i);
- if(targetObj == null || obj.buyableDelay() + obj.paybackPeriod() < targetObj.buyableDelay() + targetObj.paybackPeriod()) {
- targetObj = obj;
- }
- }
- var targetBuyable = cheapestUpgrade && cheapestUpgrade.price()*2 < targetObj.price() ? cheapestUpgrade : targetObj;
- buyingInfo.textContent = "Buying "+targetBuyable.name()+" in "+targetBuyable.buyableDelay().toFixed();
- if(targetBuyable.buy()) return;
- api.clickCookie();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement