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
3 changed files with 46 additions and 6 deletions

View File

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