diff --git a/src/Faction/ui/FactionRoot.tsx b/src/Faction/ui/FactionRoot.tsx index 283d0d18e..256efe865 100644 --- a/src/Faction/ui/FactionRoot.tsx +++ b/src/Faction/ui/FactionRoot.tsx @@ -82,16 +82,24 @@ function MainPage({ faction, rerender, onAugmentations }: IMainProps): React.Rea setGangOpen(true); } + function startWork() { + player.startFocusing(); + router.toWork(); + } + function startFieldWork(faction: Faction): void { - player.startFactionFieldWork(router, faction); + player.startFactionFieldWork(faction); + startWork(); } function startHackingContracts(faction: Faction): void { - player.startFactionHackWork(router, faction); + player.startFactionHackWork(faction); + startWork(); } function startSecurityWork(faction: Faction): void { - player.startFactionSecurityWork(router, faction); + player.startFactionSecurityWork(faction); + startWork(); } // We have a special flag for whether the player this faction is the player's diff --git a/src/Locations/ui/CompanyLocation.tsx b/src/Locations/ui/CompanyLocation.tsx index 95bc5d8c8..f9d3ee96f 100644 --- a/src/Locations/ui/CompanyLocation.tsx +++ b/src/Locations/ui/CompanyLocation.tsx @@ -171,10 +171,11 @@ export function CompanyLocation(props: IProps): React.ReactElement { const pos = companyPosition; if (pos instanceof CompanyPosition) { if (pos.isPartTimeJob() || pos.isSoftwareConsultantJob() || pos.isBusinessConsultantJob()) { - p.startWorkPartTime(router, props.locName); + p.startWorkPartTime(props.locName); } else { - p.startWork(router, props.locName); + p.startWork(props.locName); } + p.startFocusing(); router.toWork(); } } diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index 1bc0131b7..9142deb1b 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -622,6 +622,21 @@ export function NetscriptSingularity( return Promise.resolve(); }); }, + isFocused: function(): boolean { + helper.updateDynamicRam("isFocused", getRamCost("isFocused")); + helper.checkSingularityAccess("isFocused", 1); + return player.focus; + }, + setFocus: function(focus: boolean): any { + helper.updateDynamicRam("setFocus", getRamCost("setFocus")); + helper.checkSingularityAccess("setFocus", 1); + if (focus === true) { + player.startFocusing(); + Router.toWork(); + } else if (focus === false) { + player.stopFocusing(); + } + }, getStats: function (): any { helper.updateDynamicRam("getStats", getRamCost("getStats")); helper.checkSingularityAccess("getStats", 1); @@ -820,10 +835,11 @@ export function NetscriptSingularity( } if (companyPosition.isPartTimeJob()) { - player.startWorkPartTime(Router, companyName); + player.startWorkPartTime(companyName); } else { - player.startWork(Router, companyName); + player.startWork(companyName); } + player.stopFocusing(); workerScript.log( "workForCompany", () => `Began working at '${player.companyName}' as a '${companyPositionName}'`, @@ -1060,7 +1076,8 @@ export function NetscriptSingularity( workerScript.log("workForFaction", () => `Faction '${fac.name}' do not need help with hacking contracts.`); return false; } - player.startFactionHackWork(Router, fac); + player.startFactionHackWork(fac); + player.stopFocusing(); workerScript.log("workForFaction", () => `Started carrying out hacking contracts for '${fac.name}'`); return true; case "field": @@ -1070,7 +1087,8 @@ export function NetscriptSingularity( workerScript.log("workForFaction", () => `Faction '${fac.name}' do not need help with field missions.`); return false; } - player.startFactionFieldWork(Router, fac); + player.startFactionFieldWork(fac); + player.stopFocusing(); workerScript.log("workForFaction", () => `Started carrying out field missions for '${fac.name}'`); return true; case "security": @@ -1080,7 +1098,8 @@ export function NetscriptSingularity( workerScript.log("workForFaction", () => `Faction '${fac.name}' do not need help with security work.`); return false; } - player.startFactionSecurityWork(Router, fac); + player.startFactionSecurityWork(fac); + player.stopFocusing(); workerScript.log("workForFaction", () => `Started carrying out security work for '${fac.name}'`); return true; default: diff --git a/src/PersonObjects/IPlayer.ts b/src/PersonObjects/IPlayer.ts index a90e2505f..346c65581 100644 --- a/src/PersonObjects/IPlayer.ts +++ b/src/PersonObjects/IPlayer.ts @@ -211,7 +211,7 @@ export interface IPlayer { setMoney(amt: number): void; singularityStopWork(): string; startBladeburner(p: any): void; - startFactionWork(router: IRouter, faction: Faction): void; + startFactionWork(faction: Faction): void; startClass(router: IRouter, costMult: number, expMult: number, className: string): void; startCorporation(corpName: string, additionalShares?: number): void; startCrime( @@ -227,13 +227,13 @@ export interface IPlayer { time: number, singParams: any, ): void; - startFactionFieldWork(router: IRouter, faction: Faction): void; - startFactionHackWork(router: IRouter, faction: Faction): void; - startFactionSecurityWork(router: IRouter, faction: Faction): void; + startFactionFieldWork(faction: Faction): void; + startFactionHackWork(faction: Faction): void; + startFactionSecurityWork(faction: Faction): void; startFocusing(): void; startGang(facName: string, isHacking: boolean): void; - startWork(router: IRouter, companyName: string): void; - startWorkPartTime(router: IRouter, companyName: string): void; + startWork(companyName: string): void; + startWorkPartTime(companyName: string): void; takeDamage(amt: number): boolean; travel(to: CityName): boolean; giveExploit(exploit: Exploit): void; diff --git a/src/PersonObjects/Player/PlayerObject.ts b/src/PersonObjects/Player/PlayerObject.ts index f01bac08d..74974ff0d 100644 --- a/src/PersonObjects/Player/PlayerObject.ts +++ b/src/PersonObjects/Player/PlayerObject.ts @@ -216,7 +216,7 @@ export class PlayerObject implements IPlayer { setMoney: (amt: number) => void; singularityStopWork: () => string; startBladeburner: (p: any) => void; - startFactionWork: (router: IRouter, faction: Faction) => void; + startFactionWork: (faction: Faction) => void; startClass: (router: IRouter, costMult: number, expMult: number, className: string) => void; startCorporation: (corpName: string, additionalShares?: number) => void; startCrime: ( @@ -232,13 +232,13 @@ export class PlayerObject implements IPlayer { time: number, singParams: any, ) => void; - startFactionFieldWork: (router: IRouter, faction: Faction) => void; - startFactionHackWork: (router: IRouter, faction: Faction) => void; - startFactionSecurityWork: (router: IRouter, faction: Faction) => void; + startFactionFieldWork: (faction: Faction) => void; + startFactionHackWork: (faction: Faction) => void; + startFactionSecurityWork: (faction: Faction) => void; startFocusing: () => void; startGang: (facName: string, isHacking: boolean) => void; - startWork: (router: IRouter, companyName: string) => void; - startWorkPartTime: (router: IRouter, companyName: string) => void; + startWork: (companyName: string) => void; + startWorkPartTime: (companyName: string) => void; takeDamage: (amt: number) => boolean; travel: (to: CityName) => boolean; giveExploit: (exploit: Exploit) => void; diff --git a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx index 95ea3e371..c5ed59dbb 100644 --- a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx +++ b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx @@ -554,10 +554,9 @@ export function processWorkEarnings(this: IPlayer, numCycles = 1): void { } /* Working for Company */ -export function startWork(this: IPlayer, router: IRouter, companyName: string): void { +export function startWork(this: IPlayer, companyName: string): void { this.resetWorkStatus(CONSTANTS.WorkTypeCompany, companyName); this.isWorking = true; - this.focus = true; this.companyName = companyName; this.workType = CONSTANTS.WorkTypeCompany; @@ -571,7 +570,6 @@ export function startWork(this: IPlayer, router: IRouter, companyName: string): this.workMoneyGainRate = this.getWorkMoneyGain(); this.timeNeededToCompleteWork = CONSTANTS.MillisecondsPer8Hours; - router.toWork(); } export function process(this: IPlayer, router: IRouter, numCycles = 1): void { @@ -723,10 +721,9 @@ export function finishWork(this: IPlayer, cancelled: boolean, sing = false): str return ""; } -export function startWorkPartTime(this: IPlayer, router: IRouter, companyName: string): void { +export function startWorkPartTime(this: IPlayer, companyName: string): void { this.resetWorkStatus(CONSTANTS.WorkTypeCompanyPartTime, companyName); this.isWorking = true; - this.focus = true; this.companyName = companyName; this.workType = CONSTANTS.WorkTypeCompanyPartTime; @@ -740,7 +737,6 @@ export function startWorkPartTime(this: IPlayer, router: IRouter, companyName: s this.workMoneyGainRate = this.getWorkMoneyGain(); this.timeNeededToCompleteWork = CONSTANTS.MillisecondsPer8Hours; - router.toWork(); } export function workPartTime(this: IPlayer, numCycles: number): boolean { @@ -832,7 +828,7 @@ export function stopFocusing(this: IPlayer): void { } /* Working for Faction */ -export function startFactionWork(this: IPlayer, router: IRouter, faction: Faction): void { +export function startFactionWork(this: IPlayer, faction: Faction): void { //Update reputation gain rate to account for faction favor let favorMult = 1 + faction.favor / 100; if (isNaN(favorMult)) { @@ -842,15 +838,13 @@ export function startFactionWork(this: IPlayer, router: IRouter, faction: Factio this.workRepGainRate *= BitNodeMultipliers.FactionWorkRepGain; this.isWorking = true; - this.focus = true; this.workType = CONSTANTS.WorkTypeFaction; this.currentWorkFactionName = faction.name; this.timeNeededToCompleteWork = CONSTANTS.MillisecondsPer20Hours; - router.toWork(); } -export function startFactionHackWork(this: IPlayer, router: IRouter, faction: Faction): void { +export function startFactionHackWork(this: IPlayer, faction: Faction): void { this.resetWorkStatus(CONSTANTS.WorkTypeFaction, faction.name, CONSTANTS.FactionWorkHacking); this.workHackExpGainRate = 0.15 * this.hacking_exp_mult * BitNodeMultipliers.FactionWorkExpGain; @@ -859,10 +853,10 @@ export function startFactionHackWork(this: IPlayer, router: IRouter, faction: Fa this.factionWorkType = CONSTANTS.FactionWorkHacking; this.currentWorkFactionDescription = "carrying out hacking contracts"; - this.startFactionWork(router, faction); + this.startFactionWork(faction); } -export function startFactionFieldWork(this: IPlayer, router: IRouter, faction: Faction): void { +export function startFactionFieldWork(this: IPlayer, faction: Faction): void { this.resetWorkStatus(CONSTANTS.WorkTypeFaction, faction.name, CONSTANTS.FactionWorkField); this.workHackExpGainRate = 0.1 * this.hacking_exp_mult * BitNodeMultipliers.FactionWorkExpGain; @@ -876,10 +870,10 @@ export function startFactionFieldWork(this: IPlayer, router: IRouter, faction: F this.factionWorkType = CONSTANTS.FactionWorkField; this.currentWorkFactionDescription = "carrying out field missions"; - this.startFactionWork(router, faction); + this.startFactionWork(faction); } -export function startFactionSecurityWork(this: IPlayer, router: IRouter, faction: Faction): void { +export function startFactionSecurityWork(this: IPlayer, faction: Faction): void { this.resetWorkStatus(CONSTANTS.WorkTypeFaction, faction.name, CONSTANTS.FactionWorkSecurity); this.workHackExpGainRate = 0.05 * this.hacking_exp_mult * BitNodeMultipliers.FactionWorkExpGain; @@ -893,7 +887,7 @@ export function startFactionSecurityWork(this: IPlayer, router: IRouter, faction this.factionWorkType = CONSTANTS.FactionWorkSecurity; this.currentWorkFactionDescription = "performing security detail"; - this.startFactionWork(router, faction); + this.startFactionWork(faction); } export function workForFaction(this: IPlayer, numCycles: number): boolean { diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index b25183298..d81149677 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -1985,6 +1985,24 @@ export interface Singularity { * @returns True if the installation was successful. */ installBackdoor(): Promise; + + /** + * SF4.2 - Check if the player is focused. + * @remarks + * RAM cost: 0.1 GB + * + * + * @returns True if the player is focused. + */ + isFocused(): void; + + /** + * SF4.2 - Set the players focus. + * @remarks + * RAM cost: 0.1 GB + * + */ + setFocus(focus: boolean): void; } /**