public bool CanAcceptItem(Loot loot, AddItemArg addItemArg) { return(Owner.InventoryAcceptsItem(this, loot, addItemArg)); }
public virtual bool Add ( Loot item, AddItemArg args = null ) { if (args == null) { args = new AddItemArg(); } var exist = false; var stackedInInv = GetStackedItem(item); var itemStacked = item as StackedLoot; if (stackedInInv != null) { exist = true; } else { exist = Items.Contains(item); } bool changed = false; if (!exist) { if (Capacity <= ItemsCount) { //Assert(false, "Capacity <= ItemsCount"); AppendAction(new InventoryAction(this) { Info = "Not enough room", Level = ActionLevel.Important, Kind = InventoryActionKind.NotEnoughRoom }); return(false); } if (item.StackedInInventory) { SetStackCount(itemStacked, itemStacked.Count); } else { Items.Add(item); } changed = true; } else { if (stackedInInv != null) { //var stackedItemCount = GetStackCount(item); //Assert(stackedItemCount > 0); SetStackCount(stackedInInv, stackedInInv.Count + itemStacked.Count); changed = true; } else { //var sameID = Items.FirstOrDefault(i => i.Id == item.Id); Assert(false, "Add(Loot item) duplicate item " + item); //throw new Exception("Add(Loot item) duplicate item " + item); } } if (changed && args.notifyObservers) { AppendAction(new InventoryAction(this) { Kind = InventoryActionKind.ItemAdded, Loot = item, Inv = this, DetailedKind = args.detailedKind }); } return(changed); }