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

@ -0,0 +1,15 @@
#pragma once
#include <cstdint>
#include <string>
namespace L2Bot::Domain::DTO
{
struct ChatMessageData
{
const uint32_t objectId = 0;
const uint8_t channel = 0;
const std::wstring name = L"";
const std::wstring text = L"";
};
}

View File

@ -0,0 +1,18 @@
#pragma once
#include <cstdint>
namespace L2Bot::Domain::DTO
{
struct ItemData
{
const uint32_t objectId = 0;
const uint32_t itemId = 0;
const uint32_t amount = 0;
const uint16_t isEquipped = 0;
const uint16_t enchantLevel = 0;
const int32_t mana = -1;
const bool isQuest = false;
const bool isTwoHanded = false;
};
}

View File

@ -0,0 +1,36 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
namespace L2Bot::Domain::Events
{
class AbnormalEffectChangedEvent : public Event
{
public:
static constexpr const char* name = "abnormalEffectChanged";
const std::string GetName() const
{
return std::string(name);
}
const std::vector<int32_t>& GetSkillInfo() const
{
return m_SkillInfo;
}
AbnormalEffectChangedEvent(const std::vector<int32_t> skillInfo) :
m_SkillInfo(skillInfo)
{
}
AbnormalEffectChangedEvent() = delete;
virtual ~AbnormalEffectChangedEvent() = default;
private:
const std::vector<int32_t> m_SkillInfo;
};
}

View File

@ -0,0 +1,37 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
#include "../DTO/ChatMessageData.h"
namespace L2Bot::Domain::Events
{
class ChatMessageCreatedEvent : public Event
{
public:
static constexpr const char* name = "chatMessageCreated";
const std::string GetName() const
{
return std::string(name);
}
const DTO::ChatMessageData& GetChatMessage() const
{
return m_ChatMessage;
}
ChatMessageCreatedEvent(const DTO::ChatMessageData chatMessage) :
m_ChatMessage(chatMessage)
{
}
ChatMessageCreatedEvent() = delete;
virtual ~ChatMessageCreatedEvent() = default;
private:
const DTO::ChatMessageData m_ChatMessage;
};
}

View File

@ -0,0 +1,43 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
namespace L2Bot::Domain::Events
{
class CreatureDiedEvent : public Event
{
public:
static constexpr const char* name = "creatureDied";
const std::string GetName() const
{
return std::string(name);
}
const uint32_t GetCreatureId() const
{
return m_CreatureId;
}
const std::vector<int32_t>& GetCreatureInfo() const
{
return m_CreatureInfo;
}
CreatureDiedEvent(uint32_t creatureId, const std::vector<int32_t>& creatureInfo) :
m_CreatureId(creatureId),
m_CreatureInfo(creatureInfo)
{
}
CreatureDiedEvent() = delete;
virtual ~CreatureDiedEvent() = default;
private:
const uint32_t m_CreatureId;
const std::vector<int32_t> m_CreatureInfo;
};
}

View File

@ -0,0 +1,15 @@
#pragma once
#include <string>
namespace L2Bot::Domain::Events
{
class Event
{
public:
virtual const std::string GetName() const = 0;
Event() = default;
virtual ~Event() = default;
};
}

View File

@ -0,0 +1,42 @@
#pragma once
#include <string>
#include <functional>
#include <unordered_map>
#include <vector>
#include "Event.h"
namespace L2Bot::Domain::Events
{
class EventDispatcher
{
public:
using Delegate = std::function<void(const Event&)>;
EventDispatcher() = default;
virtual ~EventDispatcher() = default;
void Dispatch(const Event& evt)
{
const auto& name = evt.GetName();
if (m_Handlers.find(name) == m_Handlers.end())
{
return;
}
for (const auto& handler : m_Handlers[name])
{
handler(evt);
}
}
void Subscribe(const std::string& eventName, const Delegate handler)
{
m_Handlers[eventName].push_back(handler);
}
private:
std::unordered_map<std::string, std::vector<Delegate>> m_Handlers;
};
}

