public bool RunTurnFromMainPhase(Interactions.TacticalPhase.CompiledResponse compiledMainPhaseResponse) { if (m_gameFlowThread != null && System.Threading.Thread.CurrentThread != m_gameFlowThread || CurrentPhase != "Main") { throw new InvalidOperationException("Can't run turn from main phase."); } while (true) { var result = compiledMainPhaseResponse != null ? compiledMainPhaseResponse.Restore(ActingPlayer) : new Interactions.TacticalPhase(ActingPlayer).Run(); compiledMainPhaseResponse = null; if (result.ActionType == Interactions.BaseInteraction.PlayerAction.PlayCard) { var cardToPlay = (CardInstance)result.Data; Debug.Assert(cardToPlay.Owner == ActingPlayer); StackAndFlush(new Commands.PlayCard(cardToPlay, SystemZone.Battlefield, this)); } else if (result.ActionType == Interactions.BaseInteraction.PlayerAction.ActivateAssist) { var cardToActivate = (CardInstance)result.Data; Debug.Assert(cardToActivate.Owner == ActingPlayer); var ctx = CreateResolveContext(); foreach (var card in ActingPlayer.ActivatedAssits) { ctx.QueueCommand(new Commands.DeactivateAssist(card)); } ctx.QueueCommand(new Commands.ActivateAssist(cardToActivate)); StackAndFlush(ctx); } else if (result.ActionType == Interactions.BaseInteraction.PlayerAction.CastSpell) { var spellToCast = (Behaviors.ICastableSpell)result.Data; Debug.Assert(spellToCast.Host.Owner == ActingPlayer); StackAndFlush(new Commands.CastSpell(spellToCast)); } else if (result.ActionType == Interactions.BaseInteraction.PlayerAction.Sacrifice) { var cardToSacrifice = (CardInstance)result.Data; StackAndFlush( new Commands.InitiativeMoveCard(cardToSacrifice, SystemZone.Sacrifice, this), new Commands.AddPlayerMana(ActingPlayer, 1, true, this)); DidSacrifice = true; } else if (result.ActionType == Interactions.BaseInteraction.PlayerAction.Redeem) { var cardToRedeem = (CardInstance)result.Data; StackAndFlush(new Commands.InitiativeMoveCard(cardToRedeem, SystemZone.Hand, this)); DidRedeem = true; } else if (result.ActionType == Interactions.BaseInteraction.PlayerAction.AttackCard) { var pair = (CardInstance[])result.Data; var attackerWarrior = pair[0].Warrior; StackAndFlush( new Commands.DealDamageToCard(pair[1], attackerWarrior.Attack, attackerWarrior), new Commands.SendBehaviorMessage(attackerWarrior, Behaviors.WarriorMessage.GoCoolingDown, null)); } else if (result.ActionType == Interactions.BaseInteraction.PlayerAction.AttackPlayer) { var pair = (object[])result.Data; var attackerWarrior = (pair[0] as CardInstance).Warrior; StackAndFlush( new Commands.SubtractPlayerLife(pair[1] as Player, attackerWarrior.Attack, attackerWarrior), new Commands.SendBehaviorMessage(attackerWarrior, Behaviors.WarriorMessage.GoCoolingDown, null)); } else if (result.ActionType == Interactions.BaseInteraction.PlayerAction.Pass) { break; } else if (result.ActionType == Interactions.BaseInteraction.PlayerAction.Abort) { return false; } else { throw new InvalidDataException(); } } StackAndFlush( new Commands.EndPhase(), new Commands.StartPhase("Cleanup"), new Commands.EndPhase(), new Commands.EndTurn(ActingPlayer)); return true; }