Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Feature 17: Gear Enhancement & Reforging

Overview

Endgame item progression: enhancement (+1 to +5 upgrades that increase base stats) and reforging (re-roll random bonus properties on Rare+ items). Both are material and gold sinks that give max-level players long-term goals without adding power creep.

Dependencies

  • Feature 03 (Items & Inventory) — gear with bonus properties
  • Feature 08 (Crafting) — crafting materials used as enhancement/reforge inputs
  • Feature 09 (Economy) — gold sinks

Technical Tasks

1. Enhancement Logic (crates/game)

  • Create src/enhancement.rs:
    • Enhancement levels: +1 through +5
    • Per level: material cost, gold cost, success chance
      • +1: 5 Uncommon Shards, 500 gold, 100% success
      • +2: 10 Uncommon Shards + 2 Rare Cores, 2000 gold, 80% success
      • +3: 5 Rare Cores, 5000 gold, 60% success
      • +4: 10 Rare Cores + 2 Prismatic Essences, 15000 gold, 40% success
      • +5: 5 Prismatic Essences + 1 Legendary Spark, 50000 gold, 20% success
    • Failure: item stays at current level (no downgrade), materials consumed
    • enhance_item(item: &Item, target_level: u8, rng: &mut impl Rng) -> EnhanceResult:
      • Check current enhancement < target
      • Roll success chance
      • Return Success(new_level) or Failure(current_level)
    • enhancement_stat_bonus(base_stat: u16, level: u8) -> u16:
      • +5% per level to base damage/armor/evasion

2. Reforging Logic (crates/game)

  • Create src/reforging.rs:
    • Only available for Rare+ items (they have random bonus properties)
    • reforge_cost(rarity: Rarity) -> ReforgeCost:
      • Rare: 3 Rare Cores + 1000 gold
      • Very Rare: 5 Rare Cores + 2 Prismatic Essences + 5000 gold
      • Legendary: 3 Prismatic Essences + 1 Legendary Spark + 20000 gold
    • reforge_item(item: &mut Item, rng: &mut impl Rng) -> Vec<BonusProperty>:
      • Re-roll ALL random bonus properties (keep count, re-roll values and types)
      • Signature effect is NOT re-rolled (it’s fixed per template)
      • Return new bonus properties

3. API Routes (crates/api)

  • Add to src/routes/inventory.rs:
    • POST /api/characters/:id/enhance:
      • Body: { item_id }
      • Validate: item owned, enhancement < 5, has materials + gold
      • Deduct materials and gold
      • Roll enhancement
      • Return { success, new_enhancement_level }
    • POST /api/characters/:id/reforge:
      • Body: { item_id }
      • Validate: item owned, Rare+ rarity, has materials + gold
      • Deduct materials and gold
      • Re-roll bonuses
      • Return { new_bonus_properties }

4. Client — Enhancement & Reforging UI

  • Add to inventory screen:
    • “Enhance” button on eligible items → modal showing cost, success chance, current level
    • “Reforge” button on Rare+ items → modal showing cost, current bonuses, warning about random results
    • Enhancement level displayed on item: “+3 Iron Longsword”
    • Visual indicator of enhancement level (glow effect or badge)

Tests

Unit Tests

  • enhance_item: +1 always succeeds (100%)
  • enhance_item: +5 has 20% success rate (statistical test with seeded RNG)
  • enhance_item: failure doesn’t downgrade
  • enhancement_stat_bonus: +5 at level 3 = +15% bonus
  • reforge_item: keeps same number of bonus properties
  • reforge_item: can produce different properties than original
  • reforge_item: deterministic with seeded RNG
  • reforge_cost: correct per rarity tier

Integration Tests

  • POST /api/characters/:id/enhance deducts materials and gold
  • POST /api/characters/:id/enhance on max (+5) → 409
  • POST /api/characters/:id/enhance with insufficient materials → 422
  • POST /api/characters/:id/reforge re-rolls bonuses, deducts cost
  • POST /api/characters/:id/reforge on Common item → 422
  • Enhanced item stats correctly increased in equipment calculations