mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-08 08:43:53 +01:00
SLEEVE: Add a nextCompletion promise to SleeveBladeburnerWork (#916)
This commit is contained in:
parent
0c4cf81f66
commit
aaf80a9a33
@ -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 |
|
||||
|
||||
|
13
markdown/bitburner.product.size.md
Normal file
13
markdown/bitburner.product.size.md
Normal file
@ -0,0 +1,13 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [Product](./bitburner.product.md) > [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);
|
||||
}
|
||||
}
|
||||
|
||||
|
1
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
1
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -986,6 +986,7 @@ type SleeveBladeburnerTask = {
|
||||
actionName: string;
|
||||
cyclesWorked: number;
|
||||
cyclesNeeded: number;
|
||||
nextCompletion: Promise<void>;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
|
Loading…
Reference in New Issue
Block a user