Mob looting fix and dungeon closure.

This commit is contained in:
dingo
2026-01-25 18:04:47 -05:00
parent 85c95e9f6a
commit c1a97b219e
8 changed files with 157 additions and 65 deletions
+20 -6
View File
@@ -194,6 +194,8 @@ func _on_message_received(opcode: int, data: Dictionary):
_handle_projectile_expired(data)
OpCodes.EVENT_DAMAGE_NUMBER:
_handle_damage_number(data)
OpCodes.ERROR:
_handle_error(data)
_:
print("[GameState] Unhandled opcode: ", opcode)
@@ -361,12 +363,13 @@ func _handle_dungeon_state(data: Dictionary):
# Check dungeon phase first
var phase = data.get("phase", data.get("Phase", "active"))
if phase == "cleared":
print("[GameState] Dungeon cleared! Waiting for hub state...")
# Server should send HUB_STATE next, but show a message
set_state(STATE_DUNGEONCLEARED)
dungeon_cleared.emit()
return
# Only print once when transitioning to cleared state
if dungeon.phase != "cleared":
print("[GameState] Dungeon cleared! Use the portal to exit.")
dungeon_cleared.emit()
dungeon.phase = "cleared"
# Don't return - continue processing state so player can still move and loot
var ps = data.get("players", data.get("Players", []))
for p in ps:
var pid = int(p.get("id", p.get("Id", 0)))
@@ -549,6 +552,12 @@ func send_use_item(slot_index: int):
func send_stack_items(source_slot: int, target_slot: int):
Network.send_message(OpCodes.STACK_ITEMS, {"SourceSlot": source_slot, "TargetSlot": target_slot})
func send_move_item(source_slot: int, target_slot: int):
Network.send_message(OpCodes.MOVE_ITEM, {"SourceSlot": source_slot, "TargetSlot": target_slot})
func send_auto_stack_inventory():
Network.send_message(OpCodes.AUTO_STACK_INVENTORY, {})
func send_chat(message: String):
Network.send_message(OpCodes.CHAT_SEND, {"Message": message})
@@ -650,6 +659,11 @@ func take_mob_loot_item(mob_id: int, item_index: int):
func take_all_mob_loot(mob_id: int):
Network.send_message(OpCodes.MOB_LOOT_TAKE_ALL, {"mobId": mob_id})
func _handle_error(data: Dictionary):
var error_message = data.get("error", "Unknown error")
push_error("[Server Error] " + error_message)
print("[GameState] Server error: " + error_message)
# Dungeon list handler
func _handle_dungeon_list(data: Dictionary):
print("[GameState] Received dungeon list")
+11
View File
@@ -84,6 +84,12 @@ const HOTBAR_ASSIGN = 256
## Client -> Server: Stack two consumable items together
const STACK_ITEMS = 257
## Client -> Server: Move/swap item between inventory slots
const MOVE_ITEM = 258
## Client -> Server: Auto-stack all stackable items in inventory
const AUTO_STACK_INVENTORY = 259
# ===== Chat (260-269) =====
## Client -> Server: Send chat message
@@ -290,6 +296,11 @@ const STASH_WITHDRAW = 613
## Server -> Client: Stash operation result
const STASH_RESULT = 614
# ===== Errors (900-999) =====
## Server -> Client: Error message
const ERROR = 900
# ===== Legacy / Deprecated =====
## Legacy loot notification (consider consolidating with EVENT_LOOT)
+21 -14
View File
@@ -190,21 +190,23 @@ func _on_download_completed(result: int, response_code: int, _headers: PackedStr
# Store in memory cache (works for both web and desktop)
_texture_bytes[item.filePath] = body
_local_hashes[item.filePath] = item.fileHash
print("[UpdateManager] Stored in _texture_bytes: %s (%d bytes)" % [item.filePath, body.size()])
# For desktop, also save to disk for persistence
if not _is_web:
var cache_path = _get_cache_path(item.filePath)
var dir_path = cache_path.get_base_dir()
DirAccess.make_dir_recursive_absolute(dir_path)
var file = FileAccess.open(cache_path, FileAccess.WRITE)
if file:
file.store_buffer(body)
file.close()
else:
push_warning("[UpdateManager] Failed to save file to disk: %s" % cache_path)
_files_downloaded += 1
print("[UpdateManager] Emitting file_downloaded signal for: %s" % item.filePath)
file_downloaded.emit(item.filePath)
print("[UpdateManager] Downloaded: %s (%d bytes)" % [item.filePath, body.size()])
@@ -419,32 +421,36 @@ func _find_file_recursive(dir: DirAccess, current_path: String, filename: String
func load_texture(file_path: String) -> Texture2D:
# Check already-loaded texture cache
if _loaded_textures.has(file_path):
print("[UpdateManager] load_texture(%s) - Found in _loaded_textures cache" % file_path)
return _loaded_textures[file_path]
var buffer: PackedByteArray
# Try memory cache first (works for web and desktop)
if _texture_bytes.has(file_path):
print("[UpdateManager] load_texture(%s) - Found in _texture_bytes, creating texture..." % file_path)
buffer = _texture_bytes[file_path]
elif not _is_web:
# Desktop: try disk cache
var cache_path = _get_cache_path(file_path)
if not FileAccess.file_exists(cache_path):
push_warning("[UpdateManager] Texture not in cache: %s" % file_path)
print("[UpdateManager] load_texture(%s) - Not in disk cache" % file_path)
return null
var file = FileAccess.open(cache_path, FileAccess.READ)
if not file:
push_warning("[UpdateManager] Failed to open cached file: %s" % file_path)
print("[UpdateManager] load_texture(%s) - Failed to open cached file" % file_path)
return null
buffer = file.get_buffer(file.get_length())
file.close()
# Store in memory cache for faster subsequent access
_texture_bytes[file_path] = buffer
else:
push_warning("[UpdateManager] Texture not in memory cache (web): %s" % file_path)
# Texture not in cache - this is normal for optional textures on web
# The calling code should handle null gracefully
print("[UpdateManager] load_texture(%s) - Not in memory cache (web build)" % file_path)
return null
var image = Image.new()
@@ -453,11 +459,12 @@ func load_texture(file_path: String) -> Texture2D:
err = image.load_jpg_from_buffer(buffer)
if err != OK:
err = image.load_webp_from_buffer(buffer)
if err != OK:
push_error("[UpdateManager] Failed to load image: %s" % file_path)
push_error("[UpdateManager] Failed to load image from buffer: %s (buffer size: %d bytes)" % [file_path, buffer.size()])
return null
print("[UpdateManager] load_texture(%s) - Successfully created texture from buffer" % file_path)
var texture = ImageTexture.create_from_image(image)
_loaded_textures[file_path] = texture
return texture