Added HC per second to stats and tooltip #169
This commit is contained in:
File diff suppressed because one or more lines are too long
103
src/Cache.js
103
src/Cache.js
@@ -19,6 +19,7 @@ CM.Cache.InitCache = function() {
|
||||
CM.Cache.CacheMissingUpgrades();
|
||||
CM.Cache.CacheSeaSpec();
|
||||
CM.Cache.InitCookiesDiff();
|
||||
CM.Cache.HeavenlyChipsDiff = new CMAvgQueue(5); // Used by CM.Cache.CacheHeavenlyChipsPS()
|
||||
CM.Cache.CacheAvgCPS();
|
||||
CM.Cache.CacheIncome();
|
||||
CM.Cache.CacheBuildingsPrices();
|
||||
@@ -34,18 +35,55 @@ CM.Cache.LoopCache = function() {
|
||||
// Update Wrinkler Bank
|
||||
CM.Cache.CacheWrinklers();
|
||||
|
||||
// Calculate PP
|
||||
CM.Cache.CachePP();
|
||||
|
||||
// Cache average CPS
|
||||
CM.Cache.CacheCurrWrinklerCPS();
|
||||
CM.Cache.CacheAvgCPS();
|
||||
CM.Cache.CacheHeavenlyChipsPS();
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
||||
/********
|
||||
* 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 */
|
||||
|
||||
@@ -303,45 +341,38 @@ CM.Cache.CacheSeaSpec = function() {
|
||||
}
|
||||
};
|
||||
|
||||
/********
|
||||
* Section: Functions related to Caching CPS */
|
||||
|
||||
/**
|
||||
* @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
|
||||
* This functions caches the heavenly chips per second in the last five seconds
|
||||
* It is called by CM.Cache.LoopCache()
|
||||
* @global {number} CM.Cache.HCPerSecond The Heavenly Chips per second in the last five seconds
|
||||
*/
|
||||
class CMAvgQueue {
|
||||
constructor(maxLength) {
|
||||
this.maxLength = maxLength;
|
||||
this.queue = [];
|
||||
CM.Cache.CacheHeavenlyChipsPS = function() {
|
||||
let currDate = Math.floor(Date.now() / 1000);
|
||||
// Only calculate every new second
|
||||
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) {
|
||||
if (this.queue.push(newValue) > this.maxLength) {
|
||||
this.queue.shift();
|
||||
}
|
||||
}
|
||||
// Store current data for next loop
|
||||
CM.Cache.lastHeavenlyCheck = currDate;
|
||||
CM.Cache.lastHeavenlyChips = ascendNowToGet;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
// Get average gain over period of 5 seconds
|
||||
CM.Cache.HCPerSecond = CM.Cache.HeavenlyChipsDiff.calcAverage(5);
|
||||
}
|
||||
}
|
||||
|
||||
/********
|
||||
* Section: Functions related to caching CPS */
|
||||
|
||||
/**
|
||||
* This functions caches creates the CMAvgQueue used by CM.Cache.CacheAvgCPS() to calculate CPS
|
||||
* Called by CM.Cache.InitCache()
|
||||
@@ -372,7 +403,7 @@ CM.Cache.CacheAvgCPS = function() {
|
||||
choEggTotal *= 0.05;
|
||||
|
||||
// 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 wrinkDiffAvg = Math.max(0, (CM.Cache.WrinklersTotal - CM.Cache.lastWrinkCookies)) / 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
|
||||
CM.Cache.lastDate = currDate;
|
||||
CM.Cache.lastCPSCheck = currDate;
|
||||
CM.Cache.lastCookies = Game.cookies;
|
||||
CM.Cache.lastWrinkCookies = CM.Cache.WrinklersTotal;
|
||||
CM.Cache.lastWrinkFattestCookies = CM.Cache.WrinklersFattest[0];
|
||||
|
||||
@@ -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.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.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
|
||||
CM.Data.Config.Stats = {type: 'bool', group: 'Statistics', label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true};
|
||||
|
||||
@@ -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("basic", 'Heavenly Chips Per Second (last 5 seconds)', document.createTextNode(Beautify(CM.Cache.HCPerSecond))));
|
||||
|
||||
let resetBonus = CM.Sim.ResetBonus(possiblePresMax);
|
||||
let resetFrag = document.createDocumentFragment();
|
||||
resetFrag.appendChild(document.createTextNode(Beautify(resetBonus)));
|
||||
|
||||
10
src/Main.js
10
src/Main.js
@@ -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...
|
||||
CM.Backup.Logic = Game.Logic;
|
||||
eval('CM.Backup.LogicMod = ' + Game.Logic.toString()
|
||||
.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>You need ${CM.Cache.TimeTillNextPrestige} for the next level.<br>` : ``}`;"));
|
||||
CM.Backup.LogicMod = new Function(
|
||||
`return ${Game.Logic.toString()
|
||||
.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() {
|
||||
CM.Backup.LogicMod();
|
||||
// Update Title
|
||||
|
||||
Reference in New Issue
Block a user