mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-20 21:25:47 +01:00
Pid resets to 1 when installing or destroying a BitNode.
This commit is contained in:
parent
f9dcefd6ea
commit
bbe4f9c286
@ -240,6 +240,7 @@ export let CONSTANTS: IMap<any> = {
|
|||||||
* getAugmentationStats is a new netscript function that returns the stats of
|
* getAugmentationStats is a new netscript function that returns the stats of
|
||||||
an augmentation.
|
an augmentation.
|
||||||
* getCharacterInformation now additionally returns exp
|
* getCharacterInformation now additionally returns exp
|
||||||
|
* pid resets back to 1 when installing or destroying a BitNode.
|
||||||
|
|
||||||
Misc.
|
Misc.
|
||||||
* Fixed an issue where SF3 was listed as infinitly repeatable and SF12 as
|
* Fixed an issue where SF3 was listed as infinitly repeatable and SF12 as
|
||||||
|
42
src/Netscript/Pid.ts
Normal file
42
src/Netscript/Pid.ts
Normal file
@ -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;
|
||||||
|
}
|
@ -6,6 +6,7 @@ import { killWorkerScript } from "./Netscript/killWorkerScript";
|
|||||||
import { WorkerScript } from "./Netscript/WorkerScript";
|
import { WorkerScript } from "./Netscript/WorkerScript";
|
||||||
import { workerScripts } from "./Netscript/WorkerScripts";
|
import { workerScripts } from "./Netscript/WorkerScripts";
|
||||||
import { WorkerScriptStartStopEventEmitter } from "./Netscript/WorkerScriptStartStopEventEmitter";
|
import { WorkerScriptStartStopEventEmitter } from "./Netscript/WorkerScriptStartStopEventEmitter";
|
||||||
|
import { generateNextPid } from "./Netscript/Pid";
|
||||||
|
|
||||||
import { CONSTANTS } from "./Constants";
|
import { CONSTANTS } from "./Constants";
|
||||||
import { Engine } from "./engine";
|
import { Engine } from "./engine";
|
||||||
@ -412,42 +413,6 @@ function processNetscript1Imports(code, workerScript) {
|
|||||||
return res;
|
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
|
* Used to start a RunningScript (by creating and starting its
|
||||||
* corresponding WorkerScript), and add the RunningScript to the server on which
|
* corresponding WorkerScript), and add the RunningScript to the server on which
|
||||||
|
@ -20,6 +20,7 @@ import { Message } from "./Message/Message";
|
|||||||
import { initMessages, Messages } from "./Message/MessageHelpers";
|
import { initMessages, Messages } from "./Message/MessageHelpers";
|
||||||
import { prestigeWorkerScripts } from "./NetscriptWorker";
|
import { prestigeWorkerScripts } from "./NetscriptWorker";
|
||||||
import { Player } from "./Player";
|
import { Player } from "./Player";
|
||||||
|
import { resetPidCounter } from "./Netscript/Pid";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AllServers,
|
AllServers,
|
||||||
@ -172,6 +173,8 @@ function prestigeAugmentation() {
|
|||||||
DaedalusServer.serversOnNetwork.push(WorldDaemon.ip);
|
DaedalusServer.serversOnNetwork.push(WorldDaemon.ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetPidCounter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -346,6 +349,8 @@ function prestigeSourceFile() {
|
|||||||
|
|
||||||
// Gain int exp
|
// Gain int exp
|
||||||
Player.gainIntelligenceExp(5);
|
Player.gainIntelligenceExp(5);
|
||||||
|
|
||||||
|
resetPidCounter();
|
||||||
}
|
}
|
||||||
|
|
||||||
export {prestigeAugmentation, prestigeSourceFile};
|
export {prestigeAugmentation, prestigeSourceFile};
|
||||||
|
Loading…
Reference in New Issue
Block a user