using System; using System.Linq; using KernelPanic.Core; namespace KernelPanic.Combat { public enum GoOperation { None, Deploy, Extend, ExtendAll, Cancel, WaitGroup, Gosched, Select, NumGoroutines, Rollback } public sealed class GoEffect : ICardEffect { private readonly GoOperation _operation; private readonly int _amount, _ticks; public GoEffect(GoOperation operation, int amount, int ticks = 0) { _operation = operation; _amount = amount; _ticks = ticks; } public static GoOperation OperationFor(CardInstance card) => card?.Definition != null && CardCatalog.TryGet(card.Definition.Id, out var entry) ? (GoOperation)(entry.Effects.FirstOrDefault(effect => effect.Kind == CardEffectKind.Go)?.SecondaryAmount ?? 0) : GoOperation.None; public void Execute(CombatContext context) { var combat = context.CombatManager; var go = combat.Go; switch (_operation) { case GoOperation.Deploy: combat.DeployGoroutine(context, _amount, _ticks); break; case GoOperation.Extend: go.Extend(combat.SelectedGoroutine, _amount); break; case GoOperation.ExtendAll: foreach (var work in go.Active.ToArray()) go.Extend(work, _amount); break; case GoOperation.Cancel: if (go.Terminate(combat.SelectedGoroutine)) new ShieldEffect(_amount).Execute(context); break; case GoOperation.WaitGroup: new ShieldEffect(Math.Min(9, 3 * go.Count)).Execute(context); break; case GoOperation.Gosched: new FixedDrawEffect(1).Execute(context); if (go.Count > 0) new ShieldEffect(1).Execute(context); break; case GoOperation.Select: new DealDamageEffect(3 * go.Count, 3 * go.Count, Core.Language.Go).Execute(context); break; case GoOperation.NumGoroutines: new FixedDrawEffect(Math.Min(3, go.Count)).Execute(context); break; case GoOperation.Rollback: if (combat.CanPlayerReceiveCardHeal(context.Card)) { int heal = UpgradeMath.ScaleAmount(UpgradeMath.ApplySourceFlatBonus(_amount, context), context.Card); context.Source.CurrentUptime = Math.Min(context.Source.MaxUptime, CardScaling.Add(context.Source.CurrentUptime, heal)); } go.Extend(combat.SelectedGoroutine, 1); break; } if (_operation != GoOperation.Deploy) combat.CancelGoroutineSelection(); } } }