CORPORATION: move product productionCost into cityData (#887)

This commit is contained in:
Caldwell
2023-10-30 08:10:45 +01:00
committed by GitHub
parent ca12bddaf5
commit 0bdab7bec8
5 changed files with 27 additions and 28 deletions

View File

@ -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;
}
}
});

View File

@ -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);
}
}

View File

@ -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 */

View File

@ -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={
<StatsTable
rows={[
["Prod:", formatBigNumber(product.cityData[city].productionAmount)],
["Sell:", formatBigNumber(-product.cityData[city].actualSellAmount || 0)],
["Prod:", formatBigNumber(cityData.productionAmount)],
["Sell:", formatBigNumber(-cityData.actualSellAmount || 0)],
]}
/>
}
>
<Typography>
{product.name}: {formatBigNumber(product.cityData[city].stored)} ({formatBigNumber(totalGain)}
{product.name}: {formatBigNumber(cityData.stored)} ({formatBigNumber(totalGain)}
/s)
</Typography>
</Tooltip>
@ -131,13 +131,13 @@ export function ProductElem(props: IProductProps): React.ReactElement {
</Typography>
}
>
<Typography>Effective rating: {formatBigNumber(product.cityData[city].effectiveRating)}</Typography>
<Typography>Effective rating: {formatBigNumber(cityData.effectiveRating)}</Typography>
</Tooltip>
</Box>
<Box display="flex">
<Tooltip title={<Typography>An estimate of the material cost it takes to create this Product.</Typography>}>
<Typography>
Est. Production Cost: <Money money={product.productionCost / corpConstants.baseProductProfitMult} />
Est. Production Cost: <Money money={cityData.productionCost / corpConstants.baseProductProfitMult} />
</Typography>
</Tooltip>
</Box>
@ -151,7 +151,7 @@ export function ProductElem(props: IProductProps): React.ReactElement {
}
>
<Typography>
Est. Market Price: <Money money={product.productionCost} />
Est. Market Price: <Money money={cityData.productionCost} />
</Typography>
</Tooltip>
</Box>

View File

@ -278,7 +278,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
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,