///<summary>This Method should be called by the Inventory Buttons</summary>
    public void InteractWithInventoryUI(Item invItem)
    {
        if (invItem != null)
        {
            if (invItem is Consumable)
            {
                Consumable consItem = (Consumable)invItem;

                Debug.Log("Item");

                consItem.Consume(null);
                inventory.RemoveItem(invItem, 1);
                inventoryUIConnection.UpdateInventoryUI();

                return;
            }
            if (invItem is Armor)
            {
                for (int i = 0; i < equipmentSlotArray.Length; i++)
                {
                    if (equipmentSlotArray[i] != null)
                    {
                        if (equipmentSlotArray[i].slot.ToString() == invItem.equipmentSlot.ToString())
                        {
                            equipmentSlotArray[i].Equip((Armor)invItem);
                            return;
                        }
                    }
                    else
                    {
                        Debug.Log("equipmentSlotArray " + i + " is null");
                        return;
                    }
                }
            }
            if (invItem is Weapon)
            {
                Debug.Log("Weapon");
                for (int i = 0; i < equipmentSlotArray.Length; i++)
                {
                    if (equipmentSlotArray[i] != null)
                    {
                        if (equipmentSlotArray[i].slot.ToString() == invItem.equipmentSlot.ToString())
                        {
                            equipmentSlotArray[i].Equip((Weapon)invItem);
                            return;
                        }
                    }
                    else
                    {
                        Debug.Log("equipmentSlotArray " + i + " is null");
                        return;
                    }
                }
            }
        }
    }
예제 #2
0
    public bool Equip(Item newItem)
    {
        if (newItem != null && newItem.equipmentSlot.ToString() == slot.ToString())
        {
            var previousItem = equipped;
            equipped = newItem;
            if (previousItem != null)
            {
                if (inventory.AddItem(previousItem, 1))
                {
                    previousItem.RemoveStats();  //remove the stats of the old item
                    //sets the new item
                    UpdateUIAndApplyStats(equipped);
                    inventory.RemoveItem(equipped, 1);
                    inventoryUI.UpdateInventoryUI();
                    return(true);
                }
                else
                {
                    Debug.LogWarning("You must make room in your inventory before you can equip this item");
                    return(false);
                }
            }

            else
            {
                UpdateUIAndApplyStats(equipped);
                inventory.RemoveItem(equipped, 1);
                inventoryUI.UpdateInventoryUI();
                return(true);
            }
        }
        else
        {
            return(false);
        }
    }
예제 #3
0
    public void SetTarget()
    {
        //Creates a Ray at the Crosshairposition (Ray from camera through the crisshair)
        Ray worldPosCrosshair = cam.ScreenPointToRay(crossHair.transform.position);

        RaycastHit hit;

        if (Physics.Raycast(worldPosCrosshair, out hit, 20f) && hit.transform.tag != "Terrain")
        {
            targetName.text = hit.transform.name;
            target          = hit.transform.gameObject;
            //Add Item Logic
            if (hit.transform.tag == "Interactable" && Input.GetKey(KeyCode.F))
            {
                //9 == QuestITem
                if (hit.transform.gameObject.layer == 9)
                {
                    questItemInventory.items.Add(hit.transform.GetComponent <ItemStats>().itemStats);
                    Remover.CheckAndRemove(hit.transform.gameObject);
                }
                else if (inventory.AddItem(hit.transform.GetComponent <ItemStats>().itemStats, 1))  //Add Item to Inventory
                {
                    //Update Visual Inventory
                    inventoryUI.UpdateInventoryUI();

                    //Check if the GameObject was relevant to a quest and remove it
                    Remover.CheckAndRemove(hit.transform.gameObject);
                }
            }
            //Kill test
            //if (hit.transform.tag == "Enemy" && hit.transform.GetComponent<NPCStats>() != null && Input.GetKey(KeyCode.F))
            //{
            //    hit.transform.GetComponent<NPCStats>().SufferDamage(99999999, transform.GetComponent<Stats>());
            //}
        }
        else
        {
            targetName.text = "";
        }
    }