Skip to content

Instantly share code, notes, and snippets.

@GabeStah
Last active April 10, 2020 01:47
Show Gist options
  • Save GabeStah/bed9ca6b0227a5f4c5efc150eb9ba3cd to your computer and use it in GitHub Desktop.
Save GabeStah/bed9ca6b0227a5f4c5efc150eb9ba3cd to your computer and use it in GitHub Desktop.
Kookie Autobuyer - Cookie Clicker Helper
// ==UserScript==
// @name Cookie Clicker Helper
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Helps with all the things cookie!
// @author Gabe Wyatt <[email protected]>
// @match https://orteil.dashnet.org/cookieclicker/
// @require https://code.jquery.com/jquery-3.4.1.slim.min.js
// @require https://raw.githubusercontent.com/marcuswestin/store.js/master/dist/store.everything.min.js
// @use https://gist.github.com/GabeStah/bed9ca6b0227a5f4c5efc150eb9ba3cd/raw/9d1f559624d66831f4c6a79629baed1ee8f30e5d/kookie-autobuyer.user.js
// @grant none
// ==/UserScript==
const newStore = store;
$(document).ready(function () {
setTimeout(() => {
var code =
'(' +
function () {
var checkReady = setInterval(function () {
if (typeof Game.ready !== 'undefined' && Game.ready) {
Game.LoadMod(
'https://aktanusa.github.io/CookieMonster/CookieMonster.js'
);
clearInterval(checkReady);
}
}, 1000);
}.toString() +
')()';
window.eval(code);
const DEFAULT_SETTINGS = {
// E
KLICKER_ENABLED: true,
// B
AUTOBUY_ENABLED: true,
AUTOBUY_DELAY: 100,
// M
AUTOCLICKER_ENABLED: true,
AUTOCLICKER_DELAY: 25,
// N
SEASONAL_ENABLED: true,
SEASONAL_DELAY: 500,
// G
GOLDEN_CLICKER_ENABLED: true,
GOLDEN_CLICKER_DELAY: 250,
// F
CHECK_LUCKY_THRESHOLD: true,
// F
CHECK_FRENZY_THRESHOLD: true,
// P
WRINKLER_POPPER_ENABLED: true,
WRINKLER_POPPER_DELAY: 2500,
// S, will save up for next big upgrade.
SAVE_FOR_UPGRADE_ENABLED: true,
SAVE_FOR_UPGRADE_MAX_MINS: 10,
TEMP_DISABLE_AUTOBUY_MIN_PRISMS: 250,
TEMP_DISABLE_AUTOBUY_PRISM_INCREMENT: 1,
RESET_INCOME_PERCENT: 400,
// Reincarnation delay (milliseconds)
REINCARNATION_DELAY: 10000,
ASCENSION_DELAY: 10000,
};
const PANTHEON = {
gods: [
{
// Godzamak
id: 'ruin',
slot: 0,
},
{
// Muradil
id: 'labor',
slot: 1,
},
{
// Selebrak
id: 'seasons',
slot: 2,
},
],
};
var KLICKER_ENABLED = true;
var AUTOBUYER;
var AUTOCLICKER;
var AVG_CLICKS_PER_SECOND;
var SEASONAL;
var SEASON_LIST = [
{
name: 'valentines',
order: 1,
id: 184,
},
{
name: 'christmas',
order: 2,
default: true,
id: 182,
},
{
name: 'easter',
order: 3,
id: 209,
},
{
name: 'halloween',
order: 4,
id: 183,
},
];
var GOLDEN_CLICKER;
var DRAGON_UPDATER;
var SANTA_UPDATER;
var NOTES_CLOSER;
var PANTHEON_UPDATER;
var SHOULD_DISABLE_AUTOBUY_CHECKER;
var SHOULD_RESET_GAME_CHECKER;
var TEMP_AUTOBUY_DISABLED = false;
var RESETTING_GAME = false;
var WRINKLER_POPPER;
// Time after game start at which first golden cookie pops.
var RESET_TIME_TO_GOLDEN_COOKIE = 450;
// Time after reset at which golden cookie timer is accurate with upgrades.
var RESET_TIME_TO_GOLDEN_COOKIE_TIMER_SET = 860;
var IGNORED_UPGRADES = [
'Communal brainsweep',
'Elder Covenant',
'Elder Pact',
'Elder Pledge',
'Golden switch',
//'One mind',
'Milk selector',
'Chocolate egg',
];
var UPGRADE_WHITELIST = [
{
name: 'Bingo center/Research facility',
id: 64,
},
{
name: 'Plastic mouse',
id: 75,
},
{
name: 'Iron mouse',
id: 76,
},
{
name: 'Titanium mouse',
id: 77,
},
{
name: 'Adamantium mouse',
id: 78,
},
{
name: 'Unobtainium mouse',
id: 119,
},
{
name: 'Eludium Mouse',
id: 190,
},
{
name: 'Wishalloy Mouse',
id: 191,
},
{
name: 'Fantasteel Mouse',
id: 366,
},
{
name: 'Nevercrack Mouse',
id: 367,
},
{
name: 'Armythril Mouse',
id: 427,
},
{
name: 'Technobsidian Mouse',
id: 460,
},
{
name: 'Plasmarble Mouse',
id: 461,
},
{
name: 'Lucky day',
id: 52,
ratio: 1,
},
{
name: 'Serendipity',
id: 53,
ratio: 1,
},
{
name: 'Get lucky',
id: 86,
ratio: 1,
},
// CHRISTMAS
{
name: 'A festive hat',
id: 152,
ratio: 1,
},
{
name: 'Increased merriness',
id: 153,
ratio: 1,
},
{
name: 'Improved jolliness',
id: 154,
ratio: 1,
},
{
name: 'A lump of coal',
id: 155,
ratio: 1,
},
{
name: 'An itchy sweater',
id: 156,
ratio: 1,
},
{
name: 'Reindeer baking grounds',
id: 157,
ratio: 1,
},
{
name: 'Weighted sleighs',
id: 158,
ratio: 1,
},
{
name: 'Ho ho ho-flavored frosting',
id: 159,
ratio: 1,
},
{
name: 'Season savings',
id: 160,
ratio: 1,
},
{
name: 'Specialized chocolate chips',
id: 65,
},
{
name: 'Toy workshop',
id: 161,
ratio: 1,
},
{
name: 'Naughty list',
id: 162,
ratio: 1,
},
{
name: "Santa's bottomless bag",
id: 163,
ratio: 1,
},
{
name: "Santa's helpers",
id: 164,
ratio: 1,
},
{
name: "Santa's legacy",
id: 165,
ratio: 1,
},
{
name: "Santa's milk and cookies",
id: 166,
ratio: 1,
},
{
name: "Santa's dominion",
id: 168,
ratio: 1,
},
// DRAGON
{
name: 'A crumbly egg',
id: 324,
ratio: 1,
},
//
{
name: 'Kitten experts',
id: 322,
ratio: 1,
waiting: function () {
// If 210+ Prisms owned
// Kitten experts not owned
return (
Game.Objects['Prism'].amount >= 210 &&
!Game.UpgradesById[322].bought &&
!GameUpgrade('Kitten experts').canBuy()
);
},
},
// EASTER
{
name: 'Golden goose egg',
id: 222,
ratio: 1,
},
{
name: 'Faberge egg',
id: 223,
ratio: 1,
},
{
name: 'Wrinklerspawn',
id: 224,
ratio: 1,
},
{
name: 'Cookie egg',
id: 225,
ratio: 1,
},
{
name: 'Omelette',
id: 226,
ratio: 1,
},
{
name: 'Century egg',
id: 228,
ratio: 1,
},
{
name: 'egg',
id: 229,
ratio: 1,
},
];
var LOGGED_MESSAGES = [];
// ****
// UTIL
// ****7
function AreAllWrinklersActive() {
var active = 0;
var max = 0;
if (Game.Has('One mind')) {
max = 10;
if (Game.Has('Elder spice')) {
max = 12;
}
if (
Game.season === 'halloween' &&
SeasonalUnlocksRemaining(Game.season)
) {
max = 1;
}
}
if (max > 0) {
for (var i in Game.wrinklers) {
if (Game.wrinklers[i].sucked > 0) {
active++;
}
}
return max - active <= 0;
}
return false;
}
// Purchase the next best valid item.
function BuyNextPurchase() {
// Disable during ascension
if (Game.OnAscend) return;
var purchase = GetNextPurchase();
if (purchase) {
// Check if waiting
if (
(typeof purchase.waiting == 'function' && purchase.waiting()) ||
(typeof purchase.waiting !== 'function' && purchase.waiting)
) {
LogMessage(
`Saving up for ${purchase.item.name}, time ${CM.Disp.FormatTime(
purchase.timeToPurchase
)}.`
);
} else {
if (purchase.itemType === 'object') {
//console.log(`Buying: ${purchase.item.name} [x${purchase.quantity}] for ${Beautify(purchase.item.getSumPrice(purchase.quantity))}.`);
purchase.item.buy(purchase.quantity);
} else {
Log(
`Buying: ${purchase.item.name} for ${Beautify(
purchase.item.getPrice()
)}.`
);
if (!ShouldSkipPrompt(purchase.item)) {
purchase.item.buy();
}
}
}
}
}
function ShouldSkipPrompt(item) {
if (item.id && item.id === 69) {
Game.UpgradesById[69].buy(1);
Game.ClosePrompt();
return true;
}
}
function ClickShimmers() {
for (var h in Game.shimmers) {
if (
Game.shimmers[h].type === 'golden' ||
Game.shimmers[h].type === 'reindeer'
) {
Game.shimmers[h].pop();
}
}
}
function CookiesPerSecond() {
var cps = Game.cookiesPs * (1 - Game.cpsSucked);
if (newStore.get('AUTOCLICKER_ENABLED')) {
cps = cps + AVG_CLICKS_PER_SECOND * Game.computedMouseCps;
}
return cps;
}
function DoesPriceExceedLucky(price) {
if (!newStore.get('CHECK_LUCKY_THRESHOLD')) return 0;
var lucky = CM.Cache.Lucky;
var frenzy = lucky * 7;
var amount = Game.cookies - price;
if (amount < lucky) {
// Return time (minutes) to meet requirement.
return (lucky - amount) / CookiesPerSecond();
}
return 0;
}
function DoesPriceExceedFrenzy(price) {
if (!newStore.get('CHECK_FRENZY_THRESHOLD')) return 0;
var lucky = CM.Cache.Lucky;
var frenzy = lucky * 7;
var amount = Game.cookies - price;
if (amount < frenzy) {
// Return time (minutes) to meet requirement.
return (frenzy - amount) / CookiesPerSecond();
}
return 0;
}
// Get the next purchase item.
function GetNextPurchase() {
var whitelist = GetWhitelistUpgrades();
var items = GetValidUpgrades();
var objects = GetValidObjects();
// Combine
whitelist.push(...items);
whitelist.push(...objects);
for (var i in whitelist) {
var item = whitelist[i];
// Whitelist
if (item.itemType === 'whitelistUpgrade') {
if (typeof item.waiting == 'function' && item.waiting()) {
//console.log(`Waiting for ${item.item.name}, waiting = ${item.waiting()}`)
return item;
}
//if (typeof item.ratioMet == 'function' && item.ratioMet()) return item;
if (item.ratioMet) {
//console.log(`ratio met for ${item.item.name}`)
return item;
}
}
//console.log(`Checking item: ${item.item.name} [x${item.quantity}].`);
// Check if time to frenzy exists and is excessive.
if (item.timeToFrenzy) {
if (
newStore.get('SAVE_FOR_UPGRADE_ENABLED') &&
item.itemType === 'upgrade' &&
IsTimeWithinSaveMax(item.timeToFrenzy)
) {
// Waiting
item.waiting = item.timeToFrenzy;
return item;
} else {
// Next item
continue;
}
}
// Check if time to frenzy exists and is excessive.
if (item.timeToLucky) {
if (
newStore.get('SAVE_FOR_UPGRADE_ENABLED') &&
item.itemType === 'upgrade' &&
IsTimeWithinSaveMax(item.timeToLucky)
) {
// Waiting
item.waiting = item.timeToLucky;
return item;
} else {
// Next item
continue;
}
}
//console.log(`Can purchase value: ${item.canPurchase} [x${item.quantity}].`);
// Check if purchaseable, if not, check time to purchase.
if (item.canPurchase) {
//console.log(`Can purchase item: ${item.item.name} quantity [${item.quantity}].`);
return item;
} else {
if (
newStore.get('SAVE_FOR_UPGRADE_ENABLED') &&
item.itemType === 'upgrade' &&
IsTimeWithinSaveMax(item.timeToPurchase)
) {
// Waiting
item.waiting = item.timeToPurchase;
return item;
} else {
// Next item
continue;
}
}
}
return false;
}
function IsTimeWithinSaveMax(duration) {
var mins = Math.floor(duration / 60);
return mins <= newStore.get('SAVE_FOR_UPGRADE_MAX_MINS');
}
function ClearLog() {
console.clear();
Log('Log cleared');
}
function Log(message, color) {
if (!color) {
console.log(message);
} else {
console.log(`%c${message}`, `color: ${color}`);
}
}
function LogMessage(message) {
for (var i in LOGGED_MESSAGES) {
if (LOGGED_MESSAGES[i] == message) return false;
}
// New message, add
LOGGED_MESSAGES.push(message);
console.log(message);
}
function ModifyResetIncomePercent(increase) {
if (increase) {
newStore.set(
'RESET_INCOME_PERCENT',
newStore.get('RESET_INCOME_PERCENT') + 0.5
);
Game.Popup(
`Reset income percent requirement increased to ${newStore.get(
'RESET_INCOME_PERCENT'
)}%.`
);
} else {
newStore.set(
'RESET_INCOME_PERCENT',
newStore.get('RESET_INCOME_PERCENT') - 0.5
);
if (newStore.get('RESET_INCOME_PERCENT') < 0.5) {
newStore.set('SAVE_FOR_UPGRADE_MAX_MINS', 0.5);
}
Game.Popup(
`Reset income percent requirement decreased to ${newStore.get(
'RESET_INCOME_PERCENT'
)}%.`
);
}
}
function PopEldestWrinkler() {
if (!AreAllWrinklersActive()) return false;
var list = [];
for (var i in Game.wrinklers) {
if (Game.wrinklers[i].sucked > 0) {
list.push({
sucked: Game.wrinklers[i].sucked,
index: i,
});
}
}
if (list.length > 0) {
list.sort(function (a, b) {
if (a.sucked < b.sucked) {
return 1;
} else if (a.sucked > b.sucked) {
return -1;
} else {
return 0;
}
});
Log(
`Popping eldest wrinkler for ${Beautify(list[0].sucked)} cookies.`,
'purple'
);
Game.wrinklers[list[0].index].hp = 0;
}
}
function SortByPP(list) {
var compare = function (a, b) {
if (a.pp < b.pp) return -1;
if (a.pp > b.pp) return 1;
return 0;
};
return list.sort(compare);
}
function ToggleAutoBuy(value) {
newStore.set(
'AUTOBUY_ENABLED',
value !== undefined ? value : !newStore.get('AUTOBUY_ENABLED')
);
Game.Popup(
`Autobuy is ${
newStore.get('AUTOBUY_ENABLED') ? 'enabled' : 'disabled'
}.`
);
if (newStore.get('AUTOBUY_ENABLED')) {
AUTOBUYER = setInterval(BuyNextPurchase, newStore.get('AUTOBUY_DELAY'));
} else {
clearInterval(AUTOBUYER);
}
}
function ToggleAutoClicker(value) {
newStore.set(
'AUTOCLICKER_ENABLED',
value !== undefined ? value : !newStore.get('AUTOCLICKER_ENABLED')
);
Game.Popup(
`Autoclicker is ${
newStore.get('AUTOCLICKER_ENABLED') ? 'enabled' : 'disabled'
}.`
);
if (newStore.get('AUTOCLICKER_ENABLED')) {
AUTOCLICKER = setInterval(
Game.ClickCookie,
newStore.get('AUTOCLICKER_DELAY')
);
} else {
clearInterval(AUTOCLICKER);
}
}
function ToggleAutoGolden(value) {
newStore.set(
'GOLDEN_CLICKER_ENABLED',
value !== undefined ? value : !newStore.get('GOLDEN_CLICKER_ENABLED')
);
Game.Popup(
`Golden clicker is ${
newStore.get('GOLDEN_CLICKER_ENABLED') ? 'enabled' : 'disabled'
}.`
);
if (newStore.get('GOLDEN_CLICKER_ENABLED')) {
GOLDEN_CLICKER = setInterval(
ClickShimmers,
newStore.get('GOLDEN_CLICKER_DELAY')
);
} else {
clearInterval(GOLDEN_CLICKER);
}
}
function ToggleAutoSeason(value) {
newStore.set(
'SEASONAL_ENABLED',
value !== undefined ? value : !newStore.get('SEASONAL_ENABLED')
);
Game.Popup(
`Seasonal buyer is ${
newStore.get('SEASONAL_ENABLED') ? 'enabled' : 'disabled'
}.`
);
if (newStore.get('SEASONAL_ENABLED')) {
SEASONAL = setInterval(UpdateSeason, newStore.get('SEASONAL_DELAY'));
} else {
clearInterval(SEASONAL);
}
}
function ToggleCheckLuckyFrenzy(value) {
newStore.set(
'CHECK_LUCKY_THRESHOLD',
value !== undefined ? value : !newStore.get('CHECK_LUCKY_THRESHOLD')
);
newStore.set(
'CHECK_FRENZY_THRESHOLD',
value ? value : !newStore.get('CHECK_FRENZY_THRESHOLD')
);
Game.Popup(
`Lucky/frenzy checks are ${
newStore.get('CHECK_FRENZY_THRESHOLD') ? 'enabled' : 'disabled'
}.`
);
}
function ToggleEnabled(value) {
newStore.set(
'KLICKER_ENABLED',
value !== undefined ? value : !newStore.get('KLICKER_ENABLED')
);
Game.Popup(
`Kookie Klicker is ${
newStore.get('KLICKER_ENABLED') ? 'enabled' : 'disabled'
}.`
);
if (newStore.get('KLICKER_ENABLED')) {
// Reset
Finalize();
// Reinitialize
Initialize();
} else {
Finalize();
}
}
function ToggleWrinklerPop(value) {
newStore.set(
'WRINKLER_POPPER_ENABLED',
value !== undefined ? value : !newStore.get('WRINKLER_POPPER_ENABLED')
);
Game.Popup(
`Wrinkler Popping is ${
newStore.get('WRINKLER_POPPER_ENABLED') ? 'enabled' : 'disabled'
}.`
);
if (newStore.get('WRINKLER_POPPER_ENABLED')) {
WRINKLER_POPPER = setInterval(
PopEldestWrinkler,
newStore.get('WRINKLER_POPPER_DELAY')
);
} else {
clearInterval(WRINKLER_POPPER);
}
}
function ToggleSaveForUpgrade(value) {
newStore.set(
'SAVE_FOR_UPGRADE_ENABLED',
value !== undefined ? value : !newStore.get('SAVE_FOR_UPGRADE_ENABLED')
);
Game.Popup(
`Saving for upgrades is ${
newStore.get('SAVE_FOR_UPGRADE_ENABLED') ? 'enabled' : 'disabled'
}.`
);
}
// ********
// PANTHEON
// ********
function UpdatePantheon() {
// Ensure minigame is loaded.
if (!Game.Objects['Temple'].minigameLoaded) {
return;
}
var minigame = Game.Objects['Temple'].minigame;
PANTHEON.gods.forEach((pref) => {
minigame.dragGod(minigame.gods[pref.id]);
minigame.slotHovered = pref.slot;
minigame.dropGod();
Log(
`Slotting God ${minigame.gods[pref.id].name} into slot: ${pref.slot}`
);
});
clearInterval(PANTHEON_UPDATER);
}
// ******
// OBJECT
// ******
function GameObject(val) {
if (typeof val === 'string') {
return Game.Objects[val];
} else if (typeof val === 'number') {
return Game.ObjectsById[val];
} else if (typeof val === 'object') {
return val;
}
}
// function GetBestObject() {
// var objects = GetValidObjects();
// if (objects.length == 0) return false;
// // Sort
// objects = SortByPP(objects);
// // Get first (cheapest) item.
// return objects[0].object;
// }
function GetValidObjects() {
var list = [];
var quantities = [100, 10, 1];
// Loop through displayed
for (var name in CM.Cache.Objects) {
var object = GameObject(name);
var cached = CM.Cache.Objects[name];
// Check if valid
if (IsObjectValid(object)) {
for (let quantity of quantities) {
var price = object.getSumPrice(quantity);
var amount = Game.cookies - price;
var timeToPurchase = amount / CookiesPerSecond();
if (timeToPurchase < 0) timeToPurchase = timeToPurchase * -1;
list.push({
canPurchase: Game.cookies >= price,
pp: cached.pp,
timeToPurchase: timeToPurchase,
timeToLucky: DoesPriceExceedLucky(price),
timeToFrenzy: DoesPriceExceedFrenzy(price),
item: object,
itemType: 'object',
quantity: quantity,
});
}
//console.log(`Valid object: ${name}.`);
}
}
return list;
}
function IsObjectValid(object) {
object = GameObject(object);
var cached = CM.Cache.Objects[object.name];
//console.log(`Checking validity of ${upgrade}.`)
if (typeof cached === undefined) return false;
//console.log(`Is defined: ${upgrade}.`)
//console.log(`Is valid: ${upgrade}.`)
// Is 'Green' (lowest PP)
if (cached.color !== 'Green') return false;
// Is valid
return true;
}
// *******
// UPGRADE
// *******
function GameUpgrade(val) {
if (typeof val === 'string') {
return Game.Upgrades[val];
} else if (typeof val === 'number') {
return Game.UpgradesById[val];
} else if (typeof val === 'object') {
return val;
}
}
function GetValidUpgrades() {
var list = [];
// Loop through displayed upgrades
for (var name in CM.Cache.Upgrades) {
var upgrade = GameUpgrade(name);
var cached = CM.Cache.Upgrades[name];
// Check if valid
if (IsUpgradeValid(upgrade)) {
var price = upgrade.getPrice();
var amount = Game.cookies - price;
var timeToPurchase = amount / CookiesPerSecond();
if (timeToPurchase < 0) timeToPurchase = timeToPurchase * -1;
//console.log(`Item ${name} costs ${Beautify(price)}, or ${Beautify(amount)}, at ${Beautify(CookiesPerSecond())} CPS, timeToPurchase ${timeToPurchase}, formatted ${CM.Disp.FormatTime(timeToPurchase)}`)
list.push({
canPurchase: upgrade.canBuy(),
pp: cached.pp,
timeToPurchase: timeToPurchase,
timeToLucky: DoesPriceExceedLucky(price),
timeToFrenzy: DoesPriceExceedFrenzy(price),
item: upgrade,
itemType: 'upgrade',
quantity: 1,
});
//console.log(`Valid upgrade: ${name}.`);
}
}
if (list.length > 0) {
list = SortByPP(list);
}
return list;
}
function GetWhitelistUpgrades() {
var list = [];
// Loop through displayed upgrades
for (var name in CM.Cache.Upgrades) {
var upgrade = GameUpgrade(name);
var cached = CM.Cache.Upgrades[name];
// Whitelisted
for (let item of UPGRADE_WHITELIST) {
if (item.id == upgrade.id) {
var price = upgrade.getPrice();
var amount = Game.cookies - price;
var timeToPurchase = amount / CookiesPerSecond();
if (timeToPurchase < 0) timeToPurchase = timeToPurchase * -1;
var ratio = item.ratio || 0.01;
var ratioMet = price / Game.cookies <= ratio;
if (typeof item.ratioMet == 'function' && item.ratioMet()) {
ratioMet = item.ratioMet();
}
item.canPurchase = upgrade.canBuy();
item.pp = cached.pp;
item.ratioMet = ratioMet;
item.item = upgrade;
item.itemType = 'whitelistUpgrade';
item.quantity = 1;
item.timeToPurchase = timeToPurchase;
list.push(item);
// list.push({
// canPurchase: upgrade.canBuy(),
// pp: cached.pp,
// ratioMet: ratioMet,
// item: upgrade,
// itemType: 'whitelistUpgrade',
// quantity: 1,
// });
}
}
}
return list;
}
function IsUpgradeValid(upgrade) {
upgrade = GameUpgrade(upgrade);
var cached = CM.Cache.Upgrades[upgrade.name];
//console.log(`Checking validity of ${upgrade}.`)
if (typeof cached === undefined) return false;
//console.log(`Is defined: ${upgrade}.`)
for (var i in IGNORED_UPGRADES) {
var ignored = IGNORED_UPGRADES[i];
var loc = upgrade.name.indexOf(ignored);
//console.log(`Index of ${ignored} in ${upgrade}: ${loc}`);
if (loc !== -1) return false;
}
//console.log(`Is valid: ${upgrade}.`)
// Check if 'blue' (best PP).
if (cached.color !== 'Blue') return false;
// Is valid
return true;
}
/*******
SEASONAL
*******/
function NextSeason() {
var current;
if (!Game.season) return SEASON_LIST[0];
for (let season of SEASON_LIST) {
if (season.name === Game.season) {
current = season;
}
if (current && season.order > current.order) {
//Log(`Season.order > element.order for ${season.name} vs ${current.name} (${season.order} > ${current.order})`);
return season;
}
}
return false;
}
function SeasonalUnlocksRemaining(season) {
var count = 0;
if (season == 'halloween') {
for (var i in CM.Data.HalloCookies) {
if (!Game.Has(CM.Data.HalloCookies[i])) {
count++;
}
}
} else if (season == 'christmas') {
for (var i in CM.Data.ChristCookies) {
if (!Game.Has(CM.Data.ChristCookies[i])) {
count++;
}
}
} else if (season == 'valentines') {
for (var i in CM.Data.ValCookies) {
if (!Game.Has(CM.Data.ValCookies[i])) {
count++;
}
}
} else if (season == 'easter') {
for (var i in Game.eggDrops) {
if (!Game.HasUnlocked(Game.eggDrops[i])) {
count++;
}
}
for (var i in Game.rareEggDrops) {
if (!Game.HasUnlocked(Game.rareEggDrops[i])) {
count++;
}
}
}
return count;
}
function TotalSeasonalUnlocksRemaining() {
var count = 0;
for (let season of SEASON_LIST) {
count = count + SeasonalUnlocksRemaining(season.name);
}
return count;
}
function UpdateSeason() {
// Get current season
var current = Game.season;
// Check if any unlocks remain
if (TotalSeasonalUnlocksRemaining() == 0) {
if (current !== 'christmas') {
// Revert to default, if necessary
Log(`Reverting to default season: christmas`, 'green');
GameUpgrade(182).buy();
}
// Halt
Log(`Halting auto-season changer.`, 'orange');
ToggleAutoSeason(false);
return;
}
// Check if current season is done with unlocks
if (SeasonalUnlocksRemaining(current) == 0) {
// Check if next season exists
var new_season = NextSeason();
if (new_season) {
Log(`Setting new season: ${new_season.name}`, 'green');
// Buy upgrade
GameUpgrade(new_season.id).buy();
}
}
}
/*****
DRAGON
*****/
function UpdateDragon() {
// Try to upgrade
if (Game.dragonLevel < Game.dragonLevels.length - 1) {
Game.UpgradeDragon();
}
if (Game.dragonLevel >= 20) {
// radiant
if (Game.dragonAura !== 15) {
Game.dragonAura = 15;
}
} else if (Game.dragonLevel >= 10) {
// dragonflight
if (Game.dragonAura !== 10) {
Game.dragonAura = 10;
}
} else if (Game.dragonLevel >= 2) {
// Breath of Milk
if (Game.dragonAura !== 1) {
Game.dragonAura = 1;
}
}
// Check for double unlock
if (Game.dragonLevel >= 21) {
// Check for secondary dragonflight
if (Game.dragonAura2 !== 10) {
Game.dragonAura2 = 10;
}
}
// Disable
if (Game.dragonLevel >= Game.dragonLevels.length - 1) {
clearInterval(DRAGON_UPDATER);
}
}
/****
SANTA
****/
function UpdateSanta() {
if (Game.santaLevel < 14) {
//console.log(`Upgrading Santa to level ${Game.santaLevel + 1}.`);
Game.UpgradeSanta();
}
// Disable
if (Game.santaLevel >= 14) {
Log(`Destroying Santa.`, 'red');
clearInterval(SANTA_UPDATER);
}
}
// *****
// NOTES
// *****
function CloseNotes() {
Game.CloseNotes();
}
// ******
// EVENTS
// ******
document.addEventListener('keydown', function (event) {
if (!Game.promptOn) {
if (!event.shiftKey) return false;
if (event.keyCode == 66) {
// 'b'
ToggleAutoBuy();
} else if (event.keyCode == 69) {
// 'e'
ToggleEnabled();
} else if (event.keyCode == 70) {
// 'f'
ToggleCheckLuckyFrenzy();
} else if (event.keyCode == 71) {
// 'g'
ToggleAutoGolden();
} else if (event.keyCode == 77) {
// 'm'
ToggleAutoClicker();
} else if (event.keyCode == 78) {
// 'n'
ToggleAutoSeason();
} else if (event.keyCode == 80) {
// 'p'
ToggleWrinklerPop();
} else if (event.keyCode == 83) {
// 's'
ToggleSaveForUpgrade();
} else if (event.keyCode == 38) {
// 'up'
ModifyResetIncomePercent(true);
} else if (event.keyCode == 40) {
// 'down'
ModifyResetIncomePercent(false);
}
}
});
var RESET_ORIGINAL = Game.Reset;
Game.Reset = function (hard) {
// hook before call
RESET_ORIGINAL(hard);
// Finalize
Finalize();
if (newStore.get('KLICKER_ENABLED')) {
// hook after call
Initialize();
}
};
function Initialize() {
if (!store.enabled) {
alert(
'Store.js required. Please include script from: https://github.com/marcuswestin/store.js'
);
return;
}
// Generate default settings
InitializeSettings();
// Enable autobuy
ToggleAutoBuy(newStore.get('AUTOBUY_ENABLED'));
// Enable clicker
ToggleAutoClicker(newStore.get('AUTOCLICKER_ENABLED'));
// Enable golden clicker
ToggleAutoGolden(newStore.get('GOLDEN_CLICKER_ENABLED'));
// Enable Seasoner switcher
ToggleAutoSeason(newStore.get('SEASONAL_ENABLED'));
// Enable wrinkler popping
ToggleWrinklerPop(newStore.get('WRINKLER_POPPER_ENABLED'));
// Enable holiday updates
DRAGON_UPDATER = setInterval(UpdateDragon, 1000);
SANTA_UPDATER = setInterval(UpdateSanta, 1000);
// Enable notes closer
NOTES_CLOSER = setInterval(CloseNotes, 10000);
// SLOT GODS
PANTHEON_UPDATER = setInterval(UpdatePantheon, 5000);
// Auto buy disable checker
SHOULD_DISABLE_AUTOBUY_CHECKER = setInterval(ShouldDisableAutobuy, 5000);
// Reset game checker
SHOULD_RESET_GAME_CHECKER = setInterval(ShouldResetGame, 5000);
}
function InitializeSettings() {
Object.keys(DEFAULT_SETTINGS).forEach(function (key) {
// If store doesn't have key value already, add default
if (newStore.get(key) === undefined) {
newStore.set(key, DEFAULT_SETTINGS[key]);
}
});
AVG_CLICKS_PER_SECOND = 1000 / newStore.get('AUTOCLICKER_DELAY');
}
function ShouldDisableAutobuy() {
/*
Once criteria are met, temporarily disable autobuy to save for choc egg.
Criteria:
All seasonal upgrades purchased.
Prism count reaches X (250?).
Save prism counter and increment by Y (1?) for each ascension.
*/
// Check if Autobuy is enabled
if (!newStore.get('AUTOBUY_ENABLED')) return false;
// Check that seasonal upgrades aren't occuring
if (newStore.get('SEASONAL_ENABLED')) return false;
// Prism count exceeds requirement
if (
Game.Objects['Prism'].amount >=
newStore.get('TEMP_DISABLE_AUTOBUY_MIN_PRISMS') &&
!TEMP_AUTOBUY_DISABLED
) {
// Increment counter for next reset
newStore.set(
'TEMP_DISABLE_AUTOBUY_MIN_PRISMS',
newStore.get('TEMP_DISABLE_AUTOBUY_MIN_PRISMS') +
newStore.get('TEMP_DISABLE_AUTOBUY_PRISM_INCREMENT')
);
Game.Popup(`Autobuy is temporarily disabled.`);
Log(`Temporarily disabling autobuy.`, 'purple');
TEMP_AUTOBUY_DISABLED = true;
clearInterval(AUTOBUYER);
}
// If Prism count exceeds baseline value
//'TEMP_DISABLE_AUTOBUY_MIN_PRISMS': 250,
//'TEMP_DISABLE_AUTOBUY_PRISM_INCREMENT': 1,
}
function ShouldResetGame() {
if (RESETTING_GAME) return;
/*
Criteria: Reset Bonus Income >= X% (10%)
Criteria: No active Frenzy or other bonus mode.
Temporarily disable autobuy.
Pop all Wrinklers.
Replace Dragonflight with Earth Shatterer.
Sell all buildings.
Purchase Chocolate Egg.
Click Legacy button to ascend.
FInalize ascension and click respawn.
Remove temporary hold on autobuy, if necessary.
*/
// Minimum time elapsed
var date = new Date();
date.setTime(Date.now() - Game.startDate);
var timeInSeconds = date.getTime() / 1000;
// Minimum of an hour
if (timeInSeconds < 60 * 60) return false;
var increase = Math.round(
(CM.Sim.ResetBonus(
Math.floor(
Game.HowMuchPrestige(
Game.cookiesEarned +
Game.cookiesReset +
CM.Cache.WrinkBank +
(Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')
? CM.Cache.lastChoEgg
: 0)
)
)
) /
Game.cookiesPs) *
10000
);
if (isFinite(increase) && increase != 0) {
increase = increase / 100;
} else {
return false;
}
// Check if income reset meets requirement
if (increase < newStore.get('RESET_INCOME_PERCENT')) return false;
// Check if active buff
var buffCount = 0;
for (var i in Game.buffs) {
if (Game.buffs[i]) {
// If buff active, don't trigger
return false;
}
}
// Disable autobuy if necessary
if (!TEMP_AUTOBUY_DISABLED) {
TEMP_AUTOBUY_DISABLED = true;
clearInterval(AUTOBUYER);
}
// Pop all wrinklers
CM.Disp.CollectWrinklers();
// Set Dragonflight to Earth Shatterer
if (Game.dragonLevel >= 21 && Game.dragonAura2 === 10) {
Game.dragonAura2 = 5; // Earth Shatterer
}
// Sell all buildings
for (var name in CM.Cache.Objects) {
var object = GameObject(name);
// Sell all
if (object) object.sell(object.amount);
}
// Buy chocolate egg
var egg = GameUpgrade('Chocolate egg');
if (egg) egg.buy();
RESETTING_GAME = true;
ClearLog();
Log(`--------------------------------------------`, 'green');
Log(`Resetting game at ${increase}% bonus income.`, 'green');
Log(`--------------------------------------------`, 'green');
var ascension = setTimeout(Ascend, newStore.get('ASCENSION_DELAY'));
}
function Ascend() {
// Ascend (bypass popup)
Game.Ascend(true);
var reincarnation = setTimeout(
Reincarnate,
newStore.get('REINCARNATION_DELAY')
);
}
function Reincarnate() {
// Reincarnate (bypass popup)
Game.Reincarnate(true);
Log(`Game reset.`, 'red');
// Lift temporary autobuy disable
TEMP_AUTOBUY_DISABLED = false;
//ToggleAutoBuy(newStore.get('AUTOBUY_ENABLED'));
RESETTING_GAME = false;
}
function Finalize() {
// Enable autobuy
clearInterval(AUTOBUYER);
// Enable wrinkler popping
clearInterval(WRINKLER_POPPER);
// Enable holiday updates
clearInterval(DRAGON_UPDATER);
clearInterval(SANTA_UPDATER);
// Disable note closer
clearInterval(NOTES_CLOSER);
// Disable Seasoner switcher
clearInterval(SEASONAL);
clearInterval(AUTOCLICKER);
clearInterval(GOLDEN_CLICKER);
// Auto buy disable checker
clearInterval(SHOULD_DISABLE_AUTOBUY_CHECKER);
// Reset game checker
clearInterval(SHOULD_RESET_GAME_CHECKER);
}
// ********
// DEFAULTS
// ********
Initialize();
}, 2000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment