Merge pull request #2092 from theit8514/script-focus-v2

Add focus parameter to workForCompany/workForFaction
This commit is contained in:
hydroflame 2021-12-21 11:02:26 -05:00 committed by GitHub
commit 79eb2f7e0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 15 deletions

@ -819,7 +819,7 @@ export function NetscriptSingularity(
return player.getUpgradeHomeRamCost();
},
workForCompany: function (companyName: any): any {
workForCompany: function (companyName: any, focus: boolean = true): any {
helper.updateDynamicRam("workForCompany", getRamCost("workForCompany"));
helper.checkSingularityAccess("workForCompany", 2);
@ -848,7 +848,6 @@ export function NetscriptSingularity(
return false;
}
const wasWorking = player.isWorking;
const wasFocused = player.focus;
if (player.isWorking) {
const txt = player.singularityStopWork();
@ -861,8 +860,14 @@ export function NetscriptSingularity(
player.startWork(companyName);
}
if (!wasWorking || (wasWorking && !wasFocused)) player.stopFocusing();
else if (wasWorking && wasFocused) player.startFocusing();
if (focus) {
player.startFocusing();
Router.toWork();
}
else if (wasFocused) {
player.stopFocusing();
Router.toTerminal();
}
workerScript.log(
"workForCompany",
() => `Began working at '${player.companyName}' as a '${companyPositionName}'`,
@ -986,7 +991,7 @@ export function NetscriptSingularity(
workerScript.log("joinFaction", () => `Joined the '${name}' faction.`);
return true;
},
workForFaction: function (name: any, type: any): any {
workForFaction: function (name: any, type: any, focus: boolean = true): any {
helper.updateDynamicRam("workForFaction", getRamCost("workForFaction"));
helper.checkSingularityAccess("workForFaction", 2);
getFaction("workForFaction", name);
@ -1002,8 +1007,7 @@ export function NetscriptSingularity(
return false;
}
const wasWorking = player.isWorking;
const wasFocused = player.focus;
const wasFocusing = player.focus;
if (player.isWorking) {
const txt = player.singularityStopWork();
workerScript.log("workForFaction", () => txt);
@ -1102,8 +1106,14 @@ export function NetscriptSingularity(
return false;
}
player.startFactionHackWork(fac);
if (!wasWorking || (wasWorking && !wasFocused)) player.stopFocusing();
else if (wasWorking && wasFocused) player.startFocusing();
if (focus)
{
player.startFocusing();
Router.toWork();
} else if (wasFocusing) {
player.stopFocusing();
Router.toTerminal();
}
workerScript.log("workForFaction", () => `Started carrying out hacking contracts for '${fac.name}'`);
return true;
case "field":
@ -1114,8 +1124,14 @@ export function NetscriptSingularity(
return false;
}
player.startFactionFieldWork(fac);
if (!wasWorking || (wasWorking && !wasFocused)) player.stopFocusing();
else if (wasWorking && wasFocused) player.startFocusing();
if (focus)
{
player.startFocusing();
Router.toWork();
} else if (wasFocusing) {
player.stopFocusing();
Router.toTerminal();
}
workerScript.log("workForFaction", () => `Started carrying out field missions for '${fac.name}'`);
return true;
case "security":
@ -1126,8 +1142,14 @@ export function NetscriptSingularity(
return false;
}
player.startFactionSecurityWork(fac);
if (!wasWorking || (wasWorking && !wasFocused)) player.stopFocusing();
else if (wasWorking && wasFocused) player.startFocusing();
if (focus)
{
player.startFocusing();
Router.toWork();
} else if (wasFocusing) {
player.stopFocusing();
Router.toTerminal();
}
workerScript.log("workForFaction", () => `Started carrying out security work for '${fac.name}'`);
return true;
default:

@ -1493,9 +1493,10 @@ export interface Singularity {
* //This way, your company reputation will be updated every minute.
* ```
* @param companyName - Name of company to work for. Must be an exact match. Optional. If not specified, this argument defaults to the last job that you worked
* @param focus - Acquire player focus on this work operation. Optional. Defaults to true.
* @returns True if the player starts working, and false otherwise.
*/
workForCompany(companyName?: string): boolean;
workForCompany(companyName?: string, focus?: boolean): boolean;
/**
* SF4.2 - Apply for a job at a company.
@ -1612,9 +1613,10 @@ export interface Singularity {
* ```
* @param faction - Name of faction to work for.
* @param workType - Type of work to perform for the faction.
* @param focus - Acquire player focus on this work operation. Optional. Defaults to true.
* @returns True if the player starts working, and false otherwise.
*/
workForFaction(faction: string, workType: string): boolean;
workForFaction(faction: string, workType: string, focus?: boolean): boolean;
/**
* SF4.2 - Get faction reputation.