mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-24 02:03:01 +02:00
CORPORATION: Add new API to check if player can create corporation (#1598)
* CORPORATION: Add new API to check if player can create corporation * Update description of createCorporation API * Return enum instead of true/false * Use throwIfReachable * Fix typo in comment
This commit is contained in:
@@ -56,7 +56,7 @@ import {
|
||||
} from "../Corporation/Actions";
|
||||
import { CorpUnlocks } from "../Corporation/data/CorporationUnlocks";
|
||||
import { CorpUpgrades } from "../Corporation/data/CorporationUpgrades";
|
||||
import { CorpUnlockName, CorpUpgradeName, CorpEmployeeJob, CityName } from "@enums";
|
||||
import { CorpUnlockName, CorpUpgradeName, CorpEmployeeJob, CityName, CreatingCorporationCheckResult } from "@enums";
|
||||
import { IndustriesData, IndustryResearchTrees } from "../Corporation/data/IndustryData";
|
||||
import * as corpConstants from "../Corporation/data/Constants";
|
||||
import { ResearchMap } from "../Corporation/ResearchMap";
|
||||
@@ -64,7 +64,12 @@ import { InternalAPI, NetscriptContext, setRemovedFunctions } from "../Netscript
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { getEnumHelper } from "../utils/EnumHelper";
|
||||
import { MaterialInfo } from "../Corporation/MaterialInfo";
|
||||
import { calculateOfficeSizeUpgradeCost, calculateUpgradeCost } from "../Corporation/helpers";
|
||||
import {
|
||||
calculateOfficeSizeUpgradeCost,
|
||||
calculateUpgradeCost,
|
||||
canCreateCorporation,
|
||||
convertCreatingCorporationCheckResultToMessage,
|
||||
} from "../Corporation/helpers";
|
||||
import { PositiveInteger } from "../types";
|
||||
import { getRecordKeys } from "../Types/Record";
|
||||
|
||||
@@ -588,6 +593,21 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
...warehouseAPI,
|
||||
...officeAPI,
|
||||
hasCorporation: () => () => !!Player.corporation,
|
||||
canCreateCorporation: (ctx) => (_selfFund) => {
|
||||
const selfFund = !!_selfFund;
|
||||
const checkResult = canCreateCorporation(selfFund, false);
|
||||
if (checkResult !== CreatingCorporationCheckResult.Success) {
|
||||
helpers.log(ctx, () => convertCreatingCorporationCheckResultToMessage(checkResult));
|
||||
}
|
||||
return checkResult;
|
||||
},
|
||||
createCorporation:
|
||||
(ctx) =>
|
||||
(_corporationName, _selfFund = true): boolean => {
|
||||
const corporationName = helpers.string(ctx, "corporationName", _corporationName);
|
||||
const selfFund = !!_selfFund;
|
||||
return createCorporation(corporationName, selfFund, false);
|
||||
},
|
||||
getConstants: () => () => {
|
||||
/* TODO 2.2: possibly just rework the whole corp constants structure to be more readable, and just use
|
||||
* structuredClone to provide it directly to player.
|
||||
@@ -696,13 +716,6 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
});
|
||||
return data;
|
||||
},
|
||||
createCorporation:
|
||||
(ctx) =>
|
||||
(_corporationName, _selfFund = true): boolean => {
|
||||
const corporationName = helpers.string(ctx, "corporationName", _corporationName);
|
||||
const selfFund = !!_selfFund;
|
||||
return createCorporation(corporationName, selfFund, false);
|
||||
},
|
||||
hasUnlock: (ctx) => (_unlockName) => {
|
||||
checkAccess(ctx);
|
||||
const unlockName = getEnumHelper("CorpUnlockName").nsGetMember(ctx, _unlockName, "unlockName");
|
||||
|
||||
Reference in New Issue
Block a user