MISC: move server constants into their own constant (#1075)

This commit is contained in:
Caldwell
2024-02-10 10:13:42 +01:00
committed by GitHub
parent fd5b0f8241
commit 4d551915b3
13 changed files with 56 additions and 48 deletions
+6 -5
View File
@@ -6,7 +6,7 @@ import { AddToAllServers, createUniqueRandomIp, GetServer, renameServer } from "
import { safelyCreateUniqueServer } from "./ServerHelpers";
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
import { CONSTANTS } from "../Constants";
import { ServerConstants } from "./data/Constants";
import { Player } from "@player";
import { dialogBoxCreate } from "../ui/React/DialogBox";
@@ -20,6 +20,7 @@ import { workerScripts } from "../Netscript/WorkerScripts";
* @returns Cost of purchasing the given server. Returns infinity for invalid arguments
*/
export function getPurchaseServerCost(ram: number): number {
// TODO shift checks into
const sanitizedRam = Math.round(ram);
if (isNaN(sanitizedRam) || !isPowerOfTwo(sanitizedRam) || !(Math.sign(sanitizedRam) === 1)) {
return Infinity;
@@ -33,7 +34,7 @@ export function getPurchaseServerCost(ram: number): number {
return (
sanitizedRam *
CONSTANTS.BaseCostFor1GBOfRamServer *
ServerConstants.BaseCostFor1GBOfRamServer *
currentNodeMults.PurchasedServerCost *
Math.pow(currentNodeMults.PurchasedServerSoftcap, upg)
);
@@ -86,11 +87,11 @@ export const renamePurchasedServer = (hostname: string, newName: string): void =
};
export function getPurchaseServerLimit(): number {
return Math.round(CONSTANTS.PurchasedServerLimit * currentNodeMults.PurchasedServerLimit);
return Math.round(ServerConstants.PurchasedServerLimit * currentNodeMults.PurchasedServerLimit);
}
export function getPurchaseServerMaxRam(): number {
const ram = Math.round(CONSTANTS.PurchasedServerMaxRam * currentNodeMults.PurchasedServerMaxRam);
const ram = Math.round(ServerConstants.PurchasedServerMaxRam * currentNodeMults.PurchasedServerMaxRam);
// Round this to the nearest power of 2
return 1 << (31 - Math.clz32(ram));
@@ -155,7 +156,7 @@ export function purchaseRamForHomeComputer(): void {
}
const homeComputer = Player.getHomeComputer();
if (homeComputer.maxRam >= CONSTANTS.HomeComputerMaxRam) {
if (homeComputer.maxRam >= ServerConstants.HomeComputerMaxRam) {
dialogBoxCreate(`You cannot upgrade your home computer RAM because it is at its maximum possible value`);
return;
}