Add tutorial and QoL improvements
This commit is contained in:
@@ -1,55 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using KernelPanic.Core;
|
||||
|
||||
namespace KernelPanic.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores played cards in LIFO order until explicitly force-evaluated.
|
||||
/// </summary>
|
||||
/// <summary>Immutable execution snapshot, owned by an enqueue, never by a clonable card.</summary>
|
||||
public sealed class LazyStackEntry
|
||||
{
|
||||
public CardInstance Card { get; }
|
||||
public int MultiplierPercent { get; }
|
||||
public IReadOnlyList<CombatantState> Targets { get; }
|
||||
public string MultiplierLabel => $"x{MultiplierPercent / 100}.{MultiplierPercent % 100 / 10}";
|
||||
internal LazyStackEntry(CardInstance card, int multiplierPercent)
|
||||
{
|
||||
Card = card;
|
||||
MultiplierPercent = multiplierPercent;
|
||||
Targets = Array.AsReadOnly(card.TargetSnapshot.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Top-first immutable snapshots. CombatManager alone executes/disposes cards.</summary>
|
||||
public sealed class LazyStack : IResolutionTrack
|
||||
{
|
||||
private readonly Stack<CardInstance> _stackedCards = new();
|
||||
private readonly List<CardInstance> _stackedView = new();
|
||||
|
||||
public int Count => _stackedCards.Count;
|
||||
public IReadOnlyList<CardInstance> Cards => _stackedView;
|
||||
private readonly List<LazyStackEntry> _entries = new();
|
||||
private readonly List<CardInstance> _cards = new();
|
||||
public int Count => _entries.Count;
|
||||
public IReadOnlyList<CardInstance> Cards => _cards.AsReadOnly();
|
||||
public IReadOnlyList<LazyStackEntry> Entries => _entries.AsReadOnly();
|
||||
|
||||
public void Enqueue(CardInstance card)
|
||||
{
|
||||
if (card == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_stackedCards.Push(card);
|
||||
_stackedView.Insert(0, card);
|
||||
if (card == null || _cards.Contains(card)) return;
|
||||
int multiplier = 100;
|
||||
if (card.Definition != null && card.Definition.Language == Language.Haskell)
|
||||
multiplier = 100 + 50 * Math.Min(3, _entries.Count(e => e.Card.Definition != null && e.Card.Definition.Language == Language.Haskell));
|
||||
_entries.Insert(0, new LazyStackEntry(card, multiplier));
|
||||
_cards.Insert(0, card);
|
||||
}
|
||||
|
||||
public void Resolve(CombatContext context)
|
||||
{
|
||||
ForceEvaluate(context);
|
||||
}
|
||||
public void Resolve(CombatContext context) => ForceEvaluate(context);
|
||||
public void ForceEvaluate(CombatContext context) => context?.CombatManager?.EvaluateLazyStack();
|
||||
|
||||
public void ForceEvaluate(CombatContext context)
|
||||
public bool TryPopEntry(out LazyStackEntry entry)
|
||||
{
|
||||
while (TryPop(out CardInstance card))
|
||||
{
|
||||
GameEvents.RaiseCardResolved(new CardResolvedEvent(card, ResolutionTrack.LazyStack));
|
||||
}
|
||||
entry = null;
|
||||
if (_entries.Count == 0) return false;
|
||||
entry = _entries[0];
|
||||
_entries.RemoveAt(0);
|
||||
_cards.RemoveAt(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryPop(out CardInstance card)
|
||||
{
|
||||
if (_stackedCards.Count == 0)
|
||||
{
|
||||
card = null;
|
||||
return false;
|
||||
}
|
||||
bool popped = TryPopEntry(out var entry);
|
||||
card = entry?.Card;
|
||||
if (popped) GameEvents.RaiseCardResolving(new CardResolvedEvent(card, ResolutionTrack.LazyStack));
|
||||
return popped;
|
||||
}
|
||||
|
||||
card = _stackedCards.Pop();
|
||||
_stackedView.Remove(card);
|
||||
GameEvents.RaiseCardResolving(new CardResolvedEvent(card, ResolutionTrack.LazyStack));
|
||||
return true;
|
||||
public void Clear()
|
||||
{
|
||||
foreach (var card in _cards) card.SetTargetSnapshot(Array.Empty<CombatantState>());
|
||||
_entries.Clear();
|
||||
_cards.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user