mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-23 01:32:55 +02:00
NETSCRIPT: Add additionalMsec to BasicHGWOptions
This option adds additional time to the sleep in hack/grow/weaken before the command takes effect. The critical difference between this and doing your own sleep is that it creates a single, uninterruptible sleep: This opens up multiple new avenues of gameplay for batching. Note that use of this new feature is theoretically always suboptimal, since extending the sleep time wastes RAM.
This commit is contained in:
+13
-13
@@ -144,7 +144,7 @@ export const ns: InternalAPI<NSFull> = {
|
||||
// TODO 2.2: better type safety rework for functions using assertObjectType, then remove function.
|
||||
const optsValidator: BasicHGWOptions = {};
|
||||
assertObjectType(ctx, "opts", opts, optsValidator);
|
||||
return helpers.hack(ctx, hostname, false, { threads: opts.threads, stock: opts.stock });
|
||||
return helpers.hack(ctx, hostname, false, opts);
|
||||
},
|
||||
hackAnalyzeThreads: (ctx) => (_hostname, _hackAmount) => {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
@@ -241,11 +241,11 @@ export const ns: InternalAPI<NSFull> = {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const optsValidator: BasicHGWOptions = {};
|
||||
assertObjectType(ctx, "opts", opts, optsValidator);
|
||||
const requestedThreads =
|
||||
opts.threads === undefined
|
||||
? ctx.workerScript.scriptRef.threads
|
||||
: helpers.number(ctx, "opts.threads", opts.threads);
|
||||
const threads = helpers.resolveNetscriptRequestedThreads(ctx, requestedThreads);
|
||||
const threads = helpers.resolveNetscriptRequestedThreads(ctx, opts.threads);
|
||||
const additionalMsec = helpers.number(ctx, "opts.additionalMsec", opts.additionalMsec ?? 0);
|
||||
if (additionalMsec < 0) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `additionalMsec must be non-negative, got ${additionalMsec}`);
|
||||
}
|
||||
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
@@ -264,7 +264,7 @@ export const ns: InternalAPI<NSFull> = {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, canHack.msg || "");
|
||||
}
|
||||
|
||||
const growTime = calculateGrowTime(server, Player);
|
||||
const growTime = calculateGrowTime(server, Player) + additionalMsec / 1000.0;
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
@@ -348,11 +348,11 @@ export const ns: InternalAPI<NSFull> = {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const optsValidator: BasicHGWOptions = {};
|
||||
assertObjectType(ctx, "opts", opts, optsValidator);
|
||||
const requestedThreads =
|
||||
opts.threads === undefined
|
||||
? ctx.workerScript.scriptRef.threads
|
||||
: helpers.number(ctx, "opts.threads", opts.threads);
|
||||
const threads = helpers.resolveNetscriptRequestedThreads(ctx, requestedThreads);
|
||||
const threads = helpers.resolveNetscriptRequestedThreads(ctx, opts.threads);
|
||||
const additionalMsec = helpers.number(ctx, "opts.additionalMsec", opts.additionalMsec ?? 0);
|
||||
if (additionalMsec < 0) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `additionalMsec must be non-negative, got ${additionalMsec}`);
|
||||
}
|
||||
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
@@ -366,7 +366,7 @@ export const ns: InternalAPI<NSFull> = {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, canHack.msg || "");
|
||||
}
|
||||
|
||||
const weakenTime = calculateWeakenTime(server, Player);
|
||||
const weakenTime = calculateWeakenTime(server, Player) + additionalMsec / 1000.0;
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
|
||||
Reference in New Issue
Block a user