Example #1
0
        private void View_OnItemClicked(object sender, OptionClickEventArgs e)
        {
            try
            {
                switch (e.Instruction.ToLower())
                {
                case USE_INSTRUCTION:
                    UseItem = inventory[e.ItemIndex];
                    break;

                case WATCH_INSTRUCTION:
                    GameController.Instance.DisplayText(inventory[e.ItemIndex].description, inventory[e.ItemIndex].image);
                    if (inventory[e.ItemIndex].type == InventoryType.DocumentWithAudio ||
                        inventory[e.ItemIndex].type == InventoryType.ItemWithAudio)
                    {
                        SoundManager.Instance.VoiceController.Play(inventory[e.ItemIndex].audioClip);
                    }
                    break;

                default:
                    Debug.LogError($"{e.Instruction} is not a valid instruction to InventoryController class");
                    break;
                }
                view.RemoveAllListener();
                view.ActiveOptionButtons(false);
            }
            catch (KeyNotFoundException)
            {
                Debug.Log("ITEM IS NULL");
                view.RemoveAllListener();
                view.ActiveOptionButtons(false);
                return;
            }
        }
Example #2
0
        public void RemoveFromInventory(InventoryItemModel item)
        {
            int index = -1;

            for (int i = 0; i < inventory.Count; i++)
            {
                if (inventory[i] == item)
                {
                    index = i;
                    break;
                }
            }

            if (index != -1)
            {
                if (inventory[index].amount - item.amount > 0)
                {
                    inventory[index].amount -= item.amount;
                }
                else
                {
                    view.RemoveItem(index);
                    inventory.Remove(index);
                }
            }
        }
Example #3
0
        public InventoryItemModel FindByItemName(string name)
        {
            if (name == default(string))
            {
                return(null);
            }

            InventoryItemModel item = null;

            for (int i = 0; i < inventory.Count; i++)
            {
                if (inventory[i].itemName == name)
                {
                    item = inventory[i];
                    break;
                }
            }

            return(item);
        }
Example #4
0
        public bool AddToInventory(InventoryItemModel item, bool showNow = false)
        {
            /// -1 slot is empty
            int index = -1;

            for (int i = 0; i < inventory.Count; i++)
            {
                if (inventory[i] == item)
                {
                    index = i;
                    break;
                }
            }

            if (index != -1)
            {
                if (inventory[index].amount + item.amount < item.maxAmount)
                {
                    inventory[index].amount += item.amount;
                }
            }

            else
            {
                int key = view.AddItem(item.icon);
                if (key == -1)
                {
                    return(false);
                }

                inventory.Add(key, item);
            }

            view.Display();
            return(true);
        }