From df8957338b76f160bd143b0e563ac0a0185fe188 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 7 Feb 2021 10:32:23 +0100 Subject: [PATCH] Started annotating Cache.js --- src/Cache.js | 139 ++++++++++++++++++++++----------------------------- 1 file changed, 61 insertions(+), 78 deletions(-) diff --git a/src/Cache.js b/src/Cache.js index bb5a277..e27931a 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -15,6 +15,7 @@ CM.Cache.InitCache = function() { CM.Cache.CacheDragonAuras(); CM.Cache.CacheWrinklers(); CM.Cache.CacheStats(); + CM.Cache.RemakeChain(); CM.Cache.CacheMissingUpgrades(); }; @@ -86,25 +87,22 @@ CM.Cache.CacheWrinklers = function() { * @global {string} CM.Cache.EdificeBuilding Name of most expensive building possible with Spontaneous Edifice */ CM.Cache.CacheStats = function() { - var goldenMult = CM.Cache.GoldenCookiesMult; - var wrathMult = CM.Cache.WrathCookiesMult; - CM.Cache.Lucky = (CM.Cache.NoGoldSwitchCookiesPS * 900) / 0.15; CM.Cache.Lucky *= CM.Cache.DragonsFortuneMultAdjustment; - var cpsBuffMult = CM.Sim.getCPSBuffMult(); + let cpsBuffMult = CM.Sim.getCPSBuffMult(); if (cpsBuffMult > 0) CM.Cache.Lucky /= cpsBuffMult; else CM.Cache.Lucky = 0; - CM.Cache.LuckyReward = goldenMult * (CM.Cache.Lucky * 0.15) + 13; - CM.Cache.LuckyWrathReward = wrathMult * (CM.Cache.Lucky * 0.15) + 13; + CM.Cache.LuckyReward = CM.Cache.GoldenCookiesMult * (CM.Cache.Lucky * 0.15) + 13; + CM.Cache.LuckyWrathReward = CM.Cache.WrathCookiesMult * (CM.Cache.Lucky * 0.15) + 13; CM.Cache.LuckyFrenzy = CM.Cache.Lucky * 7; - CM.Cache.LuckyRewardFrenzy = goldenMult * (CM.Cache.LuckyFrenzy * 0.15) + 13; - CM.Cache.LuckyWrathRewardFrenzy = wrathMult * (CM.Cache.LuckyFrenzy * 0.15) + 13; + CM.Cache.LuckyRewardFrenzy = CM.Cache.GoldenCookiesMult * (CM.Cache.LuckyFrenzy * 0.15) + 13; + CM.Cache.LuckyWrathRewardFrenzy = CM.Cache.WrathCookiesMult * (CM.Cache.LuckyFrenzy * 0.15) + 13; CM.Cache.Conjure = CM.Cache.Lucky * 2; CM.Cache.ConjureReward = CM.Cache.Conjure * 0.15; CM.Cache.Edifice = 0; - var max = 0; - var n = 0; + let max = 0; + let n = 0; for (let i of Object.keys(Game.Objects)) { if (Game.Objects[i].amount > max) max = Game.Objects[i].amount; if (Game.Objects[i].amount > 0) n++; @@ -119,6 +117,56 @@ CM.Cache.CacheStats = function() { } }; +/** + * This functions calculates the max possible payout + * It is called by CM.Disp.CreateStatsChainSection() and CM.Cache.RemakeChain() + * @param {number} digit + * @param {number} maxPayout + * @param {number} mult + * @returns {number} moni Cookies to be earned with Cookie Chain + */ +CM.Cache.MaxChainMoni = function(digit, maxPayout, mult) { + var chain = 1 + Math.max(0, Math.ceil(Math.log(Game.cookies) / Math.LN10) - 10); + var moni = Math.max(digit, Math.min(Math.floor(1 / 9 * Math.pow(10, chain) * digit * mult), maxPayout)); + var nextMoni = Math.max(digit, Math.min(Math.floor(1 / 9 * Math.pow(10, chain + 1) * digit * mult), maxPayout)); + while (nextMoni < maxPayout) { + chain++; + moni = Math.max(digit, Math.min(Math.floor(1 / 9 * Math.pow(10, chain) * digit * mult), maxPayout)); + nextMoni = Math.max(digit, Math.min(Math.floor(1 / 9 * Math.pow(10, chain + 1) * digit * mult), maxPayout)); + } + return [moni, nextMoni]; +}; + +/** + * This functions caches data related to Chain Cookies reward from Golden Cookioes + * It is called by CM.Loop() upon changes to cps and CM.Cache.InitCache() + * TODO: Fairly sure this is incorrect.. + * @global {number} CM.Cache.Chain Cookies required for max Cookie Chain normal + */ +CM.Cache.RemakeChain = function() { + let maxPayout = CM.Cache.NoGoldSwitchCookiesPS * 60 * 60 * 6 * CM.Cache.DragonsFortuneMultAdjustment; + // Removes effect of Frenzy etc. + let cpsBuffMult = CM.Sim.getCPSBuffMult(); + if (cpsBuffMult > 0) maxPayout /= cpsBuffMult; + else maxPayout = 0; + + CM.Cache.ChainReward = CM.Cache.MaxChainMoni(7, maxPayout, CM.Cache.GoldenCookiesMult); + CM.Cache.ChainRequired = CM.Cache.ChainReward[0] * 2; + CM.Cache.ChainRequiredNext = CM.Cache.ChainReward[1] / 60 / 60 / 6 / CM.Cache.DragonsFortuneMultAdjustment; + + CM.Cache.ChainWrathReward = CM.Cache.MaxChainMoni(6, maxPayout, CM.Cache.WrathCookiesMult); + CM.Cache.ChainWrathRequired = CM.Cache.ChainWrathReward[0] * 2; + CM.Cache.ChainWrathRequiredNext = CM.Cache.ChainWrathReward[1] / 60 / 60 / 6 / CM.Cache.DragonsFortuneMultAdjustment; + + CM.Cache.ChainFrenzyReward = CM.Cache.MaxChainMoni(7, maxPayout * 7, CM.Cache.GoldenCookiesMult); + CM.Cache.ChainFrenzyRequired = CM.Cache.ChainFrenzyReward[0] * 2; + CM.Cache.ChainFrenzyRequiredNext = CM.Cache.ChainFrenzyReward[1] / 60 / 60 / 6 / CM.Cache.DragonsFortuneMultAdjustment; + + CM.Cache.ChainFrenzyWrathReward = CM.Cache.MaxChainMoni(6, maxPayout * 7, CM.Cache.WrathCookiesMult); + CM.Cache.ChainFrenzyWrathRequired = CM.Cache.ChainFrenzyReward[0] * 2; + CM.Cache.ChainFrenzyWrathRequiredNext = CM.Cache.ChainFrenzyReward[1] / 60 / 60 / 6 / CM.Cache.DragonsFortuneMultAdjustment; +}; + /** * This functions caches variables related to missing upgrades * It is called by CM.Loop() and CM.Cache.InitCache() @@ -348,15 +396,10 @@ CM.Cache.CacheDragonCost = function() { }; /******** - * Section: UNSORTED */ + * Section: ? */ -CM.Cache.NextNumber = function(base) { - var count = base > Math.pow(2, 53) ? Math.pow(2, Math.floor(Math.log(base) / Math.log(2)) - 53) : 1; - while (base == base + count) { - count = CM.Cache.NextNumber(count); - } - return (base + count); -}; +/******** + * Section: UNSORTED */ CM.Cache.RemakeBuildingsPrices = function() { for (let i of Object.keys(Game.Objects)) { @@ -560,66 +603,6 @@ CM.Cache.RemakeGoldenAndWrathCookiesMults = function() { } }; -CM.Cache.MaxChainMoni = function(digit, maxPayout, mult) { - var chain = 1 + Math.max(0, Math.ceil(Math.log(Game.cookies) / Math.LN10) - 10); - var moni = Math.max(digit, Math.min(Math.floor(1 / 9 * Math.pow(10, chain) * digit * mult), maxPayout)); - var nextMoni = Math.max(digit, Math.min(Math.floor(1 / 9 * Math.pow(10, chain + 1) * digit * mult), maxPayout)); - while (nextMoni < maxPayout) { - chain++; - moni = Math.max(digit, Math.min(Math.floor(1 / 9 * Math.pow(10, chain) * digit * mult), maxPayout)); - nextMoni = Math.max(digit, Math.min(Math.floor(1 / 9 * Math.pow(10, chain + 1) * digit * mult), maxPayout)); - } - return moni; -}; - -CM.Cache.RemakeChain = function() { - var maxPayout = CM.Cache.NoGoldSwitchCookiesPS * 60 * 60 * 6; - maxPayout *= CM.Cache.DragonsFortuneMultAdjustment; - var cpsBuffMult = CM.Sim.getCPSBuffMult(); - if (cpsBuffMult > 0) { - maxPayout /= cpsBuffMult; - } else { - maxPayout = 0; - } - - var goldenMult = CM.Cache.GoldenCookiesMult; - var wrathMult = CM.Cache.WrathCookiesMult; - - CM.Cache.ChainReward = CM.Cache.MaxChainMoni(7, maxPayout, goldenMult); - - CM.Cache.ChainWrathReward = CM.Cache.MaxChainMoni(6, maxPayout, wrathMult); - - if (maxPayout < CM.Cache.ChainReward) { - CM.Cache.Chain = 0; - } - else { - CM.Cache.Chain = CM.Cache.NextNumber(CM.Cache.ChainReward) / 0.5; - } - if (maxPayout < CM.Cache.ChainWrathReward) { - CM.Cache.ChainWrath = 0; - } - else { - CM.Cache.ChainWrath = CM.Cache.NextNumber(CM.Cache.ChainWrathReward) / 0.5; - } - - CM.Cache.ChainFrenzyReward = CM.Cache.MaxChainMoni(7, maxPayout * 7, goldenMult); - - CM.Cache.ChainFrenzyWrathReward = CM.Cache.MaxChainMoni(6, maxPayout * 7, wrathMult); - - if ((maxPayout * 7) < CM.Cache.ChainFrenzyReward) { - CM.Cache.ChainFrenzy = 0; - } - else { - CM.Cache.ChainFrenzy = CM.Cache.NextNumber(CM.Cache.ChainFrenzyReward) / 0.5; - } - if ((maxPayout * 7) < CM.Cache.ChainFrenzyWrathReward) { - CM.Cache.ChainFrenzyWrath = 0; - } - else { - CM.Cache.ChainFrenzyWrath = CM.Cache.NextNumber(CM.Cache.ChainFrenzyWrathReward) / 0.5; - } -}; - CM.Cache.RemakeSeaSpec = function() { if (Game.season == 'christmas') { var val = Game.cookiesPs * 60;