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

            int          cardId = packet.ReadInt32();
            int          player = GetLocalPlayer(packet.ReadByte());
            CardLocation loc    = (CardLocation)packet.ReadByte();
            int          seq    = packet.ReadByte();

            packet.ReadByte();

            ClientCard card = m_duel.GetCard(player, loc, seq);

            if (card == null)
            {
                Connection.Send(CtosMessage.Response, 0);
                return;
            }

            if (card.Id == 0)
            {
                card.SetId(cardId);
            }

            int reply = m_ai.OnSelectEffectYn(card) ? (1) : (0);

            Connection.Send(CtosMessage.Response, reply);
        }
Beispiel #2
0
        private void OnSelectSum(GameServerPacket packet)
        {
            packet.ReadByte(); // mode
            packet.ReadByte(); // player
            int sumval = packet.ReadInt32();
            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          cardId = packet.ReadInt32();
                int          player = GetLocalPlayer(packet.ReadByte());
                CardLocation loc    = (CardLocation)packet.ReadByte();
                int          seq    = packet.ReadByte();
                ClientCard   card   = m_duel.GetCard(player, loc, seq);
                if (card != null)
                {
                    if (cardId != 0 && card.Id != cardId)
                    {
                        card.SetId(cardId);
                    }
                    cards.Add(card);
                }
                packet.ReadInt32();
            }

            IList <ClientCard> selected = m_ai.OnSelectSum(cards, sumval, min, max);

            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);
        }
Beispiel #3
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);
        }