Added HC per second to stats and tooltip #169

This commit is contained in:
Daniël van Noord
2021-02-20 23:25:52 +01:00
parent f1183801a8
commit 963116ba2f
5 changed files with 81 additions and 44 deletions

File diff suppressed because one or more lines are too long

View File

@@ -19,6 +19,7 @@ CM.Cache.InitCache = function() {
CM.Cache.CacheMissingUpgrades(); CM.Cache.CacheMissingUpgrades();
CM.Cache.CacheSeaSpec(); CM.Cache.CacheSeaSpec();
CM.Cache.InitCookiesDiff(); CM.Cache.InitCookiesDiff();
CM.Cache.HeavenlyChipsDiff = new CMAvgQueue(5); // Used by CM.Cache.CacheHeavenlyChipsPS()
CM.Cache.CacheAvgCPS(); CM.Cache.CacheAvgCPS();
CM.Cache.CacheIncome(); CM.Cache.CacheIncome();
CM.Cache.CacheBuildingsPrices(); CM.Cache.CacheBuildingsPrices();
@@ -34,18 +35,55 @@ CM.Cache.LoopCache = function() {
// Update Wrinkler Bank // Update Wrinkler Bank
CM.Cache.CacheWrinklers(); CM.Cache.CacheWrinklers();
// Calculate PP
CM.Cache.CachePP(); CM.Cache.CachePP();
// Cache average CPS
CM.Cache.CacheCurrWrinklerCPS(); CM.Cache.CacheCurrWrinklerCPS();
CM.Cache.CacheAvgCPS(); CM.Cache.CacheAvgCPS();
CM.Cache.CacheHeavenlyChipsPS();
let cookiesToNext = Game.HowManyCookiesReset(Math.floor(Game.HowMuchPrestige(Game.cookiesReset + Game.cookiesEarned)) + 1) - (Game.cookiesEarned + Game.cookiesReset); let cookiesToNext = Game.HowManyCookiesReset(Math.floor(Game.HowMuchPrestige(Game.cookiesReset + Game.cookiesEarned)) + 1) - (Game.cookiesEarned + Game.cookiesReset);
CM.Cache.TimeTillNextPrestige = CM.Disp.FormatTime(cookiesToNext / CM.Cache.AvgCPS); CM.Cache.TimeTillNextPrestige = CM.Disp.FormatTime(cookiesToNext / CM.Cache.AvgCPS);
}; };
/********
* Section: Helper functions */
/**
* @class
* @classdesc This is a class used to store values used to calculate average over time (mostly cps)
* @var {number} maxLength The maximum length of the value-storage
* @var {[]} queue The values stored
* @method addLatest(newValue) Appends newValue to the value storage
* @method calcAverage(timePeriod) Returns the average over the specified timeperiod
*/
class CMAvgQueue {
constructor(maxLength) {
this.maxLength = maxLength;
this.queue = [];
}
addLatest (newValue) {
if (this.queue.push(newValue) > this.maxLength) {
this.queue.shift();
}
}
/**
* This functions returns the average of the values in the queue
* @param {number} timePeriod The period in seconds to computer average over
* @returns {number} ret The average
*/
calcAverage (timePeriod) {
if (timePeriod > this.maxLength) timePeriod = this.maxLength;
if (timePeriod > this.queue.length) timePeriod = this.queue.length;
let ret = 0;
for (let i = this.queue.length - 1; i >= 0 && i > this.queue.length - 1 - timePeriod; i--) {
ret += this.queue[i];
}
return ret / timePeriod;
}
}
/******** /********
* Section: Functions related to Dragon Auras */ * Section: Functions related to Dragon Auras */
@@ -303,45 +341,38 @@ CM.Cache.CacheSeaSpec = function() {
} }
}; };
/********
* Section: Functions related to Caching CPS */
/** /**
* @class * This functions caches the heavenly chips per second in the last five seconds
* @classdesc This is a class used to store values used to calculate average over time (mostly cps) * It is called by CM.Cache.LoopCache()
* @var {number} maxLength The maximum length of the value-storage * @global {number} CM.Cache.HCPerSecond The Heavenly Chips per second in the last five seconds
* @var {[]} queue The values stored
* @method addLatest(newValue) Appends newValue to the value storage
* @method calcAverage(timePeriod) Returns the average over the specified timeperiod
*/ */
class CMAvgQueue { CM.Cache.CacheHeavenlyChipsPS = function() {
constructor(maxLength) { let currDate = Math.floor(Date.now() / 1000);
this.maxLength = maxLength; // Only calculate every new second
this.queue = []; if ((Game.T / Game.fps) % 1 === 0) {
let chipsOwned = Game.HowMuchPrestige(Game.cookiesReset);
let ascendNowToOwn = Math.floor(Game.HowMuchPrestige(Game.cookiesReset + Game.cookiesEarned));
let ascendNowToGet = ascendNowToOwn - Math.floor(chipsOwned);
// Add recent gains to AvgQueue's
let timeDiff = currDate - CM.Cache.lastHeavenlyCheck;
let heavenlyChipsDiffAvg = Math.max(0, (ascendNowToGet - CM.Cache.lastHeavenlyChips)) / timeDiff;
for (let i = 0; i < timeDiff; i++) {
CM.Cache.HeavenlyChipsDiff.addLatest(heavenlyChipsDiffAvg);
} }
addLatest (newValue) { // Store current data for next loop
if (this.queue.push(newValue) > this.maxLength) { CM.Cache.lastHeavenlyCheck = currDate;
this.queue.shift(); CM.Cache.lastHeavenlyChips = ascendNowToGet;
}
}
/** // Get average gain over period of 5 seconds
* This functions returns the average of the values in the queue CM.Cache.HCPerSecond = CM.Cache.HeavenlyChipsDiff.calcAverage(5);
* @param {number} timePeriod The period in seconds to computer average over
* @returns {number} ret The average
*/
calcAverage (timePeriod) {
if (timePeriod > this.maxLength) timePeriod = this.maxLength;
if (timePeriod > this.queue.length) timePeriod = this.queue.length;
let ret = 0;
for (let i = this.queue.length - 1; i >= 0 && i > this.queue.length - 1 - timePeriod; i--) {
ret += this.queue[i];
}
return ret / timePeriod;
} }
} }
/********
* Section: Functions related to caching CPS */
/** /**
* This functions caches creates the CMAvgQueue used by CM.Cache.CacheAvgCPS() to calculate CPS * This functions caches creates the CMAvgQueue used by CM.Cache.CacheAvgCPS() to calculate CPS
* Called by CM.Cache.InitCache() * Called by CM.Cache.InitCache()
@@ -372,7 +403,7 @@ CM.Cache.CacheAvgCPS = function() {
choEggTotal *= 0.05; choEggTotal *= 0.05;
// Add recent gains to AvgQueue's // Add recent gains to AvgQueue's
let timeDiff = currDate - CM.Cache.lastDate; let timeDiff = currDate - CM.Cache.lastCPSCheck;
let bankDiffAvg = Math.max(0, (Game.cookies - CM.Cache.lastCookies)) / timeDiff; let bankDiffAvg = Math.max(0, (Game.cookies - CM.Cache.lastCookies)) / timeDiff;
let wrinkDiffAvg = Math.max(0, (CM.Cache.WrinklersTotal - CM.Cache.lastWrinkCookies)) / timeDiff; let wrinkDiffAvg = Math.max(0, (CM.Cache.WrinklersTotal - CM.Cache.lastWrinkCookies)) / timeDiff;
let wrinkFattestDiffAvg = Math.max(0, (CM.Cache.WrinklersFattest[0] - CM.Cache.lastWrinkFattestCookies)) / timeDiff; let wrinkFattestDiffAvg = Math.max(0, (CM.Cache.WrinklersFattest[0] - CM.Cache.lastWrinkFattestCookies)) / timeDiff;
@@ -387,7 +418,7 @@ CM.Cache.CacheAvgCPS = function() {
} }
// Store current data for next loop // Store current data for next loop
CM.Cache.lastDate = currDate; CM.Cache.lastCPSCheck = currDate;
CM.Cache.lastCookies = Game.cookies; CM.Cache.lastCookies = Game.cookies;
CM.Cache.lastWrinkCookies = CM.Cache.WrinklersTotal; CM.Cache.lastWrinkCookies = CM.Cache.WrinklersTotal;
CM.Cache.lastWrinkFattestCookies = CM.Cache.WrinklersFattest[0]; CM.Cache.lastWrinkFattestCookies = CM.Cache.WrinklersFattest[0];

View File

@@ -223,7 +223,7 @@ CM.Data.Config.TooltipWrink = {type: 'bool', group: 'Tooltip', label: ['Wrinkler
CM.Data.Config.TooltipLump = {type: 'bool', group: 'Tooltip', label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true}; CM.Data.Config.TooltipLump = {type: 'bool', group: 'Tooltip', label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true};
CM.Data.Config.TooltipPlots = {type: 'bool', group: 'Tooltip', label: ['Garden Plots Tooltip OFF', 'Garden Plots Tooltip ON'], desc: 'Shows a tooltip for plants that have a cookie reward.', toggle: true}; CM.Data.Config.TooltipPlots = {type: 'bool', group: 'Tooltip', label: ['Garden Plots Tooltip OFF', 'Garden Plots Tooltip ON'], desc: 'Shows a tooltip for plants that have a cookie reward.', toggle: true};
CM.Data.Config.DragonAuraInfo = {type: 'bool', group: 'Tooltip', label: ['Extra Dragon Aura Info OFF', 'Extra Dragon Aura Info ON'], desc: 'Shows information about changes in CPS and costs in the dragon aura interface.', toggle: true}; CM.Data.Config.DragonAuraInfo = {type: 'bool', group: 'Tooltip', label: ['Extra Dragon Aura Info OFF', 'Extra Dragon Aura Info ON'], desc: 'Shows information about changes in CPS and costs in the dragon aura interface.', toggle: true};
CM.Data.Config.TooltipAscendButton = {type: 'bool', group: 'Tooltip', label: ['Show Time Left Ascend Tooltip OFF', 'Show Time Left Ascend Tooltip ON'], desc: 'Shows the time left in the ascend tooltip until next heavenly cookie.', toggle: true}; CM.Data.Config.TooltipAscendButton = {type: 'bool', group: 'Tooltip', label: ['Show Extra Info Ascend Tooltip OFF', 'Show Extra Info Ascend Tooltip ON'], desc: 'Shows additional info in the ascend tooltip', toggle: true};
// Statistics // Statistics
CM.Data.Config.Stats = {type: 'bool', group: 'Statistics', label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true}; CM.Data.Config.Stats = {type: 'bool', group: 'Statistics', label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true};

View File

@@ -2693,6 +2693,8 @@ CM.Disp.CreateStatsPrestigeSection = function() {
section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Heavenly Chips (CUR / MAX)', document.createTextNode(Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips)), 'HeavenChipMaxTooltipPlaceholder')); section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Heavenly Chips (CUR / MAX)', document.createTextNode(Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips)), 'HeavenChipMaxTooltipPlaceholder'));
section.appendChild(CM.Disp.CreateStatsListing("basic", 'Heavenly Chips Per Second (last 5 seconds)', document.createTextNode(Beautify(CM.Cache.HCPerSecond))));
let resetBonus = CM.Sim.ResetBonus(possiblePresMax); let resetBonus = CM.Sim.ResetBonus(possiblePresMax);
let resetFrag = document.createDocumentFragment(); let resetFrag = document.createDocumentFragment();
resetFrag.appendChild(document.createTextNode(Beautify(resetBonus))); resetFrag.appendChild(document.createTextNode(Beautify(resetBonus)));

View File

@@ -197,9 +197,13 @@ CM.Main.ReplaceNative = function() {
// Since the Ascend Tooltip is not actually a tooltip we need to add our additional info here... // Since the Ascend Tooltip is not actually a tooltip we need to add our additional info here...
CM.Backup.Logic = Game.Logic; CM.Backup.Logic = Game.Logic;
eval('CM.Backup.LogicMod = ' + Game.Logic.toString() CM.Backup.LogicMod = new Function(
.split('document.title').join('CM.Disp.Title') `return ${Game.Logic.toString()
.split("' more cookies</b> for the next level.<br>';").join("` more cookies</b> for the next level.<br>${CM.Options.TooltipAscendButton ? `<div class='line'></div>You need ${CM.Cache.TimeTillNextPrestige} for the next level.<br>` : ``}`;")); .split('document.title')
.join('CM.Disp.Title')
.split("' more cookies</b> for the next level.<br>';")
.join("` more cookies</b> for the next level.<br>${CM.Options.TooltipAscendButton ? `<div class='line'></div>It takes ${CM.Cache.TimeTillNextPrestige} to reach the next level and you are making ${CM.Cache.HCPerSecond} chips on average in the last 5 seconds.<br>` : ``}`;")}`,
)();
Game.Logic = function() { Game.Logic = function() {
CM.Backup.LogicMod(); CM.Backup.LogicMod();
// Update Title // Update Title