- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class InventoryManager : MonoBehaviour
- {
- [Header("Inventory Settings: ")]
- [SerializeField] private int inventoryCapacity;
- [SerializeField] private int quickInventoryCapacity = 5;
- [SerializeField] private Inventory inventory;
- [SerializeField] private Inventory quickInventory;
- public Inventory Inventory => inventory;
- public Inventory QuickInventory => quickInventory;
-
- [Header("Item Stack Prefabs")]
- [SerializeField] private Item item;
- public GameObject itemStack;
- void Awake()
- {
- inventory = new Inventory(inventoryCapacity, gameObject);
- quickInventory = new Inventory(quickInventoryCapacity, gameObject);
- }
-
- void Start()
- {
- }
-
- void Update()
- {
-
- QuickInventoryActions();
- if (Input.GetKeyDown(KeyCode.F))
- {
- AddItem(item, 1);
- Debug.Log($"Added Item: {item.ItemName}");
- }
- }
- private void QuickInventoryActions()
- {
- if (Input.GetKeyDown(InputManager.GetKey(InputAction.use1)))
- {
- UseInventoryItems(0);
- }
- else if (Input.GetKeyDown(InputManager.GetKey(InputAction.use2)))
- {
- UseInventoryItems(1);
- }
- else if (Input.GetKeyDown(InputManager.GetKey(InputAction.use3)))
- {
- UseInventoryItems(2);
- }
- else if (Input.GetKeyDown(InputManager.GetKey(InputAction.use4)))
- {
- UseInventoryItems(3);
- }
- else if (Input.GetKeyDown(InputManager.GetKey(InputAction.use5)))
- {
- UseInventoryItems(4);
- }
- }
- private void UseInventoryItems(int index)
- {
- InventorySlot slot = quickInventory.GetSlot(index);
- if (slot.IsEmpty()) return;
- Item item = slot.Item;
- if (item == null) return;
- if (transform.parent.TryGetComponent(out PlayerController controller))
- {
- switch (item)
- {
- case StatPotion potion:
- Debug.Log("Try to apply effect");
-
- potion.Visit(controller);
- slot.Owner.RemoveItemAmount(index, 1);
- return;
- }
- }
- else
- {
- Debug.LogError($"PlayerController is NULL!");
- }
- }
-
- public bool AddItem(Item item, int amount)
- {
-
- if (quickInventory.AddItem(item, amount))
- {
- return true;
- }
-
- else if(inventory.AddItem(item, amount))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public void SwapInventorySlot(InventorySlot slotA, InventorySlot slotB)
- {
- if (slotA.Owner != slotB.Owner)
- {
- Inventory.SwapInventoriesSlot(slotA, slotB);
- }
- else
- {
-
- Inventory inventory = slotA.Owner;
- inventory.SwapItemSlot(slotA.SlotIndex, slotB.SlotIndex);
- }
- }
- public void DropItem(int index, int amount)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- }