View File

@ -0,0 +1,21 @@
#pragma once
#include <cstdint>
#include "Event.h"
namespace L2Bot::Domain::Events
{
class GameEngineTickedEvent : public Event
{
public:
static constexpr const char* name = "gameEngineTicked";
const std::string GetName() const
{
return std::string(name);
}
GameEngineTickedEvent() = default;
virtual ~GameEngineTickedEvent() = default;
};
}

View File

@ -0,0 +1,22 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
namespace L2Bot::Domain::Events
{
class HeroCreatedEvent : public Event
{
public:
static constexpr const char* name = "heroCreated";
const std::string GetName() const
{
return std::string(name);
}
HeroCreatedEvent() = default;
virtual ~HeroCreatedEvent() = default;
};
}

View File

@ -0,0 +1,20 @@
#pragma once
#include "Event.h"
namespace L2Bot::Domain::Events
{
class HeroDeletedEvent : public Event
{
public:
static constexpr const char* name = "heroDeleted";
const std::string GetName() const
{
return std::string(name);
}
HeroDeletedEvent() = default;
virtual ~HeroDeletedEvent() = default;
};
}

View File

@ -0,0 +1,36 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
namespace L2Bot::Domain::Events
{
class ItemAutousedEvent : public Event
{
public:
static constexpr const char* name = "itemAutoused";
const std::string GetName() const
{
return std::string(name);
}
const std::vector<uint32_t>& GetAutouseInfo() const
{
return m_AutouseInfo;
}
ItemAutousedEvent(const std::vector<uint32_t> autouseInfo) :
m_AutouseInfo(autouseInfo)
{
}
ItemAutousedEvent() = delete;
virtual ~ItemAutousedEvent() = default;
private:
const std::vector<uint32_t> m_AutouseInfo;
};
}

View File

@ -0,0 +1,37 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
#include "../DTO/ItemData.h"
namespace L2Bot::Domain::Events
{
class ItemCreatedEvent : public Event
{
public:
static constexpr const char* name = "itemCreated";
const std::string GetName() const
{
return std::string(name);
}
const DTO::ItemData& GetItemData() const
{
return m_ItemData;
}
ItemCreatedEvent(const DTO::ItemData itemData) :
m_ItemData(itemData)
{
}
ItemCreatedEvent() = delete;
virtual ~ItemCreatedEvent() = default;
private:
const DTO::ItemData m_ItemData;
};
}

View File

@ -0,0 +1,36 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
namespace L2Bot::Domain::Events
{
class ItemDeletedEvent : public Event
{
public:
static constexpr const char* name = "itemDeleted";
const std::string GetName() const
{
return std::string(name);
}
const uint32_t GetObjectId() const
{
return m_ObjectId;
}
ItemDeletedEvent(const uint32_t objectId) :
m_ObjectId(objectId)
{
}
ItemDeletedEvent() = delete;
virtual ~ItemDeletedEvent() = default;
private:
const uint32_t m_ObjectId;
};
}

View File

@ -0,0 +1,37 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
#include "../DTO/ItemData.h"
namespace L2Bot::Domain::Events
{
class ItemUpdatedEvent : public Event
{
public:
static constexpr const char* name = "itemUpdated";
const std::string GetName() const
{
return std::string(name);
}
const DTO::ItemData& GetItemData() const
{
return m_ItemData;
}
ItemUpdatedEvent(const DTO::ItemData itemData) :
m_ItemData(itemData)
{
}
ItemUpdatedEvent() = delete;
virtual ~ItemUpdatedEvent() = default;
private:
const DTO::ItemData m_ItemData;
};
}

View File

@ -0,0 +1,20 @@
#pragma once
#include "Event.h"
namespace L2Bot::Domain::Events
{
class OnEndItemListEvent : public Event
{
public:
static constexpr const char* name = "onEndItemList";
const std::string GetName() const
{
return std::string(name);
}
OnEndItemListEvent() = default;
virtual ~OnEndItemListEvent() = default;
};
}

