Compare commits
No commits in common. "9a0ab2963a94ae1a9a6e24c6a1676d0b2f9d915e" and "eb318972b884dfb0d41cbf69bb6a2bc6ba5f7c91" have entirely different histories.
9a0ab2963a
...
eb318972b8
@ -1,177 +1,26 @@
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
import { usePlayer } from '../providers/PlayerProvider';
|
||||||
import { UnitType, usePlayer } from '../providers/PlayerProvider';
|
|
||||||
import styles from '../styles/Army.module.css';
|
import styles from '../styles/Army.module.css';
|
||||||
import { calculateBalance, toReadable } from './Counter';
|
|
||||||
|
|
||||||
const PRECISION = BigInt(10000);
|
const Army = () => {
|
||||||
const PRICE_FACTOR = BigInt(11500);
|
const { army, addUnit, isRegistered } = usePlayer()
|
||||||
|
return <div className="styles.armyGathering">
|
||||||
|
<div className={`${styles.tavern_keeper} ${styles.person} ${styles.static}`} />
|
||||||
|
{isRegistered && <>
|
||||||
|
<div onClick={() => addUnit(0)} className={`${styles.scribe} ${styles.person} ${styles.moloch_denier} ${styles.static}`}>
|
||||||
|
<div className={styles.supply}>Moloch denier: {army?.moloch_denier.level}</div>
|
||||||
|
</div>
|
||||||
|
<div onClick={() => addUnit(1)} className={`${styles.druid} ${styles.person} ${styles.apprentice} ${styles.static}`} >
|
||||||
|
<div className={styles.supply}>Apprentice: {army?.apprentice.level}</div>
|
||||||
|
</div>
|
||||||
|
<div onClick={() => addUnit(2)} className={`${styles.ranger} ${styles.person} ${styles.anointed} ${styles.static}`} >
|
||||||
|
<div className={styles.supply}>Anointed: {army?.anointed.level}</div>
|
||||||
|
</div>
|
||||||
|
<div onClick={() => addUnit(3)} className={`${styles.warrior} ${styles.person} ${styles.champion} ${styles.static}`} >
|
||||||
|
<div className={styles.supply}>Champion: {army?.champion.level}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
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 = base_cost[unit];
|
|
||||||
let price = BigInt(0);
|
|
||||||
|
|
||||||
// Each level costs 15% more than previous
|
|
||||||
for (let i = 0; i < currentLevel + units; i++) {
|
|
||||||
if (i >= currentLevel) {
|
|
||||||
price += rollingPriceCalculation;
|
|
||||||
}
|
|
||||||
rollingPriceCalculation = rollingPriceCalculation * PRICE_FACTOR / PRECISION;
|
|
||||||
}
|
|
||||||
return price;
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculateProfitPerSecond(unit: UnitType, level: number) {
|
|
||||||
// Each next unit scales progressivelly better
|
|
||||||
return BigInt(level) * profits[unit]
|
|
||||||
}
|
|
||||||
|
|
||||||
const unitTypeToCss: Record<UnitType, string> = {
|
|
||||||
0: styles.moloch_denier,
|
|
||||||
1: styles.apprentice,
|
|
||||||
2: styles.anointed,
|
|
||||||
3: styles.champion
|
|
||||||
}
|
|
||||||
|
|
||||||
const unitTypeToName: Record<UnitType, string> = {
|
|
||||||
0: "Moloch denier",
|
|
||||||
1: "Apprentice",
|
|
||||||
2: "Anointed",
|
|
||||||
3: "Champion"
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaultAvailabilityMap: Record<UnitType, boolean> = {
|
|
||||||
0: false,
|
|
||||||
1: false,
|
|
||||||
2: false,
|
|
||||||
3: false
|
|
||||||
}
|
|
||||||
|
|
||||||
const unitDiscoveredAt: Record<UnitType, bigint> = {
|
|
||||||
0: BigInt(0),
|
|
||||||
1: BigInt(300_0000),
|
|
||||||
2: BigInt(2800_0000),
|
|
||||||
3: BigInt(24000_0000)
|
|
||||||
}
|
|
||||||
const unitAvailableToDiscoverAt: Record<UnitType, bigint> = {
|
|
||||||
0: BigInt(0),
|
|
||||||
1: BigInt(200_0000),
|
|
||||||
2: BigInt(2000_0000),
|
|
||||||
3: BigInt(25000_0000),
|
|
||||||
}
|
|
||||||
|
|
||||||
interface UnitProps {
|
|
||||||
addUnit: (unitType: UnitType) => void;
|
|
||||||
unitType: UnitType;
|
|
||||||
canPurchase: boolean;
|
|
||||||
isShrouded: boolean;
|
|
||||||
n_units: number
|
|
||||||
}
|
|
||||||
|
|
||||||
const Unit = ({ addUnit, unitType, canPurchase, isShrouded, n_units }: UnitProps) => {
|
|
||||||
const [unitPrice, unitProfit] = useMemo(() => {
|
|
||||||
return [
|
|
||||||
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}`}>
|
|
||||||
<div className={`
|
|
||||||
${unitTypeToCss[unitType]}
|
|
||||||
${styles.person}
|
|
||||||
${styles.static}
|
|
||||||
${isShrouded ? styles.isShrouded : ""}
|
|
||||||
`} />
|
|
||||||
<span className={`${styles.unitName} ${styles.uiElement}`}>{isShrouded ? "???????" : unitTypeToName[unitType]}</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} <small>per sec</small></span> : null}
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
const Army = () => {
|
|
||||||
const { army, addUnit, isRegistered, player, balance } = usePlayer()
|
|
||||||
const [canPurchase, setCanPurchase] = useState<Record<UnitType, boolean>>(defaultAvailabilityMap);
|
|
||||||
const [isShrouded, setIsShrouded] = useState<Record<UnitType, boolean>>(defaultAvailabilityMap);
|
|
||||||
const [canKnowAbout, setCanKnowAbout] = useState<Record<UnitType, boolean>>(defaultAvailabilityMap);
|
|
||||||
const balanceCount = useRef(BigInt(balance ?? 0))
|
|
||||||
|
|
||||||
const setAvailabilities = useCallback(() => {
|
|
||||||
if (isRegistered) {
|
|
||||||
const totalMinted = (player?.total_minted ?? BigInt(0)) + (balanceCount.current - (balance ?? BigInt(0)));
|
|
||||||
const n_units: Record<UnitType, number> = {
|
|
||||||
0: army?.moloch_denier.level ?? 0,
|
|
||||||
1: army?.apprentice.level ?? 0,
|
|
||||||
2: army?.anointed.level ?? 0,
|
|
||||||
3: army?.champion.level ?? 0,
|
|
||||||
}
|
|
||||||
const inShroud = {
|
|
||||||
0: totalMinted < unitDiscoveredAt[0],
|
|
||||||
1: totalMinted < unitDiscoveredAt[1],
|
|
||||||
2: totalMinted < unitDiscoveredAt[2],
|
|
||||||
3: totalMinted < unitDiscoveredAt[3],
|
|
||||||
}
|
|
||||||
const isKnown = {
|
|
||||||
0: totalMinted >= unitAvailableToDiscoverAt[0],
|
|
||||||
1: totalMinted >= unitAvailableToDiscoverAt[1],
|
|
||||||
2: totalMinted >= unitAvailableToDiscoverAt[2],
|
|
||||||
3: totalMinted >= unitAvailableToDiscoverAt[3],
|
|
||||||
}
|
|
||||||
const canActuallyBuy = {
|
|
||||||
0: balanceCount.current >= calculateUnitPrice(0, n_units[0], 1) && isKnown[0] && !inShroud[0],
|
|
||||||
1: balanceCount.current >= calculateUnitPrice(1, n_units[1], 1) && isKnown[1] && !inShroud[1],
|
|
||||||
2: balanceCount.current >= calculateUnitPrice(2, n_units[2], 1) && isKnown[2] && !inShroud[2],
|
|
||||||
3: balanceCount.current >= calculateUnitPrice(3, n_units[3], 1) && isKnown[3] && !inShroud[3],
|
|
||||||
};
|
|
||||||
setCanPurchase(canActuallyBuy)
|
|
||||||
setIsShrouded(inShroud)
|
|
||||||
setCanKnowAbout(isKnown)
|
|
||||||
} else {
|
|
||||||
setCanPurchase(defaultAvailabilityMap)
|
|
||||||
setIsShrouded(defaultAvailabilityMap)
|
|
||||||
setCanKnowAbout(defaultAvailabilityMap)
|
|
||||||
}
|
|
||||||
}, [
|
|
||||||
army,
|
|
||||||
balance,
|
|
||||||
isRegistered,
|
|
||||||
player?.total_minted
|
|
||||||
])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const tickInterval = setInterval(() => {
|
|
||||||
balanceCount.current = calculateBalance(
|
|
||||||
balance ?? BigInt(0),
|
|
||||||
army?.profit_per_second ?? BigInt(0),
|
|
||||||
player?.last_raided_at ?? BigInt(0)
|
|
||||||
);
|
|
||||||
setAvailabilities()
|
|
||||||
}, 100);
|
|
||||||
return () => clearInterval(tickInterval)
|
|
||||||
}, [balance, army?.profit_per_second, player?.last_raided_at, setAvailabilities])
|
|
||||||
|
|
||||||
return <>
|
|
||||||
<div className={`${styles.tavern_keeper} ${styles.person} ${styles.static}`} />
|
|
||||||
<div className={styles.armyUnits}>
|
|
||||||
{canKnowAbout[0] && <Unit n_units={army?.moloch_denier.level ?? 0} addUnit={addUnit} unitType={0} canPurchase={canPurchase[0]} isShrouded={isShrouded[0]} />}
|
|
||||||
{canKnowAbout[1] && <Unit n_units={army?.apprentice.level ?? 0} addUnit={addUnit} unitType={1} canPurchase={canPurchase[1]} isShrouded={isShrouded[1]} />}
|
|
||||||
{canKnowAbout[2] && <Unit n_units={army?.anointed.level ?? 0} addUnit={addUnit} unitType={2} canPurchase={canPurchase[2]} isShrouded={isShrouded[2]} />}
|
|
||||||
{canKnowAbout[3] && <Unit n_units={army?.champion.level ?? 0} addUnit={addUnit} unitType={3} canPurchase={canPurchase[3]} isShrouded={isShrouded[3]} />}
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Army
|
export default Army
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
import { useEffect, useReducer, useRef } from "react";
|
import { useEffect, useReducer, useRef } from "react";
|
||||||
import { usePlayer } from "../providers/PlayerProvider"
|
import { usePlayer } from "../providers/PlayerProvider"
|
||||||
import styles from "../styles/Header.module.css"
|
import styles from "../styles/Header.module.css"
|
||||||
import { formatUnits } from "viem";
|
|
||||||
|
|
||||||
export const calculateBalance = (balance: bigint, perSecond: bigint, lastRaidedAt: bigint) => {
|
const calculateBalance = (balance: bigint, perSecond: bigint, lastRaidedAt: bigint) => {
|
||||||
// convert to milliseconds trick so we get a more smooth counter
|
// convert to milliseconds trick so we get a more smooth counter
|
||||||
const millisecondsSinceLastRaid =
|
const millisecondsSinceLastRaid =
|
||||||
(new Date()).getTime() - parseInt(lastRaidedAt.toString()) * 1000;
|
(new Date()).getTime() - parseInt(lastRaidedAt.toString()) * 1000;
|
||||||
@ -13,8 +12,8 @@ export const calculateBalance = (balance: bigint, perSecond: bigint, lastRaidedA
|
|||||||
/ BigInt(1000) /* deduct milliseconds*/))
|
/ BigInt(1000) /* deduct milliseconds*/))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const toReadable = (rawValue: bigint) => {
|
export const toReadable = (value: bigint) => {
|
||||||
const value = rawValue / BigInt(10000);
|
value = value / BigInt(10000);
|
||||||
const suffixes = [
|
const suffixes = [
|
||||||
{ value: BigInt('1000'), suffix: 'thousand' },
|
{ value: BigInt('1000'), suffix: 'thousand' },
|
||||||
{ value: BigInt('1000000'), suffix: 'million' },
|
{ value: BigInt('1000000'), suffix: 'million' },
|
||||||
@ -39,7 +38,7 @@ export const toReadable = (rawValue: bigint) => {
|
|||||||
for (let i = 0; i < suffixes.length; i++) {
|
for (let i = 0; i < suffixes.length; i++) {
|
||||||
if (value < suffixes[i].value) {
|
if (value < suffixes[i].value) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
return formatUnits(rawValue, 4);
|
return value.toString();
|
||||||
} else {
|
} else {
|
||||||
const divided = value / suffixes[i - 1].value;
|
const divided = value / suffixes[i - 1].value;
|
||||||
const numStr = (value % suffixes[i - 1].value).toString().slice(0, 3);
|
const numStr = (value % suffixes[i - 1].value).toString().slice(0, 3);
|
||||||
@ -74,7 +73,7 @@ const Counter = () => {
|
|||||||
<p className={styles.counter}>
|
<p className={styles.counter}>
|
||||||
{balanceCount.current} GELD
|
{balanceCount.current} GELD
|
||||||
</p>
|
</p>
|
||||||
<p className={styles.counter_available}>in wallet: {availableBalance.current} GELD</p>
|
<p className={styles.counter_available}>available on chain: {availableBalance.current} GELD</p>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import React, { useCallback, useMemo } from "react"
|
import React, { useCallback, useMemo } from "react"
|
||||||
import styles from "../styles/Header.module.css"
|
import styles from "../styles/Header.module.css"
|
||||||
import bgStyles from "../styles/Background.module.css"
|
|
||||||
import { usePlayer } from "../providers/PlayerProvider";
|
import { usePlayer } from "../providers/PlayerProvider";
|
||||||
import { useAccount } from 'wagmi';
|
import { useAccount } from 'wagmi';
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
@ -37,7 +36,7 @@ const Header = () => {
|
|||||||
}, [isRegistered, register])
|
}, [isRegistered, register])
|
||||||
|
|
||||||
return <header onClick={onRegister} className={styles.header}>
|
return <header onClick={onRegister} className={styles.header}>
|
||||||
<h1 className={`${styles.title} ${isConnected && !isRegistered ? bgStyles.excited : ""}`}>{title}</h1>
|
<h1 className={styles.title}>{title}</h1>
|
||||||
{subtitle}
|
{subtitle}
|
||||||
{perSecondParagraph}
|
{perSecondParagraph}
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@ -6,8 +6,6 @@ import contractAddress from '../../contract_address'
|
|||||||
|
|
||||||
const abi = contractAbi.abi
|
const abi = contractAbi.abi
|
||||||
|
|
||||||
export type UnitType = 0 | 1 | 2 | 3
|
|
||||||
|
|
||||||
export interface Player {
|
export interface Player {
|
||||||
created_at: bigint,
|
created_at: bigint,
|
||||||
last_raided_at: bigint,
|
last_raided_at: bigint,
|
||||||
@ -28,7 +26,7 @@ export interface PlayerContextType {
|
|||||||
balance: bigint,
|
balance: bigint,
|
||||||
register: () => void,
|
register: () => void,
|
||||||
raid: () => void,
|
raid: () => void,
|
||||||
addUnit: (unit: UnitType) => void
|
addUnit: (unit: number) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const PlayerContext = createContext<PlayerContextType>({
|
const PlayerContext = createContext<PlayerContextType>({
|
||||||
@ -93,7 +91,7 @@ const PlayerProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(balance, player, army)
|
console.log(player, army)
|
||||||
|
|
||||||
const register = useCallback(() => {
|
const register = useCallback(() => {
|
||||||
writeContract({
|
writeContract({
|
||||||
@ -112,7 +110,7 @@ const PlayerProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
})
|
})
|
||||||
}, [writeContract])
|
}, [writeContract])
|
||||||
|
|
||||||
const addUnit = useCallback((unit: UnitType) => {
|
const addUnit = useCallback((unit: number) => {
|
||||||
writeContract({
|
writeContract({
|
||||||
abi,
|
abi,
|
||||||
address: contractAddress,
|
address: contractAddress,
|
||||||
|
|||||||
@ -108,78 +108,6 @@
|
|||||||
.hunter {
|
.hunter {
|
||||||
background-image: url("/roles/hunter.svg");
|
background-image: url("/roles/hunter.svg");
|
||||||
}
|
}
|
||||||
|
|
||||||
.moloch_denier {
|
|
||||||
filter: sepia(0.1);
|
|
||||||
}
|
|
||||||
.apprentice {
|
|
||||||
}
|
|
||||||
.anointed {
|
|
||||||
filter: saturate(1.1);
|
|
||||||
}
|
|
||||||
.champion {
|
|
||||||
filter: saturate(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
.armyUnits {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 22px;
|
|
||||||
left: 22px;
|
|
||||||
right: 22px;
|
|
||||||
height: 180px;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
.armyUnit {
|
|
||||||
position: relative;
|
|
||||||
height: 100%;
|
|
||||||
width: 120px;
|
|
||||||
margin-right: 20px;
|
|
||||||
.person {
|
|
||||||
&.isShrouded {
|
|
||||||
filter: brightness(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&.isUnavailable {
|
|
||||||
filter: sepia(1);
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
&:hover {
|
|
||||||
.unitProfit {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.uiElement {
|
|
||||||
position: absolute;
|
|
||||||
border-radius: 10px;
|
|
||||||
background: rgba(0, 0, 0, 0.89);
|
|
||||||
padding: 0.1rem 1rem;
|
|
||||||
font-size: 0.8rem;
|
|
||||||
user-select: none;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
.unitSupply {
|
|
||||||
top: 0;
|
|
||||||
right: 0;
|
|
||||||
}
|
|
||||||
.unitName {
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 45px;
|
|
||||||
}
|
|
||||||
.unitPrice {
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 25px;
|
|
||||||
}
|
|
||||||
.unitProfit {
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 5px;
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.static {
|
.static {
|
||||||
width: 110px;
|
width: 110px;
|
||||||
height: 110px;
|
height: 110px;
|
||||||
@ -201,18 +129,47 @@
|
|||||||
height: 90px;
|
height: 90px;
|
||||||
}
|
}
|
||||||
.static.moloch_denier {
|
.static.moloch_denier {
|
||||||
|
left: calc(20% - 60px);
|
||||||
|
bottom: 70px;
|
||||||
background-image: url("/roles/scribe2.png");
|
background-image: url("/roles/scribe2.png");
|
||||||
}
|
}
|
||||||
.static.apprentice {
|
.static.apprentice {
|
||||||
|
left: calc(36% - 60px);
|
||||||
background-image: url("/roles/druid2.png");
|
background-image: url("/roles/druid2.png");
|
||||||
|
bottom: 72px;
|
||||||
}
|
}
|
||||||
.static.anointed {
|
.static.anointed {
|
||||||
|
left: calc(50% - 60px);
|
||||||
|
bottom: 64px;
|
||||||
background-image: url("/roles/ranger2.png");
|
background-image: url("/roles/ranger2.png");
|
||||||
}
|
}
|
||||||
.static.champion {
|
.static.champion {
|
||||||
|
left: calc(64% - 60px);
|
||||||
|
bottom: 66px;
|
||||||
background-image: url("/roles/warrior2.png");
|
background-image: url("/roles/warrior2.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.moloch_denier {
|
||||||
|
filter: sepia(0.1);
|
||||||
|
}
|
||||||
|
.apprentice {
|
||||||
|
}
|
||||||
|
.anointed {
|
||||||
|
filter: saturate(1.1);
|
||||||
|
}
|
||||||
|
.champion {
|
||||||
|
filter: saturate(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.supply {
|
||||||
|
position: absolute;
|
||||||
|
bottom: -40px;
|
||||||
|
background: rgba(0, 0, 0, 0.89);
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes marching {
|
@keyframes marching {
|
||||||
0% {
|
0% {
|
||||||
transform: translate(-100px, -84px);
|
transform: translate(-100px, -84px);
|
||||||
|
|||||||
@ -48,7 +48,7 @@
|
|||||||
background-image: url("/background/tower.png");
|
background-image: url("/background/tower.png");
|
||||||
width: 218px;
|
width: 218px;
|
||||||
height: 240px;
|
height: 240px;
|
||||||
top: 150px;
|
top: 200px;
|
||||||
animation: thunder_hue_hard 12s linear infinite;
|
animation: thunder_hue_hard 12s linear infinite;
|
||||||
transition: all 0.1s cubic-bezier(0.265, 1.4, 0.68, 1.65);
|
transition: all 0.1s cubic-bezier(0.265, 1.4, 0.68, 1.65);
|
||||||
transform-origin: bottom center;
|
transform-origin: bottom center;
|
||||||
@ -82,10 +82,7 @@
|
|||||||
}
|
}
|
||||||
.tower::after {
|
.tower::after {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
content: "RAID\A(collect to wallet)";
|
content: "RAID";
|
||||||
text-align: center;
|
|
||||||
white-space: pre;
|
|
||||||
word-wrap: break-word;
|
|
||||||
left: 50px;
|
left: 50px;
|
||||||
top: 22px;
|
top: 22px;
|
||||||
}
|
}
|
||||||
@ -228,10 +225,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.excited {
|
|
||||||
animation: excited 0.5s infinite linear;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes excited {
|
@keyframes excited {
|
||||||
0%,
|
0%,
|
||||||
100% {
|
100% {
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Subproject commit 1eea5bae12ae557d589f9f0f0edae2faa47cb262
|
Subproject commit 8f24d6b04c92975e0795b5868aa0d783251cdeaa
|
||||||
@ -11,29 +11,11 @@ contract RaidGeld is ERC20, Ownable {
|
|||||||
|
|
||||||
uint256 public constant BUY_IN_AMOUNT = 0.00005 ether;
|
uint256 public constant BUY_IN_AMOUNT = 0.00005 ether;
|
||||||
uint256 public constant INITIAL_GELD = 50 * MANTISSA;
|
uint256 public constant INITIAL_GELD = 50 * MANTISSA;
|
||||||
|
uint256 public constant RAID_WAIT = 15 seconds;
|
||||||
|
|
||||||
mapping(address => Player) private players;
|
mapping(address => Player) private players;
|
||||||
mapping(address => Army) private armies;
|
mapping(address => Army) private armies;
|
||||||
|
|
||||||
// Events
|
|
||||||
event PlayerRegistered(address indexed player, uint256 initialGeld);
|
|
||||||
event RaidPerformed(
|
|
||||||
address indexed player,
|
|
||||||
uint256 totalMinted,
|
|
||||||
uint256 geldBalance
|
|
||||||
);
|
|
||||||
event UnitAdded(
|
|
||||||
address indexed player,
|
|
||||||
uint8 unitType,
|
|
||||||
uint16 nUnits,
|
|
||||||
uint256 cost,
|
|
||||||
uint256 geldBalance,
|
|
||||||
uint16 molochDenierLevel,
|
|
||||||
uint16 apprenticeLevel,
|
|
||||||
uint16 anointedLevel,
|
|
||||||
uint16 championLevel
|
|
||||||
);
|
|
||||||
|
|
||||||
// Modifier for functions that should only be available to registered players
|
// Modifier for functions that should only be available to registered players
|
||||||
modifier onlyPlayer() {
|
modifier onlyPlayer() {
|
||||||
require(players[msg.sender].created_at != 0, "Not an initiated player");
|
require(players[msg.sender].created_at != 0, "Not an initiated player");
|
||||||
@ -44,21 +26,15 @@ contract RaidGeld is ERC20, Ownable {
|
|||||||
|
|
||||||
// This effectively registers the user
|
// This effectively registers the user
|
||||||
function register() external payable {
|
function register() external payable {
|
||||||
require(
|
require(players[msg.sender].created_at == 0, "Whoops, player already exists :)");
|
||||||
players[msg.sender].created_at == 0,
|
|
||||||
"Whoops, player already exists :)"
|
|
||||||
);
|
|
||||||
require(msg.value == BUY_IN_AMOUNT, "Incorrect buy in amount");
|
require(msg.value == BUY_IN_AMOUNT, "Incorrect buy in amount");
|
||||||
|
|
||||||
// Mint some starting tokens to the player
|
// Mint some starting tokens to the player
|
||||||
_mint(msg.sender, INITIAL_GELD);
|
_mint(msg.sender, INITIAL_GELD);
|
||||||
|
|
||||||
// Set initial states
|
// Set initial states
|
||||||
players[msg.sender] = Player({
|
players[msg.sender] =
|
||||||
total_minted: INITIAL_GELD,
|
Player({total_minted: INITIAL_GELD, created_at: block.timestamp, last_raided_at: block.timestamp});
|
||||||
created_at: block.timestamp,
|
|
||||||
last_raided_at: block.timestamp
|
|
||||||
});
|
|
||||||
armies[msg.sender] = Army({
|
armies[msg.sender] = Army({
|
||||||
moloch_denier: Raider({level: 0}),
|
moloch_denier: Raider({level: 0}),
|
||||||
apprentice: Raider({level: 0}),
|
apprentice: Raider({level: 0}),
|
||||||
@ -66,9 +42,6 @@ contract RaidGeld is ERC20, Ownable {
|
|||||||
champion: Raider({level: 0}),
|
champion: Raider({level: 0}),
|
||||||
profit_per_second: 0
|
profit_per_second: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
// Emit event
|
|
||||||
emit PlayerRegistered(msg.sender, INITIAL_GELD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override for default number of decimals
|
// Override for default number of decimals
|
||||||
@ -83,24 +56,21 @@ contract RaidGeld is ERC20, Ownable {
|
|||||||
|
|
||||||
// Manual minting for itchy fingers
|
// Manual minting for itchy fingers
|
||||||
function raid() external onlyPlayer {
|
function raid() external onlyPlayer {
|
||||||
uint256 totalMinted = performRaid(msg.sender);
|
require(block.timestamp >= players[msg.sender].last_raided_at + RAID_WAIT, "Tried minting too soon");
|
||||||
|
performRaid(msg.sender);
|
||||||
// Emit event
|
|
||||||
emit RaidPerformed(msg.sender, totalMinted, balanceOf(msg.sender));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper so we can use it when buying units too
|
// Helper so we can use it when buying units too
|
||||||
function performRaid(address player) private returns (uint256) {
|
function performRaid(address player) private {
|
||||||
uint256 time_past = block.timestamp - players[player].last_raided_at;
|
uint256 time_past = block.timestamp - players[player].last_raided_at;
|
||||||
|
|
||||||
uint256 new_geld = armies[player].profit_per_second * time_past;
|
uint256 new_geld = armies[player].profit_per_second * time_past;
|
||||||
|
|
||||||
// TODO: Pink noise, make it so sometimes its better than expected
|
// TODO: Pink noise, make it so sometimes its better than expected
|
||||||
|
|
||||||
_mint(player, new_geld);
|
_mint(player, new_geld);
|
||||||
players[player].last_raided_at = block.timestamp;
|
players[player].last_raided_at = block.timestamp;
|
||||||
players[player].total_minted += new_geld;
|
players[player].total_minted = new_geld;
|
||||||
|
|
||||||
return players[player].total_minted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to get Player struct
|
// Function to get Player struct
|
||||||
@ -138,24 +108,10 @@ contract RaidGeld is ERC20, Ownable {
|
|||||||
currentLevel = army.champion.level;
|
currentLevel = army.champion.level;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 cost = RaidGeldUtils.calculateUnitPrice(
|
uint256 cost = RaidGeldUtils.calculateUnitPrice(unit, currentLevel, n_units);
|
||||||
unit,
|
|
||||||
currentLevel,
|
|
||||||
n_units
|
|
||||||
);
|
|
||||||
// First trigger a raid so player receives what he is due at to this moment
|
// First trigger a raid so player receives what he is due at to this moment
|
||||||
|
performRaid(msg.sender);
|
||||||
uint256 time_past = block.timestamp -
|
require(balanceOf(msg.sender) > cost, "Not enough GELD to add this much");
|
||||||
players[msg.sender].last_raided_at;
|
|
||||||
uint256 new_geld = armies[msg.sender].profit_per_second * time_past;
|
|
||||||
require(
|
|
||||||
balanceOf(msg.sender) + new_geld >= cost,
|
|
||||||
"Not enough GELD to add this unit"
|
|
||||||
);
|
|
||||||
uint256 totalMinted = performRaid(msg.sender);
|
|
||||||
|
|
||||||
// Emit event
|
|
||||||
emit RaidPerformed(msg.sender, totalMinted, balanceOf(msg.sender));
|
|
||||||
|
|
||||||
// TODO: Since we are first minting then burning the token, this could be simplified
|
// TODO: Since we are first minting then burning the token, this could be simplified
|
||||||
// by first calculating the difference and then minting / burning in just one operation
|
// by first calculating the difference and then minting / burning in just one operation
|
||||||
@ -180,25 +136,10 @@ contract RaidGeld is ERC20, Ownable {
|
|||||||
|
|
||||||
// update profite per second
|
// update profite per second
|
||||||
army.profit_per_second = RaidGeldUtils.calculateProfitsPerSecond(army);
|
army.profit_per_second = RaidGeldUtils.calculateProfitsPerSecond(army);
|
||||||
|
|
||||||
// Emit event
|
|
||||||
emit UnitAdded(
|
|
||||||
msg.sender,
|
|
||||||
unit,
|
|
||||||
n_units,
|
|
||||||
cost,
|
|
||||||
balanceOf(msg.sender),
|
|
||||||
army.moloch_denier.level,
|
|
||||||
army.apprentice.level,
|
|
||||||
army.anointed.level,
|
|
||||||
army.champion.level
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
receive() external payable {
|
receive() external payable {
|
||||||
revert(
|
revert("No plain Ether accepted, use register() function to check in :)");
|
||||||
"No plain Ether accepted, use register() function to check in :)"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Revert any non-function-call Ether transfers or calls to non-existent functions
|
// Revert any non-function-call Ether transfers or calls to non-existent functions
|
||||||
|
|||||||
@ -5,38 +5,24 @@ import {Army} from "../src/RaidGeldStructs.sol";
|
|||||||
|
|
||||||
library RaidGeldUtils {
|
library RaidGeldUtils {
|
||||||
uint256 public constant PRECISION = 10000;
|
uint256 public constant PRECISION = 10000;
|
||||||
|
uint256 constant BASE_PRICE = 380000;
|
||||||
uint256 constant PRICE_FACTOR = 11500;
|
uint256 constant PRICE_FACTOR = 11500;
|
||||||
|
uint256 constant APPRENTICE_PROFIT = 61000;
|
||||||
// base price * (0.00666) * 11 per each next unit
|
uint256 constant ANOINTED_PROFIT = 6 * 64000;
|
||||||
uint256 constant MOLOCH_DENIER_PROFIT = 2533;
|
uint256 constant CHAMPION_PROFIT = 67000 * 61000 * 64000 / PRECISION / PRECISION;
|
||||||
uint256 constant APPRENTICE_PROFIT = 27863;
|
|
||||||
uint256 constant ANOINTED_PROFIT = 306493;
|
|
||||||
uint256 constant CHAMPION_PROFIT = 3371423;
|
|
||||||
|
|
||||||
// each costs 10 times plus a bit more
|
|
||||||
uint256 constant MOLOCH_DENIER_BASE_COST = 380000;
|
|
||||||
uint256 constant APPRENTICE_BASE_COST = 3420000;
|
|
||||||
uint256 constant ANOINTED_BASE_COST = 30096000;
|
|
||||||
uint256 constant CHAMPION_BASE_COST = 255816000;
|
|
||||||
|
|
||||||
function calculateUnitPrice(uint8 unit, uint16 currentLevel, uint16 units) internal pure returns (uint256) {
|
function calculateUnitPrice(uint8 unit, uint16 currentLevel, uint16 units) internal pure returns (uint256) {
|
||||||
require(unit <= 3, "No matching unit found");
|
require(unit <= 3, "No matching unit found");
|
||||||
uint256 rollingPriceCalculation = MOLOCH_DENIER_BASE_COST;
|
|
||||||
uint256 price = 0;
|
uint256 rollingPriceCalculation = uint256(unit + 1) * BASE_PRICE;
|
||||||
if (unit == 1) {
|
uint256 price = rollingPriceCalculation;
|
||||||
rollingPriceCalculation = APPRENTICE_BASE_COST;
|
|
||||||
} else if (unit == 2) {
|
|
||||||
rollingPriceCalculation = ANOINTED_BASE_COST;
|
|
||||||
} else if (unit == 3) {
|
|
||||||
rollingPriceCalculation = CHAMPION_BASE_COST;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Each level costs 15% more than previous
|
// Each level costs 15% more than previous
|
||||||
for (uint256 i = 0; i < currentLevel + units; i++) {
|
for (uint256 i = 1; i < currentLevel + units; i++) {
|
||||||
|
rollingPriceCalculation = rollingPriceCalculation * PRICE_FACTOR / PRECISION;
|
||||||
if (i >= currentLevel) {
|
if (i >= currentLevel) {
|
||||||
price += rollingPriceCalculation;
|
price += rollingPriceCalculation;
|
||||||
}
|
}
|
||||||
rollingPriceCalculation = rollingPriceCalculation * PRICE_FACTOR / PRECISION;
|
|
||||||
}
|
}
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
@ -44,9 +30,12 @@ library RaidGeldUtils {
|
|||||||
function calculateProfitsPerSecond(Army memory army) internal pure returns (uint256) {
|
function calculateProfitsPerSecond(Army memory army) internal pure returns (uint256) {
|
||||||
// Each next unit scales progressivelly better
|
// Each next unit scales progressivelly better
|
||||||
|
|
||||||
uint256 moloch_denier_profit = army.moloch_denier.level * MOLOCH_DENIER_PROFIT;
|
uint256 moloch_denier_profit = army.moloch_denier.level * PRECISION;
|
||||||
|
|
||||||
uint256 apprentice_profit = army.apprentice.level * APPRENTICE_PROFIT;
|
uint256 apprentice_profit = army.apprentice.level * APPRENTICE_PROFIT;
|
||||||
|
|
||||||
uint256 anointed_profit = army.anointed.level * ANOINTED_PROFIT;
|
uint256 anointed_profit = army.anointed.level * ANOINTED_PROFIT;
|
||||||
|
|
||||||
uint256 champion_profit = army.champion.level * CHAMPION_PROFIT;
|
uint256 champion_profit = army.champion.level * CHAMPION_PROFIT;
|
||||||
|
|
||||||
return moloch_denier_profit + apprentice_profit + anointed_profit + champion_profit;
|
return moloch_denier_profit + apprentice_profit + anointed_profit + champion_profit;
|
||||||
|
|||||||
@ -148,10 +148,11 @@ contract raid_geldTest is Test {
|
|||||||
|
|
||||||
// bought 1 moloch_denier
|
// bought 1 moloch_denier
|
||||||
raid_geld.addUnit(0, 1);
|
raid_geld.addUnit(0, 1);
|
||||||
vm.warp(block.timestamp + 15);
|
|
||||||
|
|
||||||
uint256 balance = raid_geld.balanceOf(player1);
|
uint256 balance = raid_geld.balanceOf(player1);
|
||||||
|
|
||||||
|
// Warp time a bit so first raid doesnt fail
|
||||||
|
vm.warp(block.timestamp + raid_geld.RAID_WAIT());
|
||||||
// Trigger raid funds minting
|
// Trigger raid funds minting
|
||||||
raid_geld.raid();
|
raid_geld.raid();
|
||||||
|
|
||||||
@ -161,8 +162,12 @@ contract raid_geldTest is Test {
|
|||||||
uint256 last_raided_at = player.last_raided_at;
|
uint256 last_raided_at = player.last_raided_at;
|
||||||
assertLt(balance, newBalance);
|
assertLt(balance, newBalance);
|
||||||
|
|
||||||
// After wait time passes raid should bring in profits again
|
// Expect fail if we raid again, we need to wait a bit
|
||||||
vm.warp(block.timestamp + 15);
|
vm.expectRevert();
|
||||||
|
raid_geld.raid();
|
||||||
|
|
||||||
|
// After wait time passes raid should work again
|
||||||
|
vm.warp(block.timestamp + raid_geld.RAID_WAIT());
|
||||||
raid_geld.raid();
|
raid_geld.raid();
|
||||||
|
|
||||||
// Balance should reflect that
|
// Balance should reflect that
|
||||||
|
|||||||
@ -9,7 +9,7 @@ contract raid_geldTest is Test {
|
|||||||
function test_0_unit_price() public pure {
|
function test_0_unit_price() public pure {
|
||||||
// buying 1 unit of moloch_denier
|
// buying 1 unit of moloch_denier
|
||||||
uint256 basePriceMolochDenier = RaidGeldUtils.calculateUnitPrice(0, 0, 1);
|
uint256 basePriceMolochDenier = RaidGeldUtils.calculateUnitPrice(0, 0, 1);
|
||||||
assertEq(basePriceMolochDenier, RaidGeldUtils.MOLOCH_DENIER_BASE_COST);
|
assertEq(basePriceMolochDenier, RaidGeldUtils.BASE_PRICE);
|
||||||
|
|
||||||
// buying 3 units
|
// buying 3 units
|
||||||
// has to be a bit more than 3 * 38 = 114
|
// has to be a bit more than 3 * 38 = 114
|
||||||
@ -37,7 +37,7 @@ contract raid_geldTest is Test {
|
|||||||
profit_per_second: 0 // irrelevant for this test
|
profit_per_second: 0 // irrelevant for this test
|
||||||
});
|
});
|
||||||
uint256 profits_per_second = RaidGeldUtils.calculateProfitsPerSecond(army);
|
uint256 profits_per_second = RaidGeldUtils.calculateProfitsPerSecond(army);
|
||||||
assertEq(profits_per_second, RaidGeldUtils.MOLOCH_DENIER_PROFIT);
|
assertEq(profits_per_second, RaidGeldUtils.PRECISION);
|
||||||
|
|
||||||
army = Army({
|
army = Army({
|
||||||
moloch_denier: Raider({level: _dLvl}),
|
moloch_denier: Raider({level: _dLvl}),
|
||||||
@ -47,7 +47,7 @@ contract raid_geldTest is Test {
|
|||||||
profit_per_second: 0 // irrelevant for this test
|
profit_per_second: 0 // irrelevant for this test
|
||||||
});
|
});
|
||||||
profits_per_second = RaidGeldUtils.calculateProfitsPerSecond(army);
|
profits_per_second = RaidGeldUtils.calculateProfitsPerSecond(army);
|
||||||
uint256 expected = _dLvl * RaidGeldUtils.MOLOCH_DENIER_PROFIT + _apLvl * RaidGeldUtils.APPRENTICE_PROFIT
|
uint256 expected = _dLvl * RaidGeldUtils.PRECISION + _apLvl * RaidGeldUtils.APPRENTICE_PROFIT
|
||||||
+ _anLvl * RaidGeldUtils.ANOINTED_PROFIT + _cLvl * RaidGeldUtils.CHAMPION_PROFIT;
|
+ _anLvl * RaidGeldUtils.ANOINTED_PROFIT + _cLvl * RaidGeldUtils.CHAMPION_PROFIT;
|
||||||
assertEq(profits_per_second, expected);
|
assertEq(profits_per_second, expected);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user