public void AddItemToPlayer(Player player, InventoryItem item)
        {
            int maxInStack = item.ItemTemplate.MaxStack;
            lock (player.Inventory.ItemsLock)
            {
                List<int> freeSlots = GetFreeSlots(player);

                if (item.ItemId == 20000000)
                {
                    player.Inventory.Money += item.Count;
                    new SpInventory(player).Send(player.Connection);
                    return;
                }

                if (freeSlots.Count <= 0 && CanDress(player, item)) //TODO isStackable
                {
                    SystemMessages.InventoryIsFull.Send(player.Connection);
                    return;
                }

                if (item.ItemTemplate.MaxStack > 1) // TODO isStackable
                {
                    for (int i = 20; i < player.Inventory.Size + 20; i++)
                    {
                        if (!player.Inventory.Items.ContainsKey(i))
                            continue;

                        if (player.Inventory.Items[i].ItemId == item.ItemId)
                        {
                            if (player.Inventory.Items[i].Count + item.Count <= maxInStack)
                            {
                                player.Inventory.Items[i].Count += item.Count;
                                new SpInventory(player).Send(player.Connection);
                                return;
                            }
                            item.Count -= (maxInStack - player.Inventory.Items[i].Count);
                            player.Inventory.Items[i].Count = maxInStack;
                        }
                    }

                    if (freeSlots.Count > 0)
                        player.Inventory.Items.Add(freeSlots[0], item);

                    new SpInventory(player).Send(player.Connection);
                    return;
                }

                player.Inventory.Items.Add(freeSlots[0], item);
                new SpInventory(player).Send(player.Connection);
            }
        }
        private bool CanDress(Player player, InventoryItem item, bool sendErrors = false)
        {
            if (GetDressSlot(item.ItemId) > 20)
                return false;

            if (item.ItemTemplate.RequiredClassesList.Count > 0
                && !item.ItemTemplate.RequiredClassesList.Contains(player.PlayerData.Class))
            {
                if (sendErrors)
                    SystemMessages.ThatItemIsUnavailableToYourClass.Send(player.Connection);
                return false;
            }

            if (item.ItemTemplate.RequiredLevel > player.GetLevel())
            {
                if (sendErrors)
                    SystemMessages.YouMustBeAHigherLevelToUseThat.Send(player.Connection);
                return false;
            }

            return true;
        }