diff --git a/main.py b/main.py index 5799906b..6621a910 100644 --- a/main.py +++ b/main.py @@ -1979,6 +1979,33 @@ async def ws_receive_snapshots( except Exception as e: logger.error(f"Failed to process inventory for {data.get('character_name', 'unknown')}: {e}", exc_info=True) continue + # --- Inventory delta: single item add/remove/update --- + if msg_type == "inventory_delta": + try: + action = data.get("action") + char_name = data.get("character_name", "unknown") + + if action == "remove": + item_id = data.get("item_id") + async with httpx.AsyncClient(timeout=10.0) as client: + await client.delete( + f"{INVENTORY_SERVICE_URL}/inventory/{char_name}/item/{item_id}" + ) + elif action in ("add", "update"): + item = data.get("item") + if item: + async with httpx.AsyncClient(timeout=10.0) as client: + await client.post( + f"{INVENTORY_SERVICE_URL}/inventory/{char_name}/item", + json=item + ) + + # Broadcast delta to all browser clients + await _broadcast_to_browser_clients(data) + logger.debug(f"Inventory delta ({action}) for {char_name}") + except Exception as e: + logger.error(f"Failed to process inventory delta: {e}", exc_info=True) + continue # --- Vitals message: store character health/stamina/mana and broadcast --- if msg_type == "vitals": payload = data.copy()