Skip to content

Instantly share code, notes, and snippets.

@XVicarious
Last active October 5, 2017 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XVicarious/37eabfab2fa21ea4d27698d9d26c3715 to your computer and use it in GitHub Desktop.
Save XVicarious/37eabfab2fa21ea4d27698d9d26c3715 to your computer and use it in GitHub Desktop.
I've taken this game too far
const head = document.getElementsByTagName('head')[0];
const jQuery = document.createElement('script');
jQuery.type = 'text/javascript';
jQuery.src = 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js';
let ogLength = 0;
const jQCode = function() {
const badUpgrades = [74, 84, 85, 182, 183, 184, 185, 209, 332, 333, 361];
/* [buildingId, multiplier] */
const upgradeEffect = [
[[0], [0, 1, 2], 2],
[[0], [3], [function() {
return Game.objectIncreasedBy(0, 0.1);
}]],
[[0], [4], [function() {
return Game.objectIncreasedBy(0, 0.5);
}]],
[[0], [5], [function() {
return Game.objectIncreasedBy(0, 5);
}]],
[[0], [6], [function() {
return Game.objectIncreasedBy(0, 50);
}]],
[[0], [43], [function() {
return Game.objectIncreasedBy(0, 500);
}]],
[[0], [82], [function() {
return Game.objectIncreasedBy(0, 5000);
}]],
[[0], [109], [function() {
return Game.objectIncreasedBy(0, 50000);
}]],
[[0], [188], [function() {
return Game.objectIncreasedBy(0, 500000);
}]],
[[0], [189], [function() {
return Game.objectIncreasedBy(0, 5000000);
}]],
[[1], [7, 8, 9, 44, 110, 192, 294, 397, 428], [2]],
[[2], [10, 11, 12, 45, 111, 193, 295, 308, 429], [2]],
[[3], [16, 17, 18, 47, 113, 195, 296, 309, 430], [2]],
[[4], [13, 14, 15, 46, 112, 194, 297, 310, 431], [2]],
[[5], [232, 233, 234, 235, 236, 237, 298, 311, 432], [2]],
[[6], [238, 239, 240, 241, 242, 243, 299, 312, 433], [2]],
[[7], [244, 245, 246, 247, 248, 249, 300, 313, 434], [2]],
[[8], [19, 20, 21, 48, 114, 196, 301, 314, 435], [2]],
[[9], [22, 23, 24, 49, 115, 197, 302, 315, 436], [2]],
[[10], [25, 26, 27, 50, 116, 198, 303, 316, 437], [2]],
[[11], [28, 29, 30, 51, 117, 199, 304, 317, 438], [2]],
[[12], [99, 100, 101, 118, 200, 305, 318, 439], [2]],
[[13], [175, 176, 177, 178, 179, 201, 306, 319, 440], [2]],
[[14], [416, 417, 418, 419, 420, 421, 422, 423, 441], [2]],
[[-1], [33, 34, 35, 36, 37], [function() {
return (Game.globalCpsMult + 0.01) / Game.globalCpsMult;
}]],
[[-1], [38, 39, 40, 41, 42, 80, 81, 88, 89, 90, 104, 105, 106, 107, 150, 151,
92, 93, 94, 95, 96, 97, 98, 125, 126, 127, 128, 344, 134, 135, 136,
137, 138, 139, 140, 143, 144, 145, 146, 147, 148, 149, 169, 170, 171,
172, 173, 174], [function() {
return (Game.globalCpsMult + 0.02) / Game.globalCpsMult;
}]],
[[-1], [258, 259, 260, 261, 262, 263, 120, 121, 122, 123, 401, 402, 202, 203,
204, 205, 206, 207, 230, 231], [function() {
return (Game.globalCpsMult + 0.03) / Game.globalCpsMult;
}]],
[[-1], [256, 257, 338, 339, 340, 341, 342, 343, 350, 351, 352, 403, 404, 405,
406, 407, 345, 346, 347, 348, 349], [function() {
return (Game.globalCpsMult + 0.04) / Game.globalCpsMult;
}]],
[[-1], [330], [function() {
return (Game.globalCpsMult + 0.05) / Game.globalCpsMult;
}]],
[[-1], [334, 335, 336, 337, 400], [function() {
return 0.1 / Game.globalCpsMult + 1;
}]],
[[1, 2], [57], [2, function() {
return (Game.ObjectsById[2].storedCps * Game.ObjectsById[1].amount) / 10000 + 1;
}]],
[[1, 3], [58], [2, function() {
return (Game.ObjectsById[3].storedCps * (Game.ObjectsById[1].amount / 2)) / 10000 + 1;
}]],
[[1, 4], [59], [2, function() {
return (Game.ObjectsById[4].storedCps * (Game.ObjectsById[1].amount / 3)) / 10000 + 1;
}]],
[[1, 5], [250], [2, function() {
return (Game.ObjectsById[5].storedCps * (Game.ObjectsById[1].amount / 4)) / 10000 + 1
}]],
[[1, 6], [251], [2, function() {
return (Game.ObjectsById[6].storedCps * (Game.ObjectsById[1].amount / 5)) / 10000 + 1;
}]],
[[1, 7], [252], [2, function() {
return (Game.ObjectsById[7].storedCps * (Game.ObjectsById[1].amount / 6)) / 10000 + 1;
}]],
[[1, 8], [60], [2, function() {
return (Game.ObjectsById[8].storedCps * (Game.ObjectsById[1].amount / 7)) / 10000 + 1;
}]],
[[1, 9], [61], [2, function() {
return (Game.ObjectsById[9].storedCps * (Game.ObjectsById[1].amount / 8)) / 10000 + 1
}]],
[[1, 10], [62], [2, function() {
return (Game.ObjectsById[10].storedCps * (Game.ObjectsById[1].amount / 9)) / 10000 + 1;
}]],
[[1, 11], [63], [2, function() {
return (Game.ObjectsById[11].storedCps * (Game.ObjectsById[1].amount / 10)) / 10000 + 1;
}]],
[[1, 12], [103], [2, function() {
return (Game.ObjectsById[12].storedCps * (Game.ObjectsById[1].amount / 11)) / 10000 + 1;
}]],
[[1, 13], [180], [2, function() {
return (Game.ObjectsById[13].storedCps * (Game.ObjectsById[1].amount / 12)) / 10000 + 1
}]],
[[1, 14], [415], [2, function() {
return (Game.ObjectsById[14].storedCps * (Game.ObjectsById[1].amount / 13)) / 10000 + 1
}]],
];
Game.findUpgradeMultiplier = function(upgradeId) {
for (let i = 0; i < upgradeEffect.length; i++) {
for (let j = 0; j < upgradeEffect[i][1].length; j++) {
if (upgradeEffect[i][1][j] === upgradeId) {
return [upgradeEffect[i][0], upgradeEffect[i][2]];
}
}
}
return 1;
};
let seasonsToVisitId = [182, 183, 184, 209];
let seasonsToVisitNames = ['christmas', '', '', 'easter'];
let totalOwned = 0;
let clicksPerSecond = 0;
Game.mostEfficientItem = null;
Game.ObjectsById.forEach(function(object) {
totalOwned += object.bought;
});
Game.objectIncreasedBy = function(objectId, increasedByEach) {
let thing = Game.ObjectsById[0].storedCps;
if (typeof Game.ObjectsById[0].storedCps === 'function') {
thing = Game.ObjectsById[0].storedCps();
}
return (((Game.BuildingsOwned - Game.ObjectsById[objectId].amount) * 0.1) / thing) + 1;
};
PlaySound = function() {};
Game.playCookieClickSound = function() {};
Game.particlesDraw = function() {};
Game.particlesUpdate = function() {};
Game.DrawBuildings = function() {};
Game.AscendGains = function() {
return parseInt(Game.ascendNumber.textContent.substr(1));
};
Game.prestigeSorter = function(a, b) {
if (a.basePrice < b.basePrice) {
return -1;
} else if (a.basePrice > b.basePrice) {
return 1;
}
return 0;
};
const clicksAtOnce = 75;
const repeatInterval = 1;
const autoClicker = function(clicksAtOnce, repeatInterval) {
let cheated = false;
const intoTheAbyss = function() {
if (!cheated) {
cheated = true;
for (let i = 0; i < clicksAtOnce; i++) {
Game.ClickCookie();
Game.lastClick = 0;
}
cheated = false;
}
};
return setInterval(intoTheAbyss, repeatInterval);
};
Game.Ascended = false;
Game.AutoAscend = function() {
Game.Ascend();
$('a#promptOption0').click();
Game.Ascended = true;
};
Game.BuyHeavenly = function() {
if (Game.Ascended) {
Game.PrestigeUpgrades.sort(Game.prestigeSorter);
for (let i = 0; i < Game.PrestigeUpgrades.length; i++) {
if (!Game.PrestigeUpgrades[i].bought
&& Game.heavenlyChips > Game.PrestigeUpgrades[i].basePrice) {
break;
}
Game.PrestigeUpgrades[i].buy();
}
}
};
Game.AutoReincarnate = function() {
Game.Reincarnate();
$('a#promptOption0').click();
Game.Ascended = false;
};
/**
* Checks what season it is and changes the season if needed.
*/
function seasonChecker() {
const christmasCookies = [143, 144, 145, 146, 147, 147, 149];
const season = Game.season;
if (season === 'christmas' && seasonDone(christmasCookies)) {
const visit = seasonsToVisitId.pop();
Game.UpgradesById[visit].buy();
}
}
/**
* Checks if the season is completed.
* @param {array} upgradeArray upgrades that are part of the season event
* @return {boolean}
*/
function seasonDone(upgradeArray) {
const upgradeArrayLength = upgradeArray.length;
for (let i = 0; i < upgradeArrayLength; i++) {
if (!Game.UpgradesById[i].bought) {
return false;
}
}
return true;
}
/**
* Clicks on things.
*/
function clickFrenzy() {
let goldenCookie = document.getElementById('goldenCookie');
if (goldenCookie.style.display !== 'none') {
goldenCookie.click();
}
if (Game.season === 'christmas') {
let seasonPopup = document.getElementById('seasonPopup');
if (seasonPopup.style.display !== 'none') {
seasonPopup.click();
}
if (Game.santaLevel < 14) {
Game.UpgradeSanta();
}
}
Game.UpgradeDragon();
autoClicker(clicksAtOnce, repeatInterval);
setTimeout(clickFrenzy, 1);
}
/**
* Purchase upgrades, except for those pesky ones.
*/
function purchaseUpgrades() {
let arrayUpgrades = document.getElementsByClassName('upgrade');
let upgradeCount = arrayUpgrades.length;
for (let i = 0; i < upgradeCount; i++) {
let onclickscript = arrayUpgrades[i].getAttribute('onclick') || -1;
if (onclickscript !== -1) {
let id = parseInt(onclickscript.substr(18).slice(
0, onclickscript.lastIndexOf(']')
));
if (badUpgrades.indexOf(id) === -1) {
eval(onclickscript);
}
}
}
}
/**
* Purchases grandma's and the like.
*/
function purchaseProducts() {
let currentEfficency = 0;
let timeSinceStart = (Date.now() - Game.startDate) / 1000;
let realCookiesPerSecond
= Game.cookiesPs + (clicksPerSecond * Game.computedMouseCps);
let products = Game.ObjectsById;
let productsLength = products.length;
let upgrades = Game.UpgradesById;
let mostEfficient = products[0];
let numberToBuy = 1;
for (let i = 0; i < productsLength; i++) {
let newProduct = products[i];
let newEfficeny = calculateUpgradeScore(realCookiesPerSecond, newProduct.storedCps, newProduct);
if (newEfficeny > currentEfficency) {
mostEfficient = newProduct;
currentEfficency = newEfficeny;
}
}
for (let i = 0; i < Game.UpgradesById.length; i++) {
if (upgrades[i].unlocked === 1 && upgrades[i].bought === 0) {
let upgradeMultipler = Game.findUpgradeMultiplier(i);
if (typeof upgradeMultipler[0] === 'undefined') {
continue;
} else if (typeof upgradeMultipler[1] === 'function') {
upgradeMultipler[1] = upgradeMultipler[1]();
}
let addedCps = 0;
for (let i = 0; i < upgradeMultipler[1].length; i++) {
if (typeof upgradeMultipler[1][i] === 'function') {
upgradeMultipler[1][i] = upgradeMultipler[1][i]();
}
if (upgradeMultipler[0][i] !== -1) {
addedCps += Game.ObjectsById[upgradeMultipler[0][i]].storedCps
* Game.ObjectsById[upgradeMultipler[0][i]].amount
* (upgradeMultipler[1][i] - 1);
} else {
addedCps += (Game.cookiesPs * (upgradeMultipler[1][i] - 1));
}
}
let newEfficeny = calculateUpgradeScore(realCookiesPerSecond, addedCps, upgrades[i]);
if (newEfficeny > currentEfficency) {
mostEfficient = upgrades[i];
currentEfficency = newEfficeny;
}
}
}
return mostEfficient;
}
/**
* Purchases upgrades and products!
*/
function twoGirlsAtOnce() {
if (!Game.Ascended && Game.prestige < Game.AscendGains()) {
//Game.AutoAscend();
}
if (Game.Ascended && Game.AscendTimer === 0) {
Game.BuyHeavenly();
Game.AutoReincarnate();
}
// purchaseUpgrades();
if (Game.mostEfficientItem === null) {
Game.mostEfficientItem = purchaseProducts();
}
if (Game.cookies >= Game.mostEfficientItem.getPrice()) {
if (Game.mostEfficientItem == Game.ObjectsById[Game.mostEfficientItem.id]) {
Game.mostEfficientItem.buy(1);
} else {
Game.mostEfficientItem.buy();
}
Game.mostEfficientItem = null;
}
setTimeout(twoGirlsAtOnce, 1);
}
/**
* todo: Figure out exactly what this does.
*/
function calculateClicksPerSecond() {
let earlyClicks = Game.cookieClicks;
setTimeout(function() {
clicksPerSecond = Game.cookieClicks - earlyClicks;
}, 1000);
setTimeout(calculateClicksPerSecond, 600000);
}
/**
* Calculates exactly what product is the most efficent to purchase.
* @param {number} cookiesPerSecond how many cookies per second are made
* @param {object} objectCps the game object
* @param {object} object the object
* @return {number} how profitable the item is to buy
*/
function calculateUpgradeScore(cookiesPerSecond, objectCps, object) {
return (100 * (cookiesPerSecond + objectCps)) / object.getPrice();
}
console.log('AutoCookie2 Loaded');
console.log('Multibuy Mode Enabled...');
console.log('Remember to disable googlesyndication and google-analytics ' +
'scripts for the best performance. They have a large hit on the script!');
const clickerBlob = URL.createObjectURL(
new Blob(['(', clickFrenzy(), ')()'], {
type: 'application/javascript',
}));
const productBlob = URL.createObjectURL(
new Blob(['(', twoGirlsAtOnce(), ')()'], {
type: 'application/javascript',
}));
const calcBlob = URL.createObjectURL(
new Blob(['(', calculateClicksPerSecond(), ')()'], {
type: 'application/javascript',
}));
Game.clickerWorker = new Worker(clickerBlob);
Game.productWorker = new Worker(productBlob);
Game.calcWorker = new Worker(calcBlob);
URL.revokeObjectURL(clickerBlob);
URL.revokeObjectURL(productBlob);
URL.revokeObjectURL(calcBlob);
};
jQuery.onreadystatechange = jQCode;
jQuery.onload = jQCode;
head.appendChild(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment