public bool Add(InteractorType item, bool isStackable, float itemDurability) { if (isStackable && Slots.Count > 0) { for (int i = 0; i < Slots.Count; i++) { if (Slots[i].Item == item) { Slots[i].AddAmount(1); InventoriesManagerEvents.OnItemAdd(); return(true); } } } if (Slots.Count >= _availableSlots) { InventoriesManagerEvents.OnInventoryFull(); return(false); } Slots.Add(new InventorySlot(item.UniqueID, item, 1, itemDurability)); InventoriesManagerEvents.OnItemAdd(); return(true); }
public void Remove(InteractorType item) { if (_selectedItem == item) { _selectedItem = null; } for (int i = 0; i < Slots.Count; i++) { if (Slots[i].Item == item) { if (Slots[i].Amount > 1) { Slots[i].RemoveAmount(1); } else { Slots.RemoveAt(i); } InventoriesManagerEvents.OnItemRemoved(); return; } } }
public bool HasFreeSlots() { if (Slots.Count >= _availableSlots) { InventoriesManagerEvents.OnInventoryFull(); return(false); } return(true); }
public void SetDataClasses(List <InventoryData> dataClasses) { dataClasses.ForEach(inventoryData => { for (int i = 0; i < Inventories.Count; i++) { if (inventoryData.ID.Equals(Inventories[i].ID)) { Inventories[i].Name = inventoryData.Name; Inventories[i].ID = inventoryData.ID; Inventories[i].MaxSlots = inventoryData.MaxSlots; Inventories[i].AvailableSlots = inventoryData.AvailableSlots; Inventories[i].Slots = new List <InventorySlot>(); foreach (InventorySlotData slotData in inventoryData.SlotsData) { InteractorType interactorType; if (slotData.ItemIsBlueprint) { interactorType = Inventories[i].ItemsDB.GetItemCopyByID(slotData.ItemUniqueID); } else { interactorType = Inventories[i].ItemsDB.GetItemByID(slotData.ItemUniqueID); } if (interactorType) { //also setup the item with data from slotData. InventorySlot slot = new InventorySlot(slotData.ItemUniqueID, interactorType, slotData.Amount, slotData.ItemDurability); Inventories[i].Slots.Add(slot); } else { //should I still add an empty slot ?? Debug.LogWarningFormat("InteractorType ID:{0} not found in {1}.", slotData.ItemUniqueID, Inventories[i].ItemsDB.name); break; } InventoriesManagerEvents.OnInventoryLoaded();//should i move this outside of the foreach ?! = 0.o } } } }); }