//Method called based of an Event Trigger of when the Mouse Pointer (left click) is released
    public void ItemDeselected()
    {
        Transform selectedItem = transform.parent.parent.GetComponent <InventoryControllerTutorial>().selectedItem;

        //if player has selected an item go through with logic
        if (selectedItem != null)
        {
            Transform orignalSlot = transform.parent.parent.GetComponent <InventoryControllerTutorial>().orignalSlot;

            Transform selectedtSlot = transform.parent.parent.GetComponent <InventoryControllerTutorial>().selectedSlot;

            // if player is swapping two items and their locations
            if (selectedItem != null &&
                orignalSlot != null &&
                selectedtSlot != null && orignalSlot != selectedtSlot)
            {
                string playerID = "AlphaTest";

                PlayerInventoryTutorial inventory = GameObject.Find(playerID).GetComponent <PlayerInventoryTutorial>();
                int indexA = orignalSlot.GetComponent <SlotControllerTutorial>().Index;
                int indexB = selectedtSlot.GetComponent <SlotControllerTutorial>().Index;

                if (inventory.isItemSlotEmpty(indexA) != true)
                {
                    if (inventory.canSwapItems(indexA, indexB))
                    {
                        inventory.swapItems(indexA, indexB);
                        Sprite temp;

                        selectedItem.position = orignalSlot.position;
                        temp = selectedItem.GetComponent <Image>().sprite;
                        selectedItem.GetComponent <Image>().sprite = selectedtSlot.GetChild(0).GetComponent <Image>().sprite;
                        selectedtSlot.GetChild(0).GetComponent <Image>().sprite = temp;
                    }
                }
            }
            //if player is deciding to throw their item away
            else if (selectedItem != null && orignalSlot != null && selectedtSlot == null)
            {
                GameObject.Find("SoundManager").GetComponent <InGameSoundManager>().playInventoryDialogPopupEffect();
                GameObject dialog = GameObject.Find("/ScreenUI/InventoryDropItemDialog/Panel");
                transform.parent.parent.GetComponent <InventoryControllerTutorial>().setItemToThrowAway(orignalSlot.GetComponent <SlotControllerTutorial>().Index);
                dialog.SetActive(true);
            }

            selectedItem.SetParent(selectedItem.GetComponent <ItemControllerTutorial>().orignalParent);
            transform.position = transform.parent.GetComponent <SlotControllerTutorial>().imageOriginalLocation.position;
            transform.parent.parent.GetComponent <InventoryControllerTutorial>().selectedItem = null;
            transform.parent.parent.GetComponent <InventoryControllerTutorial>().orignalSlot  = null;
            transform.parent.parent.GetComponent <InventoryControllerTutorial>().selectedSlot = null;
        }
    }
Example #2
0
    //Method for when Player uses a consummable Item like a potion
    public void useItem(int index)
    {
        string playerID = "AlphaTest";

        PlayerInventoryTutorial inventory = GameObject.Find(playerID).GetComponent <PlayerInventoryTutorial>();
        ItemTutorial            item      = inventory.getItem(index);

        if (item.itemType.Equals("HealthPotion"))
        {
            GameObject.Find("SoundManager").GetComponent <InGameSoundManager>().playHpHealEffect();
            GameObject.Find(playerID).GetComponent <PlayerStatTutorial>().CmdAddHealth(20f);
            inventory.removeItem(index);
            updateSlotImage(index, "");
            foreach (Transform child in GameObject.Find(playerID).transform.FindChild("Alpha:Hips/Alpha:Spine/Alpha:Spine1/Alpha:Spine2/Alpha:RightShoulder/Alpha:RightArm/Alpha:RightForeArm/Alpha:RightHand"))
            {
                if (child.name.Contains("Item"))
                {
                    if (child.GetComponent <ItemTutorial>().itemName.Equals(item.itemName))
                    {
                        GameObject.Find(playerID).GetComponent <PlayerActionsTutorial>().CmdDeleteItem(child.gameObject);
                        break;
                    }
                }
            }
        }
        else if (item.itemType.Equals("StaminaPotion"))
        {
            GameObject.Find("SoundManager").GetComponent <InGameSoundManager>().playHpHealEffect();
            GameObject.Find(playerID).GetComponent <PlayerMovementTutorial>().CmdAddStamina();
            inventory.removeItem(index);
            updateSlotImage(index, "");
            foreach (Transform child in GameObject.Find(playerID).transform.FindChild("Alpha:Hips/Alpha:Spine/Alpha:Spine1/Alpha:Spine2/Alpha:RightShoulder/Alpha:RightArm/Alpha:RightForeArm/Alpha:RightHand"))
            {
                if (child.name.Contains("Item"))
                {
                    if (child.GetComponent <ItemTutorial>().itemName.Equals(item.itemName))
                    {
                        GameObject.Find(playerID).GetComponent <PlayerActionsTutorial>().CmdDeleteItem(child.gameObject);
                        break;
                    }
                }
            }
        }
    }
Example #3
0
    //Method for when Player decides to throw the item away
    public void DropButtonYesPressed()
    {
        GameObject.Find("SoundManager").GetComponent <InGameSoundManager>().playInventoryDialogPopupYesEffect();
        GameObject dialog   = GameObject.Find("/ScreenUI/InventoryDropItemDialog/Panel");
        string     playerID = "AlphaTest";

        PlayerInventoryTutorial inventory = GameObject.Find(playerID).GetComponent <PlayerInventoryTutorial>();
        string itemToRemove = inventory.GetItemName(ItemToThrowAway);

        foreach (Transform child in GameObject.Find(playerID).transform.FindChild("Alpha:Hips/Alpha:Spine/Alpha:Spine1/Alpha:Spine2/Alpha:RightShoulder/Alpha:RightArm/Alpha:RightForeArm/Alpha:RightHand"))
        {
            if (child.name.Contains("Item"))
            {
                if (child.GetComponent <ItemTutorial>().itemName.Equals(itemToRemove))
                {
                    GameObject.Find(playerID).GetComponent <PlayerActionsTutorial>().CmdDropItem(GameObject.Find(playerID), child.gameObject);
                }
            }
        }
        inventory.removeItem(ItemToThrowAway);
        dialog.SetActive(false);
    }