refactor: move events and service locator into core project

This commit is contained in:
k0t9i
2023-10-17 14:16:58 +04:00
parent 9836ef3a17
commit 03e61a9b9a
55 changed files with 825 additions and 760 deletions

View File

@ -1,7 +1,7 @@
#pragma once
#include "Domain/Entities/ChatMessage.h"
#include "../../../DTO/ChatMessage.h"
#include "Domain/DTO/ChatMessageData.h"
using namespace L2Bot::Domain;
@ -13,7 +13,7 @@ namespace Interlude
ChatMessageFactory() = default;
virtual ~ChatMessageFactory() = default;
std::shared_ptr<Entities::ChatMessage> Create(const ChatMessage& message) const
std::shared_ptr<Entities::ChatMessage> Create(const DTO::ChatMessageData& message) const
{
return std::make_shared<Entities::ChatMessage>(
message.objectId,

View File

@ -10,7 +10,7 @@
#include "Domain/Entities/ArmorItem.h"
#include "Domain/Entities/WeaponItem.h"
#include "Domain/Entities/ShieldItem.h"
#include "../../../DTO/ItemData.h"
#include "Domain/DTO/ItemData.h"
#include "../Helpers/EnchantHelper.h"
using namespace L2Bot::Domain;
@ -88,7 +88,7 @@ namespace Interlude
ItemFactory() = delete;
virtual ~ItemFactory() = default;
std::shared_ptr<Entities::BaseItem> Create(const ItemData& itemInfo) const
std::shared_ptr<Entities::BaseItem> Create(const DTO::ItemData& itemInfo) const
{
//FIXME during first start data may be undefined
const auto data = GetItemData(itemInfo.itemId);
@ -109,7 +109,7 @@ namespace Interlude
return nullptr;
}
void Update(std::shared_ptr<Entities::BaseItem>& item, const ItemData& itemInfo) const
void Update(std::shared_ptr<Entities::BaseItem>& item, const DTO::ItemData& itemInfo) const
{
//FIXME during first start data may be undefined
const auto data = GetItemData(itemInfo.itemId);
@ -131,7 +131,7 @@ namespace Interlude
}
private:
std::shared_ptr<Entities::BaseItem> CreateEtc(const ItemData& itemInfo) const
std::shared_ptr<Entities::BaseItem> CreateEtc(const DTO::ItemData& itemInfo) const
{
const auto& data = GetEtcData(itemInfo);
@ -148,7 +148,7 @@ namespace Interlude
);
}
void UpdateEtc(std::shared_ptr<Entities::BaseItem> &item, const ItemData& itemInfo) const
void UpdateEtc(std::shared_ptr<Entities::BaseItem> &item, const DTO::ItemData& itemInfo) const
{
auto etcItem = std::dynamic_pointer_cast<Entities::EtcItem>(item);
@ -166,7 +166,7 @@ namespace Interlude
);
}
std::shared_ptr<Entities::BaseItem> CreateArmor(const ItemData& itemInfo) const
std::shared_ptr<Entities::BaseItem> CreateArmor(const DTO::ItemData& itemInfo) const
{
const auto& data = GetArmorData(itemInfo);
@ -190,7 +190,7 @@ namespace Interlude
);
}
void UpdateArmor(std::shared_ptr<Entities::BaseItem>& item, const ItemData& itemInfo) const
void UpdateArmor(std::shared_ptr<Entities::BaseItem>& item, const DTO::ItemData& itemInfo) const
{
auto armorItem = std::dynamic_pointer_cast<Entities::ArmorItem>(item);
@ -215,7 +215,7 @@ namespace Interlude
);
}
std::shared_ptr<Entities::BaseItem> CreateWeaponOrShield(const ItemData& itemInfo) const
std::shared_ptr<Entities::BaseItem> CreateWeaponOrShield(const DTO::ItemData& itemInfo) const
{
const auto itemData = static_cast<const FL2WeaponItemData*>(GetItemData(itemInfo.itemId));
@ -266,7 +266,7 @@ namespace Interlude
);
}
void UpdateWeaponOrShield(std::shared_ptr<Entities::BaseItem>& item, const ItemData& itemInfo) const
void UpdateWeaponOrShield(std::shared_ptr<Entities::BaseItem>& item, const DTO::ItemData& itemInfo) const
{
const auto itemData = static_cast<const FL2WeaponItemData*>(GetItemData(itemInfo.itemId));
@ -319,7 +319,7 @@ namespace Interlude
);
}
const BaseData GetBaseData(const ItemData& itemInfo) const
const BaseData GetBaseData(const DTO::ItemData& itemInfo) const
{
const auto data = GetItemData(itemInfo.itemId);
@ -340,7 +340,7 @@ namespace Interlude
};
}
const EtcData GetEtcData(const ItemData& itemInfo) const
const EtcData GetEtcData(const DTO::ItemData& itemInfo) const
{
const auto& baseData = GetBaseData(itemInfo);
@ -357,7 +357,7 @@ namespace Interlude
};
}
const ArmorData GetArmorData(const ItemData& itemInfo) const
const ArmorData GetArmorData(const DTO::ItemData& itemInfo) const
{
const auto& baseData = GetBaseData(itemInfo);
@ -387,7 +387,7 @@ namespace Interlude
};
}
const ShieldData GetShieldData(const ItemData& itemInfo, const FL2WeaponItemData* itemData) const
const ShieldData GetShieldData(const DTO::ItemData& itemInfo, const FL2WeaponItemData* itemData) const
{
const auto& baseData = GetBaseData(itemInfo);
@ -408,7 +408,7 @@ namespace Interlude
};
}
const WeaponData GetWeaponData(const ItemData& itemInfo, const FL2WeaponItemData* itemData) const
const WeaponData GetWeaponData(const DTO::ItemData& itemInfo, const FL2WeaponItemData* itemData) const
{
const auto& baseData = GetBaseData(itemInfo);

View File

@ -3,21 +3,24 @@
#include "../../../Common/Common.h"
#include "GameEngineWrapper.h"
#include "ProcessManipulation.h"
#include "../../../Events/SkillCreatedEvent.h"
#include "../../../Events/SkillUsedEvent.h"
#include "../../../Events/SkillCancelledEvent.h"
#include "../../../Events/AbnormalEffectChangedEvent.h"
#include "../../../Events/ItemCreatedEvent.h"
#include "../../../Events/ItemUpdatedEvent.h"
#include "../../../Events/ItemDeletedEvent.h"
#include "../../../Events/ItemAutousedEvent.h"
#include "../../../Events/GameEngineTickedEvent.h"
#include "../../../Events/ChatMessageCreatedEvent.h"
#include "../../../Events/OnEndItemListEvent.h"
#include "../../../Events/CreatureDiedEvent.h"
#include "../../../DTO/ItemData.h"
#include "Domain/Events/SkillCreatedEvent.h"
#include "Domain/Events/SkillUsedEvent.h"
#include "Domain/Events/SkillCancelledEvent.h"
#include "Domain/Events/AbnormalEffectChangedEvent.h"
#include "Domain/Events/ItemCreatedEvent.h"
#include "Domain/Events/ItemUpdatedEvent.h"
#include "Domain/Events/ItemDeletedEvent.h"
#include "Domain/Events/ItemAutousedEvent.h"
#include "Domain/Events/GameEngineTickedEvent.h"
#include "Domain/Events/ChatMessageCreatedEvent.h"
#include "Domain/Events/OnEndItemListEvent.h"
#include "Domain/Events/CreatureDiedEvent.h"
#include "Domain/DTO/ItemData.h"
#include "Domain/DTO/ChatMessageData.h"
#include "FName.h"
#include "../../../Services/ServiceLocator.h"
#include "Domain/Services/ServiceLocator.h"
using namespace L2Bot::Domain;
namespace Interlude
{
@ -94,34 +97,34 @@ namespace Interlude
void __fastcall GameEngineWrapper::__OnSkillListPacket_hook(GameEngine* This, uint32_t, L2ParamStack& stack)
{
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(SkillCreatedEvent{stack.GetBufferAsVector<int32_t>()});
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::SkillCreatedEvent{stack.GetBufferAsVector<int32_t>()});
(*__OnSkillListPacket)(This, stack);
}
int __fastcall GameEngineWrapper::__OnReceiveMagicSkillUse_hook(GameEngine* This, uint32_t, User* u1, User* u2, L2ParamStack& stack)
{
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(SkillUsedEvent{ stack.GetBufferAsVector<int32_t>() });
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::SkillUsedEvent{ stack.GetBufferAsVector<int32_t>() });
return (*__OnReceiveMagicSkillUse)(This, u1, u2, stack);
}
void __fastcall GameEngineWrapper::__OnReceiveMagicSkillCanceled_hook(GameEngine* This, uint32_t, User* user)
{
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(SkillCancelledEvent{ user->objectId });
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::SkillCancelledEvent{ user->objectId });
(*__OnReceiveMagicSkillCanceled)(This, user);
}
void __fastcall GameEngineWrapper::__AddAbnormalStatus_hook(GameEngine* This, uint32_t, L2ParamStack& stack)
{
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(AbnormalEffectChangedEvent{ stack.GetBufferAsVector<int32_t>(3) });
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::AbnormalEffectChangedEvent{ stack.GetBufferAsVector<int32_t>(3) });
(*__AddAbnormalStatus)(This, stack);
}
void __fastcall GameEngineWrapper::__AddInventoryItem_hook(GameEngine* This, uint32_t, ItemInfo& itemInfo)
{
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(
ItemCreatedEvent
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(
Events::ItemCreatedEvent
{
ItemData
DTO::ItemData
{
itemInfo.objectId,
itemInfo.itemId,
@ -139,7 +142,7 @@ namespace Interlude
void __fastcall GameEngineWrapper::__OnReceiveUpdateItemList_hook(GameEngine* This, uint32_t, UpdateItemListActionType actionType, ItemInfo& itemInfo)
{
const ItemData itemData
const DTO::ItemData itemData
{
itemInfo.objectId,
itemInfo.itemId,
@ -154,13 +157,13 @@ namespace Interlude
switch (actionType)
{
case UpdateItemListActionType::created:
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(ItemCreatedEvent{ itemData });
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::ItemCreatedEvent{ itemData });
break;
case UpdateItemListActionType::updated:
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(ItemUpdatedEvent{ itemData });
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::ItemUpdatedEvent{ itemData });
break;
case UpdateItemListActionType::deleted:
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(ItemDeletedEvent{ itemInfo.objectId });
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::ItemDeletedEvent{ itemInfo.objectId });
break;
}
(*__OnReceiveUpdateItemList)(This, actionType, itemInfo);
@ -168,7 +171,7 @@ namespace Interlude
void __fastcall GameEngineWrapper::__OnExAutoSoulShot_hook(GameEngine* This, uint32_t, L2ParamStack& stack)
{
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(ItemAutousedEvent{ stack.GetBufferAsVector<uint32_t>() });
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::ItemAutousedEvent{ stack.GetBufferAsVector<uint32_t>() });
(*__OnExAutoSoulShot)(This, stack);
}
@ -181,16 +184,16 @@ namespace Interlude
(*__Tick)(This, deltaTime);
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(GameEngineTickedEvent{});
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::GameEngineTickedEvent{});
}
void __fastcall GameEngineWrapper::__OnSay2_hook(GameEngine* This, uint32_t, L2ParamStack& stack)
{
const auto buffer = stack.GetBufferAsVector<uint32_t>();
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(
ChatMessageCreatedEvent
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(
Events::ChatMessageCreatedEvent
{
ChatMessage
DTO::ChatMessageData
{
buffer[0],
static_cast<uint8_t>(buffer[1]),
@ -204,7 +207,7 @@ namespace Interlude
}
void __fastcall GameEngineWrapper::__OnEndItemList_hook(GameEngine* This, uint32_t)
{
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(OnEndItemListEvent());
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::OnEndItemListEvent());
(*__OnEndItemList)(This);
}
// TODO ini
@ -217,7 +220,7 @@ namespace Interlude
int __fastcall GameEngineWrapper::__OnDie_hook(GameEngine* This, int, User* creature, L2ParamStack& stack)
{
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(CreatureDiedEvent{ creature->objectId, stack.GetBufferAsVector<int32_t>() });
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::CreatureDiedEvent{ creature->objectId, stack.GetBufferAsVector<int32_t>() });
return (*__OnDie)(This, creature, stack);
}

View File

@ -1,9 +1,11 @@
#include "pch.h"
#include "../../../Common/apihook.h"
#include "NetworkHandlerWrapper.h"
#include "../../../Events/SpoiledEvent.h"
#include "Domain/Events/SpoiledEvent.h"
#include "ProcessManipulation.h"
#include "../../../Services/ServiceLocator.h"
#include "Domain/Services/ServiceLocator.h"
using namespace L2Bot::Domain;
namespace Interlude
{
@ -176,7 +178,7 @@ namespace Interlude
p->GetMessageId() == static_cast<int>(L2::SystemMessagePacket::Type::SPOIL_SUCCESS) ||
p->GetMessageId() == static_cast<int>(L2::SystemMessagePacket::Type::ALREADY_SPOILED)
) {
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(SpoiledEvent{});
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::SpoiledEvent{});
}
}

View File

@ -5,10 +5,10 @@
#include <shared_mutex>
#include "Domain/Repositories/EntityRepositoryInterface.h"
#include "../Factories/AbnormalEffectFactory.h"
#include "../../../Events/AbnormalEffectChangedEvent.h"
#include "../../../Events/HeroDeletedEvent.h"
#include "Domain/Events/AbnormalEffectChangedEvent.h"
#include "Domain/Events/HeroDeletedEvent.h"
#include "../GameStructs/NetworkHandlerWrapper.h"
#include "../../../Services/ServiceLocator.h"
#include "Domain/Services/ServiceLocator.h"
using namespace L2Bot::Domain;
@ -37,10 +37,10 @@ namespace Interlude
void Init() override
{
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(AbnormalEffectChangedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::AbnormalEffectChangedEvent::name, [this](const Events::Event& evt) {
OnEffectToggled(evt);
});
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::HeroDeletedEvent::name, [this](const Events::Event& evt) {
OnHeroDeleted(evt);
});
}
@ -51,21 +51,21 @@ namespace Interlude
m_Effects.clear();
}
void OnHeroDeleted(const Event& evt)
void OnHeroDeleted(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == HeroDeletedEvent::name)
if (evt.GetName() == Events::HeroDeletedEvent::name)
{
Reset();
}
}
void OnEffectToggled(const Event& evt)
void OnEffectToggled(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == AbnormalEffectChangedEvent::name)
if (evt.GetName() == Events::AbnormalEffectChangedEvent::name)
{
const auto casted = static_cast<const AbnormalEffectChangedEvent&>(evt);
const auto casted = static_cast<const Events::AbnormalEffectChangedEvent&>(evt);
const auto &actualIds = Create(casted.GetSkillInfo());
Delete(actualIds);

View File

@ -3,8 +3,8 @@
#include <vector>
#include <shared_mutex>
#include "../Factories/ChatMessageFactory.h"
#include "../../../Events/ChatMessageCreatedEvent.h"
#include "../../../Services/ServiceLocator.h"
#include "Domain/Events/ChatMessageCreatedEvent.h"
#include "Domain/Services/ServiceLocator.h"
using namespace L2Bot::Domain;
@ -28,7 +28,7 @@ namespace Interlude
void Init() override
{
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(ChatMessageCreatedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::ChatMessageCreatedEvent::name, [this](const Events::Event& evt) {
OnMessageCreated(evt);
});
}
@ -38,12 +38,12 @@ namespace Interlude
{
}
void OnMessageCreated(const Event& evt)
void OnMessageCreated(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == ChatMessageCreatedEvent::name)
if (evt.GetName() == Events::ChatMessageCreatedEvent::name)
{
const auto casted = static_cast<const ChatMessageCreatedEvent&>(evt);
const auto casted = static_cast<const Events::ChatMessageCreatedEvent&>(evt);
const auto message = m_Factory.Create(casted.GetChatMessage());
m_Messages[message->GetId()] = message;

View File

@ -3,10 +3,10 @@
#include <shared_mutex>
#include "Domain/Repositories/EntityRepositoryInterface.h"
#include "../Factories/HeroFactory.h"
#include "../../../Events/HeroCreatedEvent.h"
#include "../../../Events/HeroDeletedEvent.h"
#include "Domain/Events/HeroCreatedEvent.h"
#include "Domain/Events/HeroDeletedEvent.h"
#include "../GameStructs/NetworkHandlerWrapper.h"
#include "../../../Services/ServiceLocator.h"
#include "Domain/Services/ServiceLocator.h"
using namespace L2Bot::Domain;
@ -25,7 +25,7 @@ namespace Interlude
if (hero) {
if (!m_Hero) {
m_Hero = m_Factory.Create(hero);
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(HeroCreatedEvent{});
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::HeroCreatedEvent{});
}
else
{
@ -35,7 +35,7 @@ namespace Interlude
}
else if (m_Hero) {
m_Hero = nullptr;
ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(HeroDeletedEvent{});
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Dispatch(Events::HeroDeletedEvent{});
}
return result;

View File

@ -6,13 +6,13 @@
#include "Domain/Repositories/EntityRepositoryInterface.h"
#include "../Factories/ItemFactory.h"
#include "../GameStructs/NetworkHandlerWrapper.h"
#include "../../../Events/ItemCreatedEvent.h"
#include "../../../Events/ItemUpdatedEvent.h"
#include "../../../Events/ItemDeletedEvent.h"
#include "../../../Events/HeroDeletedEvent.h"
#include "../../../Events/ItemAutousedEvent.h"
#include "../../../Events/OnEndItemListEvent.h"
#include "../../../Services/ServiceLocator.h"
#include "Domain/Events/ItemCreatedEvent.h"
#include "Domain/Events/ItemUpdatedEvent.h"
#include "Domain/Events/ItemDeletedEvent.h"
#include "Domain/Events/HeroDeletedEvent.h"
#include "Domain/Events/ItemAutousedEvent.h"
#include "Domain/Events/OnEndItemListEvent.h"
#include "Domain/Services/ServiceLocator.h"
using namespace L2Bot::Domain;
@ -46,10 +46,10 @@ namespace Interlude
{
}
void OnEndItemList(const Event& evt)
void OnEndItemList(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == OnEndItemListEvent::name)
if (evt.GetName() == Events::OnEndItemListEvent::name)
{
for (auto it = m_Items.begin(); it != m_Items.end();)
{
@ -67,21 +67,21 @@ namespace Interlude
}
}
void OnHeroDeleted(const Event& evt)
void OnHeroDeleted(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == HeroDeletedEvent::name)
if (evt.GetName() == Events::HeroDeletedEvent::name)
{
Reset();
}
}
void OnItemAutoused(const Event& evt)
void OnItemAutoused(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == ItemAutousedEvent::name)
if (evt.GetName() == Events::ItemAutousedEvent::name)
{
const auto casted = static_cast<const ItemAutousedEvent&>(evt);
const auto casted = static_cast<const Events::ItemAutousedEvent&>(evt);
const auto& data = casted.GetAutouseInfo();
const auto itemId = data[0];
@ -104,10 +104,10 @@ namespace Interlude
}
}
void OnItemCreated(const Event& evt)
void OnItemCreated(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == ItemCreatedEvent::name)
if (evt.GetName() == Events::ItemCreatedEvent::name)
{
if (m_IsNewCycle)
{
@ -115,7 +115,7 @@ namespace Interlude
m_NewItems.clear();
}
const auto casted = static_cast<const ItemCreatedEvent&>(evt);
const auto casted = static_cast<const Events::ItemCreatedEvent&>(evt);
const auto& data = casted.GetItemData();
@ -135,12 +135,12 @@ namespace Interlude
}
}
void OnItemUpdated(const Event& evt)
void OnItemUpdated(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == ItemUpdatedEvent::name)
if (evt.GetName() == Events::ItemUpdatedEvent::name)
{
const auto casted = static_cast<const ItemUpdatedEvent&>(evt);
const auto casted = static_cast<const Events::ItemUpdatedEvent&>(evt);
const auto& data = casted.GetItemData();
//todo exception?
@ -153,13 +153,13 @@ namespace Interlude
}
}
void OnItemDeleted(const Event& evt)
void OnItemDeleted(const Events::Event& evt)
{
//fixme may be a race condition
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == ItemDeletedEvent::name)
if (evt.GetName() == Events::ItemDeletedEvent::name)
{
const auto casted = static_cast<const ItemDeletedEvent&>(evt);
const auto casted = static_cast<const Events::ItemDeletedEvent&>(evt);
m_Items.erase(casted.GetObjectId());
}
@ -182,22 +182,22 @@ namespace Interlude
void Init() override
{
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(ItemCreatedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::ItemCreatedEvent::name, [this](const Events::Event& evt) {
OnItemCreated(evt);
});
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(ItemUpdatedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::ItemUpdatedEvent::name, [this](const Events::Event& evt) {
OnItemUpdated(evt);
});
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(ItemDeletedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::ItemDeletedEvent::name, [this](const Events::Event& evt) {
OnItemDeleted(evt);
});
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::HeroDeletedEvent::name, [this](const Events::Event& evt) {
OnHeroDeleted(evt);
});
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(ItemAutousedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::ItemAutousedEvent::name, [this](const Events::Event& evt) {
OnItemAutoused(evt);
});
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(OnEndItemListEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::OnEndItemListEvent::name, [this](const Events::Event& evt) {
OnEndItemList(evt);
});
}

