Read() публичный Метод

Reads the bit contained in the current stream to a Boolean value.
The Read method returns zero if the end of the current stream is reached. In all other cases, Read always reads at least one bit from the current stream before returning.
public Read ( bool &bit ) : int
bit bool /// When this method returns, contains the specified /// value with the bit between bitIndex and (bitIndex + count - 1) /// replaced by the bit read from the current stream. ///
Результат int
Пример #1
0
    public override void UnpackCommand(BKSystem.IO.BitStream packet)
    {
        int textLength;

        packet.Read(out textLength, 0, 8);
        char[] text = new char[textLength];
        packet.Read(text, 0, textLength);
        m_text = new string(text);
    }
Пример #2
0
    public override void UnpackCommand(BKSystem.IO.BitStream packet)
    {
        m_castableCards = new List <CastableCard>();

        int numCards;

        packet.Read(out numCards, 0, 16);
        for (int i = 0; i < numCards; i++)
        {
            CastableCard card;
            packet.Read(out card);
            m_castableCards.Add(card);
        }
    }
Пример #3
0
    public override void UnpackCommand(BKSystem.IO.BitStream packet)
    {
        int dataCount;

        packet.Read(out dataCount, 0, 16);
        for (int i = 0; i < dataCount; i++)
        {
            SpellChannelData data = new SpellChannelData();
            packet.Read(out data.cardID, 0, 16);
            packet.Read(out data.playerID, 0, 8);
            packet.Read(out data.newChannel, 0, 5);
            m_data.Add(data);
        }
    }
Пример #4
0
    public override void UnpackCommand(BKSystem.IO.BitStream packet)
    {
        m_playableCards = new List <int>();
        int numCards;

        packet.Read(out m_playerID, 0, 8);
        packet.Read(out numCards, 0, 16);

        for (int i = 0; i < numCards; i++)
        {
            int cardID;
            packet.Read(out cardID, 0, 16);
            m_playableCards.Add(cardID);
        }
    }
Пример #5
0
    public override void UnpackCommand(BKSystem.IO.BitStream packet)
    {
        packet.Read(out m_cardID, 0, 16);

        bool hasTarget;

        packet.Read(out hasTarget);

        if (hasTarget)
        {
            packet.Read(out m_targetID, 0, 16);
        }
        else
        {
            m_targetID = -1;
        }
    }
Пример #6
0
    public static SGCommand CreateCommandFromPacket(BKSystem.IO.BitStream packet, int playerID)
    {
        if (packet.Length < 0)
        {
            return(null);
        }

        ushort commandID;

        packet.Position = 0;
        packet.Read(out commandID, 0, 16);
        Debug.Log("Read packet with server command ID: " + commandID);

        SGCommand command;

        switch (commandID)
        {
        case 1:
            command = new SGC_CastSpellFromChannel0(packet, playerID);
            break;

        case 2:
            command = new SGC_PlayCardFromHand(packet, playerID);
            break;

        case 3:
            command = new SGC_SendDeck(packet, playerID);
            break;

        case 4:
            command = new SGC_RefreshTimeout(packet, playerID);
            break;

        default:
            command = null;
            break;
        }

        command.m_ID = (SGCommandID)commandID;

        return(command);
    }
Пример #7
0
 public override void UnpackCommand(BKSystem.IO.BitStream packet)
 {
     packet.Read(out m_life, 0, 16);
     packet.Read(out m_playerID, 0, 8);
 }
Пример #8
0
 public override void UnpackCommand(BKSystem.IO.BitStream packet)
 {
     packet.Read(out m_cardData);
     packet.Read(out m_cardID, 0, 16);
     Debug.Log("Drawing card " + m_cardData.cardName + " with ID " + m_cardID);
 }
Пример #9
0
 public override void UnpackCommand(BKSystem.IO.BitStream packet)
 {
     packet.Read(out m_cardData);
     packet.Read(out m_cardID, 0, 16);
     packet.Read(out m_channel, 0, 5);
 }
Пример #10
0
        private byte[] Compress(BitStream rawStream)
        {
            rawStream.Position = 0;
            var raw = new byte[rawStream.Length8];
            for (int i = 0; i < rawStream.Length8; i++)
            {
                rawStream.Read(out raw[i]);
            }
            var byteLength = (int) rawStream.Length8;
            if (byteLength == 0)
            {
                return null;
            }

            using (var memory = new MemoryStream())
            {
                using (var gzip = new GZipStream(memory, CompressionMode.Compress, true))
                {
                    gzip.Write(raw, 0, raw.Length);
                }
                return memory.ToArray();
            }
        }
