mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-25 07:32:27 +01:00
Create ports on demand. Increase max to infinity.
This commit is contained in:
parent
2592c6ccd8
commit
ec81fb60c3
@ -124,7 +124,7 @@ export const CONSTANTS: {
|
|||||||
// NeuroFlux Governor Augmentation cost multiplier
|
// NeuroFlux Governor Augmentation cost multiplier
|
||||||
NeuroFluxGovernorLevelMult: 1.14,
|
NeuroFluxGovernorLevelMult: 1.14,
|
||||||
|
|
||||||
NumNetscriptPorts: 20,
|
NumNetscriptPorts: Infinity,
|
||||||
|
|
||||||
// Server-related constants
|
// Server-related constants
|
||||||
HomeComputerMaxRam: 1073741824, // 2 ^ 30
|
HomeComputerMaxRam: 1073741824, // 2 ^ 30
|
||||||
|
@ -20,7 +20,7 @@ import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions
|
|||||||
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
||||||
import { CONSTANTS } from "../Constants";
|
import { CONSTANTS } from "../Constants";
|
||||||
import { influenceStockThroughServerHack } from "../StockMarket/PlayerInfluencing";
|
import { influenceStockThroughServerHack } from "../StockMarket/PlayerInfluencing";
|
||||||
import { IPort } from "../NetscriptPort";
|
import { IPort, NetscriptPort } from "../NetscriptPort";
|
||||||
import { NetscriptPorts } from "../NetscriptWorker";
|
import { NetscriptPorts } from "../NetscriptWorker";
|
||||||
import { IPlayer } from "../PersonObjects/IPlayer";
|
import { IPlayer } from "../PersonObjects/IPlayer";
|
||||||
import { FormulaGang } from "../Gang/formulas/formulas";
|
import { FormulaGang } from "../Gang/formulas/formulas";
|
||||||
@ -492,10 +492,16 @@ function getValidPort(ctx: NetscriptContext, port: number): IPort {
|
|||||||
`Trying to use an invalid port: ${port}. Only ports 1-${CONSTANTS.NumNetscriptPorts} are valid.`,
|
`Trying to use an invalid port: ${port}. Only ports 1-${CONSTANTS.NumNetscriptPorts} are valid.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const iport = NetscriptPorts[port - 1];
|
let iport = NetscriptPorts.get(port);
|
||||||
if (iport == null || !(iport instanceof Object)) {
|
if (iport == null || !(iport instanceof Object)) {
|
||||||
throw makeRuntimeErrorMsg(ctx, `Could not find port: ${port}. This is a bug. Report to dev.`);
|
NetscriptPorts.set(port, NetscriptPort());
|
||||||
}
|
}
|
||||||
|
// Try again.
|
||||||
|
iport = NetscriptPorts.get(port);
|
||||||
|
if (iport == null || !(iport instanceof Object)) {
|
||||||
|
throw helpers.makeRuntimeErrorMsg(ctx, `Could not find port: ${port}. This is a bug. Report to dev.`);
|
||||||
|
}
|
||||||
|
|
||||||
return iport;
|
return iport;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,7 +613,7 @@ function getRunningScriptByArgs(
|
|||||||
throw helpers.makeRuntimeRejectMsg(
|
throw helpers.makeRuntimeRejectMsg(
|
||||||
ctx.workerScript,
|
ctx.workerScript,
|
||||||
`Invalid scriptArgs argument passed into getRunningScript() from ${ctx.function}(). ` +
|
`Invalid scriptArgs argument passed into getRunningScript() from ${ctx.function}(). ` +
|
||||||
`This is probably a bug. Please report to game developer`,
|
`This is probably a bug. Please report to game developer`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ import { NetscriptCorporation } from "./NetscriptFunctions/Corporation";
|
|||||||
import { NetscriptFormulas } from "./NetscriptFunctions/Formulas";
|
import { NetscriptFormulas } from "./NetscriptFunctions/Formulas";
|
||||||
import { NetscriptStockMarket } from "./NetscriptFunctions/StockMarket";
|
import { NetscriptStockMarket } from "./NetscriptFunctions/StockMarket";
|
||||||
import { NetscriptGrafting } from "./NetscriptFunctions/Grafting";
|
import { NetscriptGrafting } from "./NetscriptFunctions/Grafting";
|
||||||
import { IPort } from "./NetscriptPort";
|
import { NetscriptPort, IPort } from "./NetscriptPort";
|
||||||
import {
|
import {
|
||||||
NS,
|
NS,
|
||||||
Player as INetscriptPlayer,
|
Player as INetscriptPlayer,
|
||||||
@ -1533,7 +1533,12 @@ const base: InternalAPI<NS> = {
|
|||||||
`Invalid port: ${port}. Only ports 1-${CONSTANTS.NumNetscriptPorts} are valid.`,
|
`Invalid port: ${port}. Only ports 1-${CONSTANTS.NumNetscriptPorts} are valid.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const iport = NetscriptPorts[port - 1];
|
let iport = NetscriptPorts.get(port);
|
||||||
|
if (iport == null || !(iport instanceof Object)) {
|
||||||
|
NetscriptPorts.set(port, NetscriptPort());
|
||||||
|
}
|
||||||
|
// Try again.
|
||||||
|
iport = NetscriptPorts.get(port);
|
||||||
if (iport == null || !(iport instanceof Object)) {
|
if (iport == null || !(iport instanceof Object)) {
|
||||||
throw helpers.makeRuntimeErrorMsg(ctx, `Could not find port: ${port}. This is a bug. Report to dev.`);
|
throw helpers.makeRuntimeErrorMsg(ctx, `Could not find port: ${port}. This is a bug. Report to dev.`);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import { CONSTANTS } from "./Constants";
|
|||||||
import { Interpreter } from "./ThirdParty/JSInterpreter";
|
import { Interpreter } from "./ThirdParty/JSInterpreter";
|
||||||
import { NetscriptFunctions } from "./NetscriptFunctions";
|
import { NetscriptFunctions } from "./NetscriptFunctions";
|
||||||
import { executeJSScript, Node } from "./NetscriptJSEvaluator";
|
import { executeJSScript, Node } from "./NetscriptJSEvaluator";
|
||||||
import { NetscriptPort, IPort } from "./NetscriptPort";
|
import { IPort } from "./NetscriptPort";
|
||||||
import { RunningScript } from "./Script/RunningScript";
|
import { RunningScript } from "./Script/RunningScript";
|
||||||
import { getRamUsageFromRunningScript } from "./Script/RunningScriptHelpers";
|
import { getRamUsageFromRunningScript } from "./Script/RunningScriptHelpers";
|
||||||
import { scriptCalculateOfflineProduction } from "./Script/ScriptHelpers";
|
import { scriptCalculateOfflineProduction } from "./Script/ScriptHelpers";
|
||||||
@ -38,17 +38,15 @@ import { ScriptArg } from "./Netscript/ScriptArg";
|
|||||||
import { helpers } from "./Netscript/NetscriptHelpers";
|
import { helpers } from "./Netscript/NetscriptHelpers";
|
||||||
|
|
||||||
// Netscript Ports are instantiated here
|
// Netscript Ports are instantiated here
|
||||||
export const NetscriptPorts: IPort[] = [];
|
export const NetscriptPorts: Map<number, IPort> = new Map();
|
||||||
for (let i = 0; i < CONSTANTS.NumNetscriptPorts; ++i) {
|
|
||||||
NetscriptPorts.push(NetscriptPort());
|
|
||||||
}
|
|
||||||
|
|
||||||
export function prestigeWorkerScripts(): void {
|
export function prestigeWorkerScripts(): void {
|
||||||
for (const ws of workerScripts.values()) {
|
for (const ws of workerScripts.values()) {
|
||||||
ws.env.stopFlag = true;
|
ws.env.stopFlag = true;
|
||||||
killWorkerScript(ws);
|
killWorkerScript(ws);
|
||||||
}
|
}
|
||||||
for (const port of NetscriptPorts) {
|
|
||||||
|
for (const [__, port] of NetscriptPorts.entries()) {
|
||||||
port.clear();
|
port.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user