mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-19 06:03:50 +01:00
move ctx.log to NetscriptHelpers
This commit is contained in:
parent
8f8d9a1d23
commit
01e63b10a1
@ -24,9 +24,9 @@ type WrappedNetscriptAPI = {
|
||||
};
|
||||
|
||||
export type NetscriptContext = {
|
||||
log: (message: () => string) => void;
|
||||
workerScript: WorkerScript;
|
||||
function: string;
|
||||
functionPath: string;
|
||||
};
|
||||
|
||||
function wrapFunction(
|
||||
@ -41,11 +41,9 @@ function wrapFunction(
|
||||
throw helpers.makeRuntimeRejectMsg(workerScript, "Failure occured while wrapping netscript api");
|
||||
}
|
||||
const ctx = {
|
||||
log: (message: () => string) => {
|
||||
workerScript.log(functionPath, message);
|
||||
},
|
||||
workerScript,
|
||||
function: functionName,
|
||||
functionPath,
|
||||
};
|
||||
function wrappedFunction(...args: unknown[]): unknown {
|
||||
helpers.checkEnvFlags(ctx);
|
||||
|
@ -55,6 +55,7 @@ export const helpers = {
|
||||
gang,
|
||||
gangMember,
|
||||
gangTask,
|
||||
log,
|
||||
};
|
||||
|
||||
export type ScriptIdentifier = //This was previously in INetscriptHelper.ts, may move to its own file or a generic types file.
|
||||
@ -341,7 +342,8 @@ async function hack(
|
||||
throw makeRuntimeErrorMsg(ctx, canHack.msg || "");
|
||||
}
|
||||
|
||||
ctx.log(
|
||||
log(
|
||||
ctx,
|
||||
() =>
|
||||
`Executing on '${server.hostname}' in ${convertTimeMsToTimeElapsedString(
|
||||
hackingTime * 1000,
|
||||
@ -390,7 +392,8 @@ async function hack(
|
||||
Player.gainHackingExp(expGainedOnSuccess);
|
||||
if (manual) Player.gainIntelligenceExp(0.005);
|
||||
ws.scriptRef.onlineExpGained += expGainedOnSuccess;
|
||||
ctx.log(
|
||||
log(
|
||||
ctx,
|
||||
() =>
|
||||
`Successfully hacked '${server.hostname}' for ${numeralWrapper.formatMoney(
|
||||
moneyGained,
|
||||
@ -408,7 +411,8 @@ async function hack(
|
||||
// Player only gains 25% exp for failure?
|
||||
Player.gainHackingExp(expGainedOnFailure);
|
||||
ws.scriptRef.onlineExpGained += expGainedOnFailure;
|
||||
ctx.log(
|
||||
log(
|
||||
ctx,
|
||||
() =>
|
||||
`Failed to hack '${server.hostname}'. Gained ${numeralWrapper.formatExp(
|
||||
expGainedOnFailure,
|
||||
@ -499,3 +503,6 @@ function gangTask(ctx: NetscriptContext, t: unknown): GangMemberTask {
|
||||
throw makeRuntimeErrorMsg(ctx, `task should be a GangMemberTask.`);
|
||||
return t as GangMemberTask;
|
||||
}
|
||||
function log(ctx: NetscriptContext, message: () => string) {
|
||||
ctx.workerScript.log(ctx.functionPath, message);
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
if (entry === null) continue;
|
||||
out.push(entry);
|
||||
}
|
||||
ctx.log(() => `returned ${server.serversOnNetwork.length} connections for ${server.hostname}`);
|
||||
helpers.log(ctx, () => `returned ${server.serversOnNetwork.length} connections for ${server.hostname}`);
|
||||
return out;
|
||||
},
|
||||
hack:
|
||||
@ -300,7 +300,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
// Check argument validity
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return -1;
|
||||
}
|
||||
if (isNaN(hackAmount)) {
|
||||
@ -331,7 +331,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -345,7 +345,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -366,7 +366,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -379,7 +379,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
if (time === undefined) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, "Takes 1 argument.");
|
||||
}
|
||||
ctx.log(() => `Sleeping for ${time} milliseconds`);
|
||||
helpers.log(ctx, () => `Sleeping for ${time} milliseconds`);
|
||||
return helpers.netscriptDelay(ctx, time).then(function () {
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
@ -387,7 +387,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
asleep: (ctx: NetscriptContext) =>
|
||||
function (_time: unknown = 0): Promise<true> {
|
||||
const time = helpers.number(ctx, "time", _time);
|
||||
ctx.log(() => `Sleeping for ${time} milliseconds`);
|
||||
helpers.log(ctx, () => `Sleeping for ${time} milliseconds`);
|
||||
return new Promise((resolve) => setTimeout(() => resolve(true), time));
|
||||
},
|
||||
grow:
|
||||
@ -401,7 +401,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return Promise.resolve(0);
|
||||
}
|
||||
|
||||
@ -417,7 +417,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
|
||||
const growTime = calculateGrowTime(server, Player);
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`Executing on '${server.hostname}' in ${convertTimeMsToTimeElapsedString(
|
||||
growTime * 1000,
|
||||
@ -431,7 +432,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
workerScript.scriptRef.recordGrow(server.hostname, threads);
|
||||
const expGain = calculateHackingExpGain(server, Player) * threads;
|
||||
const logGrowPercent = moneyAfter / moneyBefore - 1;
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`Available money on '${server.hostname}' grown by ${numeralWrapper.formatPercentage(
|
||||
logGrowPercent,
|
||||
@ -458,7 +460,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
// Check argument validity
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return 0;
|
||||
}
|
||||
if (typeof growth !== "number" || isNaN(growth) || growth < 1 || !isFinite(growth)) {
|
||||
@ -477,7 +479,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -503,7 +505,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return Promise.resolve(0);
|
||||
}
|
||||
|
||||
@ -514,7 +516,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
|
||||
const weakenTime = calculateWeakenTime(server, Player);
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`Executing on '${server.hostname}' in ${convertTimeMsToTimeElapsedString(
|
||||
weakenTime * 1000,
|
||||
@ -524,14 +527,15 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return helpers.netscriptDelay(ctx, weakenTime * 1000).then(function () {
|
||||
const host = GetServer(workerScript.hostname);
|
||||
if (host === null) {
|
||||
ctx.log(() => "Server is null, did it die?");
|
||||
helpers.log(ctx, () => "Server is null, did it die?");
|
||||
return Promise.resolve(0);
|
||||
}
|
||||
const coreBonus = 1 + (host.cpuCores - 1) / 16;
|
||||
server.weaken(CONSTANTS.ServerWeakenAmount * threads * coreBonus);
|
||||
workerScript.scriptRef.recordWeaken(server.hostname, threads);
|
||||
const expGain = calculateHackingExpGain(server, Player) * threads;
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`'${server.hostname}' security level weakened to ${
|
||||
server.hackDifficulty
|
||||
@ -551,12 +555,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return CONSTANTS.ServerWeakenAmount * threads * coreBonus * BitNodeMultipliers.ServerWeakenRate;
|
||||
},
|
||||
share: (ctx: NetscriptContext) => async (): Promise<void> => {
|
||||
ctx.log(() => "Sharing this computer.");
|
||||
helpers.log(ctx, () => "Sharing this computer.");
|
||||
const end = StartSharing(
|
||||
workerScript.scriptRef.threads * calculateIntelligenceBonus(Player.skills.intelligence, 2),
|
||||
);
|
||||
return helpers.netscriptDelay(ctx, 10000).finally(function () {
|
||||
ctx.log(() => "Finished sharing this computer.");
|
||||
helpers.log(ctx, () => "Finished sharing this computer.");
|
||||
end();
|
||||
});
|
||||
},
|
||||
@ -640,12 +644,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
for (const fn of Object.keys(possibleLogs)) {
|
||||
workerScript.disableLogs[fn] = true;
|
||||
}
|
||||
ctx.log(() => `Disabled logging for all functions`);
|
||||
helpers.log(ctx, () => `Disabled logging for all functions`);
|
||||
} else if (possibleLogs[fn] === undefined) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid argument: ${fn}.`);
|
||||
} else {
|
||||
workerScript.disableLogs[fn] = true;
|
||||
ctx.log(() => `Disabled logging for ${fn}`);
|
||||
helpers.log(ctx, () => `Disabled logging for ${fn}`);
|
||||
}
|
||||
},
|
||||
enableLog:
|
||||
@ -656,12 +660,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
for (const fn of Object.keys(possibleLogs)) {
|
||||
delete workerScript.disableLogs[fn];
|
||||
}
|
||||
ctx.log(() => `Enabled logging for all functions`);
|
||||
helpers.log(ctx, () => `Enabled logging for all functions`);
|
||||
} else if (possibleLogs[fn] === undefined) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid argument: ${fn}.`);
|
||||
}
|
||||
delete workerScript.disableLogs[fn];
|
||||
ctx.log(() => `Enabled logging for ${fn}`);
|
||||
helpers.log(ctx, () => `Enabled logging for ${fn}`);
|
||||
},
|
||||
isLogEnabled:
|
||||
(ctx: NetscriptContext) =>
|
||||
@ -678,7 +682,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const ident = helpers.scriptIdentifier(ctx, scriptID, hostname, scriptArgs);
|
||||
const runningScriptObj = getRunningScript(ctx, ident);
|
||||
if (runningScriptObj == null) {
|
||||
ctx.log(() => getCannotFindRunningScriptErrorMessage(ident));
|
||||
helpers.log(ctx, () => getCannotFindRunningScriptErrorMessage(ident));
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -690,7 +694,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const ident = helpers.scriptIdentifier(ctx, scriptID, hostname, scriptArgs);
|
||||
const runningScriptObj = getRunningScript(ctx, ident);
|
||||
if (runningScriptObj == null) {
|
||||
ctx.log(() => getCannotFindRunningScriptErrorMessage(ident));
|
||||
helpers.log(ctx, () => getCannotFindRunningScriptErrorMessage(ident));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -711,11 +715,11 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return false;
|
||||
}
|
||||
if (server.hasAdminRights) {
|
||||
ctx.log(() => `Already have root access to '${server.hostname}'.`);
|
||||
helpers.log(ctx, () => `Already have root access to '${server.hostname}'.`);
|
||||
return true;
|
||||
}
|
||||
if (!Player.hasProgram(Programs.NukeProgram.name)) {
|
||||
@ -725,7 +729,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, "Not enough ports opened to use NUKE.exe virus.");
|
||||
}
|
||||
server.hasAdminRights = true;
|
||||
ctx.log(() => `Executed NUKE.exe virus on '${server.hostname}' to gain root access.`);
|
||||
helpers.log(ctx, () => `Executed NUKE.exe virus on '${server.hostname}' to gain root access.`);
|
||||
return true;
|
||||
},
|
||||
brutessh:
|
||||
@ -734,18 +738,18 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return false;
|
||||
}
|
||||
if (!Player.hasProgram(Programs.BruteSSHProgram.name)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, "You do not have the BruteSSH.exe program!");
|
||||
}
|
||||
if (!server.sshPortOpen) {
|
||||
ctx.log(() => `Executed BruteSSH.exe on '${server.hostname}' to open SSH port (22).`);
|
||||
helpers.log(ctx, () => `Executed BruteSSH.exe on '${server.hostname}' to open SSH port (22).`);
|
||||
server.sshPortOpen = true;
|
||||
++server.openPortCount;
|
||||
} else {
|
||||
ctx.log(() => `SSH Port (22) already opened on '${server.hostname}'.`);
|
||||
helpers.log(ctx, () => `SSH Port (22) already opened on '${server.hostname}'.`);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
@ -758,18 +762,18 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return false;
|
||||
}
|
||||
if (!Player.hasProgram(Programs.FTPCrackProgram.name)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, "You do not have the FTPCrack.exe program!");
|
||||
}
|
||||
if (!server.ftpPortOpen) {
|
||||
ctx.log(() => `Executed FTPCrack.exe on '${server.hostname}' to open FTP port (21).`);
|
||||
helpers.log(ctx, () => `Executed FTPCrack.exe on '${server.hostname}' to open FTP port (21).`);
|
||||
server.ftpPortOpen = true;
|
||||
++server.openPortCount;
|
||||
} else {
|
||||
ctx.log(() => `FTP Port (21) already opened on '${server.hostname}'.`);
|
||||
helpers.log(ctx, () => `FTP Port (21) already opened on '${server.hostname}'.`);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
@ -782,18 +786,18 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return false;
|
||||
}
|
||||
if (!Player.hasProgram(Programs.RelaySMTPProgram.name)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, "You do not have the relaySMTP.exe program!");
|
||||
}
|
||||
if (!server.smtpPortOpen) {
|
||||
ctx.log(() => `Executed relaySMTP.exe on '${server.hostname}' to open SMTP port (25).`);
|
||||
helpers.log(ctx, () => `Executed relaySMTP.exe on '${server.hostname}' to open SMTP port (25).`);
|
||||
server.smtpPortOpen = true;
|
||||
++server.openPortCount;
|
||||
} else {
|
||||
ctx.log(() => `SMTP Port (25) already opened on '${server.hostname}'.`);
|
||||
helpers.log(ctx, () => `SMTP Port (25) already opened on '${server.hostname}'.`);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
@ -806,18 +810,18 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return false;
|
||||
}
|
||||
if (!Player.hasProgram(Programs.HTTPWormProgram.name)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, "You do not have the HTTPWorm.exe program!");
|
||||
}
|
||||
if (!server.httpPortOpen) {
|
||||
ctx.log(() => `Executed HTTPWorm.exe on '${server.hostname}' to open HTTP port (80).`);
|
||||
helpers.log(ctx, () => `Executed HTTPWorm.exe on '${server.hostname}' to open HTTP port (80).`);
|
||||
server.httpPortOpen = true;
|
||||
++server.openPortCount;
|
||||
} else {
|
||||
ctx.log(() => `HTTP Port (80) already opened on '${server.hostname}'.`);
|
||||
helpers.log(ctx, () => `HTTP Port (80) already opened on '${server.hostname}'.`);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
@ -830,18 +834,18 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return false;
|
||||
}
|
||||
if (!Player.hasProgram(Programs.SQLInjectProgram.name)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, "You do not have the SQLInject.exe program!");
|
||||
}
|
||||
if (!server.sqlPortOpen) {
|
||||
ctx.log(() => `Executed SQLInject.exe on '${server.hostname}' to open SQL port (1433).`);
|
||||
helpers.log(ctx, () => `Executed SQLInject.exe on '${server.hostname}' to open SQL port (1433).`);
|
||||
server.sqlPortOpen = true;
|
||||
++server.openPortCount;
|
||||
} else {
|
||||
ctx.log(() => `SQL Port (1433) already opened on '${server.hostname}'.`);
|
||||
helpers.log(ctx, () => `SQL Port (1433) already opened on '${server.hostname}'.`);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
@ -903,11 +907,11 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return runScriptFromScript(Player, "spawn", scriptServer, scriptname, args, workerScript, threads);
|
||||
}, spawnDelay * 1e3);
|
||||
|
||||
ctx.log(() => `Will execute '${scriptname}' in ${spawnDelay} seconds`);
|
||||
helpers.log(ctx, () => `Will execute '${scriptname}' in ${spawnDelay} seconds`);
|
||||
|
||||
workerScript.running = false; // Prevent workerScript from "finishing execution naturally"
|
||||
if (killWorkerScript(workerScript)) {
|
||||
ctx.log(() => "Exiting...");
|
||||
helpers.log(ctx, () => "Exiting...");
|
||||
}
|
||||
},
|
||||
kill:
|
||||
@ -928,7 +932,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const server = helpers.getServer(ctx, ident.hostname);
|
||||
const runningScriptObj = getRunningScriptByArgs(ctx, ident.scriptname, ident.hostname, ident.args);
|
||||
if (runningScriptObj == null) {
|
||||
ctx.log(() => getCannotFindRunningScriptErrorMessage(ident));
|
||||
helpers.log(ctx, () => getCannotFindRunningScriptErrorMessage(ident));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -937,16 +941,19 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
|
||||
if (res) {
|
||||
if (killByPid) {
|
||||
ctx.log(() => `Killing script with PID ${ident}`);
|
||||
helpers.log(ctx, () => `Killing script with PID ${ident}`);
|
||||
} else {
|
||||
ctx.log(() => `Killing '${scriptID}' on '${hostname}' with args: ${arrayToString(scriptArgs)}.`);
|
||||
helpers.log(ctx, () => `Killing '${scriptID}' on '${hostname}' with args: ${arrayToString(scriptArgs)}.`);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if (killByPid) {
|
||||
ctx.log(() => `No script with PID ${ident}`);
|
||||
helpers.log(ctx, () => `No script with PID ${ident}`);
|
||||
} else {
|
||||
ctx.log(() => `No such script '${scriptID}' on '${hostname}' with args: ${arrayToString(scriptArgs)}`);
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `No such script '${scriptID}' on '${hostname}' with args: ${arrayToString(scriptArgs)}`,
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -969,16 +976,19 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
++scriptsKilled;
|
||||
}
|
||||
WorkerScriptStartStopEventEmitter.emit();
|
||||
ctx.log(() => `Killing all scripts on '${server.hostname}'. May take a few minutes for the scripts to die.`);
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `Killing all scripts on '${server.hostname}'. May take a few minutes for the scripts to die.`,
|
||||
);
|
||||
|
||||
return scriptsKilled > 0;
|
||||
},
|
||||
exit: (ctx: NetscriptContext) => (): void => {
|
||||
workerScript.running = false; // Prevent workerScript from "finishing execution naturally"
|
||||
if (killWorkerScript(workerScript)) {
|
||||
ctx.log(() => "Exiting...");
|
||||
helpers.log(ctx, () => "Exiting...");
|
||||
} else {
|
||||
ctx.log(() => "Failed. This is a bug. Report to dev.");
|
||||
helpers.log(ctx, () => "Failed. This is a bug. Report to dev.");
|
||||
}
|
||||
},
|
||||
scp:
|
||||
@ -1033,18 +1043,18 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
ctx.log(() => `File '${scriptName}' does not exist.`);
|
||||
helpers.log(ctx, () => `File '${scriptName}' does not exist.`);
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
for (let i = 0; i < destServer.messages.length; ++i) {
|
||||
if (destServer.messages[i] === scriptName) {
|
||||
ctx.log(() => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||
helpers.log(ctx, () => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||
return Promise.resolve(true); // Already exists
|
||||
}
|
||||
}
|
||||
destServer.messages.push(scriptName);
|
||||
ctx.log(() => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||
helpers.log(ctx, () => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
@ -1058,7 +1068,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
}
|
||||
if (txtFile === undefined) {
|
||||
ctx.log(() => `File '${scriptName}' does not exist.`);
|
||||
helpers.log(ctx, () => `File '${scriptName}' does not exist.`);
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
@ -1066,13 +1076,13 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
if (destServer.textFiles[i].fn === scriptName) {
|
||||
// Overwrite
|
||||
destServer.textFiles[i].text = txtFile.text;
|
||||
ctx.log(() => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||
helpers.log(ctx, () => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
}
|
||||
const newFile = new TextFile(txtFile.fn, txtFile.text);
|
||||
destServer.textFiles.push(newFile);
|
||||
ctx.log(() => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||
helpers.log(ctx, () => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
@ -1085,14 +1095,14 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
}
|
||||
if (sourceScript == null) {
|
||||
ctx.log(() => `File '${scriptName}' does not exist.`);
|
||||
helpers.log(ctx, () => `File '${scriptName}' does not exist.`);
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
// Overwrite script if it already exists
|
||||
for (let i = 0; i < destServer.scripts.length; ++i) {
|
||||
if (scriptName == destServer.scripts[i].filename) {
|
||||
ctx.log(() => `WARNING: File '${scriptName}' overwritten on '${destServer?.hostname}'`);
|
||||
helpers.log(ctx, () => `WARNING: File '${scriptName}' overwritten on '${destServer?.hostname}'`);
|
||||
const oldScript = destServer.scripts[i];
|
||||
// If it's the exact same file don't actually perform the
|
||||
// copy to avoid recompiling uselessly. Players tend to scp
|
||||
@ -1111,7 +1121,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
newScript.ramUsage = sourceScript.ramUsage;
|
||||
newScript.server = destServer.hostname;
|
||||
destServer.scripts.push(newScript);
|
||||
ctx.log(() => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||
helpers.log(ctx, () => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||
return new Promise((resolve) => {
|
||||
if (destServer === null) {
|
||||
resolve(false);
|
||||
@ -1227,7 +1237,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
},
|
||||
getHackingLevel: (ctx: NetscriptContext) => (): number => {
|
||||
Player.updateSkillLevels();
|
||||
ctx.log(() => `returned ${Player.skills.hacking}`);
|
||||
helpers.log(ctx, () => `returned ${Player.skills.hacking}`);
|
||||
return Player.skills.hacking;
|
||||
},
|
||||
getHackingMultipliers: () => (): HackingMultipliers => {
|
||||
@ -1285,7 +1295,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return 0;
|
||||
}
|
||||
if (failOnHacknetServer(server, "getServerMoneyAvailable")) {
|
||||
@ -1293,10 +1303,13 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
if (server.hostname == "home") {
|
||||
// Return player's money
|
||||
ctx.log(() => `returned player's money: ${numeralWrapper.formatMoney(Player.money)}`);
|
||||
helpers.log(ctx, () => `returned player's money: ${numeralWrapper.formatMoney(Player.money)}`);
|
||||
return Player.money;
|
||||
}
|
||||
ctx.log(() => `returned ${numeralWrapper.formatMoney(server.moneyAvailable)} for '${server.hostname}'`);
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `returned ${numeralWrapper.formatMoney(server.moneyAvailable)} for '${server.hostname}'`,
|
||||
);
|
||||
return server.moneyAvailable;
|
||||
},
|
||||
getServerSecurityLevel:
|
||||
@ -1305,13 +1318,14 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return 1;
|
||||
}
|
||||
if (failOnHacknetServer(server, "getServerSecurityLevel")) {
|
||||
return 1;
|
||||
}
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `returned ${numeralWrapper.formatServerSecurity(server.hackDifficulty)} for '${server.hostname}'`,
|
||||
);
|
||||
return server.hackDifficulty;
|
||||
@ -1320,16 +1334,17 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
(ctx: NetscriptContext) =>
|
||||
(_hostname: unknown): number => {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
ctx.log(() => `getServerBaseSecurityLevel is deprecated because it's not useful.`);
|
||||
helpers.log(ctx, () => `getServerBaseSecurityLevel is deprecated because it's not useful.`);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return 1;
|
||||
}
|
||||
if (failOnHacknetServer(server, "getServerBaseSecurityLevel")) {
|
||||
return 1;
|
||||
}
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `returned ${numeralWrapper.formatServerSecurity(server.baseDifficulty)} for '${server.hostname}'`,
|
||||
);
|
||||
return server.baseDifficulty;
|
||||
@ -1340,13 +1355,16 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return 1;
|
||||
}
|
||||
if (failOnHacknetServer(server, "getServerMinSecurityLevel")) {
|
||||
return 1;
|
||||
}
|
||||
ctx.log(() => `returned ${numeralWrapper.formatServerSecurity(server.minDifficulty)} for ${server.hostname}`);
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `returned ${numeralWrapper.formatServerSecurity(server.minDifficulty)} for ${server.hostname}`,
|
||||
);
|
||||
return server.minDifficulty;
|
||||
},
|
||||
getServerRequiredHackingLevel:
|
||||
@ -1355,13 +1373,16 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return 1;
|
||||
}
|
||||
if (failOnHacknetServer(server, "getServerRequiredHackingLevel")) {
|
||||
return 1;
|
||||
}
|
||||
ctx.log(() => `returned ${numeralWrapper.formatSkill(server.requiredHackingSkill)} for '${server.hostname}'`);
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `returned ${numeralWrapper.formatSkill(server.requiredHackingSkill)} for '${server.hostname}'`,
|
||||
);
|
||||
return server.requiredHackingSkill;
|
||||
},
|
||||
getServerMaxMoney:
|
||||
@ -1370,13 +1391,13 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return 0;
|
||||
}
|
||||
if (failOnHacknetServer(server, "getServerMaxMoney")) {
|
||||
return 0;
|
||||
}
|
||||
ctx.log(() => `returned ${numeralWrapper.formatMoney(server.moneyMax)} for '${server.hostname}'`);
|
||||
helpers.log(ctx, () => `returned ${numeralWrapper.formatMoney(server.moneyMax)} for '${server.hostname}'`);
|
||||
return server.moneyMax;
|
||||
},
|
||||
getServerGrowth:
|
||||
@ -1385,13 +1406,13 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return 1;
|
||||
}
|
||||
if (failOnHacknetServer(server, "getServerGrowth")) {
|
||||
return 1;
|
||||
}
|
||||
ctx.log(() => `returned ${server.serverGrowth} for '${server.hostname}'`);
|
||||
helpers.log(ctx, () => `returned ${server.serverGrowth} for '${server.hostname}'`);
|
||||
return server.serverGrowth;
|
||||
},
|
||||
getServerNumPortsRequired:
|
||||
@ -1400,22 +1421,23 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "Cannot be executed on this server.");
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return 5;
|
||||
}
|
||||
if (failOnHacknetServer(server, "getServerNumPortsRequired")) {
|
||||
return 5;
|
||||
}
|
||||
ctx.log(() => `returned ${server.numOpenPortsRequired} for '${server.hostname}'`);
|
||||
helpers.log(ctx, () => `returned ${server.numOpenPortsRequired} for '${server.hostname}'`);
|
||||
return server.numOpenPortsRequired;
|
||||
},
|
||||
getServerRam:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_hostname: unknown): [number, number] => {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
ctx.log(() => `getServerRam is deprecated in favor of getServerMaxRam / getServerUsedRam`);
|
||||
helpers.log(ctx, () => `getServerRam is deprecated in favor of getServerMaxRam / getServerUsedRam`);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `returned [${numeralWrapper.formatRAM(server.maxRam)}, ${numeralWrapper.formatRAM(server.ramUsed)}]`,
|
||||
);
|
||||
return [server.maxRam, server.ramUsed];
|
||||
@ -1425,7 +1447,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
(_hostname: unknown): number => {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
ctx.log(() => `returned ${numeralWrapper.formatRAM(server.maxRam)}`);
|
||||
helpers.log(ctx, () => `returned ${numeralWrapper.formatRAM(server.maxRam)}`);
|
||||
return server.maxRam;
|
||||
},
|
||||
getServerUsedRam:
|
||||
@ -1433,7 +1455,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
(_hostname: unknown): number => {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
ctx.log(() => `returned ${numeralWrapper.formatRAM(server.ramUsed)}`);
|
||||
helpers.log(ctx, () => `returned ${numeralWrapper.formatRAM(server.ramUsed)}`);
|
||||
return server.ramUsed;
|
||||
},
|
||||
serverExists:
|
||||
@ -1488,7 +1510,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
|
||||
const cost = getPurchaseServerCost(ram);
|
||||
if (cost === Infinity) {
|
||||
ctx.log(() => `Invalid argument: ram='${ram}'`);
|
||||
helpers.log(ctx, () => `Invalid argument: ram='${ram}'`);
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
@ -1502,12 +1524,13 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
let hostnameStr = String(name);
|
||||
hostnameStr = hostnameStr.replace(/\s+/g, "");
|
||||
if (hostnameStr == "") {
|
||||
ctx.log(() => `Invalid argument: hostname='${hostnameStr}'`);
|
||||
helpers.log(ctx, () => `Invalid argument: hostname='${hostnameStr}'`);
|
||||
return "";
|
||||
}
|
||||
|
||||
if (Player.purchasedServers.length >= getPurchaseServerLimit()) {
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`You have reached the maximum limit of ${getPurchaseServerLimit()} servers. You cannot purchase any more.`,
|
||||
);
|
||||
@ -1517,16 +1540,16 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const cost = getPurchaseServerCost(ram);
|
||||
if (cost === Infinity) {
|
||||
if (ram > getPurchaseServerMaxRam()) {
|
||||
ctx.log(() => `Invalid argument: ram='${ram}' must not be greater than getPurchaseServerMaxRam`);
|
||||
helpers.log(ctx, () => `Invalid argument: ram='${ram}' must not be greater than getPurchaseServerMaxRam`);
|
||||
} else {
|
||||
ctx.log(() => `Invalid argument: ram='${ram}' must be a positive power of 2`);
|
||||
helpers.log(ctx, () => `Invalid argument: ram='${ram}' must be a positive power of 2`);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
if (Player.money < cost) {
|
||||
ctx.log(() => `Not enough money to purchase server. Need ${numeralWrapper.formatMoney(cost)}`);
|
||||
helpers.log(ctx, () => `Not enough money to purchase server. Need ${numeralWrapper.formatMoney(cost)}`);
|
||||
return "";
|
||||
}
|
||||
const newServ = safetlyCreateUniqueServer({
|
||||
@ -1545,7 +1568,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
homeComputer.serversOnNetwork.push(newServ.hostname);
|
||||
newServ.serversOnNetwork.push(homeComputer.hostname);
|
||||
Player.loseMoney(cost, "servers");
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `Purchased new server with hostname '${newServ.hostname}' for ${numeralWrapper.formatMoney(cost)}`,
|
||||
);
|
||||
return newServ.hostname;
|
||||
@ -1558,12 +1582,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
hostnameStr = hostnameStr.replace(/\s\s+/g, "");
|
||||
const server = GetServer(hostnameStr);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => `Invalid argument: hostname='${hostnameStr}'`);
|
||||
helpers.log(ctx, () => `Invalid argument: hostname='${hostnameStr}'`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!server.purchasedByPlayer || server.hostname === "home") {
|
||||
ctx.log(() => "Cannot delete non-purchased server.");
|
||||
helpers.log(ctx, () => "Cannot delete non-purchased server.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1571,19 +1595,19 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
|
||||
// Can't delete server you're currently connected to
|
||||
if (server.isConnectedTo) {
|
||||
ctx.log(() => "You are currently connected to the server you are trying to delete.");
|
||||
helpers.log(ctx, () => "You are currently connected to the server you are trying to delete.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// A server cannot delete itself
|
||||
if (hostname === workerScript.hostname) {
|
||||
ctx.log(() => "Cannot delete the server this script is running on.");
|
||||
helpers.log(ctx, () => "Cannot delete the server this script is running on.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Delete all scripts running on server
|
||||
if (server.runningScripts.length > 0) {
|
||||
ctx.log(() => `Cannot delete server '${hostname}' because it still has scripts running.`);
|
||||
helpers.log(ctx, () => `Cannot delete server '${hostname}' because it still has scripts running.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1598,7 +1622,10 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
ctx.log(() => `Could not identify server ${hostname} as a purchased server. This is a bug. Report to dev.`);
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `Could not identify server ${hostname} as a purchased server. This is a bug. Report to dev.`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1611,12 +1638,15 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
for (let i = 0; i < homeComputer.serversOnNetwork.length; ++i) {
|
||||
if (hostname == homeComputer.serversOnNetwork[i]) {
|
||||
homeComputer.serversOnNetwork.splice(i, 1);
|
||||
ctx.log(() => `Deleted server '${hostnameStr}`);
|
||||
helpers.log(ctx, () => `Deleted server '${hostnameStr}`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Wasn't found on home computer
|
||||
ctx.log(() => `Could not find server ${hostname} as a purchased server. This is a bug. Report to dev.`);
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `Could not find server ${hostname} as a purchased server. This is a bug. Report to dev.`,
|
||||
);
|
||||
return false;
|
||||
},
|
||||
getPurchasedServers: () => (): string[] => {
|
||||
@ -1816,7 +1846,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
|
||||
const status = s.removeFile(fn);
|
||||
if (!status.res) {
|
||||
ctx.log(() => status.msg + "");
|
||||
helpers.log(ctx, () => status.msg + "");
|
||||
}
|
||||
|
||||
return status.res;
|
||||
@ -1880,7 +1910,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "invalid for this kind of server");
|
||||
helpers.log(ctx, () => "invalid for this kind of server");
|
||||
return Infinity;
|
||||
}
|
||||
if (failOnHacknetServer(server, "getHackTime")) {
|
||||
@ -1895,7 +1925,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "invalid for this kind of server");
|
||||
helpers.log(ctx, () => "invalid for this kind of server");
|
||||
return Infinity;
|
||||
}
|
||||
if (failOnHacknetServer(server, "getGrowTime")) {
|
||||
@ -1910,7 +1940,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
ctx.log(() => "invalid for this kind of server");
|
||||
helpers.log(ctx, () => "invalid for this kind of server");
|
||||
return Infinity;
|
||||
}
|
||||
if (failOnHacknetServer(server, "getWeakenTime")) {
|
||||
@ -1934,7 +1964,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const ident = helpers.scriptIdentifier(ctx, fn, hostname, args);
|
||||
const runningScript = getRunningScript(ctx, ident);
|
||||
if (runningScript == null) {
|
||||
ctx.log(() => getCannotFindRunningScriptErrorMessage(ident));
|
||||
helpers.log(ctx, () => getCannotFindRunningScriptErrorMessage(ident));
|
||||
return -1;
|
||||
}
|
||||
return runningScript.onlineMoneyMade / runningScript.onlineRunningTime;
|
||||
@ -1952,7 +1982,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const ident = helpers.scriptIdentifier(ctx, fn, hostname, args);
|
||||
const runningScript = getRunningScript(ctx, ident);
|
||||
if (runningScript == null) {
|
||||
ctx.log(() => getCannotFindRunningScriptErrorMessage(ident));
|
||||
helpers.log(ctx, () => getCannotFindRunningScriptErrorMessage(ident));
|
||||
return -1;
|
||||
}
|
||||
return runningScript.onlineExpGained / runningScript.onlineRunningTime;
|
||||
@ -2014,7 +2044,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const target = helpers.string(ctx, "target", _target);
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
if (!isScriptFilename(target) && !target.endsWith(".txt")) {
|
||||
ctx.log(() => `Invalid target file: '${target}'. Must be a script or text file.`);
|
||||
helpers.log(ctx, () => `Invalid target file: '${target}'. Must be a script or text file.`);
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
const s = helpers.getServer(ctx, hostname);
|
||||
@ -2029,19 +2059,19 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
res = s.writeToTextFile(target, data);
|
||||
}
|
||||
if (!res.success) {
|
||||
ctx.log(() => "Failed.");
|
||||
helpers.log(ctx, () => "Failed.");
|
||||
return resolve(false);
|
||||
}
|
||||
if (res.overwritten) {
|
||||
ctx.log(() => `Successfully retrieved content and overwrote '${target}' on '${hostname}'`);
|
||||
helpers.log(ctx, () => `Successfully retrieved content and overwrote '${target}' on '${hostname}'`);
|
||||
return resolve(true);
|
||||
}
|
||||
ctx.log(() => `Successfully retrieved content to new file '${target}' on '${hostname}'`);
|
||||
helpers.log(ctx, () => `Successfully retrieved content to new file '${target}' on '${hostname}'`);
|
||||
return resolve(true);
|
||||
},
|
||||
"text",
|
||||
).fail(function (e) {
|
||||
ctx.log(() => JSON.stringify(e));
|
||||
helpers.log(ctx, () => JSON.stringify(e));
|
||||
return resolve(false);
|
||||
});
|
||||
});
|
||||
|
@ -131,7 +131,7 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
const time = bladeburner.getActionTimeNetscriptFn(player, type, name);
|
||||
if (typeof time === "string") {
|
||||
const errorLogText = `Invalid action: type='${type}' name='${name}'`;
|
||||
ctx.log(() => errorLogText);
|
||||
helpers.log(ctx, () => errorLogText);
|
||||
return -1;
|
||||
} else {
|
||||
return time;
|
||||
@ -165,7 +165,7 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
const chance = bladeburner.getActionEstimatedSuccessChanceNetscriptFn(player, type, name);
|
||||
if (typeof chance === "string") {
|
||||
const errorLogText = `Invalid action: type='${type}' name='${name}'`;
|
||||
ctx.log(() => errorLogText);
|
||||
helpers.log(ctx, () => errorLogText);
|
||||
return [-1, -1];
|
||||
} else {
|
||||
return chance;
|
||||
@ -410,11 +410,11 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
player.skills.agility >= 100
|
||||
) {
|
||||
player.bladeburner = new Bladeburner(player);
|
||||
ctx.log(() => "You have been accepted into the Bladeburner division");
|
||||
helpers.log(ctx, () => "You have been accepted into the Bladeburner division");
|
||||
|
||||
return true;
|
||||
} else {
|
||||
ctx.log(() => "You do not meet the requirements for joining the Bladeburner division");
|
||||
helpers.log(ctx, () => "You do not meet the requirements for joining the Bladeburner division");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -55,16 +55,17 @@ export function NetscriptCodingContract(player: IPlayer, workerScript: WorkerScr
|
||||
const serv = helpers.getServer(ctx, hostname);
|
||||
if (contract.isSolution(answerStr)) {
|
||||
const reward = player.gainCodingContractReward(creward, contract.getDifficulty());
|
||||
ctx.log(() => `Successfully completed Coding Contract '${filename}'. Reward: ${reward}`);
|
||||
helpers.log(ctx, () => `Successfully completed Coding Contract '${filename}'. Reward: ${reward}`);
|
||||
serv.removeContract(filename);
|
||||
return returnReward ? reward : true;
|
||||
} else {
|
||||
++contract.tries;
|
||||
if (contract.tries >= contract.getMaxNumTries()) {
|
||||
ctx.log(() => `Coding Contract attempt '${filename}' failed. Contract is now self-destructing`);
|
||||
helpers.log(ctx, () => `Coding Contract attempt '${filename}' failed. Contract is now self-destructing`);
|
||||
serv.removeContract(filename);
|
||||
} else {
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`Coding Contract attempt '${filename}' failed. ${
|
||||
contract.getMaxNumTries() - contract.tries
|
||||
|
@ -61,7 +61,7 @@ export function NetscriptGrafting(player: IPlayer): InternalAPI<IGrafting> {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, "You must be in New Tokyo to begin grafting an Augmentation.");
|
||||
}
|
||||
if (!getGraftingAvailableAugs(player).includes(augName) || !StaticAugmentations.hasOwnProperty(augName)) {
|
||||
ctx.log(() => `Invalid aug: ${augName}`);
|
||||
helpers.log(ctx, () => `Invalid aug: ${augName}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -69,12 +69,12 @@ export function NetscriptGrafting(player: IPlayer): InternalAPI<IGrafting> {
|
||||
|
||||
const craftableAug = new GraftableAugmentation(StaticAugmentations[augName]);
|
||||
if (player.money < craftableAug.cost) {
|
||||
ctx.log(() => `You don't have enough money to craft ${augName}`);
|
||||
helpers.log(ctx, () => `You don't have enough money to craft ${augName}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!hasAugmentationPrereqs(craftableAug.augmentation)) {
|
||||
ctx.log(() => `You don't have the pre-requisites for ${augName}`);
|
||||
helpers.log(ctx, () => `You don't have the pre-requisites for ${augName}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ export function NetscriptGrafting(player: IPlayer): InternalAPI<IGrafting> {
|
||||
Router.toTerminal();
|
||||
}
|
||||
|
||||
ctx.log(() => `Began grafting Augmentation ${augName}.`);
|
||||
helpers.log(ctx, () => `Began grafting Augmentation ${augName}.`);
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
@ -185,12 +185,12 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
const augs = getFactionAugmentationsFiltered(player, fac);
|
||||
|
||||
if (!player.factions.includes(fac.name)) {
|
||||
ctx.log(() => `You can't purchase augmentations from '${facName}' because you aren't a member`);
|
||||
helpers.log(ctx, () => `You can't purchase augmentations from '${facName}' because you aren't a member`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!augs.includes(augName)) {
|
||||
ctx.log(() => `Faction '${facName}' does not have the '${augName}' augmentation.`);
|
||||
helpers.log(ctx, () => `Faction '${facName}' does not have the '${augName}' augmentation.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -198,25 +198,25 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
if (!isNeuroflux) {
|
||||
for (let j = 0; j < player.queuedAugmentations.length; ++j) {
|
||||
if (player.queuedAugmentations[j].name === aug.name) {
|
||||
ctx.log(() => `You already have the '${augName}' augmentation.`);
|
||||
helpers.log(ctx, () => `You already have the '${augName}' augmentation.`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (let j = 0; j < player.augmentations.length; ++j) {
|
||||
if (player.augmentations[j].name === aug.name) {
|
||||
ctx.log(() => `You already have the '${augName}' augmentation.`);
|
||||
helpers.log(ctx, () => `You already have the '${augName}' augmentation.`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fac.playerReputation < aug.getCost(player).repCost) {
|
||||
ctx.log(() => `You do not have enough reputation with '${fac.name}'.`);
|
||||
helpers.log(ctx, () => `You do not have enough reputation with '${fac.name}'.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const res = purchaseAugmentation(aug, fac, true);
|
||||
ctx.log(() => res);
|
||||
helpers.log(ctx, () => res);
|
||||
if (isString(res) && res.startsWith("You purchased")) {
|
||||
player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain * 10);
|
||||
return true;
|
||||
@ -229,7 +229,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const cbScript = helpers.string(ctx, "cbScript", _cbScript);
|
||||
|
||||
ctx.log(() => "Soft resetting. This will cause this script to be killed");
|
||||
helpers.log(ctx, () => "Soft resetting. This will cause this script to be killed");
|
||||
setTimeout(() => {
|
||||
installAugmentations(true);
|
||||
runAfterReset(cbScript);
|
||||
@ -245,11 +245,11 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
const cbScript = helpers.string(ctx, "cbScript", _cbScript);
|
||||
|
||||
if (player.queuedAugmentations.length === 0) {
|
||||
ctx.log(() => "You do not have any Augmentations to be installed.");
|
||||
helpers.log(ctx, () => "You do not have any Augmentations to be installed.");
|
||||
return false;
|
||||
}
|
||||
player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain * 10);
|
||||
ctx.log(() => "Installing Augmentations. This will cause this script to be killed");
|
||||
helpers.log(ctx, () => "Installing Augmentations. This will cause this script to be killed");
|
||||
setTimeout(() => {
|
||||
installAugmentations();
|
||||
runAfterReset(cbScript);
|
||||
@ -266,11 +266,11 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
const locationName = helpers.string(ctx, "locationName", _locationName);
|
||||
const location = Object.values(Locations).find((l) => l.name === locationName);
|
||||
if (!location) {
|
||||
ctx.log(() => `No location named ${locationName}`);
|
||||
helpers.log(ctx, () => `No location named ${locationName}`);
|
||||
return false;
|
||||
}
|
||||
if (location.city && player.city !== location.city) {
|
||||
ctx.log(() => `No location named ${locationName} in ${player.city}`);
|
||||
helpers.log(ctx, () => `No location named ${locationName} in ${player.city}`);
|
||||
return false;
|
||||
}
|
||||
if (location.name === LocationName.TravelAgency) {
|
||||
@ -294,21 +294,28 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
switch (universityName.toLowerCase()) {
|
||||
case LocationName.AevumSummitUniversity.toLowerCase():
|
||||
if (player.city != CityName.Aevum) {
|
||||
ctx.log(() => `You cannot study at 'Summit University' because you are not in '${CityName.Aevum}'.`);
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `You cannot study at 'Summit University' because you are not in '${CityName.Aevum}'.`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
player.gotoLocation(LocationName.AevumSummitUniversity);
|
||||
break;
|
||||
case LocationName.Sector12RothmanUniversity.toLowerCase():
|
||||
if (player.city != CityName.Sector12) {
|
||||
ctx.log(() => `You cannot study at 'Rothman University' because you are not in '${CityName.Sector12}'.`);
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `You cannot study at 'Rothman University' because you are not in '${CityName.Sector12}'.`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
player.location = LocationName.Sector12RothmanUniversity;
|
||||
break;
|
||||
case LocationName.VolhavenZBInstituteOfTechnology.toLowerCase():
|
||||
if (player.city != CityName.Volhaven) {
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `You cannot study at 'ZB Institute of Technology' because you are not in '${CityName.Volhaven}'.`,
|
||||
);
|
||||
return false;
|
||||
@ -316,7 +323,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
player.location = LocationName.VolhavenZBInstituteOfTechnology;
|
||||
break;
|
||||
default:
|
||||
ctx.log(() => `Invalid university name: '${universityName}'.`);
|
||||
helpers.log(ctx, () => `Invalid university name: '${universityName}'.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -341,7 +348,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
task = ClassType.Leadership;
|
||||
break;
|
||||
default:
|
||||
ctx.log(() => `Invalid class name: ${className}.`);
|
||||
helpers.log(ctx, () => `Invalid class name: ${className}.`);
|
||||
return false;
|
||||
}
|
||||
player.startWork(
|
||||
@ -358,7 +365,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
player.stopFocusing();
|
||||
Router.toTerminal();
|
||||
}
|
||||
ctx.log(() => `Started ${task} at ${universityName}`);
|
||||
helpers.log(ctx, () => `Started ${task} at ${universityName}`);
|
||||
return true;
|
||||
},
|
||||
|
||||
@ -373,7 +380,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
switch (gymName.toLowerCase()) {
|
||||
case LocationName.AevumCrushFitnessGym.toLowerCase():
|
||||
if (player.city != CityName.Aevum) {
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`You cannot workout at '${LocationName.AevumCrushFitnessGym}' because you are not in '${CityName.Aevum}'.`,
|
||||
);
|
||||
@ -383,7 +391,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
break;
|
||||
case LocationName.AevumSnapFitnessGym.toLowerCase():
|
||||
if (player.city != CityName.Aevum) {
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`You cannot workout at '${LocationName.AevumSnapFitnessGym}' because you are not in '${CityName.Aevum}'.`,
|
||||
);
|
||||
@ -393,7 +402,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
break;
|
||||
case LocationName.Sector12IronGym.toLowerCase():
|
||||
if (player.city != CityName.Sector12) {
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`You cannot workout at '${LocationName.Sector12IronGym}' because you are not in '${CityName.Sector12}'.`,
|
||||
);
|
||||
@ -403,7 +413,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
break;
|
||||
case LocationName.Sector12PowerhouseGym.toLowerCase():
|
||||
if (player.city != CityName.Sector12) {
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`You cannot workout at '${LocationName.Sector12PowerhouseGym}' because you are not in '${CityName.Sector12}'.`,
|
||||
);
|
||||
@ -413,7 +424,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
break;
|
||||
case LocationName.VolhavenMilleniumFitnessGym.toLowerCase():
|
||||
if (player.city != CityName.Volhaven) {
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`You cannot workout at '${LocationName.VolhavenMilleniumFitnessGym}' because you are not in '${CityName.Volhaven}'.`,
|
||||
);
|
||||
@ -422,7 +434,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
player.location = LocationName.VolhavenMilleniumFitnessGym;
|
||||
break;
|
||||
default:
|
||||
ctx.log(() => `Invalid gym name: ${gymName}. gymWorkout() failed`);
|
||||
helpers.log(ctx, () => `Invalid gym name: ${gymName}. gymWorkout() failed`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -452,7 +464,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
);
|
||||
break;
|
||||
default:
|
||||
ctx.log(() => `Invalid stat: ${stat}.`);
|
||||
helpers.log(ctx, () => `Invalid stat: ${stat}.`);
|
||||
return false;
|
||||
}
|
||||
if (focus) {
|
||||
@ -462,7 +474,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
player.stopFocusing();
|
||||
Router.toTerminal();
|
||||
}
|
||||
ctx.log(() => `Started training ${stat} at ${gymName}`);
|
||||
helpers.log(ctx, () => `Started training ${stat} at ${gymName}`);
|
||||
return true;
|
||||
},
|
||||
|
||||
@ -479,12 +491,12 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
case CityName.Ishima:
|
||||
case CityName.Volhaven:
|
||||
if (player.money < CONSTANTS.TravelCost) {
|
||||
ctx.log(() => "Not enough money to travel.");
|
||||
helpers.log(ctx, () => "Not enough money to travel.");
|
||||
return false;
|
||||
}
|
||||
player.loseMoney(CONSTANTS.TravelCost, "other");
|
||||
player.city = cityName;
|
||||
ctx.log(() => `Traveled to ${cityName}`);
|
||||
helpers.log(ctx, () => `Traveled to ${cityName}`);
|
||||
player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 50000);
|
||||
return true;
|
||||
default:
|
||||
@ -497,12 +509,12 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
|
||||
if (player.hasTorRouter()) {
|
||||
ctx.log(() => "You already have a TOR router!");
|
||||
helpers.log(ctx, () => "You already have a TOR router!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (player.money < CONSTANTS.TorRouterCost) {
|
||||
ctx.log(() => "You cannot afford to purchase a Tor router.");
|
||||
helpers.log(ctx, () => "You cannot afford to purchase a Tor router.");
|
||||
return false;
|
||||
}
|
||||
player.loseMoney(CONSTANTS.TorRouterCost, "other");
|
||||
@ -513,7 +525,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
player.getHomeComputer().serversOnNetwork.push(darkweb.hostname);
|
||||
darkweb.serversOnNetwork.push(player.getHomeComputer().hostname);
|
||||
player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 500);
|
||||
ctx.log(() => "You have purchased a Tor router!");
|
||||
helpers.log(ctx, () => "You have purchased a Tor router!");
|
||||
return true;
|
||||
},
|
||||
purchaseProgram: (ctx: NetscriptContext) =>
|
||||
@ -522,25 +534,26 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
const programName = helpers.string(ctx, "programName", _programName).toLowerCase();
|
||||
|
||||
if (!player.hasTorRouter()) {
|
||||
ctx.log(() => "You do not have the TOR router.");
|
||||
helpers.log(ctx, () => "You do not have the TOR router.");
|
||||
return false;
|
||||
}
|
||||
|
||||
const item = Object.values(DarkWebItems).find((i) => i.program.toLowerCase() === programName);
|
||||
if (item == null) {
|
||||
ctx.log(() => `Invalid program name: '${programName}.`);
|
||||
helpers.log(ctx, () => `Invalid program name: '${programName}.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.money < item.price) {
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `Not enough money to purchase '${item.program}'. Need ${numeralWrapper.formatMoney(item.price)}`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.hasProgram(item.program)) {
|
||||
ctx.log(() => `You already have the '${item.program}' program`);
|
||||
helpers.log(ctx, () => `You already have the '${item.program}' program`);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -551,7 +564,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
}
|
||||
|
||||
player.loseMoney(item.price, "other");
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `You have purchased the '${item.program}' program. The new program can be found on your home computer.`,
|
||||
);
|
||||
player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 5000);
|
||||
@ -621,7 +635,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const baseserver = player.getCurrentServer();
|
||||
if (!(baseserver instanceof Server)) {
|
||||
ctx.log(() => "cannot backdoor this kind of server");
|
||||
helpers.log(ctx, () => "cannot backdoor this kind of server");
|
||||
return Promise.resolve();
|
||||
}
|
||||
const server = baseserver;
|
||||
@ -633,12 +647,13 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, canHack.msg || "");
|
||||
}
|
||||
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `Installing backdoor on '${server.hostname}' in ${convertTimeMsToTimeElapsedString(installTime, true)}`,
|
||||
);
|
||||
|
||||
return helpers.netscriptDelay(ctx, installTime).then(function () {
|
||||
ctx.log(() => `Successfully installed backdoor on '${server.hostname}'`);
|
||||
helpers.log(ctx, () => `Successfully installed backdoor on '${server.hostname}'`);
|
||||
|
||||
server.backdoorInstalled = true;
|
||||
|
||||
@ -676,7 +691,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
function (): void {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
if (player.currentWork || Router.page() === Page.Infiltration || Router.page() === Page.BitVerse) {
|
||||
ctx.log(() => "Cannot go to the hospital because the player is busy.");
|
||||
helpers.log(ctx, () => "Cannot go to the hospital because the player is busy.");
|
||||
return;
|
||||
}
|
||||
player.hospitalize();
|
||||
@ -700,13 +715,13 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
// Check if we're at max cores
|
||||
const homeComputer = player.getHomeComputer();
|
||||
if (homeComputer.cpuCores >= 8) {
|
||||
ctx.log(() => `Your home computer is at max cores.`);
|
||||
helpers.log(ctx, () => `Your home computer is at max cores.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const cost = player.getUpgradeHomeCoresCost();
|
||||
if (player.money < cost) {
|
||||
ctx.log(() => `You don't have enough money. Need ${numeralWrapper.formatMoney(cost)}`);
|
||||
helpers.log(ctx, () => `You don't have enough money. Need ${numeralWrapper.formatMoney(cost)}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -714,7 +729,10 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
player.loseMoney(cost, "servers");
|
||||
|
||||
player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain * 2);
|
||||
ctx.log(() => `Purchased an additional core for home computer! It now has ${homeComputer.cpuCores} cores.`);
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `Purchased an additional core for home computer! It now has ${homeComputer.cpuCores} cores.`,
|
||||
);
|
||||
return true;
|
||||
},
|
||||
getUpgradeHomeCoresCost: (ctx: NetscriptContext) =>
|
||||
@ -730,13 +748,13 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
// Check if we're at max RAM
|
||||
const homeComputer = player.getHomeComputer();
|
||||
if (homeComputer.maxRam >= CONSTANTS.HomeComputerMaxRam) {
|
||||
ctx.log(() => `Your home computer is at max RAM.`);
|
||||
helpers.log(ctx, () => `Your home computer is at max RAM.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const cost = player.getUpgradeHomeRamCost();
|
||||
if (player.money < cost) {
|
||||
ctx.log(() => `You don't have enough money. Need ${numeralWrapper.formatMoney(cost)}`);
|
||||
helpers.log(ctx, () => `You don't have enough money. Need ${numeralWrapper.formatMoney(cost)}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -744,7 +762,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
player.loseMoney(cost, "servers");
|
||||
|
||||
player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain * 2);
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`Purchased additional RAM for home computer! It now has ${numeralWrapper.formatRAM(
|
||||
homeComputer.maxRam,
|
||||
@ -766,13 +785,13 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
|
||||
// Make sure its a valid company
|
||||
if (companyName == null || companyName === "" || !(Companies[companyName] instanceof Company)) {
|
||||
ctx.log(() => `Invalid company: '${companyName}'`);
|
||||
helpers.log(ctx, () => `Invalid company: '${companyName}'`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure player is actually employed at the comapny
|
||||
if (!Object.keys(player.jobs).includes(companyName)) {
|
||||
ctx.log(() => `You do not have a job at '${companyName}'`);
|
||||
helpers.log(ctx, () => `You do not have a job at '${companyName}'`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -780,7 +799,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
const companyPositionName = player.jobs[companyName];
|
||||
const companyPosition = CompanyPositions[companyPositionName];
|
||||
if (companyPositionName === "" || !(companyPosition instanceof CompanyPosition)) {
|
||||
ctx.log(() => "You do not have a job");
|
||||
helpers.log(ctx, () => "You do not have a job");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -799,7 +818,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
player.stopFocusing();
|
||||
Router.toTerminal();
|
||||
}
|
||||
ctx.log(() => `Began working at '${companyName}' as a '${companyPositionName}'`);
|
||||
helpers.log(ctx, () => `Began working at '${companyName}' as a '${companyPositionName}'`);
|
||||
return true;
|
||||
},
|
||||
applyToCompany: (ctx: NetscriptContext) =>
|
||||
@ -852,19 +871,19 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
res = player.applyForPartTimeWaiterJob(true);
|
||||
break;
|
||||
default:
|
||||
ctx.log(() => `Invalid job: '${field}'.`);
|
||||
helpers.log(ctx, () => `Invalid job: '${field}'.`);
|
||||
return false;
|
||||
}
|
||||
// TODO https://github.com/danielyxie/bitburner/issues/1378
|
||||
// The player object's applyForJob function can return string with special error messages
|
||||
// if (isString(res)) {
|
||||
// ctx.log("applyToCompany",()=> res);
|
||||
// helpers.log(ctx,"applyToCompany",()=> res);
|
||||
// return false;
|
||||
// }
|
||||
if (res) {
|
||||
ctx.log(() => `You were offered a new job at '${companyName}' as a '${player.jobs[companyName]}'`);
|
||||
helpers.log(ctx, () => `You were offered a new job at '${companyName}' as a '${player.jobs[companyName]}'`);
|
||||
} else {
|
||||
ctx.log(() => `You failed to get a new job/promotion at '${companyName}' in the '${field}' field.`);
|
||||
helpers.log(ctx, () => `You failed to get a new job/promotion at '${companyName}' in the '${field}' field.`);
|
||||
}
|
||||
return res;
|
||||
},
|
||||
@ -908,7 +927,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
getFaction(ctx, facName);
|
||||
|
||||
if (!player.factionInvitations.includes(facName)) {
|
||||
ctx.log(() => `You have not been invited by faction '${facName}'`);
|
||||
helpers.log(ctx, () => `You have not been invited by faction '${facName}'`);
|
||||
return false;
|
||||
}
|
||||
const fac = Factions[facName];
|
||||
@ -922,7 +941,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
}
|
||||
}
|
||||
player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain * 5);
|
||||
ctx.log(() => `Joined the '${facName}' faction.`);
|
||||
helpers.log(ctx, () => `Joined the '${facName}' faction.`);
|
||||
return true;
|
||||
},
|
||||
workForFaction: (ctx: NetscriptContext) =>
|
||||
@ -935,12 +954,12 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
|
||||
// if the player is in a gang and the target faction is any of the gang faction, fail
|
||||
if (player.inGang() && faction.name === player.getGangFaction().name) {
|
||||
ctx.log(() => `You can't work for '${facName}' because youre managing a gang for it`);
|
||||
helpers.log(ctx, () => `You can't work for '${facName}' because youre managing a gang for it`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!player.factions.includes(facName)) {
|
||||
ctx.log(() => `You are not a member of '${facName}'`);
|
||||
helpers.log(ctx, () => `You are not a member of '${facName}'`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -951,7 +970,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
case "hacking contracts":
|
||||
case "hackingcontracts":
|
||||
if (!FactionInfos[faction.name].offerHackingWork) {
|
||||
ctx.log(() => `Faction '${faction.name}' do not need help with hacking contracts.`);
|
||||
helpers.log(ctx, () => `Faction '${faction.name}' do not need help with hacking contracts.`);
|
||||
return false;
|
||||
}
|
||||
player.startWork(
|
||||
@ -968,13 +987,13 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
player.stopFocusing();
|
||||
Router.toTerminal();
|
||||
}
|
||||
ctx.log(() => `Started carrying out hacking contracts for '${faction.name}'`);
|
||||
helpers.log(ctx, () => `Started carrying out hacking contracts for '${faction.name}'`);
|
||||
return true;
|
||||
case "field":
|
||||
case "fieldwork":
|
||||
case "field work":
|
||||
if (!FactionInfos[faction.name].offerFieldWork) {
|
||||
ctx.log(() => `Faction '${faction.name}' do not need help with field missions.`);
|
||||
helpers.log(ctx, () => `Faction '${faction.name}' do not need help with field missions.`);
|
||||
return false;
|
||||
}
|
||||
player.startWork(
|
||||
@ -991,13 +1010,13 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
player.stopFocusing();
|
||||
Router.toTerminal();
|
||||
}
|
||||
ctx.log(() => `Started carrying out field missions for '${faction.name}'`);
|
||||
helpers.log(ctx, () => `Started carrying out field missions for '${faction.name}'`);
|
||||
return true;
|
||||
case "security":
|
||||
case "securitywork":
|
||||
case "security work":
|
||||
if (!FactionInfos[faction.name].offerSecurityWork) {
|
||||
ctx.log(() => `Faction '${faction.name}' do not need help with security work.`);
|
||||
helpers.log(ctx, () => `Faction '${faction.name}' do not need help with security work.`);
|
||||
return false;
|
||||
}
|
||||
player.startWork(
|
||||
@ -1014,10 +1033,10 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
player.stopFocusing();
|
||||
Router.toTerminal();
|
||||
}
|
||||
ctx.log(() => `Started carrying out security work for '${faction.name}'`);
|
||||
helpers.log(ctx, () => `Started carrying out security work for '${faction.name}'`);
|
||||
return true;
|
||||
default:
|
||||
ctx.log(() => `Invalid work type: '${type}`);
|
||||
helpers.log(ctx, () => `Invalid work type: '${type}`);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
@ -1049,28 +1068,32 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
const amt = helpers.number(ctx, "amt", _amt);
|
||||
const faction = getFaction(ctx, facName);
|
||||
if (!player.factions.includes(faction.name)) {
|
||||
ctx.log(() => `You can't donate to '${facName}' because you aren't a member`);
|
||||
helpers.log(ctx, () => `You can't donate to '${facName}' because you aren't a member`);
|
||||
return false;
|
||||
}
|
||||
if (player.inGang() && faction.name === player.getGangFaction().name) {
|
||||
ctx.log(() => `You can't donate to '${facName}' because youre managing a gang for it`);
|
||||
helpers.log(ctx, () => `You can't donate to '${facName}' because youre managing a gang for it`);
|
||||
return false;
|
||||
}
|
||||
if (faction.name === FactionNames.ChurchOfTheMachineGod || faction.name === FactionNames.Bladeburners) {
|
||||
ctx.log(() => `You can't donate to '${facName}' because they do not accept donations`);
|
||||
helpers.log(ctx, () => `You can't donate to '${facName}' because they do not accept donations`);
|
||||
return false;
|
||||
}
|
||||
if (typeof amt !== "number" || amt <= 0 || isNaN(amt)) {
|
||||
ctx.log(() => `Invalid donation amount: '${amt}'.`);
|
||||
helpers.log(ctx, () => `Invalid donation amount: '${amt}'.`);
|
||||
return false;
|
||||
}
|
||||
if (player.money < amt) {
|
||||
ctx.log(() => `You do not have enough money to donate ${numeralWrapper.formatMoney(amt)} to '${facName}'`);
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `You do not have enough money to donate ${numeralWrapper.formatMoney(amt)} to '${facName}'`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
const repNeededToDonate = Math.floor(CONSTANTS.BaseFavorToDonate * BitNodeMultipliers.RepToDonateToFaction);
|
||||
if (faction.favor < repNeededToDonate) {
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`You do not have enough favor to donate to this faction. Have ${faction.favor}, need ${repNeededToDonate}`,
|
||||
);
|
||||
@ -1079,7 +1102,8 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
const repGain = (amt / CONSTANTS.DonateMoneyToRepDivisor) * player.mults.faction_rep;
|
||||
faction.playerReputation += repGain;
|
||||
player.loseMoney(amt, "other");
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`${numeralWrapper.formatMoney(amt)} donated to '${facName}' for ${numeralWrapper.formatReputation(
|
||||
repGain,
|
||||
@ -1098,23 +1122,23 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
const p = Object.values(Programs).find((p) => p.name.toLowerCase() === programName);
|
||||
|
||||
if (p == null) {
|
||||
ctx.log(() => `The specified program does not exist: '${programName}`);
|
||||
helpers.log(ctx, () => `The specified program does not exist: '${programName}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.hasProgram(p.name)) {
|
||||
ctx.log(() => `You already have the '${p.name}' program`);
|
||||
helpers.log(ctx, () => `You already have the '${p.name}' program`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const create = p.create;
|
||||
if (create === null) {
|
||||
ctx.log(() => `You cannot create the '${p.name}' program`);
|
||||
helpers.log(ctx, () => `You cannot create the '${p.name}' program`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!create.req(player)) {
|
||||
ctx.log(() => `Hacking level is too low to create '${p.name}' (level ${create.level} req)`);
|
||||
helpers.log(ctx, () => `Hacking level is too low to create '${p.name}' (level ${create.level} req)`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1132,7 +1156,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
player.stopFocusing();
|
||||
Router.toTerminal();
|
||||
}
|
||||
ctx.log(() => `Began creating program: '${programName}'`);
|
||||
helpers.log(ctx, () => `Began creating program: '${programName}'`);
|
||||
return true;
|
||||
},
|
||||
commitCrime: (ctx: NetscriptContext) =>
|
||||
@ -1154,7 +1178,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
// couldn't find crime
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid crime: '${crimeRoughName}'`);
|
||||
}
|
||||
ctx.log(() => `Attempting to commit ${crime.name}...`);
|
||||
helpers.log(ctx, () => `Attempting to commit ${crime.name}...`);
|
||||
const crimeTime = crime.commit(player, 1, workerScript);
|
||||
if (focus) {
|
||||
player.startFocusing();
|
||||
@ -1195,7 +1219,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
|
||||
// If we don't have Tor, log it and return [] (empty list)
|
||||
if (!player.hasTorRouter()) {
|
||||
ctx.log(() => "You do not have the TOR router.");
|
||||
helpers.log(ctx, () => "You do not have the TOR router.");
|
||||
return [];
|
||||
}
|
||||
return Object.values(DarkWebItems).map((p) => p.program);
|
||||
@ -1207,7 +1231,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
|
||||
// If we don't have Tor, log it and return -1
|
||||
if (!player.hasTorRouter()) {
|
||||
ctx.log(() => "You do not have the TOR router.");
|
||||
helpers.log(ctx, () => "You do not have the TOR router.");
|
||||
// returning -1 rather than throwing an error to be consistent with purchaseProgram
|
||||
// which returns false if tor has
|
||||
return -1;
|
||||
@ -1228,7 +1252,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
}
|
||||
|
||||
if (player.hasProgram(item.program)) {
|
||||
ctx.log(() => `You already have the '${item.program}' program`);
|
||||
helpers.log(ctx, () => `You already have the '${item.program}' program`);
|
||||
return 0;
|
||||
}
|
||||
return item.price;
|
||||
@ -1269,7 +1293,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
|
||||
};
|
||||
|
||||
if (!hackingRequirements() && !bladeburnerRequirements()) {
|
||||
ctx.log(() => "Requirements not met to destroy the world daemon");
|
||||
helpers.log(ctx, () => "Requirements not met to destroy the world daemon");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ export function NetscriptSleeve(player: IPlayer): InternalAPI<ISleeve> {
|
||||
const checkSleeveNumber = function (ctx: NetscriptContext, sleeveNumber: number): void {
|
||||
if (sleeveNumber >= player.sleeves.length || sleeveNumber < 0) {
|
||||
const msg = `Invalid sleeve number: ${sleeveNumber}`;
|
||||
ctx.log(() => msg);
|
||||
helpers.log(ctx, () => msg);
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, msg);
|
||||
}
|
||||
};
|
||||
|
@ -55,20 +55,20 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript): In
|
||||
const time = staneksGift.inBonus() ? 200 : 1000;
|
||||
return helpers.netscriptDelay(ctx, time).then(function () {
|
||||
staneksGift.charge(player, fragment, workerScript.scriptRef.threads);
|
||||
ctx.log(() => `Charged fragment with ${ctx.workerScript.scriptRef.threads} threads.`);
|
||||
helpers.log(ctx, () => `Charged fragment with ${ctx.workerScript.scriptRef.threads} threads.`);
|
||||
return Promise.resolve();
|
||||
});
|
||||
},
|
||||
fragmentDefinitions: (ctx: NetscriptContext) =>
|
||||
function (): IFragment[] {
|
||||
checkStanekAPIAccess(ctx);
|
||||
ctx.log(() => `Returned ${Fragments.length} fragments`);
|
||||
helpers.log(ctx, () => `Returned ${Fragments.length} fragments`);
|
||||
return Fragments.map((f) => f.copy());
|
||||
},
|
||||
activeFragments: (ctx: NetscriptContext) =>
|
||||
function (): IActiveFragment[] {
|
||||
checkStanekAPIAccess(ctx);
|
||||
ctx.log(() => `Returned ${staneksGift.fragments.length} fragments`);
|
||||
helpers.log(ctx, () => `Returned ${staneksGift.fragments.length} fragments`);
|
||||
return staneksGift.fragments.map((af) => {
|
||||
return { ...af.copy(), ...af.fragment().copy() };
|
||||
});
|
||||
@ -76,7 +76,7 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript): In
|
||||
clearGift: (ctx: NetscriptContext) =>
|
||||
function (): void {
|
||||
checkStanekAPIAccess(ctx);
|
||||
ctx.log(() => `Cleared Stanek's Gift.`);
|
||||
helpers.log(ctx, () => `Cleared Stanek's Gift.`);
|
||||
staneksGift.clear();
|
||||
},
|
||||
canPlaceFragment: (ctx: NetscriptContext) =>
|
||||
@ -134,7 +134,8 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript): In
|
||||
!player.queuedAugmentations.some((a) => a.name === AugmentationNames.StaneksGift1)
|
||||
) {
|
||||
applyAugmentation({ name: AugmentationNames.StaneksGift1, level: 1 });
|
||||
ctx.log(
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `'${FactionNames.ChurchOfTheMachineGod}' joined and '${AugmentationNames.StaneksGift1}' installed.`,
|
||||
);
|
||||
}
|
||||
|
@ -371,69 +371,69 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
|
||||
},
|
||||
purchase4SMarketData: (ctx: NetscriptContext) => (): boolean => {
|
||||
if (player.has4SData) {
|
||||
ctx.log(() => "Already purchased 4S Market Data.");
|
||||
helpers.log(ctx, () => "Already purchased 4S Market Data.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (player.money < getStockMarket4SDataCost()) {
|
||||
ctx.log(() => "Not enough money to purchase 4S Market Data.");
|
||||
helpers.log(ctx, () => "Not enough money to purchase 4S Market Data.");
|
||||
return false;
|
||||
}
|
||||
|
||||
player.has4SData = true;
|
||||
player.loseMoney(getStockMarket4SDataCost(), "stock");
|
||||
ctx.log(() => "Purchased 4S Market Data");
|
||||
helpers.log(ctx, () => "Purchased 4S Market Data");
|
||||
return true;
|
||||
},
|
||||
purchase4SMarketDataTixApi: (ctx: NetscriptContext) => (): boolean => {
|
||||
checkTixApiAccess(ctx);
|
||||
|
||||
if (player.has4SDataTixApi) {
|
||||
ctx.log(() => "Already purchased 4S Market Data TIX API");
|
||||
helpers.log(ctx, () => "Already purchased 4S Market Data TIX API");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (player.money < getStockMarket4STixApiCost()) {
|
||||
ctx.log(() => "Not enough money to purchase 4S Market Data TIX API");
|
||||
helpers.log(ctx, () => "Not enough money to purchase 4S Market Data TIX API");
|
||||
return false;
|
||||
}
|
||||
|
||||
player.has4SDataTixApi = true;
|
||||
player.loseMoney(getStockMarket4STixApiCost(), "stock");
|
||||
ctx.log(() => "Purchased 4S Market Data TIX API");
|
||||
helpers.log(ctx, () => "Purchased 4S Market Data TIX API");
|
||||
return true;
|
||||
},
|
||||
purchaseWseAccount: (ctx: NetscriptContext) => (): boolean => {
|
||||
if (player.hasWseAccount) {
|
||||
ctx.log(() => "Already purchased WSE Account");
|
||||
helpers.log(ctx, () => "Already purchased WSE Account");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (player.money < getStockMarketWseCost()) {
|
||||
ctx.log(() => "Not enough money to purchase WSE Account Access");
|
||||
helpers.log(ctx, () => "Not enough money to purchase WSE Account Access");
|
||||
return false;
|
||||
}
|
||||
|
||||
player.hasWseAccount = true;
|
||||
initStockMarketFn();
|
||||
player.loseMoney(getStockMarketWseCost(), "stock");
|
||||
ctx.log(() => "Purchased WSE Account Access");
|
||||
helpers.log(ctx, () => "Purchased WSE Account Access");
|
||||
return true;
|
||||
},
|
||||
purchaseTixApi: (ctx: NetscriptContext) => (): boolean => {
|
||||
if (player.hasTixApiAccess) {
|
||||
ctx.log(() => "Already purchased TIX API");
|
||||
helpers.log(ctx, () => "Already purchased TIX API");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (player.money < getStockMarketTixApiCost()) {
|
||||
ctx.log(() => "Not enough money to purchase TIX API Access");
|
||||
helpers.log(ctx, () => "Not enough money to purchase TIX API Access");
|
||||
return false;
|
||||
}
|
||||
|
||||
player.hasTixApiAccess = true;
|
||||
player.loseMoney(getStockMarketTixApiCost(), "stock");
|
||||
ctx.log(() => "Purchased TIX API");
|
||||
helpers.log(ctx, () => "Purchased TIX API");
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
@ -12,6 +12,7 @@ import { CONSTANTS } from "../Constants";
|
||||
import { hash } from "../hash/hash";
|
||||
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
import { Terminal } from "../../src/Terminal";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
|
||||
export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
||||
return {
|
||||
@ -43,9 +44,9 @@ export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
||||
if (errors.length === 0) {
|
||||
Object.assign(Settings.theme, currentTheme);
|
||||
ThemeEvents.emit();
|
||||
ctx.log(() => `Successfully set theme`);
|
||||
helpers.log(ctx, () => `Successfully set theme`);
|
||||
} else {
|
||||
ctx.log(() => `Failed to set theme. Errors: ${errors.join(", ")}`);
|
||||
helpers.log(ctx, () => `Failed to set theme. Errors: ${errors.join(", ")}`);
|
||||
}
|
||||
},
|
||||
|
||||
@ -66,22 +67,22 @@ export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
||||
if (errors.length === 0) {
|
||||
Object.assign(Settings.styles, currentStyles);
|
||||
ThemeEvents.emit();
|
||||
ctx.log(() => `Successfully set styles`);
|
||||
helpers.log(ctx, () => `Successfully set styles`);
|
||||
} else {
|
||||
ctx.log(() => `Failed to set styles. Errors: ${errors.join(", ")}`);
|
||||
helpers.log(ctx, () => `Failed to set styles. Errors: ${errors.join(", ")}`);
|
||||
}
|
||||
},
|
||||
|
||||
resetTheme: (ctx: NetscriptContext) => (): void => {
|
||||
Settings.theme = { ...defaultTheme };
|
||||
ThemeEvents.emit();
|
||||
ctx.log(() => `Reinitialized theme to default`);
|
||||
helpers.log(ctx, () => `Reinitialized theme to default`);
|
||||
},
|
||||
|
||||
resetStyles: (ctx: NetscriptContext) => (): void => {
|
||||
Settings.styles = { ...defaultStyles };
|
||||
ThemeEvents.emit();
|
||||
ctx.log(() => `Reinitialized styles to default`);
|
||||
helpers.log(ctx, () => `Reinitialized styles to default`);
|
||||
},
|
||||
|
||||
getGameInfo: () => (): GameInfo => {
|
||||
@ -99,7 +100,7 @@ export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
||||
},
|
||||
|
||||
clearTerminal: (ctx: NetscriptContext) => (): void => {
|
||||
ctx.log(() => `Clearing terminal`);
|
||||
helpers.log(ctx, () => `Clearing terminal`);
|
||||
Terminal.clear();
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user