From 0bdab7bec82d4e5b53cd2532e974fb7bab8f22cd Mon Sep 17 00:00:00 2001 From: Caldwell <115591472+Caldwell-74@users.noreply.github.com> Date: Mon, 30 Oct 2023 08:10:45 +0100 Subject: [PATCH] CORPORATION: move product productionCost into cityData (#887) --- src/Corporation/Corporation.ts | 2 +- src/Corporation/Division.ts | 22 +++++++++++----------- src/Corporation/Product.ts | 5 ++--- src/Corporation/ui/ProductElem.tsx | 24 ++++++++++++------------ src/NetscriptFunctions/Corporation.ts | 2 +- 5 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/Corporation/Corporation.ts b/src/Corporation/Corporation.ts index 28575b407..d793cf180 100644 --- a/src/Corporation/Corporation.ts +++ b/src/Corporation/Corporation.ts @@ -232,7 +232,7 @@ export class Corporation { assets += mat.stored * mat.averagePrice; } for (const prod of ind.products.values()) { - assets += prod.cityData[warehouse.city].stored * prod.productionCost; + assets += prod.cityData[warehouse.city].stored * prod.cityData[warehouse.city].productionCost; } } }); diff --git a/src/Corporation/Division.ts b/src/Corporation/Division.ts index f653452b0..038856d1f 100644 --- a/src/Corporation/Division.ts +++ b/src/Corporation/Division.ts @@ -823,13 +823,13 @@ export class Division { } case "SALE": { //Process sale of Products - product.productionCost = 0; //Estimated production cost + product.cityData[city].productionCost = 0; //Estimated production cost for (const [reqMatName, reqQty] of getRecordEntries(product.requiredMaterials)) { - product.productionCost += reqQty * warehouse.materials[reqMatName].marketPrice; + product.cityData[city].productionCost += reqQty * warehouse.materials[reqMatName].marketPrice; } // Since its a product, its production cost is increased for labor - product.productionCost *= corpConstants.baseProductProfitMult; + product.cityData[city].productionCost *= corpConstants.baseProductProfitMult; // Sale multipliers const businessFactor = this.getBusinessFactor(office); //Business employee productivity @@ -887,33 +887,33 @@ export class Division { if (sqrtNumerator === 0) { optimalPrice = 0; // Nothing to sell } else { - optimalPrice = product.productionCost + markupLimit; + optimalPrice = product.cityData[city].productionCost + markupLimit; console.warn(`In Corporation, found illegal 0s when trying to calculate MarketTA2 sale cost`); } } else { - optimalPrice = numerator / denominator + product.productionCost; + optimalPrice = numerator / denominator + product.cityData[city].productionCost; } // Store this "optimal Price" in a property so we don't have to re-calculate for UI sCost = optimalPrice; } else if (product.marketTa1) { - sCost = product.productionCost + markupLimit; + sCost = product.cityData[city].productionCost + markupLimit; } else if (isString(sellPrice)) { let sCostString = sellPrice; if (product.markup === 0) { console.error(`mku is zero, reverting to 1 to avoid Infinity`); product.markup = 1; } - sCostString = sCostString.replace(/MP/g, product.productionCost.toString()); - sCost = Math.max(product.productionCost, eval(sCostString)); + sCostString = sCostString.replace(/MP/g, product.cityData[city].productionCost.toString()); + sCost = Math.max(product.cityData[city].productionCost, eval(sCostString)); } else { sCost = sellPrice; } product.uiMarketPrice[city] = sCost; let markup = 1; - if (sCost > product.productionCost) { - if (sCost - product.productionCost > markupLimit) { - markup = markupLimit / (sCost - product.productionCost); + if (sCost > product.cityData[city].productionCost) { + if (sCost - product.cityData[city].productionCost > markupLimit) { + markup = markupLimit / (sCost - product.cityData[city].productionCost); } } diff --git a/src/Corporation/Product.ts b/src/Corporation/Product.ts index ff6593d79..4da2181ca 100644 --- a/src/Corporation/Product.ts +++ b/src/Corporation/Product.ts @@ -31,9 +31,6 @@ export class Product { without suffering a loss in the # of sales */ markup = 0; - /** Cost of producing this product if buying its component materials at market price */ - productionCost = 0; - /** Whether the development for this product is finished yet */ finished = false; developmentProgress = 0; // Creation progress - A number between 0-100 representing percentage @@ -82,6 +79,8 @@ export class Product { desiredSellAmount: 0 as number | string, /** Player input sell price e.g. "MP * 5" */ desiredSellPrice: "" as string | number, + /** Cost of producing this product if buying its component materials at market price */ + productionCost: 0, })); /** How much warehouse space is occupied per unit of this product */ diff --git a/src/Corporation/ui/ProductElem.tsx b/src/Corporation/ui/ProductElem.tsx index dc3b32779..16de5499f 100644 --- a/src/Corporation/ui/ProductElem.tsx +++ b/src/Corporation/ui/ProductElem.tsx @@ -31,26 +31,26 @@ export function ProductElem(props: IProductProps): React.ReactElement { const [cancelOpen, setCancelOpen] = useState(false); const city = props.city; const product = props.product; - + const cityData = product.cityData[city]; const hasUpgradeDashboard = division.hasResearch("uPgrade: Dashboard"); // Total product gain = production - sale - const totalGain = product.cityData[city].productionAmount - product.cityData[city].actualSellAmount; + const totalGain = cityData.productionAmount - cityData.actualSellAmount; // Sell button let sellButtonText: JSX.Element; - const desiredSellAmount = product.cityData[city].desiredSellAmount; + const desiredSellAmount = cityData.desiredSellAmount; if (desiredSellAmount !== null) { if (isString(desiredSellAmount)) { sellButtonText = ( <> - Sell ({formatBigNumber(product.cityData[city].actualSellAmount)}/{desiredSellAmount}) + Sell ({formatBigNumber(cityData.actualSellAmount)}/{desiredSellAmount}) ); } else { sellButtonText = ( <> - Sell ({formatBigNumber(product.cityData[city].actualSellAmount)}/{formatBigNumber(desiredSellAmount)}) + Sell ({formatBigNumber(cityData.actualSellAmount)}/{formatBigNumber(desiredSellAmount)}) ); } @@ -64,7 +64,7 @@ export function ProductElem(props: IProductProps): React.ReactElement { ); // Limit Production button - const productionLimit = product.cityData[city].productionLimit; + const productionLimit = cityData.productionLimit; const limitProductionButtonText = "Limit Production" + (productionLimit !== null ? " (" + formatBigNumber(productionLimit) + ")" : ""); @@ -92,14 +92,14 @@ export function ProductElem(props: IProductProps): React.ReactElement { title={ } > - {product.name}: {formatBigNumber(product.cityData[city].stored)} ({formatBigNumber(totalGain)} + {product.name}: {formatBigNumber(cityData.stored)} ({formatBigNumber(totalGain)} /s) @@ -131,13 +131,13 @@ export function ProductElem(props: IProductProps): React.ReactElement { } > - Effective rating: {formatBigNumber(product.cityData[city].effectiveRating)} + Effective rating: {formatBigNumber(cityData.effectiveRating)} An estimate of the material cost it takes to create this Product.}> - Est. Production Cost: + Est. Production Cost: @@ -151,7 +151,7 @@ export function ProductElem(props: IProductProps): React.ReactElement { } > - Est. Market Price: + Est. Market Price: diff --git a/src/NetscriptFunctions/Corporation.ts b/src/NetscriptFunctions/Corporation.ts index abc603ca6..c5270207b 100644 --- a/src/NetscriptFunctions/Corporation.ts +++ b/src/NetscriptFunctions/Corporation.ts @@ -278,7 +278,7 @@ export function NetscriptCorporation(): InternalAPI { rating: product.rating, effectiveRating: cityData.effectiveRating, stats: cloneDeep(product.stats), - productionCost: product.productionCost, + productionCost: cityData.productionCost, desiredSellPrice: cityData.desiredSellPrice, desiredSellAmount: cityData.desiredSellAmount, stored: cityData.stored,