Beispiel #1
0
        private void OnSelectIdleCmd(GameServerPacket packet)
        {
            packet.ReadByte(); // player

            m_duel.MainPhase = new MainPhase();
            MainPhase main = m_duel.MainPhase;
            int       count;

            for (int k = 0; k < 5; k++)
            {
                count = packet.ReadByte();
                for (int i = 0; i < count; ++i)
                {
                    packet.ReadInt32(); // card id
                    int          con  = GetLocalPlayer(packet.ReadByte());
                    CardLocation loc  = (CardLocation)packet.ReadByte();
                    int          seq  = packet.ReadByte();
                    ClientCard   card = m_duel.GetCard(con, loc, seq);
                    if (card == null)
                    {
                        continue;
                    }
                    card.ActionIndex[k] = i;
                    switch (k)
                    {
                    case 0:
                        main.SummonableCards.Add(card);
                        break;

                    case 1:
                        main.SpecialSummonableCards.Add(card);
                        break;

                    case 2:
                        main.ReposableCards.Add(card);
                        break;

                    case 3:
                        main.MonsterSetableCards.Add(card);
                        break;

                    case 4:
                        main.SpellSetableCards.Add(card);
                        break;
                    }
                }
            }
            count = packet.ReadByte();
            for (int i = 0; i < count; ++i)
            {
                packet.ReadInt32(); // card id
                int          con  = GetLocalPlayer(packet.ReadByte());
                CardLocation loc  = (CardLocation)packet.ReadByte();
                int          seq  = packet.ReadByte();
                int          desc = packet.ReadInt32();

                ClientCard card = m_duel.GetCard(con, loc, seq);
                if (card == null)
                {
                    continue;
                }
                card.ActionIndex[5] = i;
                if (card.ActionActivateIndex.ContainsKey(desc))
                {
                    card.ActionActivateIndex.Remove(desc);
                }
                card.ActionActivateIndex.Add(desc, i);
                main.ActivableCards.Add(card);
                main.ActivableDescs.Add(desc);
            }

            main.CanBattlePhase = packet.ReadByte() != 0;
            main.CanEndPhase    = packet.ReadByte() != 0;
            if (!Game.IsCheckmate)
            {
                packet.ReadByte(); // CanShuffle
            }
            Connection.Send(CtosMessage.Response, m_ai.OnSelectIdleCmd(main).ToValue());
        }
Beispiel #2
0
        /// <summary>
        /// Called when the AI has to do something during the main phase.
        /// </summary>
        /// <param name="main">A lot of informations about the available actions.</param>
        /// <returns>A new MainPhaseAction containing the action to do.</returns>
        public MainPhaseAction OnSelectIdleCmd(MainPhase main)
        {
            Executor.SetMain(main);
            foreach (CardExecutor exec in Executor.Executors)
            {
                for (int i = 0; i < main.ActivableCards.Count; ++i)
                {
                    ClientCard card = main.ActivableCards[i];
                    if (ShouldExecute(exec, card, ExecutorType.Activate, main.ActivableDescs[i]))
                    {
                        m_dialogs.SendActivate(card.Name);
                        return new MainPhaseAction(MainPhaseAction.MainAction.Activate, card.ActionActivateIndex[main.ActivableDescs[i]]);
                    }
                }
                foreach (ClientCard card in main.MonsterSetableCards)
                {
                    if (ShouldExecute(exec, card, ExecutorType.MonsterSet))
                    {
                        m_dialogs.SendSetMonster();
                        return new MainPhaseAction(MainPhaseAction.MainAction.SetMonster, card.ActionIndex);
                    }
                }
                foreach (ClientCard card in main.ReposableCards)
                {
                    if (ShouldExecute(exec, card, ExecutorType.Repos))
                        return new MainPhaseAction(MainPhaseAction.MainAction.Repos, card.ActionIndex);
                }
                foreach (ClientCard card in main.SpecialSummonableCards)
                {
                    if (ShouldExecute(exec, card, ExecutorType.SpSummon))
                    {
                        m_dialogs.SendSummon(card.Name);
                        return new MainPhaseAction(MainPhaseAction.MainAction.SpSummon, card.ActionIndex);
                    }
                }
                foreach (ClientCard card in main.SummonableCards)
                {
                    if (ShouldExecute(exec, card, ExecutorType.Summon))
                    {
                        m_dialogs.SendSummon(card.Name);
                        return new MainPhaseAction(MainPhaseAction.MainAction.Summon, card.ActionIndex);
                    }
                    if (ShouldExecute(exec, card, ExecutorType.SummonOrSet))
                    {
                        if (Utils.IsEnnemyBetter(true, true) && Utils.IsAllEnnemyBetterThanValue(card.Attack + 300, false) &&
                            main.MonsterSetableCards.Contains(card))
                        {
                            m_dialogs.SendSetMonster();
                            return new MainPhaseAction(MainPhaseAction.MainAction.SetMonster, card.ActionIndex);
                        }
                        m_dialogs.SendSummon(card.Name);
                        return new MainPhaseAction(MainPhaseAction.MainAction.Summon, card.ActionIndex);
                    }
                }
                foreach (ClientCard card in main.SpellSetableCards)
                {
                    if (ShouldExecute(exec, card, ExecutorType.SpellSet))
                        return new MainPhaseAction(MainPhaseAction.MainAction.SetSpell, card.ActionIndex);
                }
            }

            if (main.CanBattlePhase && Duel.Fields[0].HasAttackingMonster())
                return new MainPhaseAction(MainPhaseAction.MainAction.ToBattlePhase);

            m_dialogs.SendEndTurn();
            return new MainPhaseAction(MainPhaseAction.MainAction.ToEndPhase);
        }
