From 5bb2b5f97b1909eaa326832630e9cc14e03455b9 Mon Sep 17 00:00:00 2001 From: Mitja Belak Date: Sat, 26 Oct 2024 15:03:27 +0200 Subject: [PATCH] Enables the counter to display sub zero amounts per second + prices and profits adjusted to match the contract --- app/src/components/Army.tsx | 35 +++++++++++++++++++--------------- app/src/components/Counter.tsx | 7 ++++--- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/src/components/Army.tsx b/app/src/components/Army.tsx index 428931d..cc12d55 100644 --- a/app/src/components/Army.tsx +++ b/app/src/components/Army.tsx @@ -4,14 +4,24 @@ import styles from '../styles/Army.module.css'; import { calculateBalance, toReadable } from './Counter'; const PRECISION = BigInt(10000); -const BASE_PRICE = BigInt(380000); const PRICE_FACTOR = BigInt(11500); -const APPRENTICE_PROFIT = BigInt(61000); -const ANOINTED_PROFIT = BigInt(6 * 64000); -const CHAMPION_PROFIT = BigInt(BigInt(67000 * 61000 * 64000) / PRECISION / PRECISION); + +const base_cost: Record = { + 0: BigInt(380000), + 1: BigInt(3420000), + 2: BigInt(30096000), + 3: BigInt(255816000), +} + +const profits: Record = { + 0: BigInt(2533), + 1: BigInt(27863), + 2: BigInt(306493), + 3: BigInt(3371423), +} function calculateUnitPrice(unit: UnitType, currentLevel: number, units: number) { - let rollingPriceCalculation = BigInt(unit + 1) * BASE_PRICE; + let rollingPriceCalculation = base_cost[unit]; let price = BigInt(0); // Each level costs 15% more than previous @@ -26,12 +36,7 @@ function calculateUnitPrice(unit: UnitType, currentLevel: number, units: number) function calculateProfitPerSecond(unit: UnitType, level: number) { // Each next unit scales progressivelly better - switch (unit) { - case 0: return BigInt(level) * PRECISION - case 1: return BigInt(level) * APPRENTICE_PROFIT - case 2: return BigInt(level) * ANOINTED_PROFIT - case 3: return BigInt(level) * CHAMPION_PROFIT - } + return BigInt(level) * profits[unit] } const unitTypeToCss: Record = { @@ -79,8 +84,8 @@ interface UnitProps { const Unit = ({ addUnit, unitType, canPurchase, isShrouded, n_units }: UnitProps) => { const [unitPrice, unitProfit] = useMemo(() => { return [ - toReadable(calculateUnitPrice(unitType, n_units, 1)) + " geld", - toReadable(calculateProfitPerSecond(unitType, n_units)) + " geld / sec" + toReadable(calculateUnitPrice(unitType, n_units, 1)), + toReadable(calculateProfitPerSecond(unitType, n_units)) ] }, [n_units, unitType]); return
addUnit(unitType)} className={`${styles.armyUnit} ${canPurchase ? "" : styles.isUnavailable}`}> @@ -91,9 +96,9 @@ const Unit = ({ addUnit, unitType, canPurchase, isShrouded, n_units }: UnitProps ${isShrouded ? styles.isShrouded : ""} `} /> {isShrouded ? "???????" : unitTypeToName[unitType]} - {isShrouded ? null : {unitPrice}} + {isShrouded ? null : {unitPrice} GELD} {n_units > 0 ? {n_units} : null} - {n_units > 0 ? {unitProfit} : null} + {n_units > 0 ? {unitProfit} per sec : null}
} diff --git a/app/src/components/Counter.tsx b/app/src/components/Counter.tsx index d188dcf..b1c0a32 100644 --- a/app/src/components/Counter.tsx +++ b/app/src/components/Counter.tsx @@ -1,6 +1,7 @@ import { useEffect, useReducer, useRef } from "react"; import { usePlayer } from "../providers/PlayerProvider" import styles from "../styles/Header.module.css" +import { formatUnits } from "viem"; export const calculateBalance = (balance: bigint, perSecond: bigint, lastRaidedAt: bigint) => { // convert to milliseconds trick so we get a more smooth counter @@ -12,8 +13,8 @@ export const calculateBalance = (balance: bigint, perSecond: bigint, lastRaidedA / BigInt(1000) /* deduct milliseconds*/)) } -export const toReadable = (value: bigint) => { - value = value / BigInt(10000); +export const toReadable = (rawValue: bigint) => { + const value = rawValue / BigInt(10000); const suffixes = [ { value: BigInt('1000'), suffix: 'thousand' }, { value: BigInt('1000000'), suffix: 'million' }, @@ -38,7 +39,7 @@ export const toReadable = (value: bigint) => { for (let i = 0; i < suffixes.length; i++) { if (value < suffixes[i].value) { if (i == 0) { - return value.toString(); + return formatUnits(rawValue, 4); } else { const divided = value / suffixes[i - 1].value; const numStr = (value % suffixes[i - 1].value).toString().slice(0, 3);