NETSCRIPTSLEEVE: Add cyclesWorked to ns.sleeve.getTask return (#409)

This commit is contained in:
Snarling 2023-03-07 05:30:15 -05:00 committed by GitHub
parent 4ebfdcc4a8
commit e74dfe9b79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 31 additions and 26 deletions

@ -13,5 +13,6 @@ type SleeveBladeburnerTask = {
actionType: "General" | "Contracts"; actionType: "General" | "Contracts";
actionName: string; actionName: string;
cyclesWorked: number; cyclesWorked: number;
cyclesNeeded: number;
}; };
``` ```

@ -8,7 +8,12 @@
**Signature:** **Signature:**
```typescript ```typescript
type SleeveCrimeTask = { type: "CRIME"; crimeType: CrimeType | `${CrimeType}`; cyclesWorked: number }; type SleeveCrimeTask = {
type: "CRIME";
crimeType: CrimeType | `${CrimeType}`;
cyclesWorked: number;
cyclesNeeded: number;
};
``` ```
**References:** [CrimeType](./bitburner.crimetype.md) **References:** [CrimeType](./bitburner.crimetype.md)

@ -8,5 +8,5 @@
**Signature:** **Signature:**
```typescript ```typescript
type SleeveInfiltrateTask = { type: "INFILTRATE"; cyclesWorked: number }; type SleeveInfiltrateTask = { type: "INFILTRATE"; cyclesWorked: number; cyclesNeeded: number };
``` ```

@ -150,7 +150,7 @@ export function NetscriptSleeve(): InternalAPI<Sleeve> {
const sl = Player.sleeves[sleeveNumber]; const sl = Player.sleeves[sleeveNumber];
if (sl.currentWork === null) return null; if (sl.currentWork === null) return null;
return sl.currentWork.APICopy(); return sl.currentWork.APICopy(sl);
}, },
getSleeve: (ctx) => (_sleeveNumber) => { getSleeve: (ctx) => (_sleeveNumber) => {
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber); const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);

@ -286,7 +286,7 @@ export class Sleeve extends Person implements SleevePerson {
if (company == null) return false; if (company == null) return false;
if (companyPosition == null) return false; if (companyPosition == null) return false;
this.startWork(new SleeveCompanyWork({ companyName: companyName })); this.startWork(new SleeveCompanyWork(companyName));
return true; return true;
} }

@ -32,7 +32,7 @@ export class SleeveBladeburnerWork extends Work {
} }
process(sleeve: Sleeve, cycles: number) { process(sleeve: Sleeve, cycles: number) {
if (!Player.bladeburner) throw new Error("sleeve doing blade work without being a member"); if (!Player.bladeburner) return sleeve.stopWork();
this.cyclesWorked += cycles; this.cyclesWorked += cycles;
const actionIdent = Player.bladeburner.getActionIdFromTypeAndName(this.actionType, this.actionName); const actionIdent = Player.bladeburner.getActionIdFromTypeAndName(this.actionType, this.actionName);
if (!actionIdent) throw new Error(`Error getting ${this.actionName} action`); if (!actionIdent) throw new Error(`Error getting ${this.actionName} action`);
@ -62,12 +62,13 @@ export class SleeveBladeburnerWork extends Work {
} }
} }
APICopy() { APICopy(sleeve: Sleeve) {
return { return {
type: WorkType.BLADEBURNER as "BLADEBURNER", type: WorkType.BLADEBURNER as "BLADEBURNER",
actionType: this.actionType, actionType: this.actionType,
actionName: this.actionName, actionName: this.actionName,
cyclesWorked: this.cyclesWorked, cyclesWorked: this.cyclesWorked,
cyclesNeeded: this.cyclesNeeded(sleeve),
}; };
} }

