private void ReadBagMeta() { //bagType * 1000000 + bagNum * 100000 + freeSlots * 1000 + self:bagSlots(bagNum) int data = reader.GetIntAtCell(cBagMeta); int bagType = (int)(data / 1000000f); data -= 1000000 * bagType; int index = (int)(data / 100000f); data -= 100000 * index; int freeSlots = (int)(data / 1000f); data -= 1000 * freeSlots; int slotCount = data; if (index >= 0 && index < bags.Length) { // default bag, the first has no equipment slot if (index != 0) { bags[index].ItemId = equipmentReader.GetId((int)InventorySlotId.Bag_0 + index - 1); } bags[index].BagType = (BagType)bagType; bags[index].SlotCount = slotCount; bags[index].FreeSlot = freeSlots; } }
public void Read() { bool hasChanged = false; // not includes the first(default) bag for (var bagSlotIndex = 0; bagSlotIndex < 4; bagSlotIndex++) { bagSlotsCount[bagSlotIndex + 1] = reader.GetLongAtCell(bagSlotCountStart + bagSlotIndex); var bagItemId = equipmentReader.GetId((int)InventorySlotId.Bag_0 + bagSlotIndex); bagForLoot[bagSlotIndex + 1] = IsContainerItem(bagItemId); } for (var bag = 0; bag < 5; bag++) { var cellIndex = bagItemsDataStart + (bag * 2); var itemCount = reader.Get5Numbers(cellIndex, SquareReader.Part.Left); var bagInfoIndex = bagInfoDataStart + bag; var isSoulbound = reader.GetLongAtCell(bagInfoIndex) == 1; // get bag and slot var val = reader.GetLongAtCell(cellIndex + 1); var bagNumber = val / 20; var slot = (int)(val - bagNumber * 20); var existingItem = BagItems.Where(b => b.BagIndex == slot).Where(b => b.Bag == bag).FirstOrDefault(); if (itemCount > 0) { var itemId = reader.Get5Numbers(cellIndex, SquareReader.Part.Right); bool addItem = true; if (existingItem != null) { if (existingItem.ItemId != itemId) { BagItems.Remove(existingItem); addItem = true; } else { addItem = false; if (existingItem.Count != itemCount) { existingItem.UpdateCount(itemCount); hasChanged = true; } } } if (addItem) { var item = new Item { Name = "Unknown" }; if (itemDb.Items.ContainsKey(itemId)) { item = itemDb.Items[itemId]; } BagItems.Add(new BagItem(bag, slot, itemId, itemCount, item, isSoulbound)); hasChanged = true; } } else { if (existingItem != null) { BagItems.Remove(existingItem); hasChanged = true; } } } if (hasChanged || (DateTime.Now - this.lastEvent).TotalSeconds > 11) { DataChanged?.Invoke(this, new EventArgs()); lastEvent = DateTime.Now; } }