View File

@ -0,0 +1,35 @@
#pragma once
#include <cstdint>
#include "Event.h"
namespace L2Bot::Domain::Events
{
class SkillCancelledEvent : public Event
{
public:
static constexpr const char* name = "skillCancelled";
const std::string GetName() const
{
return std::string(name);
}
const uint32_t GetInitiatorId() const
{
return m_InitiatorId;
}
SkillCancelledEvent(const uint32_t initiatorId) :
m_InitiatorId(initiatorId)
{
}
SkillCancelledEvent() = delete;
virtual ~SkillCancelledEvent() = default;
private:
const uint32_t m_InitiatorId;
};
}

View File

@ -0,0 +1,36 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
namespace L2Bot::Domain::Events
{
class SkillCreatedEvent : public Event
{
public:
static constexpr const char* name = "skillCreated";
const std::string GetName() const
{
return std::string(name);
}
const std::vector<int32_t>& GetSkillInfo() const
{
return m_SkillInfo;
}
SkillCreatedEvent(const std::vector<int32_t> skillInfo) :
m_SkillInfo(skillInfo)
{
}
SkillCreatedEvent() = delete;
virtual ~SkillCreatedEvent() = default;
private:
const std::vector<int32_t> m_SkillInfo;
};
}

View File

@ -0,0 +1,36 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
namespace L2Bot::Domain::Events
{
class SkillUsedEvent : public Event
{
public:
static constexpr const char* name = "skillUsed";
const std::string GetName() const
{
return std::string(name);
}
const std::vector<int32_t>& GetSkillInfo() const
{
return m_SkillInfo;
}
SkillUsedEvent(const std::vector<int32_t> skillInfo) :
m_SkillInfo(skillInfo)
{
}
SkillUsedEvent() = delete;
virtual ~SkillUsedEvent() = default;
private:
const std::vector<int32_t> m_SkillInfo;
};
}

View File

@ -0,0 +1,21 @@
#pragma once
#include <cstdint>
#include "Event.h"
namespace L2Bot::Domain::Events
{
class SpoiledEvent : public Event
{
public:
static constexpr const char* name = "spoiled";
const std::string GetName() const
{
return std::string(name);
}
SpoiledEvent() = default;
virtual ~SpoiledEvent() = default;
};
}

View File

