Add createCorp

This commit is contained in:
pigalot 2022-01-11 19:43:29 +00:00
parent bea6b0e0b1
commit e2bb76ae6d
2 changed files with 25 additions and 0 deletions

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

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