Beispiel #3
0
        /// <summary>
        /// Called when the AI has to do something during the main phase.
        /// </summary>
        /// <param name="main">A lot of informations about the available actions.</param>
        /// <returns>A new MainPhaseAction containing the action to do.</returns>
        public MainPhaseAction OnSelectIdleCmd(MainPhase main)
        {
            Executor.SetMain(main);
            foreach (CardExecutor exec in Executor.Executors)
            {
                for (int i = 0; i < main.ActivableCards.Count; ++i)
                {
                    ClientCard card = main.ActivableCards[i];
                    if (ShouldExecute(exec, card, ExecutorType.Activate, main.ActivableDescs[i]))
                    {
                        m_dialogs.SendActivate(card.Name);
                        return(new MainPhaseAction(MainPhaseAction.MainAction.Activate, card.ActionActivateIndex[main.ActivableDescs[i]]));
                    }
                }
                foreach (ClientCard card in main.MonsterSetableCards)
                {
                    if (ShouldExecute(exec, card, ExecutorType.MonsterSet))
                    {
                        m_dialogs.SendSetMonster();
                        return(new MainPhaseAction(MainPhaseAction.MainAction.SetMonster, card.ActionIndex));
                    }
                }
                foreach (ClientCard card in main.ReposableCards)
                {
                    if (ShouldExecute(exec, card, ExecutorType.Repos))
                    {
                        return(new MainPhaseAction(MainPhaseAction.MainAction.Repos, card.ActionIndex));
                    }
                }
                foreach (ClientCard card in main.SpecialSummonableCards)
                {
                    if (ShouldExecute(exec, card, ExecutorType.SpSummon))
                    {
                        m_dialogs.SendSummon(card.Name);
                        return(new MainPhaseAction(MainPhaseAction.MainAction.SpSummon, card.ActionIndex));
                    }
                }
                foreach (ClientCard card in main.SummonableCards)
                {
                    if (ShouldExecute(exec, card, ExecutorType.Summon))
                    {
                        m_dialogs.SendSummon(card.Name);
                        return(new MainPhaseAction(MainPhaseAction.MainAction.Summon, card.ActionIndex));
                    }
                    if (ShouldExecute(exec, card, ExecutorType.SummonOrSet))
                    {
                        if (Utils.IsEnnemyBetter(true, true) && Utils.IsAllEnnemyBetterThanValue(card.Attack + 300, false) &&
                            main.MonsterSetableCards.Contains(card))
                        {
                            m_dialogs.SendSetMonster();
                            return(new MainPhaseAction(MainPhaseAction.MainAction.SetMonster, card.ActionIndex));
                        }
                        m_dialogs.SendSummon(card.Name);
                        return(new MainPhaseAction(MainPhaseAction.MainAction.Summon, card.ActionIndex));
                    }
                }
                foreach (ClientCard card in main.SpellSetableCards)
                {
                    if (ShouldExecute(exec, card, ExecutorType.SpellSet))
                    {
                        return(new MainPhaseAction(MainPhaseAction.MainAction.SetSpell, card.ActionIndex));
                    }
                }
            }

            if (main.CanBattlePhase && Duel.Fields[0].HasAttackingMonster())
            {
                return(new MainPhaseAction(MainPhaseAction.MainAction.ToBattlePhase));
            }

            m_dialogs.SendEndTurn();
            return(new MainPhaseAction(MainPhaseAction.MainAction.ToEndPhase));
        }