コード例 #1
0
ファイル: ClientField.cs プロジェクト: duelqiuqiu/DevBot
 public ClientField()
 {
     Hand = new List<ClientCard>();
     MonsterZone = new ClientCard[5];
     SpellZone = new ClientCard[8];
     Graveyard = new List<ClientCard>();
     Banished = new List<ClientCard>();
     Deck = new List<ClientCard>();
     ExtraDeck = new List<ClientCard>();
 }
コード例 #2
0
ファイル: GameAI.cs プロジェクト: duelqiuqiu/DevBot
 public BattlePhaseAction Attack(ClientCard attacker, ClientCard defender)
 {
     if (defender != null)
     {
         string cardName = defender.Name ?? "monster";
         m_dialogs.SendAttack(attacker.Name, cardName);
         SelectCard(defender);
     }
     else
         m_dialogs.SendDirectAttack(attacker.Name);
     return new BattlePhaseAction(BattlePhaseAction.BattleAction.Attack, attacker.ActionIndex);
 }
コード例 #3
0
ファイル: GameAI.cs プロジェクト: duelqiuqiu/DevBot
 private bool ShouldExecute(CardExecutor exec, ClientCard card, ExecutorType type, int desc = -1)
 {
     Executor.SetCard(type, card, desc);
     if (card != null &&
         exec.Type == type &&
         (exec.CardId == -1 || exec.CardId == card.Id) &&
         (exec.Func == null || exec.Func()))
         return true;
     return false;
 }
コード例 #4
0
ファイル: GameAI.cs プロジェクト: duelqiuqiu/DevBot
 public void SelectNextCard(ClientCard card)
 {
     m_nextSelector = new CardSelector(card);
 }
コード例 #5
0
ファイル: GameAI.cs プロジェクト: duelqiuqiu/DevBot
 public void SelectCard(ClientCard card)
 {
     m_selector = new CardSelector(card);
 }
コード例 #6
0
ファイル: GameAI.cs プロジェクト: duelqiuqiu/DevBot
 /// <summary>
 /// Called when the AI has to choose to activate or not an effect.
 /// </summary>
 /// <param name="card">Card to activate.</param>
 /// <returns>True for yes, false for no.</returns>
 public bool OnSelectEffectYn(ClientCard card)
 {
     foreach (CardExecutor exec in Executor.Executors)
     {
         if (ShouldExecute(exec, card, ExecutorType.Activate))
             return true;
     }
     return false;
 }
コード例 #7
0
ファイル: GameAI.cs プロジェクト: duelqiuqiu/DevBot
 /// <summary>
 /// Called when a chain is executed.
 /// </summary>
 /// <param name="card">Card who is chained.</param>
 /// <param name="player">Player who is currently chaining.</param>
 public void OnChaining(ClientCard card, int player)
 {
     Executor.OnChaining(player,card);
 }
コード例 #8
0
ファイル: ClientCard.cs プロジェクト: duelqiuqiu/DevBot
 public bool Equals(ClientCard card)
 {
     return ReferenceEquals(this, card);
 }
コード例 #9
0
ファイル: Duel.cs プロジェクト: duelqiuqiu/DevBot
 public void RemoveCard(CardLocation loc, ClientCard card, int player, int zone)
 {
     switch (loc)
     {
         case CardLocation.Hand:
             Fields[player].Hand.Remove(card);
             break;
         case CardLocation.Grave:
             Fields[player].Graveyard.Remove(card);
             break;
         case CardLocation.Removed:
             Fields[player].Banished.Remove(card);
             break;
         case CardLocation.MonsterZone:
             Fields[player].MonsterZone[zone] = null;
             break;
         case CardLocation.SpellZone:
             Fields[player].SpellZone[zone] = null;
             break;
         case CardLocation.Deck:
             Fields[player].Deck.Remove(card);
             break;
         case CardLocation.Extra:
             Fields[player].ExtraDeck.Remove(card);
             break;
     }
 }
コード例 #10
0
        private void InternalOnSelectCard(GameServerPacket packet, Func <IList <ClientCard>, int, int, bool, IList <ClientCard> > func)
        {
            packet.ReadByte(); // player
            bool cancelable = packet.ReadByte() != 0;
            int  min        = packet.ReadByte();
            int  max        = packet.ReadByte();

            IList <ClientCard> cards = new List <ClientCard>();
            int count = packet.ReadByte();

            for (int i = 0; i < count; ++i)
            {
                int          id     = packet.ReadInt32();
                int          player = GetLocalPlayer(packet.ReadByte());
                CardLocation loc    = (CardLocation)packet.ReadByte();
                int          seq    = packet.ReadByte();
                packet.ReadByte(); // pos
                ClientCard card = m_duel.GetCard(player, loc, seq);
                if (card == null)
                {
                    continue;
                }
                if (card.Id == 0)
                {
                    card.SetId(id);
                }
                cards.Add(card);
            }

            IList <ClientCard> selected = func(cards, min, max, cancelable);

            if (selected.Count == 0 && cancelable)
            {
                Connection.Send(CtosMessage.Response, -1);
                return;
            }

            byte[] result = new byte[selected.Count + 1];
            result[0] = (byte)selected.Count;
            for (int i = 0; i < selected.Count; ++i)
            {
                int id = 0;
                for (int j = 0; j < count; ++j)
                {
                    if (cards[j] == null)
                    {
                        continue;
                    }
                    if (cards[j].Equals(selected[i]))
                    {
                        id = j;
                        break;
                    }
                }
                result[i + 1] = (byte)id;
            }

            GameClientPacket reply = new GameClientPacket(CtosMessage.Response);

            reply.Write(result);
            Connection.Send(reply);
        }
コード例 #11
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());
        }
コード例 #12
0
 public bool Equals(ClientCard card)
 {
     return(ReferenceEquals(this, card));
 }
コード例 #13
0
ファイル: GameAI.cs プロジェクト: duelqiuqiu/DevBot
 /// <summary>
 /// Called when a chain is executed.
 /// </summary>
 /// <param name="card">Card who is chained.</param>
 /// <param name="player">Player who is currently chaining.</param>
 public void OnChaining(ClientCard card, int player)
 {
     Executor.OnChaining(player, card);
 }
コード例 #14
0
ファイル: GameAI.cs プロジェクト: duelqiuqiu/DevBot
 public void SelectNextCard(ClientCard card)
 {
     m_nextSelector = new CardSelector(card);
 }
コード例 #15
0
ファイル: GameAI.cs プロジェクト: duelqiuqiu/DevBot
 public void SelectCard(ClientCard card)
 {
     m_selector = new CardSelector(card);
 }
コード例 #16
0
ファイル: GameAI.cs プロジェクト: duelqiuqiu/DevBot
        /// <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));
        }