public void LoadBank(GameSession session) { session.Send(StorageInventoryPacket.Update()); session.Send(StorageInventoryPacket.Expand(ExtraSize)); session.Send(StorageInventoryPacket.ExpandAnim()); session.Send(StorageInventoryPacket.UpdateMesos(Mesos.Amount)); LoadItems(session); }
public void Sort(GameSession session) { IEnumerable <Item> items = Items.Where(x => x is not null); // group items by item id and sum the amount, return a new list of items with updated amount (ty gh copilot) List <Item> groupedItems = items.Where(x => x.StackLimit > 1).GroupBy(x => x.Id).Select(x => new Item(x.First()) { Amount = x.Sum(y => y.Amount), BankInventoryId = Id }).ToList(); // Add items that can't be grouped groupedItems.AddRange(items.Where(x => x.StackLimit == 1)); // sort items by id groupedItems.Sort((x, y) => x.Id.CompareTo(y.Id)); // Delete items that got grouped foreach (Item oldItem in items) { Item newItem = groupedItems.FirstOrDefault(x => x.Uid == oldItem.Uid); if (newItem is null) { DatabaseManager.Items.Delete(oldItem.Uid); } } Items = new Item[DEFAULT_SIZE + ExtraSize]; for (short i = 0; i < groupedItems.Count; i++) { Item item = groupedItems[i]; item.Slot = i; Items[i] = item; DatabaseManager.Items.Update(item); } session.Send(StorageInventoryPacket.Update()); session.Send(StorageInventoryPacket.Sort(Items)); session.Send(StorageInventoryPacket.ExpandAnim()); }
private static void HandleSort(GameSession session) { session.Send(StorageInventoryPacket.Update()); session.Player.Account.BankInventory.Sort(session); }