View File

@ -5,10 +5,10 @@
#include "../GameStructs/NetworkHandlerWrapper.h"
#include "Domain/Repositories/EntityRepositoryInterface.h"
#include "../Factories/NPCFactory.h"
#include "../../../Events/SpoiledEvent.h"
#include "../../../Events/CreatureDiedEvent.h"
#include "Domain/Events/SpoiledEvent.h"
#include "Domain/Events/CreatureDiedEvent.h"
#include "../../GameStructs/FindObjectsTrait.h"
#include "../../../Services/ServiceLocator.h"
#include "Domain/Services/ServiceLocator.h"
using namespace L2Bot::Domain;
@ -57,10 +57,10 @@ namespace Interlude
void Init() override
{
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(SpoiledEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::SpoiledEvent::name, [this](const Events::Event& evt) {
OnSpoiled(evt);
});
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(CreatureDiedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::CreatureDiedEvent::name, [this](const Events::Event& evt) {
OnCreatureDied(evt);
});
}
@ -75,12 +75,12 @@ namespace Interlude
NPCRepository() = delete;
virtual ~NPCRepository() = default;
void OnSpoiled(const Event& evt)
void OnSpoiled(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == SpoiledEvent::name)
if (evt.GetName() == Events::SpoiledEvent::name)
{
const auto casted = static_cast<const SpoiledEvent&>(evt);
const auto casted = static_cast<const Events::SpoiledEvent&>(evt);
const auto hero = m_NetworkHandler.GetHero();
if (hero && hero->pawn && hero->pawn->lineagePlayerController)
{
@ -93,12 +93,12 @@ namespace Interlude
}
}
void OnCreatureDied(const Event& evt)
void OnCreatureDied(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == CreatureDiedEvent::name)
if (evt.GetName() == Events::CreatureDiedEvent::name)
{
const auto casted = static_cast<const CreatureDiedEvent&>(evt);
const auto casted = static_cast<const Events::CreatureDiedEvent&>(evt);
if (m_Spoiled.find(casted.GetCreatureId()) != m_Spoiled.end())
{
const auto isSweepable = casted.GetCreatureInfo()[4] != 0;

View File

@ -5,15 +5,15 @@
#include <shared_mutex>
#include "Domain/Repositories/EntityRepositoryInterface.h"
#include "../Factories/SkillFactory.h"
#include "../../../Events/SkillCreatedEvent.h"
#include "../../../Events/SkillUsedEvent.h"
#include "../../../Events/SkillCancelledEvent.h"
#include "../../../Events/AbnormalEffectChangedEvent.h"
#include "../../../Events/HeroDeletedEvent.h"
#include "../../../Events/GameEngineTickedEvent.h"
#include "Domain/Events/SkillCreatedEvent.h"
#include "Domain/Events/SkillUsedEvent.h"
#include "Domain/Events/SkillCancelledEvent.h"
#include "Domain/Events/AbnormalEffectChangedEvent.h"
#include "Domain/Events/HeroDeletedEvent.h"
#include "Domain/Events/GameEngineTickedEvent.h"
#include "../GameStructs/NetworkHandlerWrapper.h"
#include "../../../Common/TimerMap.h"
#include "../../../Services/ServiceLocator.h"
#include "Domain/Services/ServiceLocator.h"
using namespace L2Bot::Domain;
@ -53,30 +53,30 @@ namespace Interlude
void Init() override
{
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(SkillCreatedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::SkillCreatedEvent::name, [this](const Events::Event& evt) {
OnSkillCreated(evt);
});
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(SkillUsedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::SkillUsedEvent::name, [this](const Events::Event& evt) {
OnSkillUsed(evt);
});
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(SkillCancelledEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::SkillCancelledEvent::name, [this](const Events::Event& evt) {
OnSkillCancelled(evt);
});
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(AbnormalEffectChangedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::AbnormalEffectChangedEvent::name, [this](const Events::Event& evt) {
OnSkillToggled(evt);
});
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::HeroDeletedEvent::name, [this](const Events::Event& evt) {
OnHeroDeleted(evt);
});
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(GameEngineTickedEvent::name, [this](const Event& evt) {
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::GameEngineTickedEvent::name, [this](const Events::Event& evt) {
OnGameEngineTicked(evt);
});
}
void OnGameEngineTicked(const Event& evt)
void OnGameEngineTicked(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == GameEngineTickedEvent::name)
if (evt.GetName() == Events::GameEngineTickedEvent::name)
{
for (auto it = m_Skills.begin(); it != m_Skills.end();)
{
@ -94,10 +94,10 @@ namespace Interlude
}
}
void OnHeroDeleted(const Event& evt)
void OnHeroDeleted(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == HeroDeletedEvent::name)
if (evt.GetName() == Events::HeroDeletedEvent::name)
{
Reset();
m_CastingTimers.StopAll();
@ -106,10 +106,10 @@ namespace Interlude
}
//todo need to delete skills if they are not exists in create "queue"
void OnSkillCreated(const Event& evt)
void OnSkillCreated(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == SkillCreatedEvent::name)
if (evt.GetName() == Events::SkillCreatedEvent::name)
{
if (m_IsNewCycle)
{
@ -117,7 +117,7 @@ namespace Interlude
m_NewSkills.clear();
}
const auto casted = static_cast<const SkillCreatedEvent&>(evt);
const auto casted = static_cast<const Events::SkillCreatedEvent&>(evt);
const auto skillInfo = casted.GetSkillInfo();
const auto skillId = skillInfo[2];
@ -142,12 +142,12 @@ namespace Interlude
m_NewSkills[skillId] = skillId;
}
}
void OnSkillUsed(const Event& evt)
void OnSkillUsed(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == SkillUsedEvent::name)
if (evt.GetName() == Events::SkillUsedEvent::name)
{
const auto casted = static_cast<const SkillUsedEvent&>(evt);
const auto casted = static_cast<const Events::SkillUsedEvent&>(evt);
const auto skillInfo = casted.GetSkillInfo();
const auto skillId = skillInfo[0];
@ -174,12 +174,12 @@ namespace Interlude
});
}
}
void OnSkillCancelled(const Event& evt)
void OnSkillCancelled(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == SkillCancelledEvent::name)
if (evt.GetName() == Events::SkillCancelledEvent::name)
{
const auto casted = static_cast<const SkillCancelledEvent&>(evt);
const auto casted = static_cast<const Events::SkillCancelledEvent&>(evt);
const auto hero = m_NetworkHandler.GetHero();
@ -198,12 +198,12 @@ namespace Interlude
}
}
}
void OnSkillToggled(const Event& evt)
void OnSkillToggled(const Events::Event& evt)
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == AbnormalEffectChangedEvent::name)
if (evt.GetName() == Events::AbnormalEffectChangedEvent::name)
{
const auto casted = static_cast<const AbnormalEffectChangedEvent&>(evt);
const auto casted = static_cast<const Events::AbnormalEffectChangedEvent&>(evt);
const auto skillInfo = casted.GetSkillInfo();
std::unordered_map<uint32_t, int32_t> ids;