public Task Handle(PlayerInventoryChangedEvent evnt) { var player = _dbContext.Players .Include(p => p.WarehouseInventory) .FirstOrDefault(p => p.PlayerId == evnt.EntityId); if (player != null) { foreach (var stack in evnt.InventoryChange) { var existingInventory = player.WarehouseInventory .FirstOrDefault(i => i.ItemId == stack.Name); if (existingInventory != null) { existingInventory.Quantity += stack.Count; } else { player.WarehouseInventory.Add(new WarehouseInventory { ItemId = stack.Name, Quantity = stack.Count, }); } } } return(Task.CompletedTask); }
public Task Handle(PlayerInventoryChangedEvent evnt) { if (evnt.Metadata.SourceAssembly == Assembly.GetExecutingAssembly().FullName) { // We don't process these events if they come from this assembly return(Task.CompletedTask); } var player = _state.Players[evnt.EntityId]; foreach (var stack in evnt.InventoryChange) { if (player.Inventory.TryGetValue(stack.Name, out var inventory)) { inventory.Quantity += stack.Count; } else { player.Inventory.Add(stack.Name, new WarehouseInventory { ItemId = stack.Name, Quantity = stack.Count, }); } } return(Task.CompletedTask); }