Ejemplo n.º 1
0
    //Adds items
    public bool Add(_item item)
    {
        //checks if there is enough space
        if (items.Count >= space)
        {
            // if not, returns false so that the item is not destroyed
            return(false);
        }
        else if (item.element.packable == true && (index = SearchItem(item.element.name)) != -1)
        {
            items[index].amount += 1;

            if (onItemChangedCallBack != null)
            {
                onItemChangedCallBack.Invoke();
            }

            return(true);
        }
        else
        {
            //else, adds the item and destroys it
            item.amount += 1;
            items.Add(item);
            if (onItemChangedCallBack != null)
            {
                // calls the delegate function
                onItemChangedCallBack.Invoke();
            }
            return(true);
        }
    }
        public bool CallItemFunction(_item methodId, params object[] args)
        {
            string methodName = methodId.ToString();

            Type       type   = typeof(ItemActive);
            MethodInfo method = type.GetMethod(methodName);
            ItemActive c      = new ItemActive();

            return((bool)method.Invoke(c, args));
        }
Ejemplo n.º 3
0
    private void PickUp(_item element)
    {
        //true if the item was picked, false if not
        bool wasPickedUp = Inventory.instance.Add(element);

        //if it was picked, destroy it
        if (wasPickedUp == true)
        {
            Destroy(this.gameObject);
        }
    }
Ejemplo n.º 4
0
 public void ClearSlot()
 {
     //clears and disable the slot
     item         = new _item();
     icon.enabled = false;
     icon.sprite  = null;
     edge.enabled = false;
     edge.sprite  = null;
     //removes the removebutton
     removeButton.interactable = false;
 }
Ejemplo n.º 5
0
 public int SearchItemToRemove(_item item)
 {
     for (int i = 0; i < items.Count; i++)
     {
         if (items[i] == item)
         {
             return(i);
         }
     }
     return(-1);
 }
Ejemplo n.º 6
0
 //Adds an item
 public void AddItem(_item newItem)
 {
     //the item to be added
     item = newItem;
     //its sprite
     icon.sprite  = item.element.sprite;
     edge.sprite  = quantities[item.amount - 1];
     edge.enabled = true;
     //enable its icon
     icon.enabled = true;
     //actives the remove button
     removeButton.interactable = true;
 }
 public void Equip(Weapons newItem)
 {
     //slotIndex receives the position of the given weapon, if melee, 0, else 1.
     slotIndex = (int)newItem.equipSlot;
     //If there is an item already equipped, add it to the inventory before changing equipped items
     if (currentEquipment[slotIndex] != null)
     {
         aux.element = currentEquipment[slotIndex];
         Inventory.instance.Add(aux);
         aux = new _item();
     }
     //equip the item
     currentEquipment[slotIndex] = newItem;
     playerEquip.UpdateWeapon();
 }
Ejemplo n.º 8
0
 //Removes items
 public void Remove(_item item)
 {
     if ((index = SearchItemToRemove(item)) != -1 && items[index].amount != 1)
     {
         items[index].amount--;
     }
     else
     {
         items.Remove(item);
     }
     // calls the delegate function
     if (onItemChangedCallBack != null)
     {
         onItemChangedCallBack.Invoke();
     }
 }
Ejemplo n.º 9
0
    //THIS FUNCTION IS CALLED THROUGH THE BUTTON INSPECTOR
    public void Unequip()
    {
        int slotIndex = (int)item.equipSlot;

        if (EquipmentManager.instance.currentEquipment[slotIndex] != null)
        {
            aux.element = EquipmentManager.instance.currentEquipment[slotIndex];
            //Adds the item to the inventory
            Inventory.instance.Add(aux);
            aux = new _item();
            //Removes the item from the array of equipped items
            EquipmentManager.instance.currentEquipment[slotIndex] = null;
            //this.GetComponent<EquipmentManager>().slots[this.GetComponent<EquipmentManager>().slotIndex].ClearSlot();
            //if (EquipmentManager.instance.onItemChangedCallBackEquipped != null)
            //EquipmentManager.instance.onItemChangedCallBackEquipped.Invoke();
            ClearSlot();
            playerEquip.UpdateWeapon();
        }
    }
Ejemplo n.º 10
0
 set => SetProperty(ref _item, value);
Ejemplo n.º 11
0
 set => _setter(_item, value);