71 lines
2.7 KiB
C#
71 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using KernelPanic.Core;
|
|
|
|
namespace KernelPanic.Combat
|
|
{
|
|
/// <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 / 100m).ToString("0.0#", System.Globalization.CultureInfo.InvariantCulture);
|
|
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 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 || _cards.Contains(card)) return;
|
|
int multiplier = 100;
|
|
if (card.Definition != null && card.Definition.Language == Language.Haskell)
|
|
multiplier = CombatTuning.HaskellStackMultiplierPercent(_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 ForceEvaluate(CombatContext context) => context?.CombatManager?.EvaluateLazyStack();
|
|
|
|
public bool TryPopEntry(out LazyStackEntry entry)
|
|
{
|
|
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)
|
|
{
|
|
bool popped = TryPopEntry(out var entry);
|
|
card = entry?.Card;
|
|
if (popped) GameEvents.RaiseCardResolving(new CardResolvedEvent(card, ResolutionTrack.LazyStack));
|
|
return popped;
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
foreach (var card in _cards) card.SetTargetSnapshot(Array.Empty<CombatantState>());
|
|
_entries.Clear();
|
|
_cards.Clear();
|
|
}
|
|
}
|
|
}
|