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

@@ -4,7 +4,8 @@ Corpse looting handlers (player and NPC corpses).
import logging
import json
import random
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
@@ -14,7 +15,7 @@ logger = logging.getLogger(__name__)
async def handle_loot_player_corpse(query, user_id: int, player: dict, data: list):
"""Show player corpse loot menu."""
corpse_id = int(data[1])
corpse = await database.get_player_corpse(corpse_id)
corpse = await api_client.get_player_corpse(corpse_id)
if not corpse:
await query.answer("Corpse not found.", show_alert=False)
@@ -43,7 +44,7 @@ async def handle_take_corpse_item(query, user_id: int, player: dict, data: list)
corpse_id = int(data[1])
item_index = int(data[2])
corpse = await database.get_player_corpse(corpse_id)
corpse = await api_client.get_player_corpse(corpse_id)
if not corpse:
await query.answer("Corpse not found.", show_alert=False)
return
@@ -66,13 +67,13 @@ async def handle_take_corpse_item(query, user_id: int, player: dict, data: list)
return
# Add to inventory
await database.add_item_to_inventory(user_id, item_data['item_id'], item_data['quantity'])
await api_client.add_item_to_inventory(user_id, item_data['item_id'], item_data['quantity'])
# Remove from corpse
items.pop(item_index)
if items:
await database.update_player_corpse(corpse_id, json.dumps(items))
await api_client.update_player_corpse(corpse_id, json.dumps(items))
keyboard = keyboards.player_corpse_loot_keyboard(corpse_id, items)
location = game_world.get_location(player['location_id'])
@@ -90,15 +91,15 @@ async def handle_take_corpse_item(query, user_id: int, player: dict, data: list)
)
else:
# Bag is empty, remove it
await database.remove_player_corpse(corpse_id)
await api_client.remove_player_corpse(corpse_id)
await query.answer(
f"Took {item_def.get('name', 'Unknown')}. The bag is now empty.",
show_alert=False
)
location = game_world.get_location(player['location_id'])
dropped_items = await database.get_dropped_items_in_location(player['location_id'])
wandering_enemies = await database.get_wandering_enemies_in_location(player['location_id'])
dropped_items = await api_client.get_dropped_items_in_location(player['location_id'])
wandering_enemies = await api_client.get_wandering_enemies_in_location(player['location_id'])
keyboard = await keyboards.inspect_keyboard(player['location_id'], dropped_items, wandering_enemies)
from .handlers import send_or_edit_with_image
@@ -113,7 +114,7 @@ async def handle_take_corpse_item(query, user_id: int, player: dict, data: list)
async def handle_scavenge_npc_corpse(query, user_id: int, player: dict, data: list):
"""Show NPC corpse scavenging menu."""
corpse_id = int(data[1])
corpse = await database.get_npc_corpse(corpse_id)
corpse = await api_client.get_npc_corpse(corpse_id)
if not corpse:
await query.answer("Corpse not found.", show_alert=False)
@@ -144,7 +145,7 @@ async def handle_scavenge_corpse_item(query, user_id: int, player: dict, data: l
corpse_id = int(data[1])
loot_index = int(data[2])
corpse = await database.get_npc_corpse(corpse_id)
corpse = await api_client.get_npc_corpse(corpse_id)
if not corpse:
await query.answer("Corpse not found.", show_alert=False)
return
@@ -159,7 +160,7 @@ async def handle_scavenge_corpse_item(query, user_id: int, player: dict, data: l
# Check if player has required tool
if required_tool:
inventory_items = await database.get_inventory(user_id)
inventory_items = await api_client.get_inventory(user_id)
has_tool = any(item['item_id'] == required_tool for item in inventory_items)
if not has_tool:
@@ -184,13 +185,13 @@ async def handle_scavenge_corpse_item(query, user_id: int, player: dict, data: l
return
# Add to inventory
await database.add_item_to_inventory(user_id, loot_data['item_id'], quantity)
await api_client.add_item_to_inventory(user_id, loot_data['item_id'], quantity)
# Remove from corpse
loot_items.pop(loot_index)
if loot_items:
await database.update_npc_corpse(corpse_id, json.dumps(loot_items))
await api_client.update_npc_corpse(corpse_id, json.dumps(loot_items))
keyboard = keyboards.npc_corpse_scavenge_keyboard(corpse_id, loot_items)
location = game_world.get_location(player['location_id'])
@@ -214,15 +215,15 @@ async def handle_scavenge_corpse_item(query, user_id: int, player: dict, data: l
)
else:
# Nothing left, remove corpse
await database.remove_npc_corpse(corpse_id)
await api_client.remove_npc_corpse(corpse_id)
await query.answer(
f"Scavenged {quantity}x {item_def.get('name', 'Unknown')}. Nothing left on the corpse.",
show_alert=False
)
location = game_world.get_location(player['location_id'])
dropped_items = await database.get_dropped_items_in_location(player['location_id'])
wandering_enemies = await database.get_wandering_enemies_in_location(player['location_id'])
dropped_items = await api_client.get_dropped_items_in_location(player['location_id'])
wandering_enemies = await api_client.get_wandering_enemies_in_location(player['location_id'])
keyboard = await keyboards.inspect_keyboard(player['location_id'], dropped_items, wandering_enemies)
from .handlers import send_or_edit_with_image