mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 01:23:49 +01:00
Merge pull request #1874 from theit8514/script-focus
Reimplement setFocus
This commit is contained in:
commit
f9499d3259
@ -82,16 +82,24 @@ function MainPage({ faction, rerender, onAugmentations }: IMainProps): React.Rea
|
||||
setGangOpen(true);
|
||||
}
|
||||
|
||||
function startWork(): void {
|
||||
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
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -622,6 +622,31 @@ export function NetscriptSingularity(
|
||||
return Promise.resolve();
|
||||
});
|
||||
},
|
||||
isFocused: function(): boolean {
|
||||
helper.updateDynamicRam("isFocused", getRamCost("isFocused"));
|
||||
helper.checkSingularityAccess("isFocused", 2);
|
||||
return player.focus;
|
||||
},
|
||||
setFocus: function(focus: boolean): boolean {
|
||||
helper.updateDynamicRam("setFocus", getRamCost("setFocus"));
|
||||
helper.checkSingularityAccess("setFocus", 2);
|
||||
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) {
|
||||
player.startFocusing();
|
||||
Router.toWork();
|
||||
return true;
|
||||
} else if (player.focus && !focus) {
|
||||
player.stopFocusing();
|
||||
Router.toTerminal();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
getStats: function (): any {
|
||||
helper.updateDynamicRam("getStats", getRamCost("getStats"));
|
||||
helper.checkSingularityAccess("getStats", 1);
|
||||
@ -703,7 +728,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;
|
||||
@ -814,16 +841,23 @@ export function NetscriptSingularity(
|
||||
return false;
|
||||
}
|
||||
|
||||
const wasWorking = player.isWorking;
|
||||
const wasFocused = player.focus;
|
||||
if (player.isWorking) {
|
||||
const txt = player.singularityStopWork();
|
||||
workerScript.log("workForCompany", () => txt);
|
||||
}
|
||||
|
||||
if (companyPosition.isPartTimeJob()) {
|
||||
player.startWorkPartTime(Router, companyName);
|
||||
player.startWorkPartTime(companyName);
|
||||
} else {
|
||||
player.startWork(Router, companyName);
|
||||
player.startWork(companyName);
|
||||
}
|
||||
|
||||
if (!wasWorking || (wasWorking && !wasFocused))
|
||||
player.stopFocusing();
|
||||
else if (wasWorking && wasFocused)
|
||||
player.startFocusing();
|
||||
workerScript.log(
|
||||
"workForCompany",
|
||||
() => `Began working at '${player.companyName}' as a '${companyPositionName}'`,
|
||||
@ -963,6 +997,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);
|
||||
@ -1060,7 +1096,11 @@ 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);
|
||||
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":
|
||||
@ -1070,7 +1110,11 @@ 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);
|
||||
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":
|
||||
@ -1080,7 +1124,11 @@ 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);
|
||||
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:
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
19
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
19
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -1985,6 +1985,25 @@ export interface Singularity {
|
||||
* @returns True if the installation was successful.
|
||||
*/
|
||||
installBackdoor(): Promise<void>;
|
||||
|
||||
/**
|
||||
* SF4.2 - Check if the player is focused.
|
||||
* @remarks
|
||||
* RAM cost: 0.1 GB
|
||||
*
|
||||
*
|
||||
* @returns True if the player is focused.
|
||||
*/
|
||||
isFocused(): boolean;
|
||||
|
||||
/**
|
||||
* SF4.2 - Set the players focus.
|
||||
* @remarks
|
||||
* RAM cost: 0.1 GB
|
||||
*
|
||||
* @returns True if the focus was changed.
|
||||
*/
|
||||
setFocus(focus: boolean): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user