diff --git a/src/NetscriptFunctions/Corporation.ts b/src/NetscriptFunctions/Corporation.ts index 67bb16e76..5e2cee8ce 100644 --- a/src/NetscriptFunctions/Corporation.ts +++ b/src/NetscriptFunctions/Corporation.ts @@ -59,6 +59,21 @@ export function NetscriptCorporation( workerScript: WorkerScript, helper: INetscriptHelper, ): NSCorporation { + function createCorporation(corporationName: string, selfFund = true): boolean { + if (!player.canAccessCorporation() || player.hasCorporation()) return false; + if (!corporationName) return false; + + if (selfFund) { + if (!player.canAfford(150e9)) return false; + + player.startCorporation(corporationName); + player.loseMoney(150e9, "corporation"); + } else { + player.startCorporation(corporationName, 500e6); + } + return true; + } + function getCorporation(): ICorporation { const corporation = player.corporation; if (corporation === null) throw new Error("cannot be called without a corporation"); @@ -482,6 +497,10 @@ export function NetscriptCorporation( cities: cities, }; }, + createCorporation: function (corporationName: string, selfFund = true): boolean { + checkAccess("createCorporation"); + return createCorporation(corporationName, selfFund); + }, getCorporation: function (): CorporationInfo { checkAccess("getCorporation"); const corporation = getCorporation(); diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 8fc99aaaf..8603d6c99 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -6314,6 +6314,12 @@ export interface WarehouseAPI { * @public */ export interface Corporation extends WarehouseAPI, OfficeAPI { + /** + * Create a Corporation + * @param divisionName - Name of the division + * @returns true if created and false if not + */ + createCorporation(corporationName: string, selfFund: boolean): boolean; /** * Get corporation data * @returns Corporation data