Example #1
0
        /// <summary>
        /// Called when the AI has to do something during the battle phase.
        /// </summary>
        /// <param name="battle">Informations about usable cards.</param>
        /// <returns>A new BattlePhaseAction containing the action to do.</returns>
        public BattlePhaseAction OnSelectBattleCmd(BattlePhase battle)
        {
            Executor.SetBattle(battle);
            foreach (CardExecutor exec in Executor.Executors)
            {
                for (int i = 0; i < battle.ActivableCards.Count; ++i)
                {
                    ClientCard card = battle.ActivableCards[i];
                    if (ShouldExecute(exec, card, ExecutorType.Activate, battle.ActivableDescs[i]))
                    {
                        m_dialogs.SendChaining(card.Name);
                        return(new BattlePhaseAction(BattlePhaseAction.BattleAction.Activate, card.ActionIndex));
                    }
                }
            }

            List <ClientCard> attackers = new List <ClientCard>(battle.AttackableCards);

            attackers.Sort(AIFunctions.CompareCardAttack);

            List <ClientCard> defenders = new List <ClientCard>(Duel.Fields[1].GetMonsters());

            defenders.Sort(AIFunctions.CompareDefensePower);

            return(Executor.OnBattle(attackers, defenders));
        }
Example #2
0
        private void OnSelectBattleCmd(GameServerPacket packet)
        {
            packet.ReadByte(); // player
            m_duel.BattlePhase = new BattlePhase();
            BattlePhase battle = m_duel.BattlePhase;

            int 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)
                {
                    card.ActionIndex[0] = i;
                    battle.ActivableCards.Add(card);
                    battle.ActivableDescs.Add(desc);
                }
            }

            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();
                packet.ReadByte(); // diratt

                ClientCard card = m_duel.GetCard(con, loc, seq);
                if (card != null)
                {
                    card.ActionIndex[1] = i;
                    battle.AttackableCards.Add(m_duel.GetCard(con, loc, seq));
                }
            }

            battle.CanMainPhaseTwo = packet.ReadByte() != 0;
            battle.CanEndPhase     = packet.ReadByte() != 0;

            Connection.Send(CtosMessage.Response, m_ai.OnSelectBattleCmd(battle).ToValue());
        }
Example #3
0
        /// <summary>
        /// Called when the AI has to do something during the battle phase.
        /// </summary>
        /// <param name="battle">Informations about usable cards.</param>
        /// <returns>A new BattlePhaseAction containing the action to do.</returns>
        public BattlePhaseAction OnSelectBattleCmd(BattlePhase battle)
        {
            Executor.SetBattle(battle);
            foreach (CardExecutor exec in Executor.Executors)
            {
                for (int i = 0; i < battle.ActivableCards.Count; ++i)
                {
                    ClientCard card = battle.ActivableCards[i];
                    if (ShouldExecute(exec, card, ExecutorType.Activate, battle.ActivableDescs[i]))
                    {
                        m_dialogs.SendChaining(card.Name);
                        return new BattlePhaseAction(BattlePhaseAction.BattleAction.Activate, card.ActionIndex);
                    }
                }
            }

            List<ClientCard> attackers = new List<ClientCard>(battle.AttackableCards);
            attackers.Sort(AIFunctions.CompareCardAttack);

            List<ClientCard> defenders = new List<ClientCard>(Duel.Fields[1].GetMonsters());
            defenders.Sort(AIFunctions.CompareDefensePower);

            return Executor.OnBattle(attackers, defenders);
        }