Skip to content

Commit

Permalink
followup edits
Browse files Browse the repository at this point in the history
  • Loading branch information
suddjian committed Oct 21, 2023
1 parent 5729d70 commit 5582656
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions src/cookieclickermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const store = document.getElementById("store");
const buffs = document.getElementById("buffs");
const bankContent = document.getElementById("bankContent");
const grimoireSpells = document.getElementById("grimoireSpells");
const actualRunModHook = Game.runModHook.bind(Game);

var clicksps = 100;
var intervals = {};
Expand Down Expand Up @@ -37,6 +38,8 @@ function harvestLumpIfRipe() {
}
}

/*:・゚✧*:・゚✧ ----- SHOPPING ----- *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ */

function shopGreedily() {
if (
store.querySelector("#storeBulkBuy.selected") == null
Expand All @@ -53,8 +56,6 @@ function shopGreedily() {
}
}

/*:・゚✧*:・゚✧ ----- SHOPPING ----- *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ */

function getShopItemsSortedByProfitability() {
var products = Object.values(Game.Objects)
.filter(o => !o.locked)
Expand Down Expand Up @@ -133,7 +134,7 @@ function getUpgradeCps(upgrade) {
/*:・゚✧*:・゚✧ ----- STOCK MARKET ----- *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ */

function adjustStockPortfolio() {
if (!bankContent.checkVisibility()) {
if (bankContent == null || !bankContent.checkVisibility()) {
return;
}
var analysis = analyzeStockMarket();
Expand Down Expand Up @@ -199,7 +200,8 @@ function getStockTradeStr(good, amount) {

function handOfFateToBoostBuffs() {
if (
grimoireSpells.checkVisibility()
grimoireSpells != null
&& grimoireSpells.checkVisibility()
&& buffs.children.length >= 2
&& Grimoire.getSpellCost(Grimoire.spells["hand of fate"]) <= Grimoire.magic
) {
Expand Down Expand Up @@ -227,21 +229,43 @@ function lastOf(arr) {
return arr[arr.length - 1];
}

/*:・゚✧*:・゚✧ ----- FOLLOWUP SYSTEM ----- *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ */

var followupfns = [];
var requiredhooks = ["logic", "draw"];
var hithooks = [];

function followup(fn) {
var followupidx = timers.length;
var timer = setTimeout(() => {
timers.splice(followupidx, 1);
fn();
}, 1);
timers.push(timer);
return timer;
followupfns.push(fn);
}

function tickFollowups() {
followupfns.forEach((fn, i) => {
var index = timers.length;
var timer = setTimeout(() => {
timers.splice(index, 1);
fn();
}, i * 100);
timers.push(timer);
});
followupfns = [];
}

function hijackedRunModHook(hook, ...args) {
actualRunModHook(hook, ...args);
hithooks.push(hook);
if (!requiredhooks.some(req => !hithooks.includes(req))) {
tickFollowups();
hithooks = [];
}
}

/*:・゚✧*:・゚✧ ----- SCRIPT LIFECYCLE ----- *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ */

function cleanup() {
Object.values(window.cookieclickerhacks.intervals).forEach(clearInterval);
timers.forEach(clearTimeout);
Game.runModHook = actualRunModHook;
}

function init() {
Expand All @@ -257,6 +281,9 @@ function init() {
intervals.shimmer = setInterval(clickShimmer, 1999);
intervals.lump = setInterval(harvestLumpIfRipe, 2999);
intervals.stockmarket = setInterval(adjustStockPortfolio, 4999);

Game.runModHook = hijackedRunModHook;

if (isRestart) {
console.log("cookie clicker manager restarted");
} else {
Expand Down

0 comments on commit 5582656

Please sign in to comment.