mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 12:15:44 +01:00
CORP: Add maxProducts property to division, consolidate maxProducts logic (#551)
This commit is contained in:
parent
0d6015104e
commit
10215a924c
13
markdown/bitburner.division.maxproducts.md
Normal file
13
markdown/bitburner.division.maxproducts.md
Normal file
@ -0,0 +1,13 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[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;
|
||||
```
|
@ -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 |
|
||||
|
@ -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({
|
||||
|
@ -39,6 +39,16 @@ export class Division {
|
||||
|
||||
products = new JSONMap<string, Product>();
|
||||
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
|
||||
|
@ -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"
|
||||
: "";
|
||||
|
@ -262,6 +262,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
cities: cities,
|
||||
products: [...division.products.keys()],
|
||||
makesProducts: division.makesProducts,
|
||||
maxProducts: division.maxProducts,
|
||||
};
|
||||
}
|
||||
|
||||
|
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user