From 10215a924c6c042076d1261d1b261eac6def9b04 Mon Sep 17 00:00:00 2001 From: Kateract Date: Thu, 1 Jun 2023 12:20:54 -0700 Subject: [PATCH] CORP: Add maxProducts property to division, consolidate maxProducts logic (#551) --- markdown/bitburner.division.maxproducts.md | 13 ++++++++++++ markdown/bitburner.division.md | 1 + src/Corporation/Actions.ts | 10 ++-------- src/Corporation/Division.ts | 23 +++++++++++----------- src/Corporation/ui/DivisionOverview.tsx | 2 +- src/NetscriptFunctions/Corporation.ts | 1 + src/ScriptEditor/NetscriptDefinitions.d.ts | 2 ++ 7 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 markdown/bitburner.division.maxproducts.md diff --git a/markdown/bitburner.division.maxproducts.md b/markdown/bitburner.division.maxproducts.md new file mode 100644 index 000000000..ce68983a7 --- /dev/null +++ b/markdown/bitburner.division.maxproducts.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [Division](./bitburner.division.md) > [maxProducts](./bitburner.division.maxproducts.md) + +## Division.maxProducts property + +How many products this division can support + +**Signature:** + +```typescript +maxProducts: number; +``` diff --git a/markdown/bitburner.division.md b/markdown/bitburner.division.md index d2548e1fd..bd935d726 100644 --- a/markdown/bitburner.division.md +++ b/markdown/bitburner.division.md @@ -21,6 +21,7 @@ interface Division | [lastCycleExpenses](./bitburner.division.lastcycleexpenses.md) | | number | Expenses last cycle | | [lastCycleRevenue](./bitburner.division.lastcyclerevenue.md) | | number | Revenue last cycle | | [makesProducts](./bitburner.division.makesproducts.md) | | boolean | Whether the industry this division is in is capable of making products | +| [maxProducts](./bitburner.division.maxproducts.md) | | number | How many products this division can support | | [name](./bitburner.division.name.md) | | string | Name of the division | | [numAdVerts](./bitburner.division.numadverts.md) | | number | Number of times AdVert has been bought | | [popularity](./bitburner.division.popularity.md) | | number | Popularity of the division | diff --git a/src/Corporation/Actions.ts b/src/Corporation/Actions.ts index fc7e33bfb..722dc2709 100644 --- a/src/Corporation/Actions.ts +++ b/src/Corporation/Actions.ts @@ -396,14 +396,8 @@ export function MakeProduct( if (corp.funds < designInvest + marketingInvest) { throw new Error("You don't have enough company funds to make this large of an investment"); } - let maxProducts = 3; - if (division.hasResearch("uPgrade: Capacity.II")) { - maxProducts = 5; - } else if (division.hasResearch("uPgrade: Capacity.I")) { - maxProducts = 4; - } - if (division.products.size >= maxProducts) { - throw new Error(`You are already at the max products (${maxProducts}) for division: ${division.name}!`); + if (division.products.size >= division.maxProducts) { + throw new Error(`You are already at the max products (${division.maxProducts}) for division: ${division.name}!`); } const product = new Product({ diff --git a/src/Corporation/Division.ts b/src/Corporation/Division.ts index 0b1e4c2a2..0d1d17b0e 100644 --- a/src/Corporation/Division.ts +++ b/src/Corporation/Division.ts @@ -39,6 +39,16 @@ export class Division { products = new JSONMap(); makesProducts = false; + get maxProducts() { + if (!this.makesProducts) return 0; + + // Calculate additional number of allowed Products from Research/Upgrades + let additional = 0; + if (this.hasResearch("uPgrade: Capacity.I")) ++additional; + if (this.hasResearch("uPgrade: Capacity.II")) ++additional; + + return corpConstants.maxProductsBase + additional; + } awareness = 0; popularity = 0; @@ -103,19 +113,8 @@ export class Division { this.producedMaterials = data.producedMaterials ?? []; } - getMaximumNumberProducts(): number { - if (!this.makesProducts) return 0; - - // Calculate additional number of allowed Products from Research/Upgrades - let additional = 0; - if (this.hasResearch("uPgrade: Capacity.I")) ++additional; - if (this.hasResearch("uPgrade: Capacity.II")) ++additional; - - return corpConstants.maxProductsBase + additional; - } - hasMaximumNumberProducts(): boolean { - return this.products.size >= this.getMaximumNumberProducts(); + return this.products.size >= this.maxProducts; } //Calculates the values that factor into the production and properties of diff --git a/src/Corporation/ui/DivisionOverview.tsx b/src/Corporation/ui/DivisionOverview.tsx index 2e5540d2e..d88591537 100644 --- a/src/Corporation/ui/DivisionOverview.tsx +++ b/src/Corporation/ui/DivisionOverview.tsx @@ -71,7 +71,7 @@ function MakeProductButton(): React.ReactElement { } const disabledText = hasMaxProducts - ? `${division.name} already has the maximum number of products (${division.getMaximumNumberProducts()})` + ? `${division.name} already has the maximum number of products (${division.maxProducts})` : corp.funds < 0 ? "Insufficient corporation funds" : ""; diff --git a/src/NetscriptFunctions/Corporation.ts b/src/NetscriptFunctions/Corporation.ts index 8be73d7a0..26320426e 100644 --- a/src/NetscriptFunctions/Corporation.ts +++ b/src/NetscriptFunctions/Corporation.ts @@ -262,6 +262,7 @@ export function NetscriptCorporation(): InternalAPI { cities: cities, products: [...division.products.keys()], makesProducts: division.makesProducts, + maxProducts: division.maxProducts, }; } diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 8f09c265a..ac71b0f15 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -7681,6 +7681,8 @@ interface Division { products: string[]; /** Whether the industry this division is in is capable of making products */ makesProducts: boolean; + /** How many products this division can support */ + maxProducts: number; } /**