feat: add event bus

This commit is contained in:
k0t9i
2023-01-31 14:45:40 +04:00
parent ea6778a3bd
commit b8b92b7cf8
14 changed files with 240 additions and 48 deletions

View File

@ -1,4 +1,5 @@
using Client.Domain.Entities;
using Client.Domain.Events;
using Client.Domain.Factories;
using Client.Domain.Helpers;
using Client.Domain.ViewModels;
@ -14,22 +15,22 @@ namespace Client.Domain.Service
{
public override void OnCreate(NPC entity)
{
mainViewModel.AddNpc(entity);
entity.Level = npcInfoHelper.GetLevel(entity.NpcId);
entity.AggroRadius = npcInfoHelper.GetAggroRadius(entity.NpcId);
eventBus.Publish(new NpcCreatedEvent(entity));
}
public override void OnDelete(NPC entity)
{
mainViewModel.RemoveNpc(entity);
eventBus.Publish(new NpcDeletedEvent(entity.Id));
}
public NpcHandler(EntityFactoryInterface<NPC> factory, MainViewModelInterface mainViewModel, NpcInfoHelperInterface npcInfoHelper) : base(factory)
public NpcHandler(EntityFactoryInterface<NPC> factory, EventBusInterface eventBus, NpcInfoHelperInterface npcInfoHelper) : base(factory)
{
this.mainViewModel = mainViewModel;
this.eventBus = eventBus;
this.npcInfoHelper = npcInfoHelper;
}
private readonly MainViewModelInterface mainViewModel;
private readonly EventBusInterface eventBus;
private readonly NpcInfoHelperInterface npcInfoHelper;
}
}