SLEEVE: Add a nextCompletion promise to SleeveBladeburnerWork (#916)

This commit is contained in:
Snarling 2023-11-05 20:09:34 -05:00 committed by GitHub
parent 0c4cf81f66
commit aaf80a9a33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 3 deletions

@ -29,6 +29,7 @@ interface Product
| [productionAmount](./bitburner.product.productionamount.md) | | number | Amount of product produced last cycle |
| [productionCost](./bitburner.product.productioncost.md) | | number | Production cost |
| [rating](./bitburner.product.rating.md) | | number | Rating based on stats |
| [size](./bitburner.product.size.md) | | number | How much warehouse space is occupied per unit of this product |
| [stats](./bitburner.product.stats.md) | | { quality: number; performance: number; durability: number; reliability: number; aesthetics: number; features: number; } | Product stats |
| [stored](./bitburner.product.stored.md) | | number | Amount of product stored in warehouse |

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [Product](./bitburner.product.md) &gt; [size](./bitburner.product.size.md)
## Product.size property
How much warehouse space is occupied per unit of this product
**Signature:**
```typescript
size: number;
```

@ -14,5 +14,6 @@ type SleeveBladeburnerTask = {
actionName: string;
cyclesWorked: number;
cyclesNeeded: number;
nextCompletion: Promise<void>;
};
```

@ -5,6 +5,7 @@ import { applySleeveGains, SleeveWorkClass, SleeveWorkType } from "./Work";
import { CONSTANTS } from "../../../Constants";
import { GeneralActions } from "../../../Bladeburner/data/GeneralActions";
import { scaleWorkStats } from "../../../Work/WorkStats";
import { getKeyList } from "../../../utils/helpers/getKeyList";
interface SleeveBladeburnerWorkParams {
type: "General" | "Contracts";
@ -19,9 +20,14 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
cyclesWorked = 0;
actionType: "General" | "Contracts";
actionName: string;
signalCompletion = () => {
// Intentionally empty function, this is just an initial value and will never be used.
};
nextCompletion: Promise<void>;
constructor(params?: SleeveBladeburnerWorkParams) {
super();
this.nextCompletion = new Promise((r) => (this.signalCompletion = r));
this.actionType = params?.type ?? "General";
this.actionName = params?.name ?? "Field Analysis";
}
@ -32,6 +38,10 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
return ret / CONSTANTS.MilliPerCycle;
}
finish() {
this.signalCompletion();
}
process(sleeve: Sleeve, cycles: number) {
if (!Player.bladeburner) return sleeve.stopWork();
this.cyclesWorked += cycles;
@ -43,7 +53,7 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
if (action.count < 1) return sleeve.stopWork();
}
while (this.cyclesWorked > this.cyclesNeeded(sleeve)) {
while (this.cyclesWorked >= this.cyclesNeeded(sleeve)) {
if (this.actionType === "Contracts") {
const action = Player.bladeburner.getActionObject(actionIdent);
if (!action) throw new Error(`Error getting ${this.actionName} action object`);
@ -60,6 +70,10 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
applySleeveGains(sleeve, scaleWorkStats(retValue, sleeve.shockBonus(), false));
}
this.cyclesWorked -= this.cyclesNeeded(sleeve);
// Resolve and reset nextCompletion promise
const resolver = this.signalCompletion;
this.nextCompletion = new Promise((r) => (this.signalCompletion = r));
resolver();
}
}
@ -70,17 +84,20 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
actionName: this.actionName,
cyclesWorked: this.cyclesWorked,
cyclesNeeded: this.cyclesNeeded(sleeve),
nextCompletion: this.nextCompletion,
};
}
static savedKeys = getKeyList(SleeveBladeburnerWork, { removedKeys: ["signalCompletion", "nextCompletion"] });
/** Serialize the current object to a JSON save state. */
toJSON(): IReviverValue {
return Generic_toJSON("SleeveBladeburnerWork", this);
return Generic_toJSON("SleeveBladeburnerWork", this, SleeveBladeburnerWork.savedKeys);
}
/** Initializes a BladeburnerWork object from a JSON save state. */
static fromJSON(value: IReviverValue): SleeveBladeburnerWork {
return Generic_fromJSON(SleeveBladeburnerWork, value.data);
return Generic_fromJSON(SleeveBladeburnerWork, value.data, SleeveBladeburnerWork.savedKeys);
}
}

@ -986,6 +986,7 @@ type SleeveBladeburnerTask = {
actionName: string;
cyclesWorked: number;
cyclesNeeded: number;
nextCompletion: Promise<void>;
};
/** @public */