Changed PP colour coding #683

This commit is contained in:
Daniël van Noord
2021-03-16 22:28:54 +01:00
parent e3d3f649c3
commit 6caee4d8fb
11 changed files with 106 additions and 158 deletions

View File

@@ -4,13 +4,11 @@ import { CMOptions } from '../../Config/VariablesAndData';
import GetWrinkConfigBank from '../../Disp/HelperFunctions/GetWrinkConfigBank';
import { ColorGray } from '../../Disp/VariablesAndData';
import {
CacheArrayOfPPs,
CacheMaxPP,
CacheMidPP,
CacheMinPP,
CacheObjects1,
CacheObjects10,
CacheObjects100,
CachePPArray,
} from '../VariablesAndData';
import ColourOfPP from './ColourOfPP';
@@ -19,16 +17,29 @@ import ColourOfPP from './ColourOfPP';
* It saves all date in CM.Cache.Objects...
* It is called by CM.Cache.CacheBuildingsPP()
*/
function CacheBuildingsBulkPP(target) {
function CacheColor(target, amount) {
Object.keys(target).forEach((i) => {
target[i].color = ColourOfPP(
target[i],
Game.Objects[i].getSumPrice(amount),
);
// Colour based on excluding certain top-buildings
for (let j = 0; j < CMOptions.PPExcludeTop; j++) {
if (target[i].pp === CachePPArray[j][0]) target[i].color = ColorGray;
}
});
}
function CachePP(target, amount) {
Object.keys(target).forEach((i) => {
const price = Game.Objects[i].getSumPrice(amount);
if (Game.cookiesPs) {
target[i].pp =
Math.max(target[i].price - (Game.cookies + GetWrinkConfigBank()), 0) /
Math.max(price - (Game.cookies + GetWrinkConfigBank()), 0) /
Game.cookiesPs +
target[i].price / target[i].bonus;
} else target[i].pp = target[i].price / target[i].bonus;
target[i].color = ColourOfPP(target[i], target[i].price);
price / target[i].bonus;
} else target[i].pp = price / target[i].bonus;
CachePPArray.push([target[i].pp, amount]);
});
}
@@ -38,91 +49,28 @@ function CacheBuildingsBulkPP(target) {
*/
export default function CacheBuildingsPP() {
CacheMinPP = Infinity;
CacheMaxPP = 1;
CacheArrayOfPPs = [];
CachePPArray = [];
if (typeof CMOptions.PPExcludeTop === 'undefined') CMOptions.PPExcludeTop = 0; // Otherwise breaks during initialization
// Calculate PP and colors when compared to purchase of optimal building in single-purchase mode
if (CMOptions.ColorPPBulkMode === 0 && Game.buyMode > 0) {
Object.keys(CacheObjects1).forEach((i) => {
if (Game.cookiesPs) {
CacheObjects1[i].pp =
Math.max(
Game.Objects[i].getPrice() - (Game.cookies + GetWrinkConfigBank()),
0,
) /
Game.cookiesPs +
Game.Objects[i].getPrice() / CacheObjects1[i].bonus;
} else
CacheObjects1[i].pp =
Game.Objects[i].getPrice() / CacheObjects1[i].bonus;
CacheArrayOfPPs.push([CacheObjects1[i].pp, Game.Objects[i].getPrice()]);
});
// Set CM.Cache.min to best non-excluded buidliung
CacheArrayOfPPs.sort((a, b) => a[0] - b[0]);
if (CMOptions.PPOnlyConsiderBuyable) {
while (CacheArrayOfPPs[0][1] > Game.cookies) {
if (CacheArrayOfPPs.length === 1) {
break;
}
CacheArrayOfPPs.shift();
}
}
CacheMinPP = CacheArrayOfPPs[CMOptions.PPExcludeTop][0];
CacheMaxPP = CacheArrayOfPPs[CacheArrayOfPPs.length - 1][0];
CacheMidPP = (CacheMaxPP - CacheMinPP) / 2 + CacheMinPP;
Object.keys(CacheObjects1).forEach((i) => {
CacheObjects1[i].color = ColourOfPP(
CacheObjects1[i],
Game.Objects[i].getPrice(),
);
// Colour based on excluding certain top-buildings
for (let j = 0; j < CMOptions.PPExcludeTop; j++) {
if (CacheObjects1[i].pp === CacheArrayOfPPs[j][0])
CacheObjects1[i].color = ColorGray;
}
});
// Calculate PP of bulk-buy modes
CacheBuildingsBulkPP(CacheObjects10);
CacheBuildingsBulkPP(CacheObjects100);
} else if (Game.buyMode > 0) {
// Calculate PP and colors when compared to purchase of selected bulk mode
let target;
if (Game.buyBulk === 1) target = CacheObjects1;
else if (Game.buyBulk === 10) target = CacheObjects10;
else if (Game.buyBulk === 100) target = CacheObjects100;
Object.keys(target).forEach((i) => {
if (Game.cookiesPs) {
target[i].pp =
Math.max(
Game.Objects[i].bulkPrice - (Game.cookies + GetWrinkConfigBank()),
0,
) /
Game.cookiesPs +
Game.Objects[i].bulkPrice / target[i].bonus;
} else target[i].pp = Game.Objects[i].bulkPrice / target[i].bonus;
CacheArrayOfPPs.push([target[i].pp, Game.Objects[i].bulkPrice]);
});
// Set CM.Cache.min to best non-excluded buidliung
CacheArrayOfPPs.sort((a, b) => a[0] - b[0]);
if (CMOptions.PPOnlyConsiderBuyable) {
while (CacheArrayOfPPs[0][1] > Game.cookies) {
if (CacheArrayOfPPs.length === 1) {
break;
}
CacheArrayOfPPs.shift();
}
}
CacheMinPP = CacheArrayOfPPs[CMOptions.PPExcludeTop][0];
CacheMaxPP = CacheArrayOfPPs[CacheArrayOfPPs.length - 1][0];
CacheMidPP = (CacheMaxPP - CacheMinPP) / 2 + CacheMinPP;
// Calculate PP and colors
CachePP(CacheObjects1, 1);
CachePP(CacheObjects10, 10);
CachePP(CacheObjects100, 100);
Object.keys(CacheObjects1).forEach((i) => {
target[i].color = ColourOfPP(target[i], Game.Objects[i].bulkPrice);
// Colour based on excluding certain top-buildings
for (let j = 0; j < CMOptions.PPExcludeTop; j++) {
if (target[i].pp === CacheArrayOfPPs[j][0]) target[i].color = ColorGray;
// Set CM.Cache.min to best non-excluded buidliung
CachePPArray.sort((a, b) => a[0] - b[0]);
let indexOfMin = 0;
if (CMOptions.PPOnlyConsiderBuyable) {
while (CachePPArray[indexOfMin][1] > Game.cookies) {
if (CachePPArray.length === indexOfMin - 1) {
break;
}
});
indexOfMin += 1;
}
}
CacheMinPP = CachePPArray[CMOptions.PPExcludeTop][indexOfMin];
CacheColor(CacheObjects1, 1);
CacheColor(CacheObjects10, 10);
CacheColor(CacheObjects100, 100);
}

View File

@@ -9,7 +9,7 @@ import {
ColorRed,
ColorYellow,
} from '../../Disp/VariablesAndData';
import { CacheMaxPP, CacheMidPP, CacheMinPP } from '../VariablesAndData';
import { CacheMinPP, CachePPArray } from '../VariablesAndData';
/**
* This functions return the colour assosciated with the given pp value
@@ -24,10 +24,10 @@ export default function ColourOfPP(me, price) {
if (me.pp <= 0 || me.pp === Infinity) color = ColorGray;
else if (me.pp < CacheMinPP) color = ColorBlue;
else if (me.pp === CacheMinPP) color = ColorGreen;
else if (me.pp === CacheMaxPP) color = ColorRed;
else if (me.pp > CacheMaxPP) color = ColorPurple;
else if (me.pp > CacheMidPP) color = ColorOrange;
else color = ColorYellow;
else if (me.pp < CachePPArray[10][0]) color = ColorYellow;
else if (me.pp < CachePPArray[20][0]) color = ColorOrange;
else if (me.pp > CachePPArray[30][0]) color = ColorRed;
else color = ColorPurple;
// Colour based on price in terms of CPS
if (Number(CMOptions.PPSecondsLowerLimit) !== 0) {

View File

@@ -65,10 +65,10 @@ export let CacheSeasonPopShimmer = {};
export let CacheTimeTillNextPrestige = 0;
/** Stores lowest PP value */
export let CacheMinPP = 0;
export let CacheMidPP = 0;
export let CacheMaxPP = 0;
export let CacheArrayOfPPs = [];
/** Stores all PP values of all buildings for all buy settings (1, 10, 100) */
export let CachePPArray = [];
export let CacheGoldenShimmersByID = {};
@@ -100,6 +100,7 @@ export let CacheDoRemakeBuildPrices;
export let CacheHadBuildAura;
/** Store the CPS effect of each god if it was put into each slot */
export let CacheGods = {
0: [0, 0, 0],
1: [0, 0, 0],