Hand simulator and some data fixes
This commit is contained in:
@@ -80,6 +80,74 @@
|
||||
</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>
|
||||
@@ -123,6 +191,88 @@
|
||||
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 [];
|
||||
|
||||
Reference in New Issue
Block a user