From ad57f3dc732250698f6991c1d887fa934590f9c3 Mon Sep 17 00:00:00 2001 From: theit8514 Date: Thu, 9 Dec 2021 22:17:22 -0500 Subject: [PATCH 1/7] Work functions do not take focus setFocus readded and updated to send the user to the Work page if focusing. --- src/Faction/ui/FactionRoot.tsx | 14 +++++++-- src/Locations/ui/CompanyLocation.tsx | 5 ++-- src/NetscriptFunctions/Singularity.ts | 29 +++++++++++++++---- src/PersonObjects/IPlayer.ts | 12 ++++---- src/PersonObjects/Player/PlayerObject.ts | 12 ++++---- .../Player/PlayerObjectGeneralMethods.tsx | 24 ++++++--------- src/ScriptEditor/NetscriptDefinitions.d.ts | 18 ++++++++++++ 7 files changed, 77 insertions(+), 37 deletions(-) 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; } /** From 07d449afc227eb756ecfc01367fa674e6281cc6d Mon Sep 17 00:00:00 2001 From: theit8514 Date: Mon, 13 Dec 2021 16:34:26 -0500 Subject: [PATCH 2/7] Ensure focus does not change between calls to work --- src/NetscriptFunctions/Singularity.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index 9142deb1b..cd4574724 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -829,6 +829,8 @@ export function NetscriptSingularity( return false; } + const wasWorking = player.isWorking; + const wasFocused = player.focus; if (player.isWorking) { const txt = player.singularityStopWork(); workerScript.log("workForCompany", () => txt); @@ -839,7 +841,11 @@ export function NetscriptSingularity( } else { player.startWork(companyName); } - player.stopFocusing(); + + if (!wasWorking || (wasWorking && !wasFocused)) + player.stopFocusing(); + else if (wasWorking && wasFocused) + player.startFocusing(); workerScript.log( "workForCompany", () => `Began working at '${player.companyName}' as a '${companyPositionName}'`, @@ -979,6 +985,8 @@ export function NetscriptSingularity( return false; } + const wasWorking = player.isWorking; + const wasFocused = player.focus; if (player.isWorking) { const txt = player.singularityStopWork(); workerScript.log("workForFaction", () => txt); @@ -1077,7 +1085,10 @@ export function NetscriptSingularity( return false; } player.startFactionHackWork(fac); - player.stopFocusing(); + if (!wasWorking || (wasWorking && !wasFocused)) + player.stopFocusing(); + else if (wasWorking && wasFocused) + player.startFocusing(); workerScript.log("workForFaction", () => `Started carrying out hacking contracts for '${fac.name}'`); return true; case "field": @@ -1088,7 +1099,10 @@ export function NetscriptSingularity( return false; } player.startFactionFieldWork(fac); - player.stopFocusing(); + if (!wasWorking || (wasWorking && !wasFocused)) + player.stopFocusing(); + else if (wasWorking && wasFocused) + player.startFocusing(); workerScript.log("workForFaction", () => `Started carrying out field missions for '${fac.name}'`); return true; case "security": @@ -1099,7 +1113,10 @@ export function NetscriptSingularity( return false; } player.startFactionSecurityWork(fac); - player.stopFocusing(); + if (!wasWorking || (wasWorking && !wasFocused)) + player.stopFocusing(); + else if (wasWorking && wasFocused) + player.startFocusing(); workerScript.log("workForFaction", () => `Started carrying out security work for '${fac.name}'`); return true; default: From 2726420709b492c491b8cb34bfeb0880247fc968 Mon Sep 17 00:00:00 2001 From: theit8514 Date: Mon, 13 Dec 2021 16:45:49 -0500 Subject: [PATCH 3/7] Add errors and only change page when focus changes --- src/NetscriptFunctions/Singularity.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index cd4574724..103d27a54 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -630,11 +630,18 @@ export function NetscriptSingularity( setFocus: function(focus: boolean): any { helper.updateDynamicRam("setFocus", getRamCost("setFocus")); helper.checkSingularityAccess("setFocus", 1); - if (focus === true) { + if (!player.isWorking) { + throw helper.makeRuntimeErrorMsg("setFocus", "Not currently working"); + } + if (!(player.workType == CONSTANTS.WorkTypeFaction || player.workType == CONSTANTS.WorkTypeCompany || player.workType == CONSTANTS.WorkTypeCompanyPartTime)) { + throw helper.makeRuntimeErrorMsg("setFocus", "Cannot change focus for current job"); + } + if (!player.focus && focus === true) { player.startFocusing(); Router.toWork(); - } else if (focus === false) { + } else if (player.focus && focus === false) { player.stopFocusing(); + Router.toTerminal(); } }, getStats: function (): any { From c50c92f9b572c97d9a52d5a00ce2b58821daba42 Mon Sep 17 00:00:00 2001 From: theit8514 Date: Mon, 13 Dec 2021 16:50:58 -0500 Subject: [PATCH 4/7] Update SF requirement to match documentation --- src/NetscriptFunctions/Singularity.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index 103d27a54..7d6758dd5 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -624,12 +624,12 @@ export function NetscriptSingularity( }, isFocused: function(): boolean { helper.updateDynamicRam("isFocused", getRamCost("isFocused")); - helper.checkSingularityAccess("isFocused", 1); + helper.checkSingularityAccess("isFocused", 2); return player.focus; }, setFocus: function(focus: boolean): any { helper.updateDynamicRam("setFocus", getRamCost("setFocus")); - helper.checkSingularityAccess("setFocus", 1); + helper.checkSingularityAccess("setFocus", 2); if (!player.isWorking) { throw helper.makeRuntimeErrorMsg("setFocus", "Not currently working"); } From cd4c98d942f8125571fe786cbb0feaef4e74bb00 Mon Sep 17 00:00:00 2001 From: theit8514 Date: Wed, 15 Dec 2021 20:44:08 -0500 Subject: [PATCH 5/7] Only change to terminal when focused --- src/NetscriptFunctions/Singularity.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index 7d6758dd5..6dfb17205 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -725,7 +725,9 @@ export function NetscriptSingularity( helper.updateDynamicRam("stopAction", getRamCost("stopAction")); helper.checkSingularityAccess("stopAction", 1); if (player.isWorking) { - Router.toTerminal(); + if (player.focus) { + Router.toTerminal(); + } const txt = player.singularityStopWork(); workerScript.log("stopAction", () => txt); return true; From d59601f8485226b172d43b2e4218d9899eaf305f Mon Sep 17 00:00:00 2001 From: theit8514 Date: Wed, 15 Dec 2021 20:48:19 -0500 Subject: [PATCH 6/7] Add return value and code style cleanup --- src/Faction/ui/FactionRoot.tsx | 2 +- src/NetscriptFunctions/Singularity.ts | 9 ++++++--- src/ScriptEditor/NetscriptDefinitions.d.ts | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Faction/ui/FactionRoot.tsx b/src/Faction/ui/FactionRoot.tsx index 256efe865..dd43d2f94 100644 --- a/src/Faction/ui/FactionRoot.tsx +++ b/src/Faction/ui/FactionRoot.tsx @@ -82,7 +82,7 @@ function MainPage({ faction, rerender, onAugmentations }: IMainProps): React.Rea setGangOpen(true); } - function startWork() { + function startWork(): void { player.startFocusing(); router.toWork(); } diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index 6dfb17205..5ebc5c965 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -627,7 +627,7 @@ export function NetscriptSingularity( helper.checkSingularityAccess("isFocused", 2); return player.focus; }, - setFocus: function(focus: boolean): any { + setFocus: function(focus: boolean): boolean { helper.updateDynamicRam("setFocus", getRamCost("setFocus")); helper.checkSingularityAccess("setFocus", 2); if (!player.isWorking) { @@ -636,13 +636,16 @@ export function NetscriptSingularity( if (!(player.workType == CONSTANTS.WorkTypeFaction || player.workType == CONSTANTS.WorkTypeCompany || player.workType == CONSTANTS.WorkTypeCompanyPartTime)) { throw helper.makeRuntimeErrorMsg("setFocus", "Cannot change focus for current job"); } - if (!player.focus && focus === true) { + if (!player.focus && focus) { player.startFocusing(); Router.toWork(); - } else if (player.focus && focus === false) { + return true; + } else if (player.focus && !focus) { player.stopFocusing(); Router.toTerminal(); + return true; } + return false; }, getStats: function (): any { helper.updateDynamicRam("getStats", getRamCost("getStats")); diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index d81149677..bd0dbd032 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -2001,8 +2001,9 @@ export interface Singularity { * @remarks * RAM cost: 0.1 GB * + * @returns True if the focus was changed. */ - setFocus(focus: boolean): void; + setFocus(focus: boolean): boolean; } /** From 2e133bcf0af77fb97ef8a42a62e44168fadbcbe7 Mon Sep 17 00:00:00 2001 From: theit8514 Date: Wed, 15 Dec 2021 20:55:47 -0500 Subject: [PATCH 7/7] Fix return type of isFocused --- src/ScriptEditor/NetscriptDefinitions.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index bd0dbd032..1ec40d9e3 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -1994,7 +1994,7 @@ export interface Singularity { * * @returns True if the player is focused. */ - isFocused(): void; + isFocused(): boolean; /** * SF4.2 - Set the players focus.