public override void Handle(EzClient client, EzPacket packet) { bool shoppingCart = packet.Data.ReadByte() > 0 ? true : false; List <Item> items = ReadShoppingCart(packet); _logger.Debug("ShoppingCart: {0}", shoppingCart); if (!HasMoney(items, client.Character)) { _logger.Debug("Not enough coins, cancel purchase"); return; } if (!HasSpace(items, client.Inventory)) { _logger.Debug("Not enough space, cancel purchase"); return; } foreach (Item item in items) { InventoryItem inventoryItem = new InventoryItem(); inventoryItem.AccountId = client.Account.Id; inventoryItem.PurchaseDate = DateTime.Now; inventoryItem.Equipped = -1; inventoryItem.Item = item; inventoryItem.Slot = -1; inventoryItem.Id = -1; if (!client.Inventory.AddItem(inventoryItem)) { _logger.Error("Couldn't add item to inventory {0}", item.Name); continue; } if (!Database.InsertInventoryItem(inventoryItem)) { _logger.Error("Couldn't save item to database {0}", item.Name); continue; } _logger.Debug("Purchased Id: {0} Name: {1}", item.Id, item.Name); IBuffer purchasePacket = ShopPacket.CreatePurchasePacket(item); Send(client, 0x1D, purchasePacket); } }