From c6c54054eed665871191fd9d1c0c1142253e1cd3 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 19 Dec 2020 17:37:01 +0100 Subject: [PATCH 1/4] Added section to Cache.js --- CookieMonster.js | 71 ++++++++++++++++++++++++------------------------ src/Cache.js | 71 ++++++++++++++++++++++++------------------------ 2 files changed, 72 insertions(+), 70 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index b4ed40e..8dc4b66 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -31,6 +31,9 @@ if (typeof CM == "undefined") { * Cache * *********/ +/******** + * Section: Functions related to Dragon Auras */ + /** * This functions caches the currently selected Dragon Auras * It is called by CM.Sim.CopyData() and CM.Sim.InitData() @@ -41,6 +44,39 @@ CM.Cache.CacheDragonAuras = function() { CM.Cache.dragonAura2 = Game.dragonAura2; } +/******** + * Section: Functions related to Wrinklers */ + +CM.Cache.RemakeWrinkBank = function() { + CM.Cache.WrinkBankTotal = 0; + CM.Cache.WrinkBankNormal = 0; + var totalSucked = 0; + for (var i in Game.wrinklers) { + var sucked = Game.wrinklers[i].sucked; + var toSuck = 1.1; + if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; + if (Game.wrinklers[i].type==1) toSuck *= 3; // Shiny wrinklers + sucked *= toSuck; + if (Game.Has('Wrinklerspawn')) sucked *= 1.05; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 1) sucked *= 1.15; + else if (godLvl == 2) sucked *= 1.1; + else if (godLvl == 3) sucked *= 1.05; + } + CM.Cache.WrinkBankTotal += sucked; + if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; + } + CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; + else if (godLvl == 3) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.05; + else if (godLvl != 1) CM.Cache.WrinkGodBank *= 1.15; + } +} + + /******** * Section: UNSORTED */ @@ -81,35 +117,6 @@ CM.Cache.RemakeIncome = function() { CM.Sim.BuyBuildings(100, 'Objects100'); } -CM.Cache.RemakeWrinkBank = function() { - CM.Cache.WrinkBankTotal = 0; - CM.Cache.WrinkBankNormal = 0; - var totalSucked = 0; - for (var i in Game.wrinklers) { - var sucked = Game.wrinklers[i].sucked; - var toSuck = 1.1; - if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; - if (Game.wrinklers[i].type==1) toSuck *= 3; // Shiny wrinklers - sucked *= toSuck; - if (Game.Has('Wrinklerspawn')) sucked *= 1.05; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 1) sucked *= 1.15; - else if (godLvl == 2) sucked *= 1.1; - else if (godLvl == 3) sucked *= 1.05; - } - CM.Cache.WrinkBankTotal += sucked; - if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; - } - CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; - else if (godLvl == 3) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.05; - else if (godLvl != 1) CM.Cache.WrinkGodBank *= 1.15; - } -} - CM.Cache.RemakeBuildingsPP = function() { CM.Cache.min = -1; CM.Cache.max = -1; @@ -573,12 +580,6 @@ CM.Cache.seasonPopShimmer; CM.Cache.goldenShimmersByID = {}; CM.Cache.spawnedGoldenShimmer = 0; -/** - * This variables are used by CM.Cache.CacheDragonAuras(), naming follows naming in Game - */ -CM.Cache.dragonAura = 0; -CM.Cache.dragonAura2 = 0; - /********** * Config * **********/ diff --git a/src/Cache.js b/src/Cache.js index 83416ad..ff95705 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -2,6 +2,9 @@ * Cache * *********/ +/******** + * Section: Functions related to Dragon Auras */ + /** * This functions caches the currently selected Dragon Auras * It is called by CM.Sim.CopyData() and CM.Sim.InitData() @@ -12,6 +15,39 @@ CM.Cache.CacheDragonAuras = function() { CM.Cache.dragonAura2 = Game.dragonAura2; } +/******** + * Section: Functions related to Wrinklers */ + +CM.Cache.RemakeWrinkBank = function() { + CM.Cache.WrinkBankTotal = 0; + CM.Cache.WrinkBankNormal = 0; + var totalSucked = 0; + for (var i in Game.wrinklers) { + var sucked = Game.wrinklers[i].sucked; + var toSuck = 1.1; + if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; + if (Game.wrinklers[i].type==1) toSuck *= 3; // Shiny wrinklers + sucked *= toSuck; + if (Game.Has('Wrinklerspawn')) sucked *= 1.05; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 1) sucked *= 1.15; + else if (godLvl == 2) sucked *= 1.1; + else if (godLvl == 3) sucked *= 1.05; + } + CM.Cache.WrinkBankTotal += sucked; + if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; + } + CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; + else if (godLvl == 3) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.05; + else if (godLvl != 1) CM.Cache.WrinkGodBank *= 1.15; + } +} + + /******** * Section: UNSORTED */ @@ -52,35 +88,6 @@ CM.Cache.RemakeIncome = function() { CM.Sim.BuyBuildings(100, 'Objects100'); } -CM.Cache.RemakeWrinkBank = function() { - CM.Cache.WrinkBankTotal = 0; - CM.Cache.WrinkBankNormal = 0; - var totalSucked = 0; - for (var i in Game.wrinklers) { - var sucked = Game.wrinklers[i].sucked; - var toSuck = 1.1; - if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; - if (Game.wrinklers[i].type==1) toSuck *= 3; // Shiny wrinklers - sucked *= toSuck; - if (Game.Has('Wrinklerspawn')) sucked *= 1.05; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 1) sucked *= 1.15; - else if (godLvl == 2) sucked *= 1.1; - else if (godLvl == 3) sucked *= 1.05; - } - CM.Cache.WrinkBankTotal += sucked; - if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; - } - CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; - else if (godLvl == 3) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.05; - else if (godLvl != 1) CM.Cache.WrinkGodBank *= 1.15; - } -} - CM.Cache.RemakeBuildingsPP = function() { CM.Cache.min = -1; CM.Cache.max = -1; @@ -544,9 +551,3 @@ CM.Cache.seasonPopShimmer; CM.Cache.goldenShimmersByID = {}; CM.Cache.spawnedGoldenShimmer = 0; -/** - * This variables are used by CM.Cache.CacheDragonAuras(), naming follows naming in Game - */ -CM.Cache.dragonAura = 0; -CM.Cache.dragonAura2 = 0; - From 389dae4daa3035a5c38762f29b8f51314042d0bc Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 19 Dec 2020 17:45:33 +0100 Subject: [PATCH 2/4] Created function CM.Cache.InitCache --- CookieMonster.js | 21 ++++++++++++++++++--- src/Cache.js | 17 +++++++++++++++++ src/Main.js | 1 + src/Sim.js | 3 --- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 8dc4b66..c711f28 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -31,6 +31,19 @@ if (typeof CM == "undefined") { * Cache * *********/ +/******** + * Section: General Cache related functions */ + +/** + * This functions runs all cache-functions to generate all "full" cache + * The declaration follows the structure of the CM.Cache.js file + * It is called by CM.DelayInit + * TODO: Add all functions that should be here and remove them from CM.Loop() + */ +CM.Cache.InitCache = function() { + CM.Cache.CacheDragonAuras(); +} + /******** * Section: Functions related to Dragon Auras */ @@ -47,6 +60,10 @@ CM.Cache.CacheDragonAuras = function() { /******** * Section: Functions related to Wrinklers */ +/** + * This functions caches data related to Wrinklers + * It is called by CM.Loop() + */ CM.Cache.RemakeWrinkBank = function() { CM.Cache.WrinkBankTotal = 0; CM.Cache.WrinkBankNormal = 0; @@ -4000,6 +4017,7 @@ CM.Init = function() { CM.DelayInit = function() { CM.Sim.InitData(); + CM.Cache.InitCache(); CM.Disp.CreateCssArea(); CM.Disp.CreateBotBar(); CM.Disp.CreateTimerBar(); @@ -4469,9 +4487,6 @@ CM.Sim.InitData = function() { for (var i in Game.Achievements) { CM.Sim.Achievements[i] = CM.Sim.InitAchievement(i); } - - // Auras - CM.Cache.CacheDragonAuras(); } CM.Sim.CopyData = function() { diff --git a/src/Cache.js b/src/Cache.js index ff95705..c575948 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -2,6 +2,19 @@ * Cache * *********/ +/******** + * Section: General Cache related functions */ + +/** + * This functions runs all cache-functions to generate all "full" cache + * The declaration follows the structure of the CM.Cache.js file + * It is called by CM.DelayInit + * TODO: Add all functions that should be here and remove them from CM.Loop() + */ +CM.Cache.InitCache = function() { + CM.Cache.CacheDragonAuras(); +} + /******** * Section: Functions related to Dragon Auras */ @@ -18,6 +31,10 @@ CM.Cache.CacheDragonAuras = function() { /******** * Section: Functions related to Wrinklers */ +/** + * This functions caches data related to Wrinklers + * It is called by CM.Loop() + */ CM.Cache.RemakeWrinkBank = function() { CM.Cache.WrinkBankTotal = 0; CM.Cache.WrinkBankNormal = 0; diff --git a/src/Main.js b/src/Main.js index 12c0de1..80d16ea 100644 --- a/src/Main.js +++ b/src/Main.js @@ -229,6 +229,7 @@ CM.Init = function() { CM.DelayInit = function() { CM.Sim.InitData(); + CM.Cache.InitCache(); CM.Disp.CreateCssArea(); CM.Disp.CreateBotBar(); CM.Disp.CreateTimerBar(); diff --git a/src/Sim.js b/src/Sim.js index 7b3dd29..d4fc227 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -207,9 +207,6 @@ CM.Sim.InitData = function() { for (var i in Game.Achievements) { CM.Sim.Achievements[i] = CM.Sim.InitAchievement(i); } - - // Auras - CM.Cache.CacheDragonAuras(); } CM.Sim.CopyData = function() { From 0f865f38974ea5e6c51dbb338f87018460e2349f Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 19 Dec 2020 18:26:38 +0100 Subject: [PATCH 3/4] Button and stat for single fattest wrinkler (#177) --- CookieMonster.js | 61 ++++++++++++++++++++++++++---------------------- src/Cache.js | 41 +++++++++++++++----------------- src/Disp.js | 18 ++++++++++---- src/Main.js | 2 +- 4 files changed, 66 insertions(+), 56 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index c711f28..15a3da1 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -42,6 +42,7 @@ if (typeof CM == "undefined") { */ CM.Cache.InitCache = function() { CM.Cache.CacheDragonAuras(); + CM.Cache.CacheWrinklers(); } /******** @@ -49,10 +50,13 @@ CM.Cache.InitCache = function() { /** * This functions caches the currently selected Dragon Auras - * It is called by CM.Sim.CopyData() and CM.Sim.InitData() + * It is called by CM.Sim.CopyData() and CM.Cache.InitCache() * Uncapitalized dragon follows Game-naming + * @global {number} CM.Cache.dragonAura The number of the first (right) Aura + * @global {number} CM.Cache.dragonAura2 The number of the second (left) Aura */ CM.Cache.CacheDragonAuras = function() { + /** @global */ CM.Cache.dragonAura = Game.dragonAura; CM.Cache.dragonAura2 = Game.dragonAura2; } @@ -62,12 +66,15 @@ CM.Cache.CacheDragonAuras = function() { /** * This functions caches data related to Wrinklers - * It is called by CM.Loop() + * It is called by CM.Loop() and CM.Cache.InitCache() + * @global {number} CM.Cache.WrinklersTotal The cookies of all wrinklers + * @global {number} CM.Cache.WrinklersNormal The cookies of all normal wrinklers + * @global {[{number}, {number}]} CM.Cache.WrinklersFattest A list containing the cookies and the id of the fattest wrinkler */ -CM.Cache.RemakeWrinkBank = function() { - CM.Cache.WrinkBankTotal = 0; - CM.Cache.WrinkBankNormal = 0; - var totalSucked = 0; +CM.Cache.CacheWrinklers = function() { + CM.Cache.WrinklersTotal = 0; + CM.Cache.WrinklersNormal = 0; + CM.Cache.WrinklersFattest = [0, null]; for (var i in Game.wrinklers) { var sucked = Game.wrinklers[i].sucked; var toSuck = 1.1; @@ -81,19 +88,12 @@ CM.Cache.RemakeWrinkBank = function() { else if (godLvl == 2) sucked *= 1.1; else if (godLvl == 3) sucked *= 1.05; } - CM.Cache.WrinkBankTotal += sucked; - if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; - } - CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; - else if (godLvl == 3) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.05; - else if (godLvl != 1) CM.Cache.WrinkGodBank *= 1.15; + CM.Cache.WrinklersTotal += sucked; + if (Game.wrinklers[i].type == 0) CM.Cache.WrinklersNormal += sucked; + if (sucked > CM.Cache.WrinklersFattest[0]) CM.Cache.WrinklersFattest = [sucked, i]; } } - /******** * Section: UNSORTED */ @@ -434,7 +434,7 @@ CM.Cache.UpdateAvgCPS = function() { if (CM.Cache.lastDate != currDate) { var choEggTotal = Game.cookies + CM.Cache.SellForChoEgg; if (Game.cpsSucked > 0) { - choEggTotal += CM.Cache.WrinkGodBank; + choEggTotal += CM.Cache.WrinklersTotal; } CM.Cache.RealCookiesEarned = Math.max(Game.cookiesEarned, choEggTotal); choEggTotal *= 0.05; @@ -442,7 +442,7 @@ CM.Cache.UpdateAvgCPS = function() { if (CM.Cache.lastDate != -1) { var timeDiff = currDate - CM.Cache.lastDate var bankDiffAvg = Math.max(0, (Game.cookies - CM.Cache.lastCookies)) / timeDiff; - var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinkBankTotal - CM.Cache.lastWrinkCookies)) / timeDiff; + var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinklersTotal - CM.Cache.lastWrinkCookies)) / timeDiff; var choEggDiffAvg = Math.max(0,(choEggTotal - CM.Cache.lastChoEgg)) / timeDiff; var clicksDiffAvg = (Game.cookieClicks - CM.Cache.lastClicks) / timeDiff; for (var i = 0; i < timeDiff; i++) { @@ -464,7 +464,7 @@ CM.Cache.UpdateAvgCPS = function() { } CM.Cache.lastDate = currDate; CM.Cache.lastCookies = Game.cookies; - CM.Cache.lastWrinkCookies = CM.Cache.WrinkBankTotal; + CM.Cache.lastWrinkCookies = CM.Cache.WrinklersTotal; CM.Cache.lastChoEgg = choEggTotal; CM.Cache.lastClicks = Game.cookieClicks; @@ -547,9 +547,6 @@ CM.Cache.CalcMissingUpgrades = function() { CM.Cache.min = -1; CM.Cache.max = -1; CM.Cache.mid = -1; -CM.Cache.WrinkBankTotal = -1; -CM.Cache.WrinkBankNormal = -1; -CM.Cache.WrinkGodBank = -1; CM.Cache.GoldenCookiesMult = 1; CM.Cache.WrathCookiesMult = 1; CM.Cache.DragonsFortuneMultAdjustment = 1; @@ -1058,11 +1055,11 @@ CM.Data.ConfigDefault = { /** * This function returns the total amount stored in the Wrinkler Bank * as calculated by CM.Cache.RemakeWrinkBank() if CM.Options.CalcWrink is set - * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinkBankTotal) + * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinklersTotal) */ CM.Disp.GetWrinkConfigBank = function() { if (CM.Options.CalcWrink) - return CM.Cache.WrinkBankTotal; + return CM.Cache.WrinklersTotal; else return 0; } @@ -3164,13 +3161,21 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsHeader('Wrinklers', 'Wrink')); if (CM.Options.Header.Wrink) { var popAllFrag = document.createDocumentFragment(); - popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBankTotal) + ' / ' + Beautify(CM.Cache.WrinkBankNormal) + ' ')); + popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinklersTotal) + ' / ' + Beautify(CM.Cache.WrinklersNormal) + ' ')); var popAllA = document.createElement('a'); popAllA.textContent = 'Pop All Normal'; popAllA.className = 'option'; popAllA.onclick = function() { CM.Disp.PopAllNormalWrinklers(); }; popAllFrag.appendChild(popAllA); stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping (All/Normal)', popAllFrag)); + var popFattestFrag = document.createDocumentFragment(); + popFattestFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinklersFattest[0]) + ' ')); + var popFattestA = document.createElement('a'); + popFattestA.textContent = 'Pop single fattest'; + popFattestA.className = 'option'; + popFattestA.onclick = function() { Game.wrinklers[CM.Cache.WrinklersFattest[1]].hp = 0; }; + popFattestFrag.appendChild(popFattestA); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping Single Fattest Wrinkler (id: ' + CM.Cache.WrinklersFattest[1] + ")", popFattestFrag)); } } @@ -3575,11 +3580,11 @@ CM.Disp.CreateStatsPrestigeSection = function() { section.className = 'CMStatsPrestigeSection'; var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + - Game.cookiesReset + CM.Cache.WrinkGodBank + + Game.cookiesReset + CM.Cache.WrinklersTotal + (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0))); section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Prestige Level (CUR / MAX)', document.createTextNode(Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax)), 'PrestMaxTooltipPlaceholder')); - var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + ((Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0) ? CM.Cache.lastChoEgg : 0)); + var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinklersTotal + ((Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0) ? CM.Cache.lastChoEgg : 0)); var cookiesNextFrag = document.createDocumentFragment(); cookiesNextFrag.appendChild(document.createTextNode(Beautify(neededCook))); var cookiesNextSmall = document.createElement('small'); @@ -3959,7 +3964,7 @@ CM.Loop = function() { } // Update Wrinkler Bank - CM.Cache.RemakeWrinkBank(); + CM.Cache.CacheWrinklers(); // Calculate PP CM.Cache.RemakePP(); diff --git a/src/Cache.js b/src/Cache.js index c575948..2307ffc 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -13,6 +13,7 @@ */ CM.Cache.InitCache = function() { CM.Cache.CacheDragonAuras(); + CM.Cache.CacheWrinklers(); } /******** @@ -20,10 +21,13 @@ CM.Cache.InitCache = function() { /** * This functions caches the currently selected Dragon Auras - * It is called by CM.Sim.CopyData() and CM.Sim.InitData() + * It is called by CM.Sim.CopyData() and CM.Cache.InitCache() * Uncapitalized dragon follows Game-naming + * @global {number} CM.Cache.dragonAura The number of the first (right) Aura + * @global {number} CM.Cache.dragonAura2 The number of the second (left) Aura */ CM.Cache.CacheDragonAuras = function() { + /** @global */ CM.Cache.dragonAura = Game.dragonAura; CM.Cache.dragonAura2 = Game.dragonAura2; } @@ -33,12 +37,15 @@ CM.Cache.CacheDragonAuras = function() { /** * This functions caches data related to Wrinklers - * It is called by CM.Loop() + * It is called by CM.Loop() and CM.Cache.InitCache() + * @global {number} CM.Cache.WrinklersTotal The cookies of all wrinklers + * @global {number} CM.Cache.WrinklersNormal The cookies of all normal wrinklers + * @global {[{number}, {number}]} CM.Cache.WrinklersFattest A list containing the cookies and the id of the fattest wrinkler */ -CM.Cache.RemakeWrinkBank = function() { - CM.Cache.WrinkBankTotal = 0; - CM.Cache.WrinkBankNormal = 0; - var totalSucked = 0; +CM.Cache.CacheWrinklers = function() { + CM.Cache.WrinklersTotal = 0; + CM.Cache.WrinklersNormal = 0; + CM.Cache.WrinklersFattest = [0, null]; for (var i in Game.wrinklers) { var sucked = Game.wrinklers[i].sucked; var toSuck = 1.1; @@ -52,19 +59,12 @@ CM.Cache.RemakeWrinkBank = function() { else if (godLvl == 2) sucked *= 1.1; else if (godLvl == 3) sucked *= 1.05; } - CM.Cache.WrinkBankTotal += sucked; - if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; - } - CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; - else if (godLvl == 3) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.05; - else if (godLvl != 1) CM.Cache.WrinkGodBank *= 1.15; + CM.Cache.WrinklersTotal += sucked; + if (Game.wrinklers[i].type == 0) CM.Cache.WrinklersNormal += sucked; + if (sucked > CM.Cache.WrinklersFattest[0]) CM.Cache.WrinklersFattest = [sucked, i]; } } - /******** * Section: UNSORTED */ @@ -405,7 +405,7 @@ CM.Cache.UpdateAvgCPS = function() { if (CM.Cache.lastDate != currDate) { var choEggTotal = Game.cookies + CM.Cache.SellForChoEgg; if (Game.cpsSucked > 0) { - choEggTotal += CM.Cache.WrinkGodBank; + choEggTotal += CM.Cache.WrinklersTotal; } CM.Cache.RealCookiesEarned = Math.max(Game.cookiesEarned, choEggTotal); choEggTotal *= 0.05; @@ -413,7 +413,7 @@ CM.Cache.UpdateAvgCPS = function() { if (CM.Cache.lastDate != -1) { var timeDiff = currDate - CM.Cache.lastDate var bankDiffAvg = Math.max(0, (Game.cookies - CM.Cache.lastCookies)) / timeDiff; - var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinkBankTotal - CM.Cache.lastWrinkCookies)) / timeDiff; + var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinklersTotal - CM.Cache.lastWrinkCookies)) / timeDiff; var choEggDiffAvg = Math.max(0,(choEggTotal - CM.Cache.lastChoEgg)) / timeDiff; var clicksDiffAvg = (Game.cookieClicks - CM.Cache.lastClicks) / timeDiff; for (var i = 0; i < timeDiff; i++) { @@ -435,7 +435,7 @@ CM.Cache.UpdateAvgCPS = function() { } CM.Cache.lastDate = currDate; CM.Cache.lastCookies = Game.cookies; - CM.Cache.lastWrinkCookies = CM.Cache.WrinkBankTotal; + CM.Cache.lastWrinkCookies = CM.Cache.WrinklersTotal; CM.Cache.lastChoEgg = choEggTotal; CM.Cache.lastClicks = Game.cookieClicks; @@ -518,9 +518,6 @@ CM.Cache.CalcMissingUpgrades = function() { CM.Cache.min = -1; CM.Cache.max = -1; CM.Cache.mid = -1; -CM.Cache.WrinkBankTotal = -1; -CM.Cache.WrinkBankNormal = -1; -CM.Cache.WrinkGodBank = -1; CM.Cache.GoldenCookiesMult = 1; CM.Cache.WrathCookiesMult = 1; CM.Cache.DragonsFortuneMultAdjustment = 1; diff --git a/src/Disp.js b/src/Disp.js index 7516ed8..8513c30 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -13,11 +13,11 @@ /** * This function returns the total amount stored in the Wrinkler Bank * as calculated by CM.Cache.RemakeWrinkBank() if CM.Options.CalcWrink is set - * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinkBankTotal) + * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinklersTotal) */ CM.Disp.GetWrinkConfigBank = function() { if (CM.Options.CalcWrink) - return CM.Cache.WrinkBankTotal; + return CM.Cache.WrinklersTotal; else return 0; } @@ -2119,13 +2119,21 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsHeader('Wrinklers', 'Wrink')); if (CM.Options.Header.Wrink) { var popAllFrag = document.createDocumentFragment(); - popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBankTotal) + ' / ' + Beautify(CM.Cache.WrinkBankNormal) + ' ')); + popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinklersTotal) + ' / ' + Beautify(CM.Cache.WrinklersNormal) + ' ')); var popAllA = document.createElement('a'); popAllA.textContent = 'Pop All Normal'; popAllA.className = 'option'; popAllA.onclick = function() { CM.Disp.PopAllNormalWrinklers(); }; popAllFrag.appendChild(popAllA); stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping (All/Normal)', popAllFrag)); + var popFattestFrag = document.createDocumentFragment(); + popFattestFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinklersFattest[0]) + ' ')); + var popFattestA = document.createElement('a'); + popFattestA.textContent = 'Pop single fattest'; + popFattestA.className = 'option'; + popFattestA.onclick = function() { Game.wrinklers[CM.Cache.WrinklersFattest[1]].hp = 0; }; + popFattestFrag.appendChild(popFattestA); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping Single Fattest Wrinkler (id: ' + CM.Cache.WrinklersFattest[1] + ")", popFattestFrag)); } } @@ -2530,11 +2538,11 @@ CM.Disp.CreateStatsPrestigeSection = function() { section.className = 'CMStatsPrestigeSection'; var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + - Game.cookiesReset + CM.Cache.WrinkGodBank + + Game.cookiesReset + CM.Cache.WrinklersTotal + (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0))); section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Prestige Level (CUR / MAX)', document.createTextNode(Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax)), 'PrestMaxTooltipPlaceholder')); - var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + ((Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0) ? CM.Cache.lastChoEgg : 0)); + var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinklersTotal + ((Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0) ? CM.Cache.lastChoEgg : 0)); var cookiesNextFrag = document.createDocumentFragment(); cookiesNextFrag.appendChild(document.createTextNode(Beautify(neededCook))); var cookiesNextSmall = document.createElement('small'); diff --git a/src/Main.js b/src/Main.js index 80d16ea..ff447e1 100644 --- a/src/Main.js +++ b/src/Main.js @@ -171,7 +171,7 @@ CM.Loop = function() { } // Update Wrinkler Bank - CM.Cache.RemakeWrinkBank(); + CM.Cache.CacheWrinklers(); // Calculate PP CM.Cache.RemakePP(); From 07d73b10e36b87f47241da934e1c88df9628904f Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 19 Dec 2020 18:32:53 +0100 Subject: [PATCH 4/4] Option to calc with single fattest wrinkler (#245) --- CookieMonster.js | 17 ++++++++++------- src/Cache.js | 3 ++- src/Data.js | 2 +- src/Disp.js | 12 +++++++----- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 15a3da1..42d30ea 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -506,7 +506,8 @@ CM.Cache.UpdateAvgCPS = function() { totalGainWrink += sortedGainWrink[i]; totalGainChoEgg += sortedGainChoEgg[i]; } - CM.Cache.AvgCPS = (totalGainBank + (CM.Options.CalcWrink ? totalGainWrink : 0)) / sortedGainBank.length; + // TODO: Incorporate situation if CM.Options.CalcWrink == 2 + CM.Cache.AvgCPS = (totalGainBank + (CM.Options.CalcWrink == 1 ? totalGainWrink : 0)) / sortedGainBank.length; var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); @@ -869,7 +870,7 @@ CM.ConfigData.Colors = { type: 'color', group: 'BarsColors', CM.ConfigData.UpgradeBarFixedPos = {type: 'bool', group: 'BarsColors', label: ['Upgrade Bar Fixed Position OFF', 'Upgrade Bar Fixed Position ON'], desc: 'Lock the upgrade bar at top of the screen to prevent it from moving ofscreen when scrolling', toggle: true, func: function() {CM.Disp.ToggleUpgradeBarFixedPos();}}; // Calculation -CM.ConfigData.CalcWrink = {type: 'bool', group: 'Calculation', label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON'], desc: 'Calculate times and average Cookies Per Second with Wrinklers', toggle: true}; +CM.ConfigData.CalcWrink = {type: 'bool', group: 'Calculation', label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON', 'Calculate with Single Fattest Wrinkler ON'], desc: 'Calculate times and average Cookies Per Second with (only the single fattest) Wrinklers', toggle: true}; CM.ConfigData.CPSMode = {type: 'bool', group: 'Calculation', label: ['Current Cookies Per Second', 'Average Cookies Per Second'], desc: 'Calculate times using current Cookies Per Second or average Cookies Per Second', toggle: false}; CM.ConfigData.AvgCPSHist = {type: 'bool', group: 'Calculation', label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false}; CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false}; @@ -1054,14 +1055,16 @@ CM.Data.ConfigDefault = { /** * This function returns the total amount stored in the Wrinkler Bank - * as calculated by CM.Cache.RemakeWrinkBank() if CM.Options.CalcWrink is set + * as calculated by CM.Cache.CacheWrinklers() if CM.Options.CalcWrink is set * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinklersTotal) */ CM.Disp.GetWrinkConfigBank = function() { - if (CM.Options.CalcWrink) - return CM.Cache.WrinklersTotal; - else - return 0; + if (CM.Options.CalcWrink == 1) { + return CM.Cache.WrinklersTotal;} + else if (CM.Options.CalcWrink == 2) { + return CM.Cache.WrinklersFattest[0];} + else { + return 0;} } /** diff --git a/src/Cache.js b/src/Cache.js index 2307ffc..c8377c9 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -477,7 +477,8 @@ CM.Cache.UpdateAvgCPS = function() { totalGainWrink += sortedGainWrink[i]; totalGainChoEgg += sortedGainChoEgg[i]; } - CM.Cache.AvgCPS = (totalGainBank + (CM.Options.CalcWrink ? totalGainWrink : 0)) / sortedGainBank.length; + // TODO: Incorporate situation if CM.Options.CalcWrink == 2 + CM.Cache.AvgCPS = (totalGainBank + (CM.Options.CalcWrink == 1 ? totalGainWrink : 0)) / sortedGainBank.length; var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); diff --git a/src/Data.js b/src/Data.js index ee4c109..e96b951 100644 --- a/src/Data.js +++ b/src/Data.js @@ -103,7 +103,7 @@ CM.ConfigData.Colors = { type: 'color', group: 'BarsColors', CM.ConfigData.UpgradeBarFixedPos = {type: 'bool', group: 'BarsColors', label: ['Upgrade Bar Fixed Position OFF', 'Upgrade Bar Fixed Position ON'], desc: 'Lock the upgrade bar at top of the screen to prevent it from moving ofscreen when scrolling', toggle: true, func: function() {CM.Disp.ToggleUpgradeBarFixedPos();}}; // Calculation -CM.ConfigData.CalcWrink = {type: 'bool', group: 'Calculation', label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON'], desc: 'Calculate times and average Cookies Per Second with Wrinklers', toggle: true}; +CM.ConfigData.CalcWrink = {type: 'bool', group: 'Calculation', label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON', 'Calculate with Single Fattest Wrinkler ON'], desc: 'Calculate times and average Cookies Per Second with (only the single fattest) Wrinklers', toggle: true}; CM.ConfigData.CPSMode = {type: 'bool', group: 'Calculation', label: ['Current Cookies Per Second', 'Average Cookies Per Second'], desc: 'Calculate times using current Cookies Per Second or average Cookies Per Second', toggle: false}; CM.ConfigData.AvgCPSHist = {type: 'bool', group: 'Calculation', label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false}; CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false}; diff --git a/src/Disp.js b/src/Disp.js index 8513c30..261b707 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -12,14 +12,16 @@ /** * This function returns the total amount stored in the Wrinkler Bank - * as calculated by CM.Cache.RemakeWrinkBank() if CM.Options.CalcWrink is set + * as calculated by CM.Cache.CacheWrinklers() if CM.Options.CalcWrink is set * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinklersTotal) */ CM.Disp.GetWrinkConfigBank = function() { - if (CM.Options.CalcWrink) - return CM.Cache.WrinklersTotal; - else - return 0; + if (CM.Options.CalcWrink == 1) { + return CM.Cache.WrinklersTotal;} + else if (CM.Options.CalcWrink == 2) { + return CM.Cache.WrinklersFattest[0];} + else { + return 0;} } /**