Skip to content

Commit

Permalink
combos
Browse files Browse the repository at this point in the history
  • Loading branch information
suddjian committed Oct 31, 2023
1 parent 5f77674 commit 25e09b2
Showing 1 changed file with 109 additions and 54 deletions.
163 changes: 109 additions & 54 deletions src/cookieclickermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const store = document.getElementById("store");
var clicksps = 100;
var intervals = {};
var timers = [];
var lastBoostedAt = 0;

/*:・゚✧*:・゚✧ ----- UI ACTIONS ----- *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ */

Expand Down Expand Up @@ -65,7 +64,7 @@ function getShopItemsSortedByProfitability() {
name: product.name,
product,
l: product.l,
profitability: getProductCps(product) * Game.buyBulk / product.bulkPrice
profitability: getProductNetCps(product) * Game.buyBulk / product.bulkPrice
}));
var upgrades = Game.UpgradesInStore
.map((upgrade) => ({
Expand All @@ -88,34 +87,42 @@ function getShopItemsSortedByProfitability() {

/*:・゚✧*:・゚✧ ----- CPS CALCULATIONS ----- *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ */

function getProductCps(product) {
return (product.amount ? product.storedTotalCps / product.amount : product.storedCps) * Game.globalCpsMult;
function getBoostMult() {
return Game.cookiesPs / Game.cookiesPsRaw;
}

function getProductNetCps(product) {
return product.storedTotalCps * Game.globalCpsMult;
}

function getClickCps() {
return !intervals.click ? 0 : Game.computedMouseCps * clicksps;
}

function getHeavenlyMultiplier() {
return parseFloat(Game.prestige)*Game.heavenlyPower*Game.GetHeavenlyMultiplier();
}

function getUpgradeCps(upgrade) {
if (/grandmas$/i.test(upgrade.name)) {
var [buildingclause, clausegrandmas] = /\. .+ gain .+ per (\d+) grandma/.exec(upgrade.desc.toLowerCase()) || ["", "1"];
clausegrandmas = parseInt(clausegrandmas);
var building = Object.values(Game.Objects)
.find((b) => buildingclause.includes(b.plural));
var buildingbonus = !building ? 0 : getProductCps(building) * extractPercent(buildingclause) * (Game.Objects.Grandma.amount / clausegrandmas);
return getProductCps(Game.Objects.Grandma) + buildingbonus;
var buildingbonus = !building ? 0 : getProductNetCps(building) * extractPercent(buildingclause) * (Game.Objects.Grandma.amount / clausegrandmas);
return getProductNetCps(Game.Objects.Grandma) + buildingbonus;
}
if (/ mouse$/i.test(upgrade.name)) {
return extractPercent(upgrade.desc) * getClickCps();
}
if (/The mouse and cursors are /i.test(upgrade.desc)) {
// twice as efficient
return getProductCps(Game.Objects.Cursor) + getClickCps();
return getProductNetCps(Game.Objects.Cursor) + getClickCps();
}
if (/ fingers$/i.test(upgrade.name)) {
// plus X cookies for each non-cursor building
var buildings = Game.BuildingsOwned - Game.Objects.Cursor.amount;
return extractNum(upgrade.desc) * buildings * (Game.Objects.Cursor.amount + clicksps);
return extractNum(upgrade.desc) * buildings * (Game.Objects.Cursor.amount + clicksps) * Game.globalCpsMult;
}
if (upgrade.pool === "cookie") {
return extractPercent(upgrade.desc) * Game.cookiesPs;
Expand All @@ -130,11 +137,22 @@ function getUpgradeCps(upgrade) {
return Game.cookiesPs * extractPercent(upgrade.desc);
}
if (/potential of your prestige level/i.test(upgrade.desc)) {
var heavenlyMultiplier = parseFloat(Game.prestige)*Game.heavenlyPower*Game.GetHeavenlyMultiplier()*0.01;
return Game.cookiesPs * heavenlyMultiplier;
return Game.cookiesPs * getHeavenlyMultiplier();
}
if (/^synergy\d+/i.test(upgrade.tier) && upgrade.buildingTie1 && upgrade.buildingTie2) {
var building1 = upgrade.buildingTie1;
var building2 = upgrade.buildingTie2;
var bldg1reg = new RegExp(`${building1.plural} gain (.+) CpS per ${building2.single}`, "i");
var bldg2reg = new RegExp(`${building2.plural} gain (.+) CpS per ${building1.single}`, "i");
var percent1 = extractPercent(bldg1reg.exec(upgrade.desc)[1]);
var percent2 = extractPercent(bldg2reg.exec(upgrade.desc)[1]);
return (
getProductNetCps(building1) * percent1 * building2.amount
+ getProductNetCps(building2) * percent2 * building1.amount
);
}
if (upgrade.buildingTie) {
return getProductCps(upgrade.buildingTie) * upgrade.buildingTie.amount;
return getProductNetCps(upgrade.buildingTie);
}
return 0;
}
Expand Down Expand Up @@ -249,60 +267,94 @@ function getStockTradeStr(good, amount) {

/*:・゚✧*:・゚✧ ----- COMBOS ----- *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ */

var currentcombo = null;
var combonum = 0;

function combolog(str) {
console.log(`%c[Combo ${combonum}] ${str}`, "color:slateblue");
}

var maxbuffpreamble = 24 + Object.keys(Game.buffTypesByName).reduce((max, str) => Math.max(max, str.length), 0);

function combologWithCpS(preamble) {
if (preamble.length > maxbuffpreamble) {
maxbuffpreamble = preamble.length;
}
var cpsstr = ` ${Beautify(Game.cookiesPs)} CpS, ${Beautify(Game.cookies)} 🍪, ${Beautify(getBoostMult(), 3)}x boost`;
combolog(preamble + cpsstr.padStart(maxbuffpreamble - preamble.length));
}

function boostBuffs() {
var [nerfs, buffs] = partition(
Object.values(Game.buffs),
buff => buff.name === "Clot" || buff.multCpS < 1
);
if (nerfs.length) return;
var [nerfs, buffs] = partition(Object.values(Game.buffs), buff => (buff.multCpS != null && buff.multCpS < 1));
var cpsbuffs = buffs.filter(buff => buff.multCpS > 1 || buff.multClick > 1);

// is there anything to boost?
if (nerfs.length > 0 || cpsbuffs.length === 0) {
if (currentcombo) {
combologWithCpS("Combo ended.");
console.log({ nerfs, buffs });
currentcombo = null;
}
return;
}

// should we start a combo?
if (cpsbuffs.length >= 2 && currentcombo == null) {
combonum++;
currentcombo = {
hof: 0,
loan1: 0,
loan2: 0,
stretch: 0,
buffnames: new Set(),
};
combologWithCpS("Combo starting.");
}

if (!currentcombo) return;

// updating the combo stats
var endedbuffs = currentcombo.buffnames.values().filter(name => !buffs.some(buff => buff.name === name));
endedbuffs.forEach(name => currentcombo.buffnames.delete(name));
if (endedbuffs.length) {
combologWithCpS(`${endedbuffs.join(", ")} ended.`);
}

var newbuffs = cpsbuffs.filter(b => !currentcombo.buffnames.has(b.name));
newbuffs.forEach(buff => currentcombo.buffnames.add(buff.name));
if (newbuffs.length) {
var names = newbuffs.map(b => b.name).join(", ");
combologWithCpS(`${names} started.`);
console.log(...newbuffs);
}

// applying combo buffs
var grimoireSpells = findGameElement("grimoireSpells");
var handOfFate = Grimoire.spells["hand of fate"];
var stretchTime = Grimoire.spells["stretch time"];
var bankLoan1 = findGameElement("bankLoan1");
var bankLoan2 = findGameElement("bankLoan2");
var boosted = false;

if (
buffs.length >= 2
&& grimoireSpells
&& Grimoire.getSpellCost(handOfFate) <= Grimoire.magic
) {
console.log("%cCookie manager forcing the hand of fate to boost buffs", "color:slateblue");
boosted = true;

if (cpsbuffs.length >= 2 && grimoireSpells && Grimoire.getSpellCost(handOfFate) <= Grimoire.magic && !currentcombo.hof) {
combolog("forcing the hand of fate");
currentcombo.hof++;
clickOn(grimoireSpells.children[handOfFate.id]);
}
if (buffs.length >= 3 && bankLoan1 && !bankLoan1.classList.contains("bankButtonOff")) {
console.log("%cCookie manager taking out first loan to boost buffs", "color:slateblue");
boosted = true;
if (cpsbuffs.length >= 3 && grimoireSpells && Grimoire.getSpellCost(stretchTime) <= Grimoire.magic && !currentcombo.stretch) {
combolog("stretching time");
currentcombo.stretch++;
clickOn(grimoireSpells.children[stretchTime.id]);
}
if (cpsbuffs.length >= 3 && bankLoan1 && !bankLoan1.classList.contains("bankButtonOff") && !currentcombo.loan1) {
combolog("taking out first loan");
currentcombo.loan1++;
clickOn(bankLoan1);
}
if (buffs.length >= 4 && bankLoan2 && !bankLoan2.classList.contains("bankButtonOff")) {
console.log("%cCookie manager taking out second loan to boost buffs", "color:slateblue");
boosted = true;
if (cpsbuffs.length >= 4 && bankLoan2 && !bankLoan2.classList.contains("bankButtonOff") && !currentcombo.loan2) {
combolog("taking out second loan");
currentcombo.loan2++;
clickOn(bankLoan2);
}
if (buffs.length >= 3 && grimoireSpells && Grimoire.getSpellCost(stretchTime) <= Grimoire.magic) {
console.log("%cCookie manager stretching time to boost buffs", "color:slateblue");
boosted = true;
clickOn(grimoireSpells.children[stretchTime.id]);
}
if (boosted) {
var hasntBoostedInAWhile = Date.now() - lastBoostedAt > 5 * 60000;
if (hasntBoostedInAWhile) {
console.log(`%cCurrent CpS: ${Game.cookiesPs}; ${Beautify(Game.cookies)} cookies`, "color:slateblue");
setTimeout(() => {
console.log(`%cCpS 5s after boost: ${Game.cookiesPs}; ${Beautify(Game.cookies)} cookies`, "color:slateblue");
}, 5000);
setTimeout(() => {
console.log(`%cCpS 10s after boost: ${Game.cookiesPs}; ${Beautify(Game.cookies)} cookies`, "color:slateblue");
}, 10000);
setTimeout(() => {
console.log(`%cCpS 1m after boost: ${Game.cookiesPs}; ${Beautify(Game.cookies)} cookies`, "color:slateblue");
}, 60000);
}
lastBoostedAt = Date.now();
}
}

/*:・゚✧*:・゚✧ ----- UTILITIES ----- *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ *:・゚✧*:・゚✧ */
Expand Down Expand Up @@ -352,8 +404,8 @@ function init() {

intervals.click = setInterval(clickBigCookie, 1000 / clicksps);
/* primes bcuz */
intervals.boost = setInterval(boostBuffs, 499);
intervals.buy = setInterval(shopGreedily, 997);
intervals.boost = setInterval(boostBuffs, 1117);
intervals.shimmer = setInterval(clickShimmer, 1999);
intervals.lump = setInterval(harvestLumpIfRipe, 2999);
intervals.stockmarket = setInterval(adjustStockPortfolio, 49999);
Expand All @@ -378,14 +430,17 @@ window.cookieclickerhacks = {
extractNum,
extractPercent,
getShopItemsSortedByProfitability,
getBoostMult,
getClickCps,
getProductCps,
getProductNetCps,
getUpgradeCps,
getStockTradeStr,
adjustStockPortfolio,
analyzeStockMarketV1,
analyzeStockMarketV2,
boostBuffs,
findGameElement,
partition,
intervals,
timers,
cleanup,
Expand Down

0 comments on commit 25e09b2

Please sign in to comment.