/// <inheritdoc /> public void ChangeFace(IPlayerEntity player, uint objectId, uint faceId, bool useCoupon) { if (!useCoupon) { if (player.PlayerData.Gold < _worldServerConfiguration.Customization.ChangeFaceCost) { _textPacketFactory.SendDefinedText(player, DefineText.TID_GAME_LACKMONEY); } else { player.VisualAppearance.FaceId = (int)faceId; _playerDataSystem.DecreaseGold(player, (int)_worldServerConfiguration.Customization.ChangeFaceCost); _customizationPacketFactory.SendChangeFace(player, faceId); } } else { Item couponItem = player.Inventory.GetItemById(DefineItem.II_SYS_SYS_SCR_FACEOFFFREE); if (couponItem == null) { _textPacketFactory.SendDefinedText(player, DefineText.TID_GAME_WARNNING_COUPON); return; } _inventorySystem.DeleteItem(player, couponItem, 1); _customizationPacketFactory.SendChangeFace(player, faceId); } }
/// <inheritdoc /> public void SellItem(IPlayerEntity player, int playerItemUniqueId, int quantity) { Item itemToSell = player.Inventory.GetItemAtIndex(playerItemUniqueId); if (itemToSell == null) { throw new ArgumentNullException(nameof(itemToSell), $"Cannot find item with unique id: '{playerItemUniqueId}' in '{player.Object.Name}''s inventory."); } if (itemToSell.Data == null) { throw new ArgumentNullException($"Cannot find item data for item '{itemToSell.Id}'."); } if (quantity > itemToSell.Data.PackMax) { throw new InvalidOperationException($"Cannot sell more items than the pack max value. {quantity} > {itemToSell.Data.PackMax}"); } // TODO: make more checks: // is a quest item // is sealed to character // ect... int sellPrice = itemToSell.Data.Cost / 4; // TODO: make this configurable _logger.LogDebug("Selling item: '{0}' for {1}", itemToSell.Data.Name, sellPrice); int deletedQuantity = _inventorySystem.DeleteItem(player, playerItemUniqueId, quantity); if (deletedQuantity > 0) { _playerDataSystem.IncreaseGold(player, sellPrice * deletedQuantity); } }
/// <summary> /// Transfers the items between traders. /// </summary> /// <param name="player">Current player.</param> /// <param name="target">Target trader.</param> private void ProcessItemTransfer(IPlayerEntity player, IPlayerEntity target) { for (int i = 0; i < MaxTrade; i++) { Item item = player.Trade.Items.ElementAt(i); if (item == null || item.Slot == -1) { continue; } Item newItem = item.Clone(); int tradeQuantity = item.ExtraUsed; int futureQuantity = Math.Max(item.Quantity - tradeQuantity, 0); if (futureQuantity <= 0) { _inventorySystem.DeleteItem(player, item.UniqueId, item.ExtraUsed, sendToPlayer: false); } _inventorySystem.CreateItem(target, newItem, tradeQuantity, sendToPlayer: false); if (futureQuantity > 0) { item.Quantity = futureQuantity; item.ExtraUsed = 0; } } }
public void OnDeleteItem(IWorldClient client, RemoveInventoryItemPacket packet) { _inventorySystem.DeleteItem(client.Player, packet.ItemUniqueId, packet.ItemQuantity); }