mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-01-02 19:37:34 +01:00
most anys in NetFunc
This commit is contained in:
parent
7dacf947bd
commit
70d5390e4d
@ -256,8 +256,13 @@ v2.0.0 - 2022-07-19 Work rework
|
|||||||
* Backdooring company server reduces faction requirement to 300k.
|
* Backdooring company server reduces faction requirement to 300k.
|
||||||
* All work generally no longer keep track of cumulative gains like exp and reputation since it's applied instantly.
|
* All work generally no longer keep track of cumulative gains like exp and reputation since it's applied instantly.
|
||||||
* getPlayer returns way less fields but does return the new 'currentWork' field.
|
* getPlayer returns way less fields but does return the new 'currentWork' field.
|
||||||
|
|
||||||
|
API breaks
|
||||||
|
|
||||||
* workForCompany argument 'companyName' is now not-optional
|
* workForCompany argument 'companyName' is now not-optional
|
||||||
* commitCrime now has 'focus' optional parameter
|
* commitCrime now has 'focus' optional parameter
|
||||||
|
* using getScriptIncome to get total income has been separated to getTotalScriptIncome.
|
||||||
|
* using getScriptExpGain to get total income has been separated to getTotalScriptExpGain.
|
||||||
|
|
||||||
Multipliers
|
Multipliers
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import { FormulaGang } from "../Gang/formulas/formulas";
|
|||||||
import { INetscriptHelper, ScriptIdentifier } from "../NetscriptFunctions/INetscriptHelper";
|
import { INetscriptHelper, ScriptIdentifier } from "../NetscriptFunctions/INetscriptHelper";
|
||||||
import { GangMember } from "../Gang/GangMember";
|
import { GangMember } from "../Gang/GangMember";
|
||||||
import { GangMemberTask } from "../Gang/GangMemberTask";
|
import { GangMemberTask } from "../Gang/GangMemberTask";
|
||||||
|
import { ScriptArg } from "./ScriptArg";
|
||||||
|
|
||||||
type ExternalFunction = (...args: unknown[]) => unknown;
|
type ExternalFunction = (...args: unknown[]) => unknown;
|
||||||
export type ExternalAPI = {
|
export type ExternalAPI = {
|
||||||
@ -47,6 +48,7 @@ type WrappedNetscriptHelpers = {
|
|||||||
number: (argName: string, v: unknown) => number;
|
number: (argName: string, v: unknown) => number;
|
||||||
ustring: (argName: string, v: unknown) => string | undefined;
|
ustring: (argName: string, v: unknown) => string | undefined;
|
||||||
unumber: (argName: string, v: unknown) => number | undefined;
|
unumber: (argName: string, v: unknown) => number | undefined;
|
||||||
|
scriptArgs(args: unknown): ScriptArg[];
|
||||||
scriptIdentifier: (fn: unknown, hostname: unknown, args: unknown) => ScriptIdentifier;
|
scriptIdentifier: (fn: unknown, hostname: unknown, args: unknown) => ScriptIdentifier;
|
||||||
city: (argName: string, v: unknown) => CityName;
|
city: (argName: string, v: unknown) => CityName;
|
||||||
boolean: (v: unknown) => boolean;
|
boolean: (v: unknown) => boolean;
|
||||||
@ -88,6 +90,7 @@ function wrapFunction(
|
|||||||
number: (argName: string, v: unknown) => helpers.number(functionPath, argName, v),
|
number: (argName: string, v: unknown) => helpers.number(functionPath, argName, v),
|
||||||
ustring: (argName: string, v: unknown) => helpers.string(functionPath, argName, v),
|
ustring: (argName: string, v: unknown) => helpers.string(functionPath, argName, v),
|
||||||
unumber: (argName: string, v: unknown) => helpers.number(functionPath, argName, v),
|
unumber: (argName: string, v: unknown) => helpers.number(functionPath, argName, v),
|
||||||
|
scriptArgs: (v: unknown) => helpers.scriptArgs(functionPath, v),
|
||||||
scriptIdentifier: (fn: unknown, hostname: unknown, args: unknown) =>
|
scriptIdentifier: (fn: unknown, hostname: unknown, args: unknown) =>
|
||||||
helpers.scriptIdentifier(functionPath, fn, hostname, args),
|
helpers.scriptIdentifier(functionPath, fn, hostname, args),
|
||||||
city: (argName: string, v: unknown) => helpers.city(functionPath, argName, v),
|
city: (argName: string, v: unknown) => helpers.city(functionPath, argName, v),
|
||||||
|
@ -505,7 +505,9 @@ const SourceRamCosts = {
|
|||||||
getHackTime: RamCostConstants.ScriptGetHackTimeRamCost,
|
getHackTime: RamCostConstants.ScriptGetHackTimeRamCost,
|
||||||
getGrowTime: RamCostConstants.ScriptGetHackTimeRamCost,
|
getGrowTime: RamCostConstants.ScriptGetHackTimeRamCost,
|
||||||
getWeakenTime: RamCostConstants.ScriptGetHackTimeRamCost,
|
getWeakenTime: RamCostConstants.ScriptGetHackTimeRamCost,
|
||||||
|
getTotalScriptIncome: RamCostConstants.ScriptGetScriptRamCost,
|
||||||
getScriptIncome: RamCostConstants.ScriptGetScriptRamCost,
|
getScriptIncome: RamCostConstants.ScriptGetScriptRamCost,
|
||||||
|
getTotalScriptExpGain: RamCostConstants.ScriptGetScriptRamCost,
|
||||||
getScriptExpGain: RamCostConstants.ScriptGetScriptRamCost,
|
getScriptExpGain: RamCostConstants.ScriptGetScriptRamCost,
|
||||||
getRunningScript: RamCostConstants.ScriptGetRunningScriptRamCost,
|
getRunningScript: RamCostConstants.ScriptGetRunningScriptRamCost,
|
||||||
nFormat: 0,
|
nFormat: 0,
|
||||||
|
@ -499,6 +499,15 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
throw makeRuntimeErrorMsg(funcName, `'${argName}' should be a number.`);
|
throw makeRuntimeErrorMsg(funcName, `'${argName}' should be a number.`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isScriptArgs = (_args: unknown): _args is ScriptArg[] =>
|
||||||
|
Array.isArray(_args) &&
|
||||||
|
_args.every((a) => typeof a === "string" || typeof a === "number" || typeof a === "boolean");
|
||||||
|
|
||||||
|
const helperScriptArgs = (funcName: string, args: unknown): ScriptArg[] => {
|
||||||
|
if (!isScriptArgs(args)) throw makeRuntimeErrorMsg(funcName, "'args' is not an array of script args");
|
||||||
|
return args as ScriptArg[];
|
||||||
|
};
|
||||||
|
|
||||||
const helper: INetscriptHelper = {
|
const helper: INetscriptHelper = {
|
||||||
updateDynamicRam: updateDynamicRam,
|
updateDynamicRam: updateDynamicRam,
|
||||||
makeRuntimeErrorMsg: makeRuntimeErrorMsg,
|
makeRuntimeErrorMsg: makeRuntimeErrorMsg,
|
||||||
@ -512,11 +521,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
if (v === undefined) return undefined;
|
if (v === undefined) return undefined;
|
||||||
return helperNumber(funcName, argName, v);
|
return helperNumber(funcName, argName, v);
|
||||||
},
|
},
|
||||||
|
scriptArgs: helperScriptArgs,
|
||||||
scriptIdentifier: (funcName: string, _fn: unknown, _hostname: unknown, _args: unknown): ScriptIdentifier => {
|
scriptIdentifier: (funcName: string, _fn: unknown, _hostname: unknown, _args: unknown): ScriptIdentifier => {
|
||||||
const isScriptArgs = (_args: unknown): _args is ScriptArg[] =>
|
|
||||||
Array.isArray(_args) &&
|
|
||||||
_args.every((a) => typeof a === "string" || typeof a === "number" || typeof a === "boolean");
|
|
||||||
|
|
||||||
if (_fn === undefined) return workerScript.pid;
|
if (_fn === undefined) return workerScript.pid;
|
||||||
if (typeof _fn === "number") return _fn;
|
if (typeof _fn === "number") return _fn;
|
||||||
if (typeof _fn === "string") {
|
if (typeof _fn === "string") {
|
||||||
@ -1181,9 +1187,10 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
},
|
},
|
||||||
run:
|
run:
|
||||||
(ctx: NetscriptContext) =>
|
(ctx: NetscriptContext) =>
|
||||||
(_scriptname: unknown, _threads: unknown = 1, ...args: any[]): number => {
|
(_scriptname: unknown, _threads: unknown = 1, ..._args: unknown[]): number => {
|
||||||
const scriptname = ctx.helper.string("scriptname", _scriptname);
|
const scriptname = ctx.helper.string("scriptname", _scriptname);
|
||||||
const threads = ctx.helper.number("threads", _threads);
|
const threads = ctx.helper.number("threads", _threads);
|
||||||
|
const args = ctx.helper.scriptArgs(_args);
|
||||||
if (scriptname === undefined) {
|
if (scriptname === undefined) {
|
||||||
throw ctx.makeRuntimeErrorMsg("Usage: run(scriptname, [numThreads], [arg1], [arg2]...)");
|
throw ctx.makeRuntimeErrorMsg("Usage: run(scriptname, [numThreads], [arg1], [arg2]...)");
|
||||||
}
|
}
|
||||||
@ -1199,10 +1206,11 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
},
|
},
|
||||||
exec:
|
exec:
|
||||||
(ctx: NetscriptContext) =>
|
(ctx: NetscriptContext) =>
|
||||||
(_scriptname: unknown, _hostname: unknown, _threads: unknown = 1, ...args: any[]): number => {
|
(_scriptname: unknown, _hostname: unknown, _threads: unknown = 1, ..._args: unknown[]): number => {
|
||||||
const scriptname = ctx.helper.string("scriptname", _scriptname);
|
const scriptname = ctx.helper.string("scriptname", _scriptname);
|
||||||
const hostname = ctx.helper.string("hostname", _hostname);
|
const hostname = ctx.helper.string("hostname", _hostname);
|
||||||
const threads = ctx.helper.number("threads", _threads);
|
const threads = ctx.helper.number("threads", _threads);
|
||||||
|
const args = ctx.helper.scriptArgs(_args);
|
||||||
if (scriptname === undefined || hostname === undefined) {
|
if (scriptname === undefined || hostname === undefined) {
|
||||||
throw ctx.makeRuntimeErrorMsg("Usage: exec(scriptname, server, [numThreads], [arg1], [arg2]...)");
|
throw ctx.makeRuntimeErrorMsg("Usage: exec(scriptname, server, [numThreads], [arg1], [arg2]...)");
|
||||||
}
|
}
|
||||||
@ -1214,9 +1222,10 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
},
|
},
|
||||||
spawn:
|
spawn:
|
||||||
(ctx: NetscriptContext) =>
|
(ctx: NetscriptContext) =>
|
||||||
(_scriptname: unknown, _threads: unknown = 1, ...args: any[]): void => {
|
(_scriptname: unknown, _threads: unknown = 1, ..._args: unknown[]): void => {
|
||||||
const scriptname = ctx.helper.string("scriptname", _scriptname);
|
const scriptname = ctx.helper.string("scriptname", _scriptname);
|
||||||
const threads = ctx.helper.number("threads", _threads);
|
const threads = ctx.helper.number("threads", _threads);
|
||||||
|
const args = ctx.helper.scriptArgs(_args);
|
||||||
if (!scriptname || !threads) {
|
if (!scriptname || !threads) {
|
||||||
throw ctx.makeRuntimeErrorMsg("Usage: spawn(scriptname, threads)");
|
throw ctx.makeRuntimeErrorMsg("Usage: spawn(scriptname, threads)");
|
||||||
}
|
}
|
||||||
@ -1314,12 +1323,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
},
|
},
|
||||||
scp:
|
scp:
|
||||||
(ctx: NetscriptContext) =>
|
(ctx: NetscriptContext) =>
|
||||||
async (scriptname: any, _hostname1: unknown, _hostname2?: unknown): Promise<boolean> => {
|
async (_scriptname: unknown, _hostname1: unknown, _hostname2?: unknown): Promise<boolean> => {
|
||||||
const hostname1 = ctx.helper.string("hostname1", _hostname1);
|
const hostname1 = ctx.helper.string("hostname1", _hostname1);
|
||||||
const hostname2 = ctx.helper.ustring("hostname2", _hostname2);
|
const hostname2 = ctx.helper.ustring("hostname2", _hostname2);
|
||||||
if (scriptname && scriptname.constructor === Array) {
|
if (Array.isArray(_scriptname)) {
|
||||||
// Recursively call scp on all elements of array
|
// Recursively call scp on all elements of array
|
||||||
const scripts: string[] = scriptname;
|
const scripts: string[] = _scriptname;
|
||||||
if (scripts.length === 0) {
|
if (scripts.length === 0) {
|
||||||
throw ctx.makeRuntimeErrorMsg("No scripts to copy");
|
throw ctx.makeRuntimeErrorMsg("No scripts to copy");
|
||||||
}
|
}
|
||||||
@ -1334,13 +1343,15 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return Promise.resolve(res);
|
return Promise.resolve(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const scriptName = ctx.helper.string("scriptName", _scriptname);
|
||||||
|
|
||||||
// Invalid file type
|
// Invalid file type
|
||||||
if (!isValidFilePath(scriptname)) {
|
if (!isValidFilePath(scriptName)) {
|
||||||
throw ctx.makeRuntimeErrorMsg(`Invalid filename: '${scriptname}'`);
|
throw ctx.makeRuntimeErrorMsg(`Invalid filename: '${scriptName}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invalid file name
|
// Invalid file name
|
||||||
if (!scriptname.endsWith(".lit") && !isScriptFilename(scriptname) && !scriptname.endsWith("txt")) {
|
if (!scriptName.endsWith(".lit") && !isScriptFilename(scriptName) && !scriptName.endsWith("txt")) {
|
||||||
throw ctx.makeRuntimeErrorMsg("Only works for scripts, .lit and .txt files");
|
throw ctx.makeRuntimeErrorMsg("Only works for scripts, .lit and .txt files");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1349,14 +1360,14 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
|
|
||||||
if (hostname2 != null) {
|
if (hostname2 != null) {
|
||||||
// 3 Argument version: scriptname, source, destination
|
// 3 Argument version: scriptname, source, destination
|
||||||
if (scriptname === undefined || hostname1 === undefined || hostname2 === undefined) {
|
if (scriptName === undefined || hostname1 === undefined || hostname2 === undefined) {
|
||||||
throw ctx.makeRuntimeErrorMsg("Takes 2 or 3 arguments");
|
throw ctx.makeRuntimeErrorMsg("Takes 2 or 3 arguments");
|
||||||
}
|
}
|
||||||
destServer = safeGetServer(hostname2, ctx);
|
destServer = safeGetServer(hostname2, ctx);
|
||||||
currServ = safeGetServer(hostname1, ctx);
|
currServ = safeGetServer(hostname1, ctx);
|
||||||
} else if (hostname1 != null) {
|
} else if (hostname1 != null) {
|
||||||
// 2 Argument version: scriptname, destination
|
// 2 Argument version: scriptname, destination
|
||||||
if (scriptname === undefined || hostname1 === undefined) {
|
if (scriptName === undefined || hostname1 === undefined) {
|
||||||
throw ctx.makeRuntimeErrorMsg("Takes 2 or 3 arguments");
|
throw ctx.makeRuntimeErrorMsg("Takes 2 or 3 arguments");
|
||||||
}
|
}
|
||||||
destServer = safeGetServer(hostname1, ctx);
|
destServer = safeGetServer(hostname1, ctx);
|
||||||
@ -1371,76 +1382,76 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scp for lit files
|
// Scp for lit files
|
||||||
if (scriptname.endsWith(".lit")) {
|
if (scriptName.endsWith(".lit")) {
|
||||||
let found = false;
|
let found = false;
|
||||||
for (let i = 0; i < currServ.messages.length; ++i) {
|
for (let i = 0; i < currServ.messages.length; ++i) {
|
||||||
if (currServ.messages[i] == scriptname) {
|
if (currServ.messages[i] == scriptName) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
ctx.log(() => `File '${scriptname}' does not exist.`);
|
ctx.log(() => `File '${scriptName}' does not exist.`);
|
||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < destServer.messages.length; ++i) {
|
for (let i = 0; i < destServer.messages.length; ++i) {
|
||||||
if (destServer.messages[i] === scriptname) {
|
if (destServer.messages[i] === scriptName) {
|
||||||
ctx.log(() => `File '${scriptname}' copied over to '${destServer?.hostname}'.`);
|
ctx.log(() => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||||
return Promise.resolve(true); // Already exists
|
return Promise.resolve(true); // Already exists
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
destServer.messages.push(scriptname);
|
destServer.messages.push(scriptName);
|
||||||
ctx.log(() => `File '${scriptname}' copied over to '${destServer?.hostname}'.`);
|
ctx.log(() => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scp for text files
|
// Scp for text files
|
||||||
if (scriptname.endsWith(".txt")) {
|
if (scriptName.endsWith(".txt")) {
|
||||||
let txtFile;
|
let txtFile;
|
||||||
for (let i = 0; i < currServ.textFiles.length; ++i) {
|
for (let i = 0; i < currServ.textFiles.length; ++i) {
|
||||||
if (currServ.textFiles[i].fn === scriptname) {
|
if (currServ.textFiles[i].fn === scriptName) {
|
||||||
txtFile = currServ.textFiles[i];
|
txtFile = currServ.textFiles[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (txtFile === undefined) {
|
if (txtFile === undefined) {
|
||||||
ctx.log(() => `File '${scriptname}' does not exist.`);
|
ctx.log(() => `File '${scriptName}' does not exist.`);
|
||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < destServer.textFiles.length; ++i) {
|
for (let i = 0; i < destServer.textFiles.length; ++i) {
|
||||||
if (destServer.textFiles[i].fn === scriptname) {
|
if (destServer.textFiles[i].fn === scriptName) {
|
||||||
// Overwrite
|
// Overwrite
|
||||||
destServer.textFiles[i].text = txtFile.text;
|
destServer.textFiles[i].text = txtFile.text;
|
||||||
ctx.log(() => `File '${scriptname}' copied over to '${destServer?.hostname}'.`);
|
ctx.log(() => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const newFile = new TextFile(txtFile.fn, txtFile.text);
|
const newFile = new TextFile(txtFile.fn, txtFile.text);
|
||||||
destServer.textFiles.push(newFile);
|
destServer.textFiles.push(newFile);
|
||||||
ctx.log(() => `File '${scriptname}' copied over to '${destServer?.hostname}'.`);
|
ctx.log(() => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scp for script files
|
// Scp for script files
|
||||||
let sourceScript = null;
|
let sourceScript = null;
|
||||||
for (let i = 0; i < currServ.scripts.length; ++i) {
|
for (let i = 0; i < currServ.scripts.length; ++i) {
|
||||||
if (scriptname == currServ.scripts[i].filename) {
|
if (scriptName == currServ.scripts[i].filename) {
|
||||||
sourceScript = currServ.scripts[i];
|
sourceScript = currServ.scripts[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sourceScript == null) {
|
if (sourceScript == null) {
|
||||||
ctx.log(() => `File '${scriptname}' does not exist.`);
|
ctx.log(() => `File '${scriptName}' does not exist.`);
|
||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overwrite script if it already exists
|
// Overwrite script if it already exists
|
||||||
for (let i = 0; i < destServer.scripts.length; ++i) {
|
for (let i = 0; i < destServer.scripts.length; ++i) {
|
||||||
if (scriptname == destServer.scripts[i].filename) {
|
if (scriptName == destServer.scripts[i].filename) {
|
||||||
ctx.log(() => `WARNING: File '${scriptname}' overwritten on '${destServer?.hostname}'`);
|
ctx.log(() => `WARNING: File '${scriptName}' overwritten on '${destServer?.hostname}'`);
|
||||||
const oldScript = destServer.scripts[i];
|
const oldScript = destServer.scripts[i];
|
||||||
// If it's the exact same file don't actually perform the
|
// If it's the exact same file don't actually perform the
|
||||||
// copy to avoid recompiling uselessly. Players tend to scp
|
// copy to avoid recompiling uselessly. Players tend to scp
|
||||||
@ -1454,12 +1465,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create new script if it does not already exist
|
// Create new script if it does not already exist
|
||||||
const newScript = new Script(Player, scriptname);
|
const newScript = new Script(Player, scriptName);
|
||||||
newScript.code = sourceScript.code;
|
newScript.code = sourceScript.code;
|
||||||
newScript.ramUsage = sourceScript.ramUsage;
|
newScript.ramUsage = sourceScript.ramUsage;
|
||||||
newScript.server = destServer.hostname;
|
newScript.server = destServer.hostname;
|
||||||
destServer.scripts.push(newScript);
|
destServer.scripts.push(newScript);
|
||||||
ctx.log(() => `File '${scriptname}' copied over to '${destServer?.hostname}'.`);
|
ctx.log(() => `File '${scriptName}' copied over to '${destServer?.hostname}'.`);
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (destServer === null) {
|
if (destServer === null) {
|
||||||
resolve(false);
|
resolve(false);
|
||||||
@ -2263,10 +2274,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
|
|
||||||
return calculateWeakenTime(server, Player) * 1000;
|
return calculateWeakenTime(server, Player) * 1000;
|
||||||
},
|
},
|
||||||
getScriptIncome:
|
getTotalScriptIncome: () => (): [number, number] => {
|
||||||
(ctx: NetscriptContext) =>
|
|
||||||
(scriptname?: any, hostname?: any, ...args: any[]): any => {
|
|
||||||
if (scriptname === undefined) {
|
|
||||||
// First element is total income of all currently running scripts
|
// First element is total income of all currently running scripts
|
||||||
let total = 0;
|
let total = 0;
|
||||||
for (const script of workerScripts.values()) {
|
for (const script of workerScripts.values()) {
|
||||||
@ -2274,36 +2282,35 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [total, Player.scriptProdSinceLastAug / (Player.playtimeSinceLastAug / 1000)];
|
return [total, Player.scriptProdSinceLastAug / (Player.playtimeSinceLastAug / 1000)];
|
||||||
} else {
|
},
|
||||||
// Get income for a particular script
|
getScriptIncome:
|
||||||
const server = safeGetServer(hostname, ctx);
|
(ctx: NetscriptContext) =>
|
||||||
const runningScriptObj = findRunningScript(scriptname, args, server);
|
(fn: unknown, hostname: unknown, ...args: unknown[]): number => {
|
||||||
if (runningScriptObj == null) {
|
const ident = ctx.helper.scriptIdentifier(fn, hostname, args);
|
||||||
ctx.log(() => `No such script '${scriptname}' on '${server.hostname}' with args: ${arrayToString(args)}`);
|
const runningScript = getRunningScript(ctx, ident);
|
||||||
|
if (runningScript == null) {
|
||||||
|
ctx.log(() => getCannotFindRunningScriptErrorMessage(ident));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return runningScriptObj.onlineMoneyMade / runningScriptObj.onlineRunningTime;
|
return runningScript.onlineMoneyMade / runningScript.onlineRunningTime;
|
||||||
}
|
|
||||||
},
|
},
|
||||||
getScriptExpGain:
|
getTotalScriptExpGain: () => (): number => {
|
||||||
(ctx: NetscriptContext) =>
|
|
||||||
(scriptname?: any, hostname?: any, ...args: any[]): number => {
|
|
||||||
if (scriptname === undefined) {
|
|
||||||
let total = 0;
|
let total = 0;
|
||||||
for (const ws of workerScripts.values()) {
|
for (const ws of workerScripts.values()) {
|
||||||
total += ws.scriptRef.onlineExpGained / ws.scriptRef.onlineRunningTime;
|
total += ws.scriptRef.onlineExpGained / ws.scriptRef.onlineRunningTime;
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
} else {
|
},
|
||||||
// Get income for a particular script
|
getScriptExpGain:
|
||||||
const server = safeGetServer(hostname, ctx);
|
(ctx: NetscriptContext) =>
|
||||||
const runningScriptObj = findRunningScript(scriptname, args, server);
|
(fn: unknown, hostname: unknown, ...args: unknown[]): number => {
|
||||||
if (runningScriptObj == null) {
|
const ident = ctx.helper.scriptIdentifier(fn, hostname, args);
|
||||||
ctx.log(() => `No such script '${scriptname}' on '${server.hostname}' with args: ${arrayToString(args)}`);
|
const runningScript = getRunningScript(ctx, ident);
|
||||||
|
if (runningScript == null) {
|
||||||
|
ctx.log(() => getCannotFindRunningScriptErrorMessage(ident));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return runningScriptObj.onlineExpGained / runningScriptObj.onlineRunningTime;
|
return runningScript.onlineExpGained / runningScript.onlineRunningTime;
|
||||||
}
|
|
||||||
},
|
},
|
||||||
nFormat:
|
nFormat:
|
||||||
(ctx: NetscriptContext) =>
|
(ctx: NetscriptContext) =>
|
||||||
|
@ -25,6 +25,7 @@ export interface INetscriptHelper {
|
|||||||
number(funcName: string, argName: string, v: unknown): number;
|
number(funcName: string, argName: string, v: unknown): number;
|
||||||
ustring(funcName: string, argName: string, v: unknown): string | undefined;
|
ustring(funcName: string, argName: string, v: unknown): string | undefined;
|
||||||
unumber(funcName: string, argName: string, v: unknown): number | undefined;
|
unumber(funcName: string, argName: string, v: unknown): number | undefined;
|
||||||
|
scriptArgs(funcName: string, args: unknown): ScriptArg[];
|
||||||
scriptIdentifier(funcName: string, fn: unknown, hostname: unknown, args: unknown): ScriptIdentifier;
|
scriptIdentifier(funcName: string, fn: unknown, hostname: unknown, args: unknown): ScriptIdentifier;
|
||||||
city(funcName: string, argName: string, v: unknown): CityName;
|
city(funcName: string, argName: string, v: unknown): CityName;
|
||||||
boolean(v: unknown): boolean;
|
boolean(v: unknown): boolean;
|
||||||
|
35
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
35
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -6202,6 +6202,19 @@ export interface NS {
|
|||||||
*/
|
*/
|
||||||
getWeakenTime(host: string): number;
|
getWeakenTime(host: string): number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the income of all script.
|
||||||
|
* @remarks
|
||||||
|
* RAM cost: 0.1 GB
|
||||||
|
*
|
||||||
|
* @returns an array of two values.
|
||||||
|
* The first value is the total income (dollar / second) of all of your active scripts
|
||||||
|
* (scripts that are currently running on any server).
|
||||||
|
* The second value is the total income (dollar / second) that you’ve earned from scripts
|
||||||
|
* since you last installed Augmentations.
|
||||||
|
*/
|
||||||
|
getTotalScriptIncome(): [number, number];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the income of a script.
|
* Get the income of a script.
|
||||||
* @remarks
|
* @remarks
|
||||||
@ -6214,24 +6227,21 @@ export interface NS {
|
|||||||
* in order to use this function to get that script’s income you must specify
|
* in order to use this function to get that script’s income you must specify
|
||||||
* those same arguments in the same order in this function call.
|
* those same arguments in the same order in this function call.
|
||||||
*
|
*
|
||||||
* This function can also be called with no arguments.
|
|
||||||
* If called with no arguments, then this function will return an array of two values.
|
|
||||||
* The first value is the total income (dollar / second) of all of your active scripts
|
|
||||||
* (scripts that are currently running on any server).
|
|
||||||
* The second value is the total income (dollar / second) that you’ve earned from scripts
|
|
||||||
* since you last installed Augmentations.
|
|
||||||
*
|
|
||||||
* @param script - Filename of script.
|
* @param script - Filename of script.
|
||||||
* @param host - Server on which script is running.
|
* @param host - Server on which script is running.
|
||||||
* @param args - Arguments that the script is running with.
|
* @param args - Arguments that the script is running with.
|
||||||
* @returns Amount of income the specified script generates while online.
|
* @returns Amount of income the specified script generates while online.
|
||||||
*/
|
*/
|
||||||
getScriptIncome(): [number, number];
|
getScriptIncome(script: string, host: string, ...args: (string | number | boolean)[]): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc NS.(getScriptIncome:1)}
|
* Get the exp gain of all script.
|
||||||
|
* @remarks
|
||||||
|
* RAM cost: 0.1 GB
|
||||||
|
*
|
||||||
|
* @returns total experience gain rate of all of your active scripts.
|
||||||
*/
|
*/
|
||||||
getScriptIncome(script: string, host: string, ...args: (string | number | boolean)[]): number;
|
getTotalScriptExpGain(): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the exp gain of a script.
|
* Get the exp gain of a script.
|
||||||
@ -6250,11 +6260,6 @@ export interface NS {
|
|||||||
* @param args - Arguments that the script is running with.
|
* @param args - Arguments that the script is running with.
|
||||||
* @returns Amount of hacking experience the specified script generates while online.
|
* @returns Amount of hacking experience the specified script generates while online.
|
||||||
*/
|
*/
|
||||||
getScriptExpGain(): number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc NS.(getScriptExpGain:1)}
|
|
||||||
*/
|
|
||||||
getScriptExpGain(script: string, host: string, ...args: (string | number | boolean)[]): number;
|
getScriptExpGain(script: string, host: string, ...args: (string | number | boolean)[]): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user