API: Add ns.singularity.getHackingLevelRequirementOfProgram (#2271)

This commit is contained in:
catloversg
2025-07-31 04:44:06 +07:00
committed by GitHub
parent 952fc28b67
commit 8976d54532
7 changed files with 82 additions and 16 deletions

View File

@@ -33,7 +33,7 @@ This function will automatically set you to start working on creating the specif
This function returns true if you successfully start working on the specified program, and false otherwise.
Note that creating a program using this function has the same hacking level requirements as it normally would. These level requirements are:<br/> - BruteSSH.exe: 50<br/> - FTPCrack.exe: 100<br/> - relaySMTP.exe: 250<br/> - HTTPWorm.exe: 500<br/> - SQLInject.exe: 750<br/> - DeepscanV1.exe: 75<br/> - DeepscanV2.exe: 400<br/> - ServerProfiler.exe: 75<br/> - AutoLink.exe: 25
Note that creating a program using this function has the same hacking level requirements as it normally would. You can call [getHackingLevelRequirementOfProgram](./bitburner.singularity.gethackinglevelrequirementofprogram.md) to get that value.
## Example

View File

@@ -0,0 +1,32 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [Singularity](./bitburner.singularity.md) &gt; [getHackingLevelRequirementOfProgram](./bitburner.singularity.gethackinglevelrequirementofprogram.md)
## Singularity.getHackingLevelRequirementOfProgram() method
Get the hacking level requirement of a program.
**Signature:**
```typescript
getHackingLevelRequirementOfProgram(program: string): number;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| program | string | Name of program to create. |
**Returns:**
number
Hacking level requirement. Return Infinity if the specified program cannot be created.
## Remarks
RAM cost: 5 GB \* 16/4/1
In order to create a program via UI or [createProgram](./bitburner.singularity.createprogram.md)<!-- -->, your hacking level must meet the requirement of that program. This API returns that value.

View File

@@ -55,6 +55,7 @@ This API requires Source-File 4 to use. The RAM cost of all these functions is m
| [getFactionInviteRequirements(faction)](./bitburner.singularity.getfactioninviterequirements.md) | List conditions for being invited to a faction. |
| [getFactionRep(faction)](./bitburner.singularity.getfactionrep.md) | Get faction reputation. |
| [getFactionWorkTypes(faction)](./bitburner.singularity.getfactionworktypes.md) | Get the work types of a faction. |
| [getHackingLevelRequirementOfProgram(program)](./bitburner.singularity.gethackinglevelrequirementofprogram.md) | Get the hacking level requirement of a program. |
| [getOwnedAugmentations(purchased)](./bitburner.singularity.getownedaugmentations.md) | Get a list of owned augmentation. |
| [getOwnedSourceFiles()](./bitburner.singularity.getownedsourcefiles.md) | Get a list of acquired Source-Files. |
| [getSaveData()](./bitburner.singularity.getsavedata.md) | This function returns the save data. |

View File

@@ -199,6 +199,7 @@ const singularity = {
getFactionFavorGain: SF4Cost(RamCostConstants.SingularityFn2 / 4),
donateToFaction: SF4Cost(RamCostConstants.SingularityFn3),
createProgram: SF4Cost(RamCostConstants.SingularityFn3),
getHackingLevelRequirementOfProgram: SF4Cost(RamCostConstants.SingularityFn3),
commitCrime: SF4Cost(RamCostConstants.SingularityFn3),
getCrimeChance: SF4Cost(RamCostConstants.SingularityFn3),
getCrimeStats: SF4Cost(RamCostConstants.SingularityFn3),

View File

@@ -1,7 +1,7 @@
import type { Singularity as ISingularity } from "@nsdefs";
import { Player } from "@player";
import { CityName, FactionWorkType, LocationName } from "@enums";
import { CityName, CompletedProgramName, FactionWorkType, LocationName } from "@enums";
import { purchaseAugmentation, joinFaction, getFactionAugmentationsFiltered } from "../Faction/FactionHelpers";
import { startWorkerScript } from "../NetscriptWorker";
import { Augmentations } from "../Augmentation/Augmentations";
@@ -16,7 +16,7 @@ import { Page } from "../ui/Router";
import { SpecialServers } from "../Server/data/SpecialServers";
import { Locations } from "../Locations/Locations";
import { GetServer } from "../Server/AllServers";
import { Programs } from "../Programs/Programs";
import { getEffectiveHackingLevelRequirement, Programs } from "../Programs/Programs";
import { formatMoney, formatRam, formatReputation } from "../ui/formatNumber";
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
import { Companies } from "../Company/Companies";
@@ -963,7 +963,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
const p = Object.values(Programs).find((p) => p.name.toLowerCase() === programName);
if (p == null) {
helpers.log(ctx, () => `The specified program does not exist: '${programName}`);
helpers.log(ctx, () => `The specified program does not exist: '${programName}'`);
return false;
}
@@ -1002,6 +1002,28 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
helpers.log(ctx, () => `Began creating program: '${programName}'`);
return true;
},
getHackingLevelRequirementOfProgram: (ctx) => (_programName) => {
helpers.checkSingularityAccess(ctx);
const programName = helpers.string(ctx, "programName", _programName).toLowerCase();
const program = Object.values(Programs).find((p) => p.name.toLowerCase() === programName);
if (program == null) {
throw helpers.errorMessage(ctx, `The specified program does not exist: '${programName}'`);
}
const create = program.create;
// Return Infinity if this program cannot be created.
if (create === null) {
return Infinity;
}
// The hacking level requirement of bitFlume is exactly 1. It does not depend on Intelligence.
if (program.name === CompletedProgramName.bitFlume) {
return 1;
}
return getEffectiveHackingLevelRequirement(create.level);
},
commitCrime: (ctx) => (_crimeType, _focus) => {
helpers.checkSingularityAccess(ctx);
const crimeType = getEnumHelper("CrimeType").nsGetMember(ctx, _crimeType);

View File

@@ -14,13 +14,18 @@ import { CompletedProgramName, FactionName } from "@enums";
import { Router } from "../ui/GameRoot";
import { Page } from "../ui/Router";
import { knowAboutBitverse } from "../BitNode/BitNodeUtils";
import { clampNumber } from "../utils/helpers/clampNumber";
function requireHackingLevel(lvl: number) {
return function () {
return Player.skills.hacking + Player.skills.intelligence / 2 >= lvl;
return Player.skills.hacking >= getEffectiveHackingLevelRequirement(lvl);
};
}
export function getEffectiveHackingLevelRequirement(level: number): number {
return clampNumber(level - Player.skills.intelligence / 2, 1);
}
function bitFlumeRequirements() {
return function () {
return knowAboutBitverse() && Player.skills.hacking >= 1;

View File

@@ -2418,17 +2418,9 @@ export interface Singularity {
*
* This function returns true if you successfully start working on the specified program, and false otherwise.
*
* Note that creating a program using this function has the same hacking level requirements as it normally would.
* These level requirements are:<br/>
* - BruteSSH.exe: 50<br/>
* - FTPCrack.exe: 100<br/>
* - relaySMTP.exe: 250<br/>
* - HTTPWorm.exe: 500<br/>
* - SQLInject.exe: 750<br/>
* - DeepscanV1.exe: 75<br/>
* - DeepscanV2.exe: 400<br/>
* - ServerProfiler.exe: 75<br/>
* - AutoLink.exe: 25
* Note that creating a program using this function has the same hacking level requirements as it normally would. You
* can call {@link Singularity.getHackingLevelRequirementOfProgram | getHackingLevelRequirementOfProgram} to get that
* value.
*
* @example
* ```js
@@ -2442,6 +2434,19 @@ export interface Singularity {
*/
createProgram(program: string, focus?: boolean): boolean;
/**
* Get the hacking level requirement of a program.
* @remarks
* RAM cost: 5 GB * 16/4/1
*
* In order to create a program via UI or {@link Singularity.createProgram | createProgram}, your hacking level must
* meet the requirement of that program. This API returns that value.
*
* @param program - Name of program to create.
* @returns Hacking level requirement. Return Infinity if the specified program cannot be created.
*/
getHackingLevelRequirementOfProgram(program: string): number;
/**
* Commit a crime.
* @remarks