mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 12:15:44 +01:00
SLEEVES: add nextCompletion to SleeveInfiltrationWork (#1177)
* add nextCompletion to InfilWork and make nextCompletion in BladeburnerWork uniform with other promisePairs
This commit is contained in:
parent
bbd942ceca
commit
803afc5244
@ -8,5 +8,10 @@
|
|||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
type SleeveInfiltrateTask = { type: "INFILTRATE"; cyclesWorked: number; cyclesNeeded: number };
|
type SleeveInfiltrateTask = {
|
||||||
|
type: "INFILTRATE";
|
||||||
|
cyclesWorked: number;
|
||||||
|
cyclesNeeded: number;
|
||||||
|
nextCompletion: Promise<void>;
|
||||||
|
};
|
||||||
```
|
```
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import type { PromisePair } from "../../../Types/Promises";
|
||||||
import { Player } from "@player";
|
import { Player } from "@player";
|
||||||
import { Generic_fromJSON, Generic_toJSON, IReviverValue, constructorsForReviver } from "../../../utils/JSONReviver";
|
import { Generic_fromJSON, Generic_toJSON, IReviverValue, constructorsForReviver } from "../../../utils/JSONReviver";
|
||||||
import { Sleeve } from "../Sleeve";
|
import { Sleeve } from "../Sleeve";
|
||||||
@ -21,14 +22,10 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
|
|||||||
cyclesWorked = 0;
|
cyclesWorked = 0;
|
||||||
actionType: "General" | "Contracts";
|
actionType: "General" | "Contracts";
|
||||||
actionName: string;
|
actionName: string;
|
||||||
signalCompletion = () => {
|
nextCompletionPair: PromisePair<void> = { promise: null, resolve: null };
|
||||||
// Intentionally empty function, this is just an initial value and will never be used.
|
|
||||||
};
|
|
||||||
nextCompletionPromise: Promise<void> | null;
|
|
||||||
|
|
||||||
constructor(params?: SleeveBladeburnerWorkParams) {
|
constructor(params?: SleeveBladeburnerWorkParams) {
|
||||||
super();
|
super();
|
||||||
this.nextCompletionPromise = null;
|
|
||||||
this.actionType = params?.type ?? "General";
|
this.actionType = params?.type ?? "General";
|
||||||
this.actionName = params?.name ?? "Field Analysis";
|
this.actionName = params?.name ?? "Field Analysis";
|
||||||
}
|
}
|
||||||
@ -40,7 +37,11 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
finish() {
|
finish() {
|
||||||
if (this.nextCompletionPromise) this.signalCompletion();
|
if (this.nextCompletionPair.resolve) {
|
||||||
|
this.nextCompletionPair.resolve();
|
||||||
|
this.nextCompletionPair.resolve = null;
|
||||||
|
this.nextCompletionPair.promise = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
process(sleeve: Sleeve, cycles: number) {
|
process(sleeve: Sleeve, cycles: number) {
|
||||||
@ -73,12 +74,13 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
|
|||||||
this.tasksCompleted++;
|
this.tasksCompleted++;
|
||||||
this.cyclesWorked -= this.cyclesNeeded(sleeve);
|
this.cyclesWorked -= this.cyclesNeeded(sleeve);
|
||||||
// Resolve and reset nextCompletion promise
|
// Resolve and reset nextCompletion promise
|
||||||
if (this.nextCompletionPromise) this.signalCompletion();
|
this.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
get nextCompletion(): Promise<void> {
|
get nextCompletion(): Promise<void> {
|
||||||
if (!this.nextCompletionPromise) this.nextCompletionPromise = new Promise((r) => (this.signalCompletion = r));
|
if (!this.nextCompletionPair.promise)
|
||||||
return this.nextCompletionPromise;
|
this.nextCompletionPair.promise = new Promise((r) => (this.nextCompletionPair.resolve = r));
|
||||||
|
return this.nextCompletionPair.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
APICopy(sleeve: Sleeve) {
|
APICopy(sleeve: Sleeve) {
|
||||||
@ -93,7 +95,7 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static savedKeys = getKeyList(SleeveBladeburnerWork, { removedKeys: ["signalCompletion", "nextCompletion"] });
|
static savedKeys = getKeyList(SleeveBladeburnerWork, { removedKeys: ["nextCompletionPair"] });
|
||||||
|
|
||||||
/** Serialize the current object to a JSON save state. */
|
/** Serialize the current object to a JSON save state. */
|
||||||
toJSON(): IReviverValue {
|
toJSON(): IReviverValue {
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
import type { PromisePair } from "../../../Types/Promises";
|
||||||
import { Player } from "@player";
|
import { Player } from "@player";
|
||||||
import { Generic_fromJSON, Generic_toJSON, IReviverValue, constructorsForReviver } from "../../../utils/JSONReviver";
|
import { Generic_fromJSON, Generic_toJSON, IReviverValue, constructorsForReviver } from "../../../utils/JSONReviver";
|
||||||
import { Sleeve } from "../Sleeve";
|
import { Sleeve } from "../Sleeve";
|
||||||
import { SleeveWorkClass, SleeveWorkType } from "./Work";
|
import { SleeveWorkClass, SleeveWorkType } from "./Work";
|
||||||
import { CONSTANTS } from "../../../Constants";
|
import { CONSTANTS } from "../../../Constants";
|
||||||
|
import { getKeyList } from "../../../utils/helpers/getKeyList";
|
||||||
|
|
||||||
const infiltrateCycles = 60000 / CONSTANTS.MilliPerCycle;
|
const infiltrateCycles = 60000 / CONSTANTS.MilliPerCycle;
|
||||||
|
|
||||||
@ -12,6 +14,7 @@ export const isSleeveInfiltrateWork = (w: SleeveWorkClass | null): w is SleeveIn
|
|||||||
export class SleeveInfiltrateWork extends SleeveWorkClass {
|
export class SleeveInfiltrateWork extends SleeveWorkClass {
|
||||||
type: SleeveWorkType.INFILTRATE = SleeveWorkType.INFILTRATE;
|
type: SleeveWorkType.INFILTRATE = SleeveWorkType.INFILTRATE;
|
||||||
cyclesWorked = 0;
|
cyclesWorked = 0;
|
||||||
|
nextCompletionPair: PromisePair<void> = { promise: null, resolve: null };
|
||||||
|
|
||||||
cyclesNeeded(): number {
|
cyclesNeeded(): number {
|
||||||
return infiltrateCycles;
|
return infiltrateCycles;
|
||||||
@ -23,25 +26,34 @@ export class SleeveInfiltrateWork extends SleeveWorkClass {
|
|||||||
if (this.cyclesWorked > this.cyclesNeeded()) {
|
if (this.cyclesWorked > this.cyclesNeeded()) {
|
||||||
this.cyclesWorked -= this.cyclesNeeded();
|
this.cyclesWorked -= this.cyclesNeeded();
|
||||||
Player.bladeburner.infiltrateSynthoidCommunities();
|
Player.bladeburner.infiltrateSynthoidCommunities();
|
||||||
|
this.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
get nextCompletion(): Promise<void> {
|
||||||
|
if (!this.nextCompletionPair.promise)
|
||||||
|
this.nextCompletionPair.promise = new Promise((r) => (this.nextCompletionPair.resolve = r));
|
||||||
|
return this.nextCompletionPair.promise;
|
||||||
|
}
|
||||||
|
|
||||||
APICopy() {
|
APICopy() {
|
||||||
return {
|
return {
|
||||||
type: SleeveWorkType.INFILTRATE as const,
|
type: SleeveWorkType.INFILTRATE as const,
|
||||||
cyclesWorked: this.cyclesWorked,
|
cyclesWorked: this.cyclesWorked,
|
||||||
cyclesNeeded: this.cyclesNeeded(),
|
cyclesNeeded: this.cyclesNeeded(),
|
||||||
|
nextCompletion: this.nextCompletion,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static savedKeys = getKeyList(SleeveInfiltrateWork, { removedKeys: ["nextCompletionPair"] });
|
||||||
|
|
||||||
/** 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("SleeveInfiltrateWork", this);
|
return Generic_toJSON("SleeveInfiltrateWork", this, SleeveInfiltrateWork.savedKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initializes a BladeburnerWork object from a JSON save state. */
|
/** Initializes a BladeburnerWork object from a JSON save state. */
|
||||||
static fromJSON(value: IReviverValue): SleeveInfiltrateWork {
|
static fromJSON(value: IReviverValue): SleeveInfiltrateWork {
|
||||||
return Generic_fromJSON(SleeveInfiltrateWork, value.data);
|
return Generic_fromJSON(SleeveInfiltrateWork, value.data, SleeveInfiltrateWork.savedKeys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
7
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -1034,7 +1034,12 @@ type SleeveFactionTask = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
type SleeveInfiltrateTask = { type: "INFILTRATE"; cyclesWorked: number; cyclesNeeded: number };
|
type SleeveInfiltrateTask = {
|
||||||
|
type: "INFILTRATE";
|
||||||
|
cyclesWorked: number;
|
||||||
|
cyclesNeeded: number;
|
||||||
|
nextCompletion: Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
type SleeveRecoveryTask = { type: "RECOVERY" };
|
type SleeveRecoveryTask = { type: "RECOVERY" };
|
||||||
|
Loading…
Reference in New Issue
Block a user