mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-22 07:33:48 +01:00
API: Get Sleeve Success at BB tasks through existing commands (#1428)
This commit is contained in:
parent
9c9a69f2e2
commit
61ec7dde80
@ -9,7 +9,7 @@ Get estimate success chance of an action.
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
getActionEstimatedSuccessChance(type: string, name: string): [number, number];
|
||||
getActionEstimatedSuccessChance(type: string, name: string, sleeve?: number): [number, number];
|
||||
```
|
||||
|
||||
## Parameters
|
||||
@ -18,6 +18,7 @@ getActionEstimatedSuccessChance(type: string, name: string): [number, number];
|
||||
| --- | --- | --- |
|
||||
| type | string | Type of action. |
|
||||
| name | string | Name of action. Must be an exact match. |
|
||||
| sleeve | number | _(Optional)_ Optional. Sleeve number to check for success. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -24,7 +24,7 @@ You have to be employed in the Bladeburner division and be in BitNode-7 or have
|
||||
| [getActionCountRemaining(type, name)](./bitburner.bladeburner.getactioncountremaining.md) | Get action count remaining. |
|
||||
| [getActionCurrentLevel(type, name)](./bitburner.bladeburner.getactioncurrentlevel.md) | Get the current level of an action. |
|
||||
| [getActionCurrentTime()](./bitburner.bladeburner.getactioncurrenttime.md) | Get the time elapsed on current action. |
|
||||
| [getActionEstimatedSuccessChance(type, name)](./bitburner.bladeburner.getactionestimatedsuccesschance.md) | Get estimate success chance of an action. |
|
||||
| [getActionEstimatedSuccessChance(type, name, sleeve)](./bitburner.bladeburner.getactionestimatedsuccesschance.md) | Get estimate success chance of an action. |
|
||||
| [getActionMaxLevel(type, name)](./bitburner.bladeburner.getactionmaxlevel.md) | Get the maximum level of an action. |
|
||||
| [getActionRepGain(type, name, level)](./bitburner.bladeburner.getactionrepgain.md) | Get the reputation gain of an action. |
|
||||
| [getActionSuccesses(type, name)](./bitburner.bladeburner.getactionsuccesses.md) | Get action successes. |
|
||||
|
@ -11,6 +11,7 @@ import { getEnumHelper } from "../utils/EnumHelper";
|
||||
import { Skills } from "../Bladeburner/data/Skills";
|
||||
import { assertString } from "../Netscript/TypeAssertion";
|
||||
import { BlackOperations, blackOpsArray } from "../Bladeburner/data/BlackOperations";
|
||||
import { checkSleeveAPIAccess, checkSleeveNumber } from "../NetscriptFunctions/Sleeve";
|
||||
|
||||
export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
const checkBladeburnerAccess = function (ctx: NetscriptContext): void {
|
||||
@ -27,7 +28,6 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
throw helpers.errorMessage(ctx, "You must be a member of the Bladeburner division to use this API.");
|
||||
return bladeburner;
|
||||
};
|
||||
|
||||
function getAction(ctx: NetscriptContext, type: unknown, name: unknown): Action {
|
||||
const bladeburner = Player.bladeburner;
|
||||
assertString(ctx, "type", type);
|
||||
@ -117,10 +117,20 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
1000
|
||||
);
|
||||
},
|
||||
getActionEstimatedSuccessChance: (ctx) => (type, name) => {
|
||||
getActionEstimatedSuccessChance: (ctx) => (type, name, _sleeve) => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
const action = getAction(ctx, type, name);
|
||||
if (_sleeve != null) {
|
||||
checkSleeveAPIAccess(ctx);
|
||||
const sleeveNumber = helpers.number(ctx, "sleeve", _sleeve);
|
||||
checkSleeveNumber(ctx, sleeveNumber);
|
||||
if (action.type === BladeActionType.contract) {
|
||||
const sleevePerson = Player.sleeves[sleeveNumber];
|
||||
return action.getSuccessRange(bladeburner, sleevePerson);
|
||||
} else return [0, 0];
|
||||
} else {
|
||||
return action.getSuccessRange(bladeburner, Player);
|
||||
}
|
||||
},
|
||||
getActionRepGain: (ctx) => (type, name, _level) => {
|
||||
checkBladeburnerAccess(ctx);
|
||||
|
@ -16,8 +16,7 @@ import { getAugCost } from "../Augmentation/AugmentationHelpers";
|
||||
import { Factions } from "../Faction/Factions";
|
||||
import { SleeveWorkType } from "../PersonObjects/Sleeve/Work/Work";
|
||||
|
||||
export function NetscriptSleeve(): InternalAPI<NetscriptSleeve> {
|
||||
const checkSleeveAPIAccess = function (ctx: NetscriptContext) {
|
||||
export const checkSleeveAPIAccess = function (ctx: NetscriptContext) {
|
||||
if (Player.bitNodeN !== 10 && !Player.sourceFileLvl(10)) {
|
||||
throw helpers.errorMessage(
|
||||
ctx,
|
||||
@ -26,7 +25,7 @@ export function NetscriptSleeve(): InternalAPI<NetscriptSleeve> {
|
||||
}
|
||||
};
|
||||
|
||||
const checkSleeveNumber = function (ctx: NetscriptContext, sleeveNumber: number) {
|
||||
export const checkSleeveNumber = function (ctx: NetscriptContext, sleeveNumber: number) {
|
||||
if (sleeveNumber >= Player.sleeves.length || sleeveNumber < 0) {
|
||||
const msg = `Invalid sleeve number: ${sleeveNumber}`;
|
||||
helpers.log(ctx, () => msg);
|
||||
@ -34,6 +33,7 @@ export function NetscriptSleeve(): InternalAPI<NetscriptSleeve> {
|
||||
}
|
||||
};
|
||||
|
||||
export function NetscriptSleeve(): InternalAPI<NetscriptSleeve> {
|
||||
const sleeveFunctions: InternalAPI<NetscriptSleeve> = {
|
||||
getNumSleeves: (ctx) => () => {
|
||||
checkSleeveAPIAccess(ctx);
|
||||
|
3
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
3
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -3144,9 +3144,10 @@ export interface Bladeburner {
|
||||
*
|
||||
* @param type - Type of action.
|
||||
* @param name - Name of action. Must be an exact match.
|
||||
* @param sleeve - Optional. Sleeve number to check for success.
|
||||
* @returns Estimated success chance for the specified action.
|
||||
*/
|
||||
getActionEstimatedSuccessChance(type: string, name: string): [number, number];
|
||||
getActionEstimatedSuccessChance(type: string, name: string, sleeve?: number): [number, number];
|
||||
|
||||
/**
|
||||
* Get the reputation gain of an action.
|
||||
|
Loading…
Reference in New Issue
Block a user