diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index 1c6a30285..8fa56851f 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -155,6 +155,7 @@ const singularity = { purchaseTor: SF4Cost(RamCostConstants.SingularityFn1), purchaseProgram: SF4Cost(RamCostConstants.SingularityFn1), getCurrentServer: SF4Cost(RamCostConstants.SingularityFn1), + getCompanyPositions: SF4Cost(RamCostConstants.SingularityFn1), connect: SF4Cost(RamCostConstants.SingularityFn1), manualHack: SF4Cost(RamCostConstants.SingularityFn1), installBackdoor: SF4Cost(RamCostConstants.SingularityFn1), diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index b8792d79d..1e5fc8616 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -674,6 +674,19 @@ export function NetscriptSingularity(): InternalAPI { return Player.getUpgradeHomeRamCost(); }, + getCompanyPositions: (ctx) => (_companyName) => { + helpers.checkSingularityAccess(ctx); + const companyName = helpers.string(ctx, "companyName", _companyName); + + // Make sure its a valid company + if (companyName == null || companyName === "" || !Companies[companyName]) { + throw helpers.makeRuntimeErrorMsg(ctx, `Invalid company: '${companyName}'`); + } + + return Object.entries(CompanyPositions) + .filter((_position) => Companies[companyName].hasPosition(_position[0])) + .map((_position) => _position[1]["name"]); + }, workForCompany: (ctx) => (_companyName, _focus = true) => { @@ -683,22 +696,19 @@ export function NetscriptSingularity(): InternalAPI { // Make sure its a valid company if (companyName == null || companyName === "" || !Companies[companyName]) { - helpers.log(ctx, () => `Invalid company: '${companyName}'`); - return false; + throw helpers.makeRuntimeErrorMsg(ctx, `Invalid company: '${companyName}'`); } // Make sure player is actually employed at the company if (!Object.keys(Player.jobs).includes(companyName)) { - helpers.log(ctx, () => `You do not have a job at '${companyName}'`); - return false; + throw helpers.makeRuntimeErrorMsg(ctx, `You do not have a job at: '${companyName}'`); } // Check to make sure company position data is valid const companyPositionName = Player.jobs[companyName]; const companyPosition = CompanyPositions[companyPositionName]; if (companyPositionName === "" || !companyPosition) { - helpers.log(ctx, () => "You do not have a job"); - return false; + throw helpers.makeRuntimeErrorMsg(ctx, `You do not have a job`); } const wasFocused = Player.focus; diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 39b0b8d35..7c6495d6b 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -1698,6 +1698,35 @@ export interface Singularity { */ getUpgradeHomeCoresCost(): number; + /** + * Get List of Company Positions. + * @remarks + * RAM cost: 2 GB * 16/4/1 + * + * + * This function will return a list of positions at a specific company. + * + * This function will return the position list if the company name is valid. + * + * @example + * ```js + * // NS1: + * var COMPANY_NAME = "Noodle Bar"; + * + * var jobList = singularity.getCompanyPositions(COMPANY_NAME); + * ``` + * @example + * ```js + * // NS2: + * const COMPANY_NAME = "Noodle Bar"; + * + * let jobList = ns.singularity.getCompanyPositions(COMPANY_NAME); + * ``` + * @param companyName - Name of company to get the position list for. Must be an exact match. + * @returns The position list if the company name is valid. + */ + getCompanyPositions(companyName: string): CompanyPosName[]; + /** * Work for a company. * @remarks