mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 14:28:36 +02:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user