Ability work and portal fixes....
This commit is contained in:
@@ -39,6 +39,7 @@ const STATE_NAMES = ["AUTH", "HUB", "PLAYING", "DEAD", "PORTALUSED","DUNGEONCLEA
|
||||
|
||||
var current_state: int = STATE_AUTH
|
||||
var account_id: int = 0
|
||||
var _hub_fallback_timer: SceneTreeTimer = null
|
||||
|
||||
# Character data
|
||||
var character: Dictionary = {
|
||||
@@ -80,6 +81,8 @@ var chests: Dictionary = {}
|
||||
var dropped_items: Dictionary = {}
|
||||
var portals: Dictionary = {}
|
||||
var loot_chests: Dictionary = {}
|
||||
var active_projectiles: Dictionary = {} # Projectiles from DUNGEON_STATE spatial tick
|
||||
var hazards: Dictionary = {} # Active hazard zones from DUNGEON_STATE
|
||||
|
||||
# Inventory
|
||||
var inventory: Array = []
|
||||
@@ -232,6 +235,8 @@ func _handle_hub_state(data: Dictionary):
|
||||
"gold": int(c.get("gold", c.get("Gold", 0)))
|
||||
}
|
||||
if current_state != STATE_PLAYING and current_state != STATE_DEAD:
|
||||
# Cancel the fallback timer — server responded in time
|
||||
_hub_fallback_timer = null
|
||||
set_state(STATE_HUB)
|
||||
character_updated.emit()
|
||||
|
||||
@@ -516,6 +521,22 @@ func _handle_dungeon_state(data: Dictionary):
|
||||
var lcid = lc.get("id", lc.get("Id"))
|
||||
loot_chests[lcid] = lc
|
||||
|
||||
# Parse active projectiles (spatially-filtered, sent each tick like mobs)
|
||||
var projs = data.get("projectiles", data.get("Projectiles", []))
|
||||
active_projectiles.clear()
|
||||
for proj in projs:
|
||||
var pid = proj.get("id", proj.get("Id"))
|
||||
if pid != null:
|
||||
active_projectiles[pid] = proj
|
||||
|
||||
# Parse active hazard zones (ability type 29 ground effects)
|
||||
var hzs = data.get("hazards", data.get("Hazards", []))
|
||||
hazards.clear()
|
||||
for hz in hzs:
|
||||
var hid = hz.get("id", hz.get("Id"))
|
||||
if hid != null:
|
||||
hazards[hid] = hz
|
||||
|
||||
# Parse events (damage, deaths, projectile hits/expires)
|
||||
var events = data.get("events")
|
||||
if events:
|
||||
@@ -600,7 +621,7 @@ func _handle_levelup(data: Dictionary):
|
||||
func _handle_escape_success(_data: Dictionary):
|
||||
print("[GameState] Escape successful! Returning to hub...")
|
||||
is_escaping = false
|
||||
|
||||
|
||||
# Clear dungeon data
|
||||
players.clear()
|
||||
mobs.clear()
|
||||
@@ -608,6 +629,9 @@ func _handle_escape_success(_data: Dictionary):
|
||||
chests.clear()
|
||||
dropped_items.clear()
|
||||
portals.clear()
|
||||
loot_chests.clear()
|
||||
active_projectiles.clear()
|
||||
hazards.clear()
|
||||
dungeon = {
|
||||
"id": "",
|
||||
"tier": 1,
|
||||
@@ -616,9 +640,23 @@ func _handle_escape_success(_data: Dictionary):
|
||||
"tiles": [],
|
||||
"phase": "active"
|
||||
}
|
||||
|
||||
set_state(STATE_PORTALUSED)
|
||||
escaped.emit()
|
||||
# Server will send HUB_STATE next which will call set_state(STATE_HUB)
|
||||
# Server will send HUB_STATE next which will call set_state(STATE_HUB).
|
||||
# Safety timeout: if HUB_STATE never arrives (network drop), force transition.
|
||||
_start_hub_fallback_timer()
|
||||
|
||||
func _start_hub_fallback_timer():
|
||||
# Cancel any existing fallback timer
|
||||
if _hub_fallback_timer and _hub_fallback_timer.time_left > 0:
|
||||
_hub_fallback_timer.timeout.disconnect(_on_hub_fallback_timeout)
|
||||
_hub_fallback_timer = get_tree().create_timer(5.0)
|
||||
_hub_fallback_timer.timeout.connect(_on_hub_fallback_timeout)
|
||||
|
||||
func _on_hub_fallback_timeout():
|
||||
if current_state == STATE_PORTALUSED or current_state == STATE_DUNGEONCLEARED:
|
||||
print("[GameState] HUB_STATE not received in time — forcing transition to HUB")
|
||||
set_state(STATE_HUB)
|
||||
|
||||
# Helper functions
|
||||
func send_move(dx: float, dy: float, aim_angle: float):
|
||||
@@ -687,7 +725,7 @@ func send_use_portal(portal_id: int):
|
||||
func _handle_portal_used(_data: Dictionary):
|
||||
print("[GameState] Portal used! Returning to hub...")
|
||||
is_escaping = false
|
||||
|
||||
|
||||
# Clear dungeon data
|
||||
players.clear()
|
||||
mobs.clear()
|
||||
@@ -696,6 +734,8 @@ func _handle_portal_used(_data: Dictionary):
|
||||
dropped_items.clear()
|
||||
portals.clear()
|
||||
loot_chests.clear()
|
||||
active_projectiles.clear()
|
||||
hazards.clear()
|
||||
dungeon = {
|
||||
"id": "",
|
||||
"tier": 1,
|
||||
@@ -706,7 +746,9 @@ func _handle_portal_used(_data: Dictionary):
|
||||
}
|
||||
set_state(STATE_PORTALUSED)
|
||||
escaped.emit()
|
||||
# Server will send HUB_STATE next which will call set_state(STATE_HUB)
|
||||
# Server will send HUB_STATE next which will call set_state(STATE_HUB).
|
||||
# Safety timeout: if HUB_STATE never arrives (network drop), force transition.
|
||||
_start_hub_fallback_timer()
|
||||
|
||||
# Loot chest handlers
|
||||
func _handle_loot_chest_spawned(data: Dictionary):
|
||||
|
||||
Reference in New Issue
Block a user