Example #1
0
        // Takes even if not exact
        public ItemAmount TakeItem(ItemAmount itemAmount)
        {
            for (int i = 0; i < itemList.Count; i++)
            {
                ItemAmount itemInInventory = itemList[i];
                if (itemInInventory.type == itemAmount.type)
                {
                    int amountTaken = Mathf.Min(itemInInventory.amount, itemAmount.amount);
                    itemInInventory.amount = Mathf.Max(0, itemInInventory.amount - amountTaken);
                    if (itemInInventory.amount == 0)
                    {
                        itemList.RemoveAt(i);
                    }
                    else
                    {
                        itemList[i] = itemInInventory;
                    }

                    InventoryChange(itemList);
                    return(new ItemAmount(itemAmount.type, amountTaken));
                }
            }

            return(new ItemAmount(itemAmount.type, 0));
        }
Example #2
0
        public void AddItem(ItemAmount itemAmount)
        {
            if (itemAmount.type == ItemType.POTATO)
            {
                AddFuel(itemAmount.amount);
                return;
            }

            var added = false;

            for (var i = 0; i < itemList.Count; i++)
            {
                if (itemList[i].type == itemAmount.type)
                {
                    added       = true;
                    itemList[i] = new ItemAmount(itemAmount.type,
                                                 itemList[i].amount + itemAmount.amount);
                    break;
                }
            }

            if (!added)
            {
                itemList.Add(itemAmount);
            }

            InventoryChange(itemList);
        }
Example #3
0
 public static void ZeroAmounts(List <ItemAmount> items)
 {
     for (var i = 0; i < items.Count; i++)
     {
         items[i] = new ItemAmount(items[i].type, 0);
     }
 }
Example #4
0
        public bool HasItem(ItemAmount itemAmount)
        {
            foreach (ItemAmount itemInInventory in itemList)
            {
                if (itemInInventory.type == itemAmount.type)
                {
                    return(itemAmount.amount <= itemInInventory.amount);
                }
            }

            return(false);
        }
Example #5
0
        public void AddItem(ItemAmount itemToAdd)
        {
            var added = false;

            for (var i = 0; i < items.Count; i++)
            {
                var item = items[i];
                if (item.type == itemToAdd.type)
                {
                    items[i] = new ItemAmount(item.type, item.amount + itemToAdd.amount);
                    added    = true;
                }
            }

            if (!added)
            {
                items.Add(itemToAdd);
            }
        }
Example #6
0
        public static List <ItemAmount> Add(List <ItemAmount> items, ItemAmount item)
        {
            var added = false;

            for (var i = 0; i < items.Count; i++)
            {
                var itemInList = items[i];
                if (item.type == itemInList.type)
                {
                    itemInList.amount = itemInList.amount + item.amount;
                    items[i]          = itemInList;
                    added             = true;
                }
            }

            if (!added)
            {
                items.Add(item);
            }

            return(items);
        }
Example #7
0
 void Awake()
 {
     _fuel    = new ItemAmount(ItemType.POTATO, LevelManager.Instance.currentLevelData.potatoAmount);
     itemList = LevelManager.Instance.currentLevelData.initialInventory.ToList();
 }