Co-op pass: host-disconnect handling, spectate, late-join wave sync

- Clients now handle the host closing the arena: bank winnings if
  still alive (retire), reset the HUD, and return to the camp menu
  instead of being stranded in a dead world
- Death in co-op offers Spectate when a teammate is still fighting:
  closes the results overlay and watches the run; the escape menu
  gains a "Back to Camp" option for dead spectators to leave later
- Late joiners receive the current wave number on connect so their
  HUD doesn't sit on "Prepare..." until the next wave starts
This commit is contained in:
2026-07-01 23:57:38 +01:00
parent f5e0642b39
commit fb10f7b042
3 changed files with 56 additions and 4 deletions
+19
View File
@@ -45,6 +45,9 @@ func _ready():
# Reshape the menu into the gladiator outfitting screen
_setup_outfitting_menu()
# Clients: if the host closes the arena, bank winnings and return to camp
Network.server_disconnected.connect(_on_server_closed)
# Create or find weapons container
if has_node("WeaponsContainer"):
weapons_container = get_node("WeaponsContainer")
@@ -81,6 +84,19 @@ func _on_connected_to_server():
print("[Level] Connected to server! Cleaning up manual weapons")
_cleanup_manual_weapons_on_client()
## The host closed the arena while we were connected (client side).
## Leaving alive counts as retiring - bank everything, then back to camp.
func _on_server_closed():
print("[Level] Server disconnected - returning to camp")
if GameState.run_active:
GameState.retire_run()
if has_node("/root/HUD"):
get_node("/root/HUD").reset()
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
get_tree().reload_current_scene()
## Called by Network when multiplayer peer is set up
func initialize_multiplayer():
print("[Level] initialize_multiplayer called. is_server: ", multiplayer.is_server())
@@ -235,6 +251,9 @@ func _on_player_connected(peer_id, player_info):
for orb_id in _active_orbs.keys():
rpc_id(peer_id, "_spawn_health_orb_local", orb_id, _active_orbs[orb_id])
# Sync the current wave number so the late joiner's HUD isn't stuck on "Prepare..."
GameState.rpc_id(peer_id, "sync_wave", GameState.current_wave)
# Sync equipped weapons for all existing players to the newly joined player
print("[Server] Syncing equipped weapons to newly connected peer: ", peer_id)
for player_node in players_container.get_children():