Add complete item collection system (v0.2.0)
🎒 Item Collection System: - 16 unique items across 5 categories (healing, battle, rare, location, special) - Rarity tiers: Common, Uncommon, Rare, Epic, Legendary with symbols - 30% chance to find items during exploration - Location-specific items (shells, mushrooms, crystals, runes) - Inventory management with \!inventory and \!use commands - Web interface integration showing player inventories - Consumable items: healing potions, battle boosters, lucky charms 🔧 Technical Updates: - Added items and player_inventory database tables - New Inventory module for item management - Updated game engine with item discovery system - Enhanced web interface with inventory display - Item initialization from config/items.json 🆕 New Commands: - \!inventory / \!inv / \!items - View collected items by category - \!use <item name> - Use consumable items on active pets 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e0edcb391a
commit
db144da24f
13 changed files with 952 additions and 22 deletions
|
|
@ -24,6 +24,7 @@ class GameEngine:
|
|||
await self.load_moves()
|
||||
await self.load_type_chart()
|
||||
await self.load_achievements()
|
||||
await self.database.initialize_items()
|
||||
await self.init_weather_system()
|
||||
await self.battle_engine.load_battle_data()
|
||||
|
||||
|
|
@ -299,6 +300,11 @@ class GameEngine:
|
|||
if not location:
|
||||
return {"type": "error", "message": "You are not in a valid location!"}
|
||||
|
||||
# Check for item discovery first (30% chance)
|
||||
item_result = await self.check_item_discovery(player_id, location)
|
||||
if item_result:
|
||||
return item_result
|
||||
|
||||
# Get spawns for current location
|
||||
cursor = await db.execute("""
|
||||
SELECT ls.*, ps.name as species_name, ps.*
|
||||
|
|
@ -314,8 +320,8 @@ class GameEngine:
|
|||
# Apply weather modifiers to spawns
|
||||
modified_spawns = await self.get_weather_modified_spawns(location["id"], spawns)
|
||||
|
||||
# Random encounter chance (70% chance of finding something)
|
||||
if random.random() > 0.7:
|
||||
# Random encounter chance (50% chance of finding a pet after item check)
|
||||
if random.random() > 0.5:
|
||||
return {"type": "empty", "message": f"You explore {location['name']} but find nothing this time..."}
|
||||
|
||||
# Choose random spawn with weather-modified rates
|
||||
|
|
@ -347,6 +353,63 @@ class GameEngine:
|
|||
}
|
||||
}
|
||||
|
||||
async def check_item_discovery(self, player_id: int, location: Dict) -> Optional[Dict]:
|
||||
"""Check if player finds an item during exploration"""
|
||||
import json
|
||||
|
||||
# Load items config
|
||||
try:
|
||||
with open("config/items.json", "r") as f:
|
||||
items_data = json.load(f)
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
|
||||
# Get all possible items for this location
|
||||
available_items = []
|
||||
location_name = location["name"].lower().replace(" ", "_")
|
||||
|
||||
for category_items in items_data.values():
|
||||
if isinstance(category_items, list):
|
||||
for item in category_items:
|
||||
if "locations" in item:
|
||||
item_locations = item["locations"]
|
||||
if "all" in item_locations or location_name in item_locations:
|
||||
available_items.append(item)
|
||||
|
||||
if not available_items:
|
||||
return None
|
||||
|
||||
# Calculate total spawn rates for this location
|
||||
total_rate = sum(item.get("spawn_rate", 0.1) for item in available_items)
|
||||
|
||||
# 30% base chance of finding an item
|
||||
if random.random() > 0.3:
|
||||
return None
|
||||
|
||||
# Choose item based on spawn rates
|
||||
chosen_item = random.choices(
|
||||
available_items,
|
||||
weights=[item.get("spawn_rate", 0.1) for item in available_items]
|
||||
)[0]
|
||||
|
||||
# Add item to player's inventory
|
||||
success = await self.database.add_item_to_inventory(player_id, chosen_item["name"])
|
||||
|
||||
if success:
|
||||
# Get rarity info for display
|
||||
rarity_info = items_data.get("rarity_info", {}).get(chosen_item["rarity"], {})
|
||||
symbol = rarity_info.get("symbol", "○")
|
||||
|
||||
return {
|
||||
"type": "item_found",
|
||||
"location": location["name"],
|
||||
"item": chosen_item,
|
||||
"symbol": symbol,
|
||||
"message": f"🎒 You found a {symbol} {chosen_item['name']} ({chosen_item['rarity']})! {chosen_item['description']}"
|
||||
}
|
||||
|
||||
return None
|
||||
|
||||
async def attempt_catch_current_location(self, player_id: int, target_pet: Dict) -> str:
|
||||
"""Attempt to catch a pet during exploration"""
|
||||
catch_rate = 0.5 + (0.3 / target_pet.get("rarity", 1))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue