/// <summary> /// Sells an item to a NPC shop. /// </summary> /// <param name="player">Player entity</param> /// <param name="e"></param> private void SellItem(IPlayerEntity player, NpcShopSellEventArgs e) { Item itemToSell = player.Inventory.GetItem(e.ItemUniqueId); if (itemToSell?.Data == null) { throw new InvalidOperationException($"ShopSystem: Cannot find item with unique id: {e.ItemUniqueId}"); } if (e.Quantity > itemToSell.Data.PackMax) { throw new InvalidOperationException($"ShopSystem: Cannot sell more items than the pack max value. {e.Quantity} > {itemToSell.Data.PackMax}"); } // TODO: make more checks: // is a quest item // is sealed to character // ect... int sellPrice = itemToSell.Data.Cost / 4; Logger.Debug("Selling item: '{0}' for {1}", itemToSell.Data.Name, sellPrice); player.PlayerData.Gold += sellPrice * e.Quantity; itemToSell.Quantity -= e.Quantity; WorldPacketFactory.SendItemUpdate(player, UpdateItemType.UI_NUM, itemToSell.UniqueId, itemToSell.Quantity); WorldPacketFactory.SendUpdateAttributes(player, DefineAttributes.GOLD, player.PlayerData.Gold); if (itemToSell.Quantity <= 0) { itemToSell.Reset(); } }
public static void OnSellItem(WorldClient client, INetPacketStream packet) { var sellItemPacket = new SellItemPacket(packet); var npcShopEvent = new NpcShopSellEventArgs(sellItemPacket.ItemUniqueId, sellItemPacket.Quantity); client.Player.NotifySystem <NpcShopSystem>(npcShopEvent); }