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-21 10:29:58 +00:00
|
|
|
// @version 0.18.3
|
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/
|
|
|
|
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js
|
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-20 06:18:51 +00:00
|
|
|
/* global Game:galse, GM_info:false, $:false */
|
|
|
|
|
|
|
|
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() {
|
|
|
|
$('#bigCookie').click();
|
|
|
|
}
|
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
|
|
|
|
$('.shimmer').click();
|
|
|
|
|
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 10:29:58 +00:00
|
|
|
let availableUpgrades = Game.UpgradesInStore.filter(obj => obj.canBuy() && !blockingUpgrades.includes(obj.id));
|
|
|
|
while (availableUpgrades.length > 0) {
|
|
|
|
let upgrade = availableUpgrades[0];
|
|
|
|
upgrade.buy();
|
|
|
|
note('Purchased upgrade ' + upgrade.name + ' for you.');
|
2018-02-11 23:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the top enabled purchase to be made
|
2018-04-20 06:51:57 +00:00
|
|
|
let availableProducts = Game.ObjectsById.filter(obj => obj.price < Game.cookies && obj.amount < getMaxBuy());
|
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-20 07:07:48 +00:00
|
|
|
for (let buyAmount = getMaxBuy() - 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-20 07:13:18 +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-20 06:51:57 +00:00
|
|
|
availableProducts = Game.ObjectsById.filter(obj => obj.price < Game.cookies && obj.amount < getMaxBuy());
|
2018-02-11 23:07:39 +00:00
|
|
|
}
|
2018-04-20 04:56:02 +00:00
|
|
|
|
2018-04-20 05:19:48 +00:00
|
|
|
manageDragon();
|
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-20 06:51:57 +00:00
|
|
|
function getMaxBuy() {
|
|
|
|
let topPurchaseCount = Game.ObjectsById[Game.ObjectsN - 1].amount;
|
|
|
|
|
|
|
|
return Math.max(Math.ceil((topPurchaseCount + 1) / purchaseSteps), 1) * purchaseSteps;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
note('Version ' + version + ' loaded.');
|
|
|
|
|
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);
|
|
|
|
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-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-02-11 22:43:56 +00:00
|
|
|
(function() {
|
2018-02-11 23:07:39 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-04-14 16:26:46 +00:00
|
|
|
window.setTimeout(installHelper, 1000);
|
2018-02-11 23:07:39 +00:00
|
|
|
})();
|