Death Chests

This commit is contained in:
dingo
2025-12-17 13:22:21 -05:00
parent 353de811f6
commit 69c5b38098
11 changed files with 212 additions and 6 deletions
+52 -2
View File
@@ -10,6 +10,9 @@ signal inventory_updated
signal chat_message_received(sender: String, message: String, type: String)
signal loot_received(items: Array)
signal player_died
signal loot_chest_spawned(chest_data: Dictionary)
signal loot_chest_state_received(chest_data: Dictionary)
signal death_loot_lost(data: Dictionary)
# Use constants instead of enum to avoid type issues
const STATE_AUTH = 0
@@ -37,7 +40,8 @@ var character: Dictionary = {
"dexterity": 1,
"max_health": 60,
"max_mana": 28,
"max_stamina": 55
"max_stamina": 55,
"gold": 0
}
# Dungeon data
@@ -57,6 +61,7 @@ var mobs: Dictionary = {}
var chests: Dictionary = {}
var dropped_items: Dictionary = {}
var portals: Dictionary = {}
var loot_chests: Dictionary = {}
# Inventory
var inventory: Array = []
@@ -122,6 +127,12 @@ func _on_message_received(opcode: int, data: Dictionary):
_handle_death(data)
OpCodes.EVENT_LEVELUP:
_handle_levelup(data)
OpCodes.LOOT_CHEST_SPAWNED:
_handle_loot_chest_spawned(data)
OpCodes.LOOT_CHEST_STATE:
_handle_loot_chest_state(data)
OpCodes.PLAYER_DEATH_LOOT_LOST:
_handle_death_loot_lost(data)
_:
print("[GameState] Unhandled opcode: ", opcode)
@@ -148,7 +159,8 @@ func _handle_hub_state(data: Dictionary):
"dexterity": int(c.get("dexterity", c.get("Dexterity", 1))),
"max_health": int(c.get("maxHealth", c.get("MaxHealth", 60))),
"max_mana": int(c.get("maxMana", c.get("MaxMana", 28))),
"max_stamina": int(c.get("maxStamina", c.get("MaxStamina", 55)))
"max_stamina": int(c.get("maxStamina", c.get("MaxStamina", 55))),
"gold": int(c.get("gold", c.get("Gold", 0)))
}
set_state(STATE_HUB)
character_updated.emit()
@@ -268,6 +280,13 @@ func _handle_dungeon_state(data: Dictionary):
var pid = p.get("id", p.get("Id"))
portals[pid] = p
# Parse loot chests (personal to this player)
var lchests = data.get("lootChests", data.get("LootChests", []))
loot_chests.clear()
for lc in lchests:
var lcid = lc.get("id", lc.get("Id"))
loot_chests[lcid] = lc
dungeon_state_updated.emit()
func _handle_inventory_state(data: Dictionary):
@@ -406,6 +425,7 @@ func _handle_portal_used(_data: Dictionary):
chests.clear()
dropped_items.clear()
portals.clear()
loot_chests.clear()
dungeon = {
"id": "",
"tier": 1,
@@ -417,3 +437,33 @@ func _handle_portal_used(_data: Dictionary):
escaped.emit()
# Server will send HUB_STATE next which will call set_state(STATE_HUB)
# Loot chest handlers
func _handle_loot_chest_spawned(data: Dictionary):
print("[GameState] Loot chest spawned: ", data)
loot_chest_spawned.emit(data)
func _handle_loot_chest_state(data: Dictionary):
print("[GameState] Loot chest state received")
loot_chest_state_received.emit(data)
func _handle_death_loot_lost(data: Dictionary):
print("[GameState] Death loot lost: ", data)
death_loot_lost.emit(data)
# Loot chest actions
func open_loot_chest(chest_id: int):
Network.send_message(OpCodes.LOOT_CHEST_OPEN, {"ChestId": chest_id})
func take_loot_chest_item(chest_id: int, slot_index: int, target_slot: int = -1):
Network.send_message(OpCodes.LOOT_CHEST_TAKE_ITEM, {
"ChestId": chest_id,
"SlotIndex": slot_index,
"TargetSlotIndex": target_slot
})
func take_all_loot_chest(chest_id: int):
Network.send_message(OpCodes.LOOT_CHEST_TAKE_ALL, {"ChestId": chest_id})
func close_loot_chest(chest_id: int):
Network.send_message(OpCodes.LOOT_CHEST_CLOSE, {"ChestId": chest_id})
+11
View File
@@ -23,6 +23,17 @@ const HOTBAR_ASSIGN = 256
const CHAT_SEND = 260
const CHAT_MESSAGE = 261
# Loot Chests
const LOOT_CHEST_OPEN = 270
const LOOT_CHEST_STATE = 271
const LOOT_CHEST_TAKE_ITEM = 272
const LOOT_CHEST_TAKE_ALL = 273
const LOOT_CHEST_CLOSE = 274
const LOOT_CHEST_SPAWNED = 275
# Player Death
const PLAYER_DEATH_LOOT_LOST = 280
# Dungeon
const DUNGEON_ENTER = 300
const DUNGEON_ENTER_RESULT = 301