VARIOUS: Various changes prior to release 2.2 (#271)

See PR #271 description
This commit is contained in:
Snarling
2022-12-29 20:28:53 -05:00
committed by GitHub
parent 24ad342203
commit fb1f95c26e
310 changed files with 3768 additions and 2583 deletions
+15 -29
View File
@@ -1,11 +1,13 @@
import { Player } from "@player";
import { Bladeburner } from "../Bladeburner/Bladeburner";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { Bladeburner as INetscriptBladeburner } from "../ScriptEditor/NetscriptDefinitions";
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";
export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
const checkBladeburnerAccess = function (ctx: NetscriptContext): void {
@@ -23,14 +25,6 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
return bladeburner;
};
const checkBladeburnerCity = function (ctx: NetscriptContext, city: string): void {
const bladeburner = Player.bladeburner;
if (bladeburner === null) throw new Error("Must have joined bladeburner");
if (!bladeburner.cities.hasOwnProperty(city)) {
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid city: ${city}`);
}
};
const getBladeburnerActionObject = function (ctx: NetscriptContext, type: string, name: string): Action {
const bladeburner = Player.bladeburner;
if (bladeburner === null) throw new Error("Must have joined bladeburner");
@@ -227,9 +221,9 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
getSkillUpgradeCost:
(ctx) =>
(_skillName, _count = 1) => {
const bladeburner = getBladeburner(ctx);
const skillName = helpers.string(ctx, "skillName", _skillName);
const count = helpers.number(ctx, "count", _count);
const bladeburner = getBladeburner(ctx);
try {
return bladeburner.getSkillUpgradeCostNetscriptFn(skillName, count, ctx.workerScript);
} catch (e: unknown) {
@@ -239,9 +233,9 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
upgradeSkill:
(ctx) =>
(_skillName, _count = 1) => {
const bladeburner = getBladeburner(ctx);
const skillName = helpers.string(ctx, "skillName", _skillName);
const count = helpers.number(ctx, "count", _count);
const bladeburner = getBladeburner(ctx);
try {
return bladeburner.upgradeSkillNetscriptFn(skillName, count, ctx.workerScript);
} catch (e: unknown) {
@@ -249,9 +243,9 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
}
},
getTeamSize: (ctx) => (_type, _name) => {
const bladeburner = getBladeburner(ctx);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
const bladeburner = getBladeburner(ctx);
try {
return bladeburner.getTeamSizeNetscriptFn(type, name, ctx.workerScript);
} catch (e: unknown) {
@@ -259,10 +253,10 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
}
},
setTeamSize: (ctx) => (_type, _name, _size) => {
const bladeburner = getBladeburner(ctx);
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
const size = helpers.number(ctx, "size", _size);
const bladeburner = getBladeburner(ctx);
try {
return bladeburner.setTeamSizeNetscriptFn(type, name, size, ctx.workerScript);
} catch (e: unknown) {
@@ -270,27 +264,21 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
}
},
getCityEstimatedPopulation: (ctx) => (_cityName) => {
const bladeburner = getBladeburner(ctx);
const cityName = helpers.string(ctx, "cityName", _cityName);
checkBladeburnerAccess(ctx);
checkBladeburnerCity(ctx, cityName);
const bladeburner = Player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city: ${cityName}`);
return bladeburner.cities[cityName].popEst;
},
getCityCommunities: (ctx) => (_cityName) => {
const bladeburner = getBladeburner(ctx);
const cityName = helpers.string(ctx, "cityName", _cityName);
checkBladeburnerAccess(ctx);
checkBladeburnerCity(ctx, cityName);
const bladeburner = Player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city: ${cityName}`);
return bladeburner.cities[cityName].comms;
},
getCityChaos: (ctx) => (_cityName) => {
const bladeburner = getBladeburner(ctx);
const cityName = helpers.string(ctx, "cityName", _cityName);
checkBladeburnerAccess(ctx);
checkBladeburnerCity(ctx, cityName);
const bladeburner = Player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city: ${cityName}`);
return bladeburner.cities[cityName].chaos;
},
getCity: (ctx) => () => {
@@ -298,11 +286,9 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
return bladeburner.city;
},
switchCity: (ctx) => (_cityName) => {
const bladeburner = getBladeburner(ctx);
const cityName = helpers.string(ctx, "cityName", _cityName);
checkBladeburnerAccess(ctx);
checkBladeburnerCity(ctx, cityName);
const bladeburner = Player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city: ${cityName}`);
bladeburner.city = cityName;
return true;
},
+3 -3
View File
@@ -1,6 +1,6 @@
import { Player as player } from "../Player";
import { Player } from "@player";
import { CodingContract } from "../CodingContracts";
import { CodingContract as ICodingContract } from "../ScriptEditor/NetscriptDefinitions";
import { CodingContract as ICodingContract } from "@nsdefs";
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
import { helpers } from "../Netscript/NetscriptHelpers";
import { codingContractTypesMetadata } from "../data/codingcontracttypes";
@@ -33,7 +33,7 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
const serv = helpers.getServer(ctx, hostname);
if (contract.isSolution(answerStr)) {
const reward = player.gainCodingContractReward(creward, contract.getDifficulty());
const reward = Player.gainCodingContractReward(creward, contract.getDifficulty());
helpers.log(ctx, () => `Successfully completed Coding Contract '${filename}'. Reward: ${reward}`);
serv.removeContract(filename);
return reward;
+103 -148
View File
@@ -6,17 +6,17 @@ import { Material } from "../Corporation/Material";
import { Warehouse } from "../Corporation/Warehouse";
import { Industry } from "../Corporation/Industry";
import { Corporation } from "../Corporation/Corporation";
import { cloneDeep, omit } from "lodash";
import {
productInfo as NSProduct,
materialInfo as NSMaterial,
divisionInfo as NSDivisionInfo,
Corporation as NSCorporation,
Division as NSDivision,
WarehouseAPI,
OfficeAPI,
InvestmentOffer,
} from "../ScriptEditor/NetscriptDefinitions";
CorpResearchName,
CorpMaterialName,
} from "@nsdefs";
import {
NewIndustry,
@@ -54,16 +54,16 @@ import {
} from "../Corporation/Actions";
import { CorporationUnlockUpgrades } from "../Corporation/data/CorporationUnlockUpgrades";
import { CorporationUpgrades } from "../Corporation/data/CorporationUpgrades";
import { EmployeePositions } from "../Corporation/EmployeePositions";
import { IndustriesData, IndustryResearchTrees, IndustryType } from "../Corporation/IndustryData";
import { CorporationConstants } from "../Corporation/data/Constants";
import { EmployeePositions, IndustryType } from "../Corporation/data/Enums";
import { IndustriesData, IndustryResearchTrees } from "../Corporation/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 } from "../Netscript/APIWrapper";
import { assertEnumMember, helpers } from "../Netscript/NetscriptHelpers";
import { InternalAPI, NetscriptContext, removedFunction } from "../Netscript/APIWrapper";
import { assertMember, helpers } from "../Netscript/NetscriptHelpers";
import { checkEnum } from "../utils/helpers/enum";
import { CityName } from "../Locations/data/CityNames";
import { CityName } from "../Enums";
import { MaterialInfo } from "../Corporation/MaterialInfo";
export function NetscriptCorporation(): InternalAPI<NSCorporation> {
@@ -123,8 +123,8 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
function getInvestmentOffer(): InvestmentOffer {
const corporation = getCorporation();
if (
corporation.fundingRound >= CorporationConstants.FundingRoundShares.length ||
corporation.fundingRound >= CorporationConstants.FundingRoundMultiplier.length ||
corporation.fundingRound >= corpConstants.fundingRoundShares.length ||
corporation.fundingRound >= corpConstants.fundingRoundMultiplier.length ||
corporation.public
)
return {
@@ -133,10 +133,10 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
round: corporation.fundingRound + 1, // Make more readable
}; // Don't throw an error here, no reason to have a second function to check if you can get investment.
const val = corporation.valuation;
const percShares = CorporationConstants.FundingRoundShares[corporation.fundingRound];
const roundMultiplier = CorporationConstants.FundingRoundMultiplier[corporation.fundingRound];
const percShares = corpConstants.fundingRoundShares[corporation.fundingRound];
const roundMultiplier = corpConstants.fundingRoundMultiplier[corporation.fundingRound];
const funding = val * percShares * roundMultiplier;
const investShares = Math.floor(CorporationConstants.INITIALSHARES * percShares);
const investShares = Math.floor(corpConstants.initialShares * percShares);
return {
funds: funding,
shares: investShares,
@@ -147,16 +147,16 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
function acceptInvestmentOffer(): boolean {
const corporation = getCorporation();
if (
corporation.fundingRound >= CorporationConstants.FundingRoundShares.length ||
corporation.fundingRound >= CorporationConstants.FundingRoundMultiplier.length ||
corporation.fundingRound >= corpConstants.fundingRoundShares.length ||
corporation.fundingRound >= corpConstants.fundingRoundMultiplier.length ||
corporation.public
)
return false;
const val = corporation.valuation;
const percShares = CorporationConstants.FundingRoundShares[corporation.fundingRound];
const roundMultiplier = CorporationConstants.FundingRoundMultiplier[corporation.fundingRound];
const percShares = corpConstants.fundingRoundShares[corporation.fundingRound];
const roundMultiplier = corpConstants.fundingRoundMultiplier[corporation.fundingRound];
const funding = val * percShares * roundMultiplier;
const investShares = Math.floor(CorporationConstants.INITIALSHARES * percShares);
const investShares = Math.floor(corpConstants.initialShares * percShares);
corporation.fundingRound++;
corporation.addFunds(funding);
corporation.numShares -= investShares;
@@ -177,7 +177,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
return true;
}
function getResearchCost(division: Industry, researchName: string): number {
function getResearchCost(division: Industry, researchName: CorpResearchName): number {
const researchTree = IndustryResearchTrees[division.type];
if (researchTree === undefined) throw new Error(`No research tree for industry '${division.type}'`);
const allResearch = researchTree.getAllNodes();
@@ -186,7 +186,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
return research.cost;
}
function hasResearched(division: Industry, researchName: string): boolean {
function hasResearched(division: Industry, researchName: CorpResearchName): boolean {
return division.researched[researchName] === undefined ? false : (division.researched[researchName] as boolean);
}
@@ -202,7 +202,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
if (!info.offersWork()) return false;
if (player.hasGangWith(factionName)) return false;
const repGain = amountCash / CorporationConstants.BribeToRepRatio;
const repGain = amountCash / corpConstants.bribeAmountPerReputation;
faction.playerReputation += repGain;
corporation.funds = corporation.funds - amountCash;
@@ -238,11 +238,9 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
return warehouse;
}
function getMaterial(divisionName: string, cityName: string, materialName: string): Material {
function getMaterial(divisionName: string, cityName: CityName, materialName: CorpMaterialName): Material {
const warehouse = getWarehouse(divisionName, cityName);
const matName = materialName.replace(/ /g, "");
const material = warehouse.materials[matName];
if (material === undefined) throw new Error(`Invalid material name: '${materialName}'`);
const material = warehouse.materials[materialName];
return material;
}
@@ -262,9 +260,9 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
}
function getSafeDivision(division: Industry): NSDivision {
const cities: string[] = [];
const cities: CityName[] = [];
for (const office of Object.values(division.offices)) {
if (office === 0) continue;
if (!office) continue;
cities.push(office.loc);
}
@@ -274,7 +272,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
awareness: division.awareness,
popularity: division.popularity,
prodMult: division.prodMult,
research: division.sciResearch.qty,
research: division.sciResearch,
lastCycleRevenue: division.lastCycleRevenue,
lastCycleExpenses: division.lastCycleExpenses,
thisCycleRevenue: division.thisCycleRevenue,
@@ -286,58 +284,6 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
};
}
function getDivisionConstants(): Record<string, NSDivisionInfo> {
const divObject: Record<string, NSDivisionInfo> = {};
for (const [ind, type] of Object.entries(IndustryType)) {
divObject[ind] = {
type: type,
cost: IndustriesData[type].startingCost,
requiredMaterials: IndustriesData[type].reqMats,
makesMaterials: IndustriesData[type].prodMats ? true : false,
makesProducts: IndustriesData[type].product ? true : false,
};
if (divObject[ind].makesProducts) {
divObject[ind].productType = IndustriesData[type].product?.name;
}
if (divObject[ind].makesMaterials) {
divObject[ind].producedMaterials = IndustriesData[type].prodMats;
}
}
return divObject;
}
function getProductInfo(): Record<string, NSProduct> {
const prodsObject: Record<string, NSProduct> = {};
for (const [ind, type] of Object.entries(IndustryType)) {
if (typeof IndustriesData[type].product !== "undefined") {
prodsObject[ind] = {
requiredMaterials: Object.keys(IndustriesData[type].reqMats),
size: 0,
division: type,
};
prodsObject[ind].type = IndustriesData[type].product?.name;
let totSize = 0;
for (const mat of prodsObject[ind].requiredMaterials) {
totSize += MaterialInfo[mat][1];
}
prodsObject[ind].size = totSize;
}
}
return prodsObject;
}
function getMaterialInfo(): Record<string, NSMaterial> {
const matsObject: Record<string, NSMaterial> = {};
for (const [mat, info] of Object.entries(MaterialInfo)) {
matsObject[mat] = {
name: info[0],
size: info[1],
prodMult: info[2],
};
}
return matsObject;
}
const warehouseAPI: InternalAPI<WarehouseAPI> = {
getUpgradeWarehouseCost:
(ctx) =>
@@ -357,7 +303,6 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
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;
},
@@ -374,11 +319,11 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
smartSupplyEnabled: warehouse.smartSupplyEnabled,
};
},
getMaterial: (ctx) => (_divisionName, _cityName, _materialName) => {
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);
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
const material = getMaterial(divisionName, cityName, materialName);
const corporation = getCorporation();
const exports = material.exp.map((e) => {
@@ -442,11 +387,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, 7);
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
const cityName = helpers.city(ctx, "cityName", _cityName);
const materialName = helpers.string(ctx, "materialName", _materialName);
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
const amt = helpers.string(ctx, "amt", _amt);
const price = helpers.string(ctx, "price", _price);
const material = getMaterial(divisionName, cityName, materialName);
@@ -481,11 +426,11 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
throw helpers.makeRuntimeErrorMsg(ctx, `You have not purchased the Smart Supply upgrade!`);
SetSmartSupply(warehouse, enabled);
},
setSmartSupplyUseLeftovers: (ctx) => (_divisionName, _cityName, _materialName, _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);
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
const enabled = !!_enabled;
const warehouse = getWarehouse(divisionName, cityName);
const material = getMaterial(divisionName, cityName, materialName);
@@ -493,25 +438,25 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
throw helpers.makeRuntimeErrorMsg(ctx, `You have not purchased the Smart Supply upgrade!`);
SetSmartSupplyUseLeftovers(warehouse, material, enabled);
},
buyMaterial: (ctx) => (_divisionName, _cityName, _materialName, _amt) => {
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);
assertMember(ctx, corpConstants.materialNames, "Material Name", "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, 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);
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
const amt = helpers.number(ctx, "amt", _amt);
const warehouse = getWarehouse(divisionName, cityName);
const material = getMaterial(divisionName, cityName, materialName);
@@ -539,13 +484,13 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
},
exportMaterial:
(ctx) =>
(_sourceDivision, sourceCity, _targetDivision, targetCity, _materialName, _amt): void => {
(_sourceDivision, sourceCity, _targetDivision, targetCity, materialName, _amt): void => {
checkAccess(ctx, 7);
const sourceDivision = helpers.string(ctx, "sourceDivision", _sourceDivision);
assertEnumMember(ctx, CityName, "City", "sourceCity", sourceCity);
assertMember(ctx, CityName, "City", "sourceCity", sourceCity);
const targetDivision = helpers.string(ctx, "targetDivision", _targetDivision);
assertEnumMember(ctx, CityName, "City", "targetCity", targetCity);
const materialName = helpers.string(ctx, "materialName", _materialName);
assertMember(ctx, CityName, "City", "targetCity", targetCity);
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
const amt = helpers.string(ctx, "amt", _amt);
ExportMaterial(
targetDivision,
@@ -557,44 +502,39 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
},
cancelExportMaterial:
(ctx) =>
(_sourceDivision, sourceCity, _targetDivision, targetCity, _materialName, _amt): void => {
(_sourceDivision, sourceCity, _targetDivision, targetCity, materialName, _amt): void => {
checkAccess(ctx, 7);
const sourceDivision = helpers.string(ctx, "sourceDivision", _sourceDivision);
assertEnumMember(ctx, CityName, "City", "sourceCity", sourceCity);
assertMember(ctx, CityName, "City Name", "sourceCity", sourceCity);
const targetDivision = helpers.string(ctx, "targetDivision", _targetDivision);
assertEnumMember(ctx, CityName, "City", "targetCity", targetCity);
const materialName = helpers.string(ctx, "materialName", _materialName);
assertMember(ctx, CityName, "City Name", "targetCity", targetCity);
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
const amt = helpers.string(ctx, "amt", _amt);
CancelExportMaterial(
targetDivision,
targetCity,
getMaterial(sourceDivision, sourceCity, materialName),
amt + "",
);
CancelExportMaterial(targetDivision, targetCity, getMaterial(sourceDivision, sourceCity, materialName), amt);
},
limitMaterialProduction: (ctx) => (_divisionName, _cityName, _materialName, _qty) => {
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);
assertMember(ctx, CityName, "City Name", "cityName", cityName);
assertMember(ctx, corpConstants.materialNames, "Material Name", "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, 7);
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
const cityName = helpers.city(ctx, "cityName", _cityName);
const materialName = helpers.string(ctx, "materialName", _materialName);
assertMember(ctx, CityName, "City Name", "cityName", cityName);
assertMember(ctx, corpConstants.materialNames, "Material Name", "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, 7);
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
const cityName = helpers.city(ctx, "cityName", _cityName);
const materialName = helpers.string(ctx, "materialName", _materialName);
assertMember(ctx, CityName, "City Name", "cityName", cityName);
assertMember(ctx, corpConstants.materialNames, "Material Name", "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}`);
@@ -633,16 +573,16 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
const division = getDivision(divisionName);
return division.numAdVerts;
},
getResearchCost: (ctx) => (_divisionName, _researchName) => {
getResearchCost: (ctx) => (_divisionName, researchName) => {
checkAccess(ctx, 8);
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
const researchName = helpers.string(ctx, "researchName", _researchName);
assertMember(ctx, corpConstants.researchNames, "Research Name", "researchName", researchName);
return getResearchCost(getDivision(divisionName), researchName);
},
hasResearched: (ctx) => (_divisionName, _researchName) => {
hasResearched: (ctx) => (_divisionName, researchName) => {
checkAccess(ctx, 8);
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
const researchName = helpers.string(ctx, "researchName", _researchName);
assertMember(ctx, corpConstants.researchNames, "Research Name", "researchName", researchName);
return hasResearched(getDivision(divisionName), researchName);
},
getOfficeSizeUpgradeCost: (ctx) => (_divisionName, _cityName, _size) => {
@@ -652,13 +592,13 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
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 initialPriceMult = Math.round(office.size / corpConstants.officeInitialSize);
const costMultiplier = 1.09;
let mult = 0;
for (let i = 0; i < size / CorporationConstants.OfficeInitialSize; ++i) {
for (let i = 0; i < size / corpConstants.officeInitialSize; ++i) {
mult += Math.pow(costMultiplier, initialPriceMult + i);
}
return CorporationConstants.OfficeInitialCost * mult;
return corpConstants.officeInitialCost * mult;
},
setAutoJobAssignment: (ctx) => (_divisionName, _cityName, _job, _amount) => {
checkAccess(ctx, 8);
@@ -721,10 +661,10 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
const corporation = getCorporation();
HireAdVert(corporation, getDivision(divisionName));
},
research: (ctx) => (_divisionName, _researchName) => {
research: (ctx) => (_divisionName, researchName) => {
checkAccess(ctx, 8);
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
const researchName = helpers.string(ctx, "researchName", _researchName);
assertMember(ctx, corpConstants.researchNames, "Research Name", "reseatchName", researchName);
Research(getDivision(divisionName), researchName);
},
getOffice: (ctx) => (_divisionName, _cityName) => {
@@ -751,30 +691,31 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
},
};
return {
enums: {
EmployeePositions,
IndustryType,
},
// TODO 2.2: Add removed function error dialogs for all the functions removed/replaced by getConstants.
const corpFunctions: InternalAPI<NSCorporation> = {
...warehouseAPI,
...officeAPI,
hasCorporation: () => () => !!Player.corporation,
getConstants: (ctx) => () => {
checkAccess(ctx);
return {
coffeeCost: 5e8,
states: [...CorporationConstants.AllCorporationStates],
bribeToRepRatio: CorporationConstants.BribeToRepRatio,
cityExpandCost: CorporationConstants.OfficeInitialCost,
warehousePurchaseCost: CorporationConstants.WarehouseInitialCost,
baseMaxProducts: CorporationConstants.BaseMaxProducts,
products: getProductInfo(),
materials: getMaterialInfo(),
unlocks: [...CorporationConstants.AllUnlocks],
upgrades: [...CorporationConstants.AllUpgrades],
researches: { base: [...CorporationConstants.BaseResearch], product: [...CorporationConstants.ProdResearch] },
divisions: getDivisionConstants(),
};
/* TODO 2.2: possibly just rework the whole corp constants structure to be more readable, and just use cloneDeep
* to provide it directly to player.
* TODO 2.2: Roll product information into industriesData, there's no reason to look up a product separately */
return cloneDeep(omit(corpConstants, "fundingRoundShares", "fundingRoundMultiplier", "valuationLength"));
// TODO: add functions for getting materialInfo and research info
},
getIndustryData: (ctx) => (_industryName) => {
checkAccess(ctx);
const industryName = helpers.string(ctx, "industryName", _industryName);
if (!checkEnum(IndustryType, industryName)) {
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid industry: ${industryName}`);
}
return cloneDeep(IndustriesData[industryName]);
},
getMaterialData: (ctx) => (materialName) => {
checkAccess(ctx);
assertMember(ctx, corpConstants.materialNames, "Material Name", "materialName", materialName);
return cloneDeep(MaterialInfo[materialName]);
},
expandIndustry: (ctx) => (_industryName, _divisionName) => {
checkAccess(ctx);
@@ -790,7 +731,6 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
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);
@@ -814,7 +754,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
issueDividends: (ctx) => (_rate) => {
checkAccess(ctx);
const rate = helpers.number(ctx, "rate", _rate);
const max = CorporationConstants.DividendMaxRate;
const max = corpConstants.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();
@@ -858,9 +798,9 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
sharePrice: corporation.sharePrice,
dividendRate: corporation.dividendRate,
dividendTax: corporation.dividendTax,
dividendEarnings: corporation.getCycleDividends() / CorporationConstants.SecsPerMarketCycle,
dividendEarnings: corporation.getCycleDividends() / corpConstants.secondsPerMarketCycle,
state: corporation.state.getState(),
divisions: corporation.divisions.map((division): string => division.name),
divisions: corporation.divisions.map((division) => division.name),
};
},
createCorporation:
@@ -926,4 +866,19 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
return Math.round(getCorporation().storedCycles / 5) * 1000;
},
};
// TODO: More removedFunctions entries for old getter functions replaced by getConstants
Object.assign(corpFunctions, {
assignJob: removedFunction(
"v2.2.0",
"Corporation employees no longer exist as separate objects.\nUse corporation.setAutoJobAssignment instead to assign employees to jobs.",
true,
),
getEmployee: removedFunction(
"v2.2.0",
"Corporation employees no longer exist as separate objects and this function no longer has a use.",
true,
),
getDivisionConstants: removedFunction("v2.2.0", "ns.corporation.getIndustryData"),
});
return corpFunctions;
}
+14 -8
View File
@@ -26,7 +26,7 @@ import {
calculateWeakenTime,
} from "../Hacking";
import { Programs } from "../Programs/Programs";
import { Formulas as IFormulas, Player as IPlayer, Person as IPerson } from "../ScriptEditor/NetscriptDefinitions";
import { Formulas as IFormulas, Player as IPlayer, Person as IPerson } from "@nsdefs";
import {
calculateRespectGain,
calculateWantedLevelGain,
@@ -37,18 +37,18 @@ import {
} from "../Gang/formulas/formulas";
import { favorToRep as calculateFavorToRep, repToFavor as calculateRepToFavor } from "../Faction/formulas/favor";
import { repFromDonation } from "../Faction/formulas/donation";
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
import { InternalAPI, NetscriptContext, removedFunction } from "../Netscript/APIWrapper";
import { helpers } from "../Netscript/NetscriptHelpers";
import { calculateCrimeWorkStats } from "../Work/Formulas";
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 } from "../utils/enums";
import { FactionWorkType, GymType, UniversityClassType, LocationName, CityName } from "../Enums";
import { defaultMultipliers } from "../PersonObjects/Multipliers";
import { checkEnum, findEnumMember } from "../utils/helpers/enum";
import { CompanyPosName } from "../utils/enums";
import { JobName } from "../Enums";
import { CompanyPositions } from "../Company/CompanyPositions";
import { findCrime } from "../Crime/CrimeHelpers";
@@ -58,7 +58,7 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
throw helpers.makeRuntimeErrorMsg(ctx, `Requires Formulas.exe to run.`);
}
};
return {
const formulasFunctions: InternalAPI<IFormulas> = {
mockServer: () => () => ({
cpuCores: 0,
ftpPortOpen: false,
@@ -92,7 +92,7 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
mults: defaultMultipliers(),
numPeopleKilled: 0,
money: 0,
city: "",
city: CityName.Sector12,
location: "",
bitNodeN: 0,
totalPlaytime: 0,
@@ -107,7 +107,7 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
skills: { hacking: 0, strength: 0, defense: 0, dexterity: 0, agility: 0, charisma: 0, intelligence: 0 },
exp: { hacking: 0, strength: 0, defense: 0, dexterity: 0, agility: 0, charisma: 0, intelligence: 0 },
mults: defaultMultipliers(),
city: "",
city: CityName.Sector12,
}),
reputation: {
calculateFavorToRep: (ctx) => (_favor) => {
@@ -397,7 +397,7 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
companyGains: (ctx) => (_person, _companyName, _positionName, _favor) => {
checkFormulasAccess(ctx);
const person = helpers.person(ctx, _person);
const positionName = findEnumMember(CompanyPosName, helpers.string(ctx, "_positionName", _positionName));
const positionName = findEnumMember(JobName, helpers.string(ctx, "_positionName", _positionName));
if (!positionName) throw new Error(`Invalid company position: ${_positionName}`);
const position = CompanyPositions[positionName];
const companyName = helpers.string(ctx, "_companyName", _companyName);
@@ -408,4 +408,10 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
},
},
};
// Removed undocumented functions added using Object.assign because typescript.
// TODO: Remove these at 3.0
Object.assign(formulasFunctions.work, {
classGains: removedFunction("2.2.0", "formulas.work.universityGains or formulas.work.gymGains"),
});
return formulasFunctions;
}
+1 -1
View File
@@ -9,7 +9,7 @@ import { GangMember } from "../Gang/GangMember";
import { GangMemberTask } from "../Gang/GangMemberTask";
import { helpers } from "../Netscript/NetscriptHelpers";
import { Gang as IGang, EquipmentStats, GangOtherInfoObject } from "../ScriptEditor/NetscriptDefinitions";
import { Gang as IGang, EquipmentStats, GangOtherInfoObject } from "@nsdefs";
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
export function NetscriptGang(): InternalAPI<IGang> {
+2 -2
View File
@@ -1,11 +1,11 @@
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
import { StaticAugmentations } from "../Augmentation/StaticAugmentations";
import { hasAugmentationPrereqs } from "../Faction/FactionHelpers";
import { CityName } from "../Locations/data/CityNames";
import { CityName } from "../Enums";
import { GraftableAugmentation } from "../PersonObjects/Grafting/GraftableAugmentation";
import { getGraftingAvailableAugs, calculateGraftingTimeWithBonus } from "../PersonObjects/Grafting/GraftingHelpers";
import { Player as player } from "../Player";
import { Grafting as IGrafting } from "../ScriptEditor/NetscriptDefinitions";
import { Grafting as IGrafting } from "@nsdefs";
import { Router } from "../ui/GameRoot";
import { Page } from "../ui/Router";
import { GraftingWork } from "../Work/GraftingWork";
+1 -1
View File
@@ -18,7 +18,7 @@ import { HashUpgrades } from "../Hacknet/HashUpgrades";
import { HashUpgrade } from "../Hacknet/HashUpgrade";
import { GetServer } from "../Server/AllServers";
import { Hacknet as IHacknet, NodeStats } from "../ScriptEditor/NetscriptDefinitions";
import { Hacknet as IHacknet, NodeStats } from "@nsdefs";
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
import { helpers } from "../Netscript/NetscriptHelpers";
+8 -6
View File
@@ -1,4 +1,4 @@
import { Infiltration as IInfiltration, InfiltrationLocation } from "../ScriptEditor/NetscriptDefinitions";
import { Infiltration as IInfiltration, InfiltrationLocation } from "@nsdefs";
import { Location } from "../Locations/Location";
import { Locations } from "../Locations/Locations";
import { calculateDifficulty, calculateReward } from "../Infiltration/formulas/game";
@@ -11,7 +11,7 @@ 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 "../utils/enums";
import { CityName, LocationName } from "../Enums";
import { helpers } from "../Netscript/NetscriptHelpers";
export function NetscriptInfiltration(): InternalAPI<IInfiltration> {
@@ -41,10 +41,12 @@ export function NetscriptInfiltration(): InternalAPI<IInfiltration> {
};
return {
getPossibleLocations: () => () => {
return getLocationsWithInfiltrations.map((l) => ({
city: l.city ?? "",
name: String(l.name),
}));
return getLocationsWithInfiltrations
.filter((l) => l.city) //Guarantees no locations with a "null" entry, which should not be infiltratable anyway.
.map((l) => ({
city: l.city as CityName,
name: l.name,
}));
},
getInfiltration: (ctx) => (_location) => {
const location = helpers.string(ctx, "location", _location);
+6 -4
View File
@@ -10,13 +10,12 @@ import { isString } from "../utils/helpers/isString";
import { RunningScript } from "../Script/RunningScript";
import { calculateAchievements } from "../Achievements/Achievements";
import { Singularity as ISingularity } from "../ScriptEditor/NetscriptDefinitions";
import { Singularity as ISingularity } from "@nsdefs";
import { findCrime } from "../Crime/CrimeHelpers";
import { CompanyPositions } from "../Company/CompanyPositions";
import { DarkWebItems } from "../DarkWeb/DarkWebItems";
import { CityName } from "../Locations/data/CityNames";
import { LocationName } from "../utils/enums";
import { CityName, LocationName } from "../Enums";
import { Router } from "../ui/GameRoot";
import { SpecialServers } from "../Server/data/SpecialServers";
import { Page } from "../ui/Router";
@@ -44,7 +43,7 @@ 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 "../utils/enums";
import { FactionWorkType, GymType, UniversityClassType } from "../Enums";
import { CompanyWork } from "../Work/CompanyWork";
import { canGetBonus, onExport } from "../ExportBonus";
import { saveObject } from "../SaveObject";
@@ -1178,6 +1177,9 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
(_nextBN, _callbackScript = "") => {
helpers.checkSingularityAccess(ctx);
const nextBN = helpers.number(ctx, "nextBN", _nextBN);
if (nextBN > 13 || nextBN < 1 || !Number.isInteger(nextBN)) {
throw new Error(`Invalid bitnode specified: ${_nextBN}`);
}
const callbackScript = helpers.string(ctx, "callbackScript", _callbackScript);
const wd = GetServer(SpecialServers.WorldDaemon);
+11 -4
View File
@@ -1,12 +1,12 @@
import { Player } from "@player";
import { StaticAugmentations } from "../Augmentation/StaticAugmentations";
import { CityName } from "../Locations/data/CityNames";
import { CityName } from "../Enums";
import { findCrime } from "../Crime/CrimeHelpers";
import { Augmentation } from "../Augmentation/Augmentation";
import { Sleeve } from "../ScriptEditor/NetscriptDefinitions";
import { Sleeve } from "@nsdefs";
import { checkEnum } from "../utils/helpers/enum";
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
import { InternalAPI, NetscriptContext, removedFunction } from "../Netscript/APIWrapper";
import { isSleeveBladeburnerWork } from "../PersonObjects/Sleeve/Work/SleeveBladeburnerWork";
import { isSleeveFactionWork } from "../PersonObjects/Sleeve/Work/SleeveFactionWork";
import { isSleeveCompanyWork } from "../PersonObjects/Sleeve/Work/SleeveCompanyWork";
@@ -31,7 +31,7 @@ export function NetscriptSleeve(): InternalAPI<Sleeve> {
}
};
return {
const sleeveFunctions: InternalAPI<Sleeve> = {
getNumSleeves: (ctx) => () => {
checkSleeveAPIAccess(ctx);
return Player.sleeves.length;
@@ -254,4 +254,11 @@ export function NetscriptSleeve(): InternalAPI<Sleeve> {
return Player.sleeves[sleeveNumber].bladeburner(action, contract);
},
};
// Removed undocumented functions added using Object.assign because typescript.
// TODO: Remove these at 3.0
Object.assign(sleeveFunctions, {
getSleeveStats: removedFunction("2.2.0", "sleeve.getSleeve"),
getSleeveInformation: removedFunction("2.2.0", "sleeve.getSleeve"),
});
return sleeveFunctions;
}
+1 -1
View File
@@ -4,7 +4,7 @@ import { staneksGift } from "../CotMG/Helper";
import { Fragments, FragmentById } from "../CotMG/Fragment";
import { FragmentType } from "../CotMG/FragmentType";
import { Stanek as IStanek } from "../ScriptEditor/NetscriptDefinitions";
import { Stanek as IStanek } from "@nsdefs";
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
import { NetscriptContext, InternalAPI } from "../Netscript/APIWrapper";
import { applyAugmentation } from "../Augmentation/AugmentationHelpers";
+1 -1
View File
@@ -12,7 +12,7 @@ import {
getStockMarketTixApiCost,
} from "../StockMarket/StockMarketCosts";
import { Stock } from "../StockMarket/Stock";
import { StockOrder, TIX } from "../ScriptEditor/NetscriptDefinitions";
import { StockOrder, TIX } from "@nsdefs";
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
import { helpers } from "../Netscript/NetscriptHelpers";
+1 -1
View File
@@ -1,4 +1,4 @@
import { UserInterface as IUserInterface } from "../ScriptEditor/NetscriptDefinitions";
import { UserInterface as IUserInterface } from "@nsdefs";
import { Settings } from "../Settings/Settings";
import { ThemeEvents } from "../Themes/ui/Theme";
import { defaultTheme } from "../Themes/Themes";