Exemple #1
0
        public override bool Drop(Draggable dragged)
        {
            // Move item to end of inventory
            // TODO when this knows about contents, instead figure out index based on position?
            InventoryManager inventory   = GameController.Instance.inventory;
            DraggableItem    draggedItem = (DraggableItem)dragged;
            int index = IndexAtPosition(Input.mousePosition);

            if (draggedItem != null && draggedItem.itemBox != this)
            {
                Item item = draggedItem.itemBox.ContainedItem;
                if (draggedItem.itemBox is InventorySlot)
                {
                    return(inventory.MoveItem(item, index));
                }
                else if (draggedItem.itemBox is EquipmentSlotUI)
                {
                    EquipmentSlotUI slot = (EquipmentSlotUI)draggedItem.itemBox;
                    item = slot.equipmentSlot.Unequip();
                    if (item != null)
                    {
                        inventory.Add(item, index);
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #2
0
        public override bool Drop(Draggable dragged)
        {
            // If item from another itembox, swap items
            DraggableItem draggedItem = (DraggableItem)dragged;

            if (draggedItem != null && draggedItem.itemBox != this)
            {
                List <Item> inventory = GameController.Instance.inventory.playerInventory;
                int         myIndex   = inventory.IndexOf(ContainedItem);
                Item        theirItem = draggedItem.itemBox.ContainedItem;

                if (draggedItem.itemBox is InventorySlot)
                {
                    // If from inventory, swap positions
                    InventorySlot theirSlot = (InventorySlot)draggedItem.itemBox;
                    return(GameController.Instance.inventory.SwapItems(ContainedItem, theirItem));
                }
                else if (draggedItem.itemBox is EquipmentSlotUI)
                {
                    // If from equipment, unequip item and insert before this
                    EquipmentSlotUI theirSlot = (EquipmentSlotUI)draggedItem.itemBox;
                    theirItem = theirSlot.equipmentSlot.Unequip();
                    if (theirItem != null)
                    {
                        GameController.Instance.inventory.Add(theirItem, myIndex);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        public override bool Drop(Draggable dragged)
        {
            // If item from another itembox, swap items

            DraggableItem draggedItem = (DraggableItem)dragged;

            if (draggedItem != null && draggedItem.itemBox != this)
            {
                // Check type of dragged item
                Equipment theirItem = draggedItem.itemBox.ContainedItem as Equipment;
                if (theirItem == null)
                {
                    return(false);
                }

                if (draggedItem.itemBox is InventorySlot)
                {
                    // If from inventory unequip this and equip theirs
                    // Note: both will end up at end, not bothering with that since
                    // equipment slots will be changed later
                    if (equipmentSlot.CanEquip(theirItem))
                    {
                        Equipment myItem = equipmentSlot.Unequip();
                        equipmentSlot.Equip(theirItem);
                        if (myItem != null)
                        {
                            GameController.Instance.inventory.Replace(theirItem, myItem);
                        }
                        else
                        {
                            GameController.Instance.inventory.Discard(theirItem);
                        }
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (draggedItem.itemBox is EquipmentSlotUI)
                {
                    //  if both rings, swap rings
                    EquipmentSlotUI otherUI   = (EquipmentSlotUI)draggedItem.itemBox;
                    EquipmentSlot   theirSlot = otherUI.equipmentSlot;
                    if (theirSlot.character == equipmentSlot.character)
                    {
                        if (equipmentSlot.SwapItem(theirSlot))
                        {
                            ContainedItem         = equipmentSlot.equippedItem;
                            otherUI.ContainedItem = theirSlot.equippedItem;
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }