refactor: move events and service locator into core project
This commit is contained in:
15
L2BotCore/Domain/DTO/ChatMessageData.h
Normal file
15
L2BotCore/Domain/DTO/ChatMessageData.h
Normal 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"";
|
||||
};
|
||||
}
|
18
L2BotCore/Domain/DTO/ItemData.h
Normal file
18
L2BotCore/Domain/DTO/ItemData.h
Normal 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;
|
||||
};
|
||||
}
|
36
L2BotCore/Domain/Events/AbnormalEffectChangedEvent.h
Normal file
36
L2BotCore/Domain/Events/AbnormalEffectChangedEvent.h
Normal 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;
|
||||
};
|
||||
}
|
37
L2BotCore/Domain/Events/ChatMessageCreatedEvent.h
Normal file
37
L2BotCore/Domain/Events/ChatMessageCreatedEvent.h
Normal 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;
|
||||
};
|
||||
}
|
43
L2BotCore/Domain/Events/CreatureDiedEvent.h
Normal file
43
L2BotCore/Domain/Events/CreatureDiedEvent.h
Normal 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;
|
||||
};
|
||||
}
|
15
L2BotCore/Domain/Events/Event.h
Normal file
15
L2BotCore/Domain/Events/Event.h
Normal 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;
|
||||
};
|
||||
}
|
42
L2BotCore/Domain/Events/EventDispatcher.h
Normal file
42
L2BotCore/Domain/Events/EventDispatcher.h
Normal 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;
|
||||
};
|
||||
}
|
21
L2BotCore/Domain/Events/GameEngineTickedEvent.h
Normal file
21
L2BotCore/Domain/Events/GameEngineTickedEvent.h
Normal 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;
|
||||
};
|
||||
}
|
22
L2BotCore/Domain/Events/HeroCreatedEvent.h
Normal file
22
L2BotCore/Domain/Events/HeroCreatedEvent.h
Normal 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;
|
||||
};
|
||||
}
|
20
L2BotCore/Domain/Events/HeroDeletedEvent.h
Normal file
20
L2BotCore/Domain/Events/HeroDeletedEvent.h
Normal 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;
|
||||
};
|
||||
}
|
36
L2BotCore/Domain/Events/ItemAutousedEvent.h
Normal file
36
L2BotCore/Domain/Events/ItemAutousedEvent.h
Normal 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;
|
||||
};
|
||||
}
|
37
L2BotCore/Domain/Events/ItemCreatedEvent.h
Normal file
37
L2BotCore/Domain/Events/ItemCreatedEvent.h
Normal 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;
|
||||
};
|
||||
}
|
36
L2BotCore/Domain/Events/ItemDeletedEvent.h
Normal file
36
L2BotCore/Domain/Events/ItemDeletedEvent.h
Normal 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;
|
||||
};
|
||||
}
|
37
L2BotCore/Domain/Events/ItemUpdatedEvent.h
Normal file
37
L2BotCore/Domain/Events/ItemUpdatedEvent.h
Normal 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;
|
||||
};
|
||||
}
|
20
L2BotCore/Domain/Events/OnEndItemListEvent.h
Normal file
20
L2BotCore/Domain/Events/OnEndItemListEvent.h
Normal 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;
|
||||
};
|
||||
}
|
35
L2BotCore/Domain/Events/SkillCancelledEvent.h
Normal file
35
L2BotCore/Domain/Events/SkillCancelledEvent.h
Normal 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;
|
||||
};
|
||||
}
|
36
L2BotCore/Domain/Events/SkillCreatedEvent.h
Normal file
36
L2BotCore/Domain/Events/SkillCreatedEvent.h
Normal 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;
|
||||
};
|
||||
}
|
36
L2BotCore/Domain/Events/SkillUsedEvent.h
Normal file
36
L2BotCore/Domain/Events/SkillUsedEvent.h
Normal 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;
|
||||
};
|
||||
}
|
21
L2BotCore/Domain/Events/SpoiledEvent.h
Normal file
21
L2BotCore/Domain/Events/SpoiledEvent.h
Normal 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;
|
||||
};
|
||||
}
|
33
L2BotCore/Domain/Services/ServiceLocator.h
Normal file
33
L2BotCore/Domain/Services/ServiceLocator.h
Normal 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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user