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";
actionName: string;
cyclesWorked: number;
cyclesNeeded: number;
};
```

@ -8,7 +8,12 @@
**Signature:**
```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)

@ -8,5 +8,5 @@
**Signature:**
```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];
if (sl.currentWork === null) return null;
return sl.currentWork.APICopy();
return sl.currentWork.APICopy(sl);
},
getSleeve: (ctx) => (_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 (companyPosition == null) return false;
this.startWork(new SleeveCompanyWork({ companyName: companyName }));
this.startWork(new SleeveCompanyWork(companyName));
return true;
}

@ -32,7 +32,7 @@ export class SleeveBladeburnerWork extends Work {
}
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;
const actionIdent = Player.bladeburner.getActionIdFromTypeAndName(this.actionType, this.actionName);
if (!actionIdent) throw new Error(`Error getting ${this.actionName} action`);
@ -62,12 +62,13 @@ export class SleeveBladeburnerWork extends Work {
}
}
APICopy() {
APICopy(sleeve: Sleeve) {
return {
type: WorkType.BLADEBURNER as "BLADEBURNER",
actionType: this.actionType,
actionName: this.actionName,
cyclesWorked: this.cyclesWorked,
cyclesNeeded: this.cyclesNeeded(sleeve),
};
}

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

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

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

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

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

@ -21,9 +21,7 @@ export class SleeveSynchroWork extends Work {
}
APICopy() {
return {
type: WorkType.SYNCHRO as "SYNCHRO",
};
return { type: WorkType.SYNCHRO as "SYNCHRO" };
}
/** 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 APICopy(): SleeveTask;
abstract APICopy(sleeve: Sleeve): SleeveTask;
abstract toJSON(): IReviverValue;
finish(): void {
/* left for children to implement */

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