mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
API: Add weakenEffect to formulas.hacking namespace (#2626)
This commit is contained in:
@@ -126,6 +126,17 @@ Calculate hack percent for one thread. (Ex: 0.25 would steal 25% of the server's
|
|||||||
Calculate hack time.
|
Calculate hack time.
|
||||||
|
|
||||||
|
|
||||||
|
</td></tr>
|
||||||
|
<tr><td>
|
||||||
|
|
||||||
|
[weakenEffect(threads, cores)](./bitburner.hackingformulas.weakeneffect.md)
|
||||||
|
|
||||||
|
|
||||||
|
</td><td>
|
||||||
|
|
||||||
|
Calculate the security decrease from a weaken operation. Unlike other hacking formulas, weaken effect depends only on thread count and core count, not on server or player properties. The core bonus formula is .
|
||||||
|
|
||||||
|
|
||||||
</td></tr>
|
</td></tr>
|
||||||
<tr><td>
|
<tr><td>
|
||||||
|
|
||||||
|
|||||||
72
markdown/bitburner.hackingformulas.weakeneffect.md
Normal file
72
markdown/bitburner.hackingformulas.weakeneffect.md
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||||
|
|
||||||
|
[Home](./index.md) > [bitburner](./bitburner.md) > [HackingFormulas](./bitburner.hackingformulas.md) > [weakenEffect](./bitburner.hackingformulas.weakeneffect.md)
|
||||||
|
|
||||||
|
## HackingFormulas.weakenEffect() method
|
||||||
|
|
||||||
|
Calculate the security decrease from a weaken operation. Unlike other hacking formulas, weaken effect depends only on thread count and core count, not on server or player properties. The core bonus formula is .
|
||||||
|
|
||||||
|
**Signature:**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
weakenEffect(threads: number, cores?: number): number;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
<table><thead><tr><th>
|
||||||
|
|
||||||
|
Parameter
|
||||||
|
|
||||||
|
|
||||||
|
</th><th>
|
||||||
|
|
||||||
|
Type
|
||||||
|
|
||||||
|
|
||||||
|
</th><th>
|
||||||
|
|
||||||
|
Description
|
||||||
|
|
||||||
|
|
||||||
|
</th></tr></thead>
|
||||||
|
<tbody><tr><td>
|
||||||
|
|
||||||
|
threads
|
||||||
|
|
||||||
|
|
||||||
|
</td><td>
|
||||||
|
|
||||||
|
number
|
||||||
|
|
||||||
|
|
||||||
|
</td><td>
|
||||||
|
|
||||||
|
Number of threads running weaken.
|
||||||
|
|
||||||
|
|
||||||
|
</td></tr>
|
||||||
|
<tr><td>
|
||||||
|
|
||||||
|
cores
|
||||||
|
|
||||||
|
|
||||||
|
</td><td>
|
||||||
|
|
||||||
|
number
|
||||||
|
|
||||||
|
|
||||||
|
</td><td>
|
||||||
|
|
||||||
|
_(Optional)_ Number of cores on the host server. Default 1.
|
||||||
|
|
||||||
|
|
||||||
|
</td></tr>
|
||||||
|
</tbody></table>
|
||||||
|
|
||||||
|
**Returns:**
|
||||||
|
|
||||||
|
number
|
||||||
|
|
||||||
|
The security decrease amount.
|
||||||
|
|
||||||
@@ -746,6 +746,7 @@ import nsDoc_bitburner_hackingformulas_hackexp_md from "../../markdown/bitburner
|
|||||||
import nsDoc_bitburner_hackingformulas_hackpercent_md from "../../markdown/bitburner.hackingformulas.hackpercent.md?raw";
|
import nsDoc_bitburner_hackingformulas_hackpercent_md from "../../markdown/bitburner.hackingformulas.hackpercent.md?raw";
|
||||||
import nsDoc_bitburner_hackingformulas_hacktime_md from "../../markdown/bitburner.hackingformulas.hacktime.md?raw";
|
import nsDoc_bitburner_hackingformulas_hacktime_md from "../../markdown/bitburner.hackingformulas.hacktime.md?raw";
|
||||||
import nsDoc_bitburner_hackingformulas_md from "../../markdown/bitburner.hackingformulas.md?raw";
|
import nsDoc_bitburner_hackingformulas_md from "../../markdown/bitburner.hackingformulas.md?raw";
|
||||||
|
import nsDoc_bitburner_hackingformulas_weakeneffect_md from "../../markdown/bitburner.hackingformulas.weakeneffect.md?raw";
|
||||||
import nsDoc_bitburner_hackingformulas_weakentime_md from "../../markdown/bitburner.hackingformulas.weakentime.md?raw";
|
import nsDoc_bitburner_hackingformulas_weakentime_md from "../../markdown/bitburner.hackingformulas.weakentime.md?raw";
|
||||||
import nsDoc_bitburner_hackingmultipliers_chance_md from "../../markdown/bitburner.hackingmultipliers.chance.md?raw";
|
import nsDoc_bitburner_hackingmultipliers_chance_md from "../../markdown/bitburner.hackingmultipliers.chance.md?raw";
|
||||||
import nsDoc_bitburner_hackingmultipliers_growth_md from "../../markdown/bitburner.hackingmultipliers.growth.md?raw";
|
import nsDoc_bitburner_hackingmultipliers_growth_md from "../../markdown/bitburner.hackingmultipliers.growth.md?raw";
|
||||||
@@ -2342,6 +2343,7 @@ AllPages["nsDoc/bitburner.hackingformulas.hackexp.md"] = nsDoc_bitburner_hacking
|
|||||||
AllPages["nsDoc/bitburner.hackingformulas.hackpercent.md"] = nsDoc_bitburner_hackingformulas_hackpercent_md;
|
AllPages["nsDoc/bitburner.hackingformulas.hackpercent.md"] = nsDoc_bitburner_hackingformulas_hackpercent_md;
|
||||||
AllPages["nsDoc/bitburner.hackingformulas.hacktime.md"] = nsDoc_bitburner_hackingformulas_hacktime_md;
|
AllPages["nsDoc/bitburner.hackingformulas.hacktime.md"] = nsDoc_bitburner_hackingformulas_hacktime_md;
|
||||||
AllPages["nsDoc/bitburner.hackingformulas.md"] = nsDoc_bitburner_hackingformulas_md;
|
AllPages["nsDoc/bitburner.hackingformulas.md"] = nsDoc_bitburner_hackingformulas_md;
|
||||||
|
AllPages["nsDoc/bitburner.hackingformulas.weakeneffect.md"] = nsDoc_bitburner_hackingformulas_weakeneffect_md;
|
||||||
AllPages["nsDoc/bitburner.hackingformulas.weakentime.md"] = nsDoc_bitburner_hackingformulas_weakentime_md;
|
AllPages["nsDoc/bitburner.hackingformulas.weakentime.md"] = nsDoc_bitburner_hackingformulas_weakentime_md;
|
||||||
AllPages["nsDoc/bitburner.hackingmultipliers.chance.md"] = nsDoc_bitburner_hackingmultipliers_chance_md;
|
AllPages["nsDoc/bitburner.hackingmultipliers.chance.md"] = nsDoc_bitburner_hackingmultipliers_chance_md;
|
||||||
AllPages["nsDoc/bitburner.hackingmultipliers.growth.md"] = nsDoc_bitburner_hackingmultipliers_growth_md;
|
AllPages["nsDoc/bitburner.hackingmultipliers.growth.md"] = nsDoc_bitburner_hackingmultipliers_growth_md;
|
||||||
|
|||||||
@@ -692,6 +692,7 @@ export const RamCosts: RamCostTree<NSFull> = {
|
|||||||
hackTime: 0,
|
hackTime: 0,
|
||||||
growTime: 0,
|
growTime: 0,
|
||||||
weakenTime: 0,
|
weakenTime: 0,
|
||||||
|
weakenEffect: 0,
|
||||||
},
|
},
|
||||||
hacknetNodes: {
|
hacknetNodes: {
|
||||||
moneyGainRate: 0,
|
moneyGainRate: 0,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Player } from "@player";
|
import { Player } from "@player";
|
||||||
import { calculateServerGrowth, calculateGrowMoney } from "../Server/formulas/grow";
|
import { calculateServerGrowth, calculateGrowMoney } from "../Server/formulas/grow";
|
||||||
import { numCycleForGrowthCorrected } from "../Server/ServerHelpers";
|
import { getWeakenEffect, numCycleForGrowthCorrected } from "../Server/ServerHelpers";
|
||||||
import {
|
import {
|
||||||
calculateMoneyGainRate,
|
calculateMoneyGainRate,
|
||||||
calculateLevelUpgradeCost,
|
calculateLevelUpgradeCost,
|
||||||
@@ -235,6 +235,14 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
|||||||
checkFormulasAccess(ctx);
|
checkFormulasAccess(ctx);
|
||||||
return calculateWeakenTime(server, person) * 1000;
|
return calculateWeakenTime(server, person) * 1000;
|
||||||
},
|
},
|
||||||
|
weakenEffect:
|
||||||
|
(ctx) =>
|
||||||
|
(_threads, _cores = 1) => {
|
||||||
|
const threads = helpers.number(ctx, "threads", _threads);
|
||||||
|
const cores = helpers.number(ctx, "cores", _cores);
|
||||||
|
checkFormulasAccess(ctx);
|
||||||
|
return getWeakenEffect(threads, cores);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
hacknetNodes: {
|
hacknetNodes: {
|
||||||
moneyGainRate:
|
moneyGainRate:
|
||||||
|
|||||||
10
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
10
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@@ -6299,6 +6299,16 @@ interface HackingFormulas {
|
|||||||
* @returns The calculated weaken time, in milliseconds.
|
* @returns The calculated weaken time, in milliseconds.
|
||||||
*/
|
*/
|
||||||
weakenTime(server: Server, player: Person): number;
|
weakenTime(server: Server, player: Person): number;
|
||||||
|
/**
|
||||||
|
* Calculate the security decrease from a weaken operation.
|
||||||
|
* Unlike other hacking formulas, weaken effect depends only on thread count and
|
||||||
|
* core count, not on server or player properties. The core bonus formula is
|
||||||
|
* {@code 1 + (cores - 1) / 16}.
|
||||||
|
* @param threads - Number of threads running weaken.
|
||||||
|
* @param cores - Number of cores on the host server. Default 1.
|
||||||
|
* @returns The security decrease amount.
|
||||||
|
*/
|
||||||
|
weakenEffect(threads: number, cores?: number): number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
30
test/jest/Netscript/WeakenEffect.test.ts
Normal file
30
test/jest/Netscript/WeakenEffect.test.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { getWeakenEffect } from "../../../src/Server/ServerHelpers";
|
||||||
|
|
||||||
|
describe("getWeakenEffect (formulas.hacking.weakenEffect)", () => {
|
||||||
|
it("returns 0.05 per thread with single core", () => {
|
||||||
|
expect(getWeakenEffect(1, 1)).toBe(0.05);
|
||||||
|
expect(getWeakenEffect(100, 1)).toBe(5.0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("applies core bonus correctly", () => {
|
||||||
|
// Core bonus: 1 + (cores - 1) / 16
|
||||||
|
// 8 cores: 1 + 7/16 = 1.4375
|
||||||
|
expect(getWeakenEffect(1, 8)).toBeCloseTo(0.071875);
|
||||||
|
expect(getWeakenEffect(100, 8)).toBeCloseTo(7.1875);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns 0 for 0 threads", () => {
|
||||||
|
expect(getWeakenEffect(0, 1)).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("handles single core (no bonus)", () => {
|
||||||
|
// Core bonus with 1 core: 1 + 0/16 = 1.0
|
||||||
|
expect(getWeakenEffect(50, 1)).toBe(2.5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("handles max cores (8)", () => {
|
||||||
|
// 8 cores: 1 + 7/16 = 1.4375
|
||||||
|
// 10 threads * 0.05 * 1.4375 = 0.71875
|
||||||
|
expect(getWeakenEffect(10, 8)).toBeCloseTo(0.71875);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user