mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 12:15:44 +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 |
|
| [productionAmount](./bitburner.product.productionamount.md) | | number | Amount of product produced last cycle |
|
||||||
| [productionCost](./bitburner.product.productioncost.md) | | number | Production cost |
|
| [productionCost](./bitburner.product.productioncost.md) | | number | Production cost |
|
||||||
| [rating](./bitburner.product.rating.md) | | number | Rating based on stats |
|
| [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 |
|
| [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 |
|
| [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;
|
actionName: string;
|
||||||
cyclesWorked: number;
|
cyclesWorked: number;
|
||||||
cyclesNeeded: number;
|
cyclesNeeded: number;
|
||||||
|
nextCompletion: Promise<void>;
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -5,6 +5,7 @@ import { applySleeveGains, SleeveWorkClass, SleeveWorkType } from "./Work";
|
|||||||
import { CONSTANTS } from "../../../Constants";
|
import { CONSTANTS } from "../../../Constants";
|
||||||
import { GeneralActions } from "../../../Bladeburner/data/GeneralActions";
|
import { GeneralActions } from "../../../Bladeburner/data/GeneralActions";
|
||||||
import { scaleWorkStats } from "../../../Work/WorkStats";
|
import { scaleWorkStats } from "../../../Work/WorkStats";
|
||||||
|
import { getKeyList } from "../../../utils/helpers/getKeyList";
|
||||||
|
|
||||||
interface SleeveBladeburnerWorkParams {
|
interface SleeveBladeburnerWorkParams {
|
||||||
type: "General" | "Contracts";
|
type: "General" | "Contracts";
|
||||||
@ -19,9 +20,14 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
|
|||||||
cyclesWorked = 0;
|
cyclesWorked = 0;
|
||||||
actionType: "General" | "Contracts";
|
actionType: "General" | "Contracts";
|
||||||
actionName: string;
|
actionName: string;
|
||||||
|
signalCompletion = () => {
|
||||||
|
// Intentionally empty function, this is just an initial value and will never be used.
|
||||||
|
};
|
||||||
|
nextCompletion: Promise<void>;
|
||||||
|
|
||||||
constructor(params?: SleeveBladeburnerWorkParams) {
|
constructor(params?: SleeveBladeburnerWorkParams) {
|
||||||
super();
|
super();
|
||||||
|
this.nextCompletion = new Promise((r) => (this.signalCompletion = r));
|
||||||
this.actionType = params?.type ?? "General";
|
this.actionType = params?.type ?? "General";
|
||||||
this.actionName = params?.name ?? "Field Analysis";
|
this.actionName = params?.name ?? "Field Analysis";
|
||||||
}
|
}
|
||||||
@ -32,6 +38,10 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
|
|||||||
return ret / CONSTANTS.MilliPerCycle;
|
return ret / CONSTANTS.MilliPerCycle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finish() {
|
||||||
|
this.signalCompletion();
|
||||||
|
}
|
||||||
|
|
||||||
process(sleeve: Sleeve, cycles: number) {
|
process(sleeve: Sleeve, cycles: number) {
|
||||||
if (!Player.bladeburner) return sleeve.stopWork();
|
if (!Player.bladeburner) return sleeve.stopWork();
|
||||||
this.cyclesWorked += cycles;
|
this.cyclesWorked += cycles;
|
||||||
@ -43,7 +53,7 @@ export class SleeveBladeburnerWork extends SleeveWorkClass {
|
|||||||
if (action.count < 1) return sleeve.stopWork();
|
if (action.count < 1) return sleeve.stopWork();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (this.cyclesWorked > this.cyclesNeeded(sleeve)) {
|
while (this.cyclesWorked >= this.cyclesNeeded(sleeve)) {
|
||||||
if (this.actionType === "Contracts") {
|
if (this.actionType === "Contracts") {
|
||||||
const action = Player.bladeburner.getActionObject(actionIdent);
|
const action = Player.bladeburner.getActionObject(actionIdent);
|
||||||
if (!action) throw new Error(`Error getting ${this.actionName} action object`);
|
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));
|
applySleeveGains(sleeve, scaleWorkStats(retValue, sleeve.shockBonus(), false));
|
||||||
}
|
}
|
||||||
this.cyclesWorked -= this.cyclesNeeded(sleeve);
|
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,
|
actionName: this.actionName,
|
||||||
cyclesWorked: this.cyclesWorked,
|
cyclesWorked: this.cyclesWorked,
|
||||||
cyclesNeeded: this.cyclesNeeded(sleeve),
|
cyclesNeeded: this.cyclesNeeded(sleeve),
|
||||||
|
nextCompletion: this.nextCompletion,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static savedKeys = getKeyList(SleeveBladeburnerWork, { removedKeys: ["signalCompletion", "nextCompletion"] });
|
||||||
|
|
||||||
/** 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("SleeveBladeburnerWork", this);
|
return Generic_toJSON("SleeveBladeburnerWork", this, SleeveBladeburnerWork.savedKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initializes a BladeburnerWork object from a JSON save state. */
|
/** Initializes a BladeburnerWork object from a JSON save state. */
|
||||||
static fromJSON(value: IReviverValue): SleeveBladeburnerWork {
|
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;
|
actionName: string;
|
||||||
cyclesWorked: number;
|
cyclesWorked: number;
|
||||||
cyclesNeeded: number;
|
cyclesNeeded: number;
|
||||||
|
nextCompletion: Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
|
Loading…
Reference in New Issue
Block a user