refactor: move event disptacher into service locator
This commit is contained in:
parent
b948273172
commit
ede55a870e
@ -9,5 +9,6 @@ namespace L2Bot::Domain::Repositories
|
|||||||
public:
|
public:
|
||||||
virtual const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() = 0;
|
virtual const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() = 0;
|
||||||
virtual void Reset() = 0;
|
virtual void Reset() = 0;
|
||||||
|
virtual void Init() {};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,15 @@ namespace L2Bot::Domain::Services
|
|||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
|
m_DropRepository.Init();
|
||||||
|
m_HeroRepository.Init();
|
||||||
|
m_NPCRepository.Init();
|
||||||
|
m_PlayerRepository.Init();
|
||||||
|
m_SkillRepository.Init();
|
||||||
|
m_ItemRepository.Init();
|
||||||
|
m_AbnormalEffectRepository.Init();
|
||||||
|
m_ChatMessageRepository.Init();
|
||||||
|
|
||||||
m_ConnectingThread = std::thread(&WorldHandler::Connect, this);
|
m_ConnectingThread = std::thread(&WorldHandler::Connect, this);
|
||||||
m_SendingThread = std::thread(&WorldHandler::Send, this);
|
m_SendingThread = std::thread(&WorldHandler::Send, this);
|
||||||
m_ReceivingThread = std::thread(&WorldHandler::Receive, this);
|
m_ReceivingThread = std::thread(&WorldHandler::Receive, this);
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
#include "Serializers/JsonIncomingMessageFactory.h"
|
#include "Serializers/JsonIncomingMessageFactory.h"
|
||||||
#include "Transports/NamedPipeTransport.h"
|
#include "Transports/NamedPipeTransport.h"
|
||||||
#include "Versions/VersionAbstractFactory.h"
|
#include "Versions/VersionAbstractFactory.h"
|
||||||
|
#include "Services/ServiceLocator.h"
|
||||||
|
#include "Events/HeroDeletedEvent.h"
|
||||||
|
|
||||||
using namespace L2Bot::Domain;
|
using namespace L2Bot::Domain;
|
||||||
|
|
||||||
@ -33,20 +35,13 @@ public:
|
|||||||
m_Transport
|
m_Transport
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
Application() = delete;
|
Application() = delete;
|
||||||
virtual ~Application() = default;
|
virtual ~Application() = default;
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
HMODULE hEngine = GetModuleHandleA("Engine.dll");
|
Init();
|
||||||
HMODULE hCore = GetModuleHandleA("Core.dll");
|
|
||||||
|
|
||||||
m_AbstractFactory.GetNetworkHandler().Init(hEngine);
|
|
||||||
m_AbstractFactory.GetGameEngine().Init(hEngine);
|
|
||||||
m_AbstractFactory.GetL2GameData().Init(hEngine);
|
|
||||||
m_AbstractFactory.GetFName().Init(hCore);
|
|
||||||
m_WorldHandler.Start();
|
m_WorldHandler.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +53,20 @@ public:
|
|||||||
m_AbstractFactory.GetNetworkHandler().Restore();
|
m_AbstractFactory.GetNetworkHandler().Restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Init()
|
||||||
|
{
|
||||||
|
ServiceLocator::GetInstance().SetEventDispatcher(std::make_unique<EventDispatcher>());
|
||||||
|
|
||||||
|
HMODULE hEngine = GetModuleHandleA("Engine.dll");
|
||||||
|
HMODULE hCore = GetModuleHandleA("Core.dll");
|
||||||
|
|
||||||
|
m_AbstractFactory.GetNetworkHandler().Init(hEngine);
|
||||||
|
m_AbstractFactory.GetGameEngine().Init(hEngine);
|
||||||
|
m_AbstractFactory.GetL2GameData().Init(hEngine);
|
||||||
|
m_AbstractFactory.GetFName().Init(hCore);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const VersionAbstractFactory& m_AbstractFactory;
|
const VersionAbstractFactory& m_AbstractFactory;
|
||||||
Services::WorldHandler m_WorldHandler;
|
Services::WorldHandler m_WorldHandler;
|
||||||
|
@ -11,10 +11,8 @@ class EventDispatcher
|
|||||||
public:
|
public:
|
||||||
using Delegate = std::function<void(const Event&)>;
|
using Delegate = std::function<void(const Event&)>;
|
||||||
|
|
||||||
static EventDispatcher& GetInstance() {
|
EventDispatcher() = default;
|
||||||
static EventDispatcher instance;
|
virtual ~EventDispatcher() = default;
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Dispatch(const Event& evt)
|
void Dispatch(const Event& evt)
|
||||||
{
|
{
|
||||||
@ -36,12 +34,6 @@ public:
|
|||||||
m_Handlers[eventName].push_back(handler);
|
m_Handlers[eventName].push_back(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
EventDispatcher() = default;
|
|
||||||
virtual ~EventDispatcher() = default;
|
|
||||||
EventDispatcher(const EventDispatcher&) = delete;
|
|
||||||
EventDispatcher& operator=(const EventDispatcher&) = delete;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, std::vector<Delegate>> m_Handlers;
|
std::unordered_map<std::string, std::vector<Delegate>> m_Handlers;
|
||||||
};
|
};
|
@ -186,6 +186,7 @@
|
|||||||
<ClInclude Include="Application.h" />
|
<ClInclude Include="Application.h" />
|
||||||
<ClInclude Include="Serializers\JsonIncomingMessageFactory.h" />
|
<ClInclude Include="Serializers\JsonIncomingMessageFactory.h" />
|
||||||
<ClInclude Include="Serializers\JsonSerializer.h" />
|
<ClInclude Include="Serializers\JsonSerializer.h" />
|
||||||
|
<ClInclude Include="Services\ServiceLocator.h" />
|
||||||
<ClInclude Include="Versions\Interlude\Services\HeroService.h" />
|
<ClInclude Include="Versions\Interlude\Services\HeroService.h" />
|
||||||
<ClInclude Include="ThirdParty\json.hpp" />
|
<ClInclude Include="ThirdParty\json.hpp" />
|
||||||
<ClInclude Include="Versions\GameStructs\FNameInterface.h" />
|
<ClInclude Include="Versions\GameStructs\FNameInterface.h" />
|
||||||
|
@ -204,6 +204,9 @@
|
|||||||
<ClInclude Include="Versions\Interlude\Services\HeroService.h">
|
<ClInclude Include="Versions\Interlude\Services\HeroService.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Services\ServiceLocator.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="dllmain.cpp">
|
<ClCompile Include="dllmain.cpp">
|
||||||
|
30
L2BotDll/Services/ServiceLocator.h
Normal file
30
L2BotDll/Services/ServiceLocator.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include "../Events/EventDispatcher.h"
|
||||||
|
|
||||||
|
class ServiceLocator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ServiceLocator& GetInstance() {
|
||||||
|
static ServiceLocator instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::unique_ptr<EventDispatcher>& GetEventDispatcher()
|
||||||
|
{
|
||||||
|
return m_EventDispatcher;
|
||||||
|
}
|
||||||
|
void SetEventDispatcher(std::unique_ptr<EventDispatcher> dispatcher)
|
||||||
|
{
|
||||||
|
m_EventDispatcher = std::move(dispatcher);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
ServiceLocator() = default;
|
||||||
|
virtual ~ServiceLocator() = default;
|
||||||
|
|
||||||
|
ServiceLocator(const ServiceLocator&) = delete;
|
||||||
|
ServiceLocator& operator=(const ServiceLocator&) = delete;
|
||||||
|
private:
|
||||||
|
std::unique_ptr<EventDispatcher> m_EventDispatcher;
|
||||||
|
};
|
@ -7,7 +7,6 @@
|
|||||||
#include "../../../Events/SkillUsedEvent.h"
|
#include "../../../Events/SkillUsedEvent.h"
|
||||||
#include "../../../Events/SkillCancelledEvent.h"
|
#include "../../../Events/SkillCancelledEvent.h"
|
||||||
#include "../../../Events/AbnormalEffectChangedEvent.h"
|
#include "../../../Events/AbnormalEffectChangedEvent.h"
|
||||||
#include "../../../Events/EventDispatcher.h"
|
|
||||||
#include "../../../Events/ItemCreatedEvent.h"
|
#include "../../../Events/ItemCreatedEvent.h"
|
||||||
#include "../../../Events/ItemUpdatedEvent.h"
|
#include "../../../Events/ItemUpdatedEvent.h"
|
||||||
#include "../../../Events/ItemDeletedEvent.h"
|
#include "../../../Events/ItemDeletedEvent.h"
|
||||||
@ -18,6 +17,7 @@
|
|||||||
#include "../../../Events/CreatureDiedEvent.h"
|
#include "../../../Events/CreatureDiedEvent.h"
|
||||||
#include "../../../DTO/ItemData.h"
|
#include "../../../DTO/ItemData.h"
|
||||||
#include "FName.h"
|
#include "FName.h"
|
||||||
|
#include "../../../Services/ServiceLocator.h"
|
||||||
|
|
||||||
namespace Interlude
|
namespace Interlude
|
||||||
{
|
{
|
||||||
@ -94,31 +94,31 @@ namespace Interlude
|
|||||||
|
|
||||||
void __fastcall GameEngineWrapper::__OnSkillListPacket_hook(GameEngine* This, uint32_t, L2ParamStack& stack)
|
void __fastcall GameEngineWrapper::__OnSkillListPacket_hook(GameEngine* This, uint32_t, L2ParamStack& stack)
|
||||||
{
|
{
|
||||||
EventDispatcher::GetInstance().Dispatch(SkillCreatedEvent{stack.GetBufferAsVector<int32_t>()});
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(SkillCreatedEvent{stack.GetBufferAsVector<int32_t>()});
|
||||||
(*__OnSkillListPacket)(This, stack);
|
(*__OnSkillListPacket)(This, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
int __fastcall GameEngineWrapper::__OnReceiveMagicSkillUse_hook(GameEngine* This, uint32_t, User* u1, User* u2, L2ParamStack& stack)
|
int __fastcall GameEngineWrapper::__OnReceiveMagicSkillUse_hook(GameEngine* This, uint32_t, User* u1, User* u2, L2ParamStack& stack)
|
||||||
{
|
{
|
||||||
EventDispatcher::GetInstance().Dispatch(SkillUsedEvent{ stack.GetBufferAsVector<int32_t>() });
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(SkillUsedEvent{ stack.GetBufferAsVector<int32_t>() });
|
||||||
return (*__OnReceiveMagicSkillUse)(This, u1, u2, stack);
|
return (*__OnReceiveMagicSkillUse)(This, u1, u2, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __fastcall GameEngineWrapper::__OnReceiveMagicSkillCanceled_hook(GameEngine* This, uint32_t, User* user)
|
void __fastcall GameEngineWrapper::__OnReceiveMagicSkillCanceled_hook(GameEngine* This, uint32_t, User* user)
|
||||||
{
|
{
|
||||||
EventDispatcher::GetInstance().Dispatch(SkillCancelledEvent{ user->objectId });
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(SkillCancelledEvent{ user->objectId });
|
||||||
(*__OnReceiveMagicSkillCanceled)(This, user);
|
(*__OnReceiveMagicSkillCanceled)(This, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __fastcall GameEngineWrapper::__AddAbnormalStatus_hook(GameEngine* This, uint32_t, L2ParamStack& stack)
|
void __fastcall GameEngineWrapper::__AddAbnormalStatus_hook(GameEngine* This, uint32_t, L2ParamStack& stack)
|
||||||
{
|
{
|
||||||
EventDispatcher::GetInstance().Dispatch(AbnormalEffectChangedEvent{ stack.GetBufferAsVector<int32_t>(3) });
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(AbnormalEffectChangedEvent{ stack.GetBufferAsVector<int32_t>(3) });
|
||||||
(*__AddAbnormalStatus)(This, stack);
|
(*__AddAbnormalStatus)(This, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __fastcall GameEngineWrapper::__AddInventoryItem_hook(GameEngine* This, uint32_t, ItemInfo& itemInfo)
|
void __fastcall GameEngineWrapper::__AddInventoryItem_hook(GameEngine* This, uint32_t, ItemInfo& itemInfo)
|
||||||
{
|
{
|
||||||
EventDispatcher::GetInstance().Dispatch(
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(
|
||||||
ItemCreatedEvent
|
ItemCreatedEvent
|
||||||
{
|
{
|
||||||
ItemData
|
ItemData
|
||||||
@ -154,13 +154,13 @@ namespace Interlude
|
|||||||
switch (actionType)
|
switch (actionType)
|
||||||
{
|
{
|
||||||
case UpdateItemListActionType::created:
|
case UpdateItemListActionType::created:
|
||||||
EventDispatcher::GetInstance().Dispatch(ItemCreatedEvent{ itemData });
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(ItemCreatedEvent{ itemData });
|
||||||
break;
|
break;
|
||||||
case UpdateItemListActionType::updated:
|
case UpdateItemListActionType::updated:
|
||||||
EventDispatcher::GetInstance().Dispatch(ItemUpdatedEvent{ itemData });
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(ItemUpdatedEvent{ itemData });
|
||||||
break;
|
break;
|
||||||
case UpdateItemListActionType::deleted:
|
case UpdateItemListActionType::deleted:
|
||||||
EventDispatcher::GetInstance().Dispatch(ItemDeletedEvent{ itemInfo.objectId });
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(ItemDeletedEvent{ itemInfo.objectId });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
(*__OnReceiveUpdateItemList)(This, actionType, itemInfo);
|
(*__OnReceiveUpdateItemList)(This, actionType, itemInfo);
|
||||||
@ -168,7 +168,7 @@ namespace Interlude
|
|||||||
|
|
||||||
void __fastcall GameEngineWrapper::__OnExAutoSoulShot_hook(GameEngine* This, uint32_t, L2ParamStack& stack)
|
void __fastcall GameEngineWrapper::__OnExAutoSoulShot_hook(GameEngine* This, uint32_t, L2ParamStack& stack)
|
||||||
{
|
{
|
||||||
EventDispatcher::GetInstance().Dispatch(ItemAutousedEvent{ stack.GetBufferAsVector<uint32_t>() });
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(ItemAutousedEvent{ stack.GetBufferAsVector<uint32_t>() });
|
||||||
(*__OnExAutoSoulShot)(This, stack);
|
(*__OnExAutoSoulShot)(This, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,13 +181,13 @@ namespace Interlude
|
|||||||
|
|
||||||
(*__Tick)(This, deltaTime);
|
(*__Tick)(This, deltaTime);
|
||||||
|
|
||||||
EventDispatcher::GetInstance().Dispatch(GameEngineTickedEvent{});
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(GameEngineTickedEvent{});
|
||||||
}
|
}
|
||||||
void __fastcall GameEngineWrapper::__OnSay2_hook(GameEngine* This, uint32_t, L2ParamStack& stack)
|
void __fastcall GameEngineWrapper::__OnSay2_hook(GameEngine* This, uint32_t, L2ParamStack& stack)
|
||||||
{
|
{
|
||||||
const auto buffer = stack.GetBufferAsVector<uint32_t>();
|
const auto buffer = stack.GetBufferAsVector<uint32_t>();
|
||||||
|
|
||||||
EventDispatcher::GetInstance().Dispatch(
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(
|
||||||
ChatMessageCreatedEvent
|
ChatMessageCreatedEvent
|
||||||
{
|
{
|
||||||
ChatMessage
|
ChatMessage
|
||||||
@ -204,7 +204,7 @@ namespace Interlude
|
|||||||
}
|
}
|
||||||
void __fastcall GameEngineWrapper::__OnEndItemList_hook(GameEngine* This, uint32_t)
|
void __fastcall GameEngineWrapper::__OnEndItemList_hook(GameEngine* This, uint32_t)
|
||||||
{
|
{
|
||||||
EventDispatcher::GetInstance().Dispatch(OnEndItemListEvent());
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(OnEndItemListEvent());
|
||||||
(*__OnEndItemList)(This);
|
(*__OnEndItemList)(This);
|
||||||
}
|
}
|
||||||
// TODO ini
|
// TODO ini
|
||||||
@ -217,7 +217,7 @@ namespace Interlude
|
|||||||
|
|
||||||
int __fastcall GameEngineWrapper::__OnDie_hook(GameEngine* This, int, User* creature, L2ParamStack& stack)
|
int __fastcall GameEngineWrapper::__OnDie_hook(GameEngine* This, int, User* creature, L2ParamStack& stack)
|
||||||
{
|
{
|
||||||
EventDispatcher::GetInstance().Dispatch(CreatureDiedEvent{ creature->objectId, stack.GetBufferAsVector<int32_t>() });
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(CreatureDiedEvent{ creature->objectId, stack.GetBufferAsVector<int32_t>() });
|
||||||
|
|
||||||
return (*__OnDie)(This, creature, stack);
|
return (*__OnDie)(This, creature, stack);
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
#include "../../../Common/apihook.h"
|
#include "../../../Common/apihook.h"
|
||||||
#include "NetworkHandlerWrapper.h"
|
#include "NetworkHandlerWrapper.h"
|
||||||
#include "../../../Events/SpoiledEvent.h"
|
#include "../../../Events/SpoiledEvent.h"
|
||||||
#include "../../../Events/EventDispatcher.h"
|
|
||||||
#include "ProcessManipulation.h"
|
#include "ProcessManipulation.h"
|
||||||
|
#include "../../../Services/ServiceLocator.h"
|
||||||
|
|
||||||
namespace Interlude
|
namespace Interlude
|
||||||
{
|
{
|
||||||
@ -176,7 +176,7 @@ namespace Interlude
|
|||||||
p->GetMessageId() == static_cast<int>(L2::SystemMessagePacket::Type::SPOIL_SUCCESS) ||
|
p->GetMessageId() == static_cast<int>(L2::SystemMessagePacket::Type::SPOIL_SUCCESS) ||
|
||||||
p->GetMessageId() == static_cast<int>(L2::SystemMessagePacket::Type::ALREADY_SPOILED)
|
p->GetMessageId() == static_cast<int>(L2::SystemMessagePacket::Type::ALREADY_SPOILED)
|
||||||
) {
|
) {
|
||||||
EventDispatcher::GetInstance().Dispatch(SpoiledEvent{});
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(SpoiledEvent{});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
#include "../Factories/AbnormalEffectFactory.h"
|
#include "../Factories/AbnormalEffectFactory.h"
|
||||||
#include "../../../Events/AbnormalEffectChangedEvent.h"
|
#include "../../../Events/AbnormalEffectChangedEvent.h"
|
||||||
#include "../../../Events/HeroDeletedEvent.h"
|
#include "../../../Events/HeroDeletedEvent.h"
|
||||||
#include "../../../Events/EventDispatcher.h"
|
|
||||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||||
|
#include "../../../Services/ServiceLocator.h"
|
||||||
|
|
||||||
using namespace L2Bot::Domain;
|
using namespace L2Bot::Domain;
|
||||||
|
|
||||||
@ -27,12 +27,6 @@ namespace Interlude
|
|||||||
AbnormalEffectRepository(const AbnormalEffectFactory& factory) :
|
AbnormalEffectRepository(const AbnormalEffectFactory& factory) :
|
||||||
m_Factory(factory)
|
m_Factory(factory)
|
||||||
{
|
{
|
||||||
EventDispatcher::GetInstance().Subscribe(AbnormalEffectChangedEvent::name, [this](const Event& evt) {
|
|
||||||
OnEffectToggled(evt);
|
|
||||||
});
|
|
||||||
EventDispatcher::GetInstance().Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
|
|
||||||
OnHeroDeleted(evt);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AbnormalEffectRepository() = delete;
|
AbnormalEffectRepository() = delete;
|
||||||
@ -41,6 +35,16 @@ namespace Interlude
|
|||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Init() override
|
||||||
|
{
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(AbnormalEffectChangedEvent::name, [this](const Event& evt) {
|
||||||
|
OnEffectToggled(evt);
|
||||||
|
});
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
|
||||||
|
OnHeroDeleted(evt);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void Reset() override
|
void Reset() override
|
||||||
{
|
{
|
||||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
#include "../Factories/ChatMessageFactory.h"
|
#include "../Factories/ChatMessageFactory.h"
|
||||||
#include "../../../Events/ChatMessageCreatedEvent.h"
|
#include "../../../Events/ChatMessageCreatedEvent.h"
|
||||||
#include "../../../Events/EventDispatcher.h"
|
#include "../../../Services/ServiceLocator.h"
|
||||||
|
|
||||||
using namespace L2Bot::Domain;
|
using namespace L2Bot::Domain;
|
||||||
|
|
||||||
@ -20,18 +20,22 @@ namespace Interlude
|
|||||||
return m_Messages;
|
return m_Messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reset()
|
void Reset() override
|
||||||
{
|
{
|
||||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||||
m_Messages.clear();
|
m_Messages.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Init() override
|
||||||
|
{
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(ChatMessageCreatedEvent::name, [this](const Event& evt) {
|
||||||
|
OnMessageCreated(evt);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ChatMessageRepository(const ChatMessageFactory& factory) :
|
ChatMessageRepository(const ChatMessageFactory& factory) :
|
||||||
m_Factory(factory)
|
m_Factory(factory)
|
||||||
{
|
{
|
||||||
EventDispatcher::GetInstance().Subscribe(ChatMessageCreatedEvent::name, [this](const Event& evt) {
|
|
||||||
OnMessageCreated(evt);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMessageCreated(const Event& evt)
|
void OnMessageCreated(const Event& evt)
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||||
#include "../Factories/HeroFactory.h"
|
#include "../Factories/HeroFactory.h"
|
||||||
#include "../../../Events/EventDispatcher.h"
|
|
||||||
#include "../../../Events/HeroCreatedEvent.h"
|
#include "../../../Events/HeroCreatedEvent.h"
|
||||||
#include "../../../Events/HeroDeletedEvent.h"
|
#include "../../../Events/HeroDeletedEvent.h"
|
||||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||||
|
#include "../../../Services/ServiceLocator.h"
|
||||||
|
|
||||||
using namespace L2Bot::Domain;
|
using namespace L2Bot::Domain;
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ namespace Interlude
|
|||||||
if (hero) {
|
if (hero) {
|
||||||
if (!m_Hero) {
|
if (!m_Hero) {
|
||||||
m_Hero = m_Factory.Create(hero);
|
m_Hero = m_Factory.Create(hero);
|
||||||
EventDispatcher::GetInstance().Dispatch(HeroCreatedEvent{});
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(HeroCreatedEvent{});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -35,7 +35,7 @@ namespace Interlude
|
|||||||
}
|
}
|
||||||
else if (m_Hero) {
|
else if (m_Hero) {
|
||||||
m_Hero = nullptr;
|
m_Hero = nullptr;
|
||||||
EventDispatcher::GetInstance().Dispatch(HeroDeletedEvent{});
|
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(HeroDeletedEvent{});
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include "../../../Events/HeroDeletedEvent.h"
|
#include "../../../Events/HeroDeletedEvent.h"
|
||||||
#include "../../../Events/ItemAutousedEvent.h"
|
#include "../../../Events/ItemAutousedEvent.h"
|
||||||
#include "../../../Events/OnEndItemListEvent.h"
|
#include "../../../Events/OnEndItemListEvent.h"
|
||||||
#include "../../../Events/EventDispatcher.h"
|
#include "../../../Services/ServiceLocator.h"
|
||||||
|
|
||||||
using namespace L2Bot::Domain;
|
using namespace L2Bot::Domain;
|
||||||
|
|
||||||
@ -44,24 +44,6 @@ namespace Interlude
|
|||||||
m_NetworkHandler(networkHandler),
|
m_NetworkHandler(networkHandler),
|
||||||
m_Factory(factory)
|
m_Factory(factory)
|
||||||
{
|
{
|
||||||
EventDispatcher::GetInstance().Subscribe(ItemCreatedEvent::name, [this](const Event& evt) {
|
|
||||||
OnItemCreated(evt);
|
|
||||||
});
|
|
||||||
EventDispatcher::GetInstance().Subscribe(ItemUpdatedEvent::name, [this](const Event& evt) {
|
|
||||||
OnItemUpdated(evt);
|
|
||||||
});
|
|
||||||
EventDispatcher::GetInstance().Subscribe(ItemDeletedEvent::name, [this](const Event& evt) {
|
|
||||||
OnItemDeleted(evt);
|
|
||||||
});
|
|
||||||
EventDispatcher::GetInstance().Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
|
|
||||||
OnHeroDeleted(evt);
|
|
||||||
});
|
|
||||||
EventDispatcher::GetInstance().Subscribe(ItemAutousedEvent::name, [this](const Event& evt) {
|
|
||||||
OnItemAutoused(evt);
|
|
||||||
});
|
|
||||||
EventDispatcher::GetInstance().Subscribe(OnEndItemListEvent::name, [this](const Event& evt) {
|
|
||||||
OnEndItemList(evt);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnEndItemList(const Event& evt)
|
void OnEndItemList(const Event& evt)
|
||||||
@ -198,6 +180,28 @@ namespace Interlude
|
|||||||
m_NetworkHandler.RequestItemList();
|
m_NetworkHandler.RequestItemList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Init() override
|
||||||
|
{
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(ItemCreatedEvent::name, [this](const Event& evt) {
|
||||||
|
OnItemCreated(evt);
|
||||||
|
});
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(ItemUpdatedEvent::name, [this](const Event& evt) {
|
||||||
|
OnItemUpdated(evt);
|
||||||
|
});
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(ItemDeletedEvent::name, [this](const Event& evt) {
|
||||||
|
OnItemDeleted(evt);
|
||||||
|
});
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
|
||||||
|
OnHeroDeleted(evt);
|
||||||
|
});
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(ItemAutousedEvent::name, [this](const Event& evt) {
|
||||||
|
OnItemAutoused(evt);
|
||||||
|
});
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(OnEndItemListEvent::name, [this](const Event& evt) {
|
||||||
|
OnEndItemList(evt);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const ItemFactory& m_Factory;
|
const ItemFactory& m_Factory;
|
||||||
std::unordered_map<std::uint32_t, std::shared_ptr<Entities::BaseItem>> m_Items;
|
std::unordered_map<std::uint32_t, std::shared_ptr<Entities::BaseItem>> m_Items;
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||||
#include "../Factories/NPCFactory.h"
|
#include "../Factories/NPCFactory.h"
|
||||||
#include "../../../Events/EventDispatcher.h"
|
|
||||||
#include "../../../Events/SpoiledEvent.h"
|
#include "../../../Events/SpoiledEvent.h"
|
||||||
#include "../../../Events/CreatureDiedEvent.h"
|
#include "../../../Events/CreatureDiedEvent.h"
|
||||||
#include "../../GameStructs/FindObjectsTrait.h"
|
#include "../../GameStructs/FindObjectsTrait.h"
|
||||||
|
#include "../../../Services/ServiceLocator.h"
|
||||||
|
|
||||||
using namespace L2Bot::Domain;
|
using namespace L2Bot::Domain;
|
||||||
|
|
||||||
@ -55,17 +55,21 @@ namespace Interlude
|
|||||||
m_Npcs.clear();
|
m_Npcs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Init() override
|
||||||
|
{
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(SpoiledEvent::name, [this](const Event& evt) {
|
||||||
|
OnSpoiled(evt);
|
||||||
|
});
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(CreatureDiedEvent::name, [this](const Event& evt) {
|
||||||
|
OnCreatureDied(evt);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
NPCRepository(const NetworkHandlerWrapper& networkHandler, const NPCFactory& factory, const uint16_t radius) :
|
NPCRepository(const NetworkHandlerWrapper& networkHandler, const NPCFactory& factory, const uint16_t radius) :
|
||||||
m_NetworkHandler(networkHandler),
|
m_NetworkHandler(networkHandler),
|
||||||
m_Factory(factory),
|
m_Factory(factory),
|
||||||
m_Radius(radius)
|
m_Radius(radius)
|
||||||
{
|
{
|
||||||
EventDispatcher::GetInstance().Subscribe(SpoiledEvent::name, [this](const Event& evt) {
|
|
||||||
OnSpoiled(evt);
|
|
||||||
});
|
|
||||||
EventDispatcher::GetInstance().Subscribe(CreatureDiedEvent::name, [this](const Event& evt) {
|
|
||||||
OnCreatureDied(evt);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NPCRepository() = delete;
|
NPCRepository() = delete;
|
||||||
|
@ -11,9 +11,9 @@
|
|||||||
#include "../../../Events/AbnormalEffectChangedEvent.h"
|
#include "../../../Events/AbnormalEffectChangedEvent.h"
|
||||||
#include "../../../Events/HeroDeletedEvent.h"
|
#include "../../../Events/HeroDeletedEvent.h"
|
||||||
#include "../../../Events/GameEngineTickedEvent.h"
|
#include "../../../Events/GameEngineTickedEvent.h"
|
||||||
#include "../../../Events/EventDispatcher.h"
|
|
||||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||||
#include "../../../Common/TimerMap.h"
|
#include "../../../Common/TimerMap.h"
|
||||||
|
#include "../../../Services/ServiceLocator.h"
|
||||||
|
|
||||||
using namespace L2Bot::Domain;
|
using namespace L2Bot::Domain;
|
||||||
|
|
||||||
@ -34,24 +34,7 @@ namespace Interlude
|
|||||||
m_NetworkHandler(networkHandler),
|
m_NetworkHandler(networkHandler),
|
||||||
m_Factory(factory)
|
m_Factory(factory)
|
||||||
{
|
{
|
||||||
EventDispatcher::GetInstance().Subscribe(SkillCreatedEvent::name, [this](const Event& evt) {
|
|
||||||
OnSkillCreated(evt);
|
|
||||||
});
|
|
||||||
EventDispatcher::GetInstance().Subscribe(SkillUsedEvent::name, [this](const Event& evt) {
|
|
||||||
OnSkillUsed(evt);
|
|
||||||
});
|
|
||||||
EventDispatcher::GetInstance().Subscribe(SkillCancelledEvent::name, [this](const Event& evt) {
|
|
||||||
OnSkillCancelled(evt);
|
|
||||||
});
|
|
||||||
EventDispatcher::GetInstance().Subscribe(AbnormalEffectChangedEvent::name, [this](const Event& evt) {
|
|
||||||
OnSkillToggled(evt);
|
|
||||||
});
|
|
||||||
EventDispatcher::GetInstance().Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
|
|
||||||
OnHeroDeleted(evt);
|
|
||||||
});
|
|
||||||
EventDispatcher::GetInstance().Subscribe(GameEngineTickedEvent::name, [this](const Event& evt) {
|
|
||||||
OnGameEngineTicked(evt);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SkillRepository() = delete;
|
SkillRepository() = delete;
|
||||||
@ -68,6 +51,28 @@ namespace Interlude
|
|||||||
m_NewSkills.clear();
|
m_NewSkills.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Init() override
|
||||||
|
{
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(SkillCreatedEvent::name, [this](const Event& evt) {
|
||||||
|
OnSkillCreated(evt);
|
||||||
|
});
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(SkillUsedEvent::name, [this](const Event& evt) {
|
||||||
|
OnSkillUsed(evt);
|
||||||
|
});
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(SkillCancelledEvent::name, [this](const Event& evt) {
|
||||||
|
OnSkillCancelled(evt);
|
||||||
|
});
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(AbnormalEffectChangedEvent::name, [this](const Event& evt) {
|
||||||
|
OnSkillToggled(evt);
|
||||||
|
});
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
|
||||||
|
OnHeroDeleted(evt);
|
||||||
|
});
|
||||||
|
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(GameEngineTickedEvent::name, [this](const Event& evt) {
|
||||||
|
OnGameEngineTicked(evt);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void OnGameEngineTicked(const Event& evt)
|
void OnGameEngineTicked(const Event& evt)
|
||||||
{
|
{
|
||||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||||
|
Loading…
Reference in New Issue
Block a user