TYPESAFETY: Strict internal typing for AugmentationName (#608)

This commit is contained in:
Snarling
2023-06-16 17:52:42 -04:00
committed by GitHub
parent 12b5c00d14
commit a4b826683e
70 changed files with 2649 additions and 3221 deletions
+2 -2
View File
@@ -9,7 +9,7 @@ import { createRandomIp } from "../utils/IPAddress";
import { getRandomInt } from "../utils/helpers/getRandomInt";
import { Reviver } from "../utils/JSONReviver";
import { SpecialServers } from "./data/SpecialServers";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
import { IPAddress, isIPAddress } from "../Types/strings";
import "../Script/RunningScript"; // For reviver side-effect
@@ -159,7 +159,7 @@ export function initForeignServers(homeComputer: Server): void {
}
if (server.hostname === SpecialServers.WorldDaemon) {
server.requiredHackingSkill *= BitNodeMultipliers.WorldDaemonDifficulty;
server.requiredHackingSkill *= currentNodeMults.WorldDaemonDifficulty;
}
AddToAllServers(server);
if (metadata.networkLayer !== undefined) {
+5 -5
View File
@@ -1,7 +1,7 @@
// Class representing a single hackable Server
import { BaseServer } from "./BaseServer";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
import { createRandomString } from "../utils/helpers/createRandomString";
import { createRandomIp } from "../utils/IPAddress";
@@ -72,12 +72,12 @@ export class Server extends BaseServer {
/* Hacking information (only valid for "foreign" aka non-purchased servers) */
this.requiredHackingSkill = params.requiredHackingSkill != null ? params.requiredHackingSkill : 1;
const baseMoney = params.moneyAvailable ?? 0;
this.moneyAvailable = baseMoney * BitNodeMultipliers.ServerStartingMoney;
this.moneyMax = 25 * baseMoney * BitNodeMultipliers.ServerMaxMoney;
this.moneyAvailable = baseMoney * currentNodeMults.ServerStartingMoney;
this.moneyMax = 25 * baseMoney * currentNodeMults.ServerMaxMoney;
//Hack Difficulty is synonymous with server security. Base Difficulty = Starting difficulty
const realDifficulty =
params.hackDifficulty != null ? params.hackDifficulty * BitNodeMultipliers.ServerStartingSecurity : 1;
params.hackDifficulty != null ? params.hackDifficulty * currentNodeMults.ServerStartingSecurity : 1;
this.hackDifficulty = Math.min(realDifficulty, 100);
this.baseDifficulty = this.hackDifficulty;
this.minDifficulty = Math.min(Math.max(1, Math.round(realDifficulty / 3)), 100);
@@ -141,7 +141,7 @@ export class Server extends BaseServer {
/** Lowers the server's security level (difficulty) by the specified amount) */
weaken(amt: number): void {
this.hackDifficulty -= amt * BitNodeMultipliers.ServerWeakenRate;
this.hackDifficulty -= amt * currentNodeMults.ServerWeakenRate;
this.capDifficulty();
}
+3 -3
View File
@@ -3,7 +3,7 @@ import { Server, IConstructorParams } from "./Server";
import { BaseServer } from "./BaseServer";
import { calculateServerGrowth } from "./formulas/grow";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
import { CONSTANTS } from "../Constants";
import { Player } from "@player";
import { CompletedProgramName, LiteratureName } from "@enums";
@@ -66,7 +66,7 @@ export function numCycleForGrowth(server: IServer, growth: number, cores = 1): n
(Math.log(ajdGrowthRate) *
Player.mults.hacking_grow *
serverGrowthPercentage *
BitNodeMultipliers.ServerGrowthRate *
currentNodeMults.ServerGrowthRate *
coreBonus);
return cycles;
@@ -105,7 +105,7 @@ export function numCycleForGrowthCorrected(
const serverGrowthPercentage = server.serverGrowth / 100.0;
const coreMultiplier = 1 + (cores - 1) / 16;
const threadMultiplier =
serverGrowthPercentage * person.mults.hacking_grow * coreMultiplier * BitNodeMultipliers.ServerGrowthRate;
serverGrowthPercentage * person.mults.hacking_grow * coreMultiplier * currentNodeMults.ServerGrowthRate;
/* To understand what is done below we need to do some math. I hope the explanation is clear enough.
* First of, the names will be shortened for ease of manipulation:
+5 -5
View File
@@ -5,7 +5,7 @@
import { AddToAllServers, createUniqueRandomIp, GetServer, renameServer } from "./AllServers";
import { safelyCreateUniqueServer } from "./ServerHelpers";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
import { CONSTANTS } from "../Constants";
import { Player } from "@player";
@@ -34,8 +34,8 @@ export function getPurchaseServerCost(ram: number): number {
return (
sanitizedRam *
CONSTANTS.BaseCostFor1GBOfRamServer *
BitNodeMultipliers.PurchasedServerCost *
Math.pow(BitNodeMultipliers.PurchasedServerSoftcap, upg)
currentNodeMults.PurchasedServerCost *
Math.pow(currentNodeMults.PurchasedServerSoftcap, upg)
);
}
@@ -86,11 +86,11 @@ export const renamePurchasedServer = (hostname: string, newName: string): void =
};
export function getPurchaseServerLimit(): number {
return Math.round(CONSTANTS.PurchasedServerLimit * BitNodeMultipliers.PurchasedServerLimit);
return Math.round(CONSTANTS.PurchasedServerLimit * currentNodeMults.PurchasedServerLimit);
}
export function getPurchaseServerMaxRam(): number {
const ram = Math.round(CONSTANTS.PurchasedServerMaxRam * BitNodeMultipliers.PurchasedServerMaxRam);
const ram = Math.round(CONSTANTS.PurchasedServerMaxRam * currentNodeMults.PurchasedServerMaxRam);
// Round this to the nearest power of 2
return 1 << (31 - Math.clz32(ram));
+2 -2
View File
@@ -1,5 +1,5 @@
import { CONSTANTS } from "../../Constants";
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
import { currentNodeMults } from "../../BitNode/BitNodeMultipliers";
import { Person as IPerson, Server as IServer } from "@nsdefs";
export function calculateServerGrowth(server: IServer, threads: number, p: IPerson, cores = 1): number {
@@ -17,7 +17,7 @@ export function calculateServerGrowth(server: IServer, threads: number, p: IPers
//Calculate adjusted server growth rate based on parameters
const serverGrowthPercentage = server.serverGrowth / 100;
const numServerGrowthCyclesAdjusted =
numServerGrowthCycles * serverGrowthPercentage * BitNodeMultipliers.ServerGrowthRate;
numServerGrowthCycles * serverGrowthPercentage * currentNodeMults.ServerGrowthRate;
//Apply serverGrowth for the calculated number of growth cycles
const coreBonus = 1 + (cores - 1) / 16;