using System; using System.Collections.Generic; using System.Linq; using KernelPanic.Combat; using KernelPanic.Core; namespace KernelPanic.Meta { [Serializable] public sealed class CardPerformance { public string cardId; public string name; public long plays, uptimeDamage, shieldDamage, shieldGranted; public CardPerformance Copy() => (CardPerformance)MemberwiseClone(); } [Serializable] public sealed class RunPerformanceSnapshot { public int schemaVersion = 1; public bool complete = true; public long damageDealt, damageTaken, shieldBlocked, cardsPlayed; public List cards = new(); public RunPerformanceSnapshot Copy() { var copy = (RunPerformanceSnapshot)MemberwiseClone(); copy.cards = (cards ?? new()).Where(c => c != null).Select(c => c.Copy()).ToList(); return copy; } private CardPerformance Find(CardInstance card) { if (card?.Definition == null) return null; cards ??= new(); var result = cards.Find(c => c.cardId == card.Definition.Id); if (result != null) return result; result = new CardPerformance { cardId = card.Definition.Id, name = card.Definition.DisplayName }; cards.Add(result); return result; } public void RecordPlay(CardInstance card) { var entry = Find(card); if (entry == null) return; entry.plays++; cardsPlayed++; } public void Record(CardContributionEvent contribution) { var entry = Find(contribution.Card); if (entry == null) return; entry.uptimeDamage += Math.Max(0, contribution.UptimeDamage); entry.shieldDamage += Math.Max(0, contribution.ShieldDamage); entry.shieldGranted += Math.Max(0, contribution.ShieldGranted); } } }