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:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
getActionEstimatedSuccessChance(type: string, name: string): [number, number];
|
getActionEstimatedSuccessChance(type: string, name: string, sleeve?: number): [number, number];
|
||||||
```
|
```
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
@ -18,6 +18,7 @@ getActionEstimatedSuccessChance(type: string, name: string): [number, number];
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| type | string | Type of action. |
|
| type | string | Type of action. |
|
||||||
| name | string | Name of action. Must be an exact match. |
|
| name | string | Name of action. Must be an exact match. |
|
||||||
|
| sleeve | number | _(Optional)_ Optional. Sleeve number to check for success. |
|
||||||
|
|
||||||
**Returns:**
|
**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. |
|
| [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. |
|
| [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. |
|
| [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. |
|
| [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. |
|
| [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. |
|
| [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 { Skills } from "../Bladeburner/data/Skills";
|
||||||
import { assertString } from "../Netscript/TypeAssertion";
|
import { assertString } from "../Netscript/TypeAssertion";
|
||||||
import { BlackOperations, blackOpsArray } from "../Bladeburner/data/BlackOperations";
|
import { BlackOperations, blackOpsArray } from "../Bladeburner/data/BlackOperations";
|
||||||
|
import { checkSleeveAPIAccess, checkSleeveNumber } from "../NetscriptFunctions/Sleeve";
|
||||||
|
|
||||||
export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||||
const checkBladeburnerAccess = function (ctx: NetscriptContext): void {
|
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.");
|
throw helpers.errorMessage(ctx, "You must be a member of the Bladeburner division to use this API.");
|
||||||
return bladeburner;
|
return bladeburner;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getAction(ctx: NetscriptContext, type: unknown, name: unknown): Action {
|
function getAction(ctx: NetscriptContext, type: unknown, name: unknown): Action {
|
||||||
const bladeburner = Player.bladeburner;
|
const bladeburner = Player.bladeburner;
|
||||||
assertString(ctx, "type", type);
|
assertString(ctx, "type", type);
|
||||||
@ -117,10 +117,20 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
|||||||
1000
|
1000
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getActionEstimatedSuccessChance: (ctx) => (type, name) => {
|
getActionEstimatedSuccessChance: (ctx) => (type, name, _sleeve) => {
|
||||||
const bladeburner = getBladeburner(ctx);
|
const bladeburner = getBladeburner(ctx);
|
||||||
const action = getAction(ctx, type, name);
|
const action = getAction(ctx, type, name);
|
||||||
return action.getSuccessRange(bladeburner, Player);
|
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) => {
|
getActionRepGain: (ctx) => (type, name, _level) => {
|
||||||
checkBladeburnerAccess(ctx);
|
checkBladeburnerAccess(ctx);
|
||||||
|
@ -16,24 +16,24 @@ import { getAugCost } from "../Augmentation/AugmentationHelpers";
|
|||||||
import { Factions } from "../Faction/Factions";
|
import { Factions } from "../Faction/Factions";
|
||||||
import { SleeveWorkType } from "../PersonObjects/Sleeve/Work/Work";
|
import { SleeveWorkType } from "../PersonObjects/Sleeve/Work/Work";
|
||||||
|
|
||||||
|
export const checkSleeveAPIAccess = function (ctx: NetscriptContext) {
|
||||||
|
if (Player.bitNodeN !== 10 && !Player.sourceFileLvl(10)) {
|
||||||
|
throw helpers.errorMessage(
|
||||||
|
ctx,
|
||||||
|
"You do not currently have access to the Sleeve API. This is either because you are not in BitNode-10 or because you do not have Source-File 10",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
throw helpers.errorMessage(ctx, msg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export function NetscriptSleeve(): InternalAPI<NetscriptSleeve> {
|
export function NetscriptSleeve(): InternalAPI<NetscriptSleeve> {
|
||||||
const checkSleeveAPIAccess = function (ctx: NetscriptContext) {
|
|
||||||
if (Player.bitNodeN !== 10 && !Player.sourceFileLvl(10)) {
|
|
||||||
throw helpers.errorMessage(
|
|
||||||
ctx,
|
|
||||||
"You do not currently have access to the Sleeve API. This is either because you are not in BitNode-10 or because you do not have Source-File 10",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const checkSleeveNumber = function (ctx: NetscriptContext, sleeveNumber: number) {
|
|
||||||
if (sleeveNumber >= Player.sleeves.length || sleeveNumber < 0) {
|
|
||||||
const msg = `Invalid sleeve number: ${sleeveNumber}`;
|
|
||||||
helpers.log(ctx, () => msg);
|
|
||||||
throw helpers.errorMessage(ctx, msg);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const sleeveFunctions: InternalAPI<NetscriptSleeve> = {
|
const sleeveFunctions: InternalAPI<NetscriptSleeve> = {
|
||||||
getNumSleeves: (ctx) => () => {
|
getNumSleeves: (ctx) => () => {
|
||||||
checkSleeveAPIAccess(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 type - Type of action.
|
||||||
* @param name - Name of action. Must be an exact match.
|
* @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.
|
* @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.
|
* Get the reputation gain of an action.
|
||||||
|
Loading…
Reference in New Issue
Block a user