diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index f281d6b02..1ed7d4ae9 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -137,6 +137,7 @@ import { IIndustry } from "./Corporation/IIndustry"; import { Faction } from "./Faction/Faction"; import { Augmentation } from "./Augmentation/Augmentation"; +import { Page } from "./ui/Router"; import { CodingContract } from "./CodingContracts"; import { Stock } from "./StockMarket/Stock"; @@ -3244,12 +3245,16 @@ function NetscriptFunctions(workerScript: WorkerScript): NS { hospitalize: function (): any { updateDynamicRam("hospitalize", getRamCost("hospitalize")); checkSingularityAccess("hospitalize", 1); + if (Player.isWorking || Router.page() === Page.Infiltration || Router.page() === Page.BitVerse) { + workerScript.log("hospitalize", "Cannot go to the hospital because the player is busy."); + return; + } return Player.hospitalize(); }, isBusy: function (): any { updateDynamicRam("isBusy", getRamCost("isBusy")); checkSingularityAccess("isBusy", 1); - return Player.isWorking; + return Player.isWorking || Router.page() === Page.Infiltration || Router.page() === Page.BitVerse; }, stopAction: function (): any { updateDynamicRam("stopAction", getRamCost("stopAction")); diff --git a/src/PersonObjects/IPlayer.ts b/src/PersonObjects/IPlayer.ts index ed18d9352..37fcd2035 100644 --- a/src/PersonObjects/IPlayer.ts +++ b/src/PersonObjects/IPlayer.ts @@ -201,6 +201,7 @@ export interface IPlayer { inGang(): boolean; isQualified(company: Company, position: CompanyPosition): boolean; loseMoney(money: number): void; + process(router: IRouter, numCycles?: number): void; reapplyAllAugmentations(resetMultipliers?: boolean): void; reapplyAllSourceFiles(): void; regenerateHp(amt: number): void; diff --git a/src/PersonObjects/Player/PlayerObject.ts b/src/PersonObjects/Player/PlayerObject.ts index b4df292c1..14ab741c9 100644 --- a/src/PersonObjects/Player/PlayerObject.ts +++ b/src/PersonObjects/Player/PlayerObject.ts @@ -245,6 +245,7 @@ export class PlayerObject implements IPlayer { getIntelligenceBonus: (weight: number) => number; getCasinoWinnings: () => number; quitJob: (company: string) => void; + process: (router: IRouter, numCycles?: number) => void; createHacknetServer: () => HacknetServer; startCreateProgramWork: (router: IRouter, programName: string, time: number, reqLevel: number) => void; queueAugmentation: (augmentationName: string) => void; @@ -505,6 +506,7 @@ export class PlayerObject implements IPlayer { this.getWorkAgiExpGain = generalMethods.getWorkAgiExpGain; this.getWorkChaExpGain = generalMethods.getWorkChaExpGain; this.getWorkRepGain = generalMethods.getWorkRepGain; + this.process = generalMethods.process; this.startCreateProgramWork = generalMethods.startCreateProgramWork; this.createProgramWork = generalMethods.createProgramWork; this.finishCreateProgramWork = generalMethods.finishCreateProgramWork; diff --git a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx index f99bf58ec..64afbb35e 100644 --- a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx +++ b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx @@ -575,6 +575,37 @@ export function startWork(this: IPlayer, router: IRouter, companyName: string): router.toWork(); } +export function process(this: IPlayer, router: IRouter, numCycles = 1): void { + // Working + if (this.isWorking) { + if (this.workType == CONSTANTS.WorkTypeFaction) { + if (this.workForFaction(numCycles)) { + router.toFaction(); + } + } else if (this.workType == CONSTANTS.WorkTypeCreateProgram) { + if (this.createProgramWork(numCycles)) { + router.toTerminal(); + } + } else if (this.workType == CONSTANTS.WorkTypeStudyClass) { + if (this.takeClass(numCycles)) { + router.toCity(); + } + } else if (this.workType == CONSTANTS.WorkTypeCrime) { + if (this.commitCrime(numCycles)) { + router.toLocation(Locations[LocationName.Slums]); + } + } else if (this.workType == CONSTANTS.WorkTypeCompanyPartTime) { + if (this.workPartTime(numCycles)) { + router.toCity(); + } + } else { + if (this.work(numCycles)) { + router.toCity(); + } + } + } +} + export function cancelationPenalty(this: IPlayer): number { const server = GetServer(this.companyName); if (server instanceof Server) { diff --git a/src/Player.ts b/src/Player.ts index 854da4d32..291a360ff 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -29,4 +29,5 @@ export function loadPlayer(saveString: string): void { } Player.exploits = sanitizeExploits(Player.exploits); + console.log(Player.bladeburner); } diff --git a/src/engine.tsx b/src/engine.tsx index dcebd9e07..2699127eb 100644 --- a/src/engine.tsx +++ b/src/engine.tsx @@ -91,34 +91,7 @@ const Engine: { Terminal.process(Router, Player, numCycles); - // Working - if (Player.isWorking) { - if (Player.workType == CONSTANTS.WorkTypeFaction) { - if (Player.workForFaction(numCycles)) { - Router.toFaction(); - } - } else if (Player.workType == CONSTANTS.WorkTypeCreateProgram) { - if (Player.createProgramWork(numCycles)) { - Router.toTerminal(); - } - } else if (Player.workType == CONSTANTS.WorkTypeStudyClass) { - if (Player.takeClass(numCycles)) { - Router.toCity(); - } - } else if (Player.workType == CONSTANTS.WorkTypeCrime) { - if (Player.commitCrime(numCycles)) { - Router.toLocation(Locations[LocationName.Slums]); - } - } else if (Player.workType == CONSTANTS.WorkTypeCompanyPartTime) { - if (Player.workPartTime(numCycles)) { - Router.toCity(); - } - } else { - if (Player.work(numCycles)) { - Router.toCity(); - } - } - } + Player.process(Router, numCycles); // Update stock prices if (Player.hasWseAccount) { diff --git a/src/utils/JSONReviver.ts b/src/utils/JSONReviver.ts index bdbac276d..58740ce0b 100644 --- a/src/utils/JSONReviver.ts +++ b/src/utils/JSONReviver.ts @@ -12,8 +12,7 @@ export interface IReviverValue { // off to that `fromJSON` fuunction, passing in the value. export function Reviver(key: string, value: IReviverValue | null): any { if (value == null) { - console.log("Reviver WRONGLY called with key: " + key + ", and value: " + value); - return 0; + return null; } if (typeof value === "object" && typeof value.ctor === "string" && typeof value.data !== "undefined") {