Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Verify all conditions to pickup a dropped item.
        /// </summary>
        /// <param name="player">The player trying to pick-up the dropped item.</param>
        /// <param name="droppedItem">The dropped item.</param>
        private void PickUpDroppedItem(IPlayerEntity player, IItemEntity droppedItem)
        {
            // TODO: check if drop belongs to a party.

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

            if (droppedItem.Drop.IsGold)
            {
                int  droppedGoldAmount = droppedItem.Drop.Item.Quantity;
                long gold = player.PlayerData.Gold + droppedGoldAmount;

                if (gold > int.MaxValue || gold < 0) // Check gold overflow
                {
                    WorldPacketFactory.SendDefinedText(player, DefineText.TID_GAME_TOOMANYMONEY_USE_PERIN);
                    return;
                }
                else
                {
                    player.PlayerData.Gold = (int)gold;
                    WorldPacketFactory.SendUpdateAttributes(player, DefineAttributes.GOLD, player.PlayerData.Gold);
                    WorldPacketFactory.SendDefinedText(player, DefineText.TID_GAME_REAPMONEY, droppedGoldAmount.ToString("###,###,###,###"), gold.ToString("###,###,###,###"));
                }
            }
            else
            {
                var inventoryItemCreationEvent = new InventoryCreateItemEventArgs(droppedItem.Drop.Item.Id, droppedItem.Drop.Item.Quantity, -1, droppedItem.Drop.Item.Refine);
                player.NotifySystem <InventorySystem>(inventoryItemCreationEvent);
                WorldPacketFactory.SendDefinedText(player, DefineText.TID_GAME_REAPITEM, $"\"{droppedItem.Object.Name}\"");
            }

            WorldPacketFactory.SendMotion(player, ObjectMessageType.OBJMSG_PICKUP);
            droppedItem.Delete();
        }