/// <summary> /// Initialize an inventory dict with all slots empty. /// </summary> /// <param name="inventory"></param> /// <param name="numSlots"></param> private void AddEmptySlots(ref Dictionary <ushort, object> inventory, InventoryMaxSlots numSlots) { for (int i = 0; i < (int)numSlots; i++) { inventory.Add((ushort)i, null); } }
private void ChunkStart(Socket sender, InventoryMaxSlots maxSize, InventoryType type) { byte[] data = new byte[0x08]; Buffer.BlockCopy(BitConverter.GetBytes(User.Instance.Character.Id), 0, data, 0, sizeof(uint)); Buffer.BlockCopy(BitConverter.GetBytes((ushort)maxSize), 0, data, 0x04, sizeof(ushort)); Buffer.BlockCopy(BitConverter.GetBytes((ushort)type), 0, data, 0x06, sizeof(ushort)); SendPacket(sender, ServerOpcode.ChunkStart, data); }
/// <summary> /// Send packets containing all items in the specified inventory. /// </summary> /// <param name="sender"></param> /// <param name="inventory"></param> private void SendInventory(Socket sender, Dictionary <ushort, object> inventory, InventoryMaxSlots maxSlots, InventoryType invType) { ChunkStart(sender, maxSlots, invType); //get the number if items in the inventory List <Item> items = new List <Item>(); foreach (var slot in inventory) { if (slot.Value != null) { items.Add((Item)slot.Value); } } int itemCount = items.Count; if (itemCount > 0) { int index = 0; while (itemCount > 0) { if (itemCount >= 64) { itemCount = SendItemsChunk(sender, ServerOpcode.x64InventoryChunk, 64, itemCount, ref index, ref items); } else if (itemCount >= 32) { itemCount = SendItemsChunk(sender, ServerOpcode.x32InventoryChunk, 32, itemCount, ref index, ref items); } else if (itemCount >= 16) { itemCount = SendItemsChunk(sender, ServerOpcode.x16InventoryChunk, 16, itemCount, ref index, ref items); } else if (itemCount >= 08 || itemCount < 08) { itemCount = SendItemsChunk(sender, ServerOpcode.x08InventoryChunk, 08, itemCount, ref index, ref items); } } } ChunkEnd(sender); }