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
14 changed files with 31 additions and 26 deletions
+1 -1
View File
@@ -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. */
+1 -1
View File
@@ -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 */