SINGULARITY: Added getCompanyPositions (#459)

Also workForCompany will throw an error if provided a bad company name, instead of returning false
This commit is contained in:
T.J. Eckman 2023-04-01 21:30:46 -04:00 committed by GitHub
parent 8b83791515
commit df334ea6de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 6 deletions

@ -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),

@ -674,6 +674,19 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
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<ISingularity> {
// 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;

@ -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