Allow pp based on "less than x secs of CPS" #149

This commit is contained in:
Daniël van Noord
2021-02-21 16:21:43 +01:00
parent 9ead87dd16
commit 69f972fac2
4 changed files with 45 additions and 41 deletions

View File

@@ -649,31 +649,51 @@ CM.Cache.CachePP = function() {
CM.Cache.CacheUpgradePP();
};
/**
* This functions return the colour assosciated with the given pp value
* It is called by CM.Cache.CacheBuildingsPP(), CM.Cache.CacheBuildingsBulkPP() and CM.Cache.CacheUpgradePP()
* @params {object} obj The obj of which the pp value should be checked
* @params {number} price The price of the object
* @returns {string} color The colour assosciated with the pp value
*/
CM.Cache.ColourOfPP = function(me, price) {
let color = '';
// Colour based on PP
if (me.pp <= 0 || me.pp === Infinity) color = CM.Disp.colorGray;
else if (me.pp < CM.Cache.min) color = CM.Disp.colorBlue;
else if (me.pp === CM.Cache.min) color = CM.Disp.colorGreen;
else if (me.pp === CM.Cache.max) color = CM.Disp.colorRed;
else if (me.pp > CM.Cache.max) color = CM.Disp.colorPurple;
else if (me.pp > CM.Cache.mid) color = CM.Disp.colorOrange;
else color = CM.Disp.colorYellow;
// Colour based on price in terms of CPS
if (Number(CM.Options.PPSecondsLowerLimit) !== 0) {
if (price / CM.Cache.AvgCPS < Number(CM.Options.PPSecondsLowerLimit)) color = CM.Disp.colorBlue
}
return color
};
/**
* This functions caches the PP of each building it saves all date in CM.Cache.Objects...
* It is called by CM.Cache.CachePP()
*/
CM.Cache.CacheBuildingsPP = function() {
CM.Cache.min = -1;
CM.Cache.max = -1;
CM.Cache.mid = -1;
CM.Cache.min = Infinity;
CM.Cache.max = 1;
// Calculate PP and colors when compared to purchase of optimal building in single-purchase mode
if (CM.Options.ColorPPBulkMode === 0) {
for (let i of Object.keys(CM.Cache.Objects1)) {
if (Game.cookiesPs) {
CM.Cache.Objects1[i].pp = (Math.max(Game.Objects[i].getPrice() - (Game.cookies + CM.Disp.GetWrinkConfigBank()), 0) / Game.cookiesPs) + (Game.Objects[i].getPrice() / CM.Cache.Objects1[i].bonus);
} else CM.Cache.Objects1[i].pp = (Game.Objects[i].getPrice() / CM.Cache.Objects1[i].bonus);
if (CM.Cache.min === -1 || CM.Cache.Objects1[i].pp < CM.Cache.min) CM.Cache.min = CM.Cache.Objects1[i].pp;
if (CM.Cache.max === -1 || CM.Cache.Objects1[i].pp > CM.Cache.max) CM.Cache.max = CM.Cache.Objects1[i].pp;
if (CM.Cache.Objects1[i].pp < CM.Cache.min) CM.Cache.min = CM.Cache.Objects1[i].pp;
if (CM.Cache.Objects1[i].pp > CM.Cache.max) CM.Cache.max = CM.Cache.Objects1[i].pp;
}
CM.Cache.mid = ((CM.Cache.max - CM.Cache.min) / 2) + CM.Cache.min;
for (let i of Object.keys(CM.Cache.Objects1)) {
let color = '';
if (CM.Cache.Objects1[i].pp === CM.Cache.min) color = CM.Disp.colorGreen;
else if (CM.Cache.Objects1[i].pp === CM.Cache.max) color = CM.Disp.colorRed;
else if (CM.Cache.Objects1[i].pp > CM.Cache.mid) color = CM.Disp.colorOrange;
else color = CM.Disp.colorYellow;
CM.Cache.Objects1[i].color = color;
CM.Cache.Objects1[i].color = CM.Cache.ColourOfPP(CM.Cache.Objects1[i], Game.Objects[i].getPrice());
}
// Calculate PP of bulk-buy modes
CM.Cache.CacheBuildingsBulkPP('Objects10');
@@ -691,12 +711,7 @@ CM.Cache.CacheBuildingsPP = function() {
}
CM.Cache.mid = ((CM.Cache.max - CM.Cache.min) / 2) + CM.Cache.min;
for (let i of Object.keys(CM.Cache.Objects1)) {
let color = '';
if (CM.Cache[target][i].pp === CM.Cache.min) color = CM.Disp.colorGreen;
else if (CM.Cache[target][i].pp === CM.Cache.max) color = CM.Disp.colorRed;
else if (CM.Cache[target][i].pp > CM.Cache.mid) color = CM.Disp.colorOrange;
else color = CM.Disp.colorYellow;
CM.Cache[target][i].color = color;
CM.Cache[target][i].color = CM.Cache.ColourOfPP(CM.Cache[target][i], Game.Objects[i].bulkPrice);
}
}
};
@@ -712,15 +727,7 @@ CM.Cache.CacheBuildingsBulkPP = function(target) {
CM.Cache[target][i].pp = (Math.max(CM.Cache[target][i].price - (Game.cookies + CM.Disp.GetWrinkConfigBank()), 0) / Game.cookiesPs) + (CM.Cache[target][i].price / CM.Cache[target][i].bonus);
} else CM.Cache[target][i].pp = (CM.Cache[target][i].price / CM.Cache[target][i].bonus);
let color = '';
if (CM.Cache[target][i].pp <= 0 || CM.Cache[target][i].pp === Infinity) color = CM.Disp.colorGray;
else if (CM.Cache[target][i].pp < CM.Cache.min) color = CM.Disp.colorBlue;
else if (CM.Cache[target][i].pp === CM.Cache.min) color = CM.Disp.colorGreen;
else if (CM.Cache[target][i].pp === CM.Cache.max) color = CM.Disp.colorRed;
else if (CM.Cache[target][i].pp > CM.Cache.max) color = CM.Disp.colorPurple;
else if (CM.Cache[target][i].pp > CM.Cache.mid) color = CM.Disp.colorOrange;
else color = CM.Disp.colorYellow;
CM.Cache[target][i].color = color;
CM.Cache[target][i].color = CM.Cache.ColourOfPP(CM.Cache[target][i], CM.Cache[target][i].price);
}
};
@@ -734,15 +741,8 @@ CM.Cache.CacheUpgradePP = function() {
CM.Cache.Upgrades[i].pp = (Math.max(Game.Upgrades[i].getPrice() - (Game.cookies + CM.Disp.GetWrinkConfigBank()), 0) / Game.cookiesPs) + (Game.Upgrades[i].getPrice() / CM.Cache.Upgrades[i].bonus);
} else CM.Cache.Upgrades[i].pp = (Game.Upgrades[i].getPrice() / CM.Cache.Upgrades[i].bonus);
if (isNaN(CM.Cache.Upgrades[i].pp)) CM.Cache.Upgrades[i].pp = Infinity;
let color = '';
if (CM.Cache.Upgrades[i].pp <= 0 || CM.Cache.Upgrades[i].pp === Infinity) color = CM.Disp.colorGray;
else if (CM.Cache.Upgrades[i].pp < CM.Cache.min) color = CM.Disp.colorBlue;
else if (CM.Cache.Upgrades[i].pp === CM.Cache.min) color = CM.Disp.colorGreen;
else if (CM.Cache.Upgrades[i].pp === CM.Cache.max) color = CM.Disp.colorRed;
else if (CM.Cache.Upgrades[i].pp > CM.Cache.max) color = CM.Disp.colorPurple;
else if (CM.Cache.Upgrades[i].pp > CM.Cache.mid) color = CM.Disp.colorOrange;
else color = CM.Disp.colorYellow;
CM.Cache.Upgrades[i].color = color;
CM.Cache.Upgrades[i].color = CM.Cache.ColourOfPP(CM.Cache.Upgrades[i], Game.Upgrades[i].getPrice());
}
};

