1
0
forked from mico/idle_moloch

Enables the counter to display sub zero amounts per second + prices and profits adjusted to match the contract

This commit is contained in:
mic0 2024-10-26 15:03:27 +02:00
parent 0ea4ba320c
commit 5bb2b5f97b
Signed by: mico
GPG Key ID: A3F8023524CF1C8D
2 changed files with 24 additions and 18 deletions

View File

@ -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<UnitType, bigint> = {
0: BigInt(380000),
1: BigInt(3420000),
2: BigInt(30096000),
3: BigInt(255816000),
}
const profits: Record<UnitType, bigint> = {
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<UnitType, string> = {
@ -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 <div onClick={() => addUnit(unitType)} className={`${styles.armyUnit} ${canPurchase ? "" : styles.isUnavailable}`}>
@ -91,9 +96,9 @@ const Unit = ({ addUnit, unitType, canPurchase, isShrouded, n_units }: UnitProps
${isShrouded ? styles.isShrouded : ""}
`} />
<span className={`${styles.unitName} ${styles.uiElement}`}>{isShrouded ? "???????" : unitTypeToName[unitType]}</span>
{isShrouded ? null : <span className={`${styles.unitPrice} ${styles.uiElement}`}>{unitPrice}</span>}
{isShrouded ? null : <span className={`${styles.unitPrice} ${styles.uiElement}`}>{unitPrice} <small>GELD</small></span>}
{n_units > 0 ? <span className={`${styles.unitSupply} ${styles.uiElement}`}>{n_units}</span> : null}
{n_units > 0 ? <span className={`${styles.unitProfit} ${styles.uiElement}`}>{unitProfit}</span> : null}
{n_units > 0 ? <span className={`${styles.unitProfit} ${styles.uiElement}`}>{unitProfit} <small>per sec</small></span> : null}
</div>
}

View File

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