mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-08 08:43:53 +01:00
GRAFTING: Add new api for checking ongoing grafting (#1435)
This commit is contained in:
parent
32eb6324fd
commit
b1c1fc24a9
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
## Grafting.getAugmentationGraftTime() method
|
## Grafting.getAugmentationGraftTime() method
|
||||||
|
|
||||||
Retrieves the time required to graft an aug.
|
Retrieves the time required to graft an aug. Do not use this value to determine when the ongoing grafting finishes. The ongoing grafting is affected by current intelligence level and focus bonus. You should use [waitForOngoingGrafting](./bitburner.grafting.waitforongoinggrafting.md) for that purpose.
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ getAugmentationGraftTime(augName: string): number;
|
|||||||
|
|
||||||
number
|
number
|
||||||
|
|
||||||
The time required, in millis, to graft the named augmentation.
|
The time required, in milliseconds, to graft the named augmentation.
|
||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
## Grafting.graftAugmentation() method
|
## Grafting.graftAugmentation() method
|
||||||
|
|
||||||
Begins grafting the named aug. You must be in New Tokyo to use this.
|
Begins grafting the named aug. You must be in New Tokyo to use this. When you call this API, the current work (grafting or other actions) will be canceled.
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ This API requires Source-File 10 to use.
|
|||||||
| Method | Description |
|
| Method | Description |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| [getAugmentationGraftPrice(augName)](./bitburner.grafting.getaugmentationgraftprice.md) | Retrieve the grafting cost of an aug. |
|
| [getAugmentationGraftPrice(augName)](./bitburner.grafting.getaugmentationgraftprice.md) | Retrieve the grafting cost of an aug. |
|
||||||
| [getAugmentationGraftTime(augName)](./bitburner.grafting.getaugmentationgrafttime.md) | Retrieves the time required to graft an aug. |
|
| [getAugmentationGraftTime(augName)](./bitburner.grafting.getaugmentationgrafttime.md) | Retrieves the time required to graft an aug. Do not use this value to determine when the ongoing grafting finishes. The ongoing grafting is affected by current intelligence level and focus bonus. You should use [waitForOngoingGrafting](./bitburner.grafting.waitforongoinggrafting.md) for that purpose. |
|
||||||
| [getGraftableAugmentations()](./bitburner.grafting.getgraftableaugmentations.md) | Retrieves a list of Augmentations that can be grafted. |
|
| [getGraftableAugmentations()](./bitburner.grafting.getgraftableaugmentations.md) | Retrieves a list of Augmentations that can be grafted. |
|
||||||
| [graftAugmentation(augName, focus)](./bitburner.grafting.graftaugmentation.md) | Begins grafting the named aug. You must be in New Tokyo to use this. |
|
| [graftAugmentation(augName, focus)](./bitburner.grafting.graftaugmentation.md) | Begins grafting the named aug. You must be in New Tokyo to use this. When you call this API, the current work (grafting or other actions) will be canceled. |
|
||||||
|
| [waitForOngoingGrafting()](./bitburner.grafting.waitforongoinggrafting.md) | Wait until the ongoing grafting finishes or is canceled. |
|
||||||
|
|
||||||
|
23
markdown/bitburner.grafting.waitforongoinggrafting.md
Normal file
23
markdown/bitburner.grafting.waitforongoinggrafting.md
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||||
|
|
||||||
|
[Home](./index.md) > [bitburner](./bitburner.md) > [Grafting](./bitburner.grafting.md) > [waitForOngoingGrafting](./bitburner.grafting.waitforongoinggrafting.md)
|
||||||
|
|
||||||
|
## Grafting.waitForOngoingGrafting() method
|
||||||
|
|
||||||
|
Wait until the ongoing grafting finishes or is canceled.
|
||||||
|
|
||||||
|
**Signature:**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
waitForOngoingGrafting(): Promise<void>;
|
||||||
|
```
|
||||||
|
**Returns:**
|
||||||
|
|
||||||
|
Promise<void>
|
||||||
|
|
||||||
|
A promise that resolves when the current grafting finishes or is canceled. If there is no current work, the promise resolves immediately. If the current work is not a grafting work, the promise rejects immediately.
|
||||||
|
|
||||||
|
## Remarks
|
||||||
|
|
||||||
|
RAM cost: 1 GB
|
||||||
|
|
11
markdown/bitburner.graftingtask.completion.md
Normal file
11
markdown/bitburner.graftingtask.completion.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||||
|
|
||||||
|
[Home](./index.md) > [bitburner](./bitburner.md) > [GraftingTask](./bitburner.graftingtask.md) > [completion](./bitburner.graftingtask.completion.md)
|
||||||
|
|
||||||
|
## GraftingTask.completion property
|
||||||
|
|
||||||
|
**Signature:**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
completion: Promise<void>;
|
||||||
|
```
|
@ -21,6 +21,7 @@ An object representing the current grafting status
|
|||||||
| Property | Modifiers | Type | Description |
|
| Property | Modifiers | Type | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| [augmentation](./bitburner.graftingtask.augmentation.md) | | string | |
|
| [augmentation](./bitburner.graftingtask.augmentation.md) | | string | |
|
||||||
|
| [completion](./bitburner.graftingtask.completion.md) | | Promise<void> | |
|
||||||
| [cyclesWorked](./bitburner.graftingtask.cyclesworked.md) | | number | |
|
| [cyclesWorked](./bitburner.graftingtask.cyclesworked.md) | | number | |
|
||||||
| [type](./bitburner.graftingtask.type.md) | | "GRAFTING" | |
|
| [type](./bitburner.graftingtask.type.md) | | "GRAFTING" | |
|
||||||
|
|
||||||
|
@ -388,6 +388,7 @@ const grafting = {
|
|||||||
getAugmentationGraftTime: 3.75,
|
getAugmentationGraftTime: 3.75,
|
||||||
getGraftableAugmentations: 5,
|
getGraftableAugmentations: 5,
|
||||||
graftAugmentation: 7.5,
|
graftAugmentation: 7.5,
|
||||||
|
waitForOngoingGrafting: 1,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const corporation = {
|
const corporation = {
|
||||||
|
@ -97,5 +97,18 @@ export function NetscriptGrafting(): InternalAPI<IGrafting> {
|
|||||||
helpers.log(ctx, () => `Began grafting Augmentation ${augName}.`);
|
helpers.log(ctx, () => `Began grafting Augmentation ${augName}.`);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
waitForOngoingGrafting: (ctx) => () => {
|
||||||
|
checkGraftingAPIAccess(ctx);
|
||||||
|
if (!Player.currentWork) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
if (!(Player.currentWork instanceof GraftingWork)) {
|
||||||
|
return Promise.reject(
|
||||||
|
`The current work is not a grafting work. Type of current work: ${Player.currentWork.type}.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Player.currentWork.completion;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
24
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
24
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -1690,6 +1690,7 @@ export interface GraftingTask {
|
|||||||
type: "GRAFTING";
|
type: "GRAFTING";
|
||||||
cyclesWorked: number;
|
cyclesWorked: number;
|
||||||
augmentation: string;
|
augmentation: string;
|
||||||
|
completion: Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4634,18 +4635,22 @@ export interface Grafting {
|
|||||||
getAugmentationGraftPrice(augName: string): number;
|
getAugmentationGraftPrice(augName: string): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the time required to graft an aug.
|
* Retrieves the time required to graft an aug. Do not use this value to determine when the ongoing grafting finishes.
|
||||||
|
* The ongoing grafting is affected by current intelligence level and focus bonus. You should use
|
||||||
|
* {@link Grafting.waitForOngoingGrafting | waitForOngoingGrafting} for that purpose.
|
||||||
|
*
|
||||||
* @remarks
|
* @remarks
|
||||||
* RAM cost: 3.75 GB
|
* RAM cost: 3.75 GB
|
||||||
*
|
*
|
||||||
* @param augName - Name of the aug to check the grafting time of. Must be an exact match.
|
* @param augName - Name of the aug to check the grafting time of. Must be an exact match.
|
||||||
* @returns The time required, in millis, to graft the named augmentation.
|
* @returns The time required, in milliseconds, to graft the named augmentation.
|
||||||
* @throws Will error if an invalid Augmentation name is provided.
|
* @throws Will error if an invalid Augmentation name is provided.
|
||||||
*/
|
*/
|
||||||
getAugmentationGraftTime(augName: string): number;
|
getAugmentationGraftTime(augName: string): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a list of Augmentations that can be grafted.
|
* Retrieves a list of Augmentations that can be grafted.
|
||||||
|
*
|
||||||
* @remarks
|
* @remarks
|
||||||
* RAM cost: 5 GB
|
* RAM cost: 5 GB
|
||||||
*
|
*
|
||||||
@ -4657,7 +4662,9 @@ export interface Grafting {
|
|||||||
getGraftableAugmentations(): string[];
|
getGraftableAugmentations(): string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begins grafting the named aug. You must be in New Tokyo to use this.
|
* Begins grafting the named aug. You must be in New Tokyo to use this. When you call this API, the current work
|
||||||
|
* (grafting or other actions) will be canceled.
|
||||||
|
*
|
||||||
* @remarks
|
* @remarks
|
||||||
* RAM cost: 7.5 GB
|
* RAM cost: 7.5 GB
|
||||||
*
|
*
|
||||||
@ -4668,6 +4675,17 @@ export interface Grafting {
|
|||||||
* @throws Will error if called while you are not in New Tokyo.
|
* @throws Will error if called while you are not in New Tokyo.
|
||||||
*/
|
*/
|
||||||
graftAugmentation(augName: string, focus?: boolean): boolean;
|
graftAugmentation(augName: string, focus?: boolean): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait until the ongoing grafting finishes or is canceled.
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* RAM cost: 1 GB
|
||||||
|
*
|
||||||
|
* @returns A promise that resolves when the current grafting finishes or is canceled. If there is no current work,
|
||||||
|
* the promise resolves immediately. If the current work is not a grafting work, the promise rejects immediately.
|
||||||
|
*/
|
||||||
|
waitForOngoingGrafting(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,6 +10,8 @@ import { dialogBoxCreate } from "../ui/React/DialogBox";
|
|||||||
import { constructorsForReviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver";
|
import { constructorsForReviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver";
|
||||||
import { GraftableAugmentation } from "../PersonObjects/Grafting/GraftableAugmentation";
|
import { GraftableAugmentation } from "../PersonObjects/Grafting/GraftableAugmentation";
|
||||||
import { Augmentations } from "../Augmentation/Augmentations";
|
import { Augmentations } from "../Augmentation/Augmentations";
|
||||||
|
import { PromisePair } from "../Types/Promises";
|
||||||
|
import { getKeyList } from "../utils/helpers/getKeyList";
|
||||||
|
|
||||||
export const isGraftingWork = (w: Work | null): w is GraftingWork => w !== null && w.type === WorkType.GRAFTING;
|
export const isGraftingWork = (w: Work | null): w is GraftingWork => w !== null && w.type === WorkType.GRAFTING;
|
||||||
|
|
||||||
@ -22,6 +24,14 @@ export class GraftingWork extends Work {
|
|||||||
augmentation: AugmentationName;
|
augmentation: AugmentationName;
|
||||||
unitCompleted: number;
|
unitCompleted: number;
|
||||||
unitRate: number;
|
unitRate: number;
|
||||||
|
completionPromisePair: PromisePair<void> = { promise: null, resolve: null };
|
||||||
|
|
||||||
|
get completion(): Promise<void> {
|
||||||
|
if (!this.completionPromisePair.promise) {
|
||||||
|
this.completionPromisePair.promise = new Promise((r) => (this.completionPromisePair.resolve = r));
|
||||||
|
}
|
||||||
|
return this.completionPromisePair.promise;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(params?: GraftingWorkParams) {
|
constructor(params?: GraftingWorkParams) {
|
||||||
super(WorkType.GRAFTING, params?.singularity ?? true);
|
super(WorkType.GRAFTING, params?.singularity ?? true);
|
||||||
@ -79,6 +89,12 @@ export class GraftingWork extends Work {
|
|||||||
(CONSTANTS.IntelligenceGraftBaseExpGain * this.cyclesWorked * CONSTANTS.MilliPerCycle) / 10000,
|
(CONSTANTS.IntelligenceGraftBaseExpGain * this.cyclesWorked * CONSTANTS.MilliPerCycle) / 10000,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.completionPromisePair.resolve) {
|
||||||
|
this.completionPromisePair.resolve();
|
||||||
|
this.completionPromisePair.resolve = null;
|
||||||
|
this.completionPromisePair.promise = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
APICopy() {
|
APICopy() {
|
||||||
@ -86,17 +102,20 @@ export class GraftingWork extends Work {
|
|||||||
type: WorkType.GRAFTING as const,
|
type: WorkType.GRAFTING as const,
|
||||||
cyclesWorked: this.cyclesWorked,
|
cyclesWorked: this.cyclesWorked,
|
||||||
augmentation: this.augmentation,
|
augmentation: this.augmentation,
|
||||||
|
completion: this.completion,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static savedKeys = getKeyList(GraftingWork, { removedKeys: ["completionPromisePair"] });
|
||||||
|
|
||||||
/** Serialize the current object to a JSON save state. */
|
/** Serialize the current object to a JSON save state. */
|
||||||
toJSON(): IReviverValue {
|
toJSON(): IReviverValue {
|
||||||
return Generic_toJSON("GraftingWork", this);
|
return Generic_toJSON("GraftingWork", this, GraftingWork.savedKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initializes a GraftingWork object from a JSON save state. */
|
/** Initializes a GraftingWork object from a JSON save state. */
|
||||||
static fromJSON(value: IReviverValue): GraftingWork {
|
static fromJSON(value: IReviverValue): GraftingWork {
|
||||||
return Generic_fromJSON(GraftingWork, value.data);
|
return Generic_fromJSON(GraftingWork, value.data, GraftingWork.savedKeys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user