示例#1
0
        /// <summary>
        /// Updates the client with the changes that have been made to the UserInventory.
        /// </summary>
        public void Update()
        {
            // Don't actually grab the PacketWriter from the pool until we know we will need it
            PacketWriter pw = null;

            try
            {
                // Loop through all slots
                for (var slot = 0; slot < GameData.MaxInventorySize; slot++)
                {
                    // Skip unchanged slots
                    if (!_slotChanged[slot])
                    {
                        continue;
                    }

                    // Get the item in the slot
                    var invSlot = new InventorySlot(slot);
                    var item    = UserInventory[invSlot];

                    // Get the values to send, which depends on if the slot is empty (item == null) or not
                    GrhIndex sendItemGraphic;
                    byte     sendItemAmount;

                    if (item == null)
                    {
                        sendItemGraphic = GrhIndex.Invalid;
                        sendItemAmount  = 0;
                    }
                    else
                    {
                        sendItemGraphic = item.GraphicIndex;
                        sendItemAmount  = item.Amount;
                    }

                    // Grab the PacketWriter if we have not already, or clear it if we have
                    if (pw == null)
                    {
                        pw = ServerPacket.GetWriter();
                    }
                    else
                    {
                        pw.Reset();
                    }

                    // Pack the data and send it
                    ServerPacket.SetInventorySlot(pw, invSlot, sendItemGraphic, sendItemAmount);
                    OwnerUser.Send(pw, ServerMessageType.GUIItems);
                }
            }
            finally
            {
                // If we grabbed a PacketWriter, make sure we dispose of it!
                if (pw != null)
                {
                    pw.Dispose();
                }
            }

            // Changes complete
            _slotChanged.SetAll(false);
        }