mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-02 13:57:05 +02:00
fix sleeve memory bug
This commit is contained in:
@@ -36,12 +36,8 @@ export function AddToAllServers(server: Server | HacknetServer): void {
|
||||
const serverIp = server.ip;
|
||||
if (ipExists(serverIp)) {
|
||||
console.warn(`IP of server that's being added: ${serverIp}`);
|
||||
console.warn(
|
||||
`Hostname of the server thats being added: ${server.hostname}`,
|
||||
);
|
||||
console.warn(
|
||||
`The server that already has this IP is: ${AllServers[serverIp].hostname}`,
|
||||
);
|
||||
console.warn(`Hostname of the server thats being added: ${server.hostname}`);
|
||||
console.warn(`The server that already has this IP is: ${AllServers[serverIp].hostname}`);
|
||||
throw new Error("Error: Trying to add a server with an existing IP");
|
||||
}
|
||||
|
||||
@@ -85,9 +81,7 @@ export function initForeignServers(homeComputer: Server): void {
|
||||
case "object":
|
||||
return getRandomInt(value.min, value.max);
|
||||
default:
|
||||
throw Error(
|
||||
`Do not know how to convert the type '${typeof value}' to a number`,
|
||||
);
|
||||
throw Error(`Do not know how to convert the type '${typeof value}' to a number`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -132,10 +126,7 @@ export function initForeignServers(homeComputer: Server): void {
|
||||
|
||||
const getRandomArrayItem = (arr: any[]): any => arr[Math.floor(Math.random() * arr.length)];
|
||||
|
||||
const linkNetworkLayers = (
|
||||
network1: Server[],
|
||||
selectServer: () => Server,
|
||||
): void => {
|
||||
const linkNetworkLayers = (network1: Server[], selectServer: () => Server): void => {
|
||||
for (const server of network1) {
|
||||
linkComputers(server, selectServer());
|
||||
}
|
||||
@@ -144,8 +135,7 @@ export function initForeignServers(homeComputer: Server): void {
|
||||
// Connect the first tier of servers to the player's home computer
|
||||
linkNetworkLayers(networkLayers[0], () => homeComputer);
|
||||
for (let i = 1; i < networkLayers.length; i++) {
|
||||
linkNetworkLayers(networkLayers[i], () => getRandomArrayItem(networkLayers[i - 1]),
|
||||
);
|
||||
linkNetworkLayers(networkLayers[i], () => getRandomArrayItem(networkLayers[i - 1]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,20 +95,15 @@ export class BaseServer {
|
||||
// Text files on this server
|
||||
textFiles: TextFile[] = [];
|
||||
|
||||
constructor(
|
||||
params: IConstructorParams = { hostname: "", ip: createRandomIp() },
|
||||
) {
|
||||
constructor(params: IConstructorParams = { hostname: "", ip: createRandomIp() }) {
|
||||
this.ip = params.ip ? params.ip : createRandomIp();
|
||||
|
||||
this.hostname = params.hostname;
|
||||
this.organizationName =
|
||||
params.organizationName != null ? params.organizationName : "";
|
||||
this.isConnectedTo =
|
||||
params.isConnectedTo != null ? params.isConnectedTo : false;
|
||||
this.organizationName = params.organizationName != null ? params.organizationName : "";
|
||||
this.isConnectedTo = params.isConnectedTo != null ? params.isConnectedTo : false;
|
||||
|
||||
//Access information
|
||||
this.hasAdminRights =
|
||||
params.adminRights != null ? params.adminRights : false;
|
||||
this.hasAdminRights = params.adminRights != null ? params.adminRights : false;
|
||||
}
|
||||
|
||||
addContract(contract: CodingContract): void {
|
||||
@@ -131,10 +126,7 @@ export class BaseServer {
|
||||
* @returns RunningScript for the specified active script
|
||||
* Returns null if no such script can be found
|
||||
*/
|
||||
getRunningScript(
|
||||
scriptName: string,
|
||||
scriptArgs: any[],
|
||||
): RunningScript | null {
|
||||
getRunningScript(scriptName: string, scriptArgs: any[]): RunningScript | null {
|
||||
for (const rs of this.runningScripts) {
|
||||
if (rs.filename === scriptName && compareArrays(rs.args, scriptArgs)) {
|
||||
return rs;
|
||||
@@ -189,10 +181,7 @@ export class BaseServer {
|
||||
* @returns {IReturnStatus} Return status object indicating whether or not file was deleted
|
||||
*/
|
||||
removeFile(fn: string): IReturnStatus {
|
||||
if (
|
||||
fn.endsWith(".exe") ||
|
||||
fn.match(/^.+\.exe-\d+(?:\.\d*)?%-INC$/) != null
|
||||
) {
|
||||
if (fn.endsWith(".exe") || fn.match(/^.+\.exe-\d+(?:\.\d*)?%-INC$/) != null) {
|
||||
for (let i = 0; i < this.programs.length; ++i) {
|
||||
if (this.programs[i] === fn) {
|
||||
this.programs.splice(i, 1);
|
||||
|
||||
+8
-22
@@ -5,11 +5,7 @@ import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
||||
|
||||
import { createRandomString } from "../utils/helpers/createRandomString";
|
||||
import { createRandomIp } from "../../utils/IPAddress";
|
||||
import {
|
||||
Generic_fromJSON,
|
||||
Generic_toJSON,
|
||||
Reviver,
|
||||
} from "../../utils/JSONReviver";
|
||||
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../utils/JSONReviver";
|
||||
|
||||
export interface IConstructorParams {
|
||||
adminRights?: boolean;
|
||||
@@ -62,9 +58,7 @@ export class Server extends BaseServer {
|
||||
// be increased using the grow() Netscript function
|
||||
serverGrowth = 1;
|
||||
|
||||
constructor(
|
||||
params: IConstructorParams = { hostname: "", ip: createRandomIp() },
|
||||
) {
|
||||
constructor(params: IConstructorParams = { hostname: "", ip: createRandomIp() }) {
|
||||
super(params);
|
||||
|
||||
// "hacknet-node-X" hostnames are reserved for Hacknet Servers
|
||||
@@ -72,34 +66,26 @@ export class Server extends BaseServer {
|
||||
this.hostname = createRandomString(10);
|
||||
}
|
||||
|
||||
this.purchasedByPlayer =
|
||||
params.purchasedByPlayer != null ? params.purchasedByPlayer : false;
|
||||
this.purchasedByPlayer = params.purchasedByPlayer != null ? params.purchasedByPlayer : false;
|
||||
|
||||
//RAM, CPU speed and Scripts
|
||||
this.maxRam = params.maxRam != null ? params.maxRam : 0; //GB
|
||||
|
||||
/* Hacking information (only valid for "foreign" aka non-purchased servers) */
|
||||
this.requiredHackingSkill =
|
||||
params.requiredHackingSkill != null ? params.requiredHackingSkill : 1;
|
||||
this.requiredHackingSkill = params.requiredHackingSkill != null ? params.requiredHackingSkill : 1;
|
||||
this.moneyAvailable =
|
||||
params.moneyAvailable != null
|
||||
? params.moneyAvailable * BitNodeMultipliers.ServerStartingMoney
|
||||
: 0;
|
||||
this.moneyMax =
|
||||
25 * this.moneyAvailable * BitNodeMultipliers.ServerMaxMoney;
|
||||
params.moneyAvailable != null ? params.moneyAvailable * BitNodeMultipliers.ServerStartingMoney : 0;
|
||||
this.moneyMax = 25 * this.moneyAvailable * BitNodeMultipliers.ServerMaxMoney;
|
||||
|
||||
//Hack Difficulty is synonymous with server security. Base Difficulty = Starting difficulty
|
||||
this.hackDifficulty =
|
||||
params.hackDifficulty != null
|
||||
? params.hackDifficulty * BitNodeMultipliers.ServerStartingSecurity
|
||||
: 1;
|
||||
params.hackDifficulty != null ? params.hackDifficulty * BitNodeMultipliers.ServerStartingSecurity : 1;
|
||||
this.baseDifficulty = this.hackDifficulty;
|
||||
this.minDifficulty = Math.max(1, Math.round(this.hackDifficulty / 3));
|
||||
this.serverGrowth = params.serverGrowth != null ? params.serverGrowth : 1; //Integer from 0 to 100. Affects money increase from grow()
|
||||
|
||||
//Port information, required for porthacking servers to get admin rights
|
||||
this.numOpenPortsRequired =
|
||||
params.numOpenPortsRequired != null ? params.numOpenPortsRequired : 5;
|
||||
this.numOpenPortsRequired = params.numOpenPortsRequired != null ? params.numOpenPortsRequired : 5;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,13 +44,8 @@ export function safetlyCreateUniqueServer(params: IConstructorParams): Server {
|
||||
* @param p - Reference to Player object
|
||||
* @returns Number of "growth cycles" needed
|
||||
*/
|
||||
export function numCycleForGrowth(
|
||||
server: Server,
|
||||
growth: number,
|
||||
p: IPlayer,
|
||||
): number {
|
||||
let ajdGrowthRate =
|
||||
1 + (CONSTANTS.ServerBaseGrowthRate - 1) / server.hackDifficulty;
|
||||
export function numCycleForGrowth(server: Server, growth: number, p: IPlayer): number {
|
||||
let ajdGrowthRate = 1 + (CONSTANTS.ServerBaseGrowthRate - 1) / server.hackDifficulty;
|
||||
if (ajdGrowthRate > CONSTANTS.ServerMaxGrowthRate) {
|
||||
ajdGrowthRate = CONSTANTS.ServerMaxGrowthRate;
|
||||
}
|
||||
@@ -59,21 +54,13 @@ export function numCycleForGrowth(
|
||||
|
||||
const cycles =
|
||||
Math.log(growth) /
|
||||
(Math.log(ajdGrowthRate) *
|
||||
p.hacking_grow_mult *
|
||||
serverGrowthPercentage *
|
||||
BitNodeMultipliers.ServerGrowthRate);
|
||||
(Math.log(ajdGrowthRate) * p.hacking_grow_mult * serverGrowthPercentage * BitNodeMultipliers.ServerGrowthRate);
|
||||
|
||||
return cycles;
|
||||
}
|
||||
|
||||
//Applied server growth for a single server. Returns the percentage growth
|
||||
export function processSingleServerGrowth(
|
||||
server: Server,
|
||||
threads: number,
|
||||
p: IPlayer,
|
||||
cores = 1,
|
||||
): number {
|
||||
export function processSingleServerGrowth(server: Server, threads: number, p: IPlayer, cores = 1): number {
|
||||
let serverGrowth = calculateServerGrowth(server, threads, p, cores);
|
||||
if (serverGrowth < 1) {
|
||||
console.warn("serverGrowth calculated to be less than 1");
|
||||
@@ -89,21 +76,14 @@ export function processSingleServerGrowth(
|
||||
}
|
||||
|
||||
// cap at max
|
||||
if (
|
||||
isValidNumber(server.moneyMax) &&
|
||||
server.moneyAvailable > server.moneyMax
|
||||
) {
|
||||
if (isValidNumber(server.moneyMax) && server.moneyAvailable > server.moneyMax) {
|
||||
server.moneyAvailable = server.moneyMax;
|
||||
}
|
||||
|
||||
// if there was any growth at all, increase security
|
||||
if (oldMoneyAvailable !== server.moneyAvailable) {
|
||||
//Growing increases server security twice as much as hacking
|
||||
let usedCycles = numCycleForGrowth(
|
||||
server,
|
||||
server.moneyAvailable / oldMoneyAvailable,
|
||||
p,
|
||||
);
|
||||
let usedCycles = numCycleForGrowth(server, server.moneyAvailable / oldMoneyAvailable, p);
|
||||
usedCycles = Math.max(0, usedCycles);
|
||||
server.fortify(2 * CONSTANTS.ServerFortifyAmount * Math.ceil(usedCycles));
|
||||
}
|
||||
@@ -134,9 +114,7 @@ export function prestigeHomeComputer(homeComp: Server): void {
|
||||
|
||||
//Returns server object with corresponding hostname
|
||||
// Relatively slow, would rather not use this a lot
|
||||
export function GetServerByHostname(
|
||||
hostname: string,
|
||||
): Server | HacknetServer | null {
|
||||
export function GetServerByHostname(hostname: string): Server | HacknetServer | null {
|
||||
for (const ip in AllServers) {
|
||||
if (AllServers.hasOwnProperty(ip)) {
|
||||
if (AllServers[ip].hostname == hostname) {
|
||||
@@ -163,10 +141,7 @@ export function getServer(s: string): Server | HacknetServer | null {
|
||||
// Returns the i-th server on the specified server's network
|
||||
// A Server's serverOnNetwork property holds only the IPs. This function returns
|
||||
// the actual Server object
|
||||
export function getServerOnNetwork(
|
||||
server: Server,
|
||||
i: number,
|
||||
): Server | HacknetServer | null {
|
||||
export function getServerOnNetwork(server: Server, i: number): Server | HacknetServer | null {
|
||||
if (i > server.serversOnNetwork.length) {
|
||||
console.error("Tried to get server on network that was out of range");
|
||||
return null;
|
||||
|
||||
@@ -29,23 +29,15 @@ export function getPurchaseServerCost(ram: number): number {
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
return (
|
||||
sanitizedRam *
|
||||
CONSTANTS.BaseCostFor1GBOfRamServer *
|
||||
BitNodeMultipliers.PurchasedServerCost
|
||||
);
|
||||
return sanitizedRam * CONSTANTS.BaseCostFor1GBOfRamServer * BitNodeMultipliers.PurchasedServerCost;
|
||||
}
|
||||
|
||||
export function getPurchaseServerLimit(): number {
|
||||
return Math.round(
|
||||
CONSTANTS.PurchasedServerLimit * BitNodeMultipliers.PurchasedServerLimit,
|
||||
);
|
||||
return Math.round(CONSTANTS.PurchasedServerLimit * BitNodeMultipliers.PurchasedServerLimit);
|
||||
}
|
||||
|
||||
export function getPurchaseServerMaxRam(): number {
|
||||
const ram = Math.round(
|
||||
CONSTANTS.PurchasedServerMaxRam * BitNodeMultipliers.PurchasedServerMaxRam,
|
||||
);
|
||||
const ram = Math.round(CONSTANTS.PurchasedServerMaxRam * BitNodeMultipliers.PurchasedServerMaxRam);
|
||||
|
||||
// Round this to the nearest power of 2
|
||||
return 1 << (31 - Math.clz32(ram));
|
||||
@@ -57,10 +49,7 @@ export function purchaseServer(ram: number, p: IPlayer): void {
|
||||
|
||||
//Check if player has enough money
|
||||
if (!p.canAfford(cost)) {
|
||||
dialogBoxCreate(
|
||||
"You don't have enough money to purchase this server!",
|
||||
false,
|
||||
);
|
||||
dialogBoxCreate("You don't have enough money to purchase this server!", false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -111,17 +100,13 @@ export function purchaseServer(ram: number, p: IPlayer): void {
|
||||
export function purchaseRamForHomeComputer(p: IPlayer): void {
|
||||
const cost = p.getUpgradeHomeRamCost();
|
||||
if (!p.canAfford(cost)) {
|
||||
dialogBoxCreate(
|
||||
"You do not have enough money to purchase additional RAM for your home computer",
|
||||
);
|
||||
dialogBoxCreate("You do not have enough money to purchase additional RAM for your home computer");
|
||||
return;
|
||||
}
|
||||
|
||||
const homeComputer = p.getHomeComputer();
|
||||
if (homeComputer.maxRam >= CONSTANTS.HomeComputerMaxRam) {
|
||||
dialogBoxCreate(
|
||||
`You cannot upgrade your home computer RAM because it is at its maximum possible value`,
|
||||
);
|
||||
dialogBoxCreate(`You cannot upgrade your home computer RAM because it is at its maximum possible value`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { IMap } from "../types";
|
||||
import {
|
||||
Reviver,
|
||||
Generic_toJSON,
|
||||
Generic_fromJSON,
|
||||
} from "../../utils/JSONReviver";
|
||||
import { Reviver, Generic_toJSON, Generic_fromJSON } from "../../utils/JSONReviver";
|
||||
|
||||
/* Holds IP of Special Servers */
|
||||
export const SpecialServerNames: IMap<string> = {
|
||||
|
||||
@@ -211,10 +211,7 @@ export const serverMetadata: IServerMetadata[] = [
|
||||
min: 90,
|
||||
},
|
||||
hostname: "omnitek",
|
||||
literature: [
|
||||
LiteratureNames.CodedIntelligence,
|
||||
LiteratureNames.HistoryOfSynthoids,
|
||||
],
|
||||
literature: [LiteratureNames.CodedIntelligence, LiteratureNames.HistoryOfSynthoids],
|
||||
maxRamExponent: {
|
||||
max: 9,
|
||||
min: 7,
|
||||
@@ -558,10 +555,7 @@ export const serverMetadata: IServerMetadata[] = [
|
||||
min: 70,
|
||||
},
|
||||
hostname: "taiyang-digital",
|
||||
literature: [
|
||||
LiteratureNames.AGreenTomorrow,
|
||||
LiteratureNames.BrighterThanTheSun,
|
||||
],
|
||||
literature: [LiteratureNames.AGreenTomorrow, LiteratureNames.BrighterThanTheSun],
|
||||
moneyAvailable: {
|
||||
max: 900000000,
|
||||
min: 800000000,
|
||||
@@ -704,10 +698,7 @@ export const serverMetadata: IServerMetadata[] = [
|
||||
min: 70,
|
||||
},
|
||||
hostname: "solaris",
|
||||
literature: [
|
||||
LiteratureNames.AGreenTomorrow,
|
||||
LiteratureNames.TheFailedFrontier,
|
||||
],
|
||||
literature: [LiteratureNames.AGreenTomorrow, LiteratureNames.TheFailedFrontier],
|
||||
maxRamExponent: {
|
||||
max: 7,
|
||||
min: 4,
|
||||
@@ -1025,11 +1016,7 @@ export const serverMetadata: IServerMetadata[] = [
|
||||
min: 45,
|
||||
},
|
||||
hostname: "summit-uni",
|
||||
literature: [
|
||||
LiteratureNames.SecretSocieties,
|
||||
LiteratureNames.TheFailedFrontier,
|
||||
LiteratureNames.SyntheticMuscles,
|
||||
],
|
||||
literature: [LiteratureNames.SecretSocieties, LiteratureNames.TheFailedFrontier, LiteratureNames.SyntheticMuscles],
|
||||
maxRamExponent: {
|
||||
max: 6,
|
||||
min: 4,
|
||||
|
||||
@@ -3,12 +3,7 @@ import { Server } from "../Server";
|
||||
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
|
||||
import { IPlayer } from "../../PersonObjects/IPlayer";
|
||||
|
||||
export function calculateServerGrowth(
|
||||
server: Server,
|
||||
threads: number,
|
||||
p: IPlayer,
|
||||
cores = 1,
|
||||
): number {
|
||||
export function calculateServerGrowth(server: Server, threads: number, p: IPlayer, cores = 1): number {
|
||||
const numServerGrowthCycles = Math.max(Math.floor(threads), 0);
|
||||
|
||||
//Get adjusted growth rate, which accounts for server security
|
||||
@@ -21,14 +16,9 @@ export function calculateServerGrowth(
|
||||
//Calculate adjusted server growth rate based on parameters
|
||||
const serverGrowthPercentage = server.serverGrowth / 100;
|
||||
const numServerGrowthCyclesAdjusted =
|
||||
numServerGrowthCycles *
|
||||
serverGrowthPercentage *
|
||||
BitNodeMultipliers.ServerGrowthRate;
|
||||
numServerGrowthCycles * serverGrowthPercentage * BitNodeMultipliers.ServerGrowthRate;
|
||||
|
||||
//Apply serverGrowth for the calculated number of growth cycles
|
||||
const coreBonus = 1 + (cores - 1) / 16;
|
||||
return Math.pow(
|
||||
adjGrowthRate,
|
||||
numServerGrowthCyclesAdjusted * p.hacking_grow_mult * coreBonus,
|
||||
);
|
||||
return Math.pow(adjGrowthRate, numServerGrowthCyclesAdjusted * p.hacking_grow_mult * coreBonus);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user