mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-27 19:37:07 +02:00
ENUMS: Initial Enum Helper rework + Reorganization (#596)
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import type { Bladeburner as INetscriptBladeburner } from "@nsdefs";
|
||||
import type { Action } from "../Bladeburner/Action";
|
||||
import type { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
|
||||
import { Player } from "@player";
|
||||
import { Bladeburner } from "../Bladeburner/Bladeburner";
|
||||
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
||||
import { Bladeburner as INetscriptBladeburner } from "@nsdefs";
|
||||
import { Action } from "src/Bladeburner/Action";
|
||||
import { InternalAPI, NetscriptContext } from "src/Netscript/APIWrapper";
|
||||
import { BlackOperation } from "../Bladeburner/BlackOperation";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { checkEnum } from "../utils/helpers/enum";
|
||||
import { CityName } from "../Enums";
|
||||
import { getEnumHelper } from "../utils/EnumHelper";
|
||||
|
||||
export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
const checkBladeburnerAccess = function (ctx: NetscriptContext): void {
|
||||
@@ -266,20 +266,17 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
},
|
||||
getCityEstimatedPopulation: (ctx) => (_cityName) => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
const cityName = helpers.string(ctx, "cityName", _cityName);
|
||||
if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city: ${cityName}`);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
return bladeburner.cities[cityName].popEst;
|
||||
},
|
||||
getCityCommunities: (ctx) => (_cityName) => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
const cityName = helpers.string(ctx, "cityName", _cityName);
|
||||
if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city: ${cityName}`);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
return bladeburner.cities[cityName].comms;
|
||||
},
|
||||
getCityChaos: (ctx) => (_cityName) => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
const cityName = helpers.string(ctx, "cityName", _cityName);
|
||||
if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city: ${cityName}`);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
return bladeburner.cities[cityName].chaos;
|
||||
},
|
||||
getCity: (ctx) => () => {
|
||||
@@ -288,8 +285,7 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
},
|
||||
switchCity: (ctx) => (_cityName) => {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
const cityName = helpers.string(ctx, "cityName", _cityName);
|
||||
if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city: ${cityName}`);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
bladeburner.city = cityName;
|
||||
return true;
|
||||
},
|
||||
|
||||
@@ -51,16 +51,15 @@ import {
|
||||
} from "../Corporation/Actions";
|
||||
import { CorpUnlocks } from "../Corporation/data/CorporationUnlocks";
|
||||
import { CorpUpgrades } from "../Corporation/data/CorporationUpgrades";
|
||||
import { CorpUnlockName, CorpUpgradeName, CorpEmployeeJob, IndustryType } from "../Corporation/data/Enums";
|
||||
import { CorpUnlockName, CorpUpgradeName, CorpEmployeeJob, CityName } from "@enums";
|
||||
import { IndustriesData, IndustryResearchTrees } from "../Corporation/data/IndustryData";
|
||||
import * as corpConstants from "../Corporation/data/Constants";
|
||||
import { ResearchMap } from "../Corporation/ResearchMap";
|
||||
import { Factions } from "../Faction/Factions";
|
||||
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
||||
import { InternalAPI, NetscriptContext, removedFunction } from "../Netscript/APIWrapper";
|
||||
import { assertMember, helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { checkEnum } from "../utils/helpers/enum";
|
||||
import { CityName } from "../Enums";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { getEnumHelper } from "../utils/EnumHelper";
|
||||
import { MaterialInfo } from "../Corporation/MaterialInfo";
|
||||
import { calculateUpgradeCost } from "../Corporation/helpers";
|
||||
import { PositiveInteger } from "../types";
|
||||
@@ -207,17 +206,15 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
return division;
|
||||
}
|
||||
|
||||
function getOffice(divisionName: string, cityName: string): OfficeSpace {
|
||||
function getOffice(divisionName: string, cityName: CityName): OfficeSpace {
|
||||
const division = getDivision(divisionName);
|
||||
if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city name '${cityName}'`);
|
||||
const office = division.offices[cityName];
|
||||
if (!office) throw new Error(`${division.name} has not expanded to '${cityName}'`);
|
||||
return office;
|
||||
}
|
||||
|
||||
function getWarehouse(divisionName: string, cityName: string): Warehouse {
|
||||
function getWarehouse(divisionName: string, cityName: CityName): Warehouse {
|
||||
const division = getDivision(divisionName);
|
||||
if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city name '${cityName}'`);
|
||||
const warehouse = division.warehouses[cityName];
|
||||
if (!warehouse) throw new Error(`${division.name} does not have a warehouse in '${cityName}'`);
|
||||
return warehouse;
|
||||
@@ -272,7 +269,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
(_divisionName, _cityName, _amt = 1) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const amt = helpers.number(ctx, "amount", _amt);
|
||||
if (amt < 1) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, "You must provide a positive number");
|
||||
@@ -283,14 +280,14 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
hasWarehouse: (ctx) => (_divisionName, _cityName) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const division = getDivision(divisionName);
|
||||
return cityName in division.warehouses;
|
||||
},
|
||||
getWarehouse: (ctx) => (_divisionName, _cityName) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const warehouse = getWarehouse(divisionName, cityName);
|
||||
return {
|
||||
level: warehouse.level,
|
||||
@@ -300,11 +297,11 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
smartSupplyEnabled: warehouse.smartSupplyEnabled,
|
||||
};
|
||||
},
|
||||
getMaterial: (ctx) => (_divisionName, _cityName, materialName) => {
|
||||
getMaterial: (ctx) => (_divisionName, _cityName, _materialName) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const materialName = getEnumHelper("CorpMaterialName").nsGetMember(ctx, _materialName, "materialName");
|
||||
const material = getMaterial(divisionName, cityName, materialName);
|
||||
const corporation = getCorporation();
|
||||
const exports = cloneDeep(material.exports);
|
||||
@@ -326,7 +323,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const productName = helpers.string(ctx, "productName", _productName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const product = getProduct(divisionName, productName);
|
||||
const corporation = getCorporation();
|
||||
const cityData = product.cityData[cityName];
|
||||
@@ -349,7 +346,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
purchaseWarehouse: (ctx) => (_divisionName, _cityName) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const corporation = getCorporation();
|
||||
purchaseWarehouse(corporation, getDivision(divisionName), cityName);
|
||||
},
|
||||
@@ -358,7 +355,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
(_divisionName, _cityName, _amt = 1): void => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const amt = helpers.number(ctx, "amount", _amt);
|
||||
const corporation = getCorporation();
|
||||
if (amt < 1) {
|
||||
@@ -366,11 +363,11 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
}
|
||||
UpgradeWarehouse(corporation, getDivision(divisionName), getWarehouse(divisionName, cityName), amt);
|
||||
},
|
||||
sellMaterial: (ctx) => (_divisionName, _cityName, materialName, _amt, _price) => {
|
||||
sellMaterial: (ctx) => (_divisionName, _cityName, _materialName, _amt, _price) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const materialName = getEnumHelper("CorpMaterialName").nsGetMember(ctx, _materialName, "materialName");
|
||||
const amt = helpers.string(ctx, "amt", _amt);
|
||||
const price = helpers.string(ctx, "price", _price);
|
||||
const material = getMaterial(divisionName, cityName, materialName);
|
||||
@@ -381,7 +378,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
(_divisionName, _cityName, _productName, _amt, _price, _all): void => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const productName = helpers.string(ctx, "productName", _productName);
|
||||
const amt = helpers.string(ctx, "amt", _amt);
|
||||
const price = helpers.string(ctx, "price", _price);
|
||||
@@ -398,43 +395,42 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
setSmartSupply: (ctx) => (_divisionName, _cityName, _enabled) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const enabled = !!_enabled;
|
||||
const warehouse = getWarehouse(divisionName, cityName);
|
||||
if (!hasUnlock(CorpUnlockName.SmartSupply))
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `You have not purchased the Smart Supply upgrade!`);
|
||||
SetSmartSupply(warehouse, enabled);
|
||||
},
|
||||
setSmartSupplyOption: (ctx) => (_divisionName, _cityName, materialName, _option) => {
|
||||
setSmartSupplyOption: (ctx) => (_divisionName, _cityName, _materialName, _option) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const materialName = getEnumHelper("CorpMaterialName").nsGetMember(ctx, _materialName, "materialName");
|
||||
const warehouse = getWarehouse(divisionName, cityName);
|
||||
const material = getMaterial(divisionName, cityName, materialName);
|
||||
const option = helpers.string(ctx, "option", _option);
|
||||
assertMember(ctx, corpConstants.smartSupplyOptions, "Smart Supply Option", "option", option);
|
||||
const option = getEnumHelper("SmartSupplyOption").nsGetMember(ctx, _option);
|
||||
if (!hasUnlock(CorpUnlockName.SmartSupply))
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `You have not purchased the Smart Supply upgrade!`);
|
||||
SetSmartSupplyOption(warehouse, material, option);
|
||||
},
|
||||
buyMaterial: (ctx) => (_divisionName, _cityName, materialName, _amt) => {
|
||||
buyMaterial: (ctx) => (_divisionName, _cityName, _materialName, _amt) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const materialName = getEnumHelper("CorpMaterialName").nsGetMember(ctx, _materialName, "materialName");
|
||||
const amt = helpers.number(ctx, "amt", _amt);
|
||||
if (amt < 0 || !Number.isFinite(amt))
|
||||
throw new Error("Invalid value for amount field! Must be numeric and greater than 0");
|
||||
const material = getMaterial(divisionName, cityName, materialName);
|
||||
BuyMaterial(material, amt);
|
||||
},
|
||||
bulkPurchase: (ctx) => (_divisionName, _cityName, materialName, _amt) => {
|
||||
bulkPurchase: (ctx) => (_divisionName, _cityName, _materialName, _amt) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const corporation = getCorporation();
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const materialName = getEnumHelper("CorpMaterialName").nsGetMember(ctx, _materialName, "materialName");
|
||||
const amt = helpers.number(ctx, "amt", _amt);
|
||||
const warehouse = getWarehouse(divisionName, cityName);
|
||||
const material = getMaterial(divisionName, cityName, materialName);
|
||||
@@ -445,7 +441,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
(_divisionName, _cityName, _productName, _designInvest, _marketingInvest): void => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const productName = helpers.string(ctx, "productName", _productName);
|
||||
const designInvest = helpers.number(ctx, "designInvest", _designInvest);
|
||||
const marketingInvest = helpers.number(ctx, "marketingInvest", _marketingInvest);
|
||||
@@ -455,57 +451,58 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
limitProductProduction: (ctx) => (_divisionName, _cityName, _productName, _qty) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const productName = helpers.string(ctx, "productName", _productName);
|
||||
const qty = helpers.number(ctx, "qty", _qty);
|
||||
LimitProductProduction(getProduct(divisionName, productName), cityName, qty);
|
||||
},
|
||||
exportMaterial:
|
||||
(ctx) =>
|
||||
(_sourceDivision, sourceCity, _targetDivision, targetCity, materialName, _amt): void => {
|
||||
(_sourceDivision, _sourceCity, _targetDivision, _targetCity, _materialName, _amt): void => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const sourceDivision = helpers.string(ctx, "sourceDivision", _sourceDivision);
|
||||
assertMember(ctx, CityName, "City", "sourceCity", sourceCity);
|
||||
const sourceCity = getEnumHelper("CityName").nsGetMember(ctx, _sourceCity, "sourceCity");
|
||||
const targetDivision = getDivision(helpers.string(ctx, "targetDivision", _targetDivision));
|
||||
assertMember(ctx, CityName, "City", "targetCity", targetCity);
|
||||
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
|
||||
const targetCity = getEnumHelper("CityName").nsGetMember(ctx, _targetCity, "targetCity");
|
||||
const materialName = getEnumHelper("CorpMaterialName").nsGetMember(ctx, _materialName, "materialName");
|
||||
const amt = helpers.string(ctx, "amt", _amt);
|
||||
|
||||
ExportMaterial(targetDivision, targetCity, getMaterial(sourceDivision, sourceCity, materialName), amt);
|
||||
},
|
||||
cancelExportMaterial:
|
||||
(ctx) =>
|
||||
(_sourceDivision, sourceCity, _targetDivision, targetCity, materialName): void => {
|
||||
(_sourceDivision, _sourceCity, _targetDivision, _targetCity, _materialName): void => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const sourceDivision = helpers.string(ctx, "sourceDivision", _sourceDivision);
|
||||
assertMember(ctx, CityName, "City Name", "sourceCity", sourceCity);
|
||||
const sourceCity = getEnumHelper("CityName").nsGetMember(ctx, _sourceCity, "sourceCity");
|
||||
const targetDivision = helpers.string(ctx, "targetDivision", _targetDivision);
|
||||
assertMember(ctx, CityName, "City Name", "targetCity", targetCity);
|
||||
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
|
||||
const targetCity = getEnumHelper("CityName").nsGetMember(ctx, _targetCity, "targetCity");
|
||||
const materialName = getEnumHelper("CorpMaterialName").nsGetMember(ctx, _materialName, "materialName");
|
||||
CancelExportMaterial(targetDivision, targetCity, getMaterial(sourceDivision, sourceCity, materialName));
|
||||
},
|
||||
limitMaterialProduction: (ctx) => (_divisionName, cityName, materialName, _qty) => {
|
||||
limitMaterialProduction: (ctx) => (_divisionName, _cityName, _materialName, _qty) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
assertMember(ctx, CityName, "City Name", "cityName", cityName);
|
||||
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const materialName = getEnumHelper("CorpMaterialName").nsGetMember(ctx, _materialName, "materialName");
|
||||
const qty = helpers.number(ctx, "qty", _qty);
|
||||
LimitMaterialProduction(getMaterial(divisionName, cityName, materialName), qty);
|
||||
},
|
||||
setMaterialMarketTA1: (ctx) => (_divisionName, cityName, materialName, _on) => {
|
||||
setMaterialMarketTA1: (ctx) => (_divisionName, _cityName, _materialName, _on) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
assertMember(ctx, CityName, "City Name", "cityName", cityName);
|
||||
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const materialName = getEnumHelper("CorpMaterialName").nsGetMember(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) => {
|
||||
setMaterialMarketTA2: (ctx) => (_divisionName, _cityName, _materialName, _on) => {
|
||||
checkAccess(ctx, CorpUnlockName.WarehouseAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
assertMember(ctx, CityName, "City Name", "cityName", cityName);
|
||||
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const materialName = getEnumHelper("CorpMaterialName").nsGetMember(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}`);
|
||||
@@ -544,22 +541,22 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
const division = getDivision(divisionName);
|
||||
return division.numAdVerts;
|
||||
},
|
||||
getResearchCost: (ctx) => (_divisionName, researchName) => {
|
||||
getResearchCost: (ctx) => (_divisionName, _researchName) => {
|
||||
checkAccess(ctx, CorpUnlockName.OfficeAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
assertMember(ctx, corpConstants.researchNames, "Research Name", "researchName", researchName);
|
||||
const researchName = getEnumHelper("CorpResearchName").nsGetMember(ctx, _researchName, "researchName");
|
||||
return getResearchCost(getDivision(divisionName), researchName);
|
||||
},
|
||||
hasResearched: (ctx) => (_divisionName, researchName) => {
|
||||
hasResearched: (ctx) => (_divisionName, _researchName) => {
|
||||
checkAccess(ctx, CorpUnlockName.OfficeAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
assertMember(ctx, corpConstants.researchNames, "Research Name", "researchName", researchName);
|
||||
const researchName = getEnumHelper("CorpResearchName").nsGetMember(ctx, _researchName, "researchName");
|
||||
return hasResearched(getDivision(divisionName), researchName);
|
||||
},
|
||||
getOfficeSizeUpgradeCost: (ctx) => (_divisionName, _cityName, _size) => {
|
||||
checkAccess(ctx, CorpUnlockName.OfficeAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _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);
|
||||
@@ -574,11 +571,10 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
setAutoJobAssignment: (ctx) => (_divisionName, _cityName, _job, _amount) => {
|
||||
checkAccess(ctx, CorpUnlockName.OfficeAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const amount = helpers.number(ctx, "amount", _amount);
|
||||
const job = helpers.string(ctx, "job", _job);
|
||||
const job = getEnumHelper("CorpEmployeeJob").nsGetMember(ctx, _job, "job");
|
||||
|
||||
if (!checkEnum(CorpEmployeeJob, job)) throw new Error(`'${job}' is not a valid job.`);
|
||||
if (job === CorpEmployeeJob.Unassigned) return false;
|
||||
if (amount < 0 || !Number.isInteger(amount))
|
||||
throw helpers.makeRuntimeErrorMsg(
|
||||
@@ -600,18 +596,16 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
hireEmployee: (ctx) => (_divisionName, _cityName, _position?) => {
|
||||
checkAccess(ctx, CorpUnlockName.OfficeAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const position = _position ? helpers.string(ctx, "position", _position) : CorpEmployeeJob.Unassigned;
|
||||
if (!checkEnum(CorpEmployeeJob, position)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid position: ${position}`);
|
||||
}
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const position = getEnumHelper("CorpEmployeeJob").nsGetMember(ctx, _position, "position");
|
||||
|
||||
const office = getOffice(divisionName, cityName);
|
||||
return office.hireRandomEmployee(position);
|
||||
},
|
||||
upgradeOfficeSize: (ctx) => (_divisionName, _cityName, _size) => {
|
||||
checkAccess(ctx, CorpUnlockName.OfficeAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _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);
|
||||
@@ -621,7 +615,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
throwParty: (ctx) => (_divisionName, _cityName, _costPerEmployee) => {
|
||||
checkAccess(ctx, CorpUnlockName.OfficeAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const costPerEmployee = helpers.number(ctx, "costPerEmployee", _costPerEmployee);
|
||||
|
||||
if (costPerEmployee < 0) {
|
||||
@@ -635,7 +629,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
buyTea: (ctx) => (_divisionName, _cityName) => {
|
||||
checkAccess(ctx, CorpUnlockName.OfficeAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
|
||||
const corporation = getCorporation();
|
||||
const office = getOffice(divisionName, cityName);
|
||||
@@ -647,16 +641,16 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
const corporation = getCorporation();
|
||||
HireAdVert(corporation, getDivision(divisionName));
|
||||
},
|
||||
research: (ctx) => (_divisionName, researchName) => {
|
||||
research: (ctx) => (_divisionName, _researchName) => {
|
||||
checkAccess(ctx, CorpUnlockName.OfficeAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
assertMember(ctx, corpConstants.researchNames, "Research Name", "reseatchName", researchName);
|
||||
const researchName = getEnumHelper("CorpResearchName").nsGetMember(ctx, _researchName, "researchName");
|
||||
Research(getDivision(divisionName), researchName);
|
||||
},
|
||||
getOffice: (ctx) => (_divisionName, _cityName) => {
|
||||
checkAccess(ctx, CorpUnlockName.OfficeAPI);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const office = getOffice(divisionName, cityName);
|
||||
return {
|
||||
city: office.city,
|
||||
@@ -688,23 +682,17 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
},
|
||||
getIndustryData: (ctx) => (_industryName) => {
|
||||
checkAccess(ctx);
|
||||
const industryName = helpers.string(ctx, "industryName", _industryName);
|
||||
if (!checkEnum(IndustryType, industryName)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid industry: ${industryName}`);
|
||||
}
|
||||
const industryName = getEnumHelper("IndustryType").nsGetMember(ctx, _industryName, "industryName");
|
||||
return cloneDeep(IndustriesData[industryName]);
|
||||
},
|
||||
getMaterialData: (ctx) => (materialName) => {
|
||||
getMaterialData: (ctx) => (_materialName) => {
|
||||
checkAccess(ctx);
|
||||
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
|
||||
const materialName = getEnumHelper("CorpMaterialName").nsGetMember(ctx, _materialName, "materialName");
|
||||
return cloneDeep(MaterialInfo[materialName]);
|
||||
},
|
||||
expandIndustry: (ctx) => (_industryName, _divisionName) => {
|
||||
checkAccess(ctx);
|
||||
const industryName = helpers.string(ctx, "industryName", _industryName);
|
||||
if (!checkEnum(IndustryType, industryName)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid industry: ${industryName}`);
|
||||
}
|
||||
const industryName = getEnumHelper("IndustryType").nsGetMember(ctx, _industryName, "industryName");
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const corporation = getCorporation();
|
||||
NewDivision(corporation, industryName, divisionName);
|
||||
@@ -712,23 +700,21 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
expandCity: (ctx) => (_divisionName, _cityName) => {
|
||||
checkAccess(ctx);
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
const corporation = getCorporation();
|
||||
const division = getDivision(divisionName);
|
||||
purchaseOffice(corporation, division, cityName);
|
||||
},
|
||||
purchaseUnlock: (ctx) => (_unlockName) => {
|
||||
checkAccess(ctx);
|
||||
const unlockName = helpers.string(ctx, "upgradeName", _unlockName);
|
||||
if (!checkEnum(CorpUnlockName, unlockName)) throw new Error(`No unlock named ${unlockName}`);
|
||||
const unlockName = getEnumHelper("CorpUnlockName").nsGetMember(ctx, _unlockName, "unlockName");
|
||||
const corporation = getCorporation();
|
||||
const message = corporation.purchaseUnlock(unlockName);
|
||||
if (message) throw new Error(`Could not unlock ${unlockName}: ${message}`);
|
||||
},
|
||||
levelUpgrade: (ctx) => (_upgradeName) => {
|
||||
checkAccess(ctx);
|
||||
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
||||
if (!checkEnum(CorpUpgradeName, upgradeName)) throw new Error(`No upgrade named '${upgradeName}'`);
|
||||
const upgradeName = getEnumHelper("CorpUpgradeName").nsGetMember(ctx, _upgradeName, "upgradeName");
|
||||
const corporation = getCorporation();
|
||||
const message = corporation.purchaseUpgrade(upgradeName, 1);
|
||||
if (message) throw new Error(`Could not upgrade ${upgradeName}: ${message}`);
|
||||
@@ -794,26 +780,22 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
},
|
||||
hasUnlock: (ctx) => (_unlockName) => {
|
||||
checkAccess(ctx);
|
||||
const unlockName = helpers.string(ctx, "upgradeName", _unlockName);
|
||||
if (!checkEnum(CorpUnlockName, unlockName)) throw new Error(`${unlockName} is not a valid unlock name.`);
|
||||
const unlockName = getEnumHelper("CorpUnlockName").nsGetMember(ctx, _unlockName, "unlockName");
|
||||
return hasUnlock(unlockName);
|
||||
},
|
||||
getUnlockCost: (ctx) => (_unlockName) => {
|
||||
checkAccess(ctx);
|
||||
const unlockName = helpers.string(ctx, "upgradeName", _unlockName);
|
||||
if (!checkEnum(CorpUnlockName, unlockName)) throw new Error(`${unlockName} is not a valid unlock name.`);
|
||||
const unlockName = getEnumHelper("CorpUnlockName").nsGetMember(ctx, _unlockName, "unlockName");
|
||||
return getUnlockCost(unlockName);
|
||||
},
|
||||
getUpgradeLevel: (ctx) => (_upgradeName) => {
|
||||
checkAccess(ctx);
|
||||
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
||||
if (!checkEnum(CorpUpgradeName, upgradeName)) throw new Error(`${upgradeName} is not a valid upgrade name.`);
|
||||
const upgradeName = getEnumHelper("CorpUpgradeName").nsGetMember(ctx, _upgradeName, "upgradeName");
|
||||
return getUpgradeLevel(upgradeName);
|
||||
},
|
||||
getUpgradeLevelCost: (ctx) => (_upgradeName) => {
|
||||
checkAccess(ctx);
|
||||
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
||||
if (!checkEnum(CorpUpgradeName, upgradeName)) throw new Error(`${upgradeName} is not a valid upgrade name.`);
|
||||
const upgradeName = getEnumHelper("CorpUpgradeName").nsGetMember(ctx, _upgradeName, "upgradeName");
|
||||
return getUpgradeLevelCost(upgradeName);
|
||||
},
|
||||
getInvestmentOffer: (ctx) => () => {
|
||||
|
||||
@@ -26,7 +26,15 @@ import {
|
||||
calculateGrowTime,
|
||||
calculateWeakenTime,
|
||||
} from "../Hacking";
|
||||
import { CompletedProgramName } from "../Programs/Programs";
|
||||
import {
|
||||
CityName,
|
||||
CompletedProgramName,
|
||||
FactionWorkType,
|
||||
GymType,
|
||||
JobName,
|
||||
LocationName,
|
||||
UniversityClassType,
|
||||
} from "@enums";
|
||||
import { Formulas as IFormulas, Player as IPlayer, Person as IPerson } from "@nsdefs";
|
||||
import {
|
||||
calculateRespectGain,
|
||||
@@ -45,11 +53,10 @@ import { calculateCompanyWorkStats } from "../Work/Formulas";
|
||||
import { Companies } from "../Company/Companies";
|
||||
import { calculateClassEarnings } from "../Work/Formulas";
|
||||
import { calculateFactionExp, calculateFactionRep } from "../Work/Formulas";
|
||||
import { FactionWorkType, GymType, UniversityClassType, LocationName, CityName } from "../Enums";
|
||||
|
||||
import { defaultMultipliers } from "../PersonObjects/Multipliers";
|
||||
import { checkEnum, findEnumMember } from "../utils/helpers/enum";
|
||||
import { JobName } from "../Enums";
|
||||
import { findEnumMember } from "../utils/helpers/enum";
|
||||
import { getEnumHelper } from "../utils/EnumHelper";
|
||||
import { CompanyPositions } from "../Company/CompanyPositions";
|
||||
import { findCrime } from "../Crime/CrimeHelpers";
|
||||
|
||||
@@ -384,8 +391,7 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
const person = helpers.person(ctx, _person);
|
||||
const classType = findEnumMember(GymType, helpers.string(ctx, "classType", _classType));
|
||||
if (!classType) throw new Error(`Invalid gym training type: ${_classType}`);
|
||||
const locationName = helpers.string(ctx, "locationName", _locationName);
|
||||
if (!checkEnum(LocationName, locationName)) throw new Error(`Invalid location name: ${locationName}`);
|
||||
const locationName = getEnumHelper("LocationName").nsGetMember(ctx, _locationName);
|
||||
return calculateClassEarnings(person, classType, locationName);
|
||||
},
|
||||
universityGains: (ctx) => (_person, _classType, _locationName) => {
|
||||
@@ -393,8 +399,7 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
const person = helpers.person(ctx, _person);
|
||||
const classType = findEnumMember(UniversityClassType, helpers.string(ctx, "classType", _classType));
|
||||
if (!classType) throw new Error(`Invalid university class type: ${_classType}`);
|
||||
const locationName = helpers.string(ctx, "locationName", _locationName);
|
||||
if (!checkEnum(LocationName, locationName)) throw new Error(`Invalid location name: ${locationName}`);
|
||||
const locationName = getEnumHelper("LocationName").nsGetMember(ctx, _locationName);
|
||||
return calculateClassEarnings(person, classType, locationName);
|
||||
},
|
||||
factionGains: (ctx) => (_player, _workType, _favor) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FactionNames } from "../Faction/data/FactionNames";
|
||||
import { FactionName } from "@enums";
|
||||
import { GangConstants } from "../Gang/data/Constants";
|
||||
import { Player } from "@player";
|
||||
import { Gang } from "../Gang/Gang";
|
||||
@@ -43,7 +43,7 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
if (Player.gang) return false;
|
||||
if (!Player.factions.includes(faction)) return false;
|
||||
|
||||
const isHacking = faction === FactionNames.NiteSec || faction === FactionNames.TheBlackHand;
|
||||
const isHacking = faction === FactionName.NiteSec || faction === FactionName.TheBlackHand;
|
||||
Player.startGang(faction, isHacking);
|
||||
return true;
|
||||
},
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
import type { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
import { StaticAugmentations } from "../Augmentation/StaticAugmentations";
|
||||
import { hasAugmentationPrereqs } from "../Faction/FactionHelpers";
|
||||
import { CityName } from "../Enums";
|
||||
import { CityName } from "@enums";
|
||||
import { GraftableAugmentation } from "../PersonObjects/Grafting/GraftableAugmentation";
|
||||
import { getGraftingAvailableAugs, calculateGraftingTimeWithBonus } from "../PersonObjects/Grafting/GraftingHelpers";
|
||||
import { Player as player } from "../Player";
|
||||
import { Player } from "@player";
|
||||
import { Grafting as IGrafting } from "@nsdefs";
|
||||
import { Router } from "../ui/GameRoot";
|
||||
import { Page } from "../ui/Router";
|
||||
@@ -14,7 +14,7 @@ import { augmentationExists } from "../Augmentation/AugmentationHelpers";
|
||||
|
||||
export function NetscriptGrafting(): InternalAPI<IGrafting> {
|
||||
const checkGraftingAPIAccess = (ctx: NetscriptContext): void => {
|
||||
if (!player.canAccessGrafting()) {
|
||||
if (!Player.canAccessGrafting()) {
|
||||
throw helpers.makeRuntimeErrorMsg(
|
||||
ctx,
|
||||
"You do not currently have access to the Grafting API. This is either because you are not in BitNode 10 or because you do not have Source-File 10",
|
||||
@@ -58,7 +58,7 @@ export function NetscriptGrafting(): InternalAPI<IGrafting> {
|
||||
const augName = helpers.string(ctx, "augName", _augName);
|
||||
const focus = !!_focus;
|
||||
checkGraftingAPIAccess(ctx);
|
||||
if (player.city !== CityName.NewTokyo) {
|
||||
if (Player.city !== CityName.NewTokyo) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, "You must be in New Tokyo to begin grafting an Augmentation.");
|
||||
}
|
||||
if (!isValidGraftingAugName(augName)) {
|
||||
@@ -66,10 +66,10 @@ export function NetscriptGrafting(): InternalAPI<IGrafting> {
|
||||
return false;
|
||||
}
|
||||
|
||||
const wasFocusing = player.focus;
|
||||
const wasFocusing = Player.focus;
|
||||
|
||||
const craftableAug = new GraftableAugmentation(StaticAugmentations[augName]);
|
||||
if (player.money < craftableAug.cost) {
|
||||
if (Player.money < craftableAug.cost) {
|
||||
helpers.log(ctx, () => `You don't have enough money to craft ${augName}`);
|
||||
return false;
|
||||
}
|
||||
@@ -79,7 +79,7 @@ export function NetscriptGrafting(): InternalAPI<IGrafting> {
|
||||
return false;
|
||||
}
|
||||
|
||||
player.startWork(
|
||||
Player.startWork(
|
||||
new GraftingWork({
|
||||
singularity: true,
|
||||
augmentation: augName,
|
||||
@@ -87,10 +87,10 @@ export function NetscriptGrafting(): InternalAPI<IGrafting> {
|
||||
);
|
||||
|
||||
if (focus) {
|
||||
player.startFocusing();
|
||||
Player.startFocusing();
|
||||
Router.toPage(Page.Work);
|
||||
} else if (wasFocusing) {
|
||||
player.stopFocusing();
|
||||
Player.stopFocusing();
|
||||
Router.toPage(Page.Terminal);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Infiltration as IInfiltration, InfiltrationLocation } from "@nsdefs";
|
||||
import type { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
import { Infiltration as NetscriptInfiltation, InfiltrationLocation } from "@nsdefs";
|
||||
import { FactionName, LocationName } from "@enums";
|
||||
import { Location } from "../Locations/Location";
|
||||
import { Locations } from "../Locations/Locations";
|
||||
import { calculateDifficulty, calculateReward } from "../Infiltration/formulas/game";
|
||||
@@ -7,21 +9,17 @@ import {
|
||||
calculateSellInformationCashReward,
|
||||
calculateTradeInformationRepReward,
|
||||
} from "../Infiltration/formulas/victory";
|
||||
import { FactionNames } from "../Faction/data/FactionNames";
|
||||
import { Factions } from "../Faction/Factions";
|
||||
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
import { checkEnum } from "../utils/helpers/enum";
|
||||
import { LocationName } from "../Enums";
|
||||
import { getEnumHelper } from "../utils/EnumHelper";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { filterTruthy } from "../utils/helpers/ArrayHelpers";
|
||||
|
||||
export function NetscriptInfiltration(): InternalAPI<IInfiltration> {
|
||||
export function NetscriptInfiltration(): InternalAPI<NetscriptInfiltation> {
|
||||
const getLocationsWithInfiltrations = Object.values(Locations).filter(
|
||||
(location: Location) => location.infiltrationData,
|
||||
);
|
||||
|
||||
const calculateInfiltrationData = (ctx: NetscriptContext, locationName: string): InfiltrationLocation => {
|
||||
if (!checkEnum(LocationName, locationName)) throw new Error(`Location '${locationName}' does not exists.`);
|
||||
const calculateInfiltrationData = (ctx: NetscriptContext, locationName: LocationName): InfiltrationLocation => {
|
||||
const location = Locations[locationName];
|
||||
if (location === undefined) throw helpers.makeRuntimeErrorMsg(ctx, `Location '${location}' does not exists.`);
|
||||
if (location.infiltrationData === undefined)
|
||||
@@ -35,7 +33,7 @@ export function NetscriptInfiltration(): InternalAPI<IInfiltration> {
|
||||
reward: {
|
||||
tradeRep: calculateTradeInformationRepReward(reward, maxLevel, startingSecurityLevel),
|
||||
sellCash: calculateSellInformationCashReward(reward, maxLevel, startingSecurityLevel),
|
||||
SoARep: calculateInfiltratorsRepReward(Factions[FactionNames.ShadowsOfAnarchy], startingSecurityLevel),
|
||||
SoARep: calculateInfiltratorsRepReward(Factions[FactionName.ShadowsOfAnarchy], startingSecurityLevel),
|
||||
},
|
||||
difficulty: difficulty,
|
||||
};
|
||||
@@ -52,9 +50,9 @@ export function NetscriptInfiltration(): InternalAPI<IInfiltration> {
|
||||
}),
|
||||
);
|
||||
},
|
||||
getInfiltration: (ctx) => (_location) => {
|
||||
const location = helpers.string(ctx, "location", _location);
|
||||
return calculateInfiltrationData(ctx, location);
|
||||
getInfiltration: (ctx) => (_locationName) => {
|
||||
const locationName = getEnumHelper("LocationName").nsGetMember(ctx, _locationName);
|
||||
return calculateInfiltrationData(ctx, locationName);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,20 +1,29 @@
|
||||
import type { Singularity as ISingularity } from "@nsdefs";
|
||||
import type { Augmentation } from "../Augmentation/Augmentation";
|
||||
import type { Company } from "../Company/Company";
|
||||
import type { Faction } from "../Faction/Faction";
|
||||
|
||||
import { Player } from "@player";
|
||||
import {
|
||||
AugmentationName,
|
||||
BlackOperationName,
|
||||
CityName,
|
||||
FactionName,
|
||||
FactionWorkType,
|
||||
GymType,
|
||||
LocationName,
|
||||
UniversityClassType,
|
||||
} from "@enums";
|
||||
import { purchaseAugmentation, joinFaction, getFactionAugmentationsFiltered } from "../Faction/FactionHelpers";
|
||||
import { startWorkerScript } from "../NetscriptWorker";
|
||||
import { Augmentation } from "../Augmentation/Augmentation";
|
||||
import { StaticAugmentations } from "../Augmentation/StaticAugmentations";
|
||||
import { augmentationExists, installAugmentations } from "../Augmentation/AugmentationHelpers";
|
||||
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
|
||||
import { CONSTANTS } from "../Constants";
|
||||
import { RunningScript } from "../Script/RunningScript";
|
||||
import { calculateAchievements } from "../Achievements/Achievements";
|
||||
|
||||
import { Singularity as ISingularity } from "@nsdefs";
|
||||
|
||||
import { findCrime } from "../Crime/CrimeHelpers";
|
||||
import { CompanyPositions } from "../Company/CompanyPositions";
|
||||
import { DarkWebItems } from "../DarkWeb/DarkWebItems";
|
||||
import { CityName, LocationName, JobName } from "../Enums";
|
||||
import { Router } from "../ui/GameRoot";
|
||||
import { SpecialServers } from "../Server/data/SpecialServers";
|
||||
import { Page } from "../ui/Router";
|
||||
@@ -23,11 +32,9 @@ import { GetServer } from "../Server/AllServers";
|
||||
import { Programs } from "../Programs/Programs";
|
||||
import { formatMoney, formatRam, formatReputation } from "../ui/formatNumber";
|
||||
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
||||
import { Company } from "../Company/Company";
|
||||
import { Companies } from "../Company/Companies";
|
||||
import { companiesMetadata } from "../Company/data/CompaniesMetadata";
|
||||
import { Factions, factionExists } from "../Faction/Factions";
|
||||
import { Faction } from "../Faction/Faction";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions";
|
||||
import { getServerOnNetwork } from "../Server/ServerHelpers";
|
||||
@@ -37,20 +44,17 @@ import { Server } from "../Server/Server";
|
||||
import { netscriptCanHack } from "../Hacking/netscriptCanHack";
|
||||
import { FactionInfos } from "../Faction/FactionInfo";
|
||||
import { InternalAPI, NetscriptContext, removedFunction } from "../Netscript/APIWrapper";
|
||||
import { BlackOperationNames } from "../Bladeburner/data/BlackOperationNames";
|
||||
import { enterBitNode } from "../RedPill";
|
||||
import { FactionNames } from "../Faction/data/FactionNames";
|
||||
import { ClassWork } from "../Work/ClassWork";
|
||||
import { CreateProgramWork, isCreateProgramWork } from "../Work/CreateProgramWork";
|
||||
import { FactionWork } from "../Work/FactionWork";
|
||||
import { FactionWorkType, GymType, UniversityClassType } from "../Enums";
|
||||
import { CompanyWork } from "../Work/CompanyWork";
|
||||
import { canGetBonus, onExport } from "../ExportBonus";
|
||||
import { saveObject } from "../SaveObject";
|
||||
import { calculateCrimeWorkStats } from "../Work/Formulas";
|
||||
import { findEnumMember } from "../utils/helpers/enum";
|
||||
import { Engine } from "../engine";
|
||||
import { checkEnum } from "../utils/helpers/enum";
|
||||
import { getEnumHelper } from "../utils/EnumHelper";
|
||||
import { ScriptFilePath, resolveScriptFilePath } from "../Paths/ScriptFilePath";
|
||||
import { root } from "../Paths/Directory";
|
||||
|
||||
@@ -170,7 +174,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
return false;
|
||||
}
|
||||
|
||||
const isNeuroflux = aug.name === AugmentationNames.NeuroFluxGovernor;
|
||||
const isNeuroflux = aug.name === AugmentationName.NeuroFluxGovernor;
|
||||
if (!isNeuroflux) {
|
||||
for (let j = 0; j < Player.queuedAugmentations.length; ++j) {
|
||||
if (Player.queuedAugmentations[j].name === aug.name) {
|
||||
@@ -405,7 +409,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
|
||||
travelToCity: (ctx) => (_cityName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const cityName = helpers.city(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
|
||||
switch (cityName) {
|
||||
case CityName.Aevum:
|
||||
@@ -698,18 +702,13 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
getCompanyPositionInfo: (ctx) => (_companyName, _positionName) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
const companyName = helpers.string(ctx, "companyName", _companyName);
|
||||
const positionName = helpers.string(ctx, "positionName", _positionName);
|
||||
const positionName = getEnumHelper("JobName").nsGetMember(ctx, _positionName, "positionName");
|
||||
|
||||
// Make sure its a valid company
|
||||
if (!(companyName in Companies)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid company: '${companyName}'`);
|
||||
}
|
||||
|
||||
// Make sure its a valid position
|
||||
if (!checkEnum(JobName, positionName)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid position: '${positionName}'`);
|
||||
}
|
||||
|
||||
if (!Companies[companyName].hasPosition(positionName)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Company '${companyName}' does not have position '${positionName}'`);
|
||||
}
|
||||
@@ -1025,7 +1024,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
helpers.log(ctx, () => `You can't donate to '${facName}' because youre managing a gang for it`);
|
||||
return false;
|
||||
}
|
||||
if (faction.name === FactionNames.ChurchOfTheMachineGod || faction.name === FactionNames.Bladeburners) {
|
||||
if (faction.name === FactionName.ChurchOfTheMachineGod || faction.name === FactionName.Bladeburners) {
|
||||
helpers.log(ctx, () => `You can't donate to '${facName}' because they do not accept donations`);
|
||||
return false;
|
||||
}
|
||||
@@ -1228,7 +1227,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
};
|
||||
const bladeburnerRequirements = () => {
|
||||
if (!Player.bladeburner) return false;
|
||||
return Player.bladeburner.blackops[BlackOperationNames.OperationDaedalus];
|
||||
return Player.bladeburner.blackops[BlackOperationName.OperationDaedalus];
|
||||
};
|
||||
|
||||
if (!hackingRequirements() && !bladeburnerRequirements()) {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { Player } from "@player";
|
||||
import type { Sleeve as NetscriptSleeve } from "@nsdefs";
|
||||
import { StaticAugmentations } from "../Augmentation/StaticAugmentations";
|
||||
import { CityName } from "../Enums";
|
||||
import { findCrime } from "../Crime/CrimeHelpers";
|
||||
import { Augmentation } from "../Augmentation/Augmentation";
|
||||
|
||||
import { Sleeve } from "@nsdefs";
|
||||
import { checkEnum } from "../utils/helpers/enum";
|
||||
import { getEnumHelper } from "../utils/EnumHelper";
|
||||
import { InternalAPI, NetscriptContext, removedFunction } from "../Netscript/APIWrapper";
|
||||
import { isSleeveBladeburnerWork } from "../PersonObjects/Sleeve/Work/SleeveBladeburnerWork";
|
||||
import { isSleeveFactionWork } from "../PersonObjects/Sleeve/Work/SleeveFactionWork";
|
||||
@@ -13,7 +12,7 @@ import { isSleeveCompanyWork } from "../PersonObjects/Sleeve/Work/SleeveCompanyW
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { cloneDeep } from "lodash";
|
||||
|
||||
export function NetscriptSleeve(): InternalAPI<Sleeve> {
|
||||
export function NetscriptSleeve(): InternalAPI<NetscriptSleeve> {
|
||||
const checkSleeveAPIAccess = function (ctx: NetscriptContext) {
|
||||
if (Player.bitNodeN !== 10 && !Player.sourceFileLvl(10)) {
|
||||
throw helpers.makeRuntimeErrorMsg(
|
||||
@@ -31,7 +30,7 @@ export function NetscriptSleeve(): InternalAPI<Sleeve> {
|
||||
}
|
||||
};
|
||||
|
||||
const sleeveFunctions: InternalAPI<Sleeve> = {
|
||||
const sleeveFunctions: InternalAPI<NetscriptSleeve> = {
|
||||
getNumSleeves: (ctx) => () => {
|
||||
checkSleeveAPIAccess(ctx);
|
||||
return Player.sleeves.length;
|
||||
@@ -73,14 +72,10 @@ export function NetscriptSleeve(): InternalAPI<Sleeve> {
|
||||
},
|
||||
travel: (ctx) => (_sleeveNumber, _cityName) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
const cityName = helpers.string(ctx, "cityName", _cityName);
|
||||
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
||||
checkSleeveAPIAccess(ctx);
|
||||
checkSleeveNumber(ctx, sleeveNumber);
|
||||
if (checkEnum(CityName, cityName)) {
|
||||
return Player.sleeves[sleeveNumber].travel(cityName);
|
||||
} else {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid city name: '${cityName}'.`);
|
||||
}
|
||||
return Player.sleeves[sleeveNumber].travel(cityName);
|
||||
},
|
||||
setToCompanyWork: (ctx) => (_sleeveNumber, acompanyName) => {
|
||||
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
import { Player as player } from "../Player";
|
||||
import { Player } from "@player";
|
||||
import { AugmentationName, FactionName } from "@enums";
|
||||
|
||||
import { staneksGift } from "../CotMG/Helper";
|
||||
import { Fragments, FragmentById } from "../CotMG/Fragment";
|
||||
import { FragmentType } from "../CotMG/FragmentType";
|
||||
|
||||
import { Stanek as IStanek } from "@nsdefs";
|
||||
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
|
||||
import { NetscriptContext, InternalAPI } from "../Netscript/APIWrapper";
|
||||
import { applyAugmentation } from "../Augmentation/AugmentationHelpers";
|
||||
import { FactionNames } from "../Faction/data/FactionNames";
|
||||
import { joinFaction } from "../Faction/FactionHelpers";
|
||||
import { Factions } from "../Faction/Factions";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
|
||||
export function NetscriptStanek(): InternalAPI<IStanek> {
|
||||
function checkStanekAPIAccess(ctx: NetscriptContext): void {
|
||||
if (!player.hasAugmentation(AugmentationNames.StaneksGift1, true)) {
|
||||
if (!Player.hasAugmentation(AugmentationName.StaneksGift1, true)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, "Stanek's Gift is not installed");
|
||||
}
|
||||
}
|
||||
@@ -108,28 +107,28 @@ export function NetscriptStanek(): InternalAPI<IStanek> {
|
||||
acceptGift: (ctx) => () => {
|
||||
//Check if the player is eligible to join the church
|
||||
if (
|
||||
player.canAccessCotMG() &&
|
||||
player.augmentations.filter((a) => a.name !== AugmentationNames.NeuroFluxGovernor).length == 0 &&
|
||||
player.queuedAugmentations.filter((a) => a.name !== AugmentationNames.NeuroFluxGovernor).length == 0
|
||||
Player.canAccessCotMG() &&
|
||||
Player.augmentations.filter((a) => a.name !== AugmentationName.NeuroFluxGovernor).length == 0 &&
|
||||
Player.queuedAugmentations.filter((a) => a.name !== AugmentationName.NeuroFluxGovernor).length == 0
|
||||
) {
|
||||
//Attempt to join CotMG
|
||||
joinFaction(Factions[FactionNames.ChurchOfTheMachineGod]);
|
||||
joinFaction(Factions[FactionName.ChurchOfTheMachineGod]);
|
||||
//Attempt to install the first Stanek aug
|
||||
if (
|
||||
!player.hasAugmentation(AugmentationNames.StaneksGift1) &&
|
||||
!player.queuedAugmentations.some((a) => a.name === AugmentationNames.StaneksGift1)
|
||||
!Player.hasAugmentation(AugmentationName.StaneksGift1) &&
|
||||
!Player.queuedAugmentations.some((a) => a.name === AugmentationName.StaneksGift1)
|
||||
) {
|
||||
applyAugmentation({ name: AugmentationNames.StaneksGift1, level: 1 });
|
||||
applyAugmentation({ name: AugmentationName.StaneksGift1, level: 1 });
|
||||
helpers.log(
|
||||
ctx,
|
||||
() => `'${FactionNames.ChurchOfTheMachineGod}' joined and '${AugmentationNames.StaneksGift1}' installed.`,
|
||||
() => `'${FactionName.ChurchOfTheMachineGod}' joined and '${AugmentationName.StaneksGift1}' installed.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
//Return true iff the player is in CotMG and has the first Stanek aug installed
|
||||
return (
|
||||
Factions[FactionNames.ChurchOfTheMachineGod].isMember &&
|
||||
player.hasAugmentation(AugmentationNames.StaneksGift1, true)
|
||||
Factions[FactionName.ChurchOfTheMachineGod].isMember &&
|
||||
Player.hasAugmentation(AugmentationName.StaneksGift1, true)
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -2,9 +2,7 @@ import { Player as player } from "../Player";
|
||||
import { buyStock, sellStock, shortStock, sellShort } from "../StockMarket/BuyingAndSelling";
|
||||
import { StockMarket, SymbolToStockMap, placeOrder, cancelOrder, initStockMarket } from "../StockMarket/StockMarket";
|
||||
import { getBuyTransactionCost, getSellTransactionGain } from "../StockMarket/StockMarketHelpers";
|
||||
import { OrderTypes } from "../StockMarket/data/OrderTypes";
|
||||
import { PositionTypes } from "../StockMarket/data/PositionTypes";
|
||||
import { StockSymbols } from "../StockMarket/data/StockSymbols";
|
||||
import { PositionType, OrderType, StockSymbol } from "@enums";
|
||||
import {
|
||||
getStockMarket4SDataCost,
|
||||
getStockMarket4STixApiCost,
|
||||
@@ -51,7 +49,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
},
|
||||
getSymbols: (ctx) => () => {
|
||||
checkTixApiAccess(ctx);
|
||||
return Object.values(StockSymbols);
|
||||
return Object.values(StockSymbol);
|
||||
},
|
||||
getPrice: (ctx) => (_symbol) => {
|
||||
const symbol = helpers.string(ctx, "symbol", _symbol);
|
||||
@@ -108,9 +106,9 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
let pos;
|
||||
const sanitizedPosType = posType.toLowerCase();
|
||||
if (sanitizedPosType.includes("l")) {
|
||||
pos = PositionTypes.Long;
|
||||
pos = PositionType.Long;
|
||||
} else if (sanitizedPosType.includes("s")) {
|
||||
pos = PositionTypes.Short;
|
||||
pos = PositionType.Short;
|
||||
} else {
|
||||
return Infinity;
|
||||
}
|
||||
@@ -133,9 +131,9 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
let pos;
|
||||
const sanitizedPosType = posType.toLowerCase();
|
||||
if (sanitizedPosType.includes("l")) {
|
||||
pos = PositionTypes.Long;
|
||||
pos = PositionType.Long;
|
||||
} else if (sanitizedPosType.includes("s")) {
|
||||
pos = PositionTypes.Short;
|
||||
pos = PositionType.Short;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
@@ -219,22 +217,22 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
let orderPos;
|
||||
const ltype = type.toLowerCase();
|
||||
if (ltype.includes("limit") && ltype.includes("buy")) {
|
||||
orderType = OrderTypes.LimitBuy;
|
||||
orderType = OrderType.LimitBuy;
|
||||
} else if (ltype.includes("limit") && ltype.includes("sell")) {
|
||||
orderType = OrderTypes.LimitSell;
|
||||
orderType = OrderType.LimitSell;
|
||||
} else if (ltype.includes("stop") && ltype.includes("buy")) {
|
||||
orderType = OrderTypes.StopBuy;
|
||||
orderType = OrderType.StopBuy;
|
||||
} else if (ltype.includes("stop") && ltype.includes("sell")) {
|
||||
orderType = OrderTypes.StopSell;
|
||||
orderType = OrderType.StopSell;
|
||||
} else {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid order type: ${type}`);
|
||||
}
|
||||
|
||||
const lpos = pos.toLowerCase();
|
||||
if (lpos.includes("l")) {
|
||||
orderPos = PositionTypes.Long;
|
||||
orderPos = PositionType.Long;
|
||||
} else if (lpos.includes("s")) {
|
||||
orderPos = PositionTypes.Short;
|
||||
orderPos = PositionType.Short;
|
||||
} else {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid position type: ${pos}`);
|
||||
}
|
||||
@@ -267,22 +265,22 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
let orderPos;
|
||||
const ltype = type.toLowerCase();
|
||||
if (ltype.includes("limit") && ltype.includes("buy")) {
|
||||
orderType = OrderTypes.LimitBuy;
|
||||
orderType = OrderType.LimitBuy;
|
||||
} else if (ltype.includes("limit") && ltype.includes("sell")) {
|
||||
orderType = OrderTypes.LimitSell;
|
||||
orderType = OrderType.LimitSell;
|
||||
} else if (ltype.includes("stop") && ltype.includes("buy")) {
|
||||
orderType = OrderTypes.StopBuy;
|
||||
orderType = OrderType.StopBuy;
|
||||
} else if (ltype.includes("stop") && ltype.includes("sell")) {
|
||||
orderType = OrderTypes.StopSell;
|
||||
orderType = OrderType.StopSell;
|
||||
} else {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid order type: ${type}`);
|
||||
}
|
||||
|
||||
const lpos = pos.toLowerCase();
|
||||
if (lpos.includes("l")) {
|
||||
orderPos = PositionTypes.Long;
|
||||
orderPos = PositionType.Long;
|
||||
} else if (lpos.includes("s")) {
|
||||
orderPos = PositionTypes.Short;
|
||||
orderPos = PositionType.Short;
|
||||
} else {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid position type: ${pos}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user