be5c41f82f
Match phases (autoload/match_manager.gd, world/game_modes/):
- New server-authoritative MatchManager loops PRE_MATCH (30s countdown,
ships held invisible/uncollidable, flagships creep into formation) ->
IN_PROGRESS (active GameMode's clock runs) -> POST_MATCH (winner
banner, result reported to matchmaking-api) -> back to a fresh
PRE_MATCH forever, matching the always-on server-pool model instead
of kicking players to the menu at match end.
- Win-condition logic lives in a new GameMode abstraction (game_mode.gd
base + team_deathmatch_mode.gd, the only mode so far) so a future
mode is a new subclass plus one factory branch, no timer/scoreboard/
banner code changes needed.
- Three new HUD pieces: match_timer.gd (countdown/clock), scoreboard.gd
(hold-Tab two-team panel), match_banner.gd (winner banner).
- New MatchStats autoload tracks per-match kills/deaths by peer_id
(including bots), hooked into kill_feed_manager's existing
report_kill() call site.
Persistent stats (matchmaking-api/):
- Player gains kills/deaths/hours_played columns; new
POST /matches/report endpoint (server-only, called once at
POST_MATCH) upserts each real player's totals by callsign via a
shared app/crud.py helper also used by the matchmaking-queue join
path. GET /stats/{callsign} returns the new fields alongside mmr/
wins/losses.
Capital-ship fleet polish (world/flagship.gd, world/world.gd,
ships/ship_movement.gd, autoload/game_config.gd):
- Flagship formations are now a clean vertical line (no per-ship
position/rotation jitter) so play_creep_in()'s rigid-group tween
reads as one disciplined fleet arriving together, rising from
directly below (not a random compass direction) over the full 30s
countdown.
- Fixed a real bug where the creep-in tween only ever played on the
server -- MatchManager._run_pre_match() called straight into World,
server-only code a remote client's own process never runs, leaving
their flagships static all match. World now triggers it off
MatchManager.phase_changed instead, which fires identically on every
peer.
- Fixed a second bug (only reachable on a fresh server boot's very
first spawn): a phase==PRE_MATCH check that's true even before the
match loop has genuinely started that phase for the first time fired
play_creep_in() with a bogus zero-duration tween, corrupting the
target the real 30s tween read moments later -- flagships would
settle 4000 units off from their intended formation slot and fire
from there instead. Guarded on get_remaining_seconds() > 0 too.
- The held ship's camera now actively tracks its own team's flagship
centroid every tick during the countdown (position_smoothing
disabled for the hold, since it fights a manually-driven target and
was the reason the fleet read as invisible) instead of sitting fixed
and wide-angle; local offset/zoom/smoothing are explicitly reset on
release so control handback doesn't inherit a stale camera transform.
- _apply_pre_match_hold()/_apply_respawn() now set _dead/
_held_for_pre_match inside the RPC itself, not just in the
server-only caller -- those flags never reached remote clients
before, so WASD wasn't actually blocked for them during the hold.
- Ships now launch from a narrow point directly beneath their own
flagship formation instead of a full-circle scatter around the spawn
marker (which could land a spawn behind/inside a hull). Bumped
flagship_defense_radius so it still comfortably reaches a player who
flies a straight line to the enemy side without correcting for that
new offset.
ISN gets a Stealth Corvette hull mixed into its flagship formation
(assets/images/ships/isn/), banner art renamed off opaque UUID
filenames to isn_banner.jpeg/orc_banner.jpeg.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
162 lines
5.7 KiB
GDScript
162 lines
5.7 KiB
GDScript
extends Node
|
|
|
|
# Server-authoritative match-phase state machine — see overview/map1.md.
|
|
# PRE_MATCH (ships hidden, capital ships creep into formation, countdown) ->
|
|
# IN_PROGRESS (ships released, GameMode's clock runs) -> POST_MATCH (winner
|
|
# banner) -> loops back into a fresh PRE_MATCH, forever, matching this
|
|
# project's always-on server-pool model (see CLAUDE.md item 16) rather than
|
|
# kicking players to the menu at match end.
|
|
#
|
|
# Follows the exact "decide once on the server, RPC-broadcast the concrete
|
|
# value, late joiners pull it" pattern world.gd's decide_offered_races()/
|
|
# _deliver_offered_races already established -- _begin_phase broadcasts a
|
|
# phase change to every already-connected peer; request_match_state() is the
|
|
# pull a late joiner uses to catch up.
|
|
|
|
enum Phase { PRE_MATCH, IN_PROGRESS, POST_MATCH }
|
|
|
|
signal phase_changed(phase: int, duration_sec: float)
|
|
signal match_ended(winner_race_id: int, is_draw: bool)
|
|
|
|
var phase: int = Phase.PRE_MATCH
|
|
var phase_started_at_msec: int = 0
|
|
var phase_duration_sec: float = 0.0
|
|
var current_mode: GameMode = null
|
|
|
|
var _world: Node = null
|
|
|
|
|
|
func _ready() -> void:
|
|
# Every peer builds the same mode object locally from the same shared
|
|
# GameConfig constant -- no replication needed, same as TeamSelect.RACES.
|
|
current_mode = _create_mode(GameConfig.default_game_mode_id)
|
|
|
|
|
|
func _create_mode(mode_id: String) -> GameMode:
|
|
match mode_id:
|
|
"team_deathmatch":
|
|
return TeamDeathmatchMode.new()
|
|
_:
|
|
return TeamDeathmatchMode.new()
|
|
|
|
|
|
# Called once by World._ready() (server only), after map/spawn setup.
|
|
func start(world: Node) -> void:
|
|
if not multiplayer.is_server():
|
|
return
|
|
_world = world
|
|
_run_match_loop()
|
|
|
|
|
|
func _run_match_loop() -> void:
|
|
# Lets this frame's deferred flagship spawn (world.gd's decide_offered_races())
|
|
# land before the first _set_phase(PRE_MATCH) call needs those nodes to exist
|
|
# (see World._on_match_phase_changed(), which is what actually plays the
|
|
# creep-in tween now -- see its own comment for why).
|
|
await get_tree().process_frame
|
|
while true:
|
|
await _run_pre_match()
|
|
await _run_in_progress()
|
|
var result: Dictionary = current_mode.check_win_condition(_world)
|
|
await _run_post_match(result)
|
|
|
|
|
|
func _run_pre_match() -> void:
|
|
MatchStats.reset_for_new_match()
|
|
_world.hold_all_ships_for_pre_match()
|
|
var duration: float = GameConfig.match_pre_match_duration
|
|
# Flagship creep-in is no longer triggered directly from here -- this
|
|
# function only ever runs on the server (see start()), so a direct call
|
|
# into World never reached remote clients, leaving their flagships static
|
|
# the whole match. World now plays it off phase_changed instead (emitted
|
|
# identically on every peer by the RPC below), so this just needs to
|
|
# broadcast the phase.
|
|
_set_phase(Phase.PRE_MATCH, duration)
|
|
await get_tree().create_timer(duration).timeout
|
|
|
|
|
|
func _run_in_progress() -> void:
|
|
var duration: float = current_mode.get_match_duration()
|
|
_set_phase(Phase.IN_PROGRESS, duration)
|
|
_world.release_held_ships()
|
|
var elapsed := 0.0
|
|
while elapsed < duration:
|
|
await get_tree().create_timer(1.0).timeout
|
|
elapsed += 1.0
|
|
if current_mode.should_end_early(_world):
|
|
break
|
|
|
|
|
|
func _run_post_match(result: Dictionary) -> void:
|
|
_set_phase(Phase.POST_MATCH, GameConfig.match_post_match_duration)
|
|
_announce_winner.rpc(result.winner_race_id, result.is_draw)
|
|
_report_match_result(result)
|
|
await get_tree().create_timer(GameConfig.match_post_match_duration).timeout
|
|
|
|
|
|
func _set_phase(new_phase: int, duration: float) -> void:
|
|
_begin_phase.rpc(new_phase, duration)
|
|
|
|
|
|
@rpc("authority", "call_local", "reliable")
|
|
func _begin_phase(new_phase: int, duration: float) -> void:
|
|
phase = new_phase
|
|
phase_duration_sec = duration
|
|
phase_started_at_msec = Time.get_ticks_msec()
|
|
phase_changed.emit(new_phase, duration)
|
|
|
|
|
|
@rpc("authority", "call_local", "reliable")
|
|
func _announce_winner(winner_race_id: int, is_draw: bool) -> void:
|
|
match_ended.emit(winner_race_id, is_draw)
|
|
|
|
|
|
func get_remaining_seconds() -> float:
|
|
var elapsed := (Time.get_ticks_msec() - phase_started_at_msec) / 1000.0
|
|
return max(0.0, phase_duration_sec - elapsed)
|
|
|
|
|
|
@rpc("any_peer", "call_remote", "reliable")
|
|
func request_match_state() -> void:
|
|
if not multiplayer.is_server():
|
|
return
|
|
var sender_id := multiplayer.get_remote_sender_id()
|
|
_deliver_match_state.rpc_id(sender_id, phase, get_remaining_seconds())
|
|
|
|
|
|
@rpc("authority", "call_remote", "reliable")
|
|
func _deliver_match_state(current_phase: int, remaining: float) -> void:
|
|
phase = current_phase
|
|
phase_duration_sec = remaining
|
|
phase_started_at_msec = Time.get_ticks_msec()
|
|
phase_changed.emit(current_phase, remaining)
|
|
|
|
|
|
# Reports this match's final per-player stats to matchmaking-api so
|
|
# Player.kills/deaths/wins/losses/hours_played persist across matches (see
|
|
# overview/map1.md). Bots (negative peer_id) never report -- no backend
|
|
# identity for them, they're padding, not a player's history.
|
|
func _report_match_result(result: Dictionary) -> void:
|
|
if not multiplayer.is_server():
|
|
return
|
|
var players_payload: Array = []
|
|
for peer_id in PlayerRegistry.players:
|
|
if peer_id < 0:
|
|
continue
|
|
var info: Dictionary = PlayerRegistry.get_info(peer_id)
|
|
var stats: Dictionary = MatchStats.get_stats(peer_id)
|
|
var is_winner: bool = not result.is_draw and info.get("race", 0) == result.winner_race_id
|
|
players_payload.append({
|
|
"callsign": info.get("name", ""),
|
|
"team": info.get("race", 0),
|
|
"kills": stats.get("kills", 0),
|
|
"deaths": stats.get("deaths", 0),
|
|
"is_winner": is_winner,
|
|
"seconds_played": current_mode.get_match_duration(),
|
|
})
|
|
if players_payload.is_empty():
|
|
return
|
|
var addr: Dictionary = NetworkManager.get_registered_address()
|
|
var winner_team: int = -1 if result.is_draw else result.winner_race_id
|
|
MatchmakingClient.report_match_result(addr.ip, addr.port, "casual", winner_team, players_payload)
|