# Economy System

## Overview
Advenexus has a dual-currency economy with **Coins (🪙)** and **Gems (💎)**, plus a premium **Cash (💵)** currency. Players earn coins through hunting, battling, daily rewards, dungeons, and gambling. Gems are earned mainly through voting and sacrificing animals. The economy includes quests, giving, stealing, a guard dog defense system, and inventory management with capacity limits.

---

## Commands

| Command | Description | Cooldown |
|---|---|---|
| `.daily` | Claim daily coin + lootbox + crate reward | 24 hours |
| `.vote` | Claim vote reward (500 🪙 + 10 💎) | 12 hours |
| `.money` / `.balance` | View your coin/gem balance | — |
| `.profile [@user]` | View player profile and stats | — |
| `.give @user <amount>` | Send coins to another player | 3x per 5 hours |
| `.quest` | View or start a daily quest | — |
| `.get items` | Claim items from temporary overflow storage | — |

---

## Currencies

### Coins (🪙)
The primary currency. Used for:
- Buying weapons, lootboxes, crates, guard dogs, diamonds
- Guild bank deposits
- Dungeon entry fees
- Gambling

### Gems (💎)
Secondary currency. Used for:
- Weapon rerolls (700 💎 per reroll)
- Gem shop purchases

Earned from:
- Voting (+10 💎)
- Dismantling weapons (1–1,000 💎 based on rarity)
- Sacrificing animals

### Cash (💵)
Premium currency purchased with real money. Used for:
- Guild capacity upgrades (250 💵 per slot)
- Premium cosmetics

---

## Daily Reward

- **Base:** 300–500 🪙 (random)
- **Level bonus:** min(level, 25) × 20
- **Streak multiplier** (based on battle win streak):

| Win Streak | Multiplier |
|---|---|
| 0–6 | 1× |
| 7–13 | 2× |
| 14–20 | 4× |
| 21–27 | 6× |
| 28+ | 8× |

**Formula:** `total = round(base × streakMultiplier + levelBonus)`

- Also gives: **+1 Lootbox** and **+1 Weapon Crate** every daily

---

## ELO Rank Tiers

| Rank | ELO Threshold |
|---|---|
| Iron | 0–499 |
| Bronze | 500–799 |
| Silver | 800–1,199 |
| Gold | 1,200–1,699 |
| Platinum | 1,700–2,299 |
| Diamond | 2,300–2,999 |
| Master | 3,000–3,799 |
| Grandmaster | 3,800–4,499 |
| Legend | 4,500+ |

---

## Give (Transfer Coins)

- Send coins to any other player
- **Rate limit:** max 3 transfers per 5-hour window (spam prevention)
- Gifts of 10,000+ coins trigger a celebration animation
- Cannot give more than your balance

---

## Quests

Random daily objectives with coin + XP rewards.

| Quest | Goal | Coins | XP |
|---|---|---|---|
| Hunt 5 animals | 5 hunts | 2,000 🪙 | 100 |
| Hunt 20 animals | 20 hunts | 10,000 🪙 | 500 |
| Win 3 battles | 3 wins | 5,000 🪙 | 300 |
| Catch a Rare animal | 1 catch | 3,000 🪙 | 200 |
| Spend 500 🪙 in shop | 500 spent | 8,000 🪙 | 400 |

- One active quest at a time
- Quest expires after **24 hours** if not completed
- New quest auto-assigns when no active quest exists

---

## Gambling

### Coinflip (`.coinflip <bet> <heads/tails>`)
- **Cooldown:** 5 seconds
- **Max bet:** 100,000 🪙
- 50/50 odds — win = double your bet, lose = lose your bet

### Slots (`.slots <bet>`)
- **Cooldown:** 10 seconds
- **Max bet:** 100,000 🪙
- **8% house edge** on wins

| Outcome | Probability | Payout |
|---|---|---|
| 🍒🍒🍒 | 37% | 2× bet |
| 🍀🍀🍀 | 10% | Push (bet returned) |
| 💎💎💎 | 3% | 5× bet |
| 🎰🎰🎰 | 0.05% | 20× bet (jackpot) |
| No match | ~50% | Loss |

