mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-22 15:43:49 +01:00
NETSCRIPT: Added ns.corporation.getConstants, replacing many other corporation getter functions (#260)
This commit is contained in:
parent
018053d79e
commit
556fe8dd33
@ -1,5 +1,5 @@
|
||||
import { Player } from "@player";
|
||||
import { MaterialSizes } from "./MaterialSizes";
|
||||
import { MaterialInfo } from "./MaterialInfo";
|
||||
import { Corporation } from "./Corporation";
|
||||
import { IndustryResearchTrees, IndustryType, IndustriesData } from "./IndustryData";
|
||||
import { Industry } from "./Industry";
|
||||
@ -254,7 +254,7 @@ export function BuyMaterial(material: Material, amt: number): void {
|
||||
}
|
||||
|
||||
export function BulkPurchase(corp: Corporation, warehouse: Warehouse, material: Material, amt: number): void {
|
||||
const matSize = MaterialSizes[material.name];
|
||||
const matSize = MaterialInfo[material.name][1];
|
||||
const maxAmount = (warehouse.size - warehouse.sizeUsed) / matSize;
|
||||
if (isNaN(amt) || amt < 0) {
|
||||
throw new Error(`Invalid input amount`);
|
||||
|
@ -10,7 +10,7 @@ import { OfficeSpace } from "./OfficeSpace";
|
||||
import { Product } from "./Product";
|
||||
import { dialogBoxCreate } from "../ui/React/DialogBox";
|
||||
import { isString } from "../utils/helpers/isString";
|
||||
import { MaterialSizes } from "./MaterialSizes";
|
||||
import { MaterialInfo } from "./MaterialInfo";
|
||||
import { Warehouse } from "./Warehouse";
|
||||
import { Corporation } from "./Corporation";
|
||||
|
||||
@ -324,7 +324,7 @@ export class Industry {
|
||||
}
|
||||
buyAmt = mat.buy * CorporationConstants.SecsPerMarketCycle * marketCycles;
|
||||
|
||||
maxAmt = Math.floor((warehouse.size - warehouse.sizeUsed) / MaterialSizes[matName]);
|
||||
maxAmt = Math.floor((warehouse.size - warehouse.sizeUsed) / MaterialInfo[matName][1]);
|
||||
|
||||
buyAmt = Math.min(buyAmt, maxAmt);
|
||||
if (buyAmt > 0) {
|
||||
@ -346,7 +346,7 @@ export class Industry {
|
||||
if (reqMat === undefined) throw new Error(`reqMat "${matName}" is undefined`);
|
||||
mat.buy = reqMat * warehouse.smartSupplyStore;
|
||||
let buyAmt = mat.buy * CorporationConstants.SecsPerMarketCycle * marketCycles;
|
||||
const maxAmt = Math.floor((warehouse.size - warehouse.sizeUsed) / MaterialSizes[matName]);
|
||||
const maxAmt = Math.floor((warehouse.size - warehouse.sizeUsed) / MaterialInfo[matName][1]);
|
||||
buyAmt = Math.min(buyAmt, maxAmt);
|
||||
if (buyAmt > 0) smartBuy[matName] = buyAmt;
|
||||
}
|
||||
@ -374,7 +374,7 @@ export class Industry {
|
||||
for (const matName of Object.keys(smartBuy)) {
|
||||
const buyAmt = smartBuy[matName];
|
||||
if (buyAmt === undefined) throw new Error(`Somehow smartbuy matname is undefined`);
|
||||
totalSize += buyAmt * MaterialSizes[matName];
|
||||
totalSize += buyAmt * MaterialInfo[matName][1];
|
||||
}
|
||||
|
||||
// Shrink to the size of available space.
|
||||
@ -432,12 +432,12 @@ export class Industry {
|
||||
// Calculate net change in warehouse storage making the produced materials will cost
|
||||
let totalMatSize = 0;
|
||||
for (let tmp = 0; tmp < this.prodMats.length; ++tmp) {
|
||||
totalMatSize += MaterialSizes[this.prodMats[tmp]];
|
||||
totalMatSize += MaterialInfo[this.prodMats[tmp]][1];
|
||||
}
|
||||
for (const reqMatName of Object.keys(this.reqMats)) {
|
||||
const normQty = this.reqMats[reqMatName];
|
||||
if (normQty === undefined) continue;
|
||||
totalMatSize -= MaterialSizes[reqMatName] * normQty;
|
||||
totalMatSize -= MaterialInfo[reqMatName][1] * normQty;
|
||||
}
|
||||
// If not enough space in warehouse, limit the amount of produced materials
|
||||
if (totalMatSize > 0) {
|
||||
@ -684,7 +684,9 @@ export class Industry {
|
||||
// affect revenue so just return 0's
|
||||
return [0, 0];
|
||||
} else {
|
||||
const maxAmt = Math.floor((expWarehouse.size - expWarehouse.sizeUsed) / MaterialSizes[matName]);
|
||||
const maxAmt = Math.floor(
|
||||
(expWarehouse.size - expWarehouse.sizeUsed) / MaterialInfo[matName][1],
|
||||
);
|
||||
amt = Math.min(maxAmt, amt);
|
||||
}
|
||||
expWarehouse.materials[matName].imp +=
|
||||
@ -797,7 +799,7 @@ export class Industry {
|
||||
for (const reqMatName of Object.keys(product.reqMats)) {
|
||||
if (product.reqMats.hasOwnProperty(reqMatName)) {
|
||||
const normQty = product.reqMats[reqMatName];
|
||||
netStorageSize -= MaterialSizes[reqMatName] * normQty;
|
||||
netStorageSize -= MaterialInfo[reqMatName][1] * normQty;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,11 +21,21 @@ export enum IndustryType {
|
||||
RealEstate = "RealEstate",
|
||||
}
|
||||
|
||||
export interface IProductRatingWeight {
|
||||
Aesthetics?: number;
|
||||
Durability?: number;
|
||||
Features?: number;
|
||||
Quality?: number;
|
||||
Performance?: number;
|
||||
Reliability?: number;
|
||||
}
|
||||
|
||||
type IndustryData = {
|
||||
startingCost: number;
|
||||
description: string;
|
||||
/** Product name for industry. Empty string for industries with no products. */
|
||||
product?: { name: string; verb: string; desc: string };
|
||||
ProductRatingWeights?: IProductRatingWeight;
|
||||
recommendStarting: boolean;
|
||||
reqMats: Record<string, number>;
|
||||
/** Real estate factor */
|
||||
@ -74,6 +84,14 @@ export const IndustriesData: Record<IndustryType, IndustryData> = {
|
||||
startingCost: 500e9,
|
||||
description: "Develop and manufacture new computer hardware and networking infrastructures.",
|
||||
product: { name: "Product", verb: "Create", desc: "Design and manufacture a new computer hardware product!" },
|
||||
ProductRatingWeights: {
|
||||
Quality: 0.15,
|
||||
Performance: 0.25,
|
||||
Durability: 0.25,
|
||||
Reliability: 0.2,
|
||||
Aesthetics: 0.05,
|
||||
Features: 0.1,
|
||||
},
|
||||
recommendStarting: false,
|
||||
reFac: 0.2,
|
||||
sciFac: 0.62,
|
||||
@ -112,6 +130,11 @@ export const IndustriesData: Record<IndustryType, IndustryData> = {
|
||||
startingCost: 10e9,
|
||||
description: "Create your own restaurants all around the world.",
|
||||
product: { name: "Restaurant", verb: "Build", desc: "Build and manage a new restaurant!" },
|
||||
ProductRatingWeights: {
|
||||
Quality: 0.7,
|
||||
Durability: 0.1,
|
||||
Aesthetics: 0.2,
|
||||
},
|
||||
recommendStarting: true,
|
||||
sciFac: 0.12,
|
||||
hwFac: 0.15,
|
||||
@ -125,6 +148,13 @@ export const IndustriesData: Record<IndustryType, IndustryData> = {
|
||||
startingCost: 750e9,
|
||||
description: "Create and manage hospitals.",
|
||||
product: { name: "Hospital", verb: "Build", desc: "Build and manage a new hospital!" },
|
||||
ProductRatingWeights: {
|
||||
Quality: 0.4,
|
||||
Performance: 0.1,
|
||||
Durability: 0.1,
|
||||
Reliability: 0.3,
|
||||
Features: 0.1,
|
||||
},
|
||||
recommendStarting: false,
|
||||
reFac: 0.1,
|
||||
sciFac: 0.75,
|
||||
@ -151,6 +181,13 @@ export const IndustriesData: Record<IndustryType, IndustryData> = {
|
||||
startingCost: 200e9,
|
||||
description: "Discover, develop, and create new pharmaceutical drugs.",
|
||||
product: { name: "Drug", verb: "Develop", desc: "Design and develop a new pharmaceutical drug!" },
|
||||
ProductRatingWeights: {
|
||||
Quality: 0.2,
|
||||
Performance: 0.2,
|
||||
Durability: 0.1,
|
||||
Reliability: 0.3,
|
||||
Features: 0.2,
|
||||
},
|
||||
recommendStarting: false,
|
||||
reFac: 0.05,
|
||||
sciFac: 0.8,
|
||||
@ -165,6 +202,13 @@ export const IndustriesData: Record<IndustryType, IndustryData> = {
|
||||
startingCost: 600e9,
|
||||
description: "Develop and manage real estate properties.",
|
||||
product: { name: "Property", verb: "Develop", desc: "Develop a new piece of real estate property!" },
|
||||
ProductRatingWeights: {
|
||||
Quality: 0.2,
|
||||
Durability: 0.25,
|
||||
Reliability: 0.1,
|
||||
Aesthetics: 0.35,
|
||||
Features: 0.1,
|
||||
},
|
||||
recommendStarting: false,
|
||||
robFac: 0.6,
|
||||
aiFac: 0.6,
|
||||
@ -172,12 +216,20 @@ export const IndustriesData: Record<IndustryType, IndustryData> = {
|
||||
sciFac: 0.05,
|
||||
hwFac: 0.05,
|
||||
reqMats: { Metal: 5, Energy: 5, Water: 2, Hardware: 4 },
|
||||
prodMats: ["RealEstate"],
|
||||
prodMats: ["Real Estate"],
|
||||
},
|
||||
[IndustryType.Robotics]: {
|
||||
startingCost: 1e12,
|
||||
description: "Develop and create robots.",
|
||||
product: { name: "Robot", verb: "Design", desc: "Design and create a new robot or robotic system!" },
|
||||
ProductRatingWeights: {
|
||||
Quality: 0.1,
|
||||
Performance: 0.2,
|
||||
Durability: 0.2,
|
||||
Reliability: 0.2,
|
||||
Aesthetics: 0.1,
|
||||
Features: 0.2,
|
||||
},
|
||||
recommendStarting: false,
|
||||
reFac: 0.32,
|
||||
sciFac: 0.65,
|
||||
@ -191,7 +243,14 @@ export const IndustriesData: Record<IndustryType, IndustryData> = {
|
||||
startingCost: 25e9,
|
||||
description: "Develop computer software and create AI Cores.",
|
||||
product: { name: "Software", verb: "Develop", desc: "Develop a new piece of software!" },
|
||||
recommendStarting: true,
|
||||
ProductRatingWeights: {
|
||||
Quality: 0.2,
|
||||
Performance: 0.2,
|
||||
Reliability: 0.2,
|
||||
Durability: 0.2,
|
||||
Features: 0.2,
|
||||
},
|
||||
recommendStarting: false,
|
||||
sciFac: 0.62,
|
||||
advFac: 0.16,
|
||||
hwFac: 0.25,
|
||||
@ -199,12 +258,17 @@ export const IndustriesData: Record<IndustryType, IndustryData> = {
|
||||
aiFac: 0.18,
|
||||
robFac: 0.05,
|
||||
reqMats: { Hardware: 0.5, Energy: 0.5 },
|
||||
prodMats: ["AICores"],
|
||||
prodMats: ["AI Cores"],
|
||||
},
|
||||
[IndustryType.Tobacco]: {
|
||||
startingCost: 20e9,
|
||||
description: "Create and distribute tobacco and tobacco-related products.",
|
||||
product: { name: "Product", verb: "Create", desc: "Create a new tobacco product!" },
|
||||
ProductRatingWeights: {
|
||||
Quality: 0.7,
|
||||
Durability: 0.1,
|
||||
Aesthetics: 0.2,
|
||||
},
|
||||
recommendStarting: true,
|
||||
reFac: 0.15,
|
||||
sciFac: 0.75,
|
||||
|
14
src/Corporation/MaterialInfo.ts
Normal file
14
src/Corporation/MaterialInfo.ts
Normal file
@ -0,0 +1,14 @@
|
||||
// Map of material (by name) to their sizes (how much space it takes in warehouse)
|
||||
export const MaterialInfo: Record<string, [string, number, boolean]> = {
|
||||
Water: ["Water", 0.05, false],
|
||||
Energy: ["Energy", 0.01, false],
|
||||
Food: ["Food", 0.03, false],
|
||||
Plants: ["Plants", 0.05, false],
|
||||
Metal: ["Metal", 0.1, false],
|
||||
Hardware: ["Hardware", 0.06, true],
|
||||
Chemicals: ["Chemicals", 0.05, false],
|
||||
Drugs: ["Drugs", 0.02, false],
|
||||
Robots: ["Robots", 0.5, true],
|
||||
AICores: ["AI Cores", 0.1, true],
|
||||
RealEstate: ["Real Estate", 0.005, true],
|
||||
};
|
@ -1,16 +0,0 @@
|
||||
// Map of material (by name) to their sizes (how much space it takes in warehouse)
|
||||
export const MaterialSizes: Record<string, number> = {
|
||||
Water: 0.05,
|
||||
Energy: 0.01,
|
||||
Food: 0.03,
|
||||
Plants: 0.05,
|
||||
Metal: 0.1,
|
||||
Hardware: 0.06,
|
||||
Chemicals: 0.05,
|
||||
Drugs: 0.02,
|
||||
Robots: 0.5,
|
||||
AICores: 0.1,
|
||||
RealEstate: 0.005,
|
||||
"Real Estate": 0.005,
|
||||
"AI Cores": 0.1,
|
||||
};
|
@ -1,7 +1,7 @@
|
||||
import { EmployeePositions } from "./EmployeePositions";
|
||||
import { MaterialSizes } from "./MaterialSizes";
|
||||
import { MaterialInfo } from "./MaterialInfo";
|
||||
import { Industry } from "./Industry";
|
||||
import { ProductRatingWeights } from "./ProductRatingWeights";
|
||||
import { IndustriesData } from "./IndustryData";
|
||||
|
||||
import { createCityMap } from "../Locations/createCityMap";
|
||||
|
||||
@ -244,12 +244,12 @@ export class Product {
|
||||
for (const matName of Object.keys(industry.reqMats)) {
|
||||
const reqMat = industry.reqMats[matName];
|
||||
if (reqMat === undefined) continue;
|
||||
this.siz += MaterialSizes[matName] * reqMat;
|
||||
this.siz += MaterialInfo[matName][1] * reqMat;
|
||||
}
|
||||
}
|
||||
|
||||
calculateRating(industry: Industry): void {
|
||||
const weights = ProductRatingWeights[industry.type];
|
||||
const weights = IndustriesData[industry.type].ProductRatingWeights;
|
||||
if (!weights) return console.error(`Could not find product rating weights for: ${industry}`);
|
||||
this.rat = 0;
|
||||
this.rat += weights.Quality ? this.qlt * weights.Quality : 0;
|
||||
|
@ -1,68 +0,0 @@
|
||||
import { IndustryType } from "./IndustryData";
|
||||
|
||||
export interface IProductRatingWeight {
|
||||
Aesthetics?: number;
|
||||
Durability?: number;
|
||||
Features?: number;
|
||||
Quality?: number;
|
||||
Performance?: number;
|
||||
Reliability?: number;
|
||||
}
|
||||
//TODO: Move this to IndustryData
|
||||
export const ProductRatingWeights: Partial<Record<IndustryType, IProductRatingWeight>> = {
|
||||
[IndustryType.Food]: {
|
||||
Quality: 0.7,
|
||||
Durability: 0.1,
|
||||
Aesthetics: 0.2,
|
||||
},
|
||||
[IndustryType.Tobacco]: {
|
||||
Quality: 0.4,
|
||||
Durability: 0.2,
|
||||
Reliability: 0.2,
|
||||
Aesthetics: 0.2,
|
||||
},
|
||||
[IndustryType.Pharmaceutical]: {
|
||||
Quality: 0.2,
|
||||
Performance: 0.2,
|
||||
Durability: 0.1,
|
||||
Reliability: 0.3,
|
||||
Features: 0.2,
|
||||
},
|
||||
[IndustryType.Computers]: {
|
||||
Quality: 0.15,
|
||||
Performance: 0.25,
|
||||
Durability: 0.25,
|
||||
Reliability: 0.2,
|
||||
Aesthetics: 0.05,
|
||||
Features: 0.1,
|
||||
},
|
||||
[IndustryType.Robotics]: {
|
||||
Quality: 0.1,
|
||||
Performance: 0.2,
|
||||
Durability: 0.2,
|
||||
Reliability: 0.2,
|
||||
Aesthetics: 0.1,
|
||||
Features: 0.2,
|
||||
},
|
||||
[IndustryType.Software]: {
|
||||
Quality: 0.2,
|
||||
Performance: 0.2,
|
||||
Reliability: 0.2,
|
||||
Durability: 0.2,
|
||||
Features: 0.2,
|
||||
},
|
||||
[IndustryType.Healthcare]: {
|
||||
Quality: 0.4,
|
||||
Performance: 0.1,
|
||||
Durability: 0.1,
|
||||
Reliability: 0.3,
|
||||
Features: 0.1,
|
||||
},
|
||||
[IndustryType.RealEstate]: {
|
||||
Quality: 0.2,
|
||||
Durability: 0.25,
|
||||
Reliability: 0.1,
|
||||
Aesthetics: 0.35,
|
||||
Features: 0.1,
|
||||
},
|
||||
};
|
@ -1,7 +1,7 @@
|
||||
import { Material } from "./Material";
|
||||
import { Corporation } from "./Corporation";
|
||||
import { Industry } from "./Industry";
|
||||
import { MaterialSizes } from "./MaterialSizes";
|
||||
import { MaterialInfo } from "./MaterialInfo";
|
||||
import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../utils/JSONReviver";
|
||||
import { exceptionAlert } from "../utils/helpers/exceptionAlert";
|
||||
|
||||
@ -86,8 +86,8 @@ export class Warehouse {
|
||||
this.sizeUsed = 0;
|
||||
for (const matName of Object.keys(this.materials)) {
|
||||
const mat = this.materials[matName];
|
||||
if (MaterialSizes.hasOwnProperty(matName)) {
|
||||
this.sizeUsed += mat.qty * MaterialSizes[matName];
|
||||
if (MaterialInfo.hasOwnProperty(matName)) {
|
||||
this.sizeUsed += mat.qty * MaterialInfo[matName][1];
|
||||
}
|
||||
}
|
||||
if (this.sizeUsed > this.size) {
|
||||
|
@ -77,7 +77,7 @@ export const CorporationConstants = {
|
||||
"ABC SalesBots",
|
||||
"Project Insight",
|
||||
],
|
||||
AllResearch: [
|
||||
BaseResearch: [
|
||||
"Hi-Tech R&D Laboratory",
|
||||
"AutoBrew",
|
||||
"AutoPartyManager",
|
||||
@ -96,12 +96,8 @@ export const CorporationConstants = {
|
||||
"Overclock",
|
||||
"Self-Correcting Assemblers",
|
||||
"Sti.mu",
|
||||
"sudo.Assist",
|
||||
"uPgrade: Capacity.I",
|
||||
"uPgrade: Capacity.II",
|
||||
"uPgrade: Dashboard",
|
||||
"uPgrade: Fulcrum",
|
||||
],
|
||||
ProdResearch: ["uPgrade: Capacity.I", "uPgrade: Capacity.II", "uPgrade: Dashboard", "uPgrade: Fulcrum"],
|
||||
FundingRoundShares: [0.1, 0.35, 0.25, 0.2],
|
||||
FundingRoundMultiplier: [4, 3, 3, 2.5],
|
||||
|
||||
|
@ -59,7 +59,7 @@ export const CorporationUpgrades: Record<CorporationUpgradeIndex, CorporationUpg
|
||||
"to consumers through their dreams. Each level of this upgrade provides a passive " +
|
||||
"increase in awareness of all of your companies (divisions) by 0.004 / market cycle," +
|
||||
"and in popularity by 0.001 / market cycle. A market cycle is approximately " +
|
||||
"15 seconds.",
|
||||
"10 seconds.",
|
||||
},
|
||||
|
||||
//Makes advertising more effective
|
||||
|
@ -7,7 +7,7 @@ import { Warehouse } from "../Warehouse";
|
||||
import { SmartSupplyModal } from "./modals/SmartSupplyModal";
|
||||
import { ProductElem } from "./ProductElem";
|
||||
import { MaterialElem } from "./MaterialElem";
|
||||
import { MaterialSizes } from "../MaterialSizes";
|
||||
import { MaterialInfo } from "../MaterialInfo";
|
||||
|
||||
import { numeralWrapper } from "../../ui/numeralFormat";
|
||||
|
||||
@ -122,11 +122,11 @@ function WarehouseRoot(props: IProps): React.ReactElement {
|
||||
const breakdownItems: JSX.Element[] = [];
|
||||
for (const matName of Object.keys(props.warehouse.materials)) {
|
||||
const mat = props.warehouse.materials[matName];
|
||||
if (!MaterialSizes.hasOwnProperty(matName)) continue;
|
||||
if (!MaterialInfo.hasOwnProperty(matName)) continue;
|
||||
if (mat.qty === 0) continue;
|
||||
breakdownItems.push(
|
||||
<>
|
||||
{matName}: {numeralWrapper.format(mat.qty * MaterialSizes[matName], "0,0.0")}
|
||||
{matName}: {numeralWrapper.format(mat.qty * MaterialInfo[matName][1], "0,0.0")}
|
||||
</>,
|
||||
);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React, { useState } from "react";
|
||||
import { dialogBoxCreate } from "../../../ui/React/DialogBox";
|
||||
import { MaterialSizes } from "../../MaterialSizes";
|
||||
import { MaterialInfo } from "../../MaterialInfo";
|
||||
import { Warehouse } from "../../Warehouse";
|
||||
import { Material } from "../../Material";
|
||||
import { numeralWrapper } from "../../../ui/numeralFormat";
|
||||
@ -33,7 +33,7 @@ function BulkPurchaseSection(props: IBPProps): React.ReactElement {
|
||||
const parsedAmt = parseFloat(props.amount);
|
||||
const cost = parsedAmt * props.mat.bCost;
|
||||
|
||||
const matSize = MaterialSizes[props.mat.name];
|
||||
const matSize = MaterialInfo[props.mat.name][1];
|
||||
const maxAmount = (props.warehouse.size - props.warehouse.sizeUsed) / matSize;
|
||||
|
||||
if (parsedAmt > maxAmount) {
|
||||
|
@ -349,6 +349,7 @@ const grafting = {
|
||||
const corporation = {
|
||||
hasCorporation: 0,
|
||||
getMaterialNames: 0,
|
||||
getConstants: 0,
|
||||
getIndustryTypes: 0,
|
||||
getEmployeePositions: 0,
|
||||
getUnlockables: 0,
|
||||
|
@ -8,6 +8,9 @@ import { Industry } from "../Corporation/Industry";
|
||||
import { Corporation } from "../Corporation/Corporation";
|
||||
|
||||
import {
|
||||
productInfo as NSProduct,
|
||||
materialInfo as NSMaterial,
|
||||
divisionInfo as NSDivisionInfo,
|
||||
Corporation as NSCorporation,
|
||||
Division as NSDivision,
|
||||
WarehouseAPI,
|
||||
@ -60,6 +63,7 @@ import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
import { assertEnumMember, helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { checkEnum } from "../utils/helpers/enum";
|
||||
import { CityName } from "../Locations/data/CityNames";
|
||||
import { MaterialInfo } from "../Corporation/MaterialInfo";
|
||||
|
||||
export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
function createCorporation(corporationName: string, selfFund = true): boolean {
|
||||
@ -115,10 +119,6 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
return baseCost * Math.pow(priceMult, level);
|
||||
}
|
||||
|
||||
function getExpandCityCost(): number {
|
||||
return CorporationConstants.OfficeInitialCost;
|
||||
}
|
||||
|
||||
function getInvestmentOffer(): InvestmentOffer {
|
||||
const corporation = getCorporation();
|
||||
if (
|
||||
@ -285,11 +285,59 @@ 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> = {
|
||||
getPurchaseWarehouseCost: (ctx) => () => {
|
||||
checkAccess(ctx, 7);
|
||||
return CorporationConstants.WarehouseInitialCost;
|
||||
},
|
||||
getUpgradeWarehouseCost:
|
||||
(ctx) =>
|
||||
(_divisionName, _cityName, _amt = 1) => {
|
||||
@ -710,22 +758,22 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
...warehouseAPI,
|
||||
...officeAPI,
|
||||
hasCorporation: () => () => !!Player.corporation,
|
||||
// Todo: Just remove these functions and provide enums?
|
||||
getMaterialNames: (ctx) => () => {
|
||||
getConstants: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return [...CorporationConstants.AllMaterials];
|
||||
},
|
||||
getUnlockables: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return [...CorporationConstants.AllUnlocks];
|
||||
},
|
||||
getUpgradeNames: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return [...CorporationConstants.AllUpgrades];
|
||||
},
|
||||
getResearchNames: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return [...CorporationConstants.AllResearch];
|
||||
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(),
|
||||
};
|
||||
},
|
||||
expandIndustry: (ctx) => (_industryName, _divisionName) => {
|
||||
checkAccess(ctx);
|
||||
@ -826,18 +874,6 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
const upgradeName = helpers.string(ctx, "upgradeName", _upgradeName);
|
||||
return getUpgradeLevelCost(ctx, upgradeName);
|
||||
},
|
||||
getExpandIndustryCost: (ctx) => (_industryName) => {
|
||||
checkAccess(ctx);
|
||||
const industryName = helpers.string(ctx, "industryName", _industryName);
|
||||
if (!checkEnum(IndustryType, industryName)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid industry: '${industryName}'`);
|
||||
}
|
||||
return IndustriesData[industryName].startingCost;
|
||||
},
|
||||
getExpandCityCost: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return getExpandCityCost();
|
||||
},
|
||||
getInvestmentOffer: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return getInvestmentOffer();
|
||||
|
@ -415,6 +415,9 @@ export function runScriptFromScript(
|
||||
return 0;
|
||||
}
|
||||
|
||||
//prevent leading / from causing a bug
|
||||
if (scriptname.startsWith("/")) scriptname = scriptname.slice(1);
|
||||
|
||||
if (typeof scriptname !== "string" || !Array.isArray(args)) {
|
||||
workerScript.log(caller, () => `Invalid arguments: scriptname='${scriptname} args='${args}'`);
|
||||
console.error(`runScriptFromScript() failed due to invalid arguments`);
|
||||
|
123
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
123
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -7039,6 +7039,17 @@ declare enum IndustryType {
|
||||
RealEstate = "RealEstate",
|
||||
}
|
||||
|
||||
/** Names of all cities
|
||||
* @public */
|
||||
declare enum CityName {
|
||||
Aevum = "Aevum",
|
||||
Chongqing = "Chongqing",
|
||||
Sector12 = "Sector-12",
|
||||
NewTokyo = "New Tokyo",
|
||||
Ishima = "Ishima",
|
||||
Volhaven = "Volhaven",
|
||||
}
|
||||
|
||||
/** Names of all locations
|
||||
* @public */
|
||||
declare enum LocationName {
|
||||
@ -7422,11 +7433,6 @@ export interface WarehouseAPI {
|
||||
* @param qty - Amount to limit to. Pass a negative value to remove the limit instead.
|
||||
*/
|
||||
limitProductProduction(divisionName: string, cityName: string, productName: string, qty: number): void;
|
||||
/**
|
||||
* Gets the cost to purchase a warehouse
|
||||
* @returns cost
|
||||
*/
|
||||
getPurchaseWarehouseCost(): number;
|
||||
/**
|
||||
* Gets the cost to upgrade a warehouse to the next level
|
||||
* @param divisionName - Name of the division
|
||||
@ -7483,34 +7489,13 @@ export interface Corporation extends WarehouseAPI, OfficeAPI {
|
||||
* @returns cost of the upgrade */
|
||||
getUpgradeLevelCost(upgradeName: string): number;
|
||||
|
||||
/** Gets the cost to expand into a new industry
|
||||
* @param industryName - Name of the industry
|
||||
* @returns cost */
|
||||
getExpandIndustryCost(industryName: IndustryType | `${IndustryType}`): number;
|
||||
|
||||
/** Gets the cost to expand into a new city
|
||||
* @returns cost */
|
||||
getExpandCityCost(): number;
|
||||
|
||||
/** Get an offer for investment based on you companies current valuation
|
||||
* @returns An offer of investment */
|
||||
getInvestmentOffer(): InvestmentOffer;
|
||||
|
||||
/** Get list of materials
|
||||
* @returns material names */
|
||||
getMaterialNames(): string[];
|
||||
|
||||
/** Get list of one-time unlockable upgrades
|
||||
* @returns unlockable upgrades names */
|
||||
getUnlockables(): string[];
|
||||
|
||||
/** Get list of upgrade names
|
||||
* @returns upgrade names */
|
||||
getUpgradeNames(): string[];
|
||||
|
||||
/** Get list of research names
|
||||
* @returns research names */
|
||||
getResearchNames(): string[];
|
||||
/** Get corporation related constants
|
||||
* @returns corporation related constants */
|
||||
getConstants(): CorpConstants;
|
||||
|
||||
/** Accept investment based on you companies current valuation
|
||||
* @remarks
|
||||
@ -7612,6 +7597,86 @@ interface CorporationInfo {
|
||||
divisions: Division[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Corporation related constants
|
||||
* @public
|
||||
*/
|
||||
interface CorpConstants {
|
||||
/** Corporation cycle states */
|
||||
states: string[];
|
||||
/** Unlockable upgrades */
|
||||
unlocks: string[];
|
||||
/** Levelable upgrades */
|
||||
upgrades: string[];
|
||||
/** Researches, product researches are only available to product making divisions */
|
||||
researches: Record<string, string[]>;
|
||||
/** Amount of funds required to bribe for 1 reputation */
|
||||
bribeToRepRatio: number;
|
||||
/** Amount of products a division can have without researches */
|
||||
baseMaxProducts: number;
|
||||
/** Cost to expand to another city within a division */
|
||||
cityExpandCost: number;
|
||||
/** Cost to purchase a warehouse in a city */
|
||||
warehousePurchaseCost: number;
|
||||
/** Cost of coffee per employee in an office */
|
||||
coffeeCost: number;
|
||||
/** Array of all material types */
|
||||
materials: Record<string, materialInfo>;
|
||||
/** Array of all product types */
|
||||
products: Record<string, productInfo>;
|
||||
/** Array of all division types */
|
||||
divisions: Record<string, divisionInfo>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Corporation material information
|
||||
* @public
|
||||
*/
|
||||
interface materialInfo {
|
||||
/** Name of the material */
|
||||
name: string;
|
||||
/** Size of the material */
|
||||
size: number;
|
||||
/** Revenue per second this cycle */
|
||||
prodMult: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Corporation product information
|
||||
* @public
|
||||
*/
|
||||
interface productInfo {
|
||||
/** Product type */
|
||||
type?: string;
|
||||
/** Size of the product */
|
||||
size: number;
|
||||
/** Materials required to make the product */
|
||||
requiredMaterials: string[];
|
||||
/** Division type which makes the product */
|
||||
division: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Corporation division information
|
||||
* @public
|
||||
*/
|
||||
interface divisionInfo {
|
||||
/** Division type */
|
||||
type: string;
|
||||
/** Cost to expand to the division */
|
||||
cost: number;
|
||||
/** Materials required for production and their amounts */
|
||||
requiredMaterials: Record<string, number>;
|
||||
/** Materials produced */
|
||||
producedMaterials?: string[];
|
||||
/** Whether the division makes materials */
|
||||
makesMaterials: boolean;
|
||||
/** Whether the division makes products */
|
||||
makesProducts: boolean;
|
||||
/** Product type */
|
||||
productType?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Product in a warehouse
|
||||
* @public
|
||||
|
@ -77,6 +77,16 @@ export enum GymType {
|
||||
agility = "agi",
|
||||
}
|
||||
|
||||
/** Names of all cities */
|
||||
export enum CityName {
|
||||
Aevum = "Aevum",
|
||||
Chongqing = "Chongqing",
|
||||
Sector12 = "Sector-12",
|
||||
NewTokyo = "New Tokyo",
|
||||
Ishima = "Ishima",
|
||||
Volhaven = "Volhaven",
|
||||
}
|
||||
|
||||
/** Names of all locations */
|
||||
export enum LocationName {
|
||||
AevumAeroCorp = "AeroCorp",
|
||||
|
Loading…
Reference in New Issue
Block a user