diff --git a/Client/App.xaml.cs b/Client/App.xaml.cs index 0dbfe06..d8bac3d 100644 --- a/Client/App.xaml.cs +++ b/Client/App.xaml.cs @@ -92,6 +92,7 @@ namespace Client .AddSingleton(typeof(NpcInfoHelperInterface), typeof(ConfigurationNpcInfoHelper)) .AddSingleton(typeof(EventBusInterface), typeof(InMemoryEventBus)) + .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) .AddTransient(typeof(EntityFactoryInterface), typeof(EntityFactory)) diff --git a/Client/Domain/Entities/Entity.cs b/Client/Domain/Entities/Entity.cs new file mode 100644 index 0000000..3466382 --- /dev/null +++ b/Client/Domain/Entities/Entity.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Client.Domain.Entities +{ + public class Entity : EntityInterface + { + public uint Id { get; set; } + } +} diff --git a/Client/Domain/Service/DropHandler.cs b/Client/Domain/Service/DropHandler.cs index 24b2cf2..53fb314 100644 --- a/Client/Domain/Service/DropHandler.cs +++ b/Client/Domain/Service/DropHandler.cs @@ -20,7 +20,7 @@ namespace Client.Domain.Service eventBus.Publish(new DropDeletedEvent(entity.Id)); } - public DropHandler(EntityFactoryInterface factory, EventBusInterface eventBus) : base(factory) + public DropHandler(EntityFactoryInterface factory, EntityFactoryInterface entityFactory, EventBusInterface eventBus) : base(factory, entityFactory) { this.eventBus = eventBus; } diff --git a/Client/Domain/Service/EntityHandler.cs b/Client/Domain/Service/EntityHandler.cs index 324b907..3d675bf 100644 --- a/Client/Domain/Service/EntityHandler.cs +++ b/Client/Domain/Service/EntityHandler.cs @@ -14,29 +14,38 @@ namespace Client.Domain.Service { public void Update(MessageOperationEnum operation, string content) { - var entity = factory.Create(content); + var baseEntity = entityFactory.Create(content); + if (baseEntity == null) + { + throw new ArgumentNullException(nameof(baseEntity)); + } + if (operation == MessageOperationEnum.Create) { + var entity = factory.Create(content); + if (entity == null) { throw new ArgumentNullException(nameof(entity)); } - entities[entity.Id] = entity; + entities[baseEntity.Id] = entity; OnCreate(entity); } else if (operation == MessageOperationEnum.Update) { - if (entity != null && entities.ContainsKey(entity.Id)) + if (entities.ContainsKey(baseEntity.Id)) { + var entity = entities[baseEntity.Id]; factory.Update(entities[entity.Id], content); OnUpdate(entities[entity.Id]); } } else if (operation == MessageOperationEnum.Delete) { - if (entity != null) + if (entities.ContainsKey(baseEntity.Id)) { + var entity = entities[baseEntity.Id]; entities.Remove(entity.Id); OnDelete(entity); } @@ -66,12 +75,14 @@ namespace Client.Domain.Service } - public EntityHandler(EntityFactoryInterface factory) + public EntityHandler(EntityFactoryInterface factory, EntityFactoryInterface entityFactory) { this.factory = factory; + this.entityFactory = entityFactory; } private readonly EntityFactoryInterface factory; + private readonly EntityFactoryInterface entityFactory; private Dictionary entities = new Dictionary(); } } diff --git a/Client/Domain/Service/HeroHandler.cs b/Client/Domain/Service/HeroHandler.cs index 1864e2f..49addf5 100644 --- a/Client/Domain/Service/HeroHandler.cs +++ b/Client/Domain/Service/HeroHandler.cs @@ -35,7 +35,7 @@ namespace Client.Domain.Service eventBus.Publish(new HeroDeletedEvent()); } - public HeroHandler(EntityFactoryInterface factory, EventBusInterface eventBus, ExperienceHelperInterface experienceHelper) : base(factory) + public HeroHandler(EntityFactoryInterface factory, EntityFactoryInterface entityFactory, EventBusInterface eventBus, ExperienceHelperInterface experienceHelper) : base(factory, entityFactory) { this.eventBus = eventBus; this.experienceHelper = experienceHelper; diff --git a/Client/Domain/Service/ItemHandler.cs b/Client/Domain/Service/ItemHandler.cs index 3f770e5..d6c28d9 100644 --- a/Client/Domain/Service/ItemHandler.cs +++ b/Client/Domain/Service/ItemHandler.cs @@ -20,7 +20,7 @@ namespace Client.Domain.Service eventBus.Publish(new ItemDeletedEvent(entity.Id)); } - public ItemHander(EntityFactoryInterface factory, EventBusInterface eventBus) : base(factory) + public ItemHander(EntityFactoryInterface factory, EntityFactoryInterface entityFactory, EventBusInterface eventBus) : base(factory, entityFactory) { this.eventBus = eventBus; } diff --git a/Client/Domain/Service/NpcHandler.cs b/Client/Domain/Service/NpcHandler.cs index 419296b..d95b053 100644 --- a/Client/Domain/Service/NpcHandler.cs +++ b/Client/Domain/Service/NpcHandler.cs @@ -33,7 +33,7 @@ namespace Client.Domain.Service @event.Hero.Target = target; } - public NpcHandler(EntityFactoryInterface factory, EventBusInterface eventBus, NpcInfoHelperInterface npcInfoHelper) : base(factory) + public NpcHandler(EntityFactoryInterface factory, EntityFactoryInterface entityFactory, EventBusInterface eventBus, NpcInfoHelperInterface npcInfoHelper) : base(factory, entityFactory) { this.eventBus = eventBus; this.npcInfoHelper = npcInfoHelper; diff --git a/Client/Domain/Service/PlayerHandler.cs b/Client/Domain/Service/PlayerHandler.cs index 1f2e37d..33a8d03 100644 --- a/Client/Domain/Service/PlayerHandler.cs +++ b/Client/Domain/Service/PlayerHandler.cs @@ -20,7 +20,7 @@ namespace Client.Domain.Service eventBus.Publish(new CreatureDeletedEvent(entity.Id)); } - public PlayerHandler(EntityFactoryInterface factory, EventBusInterface eventBus) : base(factory) + public PlayerHandler(EntityFactoryInterface factory, EntityFactoryInterface entityFactory, EventBusInterface eventBus) : base(factory, entityFactory) { this.eventBus = eventBus; } diff --git a/Client/Domain/Service/SkillHandler.cs b/Client/Domain/Service/SkillHandler.cs index c81ad10..13ebb4c 100644 --- a/Client/Domain/Service/SkillHandler.cs +++ b/Client/Domain/Service/SkillHandler.cs @@ -20,7 +20,7 @@ namespace Client.Domain.Service eventBus.Publish(new SkillDeletedEvent(entity.Id)); } - public SkillHandler(EntityFactoryInterface factory, EventBusInterface eventBus) : base(factory) + public SkillHandler(EntityFactoryInterface factory, EntityFactoryInterface entityFactory, EventBusInterface eventBus) : base(factory, entityFactory) { this.eventBus = eventBus; }