Пример #11
0
    public static CGCommand CreateCommandFromPacket(BKSystem.IO.BitStream packet)
    {
        if (packet.Length < 0)
        {
            return(null);
        }

        ushort commandID;

        packet.Position = 0;
        packet.Read(out commandID, 0, 16);
        Debug.Log("Read packet with command ID: " + commandID);

        CGCommand command;

        switch (commandID)
        {
        case (ushort)CGCommandID.CAST_SPELL:
            command = new CGC_CastSpell(packet);
            break;

        case (ushort)CGCommandID.CHANNEL_SPELL:
            command = new CGC_ChannelSpell(packet);
            break;

        case (ushort)CGCommandID.MOVE_CARD_TO_GRAVEYARD:
            command = new CGC_MoveCardToGraveyard(packet);
            break;

        case (ushort)CGCommandID.OPPONENT_DRAW_CARD:
            command = new CGC_OpponentDrawCard(packet);
            break;

        case (ushort)CGCommandID.OPPONENT_PLAY_CARD_FROM_HAND:
            command = new CGC_OpponentPlayCardFromHand(packet);
            break;

        case (ushort)CGCommandID.PLAYER_DRAW_CARD:
            command = new CGC_PlayerDrawCard(packet);
            break;

        case (ushort)CGCommandID.PLAYER_PLAY_CARD_FROM_HAND:
            command = new CGC_PlayerPlayCardFromHand(packet);
            break;

        case (ushort)CGCommandID.SET_LIFE:
            command = new CGC_SetLife(packet);
            break;

        case (ushort)CGCommandID.WAIT_FOR_CAST_SELECTION:
            command = new CGC_WaitForCastSelection(packet);
            break;

        case (ushort)CGCommandID.WAIT_FOR_PLAY_FROM_HAND:
            command = new CGC_WaitForPlayFromHand(packet);
            break;

        case (ushort)CGCommandID.SET_PLAYER_ID:
            command = new CGC_SetPlayerID(packet);
            break;

        case (ushort)CGCommandID.PHASE_TRANSITION:
            command = new CGC_PhaseTransition(packet);
            break;

        case (ushort)CGCommandID.REQUEST_DECK:
            command = new CGC_RequestDeck(packet);
            break;

        case (ushort)CGCommandID.REFRESH_TIMEOUT:
            command = new CGC_RefreshTimeout(packet);
            break;

        default:
            command = null;
            break;
        }

        return(command);
    }
Пример #12
0
 private byte Get8bitsAsUInt(BitStream bs)
 {
     byte result;
     bs.Read(out result, 0, 8);
     return result;
 }
Пример #13
0
 private int Get6bitsAsInt(BitStream bs)
 {
     int result;
     bs.Read(out result, 0, 6);
     return result;
 }
Пример #14
0
 private int Get1bitAsInt(BitStream bs)
 {
     int result;
     bs.Read(out result, 0, 1);
     return result;
 }
Пример #15
0
 private uint Get16bitsAsUInt(BitStream bs)
 {
     uint result;
     bs.Read(out result, 0, 16);
     return result;
 }
Пример #16
0
        public void HandleAtmosDisplayUpdate(NetIncomingMessage message)
        {
            if (!_loaded)
                return;
            //Length of records in bits
            int lengthBits = message.ReadInt32();
            int lengthBytes = message.ReadInt32();
            var records = new byte[lengthBytes];
            message.ReadBytes(records, 0, lengthBytes);
            byte[] decompressed = Decompress(records);
            var recordStream = new BitStream(lengthBits);
            int bitsWritten = 0;
            for (int i = 0; i < decompressed.Length; i++)
            {
                int toWrite = 8;
                if (toWrite > lengthBits - bitsWritten)
                    toWrite = lengthBits - bitsWritten;
                recordStream.Write(decompressed[i], 0, toWrite);
                bitsWritten += toWrite;
            }

            int typesCount = Enum.GetValues(typeof (GasType)).Length;
            recordStream.Position = 0;
            int types = 0;
            byte amount = 0;
            for (int x = 0; x < _mapWidth; x++)
            {
                for (int y = 0; y < _mapHeight; y++)
                {
                    recordStream.Read(out types, 0, typesCount);

                    for (int i = typesCount - 1; i >= 0; i--)
                    {
                        if ((types & (1 << i)) == (1 << i))
                        {
                            recordStream.Read(out amount, 0, 4);
                            Tile t = (Tile)GetFloorAt(new Vector2D(x * TileSpacing, y * TileSpacing));
                            if (t == null)
                                continue;
                            t.SetAtmosDisplay((GasType) i, amount);
                        }
                    }
                }
            }

            var gameScreen = IoCManager.Resolve<IStateManager>().CurrentState as GameScreen;
            gameScreen.RecalculateScene();
        }
Пример #17
0
 public override void UnpackCommand(BKSystem.IO.BitStream packet)
 {
     packet.Read(out m_cardID, 0, 16);   // The first 16 bytes contain the card ID
     packet.Read(out m_casterID, 0, 8);  // The next 8 bytes contain the caster ID
 }
Пример #18
0
 public override void UnpackCommand(BKSystem.IO.BitStream packet)
 {
     packet.Read(out m_deck);
 }