Add matchmaking + gameplay services (SOR.Matchmaking + SOR.Game)
DB layer:
- Account.RankScore (int, default 1000) — ELO rank for matchmaking
- GameEnums: MatchmakingStatus, GameSessionStatus, GamePhase
- Entities: MatchmakingEntry, GameSession, GameActionLog
- GameDbContext (schema: game) + AddGameDatabase() registration
- Migrations: AddRankScore (Identity), InitialCreate (Game)
SOR.Matchmaking:
- MatchmakerService (BackgroundService) — 5s poll, ELO ±100→±500 range
- Handlers: matchmaking.join, matchmaking.leave, matchmaking.status
- Pushes MatchFoundPush to both players via IClientPush on match
SOR.Game:
- GameState / PlayerState / CardInstance / FieldCard JSONB model
- GameEngine (pure static): Init, Draw, PlayCard, Attack, EndTurn, Concede
- ELO delta (K=32) computed and applied on game end
- Handlers: game.ready, game.get_state, game.draw, game.play_card,
game.attack, game.end_turn, game.concede
- State filtered per-viewer (opponent hand/deck hidden)
- GameOverPush with rank deltas to both players
Admin pages:
- /game/matchmaking — live queue stats, active entries, recent activity
- /game/sessions — session stats, filterable by status/account
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
namespace SOR.Game;
|
||||
|
||||
// ── Requests ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Signal that the player has loaded the game screen and is ready to start.</summary>
|
||||
public sealed record GameReadyRequest(Guid SessionId);
|
||||
|
||||
/// <summary>Request the current (filtered) game state for the caller.</summary>
|
||||
public sealed record GameGetStateRequest(Guid SessionId);
|
||||
|
||||
/// <summary>Draw a card from the player's deck.</summary>
|
||||
public sealed record GameDrawRequest(Guid SessionId);
|
||||
|
||||
/// <summary>Play a card from hand onto the field.</summary>
|
||||
public sealed record GamePlayCardRequest(Guid SessionId, string CardInstanceId);
|
||||
|
||||
/// <summary>Attack an opponent card (or their ArchSpirit) with one of your field cards.</summary>
|
||||
public sealed record GameAttackRequest(
|
||||
Guid SessionId,
|
||||
string AttackerInstanceId,
|
||||
string TargetInstanceId);
|
||||
|
||||
/// <summary>End the active player's turn.</summary>
|
||||
public sealed record GameEndTurnRequest(Guid SessionId);
|
||||
|
||||
/// <summary>Concede the game (forfeit).</summary>
|
||||
public sealed record GameConcedeRequest(Guid SessionId);
|
||||
|
||||
// ── Responses ─────────────────────────────────────────────────────────────────
|
||||
|
||||
public sealed record GameReadyResponse(Guid SessionId, string Status);
|
||||
// Status: "WaitingForOpponent" | "Started"
|
||||
|
||||
public sealed record GameGetStateResponse(GameStateDto State);
|
||||
|
||||
public sealed record GameDrawResponse(GameStateDto State);
|
||||
|
||||
public sealed record GamePlayCardResponse(GameStateDto State);
|
||||
|
||||
public sealed record GameAttackResponse(GameStateDto State);
|
||||
|
||||
public sealed record GameEndTurnResponse(GameStateDto State);
|
||||
|
||||
public sealed record GameConcedeResponse(GameStateDto State);
|
||||
|
||||
// ── Server Pushes ─────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Pushed to both players after any game action that changes state.
|
||||
/// Each player receives a version filtered for their perspective
|
||||
/// (opponent hand/deck contents are hidden).
|
||||
/// </summary>
|
||||
public sealed record GameStateUpdatePush(GameStateDto State);
|
||||
|
||||
/// <summary>Pushed to both players when the game ends.</summary>
|
||||
public sealed record GameOverPush(
|
||||
Guid SessionId,
|
||||
Guid WinnerAccountId,
|
||||
Guid LoserAccountId,
|
||||
string WinCondition, // "health" | "concede" | "disconnect"
|
||||
int WinnerRankDelta,
|
||||
int LoserRankDelta);
|
||||
|
||||
// ── DTOs ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Client-facing game state — opponent's private zones (hand, deck) are filtered.
|
||||
/// </summary>
|
||||
public sealed record GameStateDto(
|
||||
Guid SessionId,
|
||||
string Phase, // Draw | Main | End | GameOver
|
||||
string ActivePlayerAccountId,
|
||||
int TurnNumber,
|
||||
IEnumerable<PlayerStateDto> Players);
|
||||
|
||||
public sealed record PlayerStateDto(
|
||||
Guid AccountId,
|
||||
int HandCount, // always shown; actual cards visible only for self
|
||||
int DeckCount,
|
||||
IEnumerable<CardInstanceDto>? Hand, // null for opponent
|
||||
IEnumerable<CardInstanceDto> Field, // always visible
|
||||
IEnumerable<CardInstanceDto> Graveyard,
|
||||
CardInstanceDto? ArchSpirit, // leader card on field
|
||||
int CurrentSp, // spirit points this turn
|
||||
int MaxSp,
|
||||
int CurrentSt, // stone points this turn
|
||||
int MaxSt);
|
||||
|
||||
public sealed record CardInstanceDto(
|
||||
string InstanceId,
|
||||
Guid CardDefinitionId,
|
||||
string Name,
|
||||
string CardType,
|
||||
string Affinity,
|
||||
string Rarity,
|
||||
int? CurrentHealth,
|
||||
int? MaxHealth,
|
||||
int? CurrentDefense,
|
||||
int? MaxDefense,
|
||||
int? Damage,
|
||||
bool IsExhausted,
|
||||
bool IsEntrySick,
|
||||
bool IsLeader); // true for the ArchSpirit
|
||||
Reference in New Issue
Block a user