Example #1
0
        public bool PlaceItemToOtherStorage(Player player, Player second, Storage from, int fromSlot, Storage to, int toSlot, int count)
        {
            if (to.IsFull())
                return false;

            if (count < 0)
                return false;

            if (!(player.Controller is DefaultController) || !(second.Controller is DefaultController))
                return false;

            if(player == second)
            {
                StorageItem item = null;

                if(to.StorageType == StorageType.CharacterWarehouse)
                {
                    if(toSlot == -1)
                        toSlot = to.GetFreeSlot(player.CurrentBankSection * 72);

                    if(toSlot == 0 && to.Items.ContainsKey(toSlot))
                        toSlot = to.GetFreeSlot(player.CurrentBankSection * 72);

                    if (toSlot == to.LastIdRanged(player.CurrentBankSection * 72, (player.CurrentBankSection + 1) * 72 - 1))
                        toSlot = to.GetFreeSlot(player.CurrentBankSection * 72);
                }
                else
                    if ((toSlot == 0 && to.Items.ContainsKey(toSlot)) || toSlot == -1)
                        toSlot = to.GetFreeSlot();

                if (to.Items.ContainsKey(toSlot))
                {
                    if (!PlaceItemToOtherStorage(player, player, to, toSlot, player.Inventory, player.Inventory.GetFreeSlot(), to.Items[toSlot].Amount))
                        return false;
                }

                lock (from.ItemsLock)
                {
                    if(from.Items.ContainsKey(fromSlot))
                    {
                        item = from.Items[fromSlot];

                        if(item.Amount < count)
                            return false;

                        if (item.Amount == count)
                            from.Items.Remove(fromSlot);
                        else
                        {
                            from.Items[fromSlot].Amount -= count;
                            item = new StorageItem { ItemId = item.ItemId, Amount = count };
                        }
                    }
                }

                if (item == null)
                    return false;

                if (!AddItem(player, to, item.ItemId, count, toSlot))
                    AddItem(player, from, item.ItemId, count, fromSlot);
            }
            return false;
        }