示例#1
0
    private void Drop(ItemSlot dropItemSlot)
    {
        if (dragItemSlot == null)
        {
            return;
        }

        if (dropItemSlot.CanAddStacks(dragItemSlot.ItemGS))
        {
            int numAddableStacks = dropItemSlot.ItemGS.maxStack - dropItemSlot.Amount;
            int stacksToAdd      = Mathf.Min(numAddableStacks, dragItemSlot.Amount);

            dropItemSlot.Amount += stacksToAdd;
            dragItemSlot.Amount -= stacksToAdd;
        }

        else if (dropItemSlot.CanRecieveItem(dragItemSlot.ItemGS) && dragItemSlot.CanRecieveItem(dropItemSlot.ItemGS))
        {
            EquipableItem dragItem = dragItemSlot.ItemGS as EquipableItem;
            EquipableItem dropItem = dropItemSlot.ItemGS as EquipableItem;

            if (dragItemSlot is EquipmentSlot)
            {
                if (dragItem != null)
                {
                    dragItem.Unequip(this);
                }
                if (dropItem != null)
                {
                    dropItem.Equip(this);
                }
            }
            if (dropItemSlot is EquipmentSlot)
            {
                if (dragItem != null)
                {
                    dragItem.Equip(this);
                }
                if (dropItem != null)
                {
                    dropItem.Unequip(this);
                }
            }
            statPanel.UpdateStatValues();

            Items draggedItem       = dragItemSlot.ItemGS;
            int   draggedItemAmount = dragItemSlot.Amount;

            dragItemSlot.ItemGS = dropItemSlot.ItemGS;
            dragItemSlot.Amount = dropItemSlot.Amount;

            dropItemSlot.ItemGS = draggedItem;
            dropItemSlot.Amount = draggedItemAmount;

            if (dragItem.equipmentType == EquipmentType.Weapon)
            {
                string[] name = dragItem.ItemName.Split(' ');
                if (name[0] == "Sword" || name[0] == "Staff" || name[0] == "Bow")
                {
                    player.SwapWeapons(name[0]);
                }
                else
                {
                    player.SwapWeapons(name[1]);
                }
            }
            if (dragItem.equipmentType == EquipmentType.Gem)
            {
                string[] names = new string[3];
                for (int i = 5; i <= 7; i++)
                {
                    if (EquipmentPanel.EquipmentSlots[i].ItemGS != null)
                    {
                        names[i - 5] = EquipmentPanel.EquipmentSlots[i].ItemGS.ItemName;
                    }
                }
                player.SpellSelect(names);
            }
        }
    }