예제 #1
0
    /*
     * Remove a specified amount of a specified consumable from the inventory
     */
    public bool RemoveConsumable(Ressources.Consumables type, int amount)
    {
        foreach (var entry in inventory)
        {
            try
            {
                Item.Consumable ic = (Item.Consumable)entry.Key;
                if (ic.GetName() == type)
                {
                    if (entry.Value - amount == 0)
                    {
                        inventory.Remove(ic);
                        return(true);
                    }
                    else if (entry.Value - amount < 0)
                    {
                        return(false);
                    }
                    else
                    {
                        inventory[ic] = entry.Value - amount;
                        Debug.Log(inventory[ic]);
                        return(true);
                    }
                }
            }
            catch (System.InvalidCastException e) { }
        }

        return(false);
    }
예제 #2
0
파일: Item.cs 프로젝트: ThatBirkl/Bhrachan
 public Consumable(Ressources.Consumables _name, float _weight, int _value) : base(_weight, _value)
 {
     itemType = Type.ItemType.consumable;
     name     = _name;
 }