mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-23 17:53:00 +02:00
NETSCRIPT: Add growThreads to formulas, improve docs for hacking functions (#330)
This commit is contained in:
@@ -297,22 +297,27 @@ export const ns: InternalAPI<NSFull> = {
|
||||
},
|
||||
growthAnalyze:
|
||||
(ctx) =>
|
||||
(_hostname, _growth, _cores = 1) => {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const growth = helpers.number(ctx, "growth", _growth);
|
||||
(_host, _multiplier, _cores = 1) => {
|
||||
const host = helpers.string(ctx, "hostname", _host);
|
||||
const mult = helpers.number(ctx, "multiplier", _multiplier);
|
||||
const cores = helpers.number(ctx, "cores", _cores);
|
||||
|
||||
// Check argument validity
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
const server = helpers.getServer(ctx, host);
|
||||
if (!(server instanceof Server)) {
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
// Todo 2.3: Make this throw instead of returning 0?
|
||||
helpers.log(ctx, () => `${host} is not a hackable server. Returning 0.`);
|
||||
return 0;
|
||||
}
|
||||
if (typeof growth !== "number" || isNaN(growth) || growth < 1 || !isFinite(growth)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid argument: growth must be numeric and >= 1, is ${growth}.`);
|
||||
if (mult < 1 || !isFinite(mult)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid argument: multiplier must be finite and >= 1, is ${mult}.`);
|
||||
}
|
||||
// TODO 2.3: Add assertion function for positive integer, there are a lot of places everywhere that can use this
|
||||
if (!Number.isInteger(cores) || cores < 1) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Cores should be a positive integer. Cores provided: ${cores}`);
|
||||
}
|
||||
|
||||
return numCycleForGrowth(server, Number(growth), cores);
|
||||
return numCycleForGrowth(server, mult, cores);
|
||||
},
|
||||
growthAnalyzeSecurity:
|
||||
(ctx) =>
|
||||
|
||||
Reference in New Issue
Block a user