Пример #1
0
        /// <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);
            }
        }
Пример #2
0
        /// <summary>
        /// Cancels the trade and refund the player.
        /// </summary>
        /// <param name="player">Current player.</param>
        /// <param name="mode">Cancel mode.</param>
        private void CancelTradeAndRefund(IPlayerEntity player, int mode = 0)
        {
            _playerDataSystem.IncreaseGold(player, player.Trade.Gold);
            player.Trade.Reset();

            _tradePacketFactory.SendTradeCancel(player, mode);
        }
Пример #3
0
        /// <summary>
        /// Verify all conditions to pickup a dropped item.
        /// </summary>
        /// <param name="droppedItem">The dropped item.</param>
        private void PickUpDroppedItem(IItemEntity droppedItem)
        {
            // TODO: check if drop belongs to a party.

            if (droppedItem.Drop.HasOwner && droppedItem.Drop.Owner != _player)
            {
                _textPacketFactory.SendDefinedText(_player, DefineText.TID_GAME_PRIORITYITEMPER, $"\"{droppedItem.Object.Name}\"");
                return;
            }

            if (droppedItem.Drop.IsGold)
            {
                int droppedGoldAmount = droppedItem.Drop.Item.Quantity;

                if (_playerDataSystem.IncreaseGold(_player, droppedGoldAmount))
                {
                    _textPacketFactory.SendDefinedText(_player, DefineText.TID_GAME_REAPMONEY, droppedGoldAmount.ToString("###,###,###,###"), _player.PlayerData.Gold.ToString("###,###,###,###"));
                }
            }
            else
            {
                _inventorySystem.CreateItem(_player, droppedItem.Drop.Item, droppedItem.Drop.Item.Quantity);
                _textPacketFactory.SendDefinedText(_player, DefineText.TID_GAME_REAPITEM, $"\"{droppedItem.Object.Name}\"");
            }

            _moverPacketFactory.SendMotion(_player, ObjectMessageType.OBJMSG_PICKUP);
            droppedItem.Delete();
        }
Пример #4
0
        public void UsePerin(IPlayerEntity player, Item perinItem)
        {
            int perinValue = _worldServerConfiguration.Perin.PerinValue;

            if (!_playerDataSystem.IncreaseGold(player, perinValue))
            {
                _logger.LogTrace($"Failed to generate gold from a perin for player '{player.Object.Name}'.");
            }
            else
            {
                DecreaseItem(player, perinItem);
                _logger.LogTrace($"Player '{player.Object.Name}' created {perinValue} gold.");
            }
        }
Пример #5
0
        /// <inheritdoc />
        public void Execute(IPlayerEntity player, object[] parameters)
        {
            if (parameters.Length == 1)
            {
                int gold = Convert.ToInt32(parameters[0]);

                if (!_playerDataSystem.IncreaseGold(player, gold))
                {
                    _logger.LogTrace($"Failed to create {gold} for player '{player.Object.Name}'.");
                }
                else
                {
                    _logger.LogTrace($"Player '{player.Object.Name}' created {gold} gold.");
                }
            }
        }