### Blackjack (`.blackjack <bet>`)
- **Cooldown:** 10 seconds
- **Max bet:** 100,000 🪙
- Bet deducted upfront
- Use `.hit` and `.stand` to play
- **Natural blackjack** (21 on first draw) pays **2.5×**
- Dealer hits until 17
- Push returns full bet

### Lottery (`.lottery <bet>`)
- **Cooldown:** 60 seconds
- Each 100 🪙 = 1 ticket
- Draws when **5+ unique players** or **20 total tickets**
- **15% rake** (house cut)
- Winner gets remaining pool

---

## Social Economy Commands

### Cookie (`.cookie @user`)
- **Cooldown:** 24 hours
- Gives the target +1 cookie (cosmetic stat)
- Cannot cookie yourself

### Pray (`.pray @user`)
- **Cooldown:** 1 hour
- Costs you coins, gives the target coins + XP
- Three tiers (auto-downgraded if you can't afford higher):

| Tier | Your Cost | Target Coins | Target XP |
|---|---|---|---|
| Common (60%) | 100 🪙 | 50–300 | 10–50 |
| Rare (30%) | 300 🪙 | 100–1,000 | 50–200 |
| Epic (10%) | 800 🪙 | 1,000–5,000 | 200–500 |

### Curse (`.curse @user`)
- **Cooldown:** 30 minutes
- **30% backfire chance** — you lose coins instead
- Target (or you, on backfire) loses 50–500 🪙
- Cannot curse yourself

### Steal (`.steal @user`)
- **Cooldown:** 60 seconds (global), 2 hours (per target)
- Target must have ≥200 🪙
- **Guard dog:** 90% chance to block (1 dog consumed on block)
- **30% caught chance** → thief pays 500 🪙 fine
- On success: steal 200–5,000 🪙 (capped by target's balance)

---

## Guard Dogs

- **Price:** 150 🪙 each
- Blocks steals with **90% chance**
- 1 guard dog consumed per successful block
- Stackable — buy multiple for continuous protection
- Displayed in profile and balance

---

## Weapon Management

| Command | Description |
|---|---|
| `.weapon` | List all owned weapons (top 15) |
| `.equip <weaponID> <animal name>` | Equip weapon to a team animal |
| `.unequip <animal name>` | Unequip weapon from animal |
| `.weapon sell <weaponID>` | Sell weapon for 50% of shop price |
| `.weapon reroll <weaponID>` | Reroll weapon stats (700 💎) |
| `.enchant <animalName> <enchID>` | Equip enchantment on animal |
| `.enchant keep <enchID>` | Unequip enchantment from animal |

### Weapon Rerolling

Here is how the weapon reroll system works in advenexus:

You can reroll a weapon's stats using the command `.weapon reroll <weaponID>`. Each reroll costs **700 gems (💎)**. 

**The Mechanics:**
1. **Random Percentage Roll:** Every time you reroll, the game picks a random percentage modifier from this list: `-50%, -40%, -30%, -20%, -10%, 0%, +10%, +20%, +30%, +40%, +50%`. 
2. **Cumulative Bonuses:** The value you roll is **added** to your weapon's current reroll bonus. For example, if your weapon currently has a `+20%` bonus and you roll a `+30%`, your weapon's new bonus becomes `+50%`. If you roll a `-10%`, it drops to `+10%`.
3. **Stat Limits:** The total accumulated bonus is capped. It can never go lower than **-100%** and can never go higher than **+200%**. 
4. **Stat Multiplier:** When you enter a battle, this percentage acts as a direct multiplier to all of the weapon's base stats (ATK, DEF, CRIT, MANA, and LIFESTEAL). 
   - A `+50%` total bonus means your weapon's stats are multiplied by `1.5x`.
   - A maxed out `+200%` total bonus means your weapon's stats are multiplied by `3x`!

Because the bonuses are cumulative rather than replacement-based, players can keep pouring gems into a weapon to eventually push it all the way to the +200% cap (though they might suffer some setbacks if they hit negative rolls along the way).

### Weapon Selling
- Sell price = **50% of shop price** (or ATK × 10 if no shop price found)
- Must unequip weapon before selling
- Enchantment stays in inventory if weapon is sold

### Weapon Dismantling
| Rarity | Gems Received |
|---|---|
| Common | 1 💎 |
| Uncommon | 5 💎 |
| Rare | 15 💎 |
| Epic | 50 💎 |
| Mythic | 200 💎 |
| Legendary | 1,000 💎 |

---

## Lootbox & Crate

### Lootbox (`.lootbox`)
- **Price:** 2,000 🪙 (or free from daily)
- Contains a random animal:

| Rarity | Weight |
|---|---|
| Rare | 55% |
| Epic | 30% |
| Mythic | 12% |
| Legendary | 2.4% |
| Fabled | 0.6% |

### Weapon Crate (`.crate`)
- **Price:** 3,000 🪙 (or free from daily / battle wins)
- Drop table:

| Drop | Weight |
|---|---|
| Enchantment | 63% |
| Sacrificial Diamond | 15% |
| Empty (nothing) | 15% |
| Legendary Weapon | 7% |

- Enchantment tier from crate: mythic 35%, legendary 20%, fabled 8%

---

## Inventory System

- **Default capacity:** 100 items
- Tracks: gems, enchantments, weapons, profiles, lootboxes, crates, evolution stones, materials
- When inventory is full, items go to **temporary storage**
- Use `.get items` to claim from temporary storage when space is available
- Weapons count towards capacity (each weapon = 1 slot)

---

## Shop Items

| Item | Price | Description |
|---|---|---|
| Lootbox | 2,000 🪙 | Random animal |
| Weapon Crate | 3,000 🪙 | Random weapon/enchantment |
| Guard Dog | 150 🪙 | 90% steal protection |
| Sacrificial Diamond | 50,000 🪙 | Used in `.craft` for max stats |
| Cookie | 300 🪙 | Restores +10 energy to an animal |

- Weapons from the weapon shop range from 15,000–120,000 🪙 (see battle.md for full list)

---

## Global Weather System

Players can activate cosmetic weather effects that display visual overlays for all players on the server.

### Player-Activated Weather
Players can manually activate global weather effects using the `.activate <weather>` command:
- **Cost:** 100,000 🪙 per activation
- **Duration:** 1 hour (60 minutes)
- **Effects:** `rain`, `eclipse`, `aura_storm`, `coin_shimmer`, `snowflakes`
- **Visual Impact:** Displays animated overlays across all player screens
- **Cooldowns:** 
  - Personal cooldown: 1 hour after activating
  - Global cooldown: 10 minutes after any effect ends (prevents back-to-back activations)
- **Deactivation:** Only the player who activated the weather can deactivate it early using `.deactivate weather`

**Note:** Weather effects are purely cosmetic and do not modify battle stats, hunting rates, or economy rewards.

---

## Economy Sinks

To mitigate inflation, the game contains these core sinks:
1. **Marketplace Fees:** 2% upfront listing fee, 5% house rake on successful sale.
2. **Duels:** `.duel @user <amount>`. 5% of the total escrow is burned on conclusion.
3. **Guild Perks:** `.guild perk buy <tier>`. Burns up to 250,000 🪙 from the guild bank.
4. **Animal Energy:** Battles drain energy. Restoring it costs 300 🪙 per +10 energy cookie.

---

## Animal Shop

- Browse: `.animal shop`
- Buy: `.animal buy <name>` or `.buy <name>`
- Currently features **Gods tier** animals
- Only base forms available (no evolved forms in shop)
- Price determined by `RARITY_CONFIG[rarity].shopPrice`

---

## Edge Cases

- Cannot give coins to yourself (give auto-blocks same ID)
- Cannot steal from someone with less than 200 🪙
- Guard dogs are consumed on successful block, not on failed steal attempts
- Blackjack deducts bet upfront — push returns it, win gives 2×
- Lottery rake is 15% — winner gets 85% of total pool
- Weapon reroll bonus persists through equip/unequip
- Enchantments stay in inventory even when equipped — usage is tracked separately
- Quest progress is tracked automatically by the system
- Temp storage items expire (cleaned up on `.get items`)
