public void AddToInventory(Item item, bool AutoEquip, bool ForceEquip = false) { if (AutoEquip) { if (item.Equipment != Item.EquipmentCategory.NotEquippable) { GridItem lastItem; if (HandleDirectEquip(item, ForceEquip, out lastItem)) { if (lastItem != null) { AddToInventory(lastItem.GetItemReference(), false, false); ObjectPoolManager.Instance.RecycleObject(lastItem.GetComponent <PoolableObjectInstance>()); } return; } else { } } } if (item.Stacking == Item.Stackability.Stackable) { if (_items.ContainsKey(item.Id)) { List <GridItem> stackableItems = _items[item.Id]; foreach (GridItem gItem in stackableItems) { StackableGridItem sItem = gItem as StackableGridItem; if (!sItem.IsItemAtTheMax()) { int currentNumber = sItem.GetItemCount(); currentNumber++; sItem.SetCurrentNubmber(currentNumber); return; } } } AddNewGridItem(item, true); } else { AddNewGridItem(item, false); } OnItemPickedUpEvent?.Invoke(item); }
public void ConsumeGridItem(GridItem item) { if (item is StackableGridItem) { StackableGridItem stkRef = item as StackableGridItem; int currentNumber = item.GetCurrentNumber(); currentNumber -= 1; stkRef.SetCurrentNubmber(currentNumber); ConsumeItem(item.GetItemReference()); if (currentNumber == 0) { RemoveItemFromInventory(item, true); } } else { ConsumeItem(item.GetItemReference()); RemoveItemFromInventory(item, true); } }