mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-20 06:33:49 +01:00
Merge pull request #3405 from Chris380/bugfix/3111_hackAnalyzeSecurity_thread_limit
take into account max thread needed
This commit is contained in:
commit
c38ab9e65f
3
dist/bitburner.d.ts
vendored
3
dist/bitburner.d.ts
vendored
@ -2825,9 +2825,10 @@ export declare interface NS extends Singularity {
|
||||
* Returns the security increase that would occur if a hack with this many threads happened.
|
||||
*
|
||||
* @param threads - Amount of threads that will be used.
|
||||
* @param hostname - Hostname of the target server. The number of threads is limited to the number needed to hack the servers maximum amount of money.
|
||||
* @returns The security increase.
|
||||
*/
|
||||
hackAnalyzeSecurity(threads: number): number;
|
||||
hackAnalyzeSecurity(threads: number, hostname?: string): number;
|
||||
|
||||
/**
|
||||
* Get the chance of successfully hacking a server.
|
||||
|
@ -585,9 +585,24 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
|
||||
return calculatePercentMoneyHacked(server, Player);
|
||||
},
|
||||
hackAnalyzeSecurity: function (_threads: unknown): number {
|
||||
hackAnalyzeSecurity: function (_threads: unknown, hostname?: string): number {
|
||||
updateDynamicRam("hackAnalyzeSecurity", getRamCost(Player, "hackAnalyzeSecurity"));
|
||||
const threads = helper.number("hackAnalyzeSecurity", "threads", _threads);
|
||||
let threads = helper.number("hackAnalyzeSecurity", "threads", _threads);
|
||||
if (hostname) {
|
||||
const server = safeGetServer(hostname, "hackAnalyze");
|
||||
if (!(server instanceof Server)) {
|
||||
workerScript.log("hackAnalyzeSecurity", () => "Cannot be executed on this server.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const percentHacked = calculatePercentMoneyHacked(server, Player);
|
||||
|
||||
if (percentHacked > 0) {
|
||||
// thread count is limited to the maximum number of threads needed
|
||||
threads = Math.ceil(1 / percentHacked);
|
||||
}
|
||||
}
|
||||
|
||||
return CONSTANTS.ServerFortifyAmount * threads;
|
||||
},
|
||||
hackAnalyzeChance: function (_hostname: unknown): number {
|
||||
|
3
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
3
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -4555,9 +4555,10 @@ export interface NS extends Singularity {
|
||||
* Returns the security increase that would occur if a hack with this many threads happened.
|
||||
*
|
||||
* @param threads - Amount of threads that will be used.
|
||||
* @param hostname - Hostname of the target server. The number of threads is limited to the number needed to hack the servers maximum amount of money.
|
||||
* @returns The security increase.
|
||||
*/
|
||||
hackAnalyzeSecurity(threads: number): number;
|
||||
hackAnalyzeSecurity(threads: number, hostname?: string): number;
|
||||
|
||||
/**
|
||||
* Get the chance of successfully hacking a server.
|
||||
|
Loading…
Reference in New Issue
Block a user