Add dummy function to generate a mock server or player for formulas stuff

This commit is contained in:
Olivier Gagnon
2022-08-23 16:01:34 -04:00
parent 895944aa19
commit 89aa23f4b3
6 changed files with 103 additions and 6 deletions
+28 -1
View File
@@ -500,12 +500,39 @@ function player(ctx: NetscriptContext, p: unknown): IPlayer {
}
function server(ctx: NetscriptContext, s: unknown): Server {
if (!roughlyIs(new Server(), s)) throw makeRuntimeErrorMsg(ctx, `server should be a Server.`);
const fakeServer = {
cpuCores: undefined,
ftpPortOpen: undefined,
hasAdminRights: undefined,
hostname: undefined,
httpPortOpen: undefined,
ip: undefined,
isConnectedTo: undefined,
maxRam: undefined,
organizationName: undefined,
ramUsed: undefined,
smtpPortOpen: undefined,
sqlPortOpen: undefined,
sshPortOpen: undefined,
purchasedByPlayer: undefined,
backdoorInstalled: undefined,
baseDifficulty: undefined,
hackDifficulty: undefined,
minDifficulty: undefined,
moneyAvailable: undefined,
moneyMax: undefined,
numOpenPortsRequired: undefined,
openPortCount: undefined,
requiredHackingSkill: undefined,
serverGrowth: undefined,
};
if (!roughlyIs(fakeServer, s)) throw makeRuntimeErrorMsg(ctx, `server should be a Server.`);
return s as Server;
}
function roughlyIs(expect: object, actual: unknown): boolean {
if (typeof actual !== "object" || actual == null) return false;
const expects = Object.keys(expect);
const actuals = Object.keys(actual);
for (const expect of expects)