View File

@@ -125,7 +125,6 @@ CM.Data.Config.SortBuildings = {type: 'bool', group: 'BarsColors', label: ['Sort
CM.Data.Config.SortUpgrades = {type: 'bool', group: 'BarsColors', label: ['Sort Upgrades: Default', 'Sort Upgrades: PP'], desc: 'Sort the display of upgrades in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateUpgrades();}};
CM.Data.Config.BuildColor = {type: 'bool', group: 'BarsColors', label: ['Building Colors OFF', 'Building Colors ON'], desc: 'Color code buildings', toggle: true, func: function() {CM.Disp.UpdateBuildings();}};
CM.Data.Config.BulkBuildColor = {type: 'bool', group: 'BarsColors', label: ['Bulk Building Colors (Single Building Color)', 'Bulk Building Colors (Calculated Bulk Color)'], desc: 'Color code bulk buildings based on single buildings color or calculated bulk value color', toggle: false, func: function() {CM.Disp.UpdateBuildings();}};
CM.Data.Config.ColorPPBulkMode = {type: 'bool', group: 'BarsColors', label: ['Color of PP (Compared to Single)', 'Color of PP (Compared to Bulk)'], desc: 'Color PP-values based on comparison with single purchase or with selected bulk-buy mode', toggle: false};
CM.Data.Config.UpBarColor = {type: 'bool', group: 'BarsColors', label: ['Upgrade Colors/Bar OFF', 'Upgrade Colors with Bar ON', 'Upgrade Colors without Bar ON'], desc: 'Color code upgrades and optionally add a counter bar', toggle: false, func: function() {CM.Disp.ToggleUpgradeBarAndColor();}};
CM.Data.Config.Colors = { type: 'color', group: 'BarsColors',
desc: {
@@ -148,6 +147,9 @@ CM.Data.Config.CalcWrink = {type: 'bool', group: 'Calculation', label: ['Calcula
CM.Data.Config.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.Data.Config.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.Data.Config.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};
CM.Data.Config.ColorPPBulkMode = {type: 'bool', group: 'Calculation', label: ['Color of PP (Compared to Single)', 'Color of PP (Compared to Bulk)'], desc: 'Color PP-values based on comparison with single purchase or with selected bulk-buy mode', toggle: false};
CM.Data.Config.PPExcludeTop = {type: 'bool', group: 'Calculation', label: ["Don't Ignore Any", 'Ignore 1st Best', 'Ignore 1st and 2nd Best', 'Ignore 1st, 2nd and 3rd Best'], desc: 'Makes CookieMonster ignore the 1st, 2nd or 3rd best buildings in labeling and colouring PP values', toggle: true};
CM.Data.Config.PPSecondsLowerLimit = {type: 'numscale', group: 'Calculation', label: 'Lower limit for PP (in seconds): ', desc: 'If a building or upgrade costs less than the specified seconds of CPS it will also be considered optimal and label it as such ("PP is less than xx seconds of CPS"); setting to 0 ignores this option', min: 0, max: Infinity};
CM.Data.Config.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true};
// Notification
@@ -259,13 +261,15 @@ CM.Data.ConfigDefault = {
TimerBarOverlay: 2,
BuildColor: 1,
BulkBuildColor: 0,
ColorPPBulkMode: 0,
UpBarColor: 1,
UpgradeBarFixedPos: 1,
CalcWrink: 0,
CPSMode: 1,
AvgCPSHist: 3,
AvgClicksHist: 0,
ColorPPBulkMode: 0,
PPExcludeTop: 0,
PPSecondsLowerLimit: 0,
ToolWarnBon: 0,
Title: 1,
GeneralSound: 1,

View File

@@ -748,8 +748,8 @@ CM.Disp.UpdateBuildings = function() {
return o;
});
arr.sort(function(a, b){ return (a.pp > b.pp ? 1 : (a.pp < b.pp ? -1 : 0)); });
arr.sort(function(a, b){ return (CM.Disp.colors.indexOf(a.color) > CM.Disp.colors.indexOf(b.color) ? 1 : (CM.Disp.colors.indexOf(a.color) < CM.Disp.colors.indexOf(b.color) ? -1 : 0)); });
for (let x = 0; x < arr.length; x++) {
Game.Objects[arr[x].name].l.style.gridRow = (x + 2) + "/" + (x + 2);
}
@@ -832,7 +832,7 @@ CM.Disp.UpdateUpgrades = function() {
}
if (CM.Options.SortUpgrades) {
arr.sort((a, b) => a.pp - b.pp);
arr.sort((a, b) => CM.Disp.colors.indexOf(a.color) - CM.Disp.colors.indexOf(b.color));
}
else {
arr.sort((a, b) => a.price - b.price);