Beispiel #1
0
        public override void Process()
        {
            MagicEngine e = MagicEngine.CurrentEngine;

            switch (CurrentState)
            {
            case PlayerStates.Init:
                return;

            case PlayerStates.PlayDrawChoice:
                //chose to play first
                e.currentPlayerIndex = e.getPlayerIndex(this);
                CurrentState         = PlayerStates.InitialDraw;
                return;

            case PlayerStates.InitialDraw:
                initialDraw();
                CurrentState = PlayerStates.KeepMuliganChoice;
                return;

            case PlayerStates.KeepMuliganChoice:
                //choose to keep
                CurrentState = PlayerStates.Ready;
                e.RaiseMagicEvent(new MagicEventArg(MagicEventType.PlayerIsReady, this));
                return;
            }


            if (e.pp != this || e.State < EngineStates.CurrentPlayer)
            {
                return;
            }

            if (HasActionPending)
            {
                ActivateAvailableMana(e);
                return;
            }

            if (e.cp == this)
            {
                switch (e.CurrentPhase)
                {
                case GamePhases.Untap:
                    PhaseDone = true;
                    break;

                case GamePhases.Upkeep:
                    PhaseDone = true;
                    break;

                case GamePhases.Draw:
                    PhaseDone = true;
                    break;

                case GamePhases.Main1:
                case GamePhases.Main2:
                    if (AllowedLandsToBePlayed > 0)
                    {
                        if (AITryToPlayLand())
                        {
                            break;
                        }
                    }
                    if (!CastAvailableAndAllowedCreature())
                    {
                        PhaseDone = true;
                    }
                    break;

                case GamePhases.BeforeCombat:
                    PhaseDone = true;
                    break;

                case GamePhases.DeclareAttacker:
                    AITryToAttack();
                    PhaseDone = true;
                    break;

                case GamePhases.DeclareBlocker:
                    PhaseDone = true;
                    break;

                case GamePhases.FirstStrikeDame:
                    PhaseDone = true;
                    break;

                case GamePhases.CombatDamage:
                    PhaseDone = true;
                    break;

                case GamePhases.EndOfCombat:
                    PhaseDone = true;
                    break;

                case GamePhases.EndOfTurn:
                    PhaseDone = true;
                    break;

                case GamePhases.CleanUp:
                    PhaseDone = true;
                    break;
                }
            }
            else
            {
                if (e.pp == this)
                {
                    Magic.AddLog("AI just had priority");
                    e.GivePriorityToNextPlayer();
                }
//				switch (e.CurrentPhase)
//				{
//				case GamePhases.Untap:
//					PhaseDone = true;
//					break;
//				case GamePhases.Upkeep:
//					PhaseDone = true;
//					break;
//				case GamePhases.Draw:
//					PhaseDone = true;
//					break;
//				case GamePhases.Main1:
//					PhaseDone = true;
//					break;
//				case GamePhases.BeforeCombat:
//					PhaseDone = true;
//					break;
//				case GamePhases.DeclareAttacker:
//					PhaseDone = true;
//					break;
//				case GamePhases.DeclareBlocker:
//					PhaseDone = true;
//					break;
//				case GamePhases.FirstStrikeDame:
//					PhaseDone = true;
//					break;
//				case GamePhases.CombatDamage:
//					PhaseDone = true;
//					break;
//				case GamePhases.EndOfCombat:
//					PhaseDone = true;
//					break;
//				case GamePhases.Main2:
//					PhaseDone = true;
//					break;
//				case GamePhases.EndOfTurn:
//					PhaseDone = true;
//					break;
//				case GamePhases.CleanUp:
//					PhaseDone = true;
//					break;
//				}
            }
        }
Beispiel #2
0
        void MagicEngine_MagicEvent(MagicEventArg arg)
        {
            Magic.AddLog("MAGIC EVENT: " + arg.ToString());

            #region check triggers

            //check cards in play having trigger effects
            foreach (CardInstance ci in CardsInPlayHavingTriggers)
            {
                foreach (Trigger t in ci.Model.Triggers)
                {
                    if (t.ExecuteIfMatch(arg, ci))
                    {
                        Magic.AddLog("=> " + t.ToString());
                    }
                }
            }
            //check pump effect
            //todo should simplify trigger checking with a single function
            foreach (CardInstance ci in CardsInPlayHavingPumpEffects)
            {
                List <EffectGroup> egToRemove = new List <EffectGroup>();
                foreach (EffectGroup eg in ci.PumpEffect)
                {
                    if (eg.TrigEnd != null)
                    {
                        if (eg.TrigEnd.Type != arg.Type)
                        {
                            continue;
                        }
                        switch (eg.TrigEnd.Type)
                        {
                        case MagicEventType.EndTurn:
                            egToRemove.Add(eg);
                            break;
                        }
                    }
                }
                foreach (EffectGroup egtr in egToRemove)
                {
                    ci.PumpEffect.Remove(egtr);
                }
            }
            #endregion

            switch (arg.Type)
            {
            case MagicEventType.PlayerIsReady:
                //check if all players are ready
                foreach (Player p in Players)
                {
                    if (p.CurrentState != Player.PlayerStates.Ready)
                    {
                        return;
                    }
                }
                startGame();
                break;

            case MagicEventType.BeginPhase:
                processPhaseBegin(arg as PhaseEventArg);
                break;

            case MagicEventType.EndPhase:
                processPhaseEnd(arg as PhaseEventArg);
                break;

            case MagicEventType.PlayLand:
                break;

            case MagicEventType.ActivateAbility:
                break;

            case MagicEventType.CastSpell:
                break;

            case MagicEventType.TapCard:
                break;

            case MagicEventType.ChangeZone:
                if (arg.Source.IsToken)
                {
                    arg.Source.CurrentGroup.Cards.Remove(arg.Source);
                }
                break;

            case MagicEventType.Unset:
                break;

            default:
                break;
            }

            CheckCardInstanceUpdates();

            foreach (Player p in Players)            //TODO:too wide update
            {
                p.InPlay.UpdateLayout();
            }
        }