Pre-combat-improvements: Combat animations, flee fixes, corpse logic updates
This commit is contained in:
@@ -1124,46 +1124,54 @@ async def use_item(
|
||||
'tier': inv_item.get('tier')
|
||||
})
|
||||
|
||||
# Store minimal data in database
|
||||
db_items = json.dumps([{'item_id': i['item_id'], 'quantity': i['quantity']} for i in inventory])
|
||||
# Only create corpse if player has items
|
||||
corpse_data = None
|
||||
if inventory_items:
|
||||
# Store minimal data in database
|
||||
db_items = json.dumps([{'item_id': i['item_id'], 'quantity': i['quantity']} for i in inventory])
|
||||
|
||||
logger.info(f"Creating player corpse for {player['name']} at {player['location_id']} with {len(inventory_items)} items")
|
||||
|
||||
corpse_id = await db.create_player_corpse(
|
||||
player_name=player['name'],
|
||||
location_id=player['location_id'],
|
||||
items=db_items
|
||||
)
|
||||
|
||||
logger.info(f"Successfully created player corpse: ID={corpse_id}, player={player['name']}, location={player['location_id']}, items_count={len(inventory_items)}")
|
||||
|
||||
# Clear player's inventory (items are now in corpse)
|
||||
await db.clear_inventory(current_user['id'])
|
||||
|
||||
# Build corpse data for broadcast
|
||||
corpse_data = {
|
||||
"id": f"player_{corpse_id}",
|
||||
"type": "player",
|
||||
"name": f"{player['name']}'s Corpse",
|
||||
"emoji": "⚰️",
|
||||
"player_name": player['name'],
|
||||
"loot_count": len(inventory_items),
|
||||
"items": inventory_items, # Full item list for UI
|
||||
"timestamp": time_module.time()
|
||||
}
|
||||
else:
|
||||
logger.info(f"Player {player['name']} died (use_item combat) with no items, skipping corpse creation")
|
||||
|
||||
logger.info(f"Creating player corpse for {player['name']} at {player['location_id']} with {len(inventory_items)} items")
|
||||
|
||||
corpse_id = await db.create_player_corpse(
|
||||
player_name=player['name'],
|
||||
location_id=player['location_id'],
|
||||
items=db_items
|
||||
)
|
||||
|
||||
logger.info(f"Successfully created player corpse: ID={corpse_id}, player={player['name']}, location={player['location_id']}, items_count={len(inventory_items)}")
|
||||
|
||||
# Clear player's inventory (items are now in corpse)
|
||||
await db.clear_inventory(current_user['id'])
|
||||
|
||||
# Build corpse data for broadcast
|
||||
corpse_data = {
|
||||
"id": f"player_{corpse_id}",
|
||||
"type": "player",
|
||||
"name": f"{player['name']}'s Corpse",
|
||||
"emoji": "⚰️",
|
||||
"player_name": player['name'],
|
||||
"loot_count": len(inventory_items),
|
||||
"items": inventory_items, # Full item list for UI
|
||||
"timestamp": time_module.time()
|
||||
}
|
||||
|
||||
# Broadcast to location that player died and corpse appeared
|
||||
# Broadcast to location that player died (and corpse if created)
|
||||
logger.info(f"Broadcasting player_died to location {player['location_id']} for player {player['name']}")
|
||||
broadcast_data = {
|
||||
"message": get_game_message('player_defeated_broadcast', locale, player_name=player['name']),
|
||||
"action": "player_died",
|
||||
"player_id": player['id']
|
||||
}
|
||||
if corpse_data:
|
||||
broadcast_data["corpse"] = corpse_data
|
||||
|
||||
await manager.send_to_location(
|
||||
location_id=player['location_id'],
|
||||
message={
|
||||
"type": "location_update",
|
||||
"data": {
|
||||
"message": get_game_message('player_defeated_broadcast', locale, player_name=player['name']),
|
||||
"action": "player_died",
|
||||
"player_id": player['id'],
|
||||
"corpse": corpse_data # Send full corpse data
|
||||
},
|
||||
"data": broadcast_data,
|
||||
"timestamp": datetime.utcnow().isoformat()
|
||||
},
|
||||
exclude_player_id=current_user['id']
|
||||
|
||||
Reference in New Issue
Block a user