private void AddItemToInventory(Item item, int amount) { bool addingNew = !Owned(item.itemId); ItemListing listing = this.GetItemListingForId(addingNew, item.itemId); listing.Add(amount); InventoryAdjustment adjustment = addingNew ? InventoryAdjustment.ADD : InventoryAdjustment.UPDATE; var adjustmentArgs = new InventoryAdjustmentEventArgs(listing, adjustment); InventoryAdjusted.BroadcastEvent(this, adjustmentArgs); }
public void RemoveFromInventory(int itemId, int amount = 1) { if (Owned(itemId)) { ItemListing listing = inventoryListingsByItemId[itemId]; listing.Remove(amount); bool remove = listing.IsEmpty; var adjustment = InventoryAdjustment.UPDATE; if (remove) { inventoryListingsByItemId.Remove(itemId); adjustment = InventoryAdjustment.REMOVE; } var adjustmentArgs = new InventoryAdjustmentEventArgs(listing, adjustment); InventoryAdjusted.BroadcastEvent(this, adjustmentArgs); } }