2022-11-09 13:26:26 +01:00
|
|
|
import { Player, Player as player } from "../Player";
|
2021-10-14 09:22:02 +02:00
|
|
|
|
|
|
|
import { OfficeSpace } from "../Corporation/OfficeSpace";
|
|
|
|
import { Product } from "../Corporation/Product";
|
|
|
|
import { Material } from "../Corporation/Material";
|
|
|
|
import { Warehouse } from "../Corporation/Warehouse";
|
2022-09-20 12:47:54 +02:00
|
|
|
import { Industry } from "../Corporation/Industry";
|
|
|
|
import { Corporation } from "../Corporation/Corporation";
|
2021-12-04 05:06:04 +01:00
|
|
|
|
|
|
|
import {
|
|
|
|
Corporation as NSCorporation,
|
|
|
|
Division as NSDivision,
|
|
|
|
WarehouseAPI,
|
|
|
|
OfficeAPI,
|
2022-03-30 02:24:04 +02:00
|
|
|
InvestmentOffer,
|
2021-12-04 05:06:04 +01:00
|
|
|
} from "../ScriptEditor/NetscriptDefinitions";
|
2021-10-14 09:22:02 +02:00
|
|
|
|
|
|
|
import {
|
|
|
|
NewIndustry,
|
|
|
|
NewCity,
|
|
|
|
UnlockUpgrade,
|
|
|
|
LevelUpgrade,
|
|
|
|
IssueDividends,
|
|
|
|
SellMaterial,
|
|
|
|
SellProduct,
|
|
|
|
SetSmartSupply,
|
|
|
|
BuyMaterial,
|
2022-06-01 19:11:33 +02:00
|
|
|
AutoAssignJob,
|
2021-10-14 09:22:02 +02:00
|
|
|
UpgradeOfficeSize,
|
|
|
|
PurchaseWarehouse,
|
|
|
|
UpgradeWarehouse,
|
|
|
|
BuyCoffee,
|
2022-06-02 00:26:32 +02:00
|
|
|
ThrowParty,
|
2021-10-14 09:22:02 +02:00
|
|
|
HireAdVert,
|
|
|
|
MakeProduct,
|
|
|
|
Research,
|
|
|
|
ExportMaterial,
|
|
|
|
CancelExportMaterial,
|
|
|
|
SetMaterialMarketTA1,
|
|
|
|
SetMaterialMarketTA2,
|
|
|
|
SetProductMarketTA1,
|
|
|
|
SetProductMarketTA2,
|
2022-01-17 11:03:29 +01:00
|
|
|
BulkPurchase,
|
|
|
|
SellShares,
|
|
|
|
BuyBackShares,
|
2022-01-25 19:51:07 +01:00
|
|
|
SetSmartSupplyUseLeftovers,
|
2022-04-01 16:28:48 +02:00
|
|
|
LimitMaterialProduction,
|
|
|
|
LimitProductProduction,
|
2022-04-01 17:19:08 +02:00
|
|
|
UpgradeWarehouseCost,
|
2021-10-14 09:22:02 +02:00
|
|
|
} from "../Corporation/Actions";
|
|
|
|
import { CorporationUnlockUpgrades } from "../Corporation/data/CorporationUnlockUpgrades";
|
|
|
|
import { CorporationUpgrades } from "../Corporation/data/CorporationUpgrades";
|
2021-12-04 05:06:04 +01:00
|
|
|
import { EmployeePositions } from "../Corporation/EmployeePositions";
|
2022-10-25 03:54:54 +02:00
|
|
|
import { IndustriesData, IndustryResearchTrees, IndustryType } from "../Corporation/IndustryData";
|
2022-01-12 00:47:04 +01:00
|
|
|
import { CorporationConstants } from "../Corporation/data/Constants";
|
2022-01-13 18:47:11 +01:00
|
|
|
import { ResearchMap } from "../Corporation/ResearchMap";
|
2022-01-13 22:05:06 +01:00
|
|
|
import { Factions } from "../Faction/Factions";
|
2022-04-01 15:05:01 +02:00
|
|
|
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
2022-08-08 19:43:41 +02:00
|
|
|
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
2022-10-25 03:54:54 +02:00
|
|
|
import { assertEnumMember, helpers } from "../Netscript/NetscriptHelpers";
|
2022-10-05 20:52:48 +02:00
|
|
|
import { checkEnum } from "../utils/helpers/checkEnum";
|
2022-10-25 03:54:54 +02:00
|
|
|
import { CityName } from "../Locations/data/CityNames";
|
2021-10-14 09:22:02 +02:00
|
|
|
|
2022-08-09 21:41:47 +02:00
|
|
|
export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
2022-01-11 20:43:29 +01:00
|
|
|
function createCorporation(corporationName: string, selfFund = true): boolean {
|
2022-11-09 13:26:26 +01:00
|
|
|
if (!player.canAccessCorporation() || player.corporation) return false;
|
2022-01-11 20:43:29 +01:00
|
|
|
if (!corporationName) return false;
|
2022-01-11 20:53:53 +01:00
|
|
|
if (player.bitNodeN !== 3 && !selfFund) throw new Error("cannot use seed funds outside of BitNode 3");
|
2022-05-09 21:45:19 +02:00
|
|
|
if (BitNodeMultipliers.CorporationSoftcap < 0.15)
|
2022-04-11 15:54:50 +02:00
|
|
|
throw new Error(`You cannot create a corporation in Bitnode ${player.bitNodeN}`);
|
2022-01-11 20:43:29 +01:00
|
|
|
|
|
|
|
if (selfFund) {
|
|
|
|
if (!player.canAfford(150e9)) return false;
|
|
|
|
|
|
|
|
player.startCorporation(corporationName);
|
|
|
|
player.loseMoney(150e9, "corporation");
|
|
|
|
} else {
|
|
|
|
player.startCorporation(corporationName, 500e6);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-12 00:47:04 +01:00
|
|
|
function hasUnlockUpgrade(upgradeName: string): boolean {
|
|
|
|
const corporation = getCorporation();
|
2022-04-14 06:21:33 +02:00
|
|
|
const upgrade = Object.values(CorporationUnlockUpgrades).find((upgrade) => upgrade.name === upgradeName);
|
2022-01-12 00:47:04 +01:00
|
|
|
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
|
2022-04-14 06:21:33 +02:00
|
|
|
const upgN = upgrade.index;
|
2022-01-12 00:47:04 +01:00
|
|
|
return corporation.unlockUpgrades[upgN] === 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUnlockUpgradeCost(upgradeName: string): number {
|
2022-04-14 06:21:33 +02:00
|
|
|
const upgrade = Object.values(CorporationUnlockUpgrades).find((upgrade) => upgrade.name === upgradeName);
|
2022-01-12 00:47:04 +01:00
|
|
|
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
|
2022-04-14 06:21:33 +02:00
|
|
|
return upgrade.price;
|
2022-01-12 00:47:04 +01:00
|
|
|
}
|
|
|
|
|
2022-05-08 01:08:07 +02:00
|
|
|
function getUpgradeLevel(ctx: NetscriptContext, _upgradeName: string): number {
|
2022-08-08 19:43:41 +02:00
|
|
|
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
2022-01-12 00:47:04 +01:00
|
|
|
const corporation = getCorporation();
|
2022-04-14 06:21:33 +02:00
|
|
|
const upgrade = Object.values(CorporationUpgrades).find((upgrade) => upgrade.name === upgradeName);
|
2022-01-12 00:47:04 +01:00
|
|
|
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
|
2022-04-14 06:21:33 +02:00
|
|
|
const upgN = upgrade.index;
|
2022-01-12 00:47:04 +01:00
|
|
|
return corporation.upgrades[upgN];
|
|
|
|
}
|
|
|
|
|
2022-05-08 01:08:07 +02:00
|
|
|
function getUpgradeLevelCost(ctx: NetscriptContext, _upgradeName: string): number {
|
2022-08-08 19:43:41 +02:00
|
|
|
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
2022-01-12 00:47:04 +01:00
|
|
|
const corporation = getCorporation();
|
2022-04-14 06:21:33 +02:00
|
|
|
const upgrade = Object.values(CorporationUpgrades).find((upgrade) => upgrade.name === upgradeName);
|
2022-01-12 00:47:04 +01:00
|
|
|
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
|
2022-04-14 06:21:33 +02:00
|
|
|
const upgN = upgrade.index;
|
|
|
|
const baseCost = upgrade.basePrice;
|
|
|
|
const priceMult = upgrade.priceMult;
|
2022-01-12 00:47:04 +01:00
|
|
|
const level = corporation.upgrades[upgN];
|
|
|
|
return baseCost * Math.pow(priceMult, level);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getExpandCityCost(): number {
|
|
|
|
return CorporationConstants.OfficeInitialCost;
|
|
|
|
}
|
|
|
|
|
2022-01-13 12:42:23 +01:00
|
|
|
function getInvestmentOffer(): InvestmentOffer {
|
|
|
|
const corporation = getCorporation();
|
2022-03-30 02:24:04 +02:00
|
|
|
if (
|
|
|
|
corporation.fundingRound >= CorporationConstants.FundingRoundShares.length ||
|
|
|
|
corporation.fundingRound >= CorporationConstants.FundingRoundMultiplier.length ||
|
|
|
|
corporation.public
|
|
|
|
)
|
2022-01-13 12:42:23 +01:00
|
|
|
return {
|
|
|
|
funds: 0,
|
|
|
|
shares: 0,
|
2022-03-30 02:24:04 +02:00
|
|
|
round: corporation.fundingRound + 1, // Make more readable
|
2022-01-13 12:42:23 +01:00
|
|
|
}; // Don't throw an error here, no reason to have a second function to check if you can get investment.
|
2022-09-23 00:10:45 +02:00
|
|
|
const val = corporation.valuation;
|
2022-01-13 12:42:23 +01:00
|
|
|
const percShares = CorporationConstants.FundingRoundShares[corporation.fundingRound];
|
|
|
|
const roundMultiplier = CorporationConstants.FundingRoundMultiplier[corporation.fundingRound];
|
|
|
|
const funding = val * percShares * roundMultiplier;
|
|
|
|
const investShares = Math.floor(CorporationConstants.INITIALSHARES * percShares);
|
|
|
|
return {
|
|
|
|
funds: funding,
|
|
|
|
shares: investShares,
|
2022-03-30 02:24:04 +02:00
|
|
|
round: corporation.fundingRound + 1, // Make more readable
|
2022-01-13 12:42:23 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function acceptInvestmentOffer(): boolean {
|
|
|
|
const corporation = getCorporation();
|
2022-03-30 02:24:04 +02:00
|
|
|
if (
|
|
|
|
corporation.fundingRound >= CorporationConstants.FundingRoundShares.length ||
|
|
|
|
corporation.fundingRound >= CorporationConstants.FundingRoundMultiplier.length ||
|
|
|
|
corporation.public
|
|
|
|
)
|
|
|
|
return false;
|
2022-09-23 00:10:45 +02:00
|
|
|
const val = corporation.valuation;
|
2022-01-13 12:42:23 +01:00
|
|
|
const percShares = CorporationConstants.FundingRoundShares[corporation.fundingRound];
|
|
|
|
const roundMultiplier = CorporationConstants.FundingRoundMultiplier[corporation.fundingRound];
|
|
|
|
const funding = val * percShares * roundMultiplier;
|
|
|
|
const investShares = Math.floor(CorporationConstants.INITIALSHARES * percShares);
|
|
|
|
corporation.fundingRound++;
|
|
|
|
corporation.addFunds(funding);
|
|
|
|
corporation.numShares -= investShares;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-13 18:47:11 +01:00
|
|
|
function goPublic(numShares: number): boolean {
|
|
|
|
const corporation = getCorporation();
|
2022-09-23 00:10:45 +02:00
|
|
|
const initialSharePrice = corporation.valuation / corporation.totalShares;
|
2022-01-13 18:47:11 +01:00
|
|
|
if (isNaN(numShares)) throw new Error("Invalid value for number of issued shares");
|
|
|
|
if (numShares < 0) throw new Error("Invalid value for number of issued shares");
|
|
|
|
if (numShares > corporation.numShares) throw new Error("You don't have that many shares to issue!");
|
|
|
|
corporation.public = true;
|
|
|
|
corporation.sharePrice = initialSharePrice;
|
|
|
|
corporation.issuedShares = numShares;
|
|
|
|
corporation.numShares -= numShares;
|
|
|
|
corporation.addFunds(numShares * initialSharePrice);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-20 12:47:54 +02:00
|
|
|
function getResearchCost(division: Industry, researchName: string): number {
|
2022-01-13 18:47:11 +01:00
|
|
|
const researchTree = IndustryResearchTrees[division.type];
|
|
|
|
if (researchTree === undefined) throw new Error(`No research tree for industry '${division.type}'`);
|
|
|
|
const allResearch = researchTree.getAllNodes();
|
|
|
|
if (!allResearch.includes(researchName)) throw new Error(`No research named '${researchName}'`);
|
|
|
|
const research = ResearchMap[researchName];
|
|
|
|
return research.cost;
|
|
|
|
}
|
|
|
|
|
2022-09-20 12:47:54 +02:00
|
|
|
function hasResearched(division: Industry, researchName: string): boolean {
|
2022-03-30 02:24:04 +02:00
|
|
|
return division.researched[researchName] === undefined ? false : (division.researched[researchName] as boolean);
|
2022-01-13 18:47:11 +01:00
|
|
|
}
|
|
|
|
|
2022-07-26 14:20:22 +02:00
|
|
|
function bribe(factionName: string, amountCash: number): boolean {
|
2022-01-13 22:05:06 +01:00
|
|
|
if (!player.factions.includes(factionName)) throw new Error("Invalid faction name");
|
2022-07-26 14:20:22 +02:00
|
|
|
if (isNaN(amountCash) || amountCash < 0)
|
2022-10-09 07:32:44 +02:00
|
|
|
throw new Error("Invalid value for amount field! Must be numeric, greater than 0.");
|
2022-03-07 23:43:29 +01:00
|
|
|
|
2022-01-13 22:05:06 +01:00
|
|
|
const corporation = getCorporation();
|
|
|
|
if (corporation.funds < amountCash) return false;
|
2022-03-30 02:24:04 +02:00
|
|
|
const faction = Factions[factionName];
|
2022-01-13 22:05:06 +01:00
|
|
|
const info = faction.getInfo();
|
|
|
|
if (!info.offersWork()) return false;
|
|
|
|
if (player.hasGangWith(factionName)) return false;
|
|
|
|
|
2022-07-26 14:20:22 +02:00
|
|
|
const repGain = amountCash / CorporationConstants.BribeToRepRatio;
|
2022-01-13 22:05:06 +01:00
|
|
|
faction.playerReputation += repGain;
|
|
|
|
corporation.funds = corporation.funds - amountCash;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-20 12:47:54 +02:00
|
|
|
function getCorporation(): Corporation {
|
2021-10-14 09:22:02 +02:00
|
|
|
const corporation = player.corporation;
|
|
|
|
if (corporation === null) throw new Error("cannot be called without a corporation");
|
2021-12-04 05:06:04 +01:00
|
|
|
return corporation;
|
|
|
|
}
|
|
|
|
|
2022-09-20 12:47:54 +02:00
|
|
|
function getDivision(divisionName: string): Industry {
|
2021-12-04 05:06:04 +01:00
|
|
|
const corporation = getCorporation();
|
2021-10-14 09:22:02 +02:00
|
|
|
const division = corporation.divisions.find((div) => div.name === divisionName);
|
|
|
|
if (division === undefined) throw new Error(`No division named '${divisionName}'`);
|
|
|
|
return division;
|
|
|
|
}
|
|
|
|
|
2022-03-30 17:34:03 +02:00
|
|
|
function getOffice(divisionName: string, cityName: string): OfficeSpace {
|
2021-10-14 09:22:02 +02:00
|
|
|
const division = getDivision(divisionName);
|
2022-10-25 16:32:20 +02:00
|
|
|
if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city name '${cityName}'`);
|
2021-10-14 09:22:02 +02:00
|
|
|
const office = division.offices[cityName];
|
|
|
|
if (office === 0) throw new Error(`${division.name} has not expanded to '${cityName}'`);
|
|
|
|
return office;
|
|
|
|
}
|
|
|
|
|
2022-03-30 17:34:03 +02:00
|
|
|
function getWarehouse(divisionName: string, cityName: string): Warehouse {
|
2021-10-14 09:22:02 +02:00
|
|
|
const division = getDivision(divisionName);
|
2022-10-25 03:54:54 +02:00
|
|
|
if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city name '${cityName}'`);
|
2021-10-14 09:22:02 +02:00
|
|
|
const warehouse = division.warehouses[cityName];
|
|
|
|
if (warehouse === 0) throw new Error(`${division.name} has not expanded to '${cityName}'`);
|
|
|
|
return warehouse;
|
|
|
|
}
|
|
|
|
|
2022-03-30 17:34:03 +02:00
|
|
|
function getMaterial(divisionName: string, cityName: string, materialName: string): Material {
|
2021-10-14 09:22:02 +02:00
|
|
|
const warehouse = getWarehouse(divisionName, cityName);
|
2022-07-15 00:43:33 +02:00
|
|
|
const matName = materialName.replace(/ /g, "");
|
2022-01-12 00:47:04 +01:00
|
|
|
const material = warehouse.materials[matName];
|
2021-10-14 09:22:02 +02:00
|
|
|
if (material === undefined) throw new Error(`Invalid material name: '${materialName}'`);
|
|
|
|
return material;
|
|
|
|
}
|
|
|
|
|
2022-03-30 17:34:03 +02:00
|
|
|
function getProduct(divisionName: string, productName: string): Product {
|
2021-10-14 09:22:02 +02:00
|
|
|
const division = getDivision(divisionName);
|
|
|
|
const product = division.products[productName];
|
|
|
|
if (product === undefined) throw new Error(`Invalid product name: '${productName}'`);
|
|
|
|
return product;
|
|
|
|
}
|
|
|
|
|
2022-05-08 01:08:07 +02:00
|
|
|
function checkAccess(ctx: NetscriptContext, api?: number): void {
|
2022-08-08 19:43:41 +02:00
|
|
|
if (player.corporation === null) throw helpers.makeRuntimeErrorMsg(ctx, "Must own a corporation.");
|
2021-12-04 05:06:04 +01:00
|
|
|
if (!api) return;
|
|
|
|
|
2022-08-08 19:43:41 +02:00
|
|
|
if (!player.corporation.unlockUpgrades[api])
|
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, "You do not have access to this API.");
|
2021-12-04 05:06:04 +01:00
|
|
|
}
|
|
|
|
|
2022-01-11 21:25:23 +01:00
|
|
|
function getSafeDivision(division: Industry): NSDivision {
|
|
|
|
const cities: string[] = [];
|
2022-01-17 11:03:29 +01:00
|
|
|
for (const office of Object.values(division.offices)) {
|
|
|
|
if (office === 0) continue;
|
|
|
|
cities.push(office.loc);
|
|
|
|
}
|
2022-04-27 06:48:22 +02:00
|
|
|
|
2022-01-17 11:03:29 +01:00
|
|
|
return {
|
|
|
|
name: division.name,
|
|
|
|
type: division.type,
|
|
|
|
awareness: division.awareness,
|
|
|
|
popularity: division.popularity,
|
|
|
|
prodMult: division.prodMult,
|
|
|
|
research: division.sciResearch.qty,
|
|
|
|
lastCycleRevenue: division.lastCycleRevenue,
|
|
|
|
lastCycleExpenses: division.lastCycleExpenses,
|
|
|
|
thisCycleRevenue: division.thisCycleRevenue,
|
|
|
|
thisCycleExpenses: division.thisCycleExpenses,
|
2022-06-02 03:43:22 +02:00
|
|
|
upgrades: [0, division.numAdVerts],
|
2022-01-17 11:03:29 +01:00
|
|
|
cities: cities,
|
|
|
|
products: division.products === undefined ? [] : Object.keys(division.products),
|
2022-04-27 15:37:02 +02:00
|
|
|
makesProducts: division.makesProducts,
|
2022-01-17 11:03:29 +01:00
|
|
|
};
|
2022-01-11 21:25:23 +01:00
|
|
|
}
|
|
|
|
|
2022-05-08 01:08:07 +02:00
|
|
|
const warehouseAPI: InternalAPI<WarehouseAPI> = {
|
2022-10-12 14:49:27 +02:00
|
|
|
getPurchaseWarehouseCost: (ctx) => () => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkAccess(ctx, 7);
|
2022-01-12 00:47:04 +01:00
|
|
|
return CorporationConstants.WarehouseInitialCost;
|
|
|
|
},
|
2022-05-08 01:08:07 +02:00
|
|
|
getUpgradeWarehouseCost:
|
2022-10-12 14:49:27 +02:00
|
|
|
(ctx) =>
|
|
|
|
(_divisionName, _cityName, _amt = 1) => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkAccess(ctx, 7);
|
2022-08-08 19:43:41 +02:00
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const amt = helpers.number(ctx, "amount", _amt);
|
2022-05-08 01:08:07 +02:00
|
|
|
if (amt < 1) {
|
2022-08-08 19:43:41 +02:00
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, "You must provide a positive number");
|
2022-05-08 01:08:07 +02:00
|
|
|
}
|
|
|
|
const warehouse = getWarehouse(divisionName, cityName);
|
|
|
|
return UpgradeWarehouseCost(warehouse, amt);
|
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
hasWarehouse: (ctx) => (_divisionName, _cityName) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const division = getDivision(divisionName);
|
|
|
|
if (!(cityName in division.warehouses)) throw new Error(`Invalid city name '${cityName}'`);
|
|
|
|
const warehouse = division.warehouses[cityName];
|
|
|
|
return warehouse !== 0;
|
|
|
|
},
|
|
|
|
getWarehouse: (ctx) => (_divisionName, _cityName) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const warehouse = getWarehouse(divisionName, cityName);
|
|
|
|
return {
|
|
|
|
level: warehouse.level,
|
|
|
|
loc: warehouse.loc,
|
|
|
|
size: warehouse.size,
|
|
|
|
sizeUsed: warehouse.sizeUsed,
|
|
|
|
smartSupplyEnabled: warehouse.smartSupplyEnabled,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
getMaterial: (ctx) => (_divisionName, _cityName, _materialName) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const materialName = helpers.string(ctx, "materialName", _materialName);
|
|
|
|
const material = getMaterial(divisionName, cityName, materialName);
|
|
|
|
const corporation = getCorporation();
|
|
|
|
const exports = material.exp.map((e) => {
|
|
|
|
return { div: e.ind, loc: e.city, amt: e.amt };
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
cost: material.bCost,
|
|
|
|
sCost: material.sCost,
|
|
|
|
name: material.name,
|
|
|
|
qty: material.qty,
|
|
|
|
qlt: material.qlt,
|
|
|
|
dmd: corporation.unlockUpgrades[2] ? material.dmd : undefined,
|
|
|
|
cmp: corporation.unlockUpgrades[3] ? material.cmp : undefined,
|
|
|
|
prod: material.prd,
|
|
|
|
sell: material.sll,
|
|
|
|
exp: exports,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
getProduct: (ctx) => (_divisionName, _productName) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const productName = helpers.string(ctx, "productName", _productName);
|
|
|
|
const product = getProduct(divisionName, productName);
|
|
|
|
const corporation = getCorporation();
|
|
|
|
return {
|
|
|
|
name: product.name,
|
|
|
|
dmd: corporation.unlockUpgrades[2] ? product.dmd : undefined,
|
|
|
|
cmp: corporation.unlockUpgrades[3] ? product.cmp : undefined,
|
|
|
|
rat: product.rat,
|
|
|
|
properties: {
|
|
|
|
qlt: product.qlt,
|
|
|
|
per: product.per,
|
|
|
|
dur: product.dur,
|
|
|
|
rel: product.rel,
|
|
|
|
aes: product.aes,
|
|
|
|
fea: product.fea,
|
|
|
|
},
|
|
|
|
pCost: product.pCost,
|
|
|
|
sCost: product.sCost,
|
|
|
|
cityData: product.data,
|
|
|
|
developmentProgress: product.prog,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
purchaseWarehouse: (ctx) => (_divisionName, _cityName) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const corporation = getCorporation();
|
|
|
|
PurchaseWarehouse(corporation, getDivision(divisionName), cityName);
|
|
|
|
},
|
2022-05-08 01:08:07 +02:00
|
|
|
upgradeWarehouse:
|
2022-10-12 14:49:27 +02:00
|
|
|
(ctx) =>
|
|
|
|
(_divisionName, _cityName, _amt = 1): void => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkAccess(ctx, 7);
|
2022-08-08 19:43:41 +02:00
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const amt = helpers.number(ctx, "amount", _amt);
|
2022-05-08 01:08:07 +02:00
|
|
|
const corporation = getCorporation();
|
|
|
|
if (amt < 1) {
|
2022-08-08 19:43:41 +02:00
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, "You must provide a positive number");
|
2022-05-08 01:08:07 +02:00
|
|
|
}
|
|
|
|
UpgradeWarehouse(corporation, getDivision(divisionName), getWarehouse(divisionName, cityName), amt);
|
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
sellMaterial: (ctx) => (_divisionName, _cityName, _materialName, _amt, _price) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const materialName = helpers.string(ctx, "materialName", _materialName);
|
|
|
|
const amt = helpers.string(ctx, "amt", _amt);
|
|
|
|
const price = helpers.string(ctx, "price", _price);
|
|
|
|
const material = getMaterial(divisionName, cityName, materialName);
|
|
|
|
SellMaterial(material, amt, price);
|
|
|
|
},
|
2022-05-08 01:08:07 +02:00
|
|
|
sellProduct:
|
2022-10-12 14:49:27 +02:00
|
|
|
(ctx) =>
|
|
|
|
(_divisionName, _cityName, _productName, _amt, _price, _all): void => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkAccess(ctx, 7);
|
2022-08-08 19:43:41 +02:00
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const productName = helpers.string(ctx, "productName", _productName);
|
|
|
|
const amt = helpers.string(ctx, "amt", _amt);
|
|
|
|
const price = helpers.string(ctx, "price", _price);
|
|
|
|
const all = !!_all;
|
2022-05-08 01:08:07 +02:00
|
|
|
const product = getProduct(divisionName, productName);
|
|
|
|
SellProduct(product, cityName, amt, price, all);
|
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
discontinueProduct: (ctx) => (_divisionName, _productName) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const productName = helpers.string(ctx, "productName", _productName);
|
|
|
|
getDivision(divisionName).discontinueProduct(getProduct(divisionName, productName));
|
|
|
|
},
|
|
|
|
setSmartSupply: (ctx) => (_divisionName, _cityName, _enabled) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const enabled = !!_enabled;
|
|
|
|
const warehouse = getWarehouse(divisionName, cityName);
|
|
|
|
if (!hasUnlockUpgrade("Smart Supply"))
|
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, `You have not purchased the Smart Supply upgrade!`);
|
|
|
|
SetSmartSupply(warehouse, enabled);
|
|
|
|
},
|
|
|
|
setSmartSupplyUseLeftovers: (ctx) => (_divisionName, _cityName, _materialName, _enabled) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const materialName = helpers.string(ctx, "materialName", _materialName);
|
|
|
|
const enabled = !!_enabled;
|
|
|
|
const warehouse = getWarehouse(divisionName, cityName);
|
|
|
|
const material = getMaterial(divisionName, cityName, materialName);
|
|
|
|
if (!hasUnlockUpgrade("Smart Supply"))
|
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, `You have not purchased the Smart Supply upgrade!`);
|
|
|
|
SetSmartSupplyUseLeftovers(warehouse, material, enabled);
|
|
|
|
},
|
|
|
|
buyMaterial: (ctx) => (_divisionName, _cityName, _materialName, _amt) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const materialName = helpers.string(ctx, "materialName", _materialName);
|
|
|
|
const amt = helpers.number(ctx, "amt", _amt);
|
2022-10-24 22:09:53 +02:00
|
|
|
if (amt < 0 || !Number.isFinite(amt))
|
|
|
|
throw new Error("Invalid value for amount field! Must be numeric and greater than 0");
|
2022-10-12 14:49:27 +02:00
|
|
|
const material = getMaterial(divisionName, cityName, materialName);
|
|
|
|
BuyMaterial(material, amt);
|
|
|
|
},
|
|
|
|
bulkPurchase: (ctx) => (_divisionName, _cityName, _materialName, _amt) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
if (!hasResearched(getDivision(divisionName), "Bulk Purchasing"))
|
|
|
|
throw new Error(`You have not researched Bulk Purchasing in ${divisionName}`);
|
|
|
|
const corporation = getCorporation();
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const materialName = helpers.string(ctx, "materialName", _materialName);
|
|
|
|
const amt = helpers.number(ctx, "amt", _amt);
|
|
|
|
const warehouse = getWarehouse(divisionName, cityName);
|
|
|
|
const material = getMaterial(divisionName, cityName, materialName);
|
|
|
|
BulkPurchase(corporation, warehouse, material, amt);
|
|
|
|
},
|
2022-05-08 01:08:07 +02:00
|
|
|
makeProduct:
|
2022-10-12 14:49:27 +02:00
|
|
|
(ctx) =>
|
|
|
|
(_divisionName, _cityName, _productName, _designInvest, _marketingInvest): void => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkAccess(ctx, 7);
|
2022-08-08 19:43:41 +02:00
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const productName = helpers.string(ctx, "productName", _productName);
|
|
|
|
const designInvest = helpers.number(ctx, "designInvest", _designInvest);
|
|
|
|
const marketingInvest = helpers.number(ctx, "marketingInvest", _marketingInvest);
|
2022-05-08 01:08:07 +02:00
|
|
|
const corporation = getCorporation();
|
|
|
|
MakeProduct(corporation, getDivision(divisionName), cityName, productName, designInvest, marketingInvest);
|
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
limitProductProduction: (ctx) => (_divisionName, _cityName, _productName, _qty) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const productName = helpers.string(ctx, "productName", _productName);
|
|
|
|
const qty = helpers.number(ctx, "qty", _qty);
|
|
|
|
LimitProductProduction(getProduct(divisionName, productName), cityName, qty);
|
|
|
|
},
|
2022-05-08 01:08:07 +02:00
|
|
|
exportMaterial:
|
2022-10-12 14:49:27 +02:00
|
|
|
(ctx) =>
|
2022-10-25 03:54:54 +02:00
|
|
|
(_sourceDivision, sourceCity, _targetDivision, targetCity, _materialName, _amt): void => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkAccess(ctx, 7);
|
2022-08-08 19:43:41 +02:00
|
|
|
const sourceDivision = helpers.string(ctx, "sourceDivision", _sourceDivision);
|
2022-10-25 03:54:54 +02:00
|
|
|
assertEnumMember(ctx, CityName, "City", "sourceCity", sourceCity);
|
2022-08-08 19:43:41 +02:00
|
|
|
const targetDivision = helpers.string(ctx, "targetDivision", _targetDivision);
|
2022-10-25 03:54:54 +02:00
|
|
|
assertEnumMember(ctx, CityName, "City", "targetCity", targetCity);
|
2022-08-08 19:43:41 +02:00
|
|
|
const materialName = helpers.string(ctx, "materialName", _materialName);
|
|
|
|
const amt = helpers.string(ctx, "amt", _amt);
|
2022-05-08 01:08:07 +02:00
|
|
|
ExportMaterial(
|
|
|
|
targetDivision,
|
|
|
|
targetCity,
|
|
|
|
getMaterial(sourceDivision, sourceCity, materialName),
|
|
|
|
amt + "",
|
|
|
|
getDivision(targetDivision),
|
2022-03-30 02:24:04 +02:00
|
|
|
);
|
2022-05-08 01:08:07 +02:00
|
|
|
},
|
|
|
|
cancelExportMaterial:
|
2022-10-12 14:49:27 +02:00
|
|
|
(ctx) =>
|
2022-10-25 03:54:54 +02:00
|
|
|
(_sourceDivision, sourceCity, _targetDivision, targetCity, _materialName, _amt): void => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkAccess(ctx, 7);
|
2022-08-08 19:43:41 +02:00
|
|
|
const sourceDivision = helpers.string(ctx, "sourceDivision", _sourceDivision);
|
2022-10-25 03:54:54 +02:00
|
|
|
assertEnumMember(ctx, CityName, "City", "sourceCity", sourceCity);
|
2022-08-08 19:43:41 +02:00
|
|
|
const targetDivision = helpers.string(ctx, "targetDivision", _targetDivision);
|
2022-10-25 03:54:54 +02:00
|
|
|
assertEnumMember(ctx, CityName, "City", "targetCity", targetCity);
|
2022-08-08 19:43:41 +02:00
|
|
|
const materialName = helpers.string(ctx, "materialName", _materialName);
|
|
|
|
const amt = helpers.string(ctx, "amt", _amt);
|
2022-05-08 01:08:07 +02:00
|
|
|
CancelExportMaterial(
|
|
|
|
targetDivision,
|
|
|
|
targetCity,
|
|
|
|
getMaterial(sourceDivision, sourceCity, materialName),
|
|
|
|
amt + "",
|
2022-03-30 02:24:04 +02:00
|
|
|
);
|
2022-05-08 01:08:07 +02:00
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
limitMaterialProduction: (ctx) => (_divisionName, _cityName, _materialName, _qty) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const materialName = helpers.string(ctx, "materialName", _materialName);
|
|
|
|
const qty = helpers.number(ctx, "qty", _qty);
|
|
|
|
LimitMaterialProduction(getMaterial(divisionName, cityName, materialName), qty);
|
|
|
|
},
|
|
|
|
setMaterialMarketTA1: (ctx) => (_divisionName, _cityName, _materialName, _on) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const materialName = helpers.string(ctx, "materialName", _materialName);
|
|
|
|
const on = !!_on;
|
|
|
|
if (!getDivision(divisionName).hasResearch("Market-TA.I"))
|
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, `You have not researched MarketTA.I for division: ${divisionName}`);
|
|
|
|
SetMaterialMarketTA1(getMaterial(divisionName, cityName, materialName), on);
|
|
|
|
},
|
|
|
|
setMaterialMarketTA2: (ctx) => (_divisionName, _cityName, _materialName, _on) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const materialName = helpers.string(ctx, "materialName", _materialName);
|
|
|
|
const on = !!_on;
|
|
|
|
if (!getDivision(divisionName).hasResearch("Market-TA.II"))
|
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, `You have not researched MarketTA.II for division: ${divisionName}`);
|
|
|
|
SetMaterialMarketTA2(getMaterial(divisionName, cityName, materialName), on);
|
|
|
|
},
|
|
|
|
setProductMarketTA1: (ctx) => (_divisionName, _productName, _on) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const productName = helpers.string(ctx, "productName", _productName);
|
|
|
|
const on = !!_on;
|
|
|
|
if (!getDivision(divisionName).hasResearch("Market-TA.I"))
|
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, `You have not researched MarketTA.I for division: ${divisionName}`);
|
|
|
|
SetProductMarketTA1(getProduct(divisionName, productName), on);
|
|
|
|
},
|
|
|
|
setProductMarketTA2: (ctx) => (_divisionName, _productName, _on) => {
|
|
|
|
checkAccess(ctx, 7);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const productName = helpers.string(ctx, "productName", _productName);
|
|
|
|
const on = !!_on;
|
|
|
|
if (!getDivision(divisionName).hasResearch("Market-TA.II"))
|
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, `You have not researched MarketTA.II for division: ${divisionName}`);
|
|
|
|
SetProductMarketTA2(getProduct(divisionName, productName), on);
|
|
|
|
},
|
2021-12-04 05:06:04 +01:00
|
|
|
};
|
|
|
|
|
2022-05-08 01:08:07 +02:00
|
|
|
const officeAPI: InternalAPI<OfficeAPI> = {
|
2022-10-12 14:49:27 +02:00
|
|
|
getHireAdVertCost: (ctx) => (_divisionName) => {
|
|
|
|
checkAccess(ctx, 8);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const division = getDivision(divisionName);
|
|
|
|
return division.getAdVertCost();
|
|
|
|
},
|
|
|
|
getHireAdVertCount: (ctx) => (_divisionName) => {
|
|
|
|
checkAccess(ctx, 8);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const division = getDivision(divisionName);
|
|
|
|
return division.numAdVerts;
|
|
|
|
},
|
|
|
|
getResearchCost: (ctx) => (_divisionName, _researchName) => {
|
|
|
|
checkAccess(ctx, 8);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const researchName = helpers.string(ctx, "researchName", _researchName);
|
|
|
|
return getResearchCost(getDivision(divisionName), researchName);
|
|
|
|
},
|
|
|
|
hasResearched: (ctx) => (_divisionName, _researchName) => {
|
|
|
|
checkAccess(ctx, 8);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const researchName = helpers.string(ctx, "researchName", _researchName);
|
|
|
|
return hasResearched(getDivision(divisionName), researchName);
|
|
|
|
},
|
|
|
|
getOfficeSizeUpgradeCost: (ctx) => (_divisionName, _cityName, _size) => {
|
|
|
|
checkAccess(ctx, 8);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const size = helpers.number(ctx, "size", _size);
|
|
|
|
if (size < 0) throw new Error("Invalid value for size field! Must be numeric and greater than 0");
|
|
|
|
const office = getOffice(divisionName, cityName);
|
|
|
|
const initialPriceMult = Math.round(office.size / CorporationConstants.OfficeInitialSize);
|
|
|
|
const costMultiplier = 1.09;
|
|
|
|
let mult = 0;
|
|
|
|
for (let i = 0; i < size / CorporationConstants.OfficeInitialSize; ++i) {
|
|
|
|
mult += Math.pow(costMultiplier, initialPriceMult + i);
|
|
|
|
}
|
|
|
|
return CorporationConstants.OfficeInitialCost * mult;
|
|
|
|
},
|
|
|
|
setAutoJobAssignment: (ctx) => (_divisionName, _cityName, _job, _amount) => {
|
|
|
|
checkAccess(ctx, 8);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const amount = helpers.number(ctx, "amount", _amount);
|
|
|
|
const job = helpers.string(ctx, "job", _job);
|
2022-06-01 19:11:33 +02:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
if (!checkEnum(EmployeePositions, job)) throw new Error(`'${job}' is not a valid job.`);
|
|
|
|
const office = getOffice(divisionName, cityName);
|
|
|
|
return AutoAssignJob(office, job, amount);
|
|
|
|
},
|
2022-10-24 14:44:01 +02:00
|
|
|
hireEmployee: (ctx) => (_divisionName, _cityName, _position?) => {
|
2022-10-12 14:49:27 +02:00
|
|
|
checkAccess(ctx, 8);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
2022-10-24 14:44:01 +02:00
|
|
|
const position = _position ? helpers.string(ctx, "position", _position) : EmployeePositions.Unassigned;
|
|
|
|
if (!checkEnum(EmployeePositions, position)) {
|
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid position: ${position}`);
|
|
|
|
}
|
2022-10-12 14:49:27 +02:00
|
|
|
const office = getOffice(divisionName, cityName);
|
2022-10-24 14:44:01 +02:00
|
|
|
return office.hireRandomEmployee(position);
|
2022-10-12 14:49:27 +02:00
|
|
|
},
|
|
|
|
upgradeOfficeSize: (ctx) => (_divisionName, _cityName, _size) => {
|
|
|
|
checkAccess(ctx, 8);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const size = helpers.number(ctx, "size", _size);
|
|
|
|
if (size < 0) throw new Error("Invalid value for size field! Must be numeric and greater than 0");
|
|
|
|
const office = getOffice(divisionName, cityName);
|
|
|
|
const corporation = getCorporation();
|
|
|
|
UpgradeOfficeSize(corporation, office, size);
|
|
|
|
},
|
|
|
|
throwParty: (ctx) => (_divisionName, _cityName, _costPerEmployee) => {
|
|
|
|
checkAccess(ctx, 8);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const costPerEmployee = helpers.number(ctx, "costPerEmployee", _costPerEmployee);
|
2022-06-02 00:26:32 +02:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
if (costPerEmployee < 0) {
|
|
|
|
throw new Error("Invalid value for Cost Per Employee field! Must be numeric and greater than 0");
|
|
|
|
}
|
|
|
|
const corporation = getCorporation();
|
|
|
|
const office = getOffice(divisionName, cityName);
|
2022-06-02 00:26:32 +02:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
return ThrowParty(corporation, office, costPerEmployee);
|
|
|
|
},
|
|
|
|
buyCoffee: (ctx) => (_divisionName, _cityName) => {
|
|
|
|
checkAccess(ctx, 8);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
2022-06-02 00:26:32 +02:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
const corporation = getCorporation();
|
|
|
|
const office = getOffice(divisionName, cityName);
|
|
|
|
return BuyCoffee(corporation, office);
|
|
|
|
},
|
|
|
|
hireAdVert: (ctx) => (_divisionName) => {
|
|
|
|
checkAccess(ctx, 8);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const corporation = getCorporation();
|
|
|
|
HireAdVert(corporation, getDivision(divisionName));
|
|
|
|
},
|
|
|
|
research: (ctx) => (_divisionName, _researchName) => {
|
|
|
|
checkAccess(ctx, 8);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const researchName = helpers.string(ctx, "researchName", _researchName);
|
|
|
|
Research(getDivision(divisionName), researchName);
|
|
|
|
},
|
|
|
|
getOffice: (ctx) => (_divisionName, _cityName) => {
|
|
|
|
checkAccess(ctx, 8);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
const office = getOffice(divisionName, cityName);
|
|
|
|
return {
|
|
|
|
loc: office.loc,
|
|
|
|
size: office.size,
|
|
|
|
minEne: office.minEne,
|
|
|
|
maxEne: office.maxEne,
|
|
|
|
minHap: office.minHap,
|
|
|
|
maxHap: office.maxHap,
|
|
|
|
minMor: office.minMor,
|
|
|
|
maxMor: office.maxMor,
|
2022-10-24 14:44:01 +02:00
|
|
|
employees: office.totalEmployees,
|
|
|
|
avgEne: office.avgEne,
|
|
|
|
avgHap: office.avgHap,
|
|
|
|
avgMor: office.avgMor,
|
|
|
|
employeeProd: Object.assign({}, office.employeeProd),
|
|
|
|
employeeJobs: Object.assign({}, office.employeeJobs),
|
2022-10-12 14:49:27 +02:00
|
|
|
};
|
|
|
|
},
|
2021-12-04 05:06:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
...warehouseAPI,
|
|
|
|
...officeAPI,
|
2022-11-09 13:26:26 +01:00
|
|
|
hasCorporation: () => () => !!Player.corporation,
|
2022-10-25 03:54:54 +02:00
|
|
|
// Todo: Just remove these functions and provide enums?
|
2022-10-12 14:49:27 +02:00
|
|
|
getMaterialNames: (ctx) => () => {
|
2022-08-31 11:05:36 +02:00
|
|
|
checkAccess(ctx);
|
|
|
|
return [...CorporationConstants.AllMaterials];
|
2022-08-10 00:25:02 +02:00
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
getIndustryTypes: (ctx) => () => {
|
2022-08-31 11:05:36 +02:00
|
|
|
checkAccess(ctx);
|
2022-10-25 03:54:54 +02:00
|
|
|
return Object.values(IndustryType);
|
|
|
|
},
|
|
|
|
getEmployeePositions: (ctx) => () => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
return Object.values(EmployeePositions);
|
2022-08-10 00:25:02 +02:00
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
getUnlockables: (ctx) => () => {
|
2022-08-31 11:05:36 +02:00
|
|
|
checkAccess(ctx);
|
|
|
|
return [...CorporationConstants.AllUnlocks];
|
2022-08-10 00:25:02 +02:00
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
getUpgradeNames: (ctx) => () => {
|
2022-08-31 11:05:36 +02:00
|
|
|
checkAccess(ctx);
|
|
|
|
return [...CorporationConstants.AllUpgrades];
|
2022-08-10 00:25:02 +02:00
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
getResearchNames: (ctx) => () => {
|
2022-08-31 11:05:36 +02:00
|
|
|
checkAccess(ctx);
|
|
|
|
return [...CorporationConstants.AllResearch];
|
2022-08-10 00:25:02 +02:00
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
expandIndustry: (ctx) => (_industryName, _divisionName) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const industryName = helpers.string(ctx, "industryName", _industryName);
|
2022-10-25 03:54:54 +02:00
|
|
|
if (!checkEnum(IndustryType, industryName)) {
|
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid industry: ${industryName}`);
|
|
|
|
}
|
2022-10-12 14:49:27 +02:00
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const corporation = getCorporation();
|
|
|
|
NewIndustry(corporation, industryName, divisionName);
|
|
|
|
},
|
|
|
|
expandCity: (ctx) => (_divisionName, _cityName) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const cityName = helpers.city(ctx, "cityName", _cityName);
|
|
|
|
if (!CorporationConstants.Cities.includes(cityName)) throw new Error("Invalid city name");
|
|
|
|
const corporation = getCorporation();
|
|
|
|
const division = getDivision(divisionName);
|
|
|
|
NewCity(corporation, division, cityName);
|
|
|
|
},
|
|
|
|
unlockUpgrade: (ctx) => (_upgradeName) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
|
|
|
const corporation = getCorporation();
|
|
|
|
const upgrade = Object.values(CorporationUnlockUpgrades).find((upgrade) => upgrade.name === upgradeName);
|
|
|
|
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
|
|
|
|
UnlockUpgrade(corporation, upgrade);
|
|
|
|
},
|
|
|
|
levelUpgrade: (ctx) => (_upgradeName) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
|
|
|
const corporation = getCorporation();
|
|
|
|
const upgrade = Object.values(CorporationUpgrades).find((upgrade) => upgrade.name === upgradeName);
|
|
|
|
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
|
|
|
|
LevelUpgrade(corporation, upgrade);
|
|
|
|
},
|
|
|
|
issueDividends: (ctx) => (_rate) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const rate = helpers.number(ctx, "rate", _rate);
|
|
|
|
const max = CorporationConstants.DividendMaxRate;
|
|
|
|
if (rate < 0 || rate > max)
|
|
|
|
throw new Error(`Invalid value for rate field! Must be numeric, greater than 0, and less than ${max}`);
|
|
|
|
const corporation = getCorporation();
|
|
|
|
if (!corporation.public) throw helpers.makeRuntimeErrorMsg(ctx, `Your company has not gone public!`);
|
|
|
|
IssueDividends(corporation, rate);
|
|
|
|
},
|
2021-12-04 05:06:04 +01:00
|
|
|
|
2021-10-14 09:22:02 +02:00
|
|
|
// If you modify these objects you will affect them for real, it's not
|
|
|
|
// copies.
|
2022-10-12 14:49:27 +02:00
|
|
|
getDivision: (ctx) => (_divisionName) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
|
|
|
const division = getDivision(divisionName);
|
|
|
|
return getSafeDivision(division);
|
|
|
|
},
|
|
|
|
getCorporation: (ctx) => () => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkAccess(ctx);
|
2021-12-04 05:06:04 +01:00
|
|
|
const corporation = getCorporation();
|
|
|
|
return {
|
|
|
|
name: corporation.name,
|
|
|
|
funds: corporation.funds,
|
|
|
|
revenue: corporation.revenue,
|
|
|
|
expenses: corporation.expenses,
|
|
|
|
public: corporation.public,
|
|
|
|
totalShares: corporation.totalShares,
|
|
|
|
numShares: corporation.numShares,
|
|
|
|
shareSaleCooldown: corporation.shareSaleCooldown,
|
|
|
|
issuedShares: corporation.issuedShares,
|
|
|
|
sharePrice: corporation.sharePrice,
|
2022-05-30 23:21:27 +02:00
|
|
|
dividendRate: corporation.dividendRate,
|
|
|
|
dividendTax: corporation.dividendTax,
|
2022-06-01 13:59:45 +02:00
|
|
|
dividendEarnings: corporation.getCycleDividends() / CorporationConstants.SecsPerMarketCycle,
|
2021-12-24 17:32:51 +01:00
|
|
|
state: corporation.state.getState(),
|
2022-01-11 21:25:23 +01:00
|
|
|
divisions: corporation.divisions.map((division): NSDivision => getSafeDivision(division)),
|
2021-12-04 05:06:04 +01:00
|
|
|
};
|
2021-10-14 09:22:02 +02:00
|
|
|
},
|
2022-05-08 01:08:07 +02:00
|
|
|
createCorporation:
|
2022-10-12 14:49:27 +02:00
|
|
|
(ctx) =>
|
|
|
|
(_corporationName, _selfFund = true): boolean => {
|
2022-08-08 19:43:41 +02:00
|
|
|
const corporationName = helpers.string(ctx, "corporationName", _corporationName);
|
2022-08-20 16:37:39 +02:00
|
|
|
const selfFund = !!_selfFund;
|
2022-05-08 01:08:07 +02:00
|
|
|
return createCorporation(corporationName, selfFund);
|
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
hasUnlockUpgrade: (ctx) => (_upgradeName) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
|
|
|
return hasUnlockUpgrade(upgradeName);
|
|
|
|
},
|
|
|
|
getUnlockUpgradeCost: (ctx) => (_upgradeName) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
|
|
|
return getUnlockUpgradeCost(upgradeName);
|
|
|
|
},
|
|
|
|
getUpgradeLevel: (ctx) => (_upgradeName) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
|
|
|
return getUpgradeLevel(ctx, upgradeName);
|
|
|
|
},
|
|
|
|
getUpgradeLevelCost: (ctx) => (_upgradeName) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
|
|
|
return getUpgradeLevelCost(ctx, upgradeName);
|
|
|
|
},
|
|
|
|
getExpandIndustryCost: (ctx) => (_industryName) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const industryName = helpers.string(ctx, "industryName", _industryName);
|
2022-10-25 03:54:54 +02:00
|
|
|
if (!checkEnum(IndustryType, industryName)) {
|
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid industry: '${industryName}'`);
|
|
|
|
}
|
|
|
|
return IndustriesData[industryName].startingCost;
|
2022-10-12 14:49:27 +02:00
|
|
|
},
|
|
|
|
getExpandCityCost: (ctx) => () => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkAccess(ctx);
|
2022-01-12 00:47:04 +01:00
|
|
|
return getExpandCityCost();
|
2022-01-13 12:42:23 +01:00
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
getInvestmentOffer: (ctx) => () => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkAccess(ctx);
|
2022-01-13 12:42:23 +01:00
|
|
|
return getInvestmentOffer();
|
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
acceptInvestmentOffer: (ctx) => () => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkAccess(ctx);
|
2022-01-13 12:42:23 +01:00
|
|
|
return acceptInvestmentOffer();
|
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
goPublic: (ctx) => (_numShares) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const numShares = helpers.number(ctx, "numShares", _numShares);
|
|
|
|
return goPublic(numShares);
|
|
|
|
},
|
|
|
|
sellShares: (ctx) => (_numShares) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const numShares = helpers.number(ctx, "numShares", _numShares);
|
|
|
|
return SellShares(getCorporation(), numShares);
|
|
|
|
},
|
|
|
|
buyBackShares: (ctx) => (_numShares) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const numShares = helpers.number(ctx, "numShares", _numShares);
|
|
|
|
return BuyBackShares(getCorporation(), numShares);
|
|
|
|
},
|
|
|
|
bribe: (ctx) => (_factionName, _amountCash) => {
|
|
|
|
checkAccess(ctx);
|
|
|
|
const factionName = helpers.string(ctx, "factionName", _factionName);
|
|
|
|
const amountCash = helpers.number(ctx, "amountCash", _amountCash);
|
|
|
|
return bribe(factionName, amountCash);
|
|
|
|
},
|
|
|
|
getBonusTime: (ctx) => () => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkAccess(ctx);
|
2022-03-19 21:22:29 +01:00
|
|
|
return Math.round(getCorporation().storedCycles / 5) * 1000;
|
2022-03-30 02:24:04 +02:00
|
|
|
},
|
2021-10-14 09:22:02 +02:00
|
|
|
};
|
|
|
|
}
|