@ -0,0 +1,33 @@
#pragma once
#include <memory>
#include "../Events/EventDispatcher.h"
namespace L2Bot::Domain::Services
{
class ServiceLocator
{
public:
static ServiceLocator& GetInstance() {
static ServiceLocator instance;
return instance;
}
const std::unique_ptr<Events::EventDispatcher>& GetEventDispatcher()
{
return m_EventDispatcher;
}
void SetEventDispatcher(std::unique_ptr<Events::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<Events::EventDispatcher> m_EventDispatcher;
};
}

View File

@ -159,7 +159,9 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Domain\DTO\ChatMessageData.h" />
<ClInclude Include="Domain\DTO\EntityState.h" />
<ClInclude Include="Domain\DTO\ItemData.h" />
<ClInclude Include="Domain\DTO\Message.h" />
<ClInclude Include="Domain\Entities\AbnormalEffect.h" />
<ClInclude Include="Domain\Entities\ArmorItem.h" />
@ -175,12 +177,30 @@
<ClInclude Include="Domain\Enums\ChatChannelEnum.h" />
<ClInclude Include="Domain\Enums\ItemTypeEnum.h" />
<ClInclude Include="Domain\Enums\WeaponTypeEnum.h" />
<ClInclude Include="Domain\Events\AbnormalEffectChangedEvent.h" />
<ClInclude Include="Domain\Events\ChatMessageCreatedEvent.h" />
<ClInclude Include="Domain\Events\CreatureDiedEvent.h" />
<ClInclude Include="Domain\Events\Event.h" />
<ClInclude Include="Domain\Events\EventDispatcher.h" />
<ClInclude Include="Domain\Events\GameEngineTickedEvent.h" />
<ClInclude Include="Domain\Events\HeroCreatedEvent.h" />
<ClInclude Include="Domain\Events\HeroDeletedEvent.h" />
<ClInclude Include="Domain\Events\ItemAutousedEvent.h" />
<ClInclude Include="Domain\Events\ItemCreatedEvent.h" />
<ClInclude Include="Domain\Events\ItemDeletedEvent.h" />
<ClInclude Include="Domain\Events\ItemUpdatedEvent.h" />
<ClInclude Include="Domain\Events\OnEndItemListEvent.h" />
<ClInclude Include="Domain\Events\SkillCancelledEvent.h" />
<ClInclude Include="Domain\Events\SkillCreatedEvent.h" />
<ClInclude Include="Domain\Events\SkillUsedEvent.h" />
<ClInclude Include="Domain\Events\SpoiledEvent.h" />
<ClInclude Include="Domain\Serializers\IncomingMessageFactoryInterface.h" />
<ClInclude Include="Domain\Serializers\IncomingMessage.h" />
<ClInclude Include="Domain\Services\HeroServiceInterface.h" />
<ClInclude Include="Domain\Entities\ChatMessage.h" />
<ClInclude Include="Domain\Services\IncomingMessageProcessor.h" />
<ClInclude Include="Domain\Services\OutgoingMessageBuilder.h" />
<ClInclude Include="Domain\Services\ServiceLocator.h" />
<ClInclude Include="Domain\Services\WorldHandler.h" />
<ClInclude Include="Domain\ValueObjects\Vector3.h" />
<ClInclude Include="Domain\Enums\SpoilStateEnum.h" />

View File

@ -165,6 +165,66 @@
<ClInclude Include="Domain\Services\OutgoingMessageBuilder.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\EventDispatcher.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\Event.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\AbnormalEffectChangedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\ChatMessageCreatedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\CreatureDiedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\GameEngineTickedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\HeroCreatedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\HeroDeletedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\ItemAutousedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\ItemCreatedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\ItemDeletedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\ItemUpdatedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\OnEndItemListEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\SkillCancelledEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\SkillCreatedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\SkillUsedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Events\SpoiledEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\DTO\ChatMessageData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\DTO\ItemData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Services\ServiceLocator.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">

View File

@ -9,8 +9,8 @@
#include "Serializers/JsonIncomingMessageFactory.h"
#include "Transports/NamedPipeTransport.h"
#include "Versions/VersionAbstractFactory.h"
#include "Services/ServiceLocator.h"
#include "Events/HeroDeletedEvent.h"
#include "Domain/Services/ServiceLocator.h"
#include "Domain/Events/EventDispatcher.h"
using namespace L2Bot::Domain;
@ -49,7 +49,7 @@ public:
private:
void Init()
{
ServiceLocator::GetInstance().SetEventDispatcher(std::make_unique<EventDispatcher>());
Services::ServiceLocator::GetInstance().SetEventDispatcher(std::make_unique<Events::EventDispatcher>());
HMODULE hEngine = GetModuleHandleA("Engine.dll");
HMODULE hCore = GetModuleHandleA("Core.dll");

View File

@ -1,12 +0,0 @@
#pragma once
#include <cstdint>
#include <string>
struct ChatMessage
{
const uint32_t objectId = 0;
const uint8_t channel = 0;
const std::wstring name = L"";
const std::wstring text = L"";
};

View File

@ -1,15 +0,0 @@
#pragma once
#include <cstdint>
struct ItemData
{
const uint32_t objectId = 0;
const uint32_t itemId = 0;
const uint32_t amount = 0;
const uint16_t isEquipped = 0;
const uint16_t enchantLevel = 0;
const int32_t mana = -1;
const bool isQuest = false;
const bool isTwoHanded = false;
};

View File

@ -1,33 +0,0 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
class AbnormalEffectChangedEvent : public Event
{
public:
static constexpr const char* name = "abnormalEffectChanged";
const std::string GetName() const
{
return std::string(name);
}
const std::vector<int32_t>& GetSkillInfo() const
{
return m_SkillInfo;
}
AbnormalEffectChangedEvent(const std::vector<int32_t> skillInfo) :
m_SkillInfo(skillInfo)
{
}
AbnormalEffectChangedEvent() = delete;
virtual ~AbnormalEffectChangedEvent() = default;
private:
const std::vector<int32_t> m_SkillInfo;
};

View File

@ -1,34 +0,0 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
#include "../DTO/ChatMessage.h"
class ChatMessageCreatedEvent : public Event
{
public:
static constexpr const char* name = "chatMessageCreated";
const std::string GetName() const
{
return std::string(name);
}
const ChatMessage& GetChatMessage() const
{
return m_ChatMessage;
}
ChatMessageCreatedEvent(const ChatMessage chatMessage) :
m_ChatMessage(chatMessage)
{
}
ChatMessageCreatedEvent() = delete;
virtual ~ChatMessageCreatedEvent() = default;
private:
const ChatMessage m_ChatMessage;
};

View File

@ -1,39 +0,0 @@
#pragma once
#include <cstdint>
#include "Event.h"
class CreatureDiedEvent : public Event
{
public:
static constexpr const char* name = "creatureDied";
const std::string GetName() const
{
return std::string(name);
}
const uint32_t GetCreatureId() const
{
return m_CreatureId;
}
const std::vector<int32_t>& GetCreatureInfo() const
{
return m_CreatureInfo;
}
CreatureDiedEvent(uint32_t creatureId, const std::vector<int32_t>& creatureInfo) :
m_CreatureId(creatureId),
m_CreatureInfo(creatureInfo)
{
}
CreatureDiedEvent() = delete;
virtual ~CreatureDiedEvent() = default;
private:
const uint32_t m_CreatureId;
const std::vector<int32_t> m_CreatureInfo;
};

View File

@ -1,12 +0,0 @@
#pragma once
#include <string>
class Event
{
public:
virtual const std::string GetName() const = 0;
Event() = default;
virtual ~Event() = default;
};

View File

@ -1,39 +0,0 @@
#pragma once
#include <string>
#include <functional>
#include <unordered_map>
#include <vector>
#include "Event.h"
class EventDispatcher
{
public:
using Delegate = std::function<void(const Event&)>;
EventDispatcher() = default;
virtual ~EventDispatcher() = default;
void Dispatch(const Event& evt)
{
const auto& name = evt.GetName();
if (m_Handlers.find(name) == m_Handlers.end())
{
return;
}
for (const auto& handler : m_Handlers[name])
{
handler(evt);
}
}
void Subscribe(const std::string& eventName, const Delegate handler)
{
m_Handlers[eventName].push_back(handler);
}
private:
std::unordered_map<std::string, std::vector<Delegate>> m_Handlers;
};

View File

@ -1,18 +0,0 @@
#pragma once
#include <cstdint>
#include "Event.h"
class GameEngineTickedEvent : public Event
{
public:
static constexpr const char* name = "gameEngineTicked";
const std::string GetName() const
{
return std::string(name);
}
GameEngineTickedEvent() = default;
virtual ~GameEngineTickedEvent() = default;
};

View File

@ -1,19 +0,0 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
class HeroCreatedEvent : public Event
{
public:
static constexpr const char* name = "heroCreated";
const std::string GetName() const
{
return std::string(name);
}
HeroCreatedEvent() = default;
virtual ~HeroCreatedEvent() = default;
};

View File

@ -1,17 +0,0 @@
#pragma once
#include "Event.h"
class HeroDeletedEvent : public Event
{
public:
static constexpr const char* name = "heroDeleted";
const std::string GetName() const
{
return std::string(name);
}
HeroDeletedEvent() = default;
virtual ~HeroDeletedEvent() = default;
};

View File

@ -1,33 +0,0 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
class ItemAutousedEvent : public Event
{
public:
static constexpr const char* name = "itemAutoused";
const std::string GetName() const
{
return std::string(name);
}
const std::vector<uint32_t>& GetAutouseInfo() const
{
return m_AutouseInfo;
}
ItemAutousedEvent(const std::vector<uint32_t> autouseInfo) :
m_AutouseInfo(autouseInfo)
{
}
ItemAutousedEvent() = delete;
virtual ~ItemAutousedEvent() = default;
private:
const std::vector<uint32_t> m_AutouseInfo;
};

View File

@ -1,34 +0,0 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
#include "../DTO/ItemData.h"
class ItemCreatedEvent : public Event
{
public:
static constexpr const char* name = "itemCreated";
const std::string GetName() const
{
return std::string(name);
}
const ItemData& GetItemData() const
{
return m_ItemData;
}
ItemCreatedEvent(const ItemData itemData) :
m_ItemData(itemData)
{
}
ItemCreatedEvent() = delete;
virtual ~ItemCreatedEvent() = default;
private:
const ItemData m_ItemData;
};

View File

@ -1,34 +0,0 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
#include "../DTO/ItemData.h"
class ItemDeletedEvent : public Event
{
public:
static constexpr const char* name = "itemDeleted";
const std::string GetName() const
{
return std::string(name);
}
const uint32_t GetObjectId() const
{
return m_ObjectId;
}
ItemDeletedEvent(const uint32_t objectId) :
m_ObjectId(objectId)
{
}
ItemDeletedEvent() = delete;
virtual ~ItemDeletedEvent() = default;
private:
const uint32_t m_ObjectId;
};

View File

@ -1,34 +0,0 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
#include "../DTO/ItemData.h"
class ItemUpdatedEvent : public Event
{
public:
static constexpr const char* name = "itemUpdated";
const std::string GetName() const
{
return std::string(name);
}
const ItemData& GetItemData() const
{
return m_ItemData;
}
ItemUpdatedEvent(const ItemData itemData) :
m_ItemData(itemData)
{
}
ItemUpdatedEvent() = delete;
virtual ~ItemUpdatedEvent() = default;
private:
const ItemData m_ItemData;
};

View File

@ -1,17 +0,0 @@
#pragma once
#include "Event.h"
class OnEndItemListEvent : public Event
{
public:
static constexpr const char* name = "onEndItemList";
const std::string GetName() const
{
return std::string(name);
}
OnEndItemListEvent() = default;
virtual ~OnEndItemListEvent() = default;
};

View File

@ -1,32 +0,0 @@
#pragma once
#include <cstdint>
#include "Event.h"
class SkillCancelledEvent : public Event
{
public:
static constexpr const char* name = "skillCancelled";
const std::string GetName() const
{
return std::string(name);
}
const uint32_t GetInitiatorId() const
{
return m_InitiatorId;
}
SkillCancelledEvent(const uint32_t initiatorId) :
m_InitiatorId(initiatorId)
{
}
SkillCancelledEvent() = delete;
virtual ~SkillCancelledEvent() = default;
private:
const uint32_t m_InitiatorId;
};

View File

@ -1,33 +0,0 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
class SkillCreatedEvent : public Event
{
public:
static constexpr const char* name = "skillCreated";
const std::string GetName() const
{
return std::string(name);
}
const std::vector<int32_t>& GetSkillInfo() const
{
return m_SkillInfo;
}
SkillCreatedEvent(const std::vector<int32_t> skillInfo) :
m_SkillInfo(skillInfo)
{
}
SkillCreatedEvent() = delete;
virtual ~SkillCreatedEvent() = default;
private:
const std::vector<int32_t> m_SkillInfo;
};

View File

@ -1,33 +0,0 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
class SkillUsedEvent : public Event
{
public:
static constexpr const char* name = "skillUsed";
const std::string GetName() const
{
return std::string(name);
}
const std::vector<int32_t>& GetSkillInfo() const
{
return m_SkillInfo;
}
SkillUsedEvent(const std::vector<int32_t> skillInfo) :
m_SkillInfo(skillInfo)
{
}
SkillUsedEvent() = delete;
virtual ~SkillUsedEvent() = default;
private:
const std::vector<int32_t> m_SkillInfo;
};

View File

@ -1,18 +0,0 @@
#pragma once
#include <cstdint>
#include "Event.h"
class SpoiledEvent : public Event
{
public:
static constexpr const char* name = "spoiled";
const std::string GetName() const
{
return std::string(name);
}
SpoiledEvent() = default;
virtual ~SpoiledEvent() = default;
};

View File

@ -164,29 +164,9 @@
<ClInclude Include="Common\apihook.h" />
<ClInclude Include="Common\Common.h" />
<ClInclude Include="Common\TimerMap.h" />
<ClInclude Include="DTO\ChatMessage.h" />
<ClInclude Include="DTO\ItemData.h" />
<ClInclude Include="Events\ChatMessageCreatedEvent.h" />
<ClInclude Include="Events\CreatureDiedEvent.h" />
<ClInclude Include="Events\Event.h" />
<ClInclude Include="Events\EventDispatcher.h" />
<ClInclude Include="Events\GameEngineTickedEvent.h" />
<ClInclude Include="Events\HeroCreatedEvent.h" />
<ClInclude Include="Events\HeroDeletedEvent.h" />
<ClInclude Include="Events\ItemAutousedEvent.h" />
<ClInclude Include="Events\ItemCreatedEvent.h" />
<ClInclude Include="Events\ItemDeletedEvent.h" />
<ClInclude Include="Events\ItemUpdatedEvent.h" />
<ClInclude Include="Events\OnEndItemListEvent.h" />
<ClInclude Include="Events\SkillCancelledEvent.h" />
<ClInclude Include="Events\SkillCreatedEvent.h" />
<ClInclude Include="Events\AbnormalEffectChangedEvent.h" />
<ClInclude Include="Events\SkillUsedEvent.h" />
<ClInclude Include="Events\SpoiledEvent.h" />
<ClInclude Include="Application.h" />
<ClInclude Include="Serializers\JsonIncomingMessageFactory.h" />
<ClInclude Include="Serializers\JsonSerializer.h" />
<ClInclude Include="Services\ServiceLocator.h" />
<ClInclude Include="Versions\Interlude\Services\HeroService.h" />
<ClInclude Include="ThirdParty\json.hpp" />
<ClInclude Include="Versions\GameStructs\FNameInterface.h" />

View File

@ -60,18 +60,6 @@
<ClInclude Include="Versions\Interlude\AbstractFactory.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\Event.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\SpoiledEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\EventDispatcher.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\CreatureDiedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Versions\GameStructs\NetworkHandlerInterface.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -99,27 +87,9 @@
<ClInclude Include="Versions\Interlude\GameStructs\L2ParamStack.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\SkillCreatedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\SkillUsedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\SkillCancelledEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Common\TimerMap.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\HeroCreatedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\HeroDeletedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\AbnormalEffectChangedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Serializers\JsonSerializer.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -153,48 +123,21 @@
<ClInclude Include="Versions\Interlude\Repositories\ItemRepository.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\ItemCreatedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DTO\ItemData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\ItemUpdatedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\ItemDeletedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\ItemAutousedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Versions\Interlude\Factories\AbnormalEffectFactory.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Versions\Interlude\Repositories\AbnormalEffectRepository.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\GameEngineTickedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Versions\Interlude\Helpers\EnchantHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DTO\ChatMessage.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\ChatMessageCreatedEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Versions\Interlude\Factories\ChatMessageFactory.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Versions\Interlude\Repositories\ChatMessageRepository.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Events\OnEndItemListEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ThirdParty\json.hpp">
<Filter>Header Files</Filter>
</ClInclude>
@ -204,9 +147,6 @@
<ClInclude Include="Versions\Interlude\Services\HeroService.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Services\ServiceLocator.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">

View File

@ -1,30 +0,0 @@
#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;
};

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;