mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-22 01:03:01 +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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user