#!/usr/bin/env python3 """Inventory management module for PetBot""" from .base_module import BaseModule class Inventory(BaseModule): """Handles inventory, item usage, and item management commands""" def get_commands(self): return ["inventory", "inv", "items", "use", "item"] async def handle_command(self, channel, nickname, command, args): if command in ["inventory", "inv", "items"]: await self.cmd_inventory(channel, nickname) elif command in ["use", "item"]: await self.cmd_use_item(channel, nickname, args) async def cmd_inventory(self, channel, nickname): """Redirect player to their web profile for inventory management""" player = await self.require_player(channel, nickname) if not player: return # Redirect to web interface for better inventory management self.send_message(channel, f"🎒 {nickname}: View your complete inventory at: http://petz.rdx4.com/player/{nickname}#inventory") self.send_message(channel, f"💡 The web interface shows detailed item information, categories, and usage options!") async def cmd_use_item(self, channel, nickname, args): """Use an item from inventory""" if not args: self.send_message(channel, f"{nickname}: Specify an item to use! Example: !use Small Potion") return player = await self.require_player(channel, nickname) if not player: return item_name = " ".join(self.normalize_input(args)) result = await self.database.use_item(player["id"], item_name) if not result["success"]: self.send_message(channel, f"❌ {nickname}: {result['error']}") return item = result["item"] effect = result["effect"] effect_value = result["effect_value"] # Handle different item effects if effect == "heal": # Find active pet to heal active_pets = await self.database.get_active_pets(player["id"]) if not active_pets: self.send_message(channel, f"❌ {nickname}: You need an active pet to use healing items!") return # Heal the first active pet (can be expanded to choose specific pet) pet = active_pets[0] old_hp = pet["hp"] new_hp = min(pet["max_hp"], pet["hp"] + effect_value) healed_amount = new_hp - old_hp # Update pet HP in database await self.database.update_pet_hp(pet["id"], new_hp) self.send_message(channel, f"💊 {nickname}: Used {item['name']} on {pet['nickname'] or pet['species_name']}! " f"Restored {healed_amount} HP ({old_hp} → {new_hp}/{pet['max_hp']})") elif effect == "full_heal": active_pets = await self.database.get_active_pets(player["id"]) if not active_pets: self.send_message(channel, f"❌ {nickname}: You need an active pet to use healing items!") return pet = active_pets[0] old_hp = pet["hp"] healed_amount = pet["max_hp"] - old_hp await self.database.update_pet_hp(pet["id"], pet["max_hp"]) self.send_message(channel, f"✨ {nickname}: Used {item['name']} on {pet['nickname'] or pet['species_name']}! " f"Fully restored HP! ({old_hp} → {pet['max_hp']}/{pet['max_hp']})") elif effect == "attack_boost": self.send_message(channel, f"⚔️ {nickname}: Used {item['name']}! Your next battle will have +{effect_value}% attack damage!") elif effect == "defense_boost": self.send_message(channel, f"🛡️ {nickname}: Used {item['name']}! Your next battle will have +{effect_value}% damage reduction!") elif effect == "speed_boost": self.send_message(channel, f"💨 {nickname}: Used {item['name']}! You'll move first in your next battle!") elif effect == "lucky_boost": self.send_message(channel, f"🍀 {nickname}: Used {item['name']}! Rare pet encounter rate increased by {effect_value}% for 1 hour!") elif effect == "revive": # Handle revive items for fainted pets fainted_pets = await self.database.get_fainted_pets(player["id"]) if not fainted_pets: self.send_message(channel, f"❌ {nickname}: You don't have any fainted pets to revive!") return # Use the first fainted pet (can be expanded to choose specific pet) pet = fainted_pets[0] new_hp = int(pet["max_hp"] * (effect_value / 100.0)) # Convert percentage to HP # Revive the pet and restore HP await self.database.revive_pet(pet["id"], new_hp) self.send_message(channel, f"💫 {nickname}: Used {item['name']} on {pet['nickname'] or pet['species_name']}! " f"Revived and restored {new_hp}/{pet['max_hp']} HP!") elif effect == "max_revive": # Handle max revive items for fainted pets fainted_pets = await self.database.get_fainted_pets(player["id"]) if not fainted_pets: self.send_message(channel, f"❌ {nickname}: You don't have any fainted pets to revive!") return # Use the first fainted pet (can be expanded to choose specific pet) pet = fainted_pets[0] # Revive the pet and fully restore HP await self.database.revive_pet(pet["id"], pet["max_hp"]) self.send_message(channel, f"✨ {nickname}: Used {item['name']} on {pet['nickname'] or pet['species_name']}! " f"Revived and fully restored HP! ({pet['max_hp']}/{pet['max_hp']})") elif effect == "money": # Handle money items (like Coin Pouch) import random if "-" in str(effect_value): # Parse range like "1-3" min_coins, max_coins = map(int, str(effect_value).split("-")) coins_gained = random.randint(min_coins, max_coins) else: coins_gained = int(effect_value) # Add money to player await self.database.add_money(player["id"], coins_gained) self.send_message(channel, f"💰 {nickname}: Used {item['name']}! Found {coins_gained} coins inside!") elif effect == "none": self.send_message(channel, f"📦 {nickname}: Used {item['name']}! This item has no immediate effect but may be useful later.") else: self.send_message(channel, f"✅ {nickname}: Used {item['name']}! {item['description']}")