Ejemplo n.º 1
0
    public static void CtosMessage_UpdateDeck(YGOSharp.Deck deckFor)
    {
        deckStrings.Clear();
        deck = deckFor;
        Package message = new Package();

        message.Fuction = (int)CtosMessage.UpdateDeck;
        message.Data.writer.Write((int)deckFor.Main.Count + deckFor.Extra.Count);
        message.Data.writer.Write((int)deckFor.Side.Count);
        for (int i = 0; i < deckFor.Main.Count; i++)
        {
            message.Data.writer.Write((int)deckFor.Main[i]);
            var c = YGOSharp.CardsManager.Get((int)deckFor.Main[i]);
            deckStrings.Add(c.Name);
        }
        for (int i = 0; i < deckFor.Extra.Count; i++)
        {
            message.Data.writer.Write((int)deckFor.Extra[i]);
        }
        for (int i = 0; i < deckFor.Side.Count; i++)
        {
            message.Data.writer.Write((int)deckFor.Side[i]);
        }
        Send(message);
    }
Ejemplo n.º 2
0
        public bool Check(Deck deck)
        {
            if (deck.Main.Count != Main.Count || deck.Extra.Count != Extra.Count)
                return false;

            IDictionary<int, int> cards = new Dictionary<int, int>();
            IDictionary<int, int> ncards = new Dictionary<int, int>();
            IList<int>[] stacks = { Main, Extra, Side };
            foreach (IList<int> stack in stacks)
            {
                foreach (int id in stack)
                {
                    if (!cards.ContainsKey(id))
                        cards.Add(id, 1);
                    else
                        cards[id]++;
                }
            }
            stacks = new[] { deck.Main, deck.Extra, deck.Side };
            foreach (var stack in stacks)
            {
                foreach (int id in stack)
                {
                    if (!ncards.ContainsKey(id))
                        ncards.Add(id, 1);
                    else
                        ncards[id]++;
                }
            }
            foreach (var pair in cards)
            {
                if (!ncards.ContainsKey(pair.Key))
                    return false;
                if (ncards[pair.Key] != pair.Value)
                    return false;
            }
            return true;
        }
Ejemplo n.º 3
0
        private void OnUpdateDeck(GamePacketReader packet)
        {
            if (Type == (int)PlayerType.Observer)
                return;
            Deck deck = new Deck();
            int main = packet.ReadInt32();
            int side = packet.ReadInt32();

            for (int i = 0; i < main; i++)
                deck.AddMain(packet.ReadInt32());
            for (int i = 0; i < side; i++)
                deck.AddSide(packet.ReadInt32());
            if (Game.State == GameState.Lobby)
            {
                Deck = deck;
                Game.IsReady[Type] = false;
            }
            else if (Game.State == GameState.Side)
            {
                if (Game.IsReady[Type])
                    return;
                if (!Deck.Check(deck))
                {
                    GamePacketWriter error = new GamePacketWriter(StocMessage.ErrorMsg);
                    error.Write((byte)3);
                    error.Write(0);
                    Send(error);
                    return;
                }
                Deck = deck;
                Game.IsReady[Type] = true;
                Send(new GamePacketWriter(StocMessage.DuelStart));
                Game.MatchSide();
            }
        }