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-20 05:10:06 +00:00
|
|
|
// @version 0.14.1
|
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
|
|
|
|
// @grant GM_addStyle
|
2018-02-11 22:43:56 +00:00
|
|
|
// ==/UserScript==
|
|
|
|
|
2018-04-14 10:58:33 +00:00
|
|
|
var blockingUpgrades = [
|
2018-04-14 11:18:00 +00:00
|
|
|
69, // Destructive upgrade: "One mind"
|
2018-04-14 15:29:21 +00:00
|
|
|
85, // Revoke elders covenant
|
2018-04-18 21:59:25 +00:00
|
|
|
331, // Golden switch
|
2018-04-14 10:58:33 +00:00
|
|
|
333, // Milk selector
|
2018-04-18 21:59:25 +00:00
|
|
|
414, // Background selector
|
2018-04-14 10:58:33 +00:00
|
|
|
];
|
2018-04-11 20:41:32 +00:00
|
|
|
var purchaseSteps = 50;
|
|
|
|
|
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-14 13:37:55 +00:00
|
|
|
// Click all golden cookies
|
|
|
|
$('.shimmer').click();
|
|
|
|
|
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-14 10:56:05 +00:00
|
|
|
let availableUpgrades = $('.upgrade.enabled').filter(upgradeFilter);
|
2018-02-11 23:07:39 +00:00
|
|
|
if (availableUpgrades.length > 0) {
|
|
|
|
debug(availableUpgrades.length + " upgrades available, buying now...");
|
|
|
|
availableUpgrades.click();
|
2018-04-14 16:09:58 +00:00
|
|
|
note('Purchased ' + availableUpgrades.length + ' upgrades for you.');
|
2018-02-11 23:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the top enabled purchase to be made
|
2018-04-14 19:12:59 +00:00
|
|
|
let availableProducts = $('.product.unlocked.enabled').filter(productFilter);
|
2018-04-14 20:48:13 +00:00
|
|
|
if (availableProducts.length > 0 && Game.buyMode == 1) { // buyMode 1 = buy, -1 = sell
|
2018-04-14 19:14:33 +00:00
|
|
|
let product = $(availableProducts[availableProducts.length - 1]);
|
2018-04-14 19:12:59 +00:00
|
|
|
|
|
|
|
debug("Auto-Buying: " + product.find('.title:first').text());
|
2018-04-14 19:17:23 +00:00
|
|
|
product.click();
|
2018-04-14 19:12:59 +00:00
|
|
|
note('Purchased ' + product.find('.title:first').text() + ' for you.');
|
2018-02-11 23:07:39 +00:00
|
|
|
}
|
2018-04-20 04:56:02 +00:00
|
|
|
|
|
|
|
// Upgrade dragon if possible
|
2018-04-20 05:10:06 +00:00
|
|
|
if (Game.dragonLevels[Game.dragonLevel].cost()) {
|
2018-04-20 04:56:02 +00:00
|
|
|
Game.UpgradeDragon()
|
|
|
|
}
|
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-02-12 19:27:32 +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-02-12 19:22:54 +00:00
|
|
|
if (window.autoClicker != undefined) {
|
|
|
|
window.clearInterval(window.autoClicker);
|
|
|
|
window.autoClicker = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-11 22:43:56 +00:00
|
|
|
function debug(msg) {
|
2018-02-11 23:07:39 +00:00
|
|
|
console.log("[AutoCookieClicker] " + msg);
|
2018-02-11 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2018-04-11 20:23:26 +00:00
|
|
|
function getMaxBuy() {
|
2018-04-14 16:51:51 +00:00
|
|
|
let topPurchaseCount = Game.ObjectsById[Game.ObjectsN - 1].amount;
|
2018-04-11 20:23:26 +00:00
|
|
|
|
2018-04-11 20:41:32 +00:00
|
|
|
return Math.max(Math.ceil((topPurchaseCount + 1) / purchaseSteps), 1) * purchaseSteps;
|
2018-04-11 20:23:26 +00:00
|
|
|
}
|
|
|
|
|
2018-04-15 19:19:28 +00:00
|
|
|
function hasActiveClickBuff() {
|
|
|
|
var hasBuff = false;
|
|
|
|
for (key in Game.buffs) {
|
|
|
|
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-15 19:19:28 +00:00
|
|
|
window.controlAutoClicker = window.setInterval(controlAutoClicker, 1000);
|
2018-04-14 16:26:46 +00:00
|
|
|
|
|
|
|
// Enable automatic purchasing of upgrades / elements
|
|
|
|
window.autoPurchase = window.setInterval(executeAutoActions, 500);
|
|
|
|
}
|
|
|
|
|
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-14 16:38:57 +00:00
|
|
|
Game.Notify("Auto-CookieClicker", msg, [12, 0], quick, true);
|
2018-04-14 16:09:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-14 19:12:59 +00:00
|
|
|
function productFilter(idx) {
|
|
|
|
let owned = Game.ObjectsById[parseInt($(this).attr('id').replace(/^product/, ''))].amount;
|
|
|
|
return owned < getMaxBuy();
|
|
|
|
}
|
|
|
|
|
2018-04-14 16:09:58 +00:00
|
|
|
function upgradeFilter(idx) {
|
|
|
|
var onClickHandler = $(this).attr('onclick');
|
|
|
|
if (onClickHandler == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var upgradeID = parseInt(onClickHandler.replace(/^.*\[([0-9]+)\].*$/, "$1"));
|
|
|
|
return !blockingUpgrades.includes(upgradeID);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
})();
|