What a mess

This commit is contained in:
Joan
2025-11-07 15:27:13 +01:00
parent 0b79b3ae59
commit 33cc9586c2
130 changed files with 29819 additions and 1175 deletions

View File

@@ -2,7 +2,8 @@
Pickup and item collection handlers.
"""
import logging
from . import database, keyboards, logic
from . import keyboards, logic
from .api_client import api_client
from data.world_loader import game_world
from data.items import ITEMS
@@ -12,14 +13,14 @@ logger = logging.getLogger(__name__)
async def handle_pickup_menu(query, user_id: int, player: dict, data: list):
"""Show pickup options for a dropped item."""
dropped_item_id = int(data[1])
item_to_pickup = await database.get_dropped_item(dropped_item_id)
item_to_pickup = await api_client.get_dropped_item(dropped_item_id)
if not item_to_pickup:
await query.answer("Someone already picked that up!", show_alert=False)
location_id = player['location_id']
location = game_world.get_location(location_id)
dropped_items = await database.get_dropped_items_in_location(location_id)
wandering_enemies = await database.get_wandering_enemies_in_location(location_id)
dropped_items = await api_client.get_dropped_items_in_location(location_id)
wandering_enemies = await api_client.get_wandering_enemies_in_location(location_id)
keyboard = await keyboards.inspect_keyboard(location_id, dropped_items, wandering_enemies)
image_path = location.image_path if location else None
@@ -64,13 +65,13 @@ async def handle_pickup(query, user_id: int, player: dict, data: list):
dropped_item_id = int(data[1])
pickup_amount_str = data[2] if len(data) > 2 else "all"
item_to_pickup = await database.get_dropped_item(dropped_item_id)
item_to_pickup = await api_client.get_dropped_item(dropped_item_id)
if not item_to_pickup:
await query.answer("Someone already picked that up!", show_alert=False)
location_id = player['location_id']
location = game_world.get_location(location_id)
dropped_items = await database.get_dropped_items_in_location(location_id)
wandering_enemies = await database.get_wandering_enemies_in_location(location_id)
dropped_items = await api_client.get_dropped_items_in_location(location_id)
wandering_enemies = await api_client.get_wandering_enemies_in_location(location_id)
keyboard = await keyboards.inspect_keyboard(location_id, dropped_items, wandering_enemies)
image_path = location.image_path if location else None
@@ -99,20 +100,20 @@ async def handle_pickup(query, user_id: int, player: dict, data: list):
return
# Add to inventory
await database.add_item_to_inventory(user_id, item_to_pickup['item_id'], pickup_amount)
await api_client.add_item_to_inventory(user_id, item_to_pickup['item_id'], pickup_amount)
# Update or remove dropped item
remaining = item_to_pickup['quantity'] - pickup_amount
item_def = ITEMS.get(item_to_pickup['item_id'], {})
if remaining > 0:
await database.update_dropped_item(dropped_item_id, remaining)
await api_client.update_dropped_item(dropped_item_id, remaining)
await query.answer(
f"Picked up {pickup_amount}x {item_def.get('name', 'item')}. {remaining} remaining.",
show_alert=False
)
else:
await database.remove_dropped_item(dropped_item_id)
await api_client.remove_dropped_item(dropped_item_id)
await query.answer(
f"Picked up {pickup_amount}x {item_def.get('name', 'item')}.",
show_alert=False
@@ -121,8 +122,8 @@ async def handle_pickup(query, user_id: int, player: dict, data: list):
# Return to inspect area
location_id = player['location_id']
location = game_world.get_location(location_id)
dropped_items = await database.get_dropped_items_in_location(location_id)
wandering_enemies = await database.get_wandering_enemies_in_location(location_id)
dropped_items = await api_client.get_dropped_items_in_location(location_id)
wandering_enemies = await api_client.get_wandering_enemies_in_location(location_id)
keyboard = await keyboards.inspect_keyboard(location_id, dropped_items, wandering_enemies)
image_path = location.image_path if location else None