diff --git a/src/Constants.ts b/src/Constants.ts index acae9491a..ef2b82333 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -240,6 +240,7 @@ export let CONSTANTS: IMap = { * getAugmentationStats is a new netscript function that returns the stats of an augmentation. * getCharacterInformation now additionally returns exp + * pid resets back to 1 when installing or destroying a BitNode. Misc. * Fixed an issue where SF3 was listed as infinitly repeatable and SF12 as diff --git a/src/Netscript/Pid.ts b/src/Netscript/Pid.ts new file mode 100644 index 000000000..06883adf1 --- /dev/null +++ b/src/Netscript/Pid.ts @@ -0,0 +1,42 @@ +import { workerScripts } from "./WorkerScripts"; + +let pidCounter = 1; + +/** + * Find and return the next availble PID for a script + */ +export function generateNextPid(): number { + let tempCounter = pidCounter; + + // Cap the number of search iterations at some arbitrary value to avoid + // infinite loops. We'll assume that players wont have 1mil+ running scripts + let found = false; + for (let i = 0; i < 1e6;) { + if (!workerScripts.has(tempCounter + i)) { + found = true; + tempCounter = tempCounter + i; + break; + } + + if (i === Number.MAX_SAFE_INTEGER - 1) { + i = 1; + } else { + ++i; + } + } + + if (found) { + pidCounter = tempCounter + 1; + if (pidCounter >= Number.MAX_SAFE_INTEGER) { + pidCounter = 1; + } + + return tempCounter; + } else { + return -1; + } +} + +export function resetPidCounter(): void { + pidCounter = 1; +} \ No newline at end of file diff --git a/src/NetscriptWorker.js b/src/NetscriptWorker.js index a372f4906..32c6d8700 100644 --- a/src/NetscriptWorker.js +++ b/src/NetscriptWorker.js @@ -6,6 +6,7 @@ import { killWorkerScript } from "./Netscript/killWorkerScript"; import { WorkerScript } from "./Netscript/WorkerScript"; import { workerScripts } from "./Netscript/WorkerScripts"; import { WorkerScriptStartStopEventEmitter } from "./Netscript/WorkerScriptStartStopEventEmitter"; +import { generateNextPid } from "./Netscript/Pid"; import { CONSTANTS } from "./Constants"; import { Engine } from "./engine"; @@ -412,42 +413,6 @@ function processNetscript1Imports(code, workerScript) { return res; } -/** - * Find and return the next availble PID for a script - */ -let pidCounter = 1; -function generateNextPid() { - let tempCounter = pidCounter; - - // Cap the number of search iterations at some arbitrary value to avoid - // infinite loops. We'll assume that players wont have 1mil+ running scripts - let found = false; - for (let i = 0; i < 1e6;) { - if (!workerScripts.has(tempCounter + i)) { - found = true; - tempCounter = tempCounter + i; - break; - } - - if (i === Number.MAX_SAFE_INTEGER - 1) { - i = 1; - } else { - ++i; - } - } - - if (found) { - pidCounter = tempCounter + 1; - if (pidCounter >= Number.MAX_SAFE_INTEGER) { - pidCounter = 1; - } - - return tempCounter; - } else { - return -1; - } -} - /** * Used to start a RunningScript (by creating and starting its * corresponding WorkerScript), and add the RunningScript to the server on which diff --git a/src/Prestige.js b/src/Prestige.js index ae875e366..3fdc63b85 100755 --- a/src/Prestige.js +++ b/src/Prestige.js @@ -20,6 +20,7 @@ import { Message } from "./Message/Message"; import { initMessages, Messages } from "./Message/MessageHelpers"; import { prestigeWorkerScripts } from "./NetscriptWorker"; import { Player } from "./Player"; +import { resetPidCounter } from "./Netscript/Pid"; import { AllServers, @@ -172,6 +173,8 @@ function prestigeAugmentation() { DaedalusServer.serversOnNetwork.push(WorldDaemon.ip); } } + + resetPidCounter(); } @@ -346,6 +349,8 @@ function prestigeSourceFile() { // Gain int exp Player.gainIntelligenceExp(5); + + resetPidCounter(); } export {prestigeAugmentation, prestigeSourceFile};