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:
David Walker
2023-01-10 18:18:33 -08:00
parent af0ed1dbb0
commit 53755dd573
3 changed files with 26 additions and 15 deletions
+7 -2
View File
@@ -434,17 +434,22 @@ function hack(
ctx: NetscriptContext,
hostname: string,
manual: boolean,
{ threads: requestedThreads, stock }: BasicHGWOptions = {},
{ threads: requestedThreads, stock, additionalMsec: requestedSec }: BasicHGWOptions = {},
): Promise<number> {
const ws = ctx.workerScript;
const threads = helpers.resolveNetscriptRequestedThreads(ctx, requestedThreads);
const additionalMsec = number(ctx, "opts.additionalMsec", requestedSec ?? 0);
if (additionalMsec < 0) {
throw makeRuntimeErrorMsg(ctx, `additionalMsec must be non-negative, got ${additionalMsec}`);
}
const server = getServer(ctx, hostname);
if (!(server instanceof Server)) {
throw makeRuntimeErrorMsg(ctx, "Cannot be executed on this server.");
}
// Calculate the hacking time
const hackingTime = calculateHackingTime(server, Player); // This is in seconds
// This is in seconds
const hackingTime = calculateHackingTime(server, Player) + additionalMsec / 1000.0;
// No root access or skill level too low
const canHack = netscriptCanHack(server);