Ejemplo n.º 1
0
        /// <summary>
        /// Updates usable items in inventory
        /// </summary>
        public void RefreshInventory()
        {
            BagLookUp.Clear();

            foreach (ItemFactoryData temp in ItemsInBag)
            {
                SourceDataItemSO tmp;

                if (db.ItemDataMasterList.TryGetValue(temp.ItemName, out tmp))
                {
                    UsableItem itemToAdd = CreateDataListEntryItem(tmp, temp);

                    if (!BagLookUp.TryGetValue(temp.ItemName, out UsableItem item))
                    {
                        BagLookUp.Add(temp.ItemName, itemToAdd);
                    }
                    else
                    {
                        item.Quantity += itemToAdd.Quantity;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Transfers Item to another inventory
        /// </summary>
        /// <param name="itemName"></param>
        /// <param name="amount"></param>
        /// <param name="targetItem"></param>
        /// <returns></returns>
        public bool TransferItem(string itemName, int amount, out UsableItem targetItem)
        {
            if (BagLookUp.TryGetValue(itemName, out UsableItem item))
            {
                if (item.Quantity <= 0 || item.Quantity < amount)
                {
                    targetItem = item;
                    return(false);
                }

                item.Quantity -= amount;
                removeFromBag(item.ItemName, amount);
                targetItem          = item;
                targetItem.Quantity = amount;

                return(true);
            }
            else
            {
                Debug.LogWarning("ITEM DOES NOT EXIST");
                targetItem = item;
                return(false);
            }
        }