caelum0x 6c7cea7592 feat: build out backend services, web client, and game roster
Backend (services/): make the app testable and fill real gaps.
- Extract buildApp() factory; index.ts owns listen()/matcher tick
- Real Apple/Google identity verification via jose JWKS (iss/aud/sub)
- Guest -> OAuth account linking (POST /auth/link), rebind in place
- POST /matches/:id/complete: record match + participants, update
  leaderboard, idempotent, guarded by server-to-server secret
- Extract pure matchmaking pairing (computePairings); fix ticket
  deckId loss on match; map ZodError -> 400; @fastify/cors
- vitest suite (40 tests), initial Prisma migration, prisma schema path

Web (web/): new Vite + React + TS client.
- Typed API client with one-shot 401 refresh/retry, localStorage auth
- Login (guest), deck builder (slot-0 hero rule), queue polling,
  leaderboard; 11 tests, clean build

Game (Assets/, Unity C#): champion-select layout now fits the roster
size; add Golem and Bandit champions.

Docs: root DEVELOPMENT.md tying game + services + web together.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-25 18:15:12 +03:00

78 lines
2.5 KiB
C#

using System.Collections.Generic;
using UnityEngine;
namespace Siegebreak.Cards
{
/// <summary>
/// Clash-Royale-style hand rotation: 8-card deck, 4 visible in hand at
/// once, playing a card draws the next one from the shuffled remainder.
/// Server-authoritative — the client's copy is predictive display only,
/// same pattern as ElixirManager.
/// </summary>
public class DeckManager : MonoBehaviour
{
private const int HandSize = 4;
private List<CardData> _drawPile = new();
private List<CardData> _hand = new();
public IReadOnlyList<CardData> Hand => _hand;
public void Initialize(List<CardData> deck)
{
if (deck.Count != 8)
{
Debug.LogError($"Deck must have exactly 8 cards, got {deck.Count}");
return;
}
_drawPile = new List<CardData>(deck);
Shuffle(_drawPile);
_hand.Clear();
for (var i = 0; i < HandSize; i++)
{
_hand.Add(_drawPile[0]);
_drawPile.RemoveAt(0);
}
}
// Called after the server confirms a deploy (see
// CardDeploymentManager) — never remove from hand optimistically
// before that confirmation, or a rejected deploy leaves the
// client's hand out of sync with the server's.
public bool TryPlay(CardData card, out CardData nextCard)
{
nextCard = null;
var index = _hand.IndexOf(card);
if (index < 0) return false;
_hand.RemoveAt(index);
if (_drawPile.Count == 0)
{
// Discard pile → draw pile reshuffle would go here once a
// full deck-cycling implementation is needed; 8 cards
// cycling through a 4-card hand means this triggers often
// in a real match, so don't leave this TODO for later.
Debug.LogWarning("Draw pile empty — reshuffle not yet implemented");
return true;
}
nextCard = _drawPile[0];
_drawPile.RemoveAt(0);
_hand.Add(nextCard);
return true;
}
private static void Shuffle(List<CardData> list)
{
for (var i = list.Count - 1; i > 0; i--)
{
var j = Random.Range(0, i + 1);
(list[i], list[j]) = (list[j], list[i]);
}
}
}
}