2018-02-11 22:43:56 +00:00
|
|
|
// ==UserScript==
|
2018-02-11 23:07:39 +00:00
|
|
|
// @name Automate CookieClicker
|
|
|
|
// @namespace https://luzifer.io/
|
2018-04-25 10:59:08 +00:00
|
|
|
// @version 0.21.0
|
2018-02-11 23:07:39 +00:00
|
|
|
// @description Automate everything!
|
|
|
|
// @author Knut Ahlers <knut@ahlers.me>
|
2018-04-11 21:01:30 +00:00
|
|
|
// @source https://github.com/Luzifer/automate-cookie-clicker
|
2018-02-11 23:07:39 +00:00
|
|
|
// @match http://orteil.dashnet.org/cookieclicker/
|
2018-04-11 21:06:03 +00:00
|
|
|
// @updateURL https://raw.githubusercontent.com/Luzifer/automate-cookie-clicker/master/autocookieclicker.user.js
|
2018-04-15 13:43:38 +00:00
|
|
|
// @icon http://orteil.dashnet.org/cookieclicker/img/favicon.ico
|
2018-02-11 23:07:39 +00:00
|
|
|
// @grant GM_info
|
2018-02-11 22:43:56 +00:00
|
|
|
// ==/UserScript==
|
|
|
|
|
2018-04-21 11:14:31 +00:00
|
|
|
/* global Game:false, GM_info:false */
|
2018-04-20 06:18:51 +00:00
|
|
|
|
|
|
|
let blockingUpgrades = [
|
2018-04-14 11:18:00 +00:00
|
|
|
69, // Destructive upgrade: "One mind"
|
2018-04-14 10:58:33 +00:00
|
|
|
];
|
2018-04-20 06:18:51 +00:00
|
|
|
let purchaseSteps = 50;
|
2018-04-11 20:41:32 +00:00
|
|
|
|
2018-02-11 23:07:39 +00:00
|
|
|
function autoClick() {
|
2018-04-21 11:14:31 +00:00
|
|
|
Game.ClickCookie();
|
2018-02-11 23:07:39 +00:00
|
|
|
}
|
2018-02-11 22:43:56 +00:00
|
|
|
|
2018-04-14 11:21:29 +00:00
|
|
|
function executeAutoActions() {
|
2018-04-20 06:18:51 +00:00
|
|
|
if (Game.T % (Game.fps * 0.5) !== 0) {
|
2018-04-20 05:43:43 +00:00
|
|
|
// Game logic ticks very fast, only trigger every 0.5s
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-14 13:37:55 +00:00
|
|
|
// Click all golden cookies
|
2018-04-21 11:14:31 +00:00
|
|
|
Game.shimmers.forEach(obj => obj.pop());
|
2018-04-14 13:37:55 +00:00
|
|
|
|
2018-04-20 07:36:16 +00:00
|
|
|
// Get rid of wrinklers
|
|
|
|
while (Game.wrinklers.filter(obj => obj.hp > 0 && obj.phase > 0).length > 0) {
|
|
|
|
Game.PopRandomWrinkler();
|
|
|
|
}
|
|
|
|
|
2018-04-15 15:49:19 +00:00
|
|
|
// Harvest sugar lumps
|
|
|
|
if ((new Date() - Game.lumpT) > Game.lumpRipeAge) {
|
|
|
|
Game.harvestLumps(1);
|
|
|
|
}
|
|
|
|
|
2018-02-11 23:07:39 +00:00
|
|
|
// Look for upgrades being available
|
2018-04-21 12:08:04 +00:00
|
|
|
let availableUpgrades = Game.UpgradesInStore.filter(obj => obj.canBuy() && !obj.bought && !blockingUpgrades.includes(obj.id));
|
2018-04-21 10:29:58 +00:00
|
|
|
while (availableUpgrades.length > 0) {
|
|
|
|
let upgrade = availableUpgrades[0];
|
|
|
|
upgrade.buy();
|
2018-04-21 11:59:33 +00:00
|
|
|
note(`Purchased upgrade ${upgrade.name} for you.`);
|
2018-04-21 10:45:55 +00:00
|
|
|
|
2018-04-21 12:08:04 +00:00
|
|
|
availableUpgrades = Game.UpgradesInStore.filter(obj => obj.canBuy() && !obj.bought && !blockingUpgrades.includes(obj.id));
|
2018-02-11 23:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the top enabled purchase to be made
|
2018-04-25 10:59:08 +00:00
|
|
|
let availableProducts = Game.ObjectsById.filter(obj => obj.price < Game.cookies);
|
2018-04-20 06:48:31 +00:00
|
|
|
while (availableProducts.length > 0 && Game.buyMode === 1) { // buyMode 1 = buy, -1 = sell
|
|
|
|
let product = availableProducts[availableProducts.length - 1];
|
|
|
|
|
2018-04-25 10:59:08 +00:00
|
|
|
for (let buyAmount = purchaseSteps - product.amount; buyAmount > 0; buyAmount--) {
|
2018-04-20 06:48:31 +00:00
|
|
|
if (product.getSumPrice(buyAmount) <= Game.cookies) {
|
2018-04-20 07:07:48 +00:00
|
|
|
product.buy(buyAmount);
|
2018-04-21 11:59:33 +00:00
|
|
|
note(`Purchased ${buyAmount} ${buyAmount === 1 ? product.name : product.plural} for you.`);
|
2018-04-20 06:48:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-04-14 19:12:59 +00:00
|
|
|
|
2018-04-25 10:59:08 +00:00
|
|
|
availableProducts = Game.ObjectsById.filter(obj => obj.price < Game.cookies);
|
2018-02-11 23:07:39 +00:00
|
|
|
}
|
2018-02-11 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2018-04-15 19:19:28 +00:00
|
|
|
function controlAutoClicker() {
|
2018-04-14 16:05:24 +00:00
|
|
|
let cps = Game.cookiesPs;
|
2018-04-15 19:19:28 +00:00
|
|
|
if (cps < 3000 || hasActiveClickBuff()) {
|
2018-04-20 06:18:51 +00:00
|
|
|
if (window.autoClicker === undefined) {
|
2018-04-15 19:19:28 +00:00
|
|
|
window.autoClicker = window.setInterval(autoClick, 100);
|
2018-02-12 19:27:32 +00:00
|
|
|
}
|
2018-04-14 16:05:24 +00:00
|
|
|
} else {
|
2018-04-20 06:18:51 +00:00
|
|
|
if (window.autoClicker !== undefined) {
|
2018-02-12 19:22:54 +00:00
|
|
|
window.clearInterval(window.autoClicker);
|
|
|
|
window.autoClicker = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-15 19:19:28 +00:00
|
|
|
function hasActiveClickBuff() {
|
2018-04-20 06:18:51 +00:00
|
|
|
let hasBuff = false;
|
|
|
|
for (let key in Game.buffs) {
|
2018-04-15 19:19:28 +00:00
|
|
|
if (Game.buffs[key].multClick) hasBuff = true;
|
|
|
|
}
|
|
|
|
return hasBuff;
|
|
|
|
}
|
|
|
|
|
2018-04-14 16:26:46 +00:00
|
|
|
function installHelper() {
|
|
|
|
// Startup notification
|
|
|
|
let version = GM_info.script.version;
|
2018-04-21 11:59:33 +00:00
|
|
|
note(`Version ${version} loaded.`);
|
2018-04-14 16:26:46 +00:00
|
|
|
|
2018-04-21 10:17:48 +00:00
|
|
|
// Do not click toggle upgrades
|
|
|
|
blockingUpgrades = blockingUpgrades.concat(Game.UpgradesByPool['toggle'].map(obj => obj.id));
|
|
|
|
|
2018-04-20 05:38:59 +00:00
|
|
|
Game.customChecks.push(controlAutoClicker);
|
2018-04-22 00:33:44 +00:00
|
|
|
Game.customChecks.push(manageDragon);
|
|
|
|
Game.customChecks.push(manageSanta);
|
|
|
|
|
2018-04-20 05:38:59 +00:00
|
|
|
Game.customLogic.push(executeAutoActions);
|
2018-04-14 16:26:46 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 05:19:48 +00:00
|
|
|
function manageDragon() {
|
|
|
|
// Upgrade dragon if possible
|
2018-04-20 05:24:12 +00:00
|
|
|
if (Game.dragonLevels[Game.dragonLevel].cost() && Game.dragonLevel < Game.dragonLevels.length - 1) {
|
2018-04-20 06:18:51 +00:00
|
|
|
Game.UpgradeDragon();
|
2018-04-20 05:19:48 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 07:07:48 +00:00
|
|
|
// Choosing dragon aura is currently not possible :(
|
|
|
|
// This will just open a select dialogue...
|
2018-04-20 05:19:48 +00:00
|
|
|
}
|
|
|
|
|
2018-04-22 00:33:44 +00:00
|
|
|
function manageSanta() {
|
|
|
|
let moni = Math.pow(Game.santaLevel + 1, Game.santaLevel + 1);
|
|
|
|
if (Game.cookies > moni && Game.santaLevel < 14) Game.UpgradeSanta();
|
|
|
|
}
|
|
|
|
|
2018-04-14 16:21:11 +00:00
|
|
|
function note(msg, quick = true) {
|
2018-04-14 16:20:18 +00:00
|
|
|
// Icon: img/icons.png 0-based indices
|
2018-04-20 06:18:51 +00:00
|
|
|
Game.Notify('Auto-CookieClicker', msg, [12, 0], quick, true);
|
2018-04-14 16:09:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-21 11:59:33 +00:00
|
|
|
(() => window.setTimeout(installHelper, 1000))();
|