Add focus arg to Singularity functions

This commit is contained in:
nickofolas 2022-01-12 12:03:49 -06:00
parent 3e7a9ac896
commit 415f922a37
3 changed files with 39 additions and 9 deletions

9
dist/bitburner.d.ts vendored

@ -4520,9 +4520,10 @@ export declare interface Singularity {
* *
* @param universityName - Name of university. You must be in the correct city for whatever university you specify. * @param universityName - Name of university. You must be in the correct city for whatever university you specify.
* @param courseName - Name of course. * @param courseName - Name of course.
* @param focus - Acquire player focus on this class. Optional. Defaults to true.
* @returns True if actions is successfully started, false otherwise. * @returns True if actions is successfully started, false otherwise.
*/ */
universityCourse(universityName: string, courseName: string): boolean; universityCourse(universityName: string, courseName: string, focus?: boolean): boolean;
/** /**
* SF4.1 - Workout at the gym. * SF4.1 - Workout at the gym.
@ -4541,9 +4542,10 @@ export declare interface Singularity {
* *
* @param gymName - Name of gym. You must be in the correct city for whatever gym you specify. * @param gymName - Name of gym. You must be in the correct city for whatever gym you specify.
* @param stat - The stat you want to train. * @param stat - The stat you want to train.
* @param focus - Acquire player focus on this gym workout. Optional. Defaults to true.
* @returns True if actions is successfully started, false otherwise. * @returns True if actions is successfully started, false otherwise.
*/ */
gymWorkout(gymName: string, stat: string): boolean; gymWorkout(gymName: string, stat: string, focus?: boolean): boolean;
/** /**
* SF4.1 - Travel to another city. * SF4.1 - Travel to another city.
@ -4954,9 +4956,10 @@ export declare interface Singularity {
* ns.createProgram(relaysmtp.exe); * ns.createProgram(relaysmtp.exe);
* ``` * ```
* @param program - Name of program to create. * @param program - Name of program to create.
* @param focus - Acquire player focus on this program creation. Optional. Defaults to true.
* @returns True if you successfully start working on the specified program, and false otherwise. * @returns True if you successfully start working on the specified program, and false otherwise.
*/ */
createProgram(program: string): boolean; createProgram(program: string, focus?: boolean): boolean;
/** /**
* SF4.3 - Commit a crime. * SF4.3 - Commit a crime.

@ -267,9 +267,10 @@ export function NetscriptSingularity(
player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 500); player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 500);
return true; return true;
}, },
universityCourse: function (universityName: any, className: any): any { universityCourse: function (universityName: any, className: any, focus = true): any {
helper.updateDynamicRam("universityCourse", getRamCost(player, "universityCourse")); helper.updateDynamicRam("universityCourse", getRamCost(player, "universityCourse"));
helper.checkSingularityAccess("universityCourse"); helper.checkSingularityAccess("universityCourse");
const wasFocusing = player.focus;
if (player.isWorking) { if (player.isWorking) {
const txt = player.singularityStopWork(); const txt = player.singularityStopWork();
workerScript.log("universityCourse", () => txt); workerScript.log("universityCourse", () => txt);
@ -343,13 +344,21 @@ export function NetscriptSingularity(
return false; return false;
} }
player.startClass(Router, costMult, expMult, task); player.startClass(Router, costMult, expMult, task);
if (focus) {
player.startFocusing();
Router.toWork();
} else if (wasFocusing) {
player.stopFocusing();
Router.toTerminal();
}
workerScript.log("universityCourse", () => `Started ${task} at ${universityName}`); workerScript.log("universityCourse", () => `Started ${task} at ${universityName}`);
return true; return true;
}, },
gymWorkout: function (gymName: any, stat: any): any { gymWorkout: function (gymName: any, stat: any, focus = true): any {
helper.updateDynamicRam("gymWorkout", getRamCost(player, "gymWorkout")); helper.updateDynamicRam("gymWorkout", getRamCost(player, "gymWorkout"));
helper.checkSingularityAccess("gymWorkout"); helper.checkSingularityAccess("gymWorkout");
const wasFocusing = player.focus;
if (player.isWorking) { if (player.isWorking) {
const txt = player.singularityStopWork(); const txt = player.singularityStopWork();
workerScript.log("gymWorkout", () => txt); workerScript.log("gymWorkout", () => txt);
@ -442,6 +451,13 @@ export function NetscriptSingularity(
workerScript.log("gymWorkout", () => `Invalid stat: ${stat}.`); workerScript.log("gymWorkout", () => `Invalid stat: ${stat}.`);
return false; return false;
} }
if (focus) {
player.startFocusing();
Router.toWork();
} else if (wasFocusing) {
player.stopFocusing();
Router.toTerminal();
}
workerScript.log("gymWorkout", () => `Started training ${stat} at ${gymName}`); workerScript.log("gymWorkout", () => `Started training ${stat} at ${gymName}`);
return true; return true;
}, },
@ -1217,10 +1233,11 @@ export function NetscriptSingularity(
); );
return true; return true;
}, },
createProgram: function (name: any): any { createProgram: function (name: any, focus = true): any {
helper.updateDynamicRam("createProgram", getRamCost(player, "createProgram")); helper.updateDynamicRam("createProgram", getRamCost(player, "createProgram"));
helper.checkSingularityAccess("createProgram"); helper.checkSingularityAccess("createProgram");
const wasFocusing = player.focus;
if (player.isWorking) { if (player.isWorking) {
const txt = player.singularityStopWork(); const txt = player.singularityStopWork();
workerScript.log("createProgram", () => txt); workerScript.log("createProgram", () => txt);
@ -1255,6 +1272,13 @@ export function NetscriptSingularity(
} }
player.startCreateProgramWork(Router, p.name, create.time, create.level); player.startCreateProgramWork(Router, p.name, create.time, create.level);
if (focus) {
player.startFocusing();
Router.toWork();
} else if (wasFocusing) {
player.stopFocusing();
Router.toTerminal();
}
workerScript.log("createProgram", () => `Began creating program: '${name}'`); workerScript.log("createProgram", () => `Began creating program: '${name}'`);
return true; return true;
}, },

@ -1341,9 +1341,10 @@ export interface Singularity {
* *
* @param universityName - Name of university. You must be in the correct city for whatever university you specify. * @param universityName - Name of university. You must be in the correct city for whatever university you specify.
* @param courseName - Name of course. * @param courseName - Name of course.
* @param focus - Acquire player focus on this class. Optional. Defaults to true.
* @returns True if actions is successfully started, false otherwise. * @returns True if actions is successfully started, false otherwise.
*/ */
universityCourse(universityName: string, courseName: string): boolean; universityCourse(universityName: string, courseName: string, focus?: boolean): boolean;
/** /**
* Workout at the gym. * Workout at the gym.
@ -1362,9 +1363,10 @@ export interface Singularity {
* *
* @param gymName - Name of gym. You must be in the correct city for whatever gym you specify. * @param gymName - Name of gym. You must be in the correct city for whatever gym you specify.
* @param stat - The stat you want to train. * @param stat - The stat you want to train.
* @param focus - Acquire player focus on this gym workout. Optional. Defaults to true.
* @returns True if actions is successfully started, false otherwise. * @returns True if actions is successfully started, false otherwise.
*/ */
gymWorkout(gymName: string, stat: string): boolean; gymWorkout(gymName: string, stat: string, focus?: boolean): boolean;
/** /**
* Travel to another city. * Travel to another city.
@ -1775,9 +1777,10 @@ export interface Singularity {
* ns.createProgram(relaysmtp.exe); * ns.createProgram(relaysmtp.exe);
* ``` * ```
* @param program - Name of program to create. * @param program - Name of program to create.
* @param focus - Acquire player focus on this program creation. Optional. Defaults to true.
* @returns True if you successfully start working on the specified program, and false otherwise. * @returns True if you successfully start working on the specified program, and false otherwise.
*/ */
createProgram(program: string): boolean; createProgram(program: string, focus?: boolean): boolean;
/** /**
* Commit a crime. * Commit a crime.