Skip to content

Commit

Permalink
fixed Exo cost
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Jan 21, 2024
1 parent 77c1f92 commit 425832b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/frontend/src/components/boxes/ResearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const ResearchBox = ({
);

const baseCosts = baseTechCost[functionCallName];
const isExo = functionCallName === 18;
// Calculate the cumulative cost of the upgrade
const upgradeCost = useMemo(() => {
if (quantity > 0 && level != undefined) {
Expand All @@ -44,12 +45,13 @@ const ResearchBox = ({
quantity,
baseCosts.steel,
baseCosts.quartz,
baseCosts.tritium
baseCosts.tritium,
isExo
);
return cost;
}
return { steel: 0, quartz: 0, tritium: 0 };
}, [level, quantity, baseCosts]);
}, [level, quantity, baseCosts, isExo]);

const hasEnoughResources = calculEnoughResources(
upgradeCost,
Expand Down
26 changes: 19 additions & 7 deletions packages/frontend/src/shared/utils/Formulas.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { baseTechCost } from '../../constants/costs';

const GROWTH_FACTOR_LINEAR = 1.1;
const GROWTH_FACTOR_QUARTZ = 1.6;
const GROWTH_FACTOR_STEEL = 1.5;
Expand Down Expand Up @@ -117,6 +119,13 @@ export function techCostFormula(
return { steel, quartz, tritium };
}

export function exoTechFormula(level: number) {
const steel = Math.round(baseTechCost[18].steel * Math.pow(1.75, level));
const quartz = Math.round(baseTechCost[18].quartz * Math.pow(1.75, level));
const tritium = Math.round(baseTechCost[18].tritium * Math.pow(1.75, level));
return { steel, quartz, tritium };
}

export function calculateFleetLoss(timeSeconds: number): number {
const decay = Math.exp(-0.02 * (timeSeconds / 60));

Expand Down Expand Up @@ -206,17 +215,20 @@ export const getCumulativeTechCost = (
quantity: number,
baseSteelCost: number,
baseQuartzCost: number,
baseTritiumCost: number
baseTritiumCost: number,
isExo: boolean
) => {
const totalCost = { steel: 0, quartz: 0, tritium: 0 };

for (let i = 0; i < quantity; i++) {
const costAtLevel = techCostFormula(
level + i,
baseSteelCost,
baseQuartzCost,
baseTritiumCost
);
const costAtLevel = isExo
? exoTechFormula(level + i)
: techCostFormula(
level + i,
baseSteelCost,
baseQuartzCost,
baseTritiumCost
);

totalCost.steel += costAtLevel.steel;
totalCost.quartz += costAtLevel.quartz;
Expand Down

0 comments on commit 425832b

Please sign in to comment.