Skip to content

Instantly share code, notes, and snippets.

@tarcisioe
Created August 23, 2021 22:10
Show Gist options
  • Save tarcisioe/fae127be4ed0b32804b235b013a64ccd to your computer and use it in GitHub Desktop.
Save tarcisioe/fae127be4ed0b32804b235b013a64ccd to your computer and use it in GitHub Desktop.
Cookie Clicker automator (needs Cookie Monster)
// ==UserScript==
// @name New script - dashnet.org
// @namespace Violentmonkey Scripts
// @match https://orteil.dashnet.org/cookieclicker/
// @grant none
// @version 1.0
// @author -
// @description 7/22/2020, 7:35:39 PM
// ==/UserScript==
// ==UserScript==
// @name Cookie Monster
// @namespace Cookie
// @include http://orteil.dashnet.org/cookieclicker/
// @include https://orteil.dashnet.org/cookieclicker/
// @version 1
// @grant none
// ==/UserScript==
(() => {
function castSpell(grimoire) {
if (grimoire.magic >= grimoire.magicM) {
// if (Game.elderWrath > 0 && Game.wrinklers.filter(w => w.close === 1).length < Game.getWrinklersMax()) {
// grimoire.castSpell(grimoire.spells["resurrect abomination"]);
// } else {
grimoire.castSpell(grimoire.spells["hand of fate"]);
// }
}
}
function maybeBuyUpgrade() {
const upgrades = Object.entries(CM.Cache.Upgrades)
.filter(([key, item]) => item.color === 'Blue')
.map(([key, _]) => Game.Upgrades[key])
.filter(
item =>
item.pool !== 'tech' &&
item.pool !== 'toggle' &&
!item.isVaulted()
);
if (upgrades.length == 0) {
return false;
}
const upgrade = upgrades.find(
u => Game.cookies - u.getPrice() >= CM.Cache.LuckyFrenzy
);
if (upgrade) {
upgrade.buy();
}
return true;
}
function maybeBuy(pool, color, amount) {
const item = Object.entries(pool).find(([_, o]) => o.color === color);
if (!item) {
return false;
}
const [itemName, _] = item;
const product = Game.Objects[itemName];
if (Game.cookies - product.getSumPrice(amount) >= CM.Cache.LuckyFrenzy) {
product.buy(amount);
}
return true;
}
function autoBuy() {
if (!window.CM || !CM.Cache.Upgrades || !CM.Cache.Objects) {
return;
}
if (Object.keys(Game.buffs).find(b => b !== "Frenzy")) {
return;
}
maybeBuyUpgrade()
|| maybeBuy(CM.Cache.Objects100, 'Blue', 100)
|| maybeBuy(CM.Cache.Objects10, 'Blue', 10)
|| maybeBuy(CM.Cache.Objects, 'Green', 1);
}
async function waitCondition(cond) {
return new Promise(resolve => {
const checkInterval = setInterval(() => {
if (cond()) {
clearInterval(checkInterval);
resolve();
}
}, 100);
});
}
async function sleep(time) {
return new Promise(resolve => { setTimeout(resolve, time) });
}
async function popWrathThenReindeer() {
if (Game.shimmers.length == 2) {
const wrath = Game.shimmers.filter(c => c.type == "golden");
const reindeer = Game.shimmers.filter(c => c.type == "reindeer");
if (wrath.length >= 1) {
wrath.forEach(c => c.pop());
}
await sleep(100);
if (reindeer.length >= 1) {
reindeer.forEach(c => c.pop());
}
} else if (Game.shimmers.length > 2) {
Game.shimmers.forEach(c => c.pop());
}
}
function popOldestWrinkler() {
if (Game.elderWrath == 0) {
return;
}
const active = Game.wrinklers.filter(w => w.close === 1);
const max_wrinklers = Game.getWrinklersMax()
if (active.length < max_wrinklers) {
return;
}
const oldest = active.reduce((a, b) => a.sucked > b.sucked ? a : b);
oldest.hp = 0; // pop the wrinkler
}
function popAllWrinklers() {
if (Game.elderWrath == 0) {
return;
}
const active = Game.wrinklers.filter(w => w.close === 1);
active.forEach(w => w.hp = 0);
}
function dropHunt() {
const targetDrops =
(Game.season === 'halloween') ? Game.halloweenDrops :
(Game.season === 'easter') ? Game.easterEggs :
[];
if (targetDrops.some(c => !Game.Upgrades[c].unlocked)) {
Game.wrinklers.filter(w => w.close === 1).forEach(w => w.hp = 0);
}
}
function tryGetFortune() {
if (Game.TickerEffect && Game.TickerEffect.type === "fortune") {
Game.tickerL.click();
}
}
async function main() {
await waitCondition(() => Game.ready);
const wizardTower = Game.Objects["Wizard tower"];
await waitCondition(() => wizardTower.minigameLoaded);
const loop = Game.Loop;
Game.Loop = (...args) => {
loop(...args);
autoBuy();
dropHunt();
Game.shimmers.forEach(s => s.pop());
Game.ClickCookie();
castSpell(wizardTower.minigame);
tryGetFortune();
};
Game.LoadMod('https://aktanusa.github.io/CookieMonster/CookieMonster.js');
};
main();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment