Esempio n. 1
0
    void MoveToMouse()
    {
        Item item = inventory.InventoryList [slotID];

        // Taking from slot
        if (inventoryUI.GetItemAtMouse().itemName == "" && item.itemName != "")
        {
            inventoryUI.SetAtMouse(item, slotID, gameObject, GetComponent <InventorySlotData>());
            inventory.RemoveAtIndex(slotID);
            inventoryUI.GetSlotAtMouse().GetComponent <InventorySlotData> ().Empty();

            if (slotChangedEvent != null)
            {
                slotChangedEvent();
            }
        }

        // Putting in slot
        else
        {
            // Slot is empty
            if (inventory.InventoryList [slotID].itemName == "")
            {
                inventory.AddItemToInventory(inventoryUI.GetItemAtMouse(), slotID);
                InventorySlotData slotData = GetComponent <InventorySlotData> ();
                slotData.SetItem(inventory.InventoryList [slotID]);
                slotData.currentAmmo = inventoryUI.GetWeaponAmmoAtMouse();
                slotData.itemHealth  = inventoryUI.GetHealthAtMouse();
                slotData.SetItemHealth();
            }

            // Swap places
            else
            {
                InventorySlotData thisSlot  = GetComponent <InventorySlotData> ();
                InventorySlotData otherSlot = inventoryUI.GetSlotAtMouse().GetComponent <InventorySlotData> ();

                int heldAmmo = inventoryUI.GetWeaponAmmoAtMouse();  // the ammo of the item being moved
                int newAmmo  = thisSlot.currentAmmo;                // the ammo of this slot

                float heldHealth = inventoryUI.GetHealthAtMouse();  // the health of the item being moved
                float newHealth  = thisSlot.itemHealth;             // the health of this slot

                // Swap the slots
                inventory.AddItemToInventory(item, inventoryUI.GetIndexAtMouse());
                inventory.AddItemToInventory(inventoryUI.GetItemAtMouse(), slotID);

                // Replace the values
                thisSlot.currentAmmo  = heldAmmo;
                thisSlot.itemHealth   = heldHealth;
                otherSlot.currentAmmo = newAmmo;
                otherSlot.itemHealth  = newHealth;
            }

            inventoryUI.EmptyAtMouse();
        }
    }
Esempio n. 2
0
    void ShiftClick()
    {
        // From Hotbar
        if (this.slotID < 7)
        {
            for (int i = 7; i < inventory.InventoryList.Count; i++)
            {
                Item item = inventory.InventoryList [i];
                // Empty space
                if (item.itemName == "")
                {
                    inventory.MoveItemToSlot(slotID, i);
                    tooltip.Hide();

                    GameObject[] allSlots = GameObject.FindGameObjectsWithTag("InventorySlot");
                    for (int j = 0; j < allSlots.Length; j++)
                    {
                        if (allSlots [j].GetComponent <InventorySlot> ().slotID == i)
                        {
                            InventorySlotData slotData = allSlots [j].GetComponent <InventorySlotData> ();
                            InventorySlotData thisSlot = GetComponent <InventorySlotData> ();

                            slotData.SetItem(inventory.InventoryList [slotID]);
                            slotData.currentAmmo = thisSlot.currentAmmo;
                            slotData.itemHealth  = thisSlot.itemHealth;
                            slotData.SetItemHealth();
                            break;
                        }
                    }
                    break;
                }
            }
        }

        // From Inventory
        if (this.slotID >= 7)
        {
            for (int i = 0; i < 7; i++)
            {
                Item item = inventory.InventoryList [i];
                // Empty space
                if (item.itemName == "")
                {
                    inventory.MoveItemToSlot(slotID, i);
                    tooltip.Hide();

                    GameObject[] allSlots = GameObject.FindGameObjectsWithTag("InventorySlot");
                    for (int j = 0; j < allSlots.Length; j++)
                    {
                        if (allSlots [j].GetComponent <InventorySlot> ().slotID == i)
                        {
                            InventorySlotData slotData = allSlots [j].GetComponent <InventorySlotData> ();
                            InventorySlotData thisSlot = GetComponent <InventorySlotData> ();

                            slotData.SetItem(inventory.InventoryList [slotID]);
                            slotData.currentAmmo = thisSlot.currentAmmo;
                            slotData.itemHealth  = thisSlot.itemHealth;
                            slotData.SetItemHealth();
                            break;
                        }
                    }
                    break;
                }
            }
        }
    }