mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-29 19:13:49 +01:00
Merge pull request #3425 from Chris380/bugfix/3111_growthAnalyzeSecurity_thread_limit
Bugfix/3111 growthAnalyzeSecurity thread limit
This commit is contained in:
commit
cca8aa45d6
@ -34,6 +34,7 @@ import { RunningScript } from "./Script/RunningScript";
|
|||||||
import {
|
import {
|
||||||
getServerOnNetwork,
|
getServerOnNetwork,
|
||||||
numCycleForGrowth,
|
numCycleForGrowth,
|
||||||
|
numCycleForGrowthCorrected,
|
||||||
processSingleServerGrowth,
|
processSingleServerGrowth,
|
||||||
safetlyCreateUniqueServer,
|
safetlyCreateUniqueServer,
|
||||||
} from "./Server/ServerHelpers";
|
} from "./Server/ServerHelpers";
|
||||||
@ -633,7 +634,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
|
|
||||||
if (percentHacked > 0) {
|
if (percentHacked > 0) {
|
||||||
// thread count is limited to the maximum number of threads needed
|
// thread count is limited to the maximum number of threads needed
|
||||||
threads = Math.ceil(1 / percentHacked);
|
threads = Math.min(threads, Math.ceil(1 / percentHacked));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -752,9 +753,26 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
|
|
||||||
return numCycleForGrowth(server, Number(growth), Player, cores);
|
return numCycleForGrowth(server, Number(growth), Player, cores);
|
||||||
},
|
},
|
||||||
growthAnalyzeSecurity: function (_threads: unknown): number {
|
growthAnalyzeSecurity: function (_threads: unknown, _hostname?: unknown, _cores?: unknown): number {
|
||||||
updateDynamicRam("growthAnalyzeSecurity", getRamCost(Player, "growthAnalyzeSecurity"));
|
updateDynamicRam("growthAnalyzeSecurity", getRamCost(Player, "growthAnalyzeSecurity"));
|
||||||
const threads = helper.number("growthAnalyzeSecurity", "threads", _threads);
|
let threads = helper.number("growthAnalyzeSecurity", "threads", _threads);
|
||||||
|
if (_hostname) {
|
||||||
|
const cores = helper.number("growthAnalyzeSecurity", "cores", _cores) || 1;
|
||||||
|
const hostname = helper.string("growthAnalyzeSecurity", "hostname", _hostname);
|
||||||
|
const server = safeGetServer(hostname, "growthAnalyzeSecurity");
|
||||||
|
|
||||||
|
if (!(server instanceof Server)) {
|
||||||
|
workerScript.log("growthAnalyzeSecurity", () => "Cannot be executed on this server.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxThreadsNeeded = Math.ceil(
|
||||||
|
numCycleForGrowthCorrected(server, server.moneyMax, server.moneyAvailable, Player, cores),
|
||||||
|
);
|
||||||
|
|
||||||
|
threads = Math.min(threads, maxThreadsNeeded);
|
||||||
|
}
|
||||||
|
|
||||||
return 2 * CONSTANTS.ServerFortifyAmount * threads;
|
return 2 * CONSTANTS.ServerFortifyAmount * threads;
|
||||||
},
|
},
|
||||||
weaken: async function (_hostname: unknown, { threads: requestedThreads }: BasicHGWOptions = {}): Promise<number> {
|
weaken: async function (_hostname: unknown, { threads: requestedThreads }: BasicHGWOptions = {}): Promise<number> {
|
||||||
|
4
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
4
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -4647,9 +4647,11 @@ export interface NS {
|
|||||||
* Returns the security increase that would occur if a grow with this many threads happened.
|
* Returns the security increase that would occur if a grow with this many threads happened.
|
||||||
*
|
*
|
||||||
* @param threads - Amount of threads that will be used.
|
* @param threads - Amount of threads that will be used.
|
||||||
|
* @param hostname - Optional. Hostname of the target server. The number of threads is limited to the number needed to hack the servers maximum amount of money.
|
||||||
|
* @param cores - Optional. The number of cores of the server that would run grow.
|
||||||
* @returns The security increase.
|
* @returns The security increase.
|
||||||
*/
|
*/
|
||||||
growthAnalyzeSecurity(threads: number): number;
|
growthAnalyzeSecurity(threads: number, hostname?: string, cores?: number): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Suspends the script for n milliseconds.
|
* Suspends the script for n milliseconds.
|
||||||
|
Loading…
Reference in New Issue
Block a user