Update() public method

public Update ( BinaryReader reader ) : void
reader System.IO.BinaryReader
return void
Exemplo n.º 1
0
        private void InitSpectatorLocation(Player player, CardLocation loc) {
            for (int index = 0; index < 2; index++) {
                int flag = loc == CardLocation.MonsterZone ? 0x91fff : 0x81fff;
                byte[] result = _duel.QueryFieldCard(index, loc, flag, false);

                MemoryStream ms = new MemoryStream(result);
                BinaryReader reader = new BinaryReader(ms);
                BinaryWriter writer = new BinaryWriter(ms);
                while (ms.Position < ms.Length) {
                    int len = reader.ReadInt32();
                    if (len == 4)
                        continue;
                    long pos = ms.Position;
                    reader.ReadBytes(len - 4);
                    long endPos = ms.Position;

                    ms.Position = pos;
                    ClientCard card = new ClientCard();
                    card.Update(reader);
                    ms.Position = endPos;

                    bool facedown = ((card.Position & (int)CardPosition.FaceDown) != 0);

                    GameServerPacket move = new GameServerPacket(GameMessage.Move);
                    move.Write(facedown ? 0 : card.Code);
                    move.Write(0);
                    move.Write((byte)card.Controler);
                    move.Write((byte)card.Location);
                    move.Write((byte)card.Sequence);
                    move.Write((byte)card.Position);
                    move.Write(0);
                    player.Send(move);

                    foreach (ClientCard material in card.Overlay) {
                        GameServerPacket xyzcreate = new GameServerPacket(GameMessage.Move);
                        xyzcreate.Write(material.Code);
                        xyzcreate.Write(0);
                        xyzcreate.Write((byte)index);
                        xyzcreate.Write((byte)CardLocation.Grave);
                        xyzcreate.Write((byte)0);
                        xyzcreate.Write((byte)0);
                        xyzcreate.Write(0);
                        player.Send(xyzcreate);

                        GameServerPacket xyzmove = new GameServerPacket(GameMessage.Move);
                        xyzmove.Write(material.Code);
                        xyzmove.Write((byte)index);
                        xyzmove.Write((byte)CardLocation.Grave);
                        xyzmove.Write((byte)0);
                        xyzmove.Write((byte)0);
                        xyzmove.Write((byte)material.Controler);
                        xyzmove.Write((byte)material.Location);
                        xyzmove.Write((byte)material.Sequence);
                        xyzmove.Write((byte)material.Position);
                        xyzmove.Write(0);
                        player.Send(xyzmove);
                    }

                    if (facedown) {
                        ms.Position = pos;
                        writer.Write(new byte[len - 4]);
                    }
                }

                if (loc == CardLocation.MonsterZone) {
                    result = _duel.QueryFieldCard(index, loc, 0x81fff, false);
                    ms = new MemoryStream(result);
                    reader = new BinaryReader(ms);
                    writer = new BinaryWriter(ms);
                    while (ms.Position < ms.Length) {
                        int len = reader.ReadInt32();
                        if (len == 4)
                            continue;
                        long pos = ms.Position;
                        byte[] raw = reader.ReadBytes(len - 4);

                        bool facedown = ((raw[11] & (int)CardPosition.FaceDown) != 0);
                        if (facedown) {
                            ms.Position = pos;
                            writer.Write(new byte[len - 4]);
                        }
                    }
                }

                GameServerPacket update = new GameServerPacket(GameMessage.UpdateData);
                update.Write((byte)index);
                update.Write((byte)loc);
                update.Write(result);
                player.Send(update);
            }
        }
Exemplo n.º 2
0
        private void InitSpectatorLocation(Player player, CardLocation loc)
        {
            for (int index = 0; index < 2; index++)
            {
                int    flag   = loc == CardLocation.MonsterZone ? 0x91fff : 0x81fff;
                byte[] result = _duel.QueryFieldCard(index, loc, flag, false);

                MemoryStream ms     = new MemoryStream(result);
                BinaryReader reader = new BinaryReader(ms);
                BinaryWriter writer = new BinaryWriter(ms);
                while (ms.Position < ms.Length)
                {
                    int len = reader.ReadInt32();
                    if (len == 4)
                    {
                        continue;
                    }
                    long pos = ms.Position;
                    reader.ReadBytes(len - 4);
                    long endPos = ms.Position;

                    ms.Position = pos;
                    ClientCard card = new ClientCard();
                    card.Update(reader);
                    ms.Position = endPos;

                    bool facedown = ((card.Position & (int)CardPosition.FaceDown) != 0);

                    GameServerPacket move = new GameServerPacket(GameMessage.Move);
                    move.Write(facedown ? 0 : card.Code);
                    move.Write(0);
                    move.Write((byte)card.Controler);
                    move.Write((byte)card.Location);
                    move.Write((byte)card.Sequence);
                    move.Write((byte)card.Position);
                    move.Write(0);
                    player.Send(move);

                    foreach (ClientCard material in card.Overlay)
                    {
                        GameServerPacket xyzcreate = new GameServerPacket(GameMessage.Move);
                        xyzcreate.Write(material.Code);
                        xyzcreate.Write(0);
                        xyzcreate.Write((byte)index);
                        xyzcreate.Write((byte)CardLocation.Grave);
                        xyzcreate.Write((byte)0);
                        xyzcreate.Write((byte)0);
                        xyzcreate.Write(0);
                        player.Send(xyzcreate);

                        GameServerPacket xyzmove = new GameServerPacket(GameMessage.Move);
                        xyzmove.Write(material.Code);
                        xyzmove.Write((byte)index);
                        xyzmove.Write((byte)CardLocation.Grave);
                        xyzmove.Write((byte)0);
                        xyzmove.Write((byte)0);
                        xyzmove.Write((byte)material.Controler);
                        xyzmove.Write((byte)material.Location);
                        xyzmove.Write((byte)material.Sequence);
                        xyzmove.Write((byte)material.Position);
                        xyzmove.Write(0);
                        player.Send(xyzmove);
                    }

                    if (facedown)
                    {
                        ms.Position = pos;
                        writer.Write(new byte[len - 4]);
                    }
                }

                if (loc == CardLocation.MonsterZone)
                {
                    result = _duel.QueryFieldCard(index, loc, 0x81fff, false);
                    ms     = new MemoryStream(result);
                    reader = new BinaryReader(ms);
                    writer = new BinaryWriter(ms);
                    while (ms.Position < ms.Length)
                    {
                        int len = reader.ReadInt32();
                        if (len == 4)
                        {
                            continue;
                        }
                        long   pos = ms.Position;
                        byte[] raw = reader.ReadBytes(len - 4);

                        bool facedown = ((raw[11] & (int)CardPosition.FaceDown) != 0);
                        if (facedown)
                        {
                            ms.Position = pos;
                            writer.Write(new byte[len - 4]);
                        }
                    }
                }

                GameServerPacket update = new GameServerPacket(GameMessage.UpdateData);
                update.Write((byte)index);
                update.Write((byte)loc);
                update.Write(result);
                player.Send(update);
            }
        }