297 lines
11 KiB
Plaintext
297 lines
11 KiB
Plaintext
@namespace Shared.Pages
|
|
@inject CardRenderingService CardRenderer
|
|
@inject Shared.Services.CardPreviewService PreviewService
|
|
@page "/decks/{Name}"
|
|
|
|
<PageTitle>Chrono CCG - @(deck?.Name ?? "Deck Details")</PageTitle>
|
|
|
|
<HeadContent>
|
|
<meta name="description"
|
|
content="@(deck != null ? $"View details for the {deck.Name} deck. {deck.Cards.Count} cards, {deck.Syndicates.Count} factions." : "Deck details and card list.")"/>
|
|
</HeadContent>
|
|
|
|
<div class="deck-detail-page">
|
|
<a class="back-link" href="/decks"><i class="bi bi-arrow-left"></i> Back to Decks</a>
|
|
|
|
@if (deck == null)
|
|
{
|
|
<div class="empty-state">
|
|
<i class="bi bi-exclamation-circle"></i>
|
|
<p>Deck not found.</p>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<article class="deck-article">
|
|
<header class="deck-header">
|
|
<h1>@deck.Name</h1>
|
|
<b>Deck Code:</b>
|
|
<pre>@deck.DeckCode</pre>
|
|
@if (deck.Syndicates.Count > 0)
|
|
{
|
|
<div class="deck-factions">
|
|
@foreach (var f in deck.Syndicates)
|
|
{
|
|
<span class="faction-badge">@f</span>
|
|
}
|
|
</div>
|
|
}
|
|
<div class="deck-card-count">
|
|
<span>@deck.Cards.Count cards</span>
|
|
<span class="ms-3 badge @(deck.IsValid ? "bg-success" : "bg-danger")">
|
|
@(deck.IsValid ? "Valid" : "Invalid")
|
|
</span>
|
|
@if (!deck.IsValid)
|
|
{
|
|
<small class="text-danger ms-2 d-block d-md-inline">@deck.ValidationMessage</small>
|
|
}
|
|
</div>
|
|
|
|
<ManaCurve Distribution="GetManaDistribution()" MaxCostLabel="10"/>
|
|
</header>
|
|
|
|
@if (deck.Keycards.Count > 0)
|
|
{
|
|
<section class="deck-section">
|
|
<h2><i class="bi bi-star-fill" style="color: var(--gold);"></i> Keycards</h2>
|
|
<CardGrid Cards="deck.Keycards" OnSelectCard="SelectCard"/>
|
|
</section>
|
|
}
|
|
|
|
@if (deck.Divers.Count > 0)
|
|
{
|
|
<section class="deck-section">
|
|
<h2><i class="bi bi-shuffle"></i> Divers</h2>
|
|
<CardGrid Cards="deck.Divers" OnSelectCard="SelectCard"/>
|
|
</section>
|
|
}
|
|
|
|
<section class="deck-section">
|
|
<h2><i class="bi bi-collection-fill"></i> Cards</h2>
|
|
<CardGrid Cards="deck.Cards" OnSelectCard="SelectCard"/>
|
|
</section>
|
|
|
|
@if (deck.Description != null)
|
|
{
|
|
<section class="deck-section description">
|
|
<h2><i class="bi bi-chat-quote-fill"></i> Description</h2>
|
|
<div class="deck-description">
|
|
@CardRenderer.RenderDescription(deck.Description, SelectCard, doc => PreviewService.SelectDoc(doc), PreviewService)
|
|
</div>
|
|
</section>
|
|
}
|
|
|
|
<section class="deck-section simulator">
|
|
<div class="simulator-header">
|
|
<h2><i class="bi bi-play-circle-fill"></i> Opening Hand Simulator</h2>
|
|
<div class="simulator-controls">
|
|
@if (hand.Count == 0)
|
|
{
|
|
<button class="btn btn-primary" @onclick="DrawInitialHand">
|
|
<i class="bi bi-hand-index-thumb"></i> Draw Hand
|
|
</button>
|
|
}
|
|
else
|
|
{
|
|
<button class="btn btn-outline-secondary btn-sm" @onclick="DrawInitialHand">
|
|
<i class="bi bi-arrow-clockwise"></i> Reset
|
|
</button>
|
|
@if (!hasMulliganed)
|
|
{
|
|
<button class="btn btn-warning btn-sm" @onclick="Mulligan" disabled="@(!canMulligan)">
|
|
<i class="bi bi-shuffle"></i> Mulligan Selected (@mulliganSelected.Count)
|
|
</button>
|
|
}
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
@if (hand.Count > 0)
|
|
{
|
|
<div class="hand-display">
|
|
@foreach (var card in hand)
|
|
{
|
|
var isDiver = deck.Divers.Contains(card.Name);
|
|
var isSelected = mulliganSelected.Contains(card);
|
|
<div class="hand-card-wrapper @(isDiver ? "diver" : "") @(isSelected ? "selected" : "")"
|
|
@onclick="() => ToggleMulliganSelection(card)">
|
|
<div class="hand-card-img" @onmouseenter="e => PreviewService.Show(card, e.ClientX, e.ClientY)" @onmouseleave="() => PreviewService.Hide()">
|
|
@if (!string.IsNullOrEmpty(card.ImageFile))
|
|
{
|
|
<img src="cards/@card.ImageFile" alt="@card.Name" />
|
|
}
|
|
else
|
|
{
|
|
<div class="card-placeholder">@card.Name</div>
|
|
}
|
|
</div>
|
|
@if (isDiver)
|
|
{
|
|
<span class="diver-tag">Diver</span>
|
|
}
|
|
@if (isSelected)
|
|
{
|
|
<div class="mulligan-overlay"><i class="bi bi-trash"></i></div>
|
|
}
|
|
</div>
|
|
}
|
|
</div>
|
|
<p class="simulator-hint">
|
|
@if (!hasMulliganed)
|
|
{
|
|
<span>Select non-diver cards to mulligan. You can only mulligan once.</span>
|
|
}
|
|
else
|
|
{
|
|
<span class="text-success">Mulligan used.</span>
|
|
}
|
|
</p>
|
|
}
|
|
</section>
|
|
</article>
|
|
}
|
|
</div>
|
|
|
|
<CardDetailModal Card="selectedCard"
|
|
OnClose="CloseDetail"
|
|
OnSelectCard="SelectCard"
|
|
DescriptionRenderer="@(desc => CardRenderer.RenderDescription(desc, SelectCard, doc => PreviewService.SelectDoc(doc), PreviewService))"/>
|
|
|
|
@code {
|
|
[Parameter] public string Name { get; set; } = "";
|
|
|
|
private DeckData? deck;
|
|
private CardData? selectedCard;
|
|
|
|
private bool HasImage => selectedCard?.ImageFile is { Length: > 0 } && selectedCard.ImageFile != "placeholder.png";
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
var decoded = Uri.UnescapeDataString(Name);
|
|
deck = DeckDatabase.Decks.FirstOrDefault(d => d.IsVisible && d.Name == decoded);
|
|
}
|
|
|
|
private static readonly Dictionary<string, CardData> CardLookup = CardDatabase.Cards
|
|
.Where(c => !string.IsNullOrWhiteSpace(c.Name))
|
|
.GroupBy(c => c.Name, StringComparer.OrdinalIgnoreCase)
|
|
.ToDictionary(g => g.Key, g => g.First(), StringComparer.OrdinalIgnoreCase);
|
|
|
|
private CardData? LookupCard(string cardName)
|
|
{
|
|
return CardLookup.GetValueOrDefault(cardName);
|
|
}
|
|
|
|
private void SelectCard(CardData? card)
|
|
{
|
|
selectedCard = card;
|
|
}
|
|
|
|
private void CloseDetail()
|
|
{
|
|
selectedCard = null;
|
|
}
|
|
|
|
private List<CardData> hand = [];
|
|
private HashSet<CardData> mulliganSelected = [];
|
|
private bool hasMulliganed = false;
|
|
private bool canMulligan => mulliganSelected.Count > 0 && !hasMulliganed;
|
|
|
|
private void DrawInitialHand()
|
|
{
|
|
if (deck == null) return;
|
|
hand.Clear();
|
|
mulliganSelected.Clear();
|
|
hasMulliganed = false;
|
|
|
|
var random = new Random();
|
|
|
|
// 1. Get Divers
|
|
var divers = deck.Divers.Select(LookupCard).Where(c => c != null).Cast<CardData>().ToList();
|
|
// 2. Get Main Deck (excluding divers if they are in the main list, though usually they are separate in data)
|
|
var mainDeck = deck.Cards.Select(LookupCard).Where(c => c != null).Cast<CardData>().ToList();
|
|
|
|
|
|
|
|
// Add 3 random non-diver cards from main deck
|
|
var nonDivers = mainDeck.Where(c => !deck.Divers.Contains(c.Name)).OrderBy(_ => random.Next()).Take(4).ToList();
|
|
hand.AddRange(nonDivers);
|
|
|
|
// Final shuffle of hand for display
|
|
hand = hand.OrderBy(_ => random.Next()).ToList();
|
|
|
|
// Add 2 random divers
|
|
if (divers.Count > 0)
|
|
{
|
|
var newHand = divers.Take(2).ToList();
|
|
newHand.AddRange(hand);
|
|
|
|
hand = newHand;
|
|
}
|
|
}
|
|
|
|
private void ToggleMulliganSelection(CardData card)
|
|
{
|
|
if (hasMulliganed) return;
|
|
if (deck?.Divers.Contains(card.Name) == true) return; // Cannot mulligan divers
|
|
|
|
if (mulliganSelected.Contains(card))
|
|
mulliganSelected.Remove(card);
|
|
else
|
|
mulliganSelected.Add(card);
|
|
}
|
|
|
|
private void Mulligan()
|
|
{
|
|
if (deck == null || hasMulliganed || mulliganSelected.Count == 0) return;
|
|
|
|
var random = new Random();
|
|
var mainDeck = deck.Cards.Select(LookupCard).Where(c => c != null).Cast<CardData>().ToList();
|
|
var nonDiversInDeck = mainDeck.Where(c => !deck.Divers.Contains(c.Name)).ToList();
|
|
|
|
// Filter out cards currently in hand
|
|
var currentHandNames = hand.Select(c => c.Name).ToList();
|
|
var availablePool = nonDiversInDeck.Where(c => !currentHandNames.Contains(c.Name)).ToList();
|
|
|
|
var cardsToReplace = mulliganSelected.ToList();
|
|
foreach (var oldCard in cardsToReplace)
|
|
{
|
|
if (availablePool.Count > 0)
|
|
{
|
|
var newCardIdx = random.Next(availablePool.Count);
|
|
var newCard = availablePool[newCardIdx];
|
|
|
|
var handIdx = hand.IndexOf(oldCard);
|
|
if (handIdx != -1)
|
|
{
|
|
hand[handIdx] = newCard;
|
|
}
|
|
availablePool.RemoveAt(newCardIdx);
|
|
}
|
|
}
|
|
|
|
mulliganSelected.Clear();
|
|
hasMulliganed = true;
|
|
}
|
|
|
|
private List<(int Cost, int Count)> GetManaDistribution()
|
|
{
|
|
if (deck == null) return [];
|
|
var counts = new Dictionary<int, int>();
|
|
for (var i = 0; i <= 10; i++) counts[i] = 0;
|
|
|
|
foreach (var cardName in deck.Cards)
|
|
{
|
|
var card = LookupCard(cardName);
|
|
if (card?.Cost != null)
|
|
{
|
|
var cost = card.Cost.Value;
|
|
if (cost >= 10) cost = 10;
|
|
counts[cost]++;
|
|
}
|
|
}
|
|
|
|
return counts.OrderBy(x => x.Key).Select(x => (x.Key, x.Value)).ToList();
|
|
}
|
|
|
|
}
|