Changed Escape, portal spawns at spawn to exit.

This commit is contained in:
dingo
2025-12-16 22:39:50 -05:00
parent 9cd00b3b06
commit 2c9d3200f8
7 changed files with 155 additions and 9 deletions
+46 -1
View File
@@ -56,6 +56,7 @@ var players: Dictionary = {}
var mobs: Dictionary = {}
var chests: Dictionary = {}
var dropped_items: Dictionary = {}
var portals: Dictionary = {}
# Inventory
var inventory: Array = []
@@ -107,10 +108,14 @@ func _on_message_received(opcode: int, data: Dictionary):
print("[GameState] >>> CHAT_MESSAGE opcode matched! <<<")
_handle_chat_message(data)
OpCodes.ESCAPE_INTERRUPTED:
print("[OpCodes]PlayerEscape] Interrupted.")
is_escaping = false
OpCodes.ESCAPE_SUCCESS:
print("[GameState] >>> ESCAPE_SUCCESS - Returning to hub <<<")
_handle_escape_success(data)
OpCodes.PORTAL_USED:
print("[GameState] >>> PORTAL_USED - Extracting via portal <<<")
_handle_portal_used(data)
OpCodes.EVENT_DAMAGE:
_handle_damage(data)
OpCodes.EVENT_DEATH:
@@ -178,6 +183,13 @@ func _handle_dungeon_enter(data: Dictionary):
mobs.clear()
chests.clear()
dropped_items.clear()
portals.clear()
# Parse initial portals
var portal_list = data.get("portals", data.get("Portals", []))
for p in portal_list:
var pid = p.get("id", p.get("Id"))
portals[pid] = p
set_state(STATE_PLAYING)
dungeon_entered.emit()
@@ -250,6 +262,12 @@ func _handle_dungeon_state(data: Dictionary):
var iid = i.get("id", i.get("Id"))
dropped_items[iid] = i
# Parse portals
var ports = data.get("portals", data.get("Portals", []))
for p in ports:
var pid = p.get("id", p.get("Id"))
portals[pid] = p
dungeon_state_updated.emit()
func _handle_inventory_state(data: Dictionary):
@@ -313,12 +331,14 @@ func _handle_escape_success(_data: Dictionary):
mobs.clear()
chests.clear()
dropped_items.clear()
portals.clear()
dungeon = {
"id": "",
"tier": 1,
"width": 0,
"height": 0,
"tiles": []
"tiles": [],
"phase": "active"
}
escaped.emit()
@@ -372,3 +392,28 @@ func cancel_escape():
func return_to_hub():
Network.send_message(OpCodes.DUNGEON_LEAVE, {})
set_state(STATE_HUB)
func send_use_portal(portal_id: int):
Network.send_message(OpCodes.INPUT_PORTAL, {"PortalId": portal_id})
func _handle_portal_used(_data: Dictionary):
print("[GameState] Portal used! Returning to hub...")
is_escaping = false
# Clear dungeon data
players.clear()
mobs.clear()
chests.clear()
dropped_items.clear()
portals.clear()
dungeon = {
"id": "",
"tier": 1,
"width": 0,
"height": 0,
"tiles": [],
"phase": "active"
}
escaped.emit()
# Server will send HUB_STATE next which will call set_state(STATE_HUB)
+4 -1
View File
@@ -28,18 +28,21 @@ const DUNGEON_ENTER = 300
const DUNGEON_ENTER_RESULT = 301
const DUNGEON_STATE = 302
const DUNGEON_LEAVE = 303
const DUNGEON_CLEARED = 304
# Input
const INPUT_MOVE = 400
const INPUT_ATTACK = 401
const INPUT_PICKUP = 402
const INPUT_CHEST = 403
const INPUT_PORTAL = 404
# Escape
# Escape / Portal
const ESCAPE_START = 450
const ESCAPE_CANCEL = 451
const ESCAPE_INTERRUPTED = 452
const ESCAPE_SUCCESS = 453
const PORTAL_USED = 454
# Events
const EVENT_DAMAGE = 500