@ -10,19 +10,15 @@ import { influenceStockThroughCompanyWork } from "../../../StockMarket/PlayerInf
import { Player } from "@player"; import { Player } from "@player";
import { CompanyPositions } from "../../../Company/CompanyPositions"; import { CompanyPositions } from "../../../Company/CompanyPositions";
interface SleeveCompanyWorkParams {
companyName: string;
}
export const isSleeveCompanyWork = (w: Work | null): w is SleeveCompanyWork => export const isSleeveCompanyWork = (w: Work | null): w is SleeveCompanyWork =>
w !== null && w.type === WorkType.COMPANY; w !== null && w.type === WorkType.COMPANY;
export class SleeveCompanyWork extends Work { export class SleeveCompanyWork extends Work {
companyName: string; companyName: string;
constructor(params?: SleeveCompanyWorkParams) { constructor(companyName?: string) {
super(WorkType.COMPANY); super(WorkType.COMPANY);
this.companyName = params?.companyName ?? LocationName.NewTokyoNoodleBar; this.companyName = companyName ?? LocationName.NewTokyoNoodleBar;
} }
getCompany(): Company { getCompany(): Company {

@ -52,6 +52,7 @@ export class SleeveCrimeWork extends Work {
type: WorkType.CRIME as "CRIME", type: WorkType.CRIME as "CRIME",
crimeType: this.crimeType, crimeType: this.crimeType,
cyclesWorked: this.cyclesWorked, cyclesWorked: this.cyclesWorked,
cyclesNeeded: this.cyclesNeeded(),
}; };
} }

@ -20,8 +20,8 @@ export class SleeveInfiltrateWork extends Work {
return infiltrateCycles; return infiltrateCycles;
} }
process(_sleeve: Sleeve, cycles: number) { process(sleeve: Sleeve, cycles: number) {
if (!Player.bladeburner) throw new Error("sleeve doing blade work without being a member"); if (!Player.bladeburner) return sleeve.stopWork();
this.cyclesWorked += cycles; this.cyclesWorked += cycles;
if (this.cyclesWorked > this.cyclesNeeded()) { if (this.cyclesWorked > this.cyclesNeeded()) {
this.cyclesWorked -= this.cyclesNeeded(); this.cyclesWorked -= this.cyclesNeeded();
@ -33,6 +33,7 @@ export class SleeveInfiltrateWork extends Work {
return { return {
type: WorkType.INFILTRATE as "INFILTRATE", type: WorkType.INFILTRATE as "INFILTRATE",
cyclesWorked: this.cyclesWorked, cyclesWorked: this.cyclesWorked,
cyclesNeeded: this.cyclesNeeded(),
}; };
} }

@ -20,9 +20,7 @@ export class SleeveRecoveryWork extends Work {
} }
APICopy() { APICopy() {
return { return { type: WorkType.RECOVERY as "RECOVERY" };
type: WorkType.RECOVERY as "RECOVERY",
};
} }
/** Serialize the current object to a JSON save state. */ /** Serialize the current object to a JSON save state. */

@ -20,9 +20,7 @@ export class SleeveSupportWork extends Work {
} }
APICopy() { APICopy() {
return { return { type: WorkType.SUPPORT as "SUPPORT" };
type: WorkType.SUPPORT as "SUPPORT",
};
} }
/** Serialize the current object to a JSON save state. */ /** Serialize the current object to a JSON save state. */

@ -21,9 +21,7 @@ export class SleeveSynchroWork extends Work {
} }
APICopy() { APICopy() {
return { return { type: WorkType.SYNCHRO as "SYNCHRO" };
type: WorkType.SYNCHRO as "SYNCHRO",
};
} }
/** Serialize the current object to a JSON save state. */ /** Serialize the current object to a JSON save state. */

@ -22,7 +22,7 @@ export abstract class Work {
} }
abstract process(sleeve: Sleeve, cycles: number): void; abstract process(sleeve: Sleeve, cycles: number): void;
abstract APICopy(): SleeveTask; abstract APICopy(sleeve: Sleeve): SleeveTask;
abstract toJSON(): IReviverValue; abstract toJSON(): IReviverValue;
finish(): void { finish(): void {
/* left for children to implement */ /* left for children to implement */

@ -878,6 +878,7 @@ type SleeveBladeburnerTask = {
actionType: "General" | "Contracts"; actionType: "General" | "Contracts";
actionName: string; actionName: string;
cyclesWorked: number; cyclesWorked: number;
cyclesNeeded: number;
}; };
/** @public */ /** @public */
@ -891,7 +892,12 @@ type SleeveClassTask = {
type SleeveCompanyTask = { type: "COMPANY"; companyName: string }; type SleeveCompanyTask = { type: "COMPANY"; companyName: string };
/** @public */ /** @public */
type SleeveCrimeTask = { type: "CRIME"; crimeType: CrimeType | `${CrimeType}`; cyclesWorked: number }; type SleeveCrimeTask = {
type: "CRIME";
crimeType: CrimeType | `${CrimeType}`;
cyclesWorked: number;
cyclesNeeded: number;
};
/** @public */ /** @public */
type SleeveFactionTask = { type SleeveFactionTask = {
@ -901,7 +907,7 @@ type SleeveFactionTask = {
}; };
/** @public */ /** @public */
type SleeveInfiltrateTask = { type: "INFILTRATE"; cyclesWorked: number }; type SleeveInfiltrateTask = { type: "INFILTRATE"; cyclesWorked: number; cyclesNeeded: number };
/** @public */ /** @public */
type SleeveRecoveryTask = { type: "RECOVERY" }; type SleeveRecoveryTask = { type: "RECOVERY" };