From e03a366f12efc40b2866e9cd9de5ca0984c9d6a6 Mon Sep 17 00:00:00 2001 From: omuretsu <84951833+Snarling@users.noreply.github.com> Date: Sat, 27 May 2023 01:53:06 -0400 Subject: [PATCH] hotfix broken spring water --- src/Corporation/Division.ts | 9 ++++----- src/Corporation/IndustryData.tsx | 2 +- src/Corporation/Material.ts | 8 +++----- src/Corporation/Product.ts | 12 ++++++------ src/Corporation/ui/IndustryProductEquation.tsx | 7 +++---- src/Corporation/ui/MaterialElem.tsx | 6 ++---- src/Corporation/ui/modals/SmartSupplyModal.tsx | 5 ++--- 7 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/Corporation/Division.ts b/src/Corporation/Division.ts index 426dfbc0d..a5f0d5a63 100644 --- a/src/Corporation/Division.ts +++ b/src/Corporation/Division.ts @@ -423,19 +423,18 @@ export class Division { // Make our materials if they are producable if (producableFrac > 0 && prod > 0) { + const requiredMatsEntries = getRecordEntries(this.requiredMaterials); let avgQlt = 0; - let divider = 0; - for (const [reqMatName, reqMat] of getRecordEntries(this.requiredMaterials)) { + let divider = requiredMatsEntries.length; + for (const [reqMatName, reqMat] of requiredMatsEntries) { const reqMatQtyNeeded = reqMat * prod * producableFrac; warehouse.materials[reqMatName].stored -= reqMatQtyNeeded; warehouse.materials[reqMatName].productionAmount = 0; warehouse.materials[reqMatName].productionAmount -= reqMatQtyNeeded / (corpConstants.secondsPerMarketCycle * marketCycles); - avgQlt += warehouse.materials[reqMatName].quality; - divider++; + avgQlt += warehouse.materials[reqMatName].quality / divider; } - avgQlt /= divider; avgQlt = Math.max(avgQlt, 1); for (let j = 0; j < this.producedMaterials.length; ++j) { let tempQlt = diff --git a/src/Corporation/IndustryData.tsx b/src/Corporation/IndustryData.tsx index 9456e8ef7..d44408741 100644 --- a/src/Corporation/IndustryData.tsx +++ b/src/Corporation/IndustryData.tsx @@ -31,7 +31,7 @@ export const IndustriesData: Record = { aiCoreFactor: 0.1, advertisingFactor: 0.03, requiredMaterials: {}, - producedMaterials: ["Plants", "Food"], + producedMaterials: ["Water"], }, [IndustryType.Refinery]: { startingCost: 50e9, diff --git a/src/Corporation/Material.ts b/src/Corporation/Material.ts index 032ce3cab..ab9a7aa9d 100644 --- a/src/Corporation/Material.ts +++ b/src/Corporation/Material.ts @@ -131,11 +131,9 @@ export class Material { // Initializes a Material object from a JSON save state. static fromJSON(value: IReviverValue): Material { - // Gracefully load save files from when Scientific Research was considered a Material (pre 2.2). - if (value.data.name === "Scientific Research") return value.data.qty; - if (value.data.name === "RealEstate") value.data.name = "Real Estate"; - if (value.data.name === "AICores") value.data.name = "AI Cores"; - return Generic_fromJSON(Material, value.data); + const material = Generic_fromJSON(Material, value.data); + if (isNaN(material.quality)) material.quality = 1; + return material; } } diff --git a/src/Corporation/Product.ts b/src/Corporation/Product.ts index 54bdeca0f..ab57c703d 100644 --- a/src/Corporation/Product.ts +++ b/src/Corporation/Product.ts @@ -133,8 +133,8 @@ export class Product { } } - // @param industry - Industry object. Reference to industry that makes this Product - finishProduct(industry: Division): void { + // @param division - Division object. Reference to division that makes this Product + finishProduct(division: Division): void { this.finished = true; // Calculate properties @@ -147,7 +147,7 @@ export class Product { const designMult = 1 + Math.pow(this.designInvestment, 0.1) / 100; const balanceMult = 1.2 * engrRatio + 0.9 * mgmtRatio + 1.3 * rndRatio + 1.5 * opsRatio + busRatio; - const sciMult = 1 + Math.pow(industry.researchPoints, industry.researchFactor) / 800; + const sciMult = 1 + Math.pow(division.researchPoints, division.researchFactor) / 800; const totalMult = balanceMult * designMult * sciMult; this.stats.quality = @@ -192,7 +192,7 @@ export class Product { 0.02 * this.creationJobFactors[CorpEmployeeJob.RandD] + 0.05 * this.creationJobFactors[CorpEmployeeJob.Operations] + 0.05 * this.creationJobFactors[CorpEmployeeJob.Business]); - this.calculateRating(industry); + this.calculateRating(division); const advMult = 1 + Math.pow(this.advertisingInvestment, 0.1) / 100; const busmgtgRatio = Math.max(busRatio + mgmtRatio, 1 / totalProd); this.markup = 100 / (advMult * Math.pow(this.stats.quality + 0.001, 0.65) * busmgtgRatio); @@ -202,12 +202,12 @@ export class Product { if (this.markup === 0 || !isFinite(this.markup)) this.markup = 1; this.demand = - industry.awareness === 0 ? 20 : Math.min(100, advMult * (100 * (industry.popularity / industry.awareness))); + division.awareness === 0 ? 20 : Math.min(100, advMult * (100 * (division.popularity / division.awareness))); this.competition = getRandomInt(0, 70); //Calculate the product's required materials and size this.size = 0; - for (const [matName, reqQty] of getRecordEntries(industry.requiredMaterials)) { + for (const [matName, reqQty] of getRecordEntries(division.requiredMaterials)) { this.requiredMaterials[matName] = reqQty; this.size += MaterialInfo[matName].size * reqQty; } diff --git a/src/Corporation/ui/IndustryProductEquation.tsx b/src/Corporation/ui/IndustryProductEquation.tsx index 1e552d5b2..6e6ea8e78 100644 --- a/src/Corporation/ui/IndustryProductEquation.tsx +++ b/src/Corporation/ui/IndustryProductEquation.tsx @@ -1,7 +1,7 @@ import React from "react"; import { Division } from "../Division"; import { MathJax } from "better-react-mathjax"; -import { CorpMaterialName } from "@nsdefs"; +import { getRecordEntries } from "../../Types/Record"; interface IProps { division: Division; @@ -9,9 +9,8 @@ interface IProps { export function IndustryProductEquation(props: IProps): React.ReactElement { const reqs = []; - for (const reqMat of Object.keys(props.division.requiredMaterials) as CorpMaterialName[]) { - const reqAmt = props.division.requiredMaterials[reqMat]; - if (reqAmt === undefined) continue; + for (const [reqMat, reqAmt] of getRecordEntries(props.division.requiredMaterials)) { + if (!reqAmt) continue; reqs.push(String.raw`${reqAmt}\text{ }${reqMat}`); } const prod = props.division.producedMaterials.map((p) => `1\\text{ }${p}`); diff --git a/src/Corporation/ui/MaterialElem.tsx b/src/Corporation/ui/MaterialElem.tsx index d7202cef1..8d525eaf4 100644 --- a/src/Corporation/ui/MaterialElem.tsx +++ b/src/Corporation/ui/MaterialElem.tsx @@ -23,6 +23,7 @@ import Box from "@mui/material/Box"; import { LimitMaterialProductionModal } from "./modals/LimitMaterialProductionModal"; import { CityName } from "../../Enums"; import { CorpUnlockName } from "../data/Enums"; +import { getRecordKeys } from "../../Types/Record"; interface IMaterialProps { warehouse: Warehouse; @@ -57,10 +58,7 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement { // Flag that determines whether this industry is "new" and the current material should be // marked with flashing-red lights const tutorial = - division.newInd && - Object.keys(division.requiredMaterials).includes(mat.name) && - mat.buyAmount === 0 && - mat.importAmount === 0; + division.newInd && mat.name in division.requiredMaterials && mat.buyAmount === 0 && mat.importAmount === 0; // Purchase material button const purchaseButtonText = `Buy (${formatBigNumber(mat.buyAmount)})`; diff --git a/src/Corporation/ui/modals/SmartSupplyModal.tsx b/src/Corporation/ui/modals/SmartSupplyModal.tsx index 866e2c624..e758a9125 100644 --- a/src/Corporation/ui/modals/SmartSupplyModal.tsx +++ b/src/Corporation/ui/modals/SmartSupplyModal.tsx @@ -9,8 +9,8 @@ import Typography from "@mui/material/Typography"; import FormControlLabel from "@mui/material/FormControlLabel"; import Switch from "@mui/material/Switch"; import { CorpMaterialName } from "@nsdefs"; -import { materialNames } from "../../data/Constants"; import { useRerender } from "../../../ui/React/hooks"; +import { getRecordKeys } from "../../../Types/Record"; interface ISSoptionProps { matName: CorpMaterialName; @@ -80,9 +80,8 @@ export function SmartSupplyModal(props: IProps): React.ReactElement { // Create React components for materials const mats = []; - for (const matName of Object.values(materialNames)) { + for (const matName of getRecordKeys(division.requiredMaterials)) { if (!props.warehouse.materials[matName]) continue; - if (!Object.keys(division.requiredMaterials).includes(matName)) continue; mats.push(); }