refactor: remove unnecessary classes

This commit is contained in:
k0t9i
2023-10-16 00:03:43 +04:00
parent a7a9b626f4
commit 787f4969ed
57 changed files with 1651 additions and 1600 deletions

View File

@@ -2,7 +2,9 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
#include <functional>
#include "EntityInterface.h" #include "EntityInterface.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::Entities namespace L2Bot::Domain::Entities
{ {
@@ -14,29 +16,30 @@ namespace L2Bot::Domain::Entities
return m_SkillId; return m_SkillId;
} }
void Update(const EntityInterface* other) override void Update(
{ const uint8_t level,
const AbnormalEffect* casted = static_cast<const AbnormalEffect*>(other); const std::wstring& name,
SaveState(); const std::wstring& description,
const std::wstring& iconName
m_SkillId = casted->m_SkillId; ) {
m_Level = casted->m_Level; m_Level = level;
m_Name = casted->m_Name; m_Name = name;
m_Description = casted->m_Description; m_Description = description;
m_IconName = casted->m_IconName; m_IconName = iconName;
} }
void SaveState() override const size_t GetHash() const override
{ {
m_IsNewState = false; return Helpers::CombineHashes({
std::hash<uint32_t>{}(m_SkillId),
std::hash<uint8_t>{}(m_Level),
std::hash<std::wstring>{}(m_Name),
std::hash<std::wstring>{}(m_Description),
std::hash<std::wstring>{}(m_IconName)
});
} }
const bool IsEqual(const EntityInterface* other) const override const std::string GetEntityName() const override
{ {
const AbnormalEffect* casted = static_cast<const AbnormalEffect*>(other); return "abnormalEffect";
return m_SkillId == casted->m_SkillId &&
m_Level == casted->m_Level &&
m_Name == casted->m_Name &&
m_Description == casted->m_Description &&
m_IconName == casted->m_IconName;
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override
@@ -45,13 +48,9 @@ namespace L2Bot::Domain::Entities
result.push_back({ L"id", std::to_wstring(m_SkillId) }); result.push_back({ L"id", std::to_wstring(m_SkillId) });
result.push_back({ L"level", std::to_wstring(m_Level) }); result.push_back({ L"level", std::to_wstring(m_Level) });
if (m_IsNewState)
{
result.push_back({ L"name", m_Name }); result.push_back({ L"name", m_Name });
result.push_back({ L"iconName", m_IconName }); result.push_back({ L"iconName", m_IconName });
result.push_back({ L"description", m_Description }); result.push_back({ L"description", m_Description });
}
return result; return result;
} }
@@ -72,15 +71,6 @@ namespace L2Bot::Domain::Entities
} }
AbnormalEffect(const AbnormalEffect* other) :
m_SkillId(other->m_SkillId),
m_Level(other->m_Level),
m_Name(other->m_Name),
m_Description(other->m_Description),
m_IconName(other->m_IconName)
{
}
AbnormalEffect() = default; AbnormalEffect() = default;
virtual ~AbnormalEffect() = default; virtual ~AbnormalEffect() = default;
@@ -90,6 +80,5 @@ namespace L2Bot::Domain::Entities
std::wstring m_Name = L""; std::wstring m_Name = L"";
std::wstring m_Description = L""; std::wstring m_Description = L"";
std::wstring m_IconName = L""; std::wstring m_IconName = L"";
bool m_IsNewState = true;
}; };
} }

View File

@@ -2,87 +2,75 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
#include <functional>
#include "BaseItem.h" #include "BaseItem.h"
#include "../Enums/ArmorTypeEnum.h" #include "../Enums/ArmorTypeEnum.h"
#include "../Enums/CrystalTypeEnum.h" #include "../Enums/CrystalTypeEnum.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::Entities namespace L2Bot::Domain::Entities
{ {
class ArmorItem : public BaseItem class ArmorItem : public BaseItem
{ {
public: public:
void Update(const EntityInterface* other) override void Update(
{ const uint32_t itemId,
const ArmorItem* casted = static_cast<const ArmorItem*>(other); const int32_t mana,
const std::wstring& name,
const std::wstring& iconName,
const std::wstring& description,
const uint16_t weight,
const bool isEquipped,
const uint16_t enchantLevel,
const Enums::ArmorTypeEnum armorType,
const Enums::CrystalTypeEnum crystalType,
const uint32_t pDefense,
const uint32_t mDefense,
const std::wstring& setEffect,
const std::wstring& addSetEffect,
const std::wstring& enchantEffect
) {
BaseItem::Update(itemId, mana, name, iconName, description, weight);
BaseItem::Update(other); m_IsEquipped = isEquipped;
m_EnchantLevel = enchantLevel;
m_IsEquipped = casted->m_IsEquipped; m_ArmorType = armorType;
m_EnchantLevel = casted->m_EnchantLevel; m_CrystalType = crystalType;
m_ArmorType = casted->m_ArmorType; m_PDefense = pDefense;
m_CrystalType = casted->m_CrystalType; m_MDefense = mDefense;
m_PDefense = casted->m_PDefense; m_SetEffect = setEffect;
m_MDefense = casted->m_MDefense; m_AddSetEffect = addSetEffect;
m_SetEffect = casted->m_SetEffect; m_EnchantEffect = enchantEffect;
m_AddSetEffect = casted->m_AddSetEffect;
m_EnchantEffect = casted->m_EnchantEffect;
} }
void SaveState() override const size_t GetHash() const override
{ {
BaseItem::SaveState(); return Helpers::CombineHashes({
m_PrevState = BaseItem::GetHash(),
{ std::hash<bool>{}(m_IsEquipped),
m_IsEquipped, std::hash<uint16_t>{}(m_EnchantLevel),
m_EnchantLevel, std::hash<Enums::ArmorTypeEnum>{}(m_ArmorType),
m_PDefense, std::hash<Enums::CrystalTypeEnum>{}(m_CrystalType),
m_MDefense, std::hash<uint32_t>{}(m_PDefense),
false std::hash<uint32_t>{}(m_MDefense),
}; std::hash<std::wstring>{}(m_SetEffect),
} std::hash<std::wstring>{}(m_AddSetEffect),
const bool IsEqual(const EntityInterface* other) const override std::hash<std::wstring>{}(m_EnchantEffect)
{ });
const ArmorItem* casted = static_cast<const ArmorItem*>(other);
return BaseItem::IsEqual(other) &&
m_IsEquipped == casted->m_IsEquipped &&
m_EnchantLevel == casted->m_EnchantLevel &&
m_ArmorType == casted->m_ArmorType &&
m_CrystalType == casted->m_CrystalType &&
m_PDefense == casted->m_PDefense &&
m_MDefense == casted->m_MDefense &&
m_SetEffect == casted->m_SetEffect &&
m_AddSetEffect == casted->m_AddSetEffect &&
m_EnchantEffect == casted->m_EnchantEffect;
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override
{ {
std::vector<Serializers::Node> result = BaseItem::BuildSerializationNodes(); std::vector<Serializers::Node> result = BaseItem::BuildSerializationNodes();
if (m_PrevState.isNewState)
{
result.push_back({ L"armorType", std::to_wstring(static_cast<uint8_t>(m_ArmorType)) }); result.push_back({ L"armorType", std::to_wstring(static_cast<uint8_t>(m_ArmorType)) });
result.push_back({ L"crystalType", std::to_wstring(static_cast<int8_t>(m_CrystalType)) }); result.push_back({ L"crystalType", std::to_wstring(static_cast<int8_t>(m_CrystalType)) });
result.push_back({ L"setEffect", m_SetEffect }); result.push_back({ L"setEffect", m_SetEffect });
result.push_back({ L"addSetEffect", m_AddSetEffect }); result.push_back({ L"addSetEffect", m_AddSetEffect });
result.push_back({ L"enchantEffect", m_EnchantEffect }); result.push_back({ L"enchantEffect", m_EnchantEffect });
}
if (m_PrevState.isNewState || m_IsEquipped != m_PrevState.isEquipped)
{
result.push_back({ L"isEquipped", std::to_wstring(m_IsEquipped) }); result.push_back({ L"isEquipped", std::to_wstring(m_IsEquipped) });
}
if (m_PrevState.isNewState || m_EnchantLevel != m_PrevState.enchantLevel)
{
result.push_back({ L"enchantLevel", std::to_wstring(m_EnchantLevel) }); result.push_back({ L"enchantLevel", std::to_wstring(m_EnchantLevel) });
}
if (m_PrevState.isNewState || m_PDefense != m_PrevState.pDefense)
{
result.push_back({ L"pDefense", std::to_wstring(m_PDefense) }); result.push_back({ L"pDefense", std::to_wstring(m_PDefense) });
}
if (m_PrevState.isNewState || m_MDefense != m_PrevState.mDefense)
{
result.push_back({ L"mDefense", std::to_wstring(m_MDefense) }); result.push_back({ L"mDefense", std::to_wstring(m_MDefense) });
}
return result; return result;
} }
@@ -128,34 +116,9 @@ namespace L2Bot::Domain::Entities
{ {
} }
ArmorItem(const ArmorItem* other) :
BaseItem(other),
m_IsEquipped(other->m_IsEquipped),
m_EnchantLevel(other->m_EnchantLevel),
m_ArmorType(other->m_ArmorType),
m_CrystalType(other->m_CrystalType),
m_PDefense(other->m_PDefense),
m_MDefense(other->m_MDefense),
m_SetEffect(other->m_SetEffect),
m_AddSetEffect(other->m_AddSetEffect),
m_EnchantEffect(other->m_EnchantEffect)
{
}
ArmorItem() = default; ArmorItem() = default;
virtual ~ArmorItem() = default; virtual ~ArmorItem() = default;
private:
struct GetState
{
bool isEquipped = 0;
uint16_t enchantLevel = 0;
uint32_t pDefense = 0;
uint32_t mDefense = 0;
bool isNewState = true;
};
private: private:
bool m_IsEquipped = 0; bool m_IsEquipped = 0;
uint16_t m_EnchantLevel = 0; uint16_t m_EnchantLevel = 0;
@@ -166,6 +129,5 @@ namespace L2Bot::Domain::Entities
std::wstring m_SetEffect = L""; std::wstring m_SetEffect = L"";
std::wstring m_AddSetEffect = L""; std::wstring m_AddSetEffect = L"";
std::wstring m_EnchantEffect = L""; std::wstring m_EnchantEffect = L"";
GetState m_PrevState = GetState();
}; };
} }

View File

@@ -2,8 +2,10 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
#include <functional>
#include "EntityInterface.h" #include "EntityInterface.h"
#include "../Enums/ItemTypeEnum.h" #include "../Enums/ItemTypeEnum.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::Entities namespace L2Bot::Domain::Entities
{ {
@@ -18,40 +20,36 @@ namespace L2Bot::Domain::Entities
{ {
return m_ItemId; return m_ItemId;
} }
virtual void Update(const EntityInterface* other) override void Update(
{ const uint32_t itemId,
const BaseItem* casted = static_cast<const BaseItem*>(other); const int32_t mana,
SaveState(); const std::wstring& name,
const std::wstring& iconName,
m_ObjectId = casted->m_ObjectId; const std::wstring& description,
m_ItemId = casted->m_ItemId; const uint16_t weight
m_Mana = casted->m_Mana; ) {
m_Name = casted->m_Name; m_ItemId = itemId;
m_IconName = casted->m_IconName; m_Mana = mana;
m_Description = casted->m_Description; m_Name = name;
m_Weight = casted->m_Weight; m_IconName = iconName;
m_Type = casted->m_Type; m_Description = description;
m_Weight = weight;
} }
virtual void SaveState() override virtual const size_t GetHash() const override
{ {
m_PrevState = return Helpers::CombineHashes({
{ std::hash<uint32_t>{}(m_ObjectId),
m_Mana, std::hash<uint32_t>{}(m_ItemId),
m_Weight, std::hash<uint32_t>{}(m_Mana),
false std::hash<std::wstring>{}(m_Name),
}; std::hash<std::wstring>{}(m_Description),
std::hash<std::wstring>{}(m_IconName),
std::hash<uint16_t>{}(m_Weight)
});
} }
virtual const bool IsEqual(const EntityInterface* other) const override const std::string GetEntityName() const override
{ {
const BaseItem* casted = static_cast<const BaseItem*>(other); return "item";
return m_ObjectId == casted->m_ObjectId &&
m_ItemId == casted->m_ItemId &&
m_Mana == casted->m_Mana &&
m_Name == casted->m_Name &&
m_IconName == casted->m_IconName &&
m_Description == casted->m_Description &&
m_Weight == casted->m_Weight &&
m_Type == casted->m_Type;
} }
virtual const std::vector<Serializers::Node> BuildSerializationNodes() const override virtual const std::vector<Serializers::Node> BuildSerializationNodes() const override
@@ -60,23 +58,12 @@ namespace L2Bot::Domain::Entities
result.push_back({ L"id", std::to_wstring(m_ObjectId) }); result.push_back({ L"id", std::to_wstring(m_ObjectId) });
result.push_back({ L"itemId", std::to_wstring(m_ItemId) }); result.push_back({ L"itemId", std::to_wstring(m_ItemId) });
if (m_PrevState.isNewState)
{
result.push_back({ L"type", std::to_wstring(static_cast<int8_t>(m_Type)) }); result.push_back({ L"type", std::to_wstring(static_cast<int8_t>(m_Type)) });
result.push_back({ L"name", m_Name }); result.push_back({ L"name", m_Name });
result.push_back({ L"iconName", m_IconName }); result.push_back({ L"iconName", m_IconName });
result.push_back({ L"description", m_Description }); result.push_back({ L"description", m_Description });
}
if (m_PrevState.isNewState || m_Mana != m_PrevState.mana)
{
result.push_back({ L"mana", std::to_wstring(m_Mana) }); result.push_back({ L"mana", std::to_wstring(m_Mana) });
}
if (m_PrevState.isNewState || m_Weight != m_PrevState.weight)
{
result.push_back({ L"weight", std::to_wstring(m_Weight) }); result.push_back({ L"weight", std::to_wstring(m_Weight) });
}
return result; return result;
} }
@@ -117,15 +104,6 @@ namespace L2Bot::Domain::Entities
BaseItem() = default; BaseItem() = default;
virtual ~BaseItem() = default; virtual ~BaseItem() = default;
private:
struct GetState
{
int32_t mana = -1;
uint16_t weight = 0;
bool isNewState = true;
};
private: private:
uint32_t m_ObjectId = 0; uint32_t m_ObjectId = 0;
uint32_t m_ItemId = 0; uint32_t m_ItemId = 0;
@@ -135,6 +113,5 @@ namespace L2Bot::Domain::Entities
std::wstring m_Description = L""; std::wstring m_Description = L"";
uint16_t m_Weight = 0; uint16_t m_Weight = 0;
Enums::ItemTypeEnum m_Type = Enums::ItemTypeEnum::none; Enums::ItemTypeEnum m_Type = Enums::ItemTypeEnum::none;
GetState m_PrevState = GetState();
}; };
} }

View File

@@ -0,0 +1,7 @@
#include "..\..\pch.h"
#include "ChatMessage.h"
namespace L2Bot::Domain::Entities
{
uint32_t ChatMessage::m_ChatGlobalId = 0;
}

View File

@@ -1,14 +1,34 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include "../Serializers/Serializable.h" #include <functional>
#include "EntityInterface.h"
#include "../Enums/ChatChannelEnum.h" #include "../Enums/ChatChannelEnum.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::ValueObjects namespace L2Bot::Domain::Entities
{ {
class ChatMessage : public Serializers::Serializable class ChatMessage : public EntityInterface
{ {
public: public:
const uint32_t GetId() const override
{
return m_Id;
}
const size_t GetHash() const override
{
return Helpers::CombineHashes({
std::hash<uint32_t>{}(m_Id),
std::hash<uint32_t>{}(m_ObjectId),
std::hash<Enums::ChatChannelEnum>{}(m_Channel),
std::hash<std::wstring>{}(m_Name),
std::hash<std::wstring>{}(m_Text)
});
}
const std::string GetEntityName() const override
{
return "chat";
}
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override
{ {
return std::vector<Serializers::Node> return std::vector<Serializers::Node>
@@ -26,20 +46,21 @@ namespace L2Bot::Domain::ValueObjects
const std::wstring& name, const std::wstring& name,
const std::wstring& text const std::wstring& text
) : ) :
m_Id(++m_ChatGlobalId),
m_ObjectId(objectId), m_ObjectId(objectId),
m_Channel(channel), m_Channel(channel),
m_Name(name), m_Name(name),
m_Text(text) m_Text(text)
{ {
} }
ChatMessage() = default;
virtual ~ChatMessage() = default; virtual ~ChatMessage() = default;
private: private:
uint32_t m_Id = 0;
uint32_t m_ObjectId = 0; uint32_t m_ObjectId = 0;
Enums::ChatChannelEnum m_Channel = Enums::ChatChannelEnum::all; Enums::ChatChannelEnum m_Channel = Enums::ChatChannelEnum::all;
std::wstring m_Name = L""; std::wstring m_Name = L"";
std::wstring m_Text = L""; std::wstring m_Text = L"";
static uint32_t m_ChatGlobalId;
}; };
} }

View File

@@ -8,48 +8,49 @@ namespace L2Bot::Domain::Entities
class Drop : public WorldObject class Drop : public WorldObject
{ {
public: public:
void Update(const EntityInterface* other) override void Update(
{ const ValueObjects::Transform &transform,
const Drop* casted = static_cast<const Drop*>(other); const uint32_t itemId,
WorldObject::Update(other); const uint32_t amount,
m_ItemId = casted->m_ItemId; const std::wstring& name,
m_Amount = casted->m_Amount; const std::wstring& iconName
m_Name = casted->m_Name; ) {
m_IconName = casted->m_IconName; WorldObject::Update(transform);
m_ItemId = itemId;
m_Amount = amount;
m_Name = name;
m_IconName = iconName;
} }
void SaveState() override const size_t GetHash() const override
{ {
WorldObject::SaveState(); return Helpers::CombineHashes({
m_IsNewState = false; WorldObject::GetHash(),
std::hash<uint32_t>{}(m_ItemId),
std::hash<uint32_t>{}(m_Amount),
std::hash<std::wstring>{}(m_Name),
std::hash<std::wstring>{}(m_IconName)
});
} }
const bool IsEqual(const EntityInterface* other) const override const std::string GetEntityName() const override
{ {
const Drop* casted = static_cast<const Drop*>(other); return "drop";
return WorldObject::IsEqual(other) &&
m_ItemId == casted->m_ItemId &&
m_Amount == casted->m_Amount &&
m_Name == casted->m_Name &&
m_IconName == casted->m_IconName;
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override
{ {
std::vector<Serializers::Node> result = WorldObject::BuildSerializationNodes(); std::vector<Serializers::Node> result = WorldObject::BuildSerializationNodes();
if (m_IsNewState)
{
result.push_back({ L"itemId", std::to_wstring(m_ItemId) }); result.push_back({ L"itemId", std::to_wstring(m_ItemId) });
result.push_back({ L"amount", std::to_wstring(m_Amount) }); result.push_back({ L"amount", std::to_wstring(m_Amount) });
result.push_back({ L"name", m_Name }); result.push_back({ L"name", m_Name });
result.push_back({ L"iconName", m_IconName }); result.push_back({ L"iconName", m_IconName });
}
return result; return result;
} }
Drop( Drop(
const uint32_t id, const uint32_t id,
const ValueObjects::Transform transform, const ValueObjects::Transform &transform,
const uint32_t itemId, const uint32_t itemId,
const uint32_t amount, const uint32_t amount,
const std::wstring& name, const std::wstring& name,
@@ -71,6 +72,5 @@ namespace L2Bot::Domain::Entities
uint32_t m_Amount = 0; uint32_t m_Amount = 0;
std::wstring m_Name = L""; std::wstring m_Name = L"";
std::wstring m_IconName = L""; std::wstring m_IconName = L"";
bool m_IsNewState = true;
}; };
} }

View File

@@ -2,17 +2,17 @@
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <string>
#include "../Serializers/Serializable.h" #include "../Serializers/Serializable.h"
#include "Hashable.h"
namespace L2Bot::Domain::Entities namespace L2Bot::Domain::Entities
{ {
class EntityInterface : public Serializers::Serializable class EntityInterface : public Serializers::Serializable, public Hashable
{ {
public: public:
virtual const uint32_t GetId() const = 0; virtual const uint32_t GetId() const = 0;
virtual void Update(const EntityInterface* other) = 0; virtual const std::string GetEntityName() const = 0;
virtual void SaveState() = 0;
virtual const bool IsEqual(const EntityInterface* other) const = 0;
EntityInterface() = default; EntityInterface() = default;
virtual ~EntityInterface() = default; virtual ~EntityInterface() = default;

View File

@@ -2,68 +2,59 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
#include <functional>
#include "BaseItem.h" #include "BaseItem.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::Entities namespace L2Bot::Domain::Entities
{ {
class EtcItem : public BaseItem class EtcItem : public BaseItem
{ {
public: public:
void Autouse(bool enabled) void StartAutouse()
{ {
m_IsAutoused = enabled; m_IsAutoused = true;
}
void StopAutouse()
{
m_IsAutoused = true;
} }
const bool IsAutoused() const const bool IsAutoused() const
{ {
return m_IsAutoused; return m_IsAutoused;
} }
void Update(const EntityInterface* other) override void Update(
{ const uint32_t itemId,
const EtcItem* casted = static_cast<const EtcItem*>(other); const int32_t mana,
const std::wstring& name,
const std::wstring& iconName,
const std::wstring& description,
const uint16_t weight,
const uint32_t amount,
const bool isQuest
) {
BaseItem::Update(itemId, mana, name, iconName, description, weight);
BaseItem::Update(other); m_Amount = amount;
m_IsQuest = isQuest;
m_Amount = casted->m_Amount;
m_IsQuest = casted->m_IsQuest;
m_IsAutoused = casted->m_IsAutoused;
} }
void SaveState() override const size_t GetHash() const override
{ {
BaseItem::SaveState(); return Helpers::CombineHashes({
m_PrevState = BaseItem::GetHash(),
{ std::hash<uint32_t>{}(m_Amount),
m_Amount, std::hash<bool>{}(m_IsQuest)
m_IsAutoused, });
false
};
}
const bool IsEqual(const EntityInterface* other) const override
{
const EtcItem* casted = static_cast<const EtcItem*>(other);
return BaseItem::IsEqual(other) &&
m_IsQuest == casted->m_IsQuest &&
m_Amount == casted->m_Amount &&
m_IsAutoused == casted->m_IsAutoused;
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override
{ {
std::vector<Serializers::Node> result = BaseItem::BuildSerializationNodes(); std::vector<Serializers::Node> result = BaseItem::BuildSerializationNodes();
if (m_PrevState.isNewState)
{
result.push_back({ L"isQuest", std::to_wstring(m_IsQuest) }); result.push_back({ L"isQuest", std::to_wstring(m_IsQuest) });
}
if (m_PrevState.isNewState || m_Amount != m_PrevState.amount)
{
result.push_back({ L"amount", std::to_wstring(m_Amount) }); result.push_back({ L"amount", std::to_wstring(m_Amount) });
}
if (m_PrevState.isNewState || m_IsAutoused != m_PrevState.isAutoused)
{
result.push_back({ L"isAutoused", std::to_wstring(m_IsAutoused) }); result.push_back({ L"isAutoused", std::to_wstring(m_IsAutoused) });
}
return result; return result;
} }
@@ -95,30 +86,12 @@ namespace L2Bot::Domain::Entities
{ {
} }
EtcItem(const EtcItem* other) :
BaseItem(other),
m_Amount(other->m_Amount),
m_IsAutoused(other->m_IsAutoused),
m_IsQuest(other->m_IsQuest)
{
}
EtcItem() = default; EtcItem() = default;
virtual ~EtcItem() = default; virtual ~EtcItem() = default;
private:
struct GetState
{
uint32_t amount = 0;
bool isAutoused = false;
bool isNewState = true;
};
private: private:
uint32_t m_Amount = 0; uint32_t m_Amount = 0;
bool m_IsQuest = false; bool m_IsQuest = false;
bool m_IsAutoused = false; bool m_IsAutoused = false;
GetState m_PrevState = GetState();
}; };
} }

View File

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

View File

@@ -15,114 +15,82 @@ namespace L2Bot::Domain::Entities
class Hero : public WorldObject class Hero : public WorldObject
{ {
public: public:
void Update(const EntityInterface* other) override void Update(
{ const ValueObjects::Transform& transform,
const Hero* casted = static_cast<const Hero*>(other); const ValueObjects::FullName& fullName,
WorldObject::Update(other); const ValueObjects::VitalStats& vitalStats,
m_FullName = casted->m_FullName; const ValueObjects::Phenotype& phenotype,
m_VitalStats = casted->m_VitalStats; const ValueObjects::ExperienceInfo& experienceInfo,
m_Phenotype = casted->m_Phenotype; const ValueObjects::PermanentStats& permanentStats,
m_ExperienceInfo = casted->m_ExperienceInfo; const ValueObjects::VariableStats& variableStats,
m_PermanentStats = casted->m_PermanentStats; const ValueObjects::Reputation& reputation,
m_VariableStats = casted->m_VariableStats; const ValueObjects::InventoryInfo& inventoryInfo,
m_Reputation = casted->m_Reputation; const uint32_t targetId,
m_InventoryInfo = casted->m_InventoryInfo; const bool isStanding
m_TargetId = casted->m_TargetId; ) {
m_IsStanding = casted->m_IsStanding; WorldObject::Update(transform);
m_FullName = fullName;
m_VitalStats = vitalStats;
m_Phenotype = phenotype;
m_ExperienceInfo = experienceInfo;
m_PermanentStats = permanentStats;
m_VariableStats = variableStats;
m_Reputation = reputation;
m_InventoryInfo = inventoryInfo;
m_TargetId = targetId;
m_IsStanding = isStanding;
} }
void SaveState() override const size_t GetHash() const override
{ {
WorldObject::SaveState(); return Helpers::CombineHashes({
m_PrevState = WorldObject::GetHash(),
{ m_FullName.GetHash(),
m_FullName, m_VitalStats.GetHash(),
m_VitalStats, m_Phenotype.GetHash(),
m_Phenotype, m_ExperienceInfo.GetHash(),
m_ExperienceInfo, m_PermanentStats.GetHash(),
m_PermanentStats, m_VariableStats.GetHash(),
m_VariableStats, m_Reputation.GetHash(),
m_Reputation, m_InventoryInfo.GetHash(),
m_InventoryInfo, std::hash<uint32_t>{}(m_TargetId),
m_TargetId, std::hash<uint32_t>{}(m_IsStanding)
m_IsStanding, });
false
};
} }
const bool IsEqual(const EntityInterface* other) const override const std::string GetEntityName() const override
{ {
const Hero* casted = static_cast<const Hero*>(other); return "hero";
return WorldObject::IsEqual(other) &&
m_FullName.IsEqual(&casted->m_FullName) &&
m_VitalStats.IsEqual(&casted->m_VitalStats) &&
m_Phenotype.IsEqual(&casted->m_Phenotype) &&
m_ExperienceInfo.IsEqual(&casted->m_ExperienceInfo) &&
m_PermanentStats.IsEqual(&casted->m_PermanentStats) &&
m_VariableStats.IsEqual(&casted->m_VariableStats) &&
m_Reputation.IsEqual(&casted->m_Reputation) &&
m_InventoryInfo.IsEqual(&casted->m_InventoryInfo) &&
m_TargetId == casted->m_TargetId &&
m_IsStanding == casted->m_IsStanding;
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override
{ {
std::vector<Serializers::Node> result = WorldObject::BuildSerializationNodes(); std::vector<Serializers::Node> result = WorldObject::BuildSerializationNodes();
if (m_PrevState.isNewState || !m_FullName.IsEqual(&m_PrevState.fullName))
{
result.push_back({ L"fullName", m_FullName.BuildSerializationNodes() }); result.push_back({ L"fullName", m_FullName.BuildSerializationNodes() });
}
if (m_PrevState.isNewState || !m_VitalStats.IsEqual(&m_PrevState.vitalStats))
{
result.push_back({ L"vitalStats", m_VitalStats.BuildSerializationNodes() }); result.push_back({ L"vitalStats", m_VitalStats.BuildSerializationNodes() });
}
if (m_PrevState.isNewState || !m_Phenotype.IsEqual(&m_PrevState.phenotype))
{
result.push_back({ L"phenotype", m_Phenotype.BuildSerializationNodes() }); result.push_back({ L"phenotype", m_Phenotype.BuildSerializationNodes() });
}
if (m_PrevState.isNewState || !m_ExperienceInfo.IsEqual(&m_PrevState.experienceInfo))
{
result.push_back({ L"experienceInfo", m_ExperienceInfo.BuildSerializationNodes() }); result.push_back({ L"experienceInfo", m_ExperienceInfo.BuildSerializationNodes() });
}
if (m_PrevState.isNewState || !m_PermanentStats.IsEqual(&m_PrevState.permanentStats))
{
result.push_back({ L"permanentStats", m_PermanentStats.BuildSerializationNodes() }); result.push_back({ L"permanentStats", m_PermanentStats.BuildSerializationNodes() });
}
if (m_PrevState.isNewState || !m_VariableStats.IsEqual(&m_PrevState.variableStats))
{
result.push_back({ L"variableStats", m_VariableStats.BuildSerializationNodes() }); result.push_back({ L"variableStats", m_VariableStats.BuildSerializationNodes() });
}
if (m_PrevState.isNewState || !m_Reputation.IsEqual(&m_PrevState.reputation))
{
result.push_back({ L"reputation", m_Reputation.BuildSerializationNodes() }); result.push_back({ L"reputation", m_Reputation.BuildSerializationNodes() });
}
if (m_PrevState.isNewState || !m_InventoryInfo.IsEqual(&m_PrevState.inventoryInfo))
{
result.push_back({ L"inventoryInfo", m_InventoryInfo.BuildSerializationNodes() }); result.push_back({ L"inventoryInfo", m_InventoryInfo.BuildSerializationNodes() });
}
if (m_PrevState.isNewState || m_TargetId != m_PrevState.targetId)
{
result.push_back({ L"targetId", std::to_wstring(m_TargetId) }); result.push_back({ L"targetId", std::to_wstring(m_TargetId) });
}
if (m_PrevState.isNewState || m_IsStanding != m_PrevState.isStanding)
{
result.push_back({ L"isStanding", std::to_wstring(m_IsStanding) }); result.push_back({ L"isStanding", std::to_wstring(m_IsStanding) });
}
return result; return result;
} }
Hero( Hero(
const uint32_t id, const uint32_t id,
const ValueObjects::Transform transform, const ValueObjects::Transform& transform,
const ValueObjects::FullName fullName, const ValueObjects::FullName& fullName,
const ValueObjects::VitalStats vitalStats, const ValueObjects::VitalStats& vitalStats,
const ValueObjects::Phenotype phenotype, const ValueObjects::Phenotype& phenotype,
const ValueObjects::ExperienceInfo experienceInfo, const ValueObjects::ExperienceInfo& experienceInfo,
const ValueObjects::PermanentStats permanentStats, const ValueObjects::PermanentStats& permanentStats,
const ValueObjects::VariableStats variableStats, const ValueObjects::VariableStats& variableStats,
const ValueObjects::Reputation reputation, const ValueObjects::Reputation& reputation,
const ValueObjects::InventoryInfo inventoryInfo, const ValueObjects::InventoryInfo& inventoryInfo,
const uint32_t targetId, const uint32_t targetId,
const bool isStanding const bool isStanding
) : ) :
@@ -144,23 +112,6 @@ namespace L2Bot::Domain::Entities
Hero() = default; Hero() = default;
virtual ~Hero() = default; virtual ~Hero() = default;
private:
struct GetState
{
ValueObjects::FullName fullName = ValueObjects::FullName();
ValueObjects::VitalStats vitalStats = ValueObjects::VitalStats();
ValueObjects::Phenotype phenotype = ValueObjects::Phenotype();
ValueObjects::ExperienceInfo experienceInfo = ValueObjects::ExperienceInfo();
ValueObjects::PermanentStats permanentStats = ValueObjects::PermanentStats();
ValueObjects::VariableStats variableStats = ValueObjects::VariableStats();
ValueObjects::Reputation reputation = ValueObjects::Reputation();
ValueObjects::InventoryInfo inventoryInfo = ValueObjects::InventoryInfo();
uint32_t targetId = 0;
bool isStanding = true;
bool isNewState = true;
};
private: private:
ValueObjects::FullName m_FullName = ValueObjects::FullName(); ValueObjects::FullName m_FullName = ValueObjects::FullName();
ValueObjects::VitalStats m_VitalStats = ValueObjects::VitalStats(); ValueObjects::VitalStats m_VitalStats = ValueObjects::VitalStats();
@@ -172,6 +123,5 @@ namespace L2Bot::Domain::Entities
ValueObjects::InventoryInfo m_InventoryInfo = ValueObjects::InventoryInfo(); ValueObjects::InventoryInfo m_InventoryInfo = ValueObjects::InventoryInfo();
uint32_t m_TargetId = 0; uint32_t m_TargetId = 0;
bool m_IsStanding = true; bool m_IsStanding = true;
GetState m_PrevState = GetState();
}; };
} }

View File

@@ -11,76 +11,66 @@ namespace L2Bot::Domain::Entities
class NPC : public WorldObject class NPC : public WorldObject
{ {
public: public:
void Update(const EntityInterface* other) override void UpdateSpoilState(const Enums::SpoilStateEnum spoilState)
{ {
const NPC* casted = static_cast<const NPC*>(other); m_SpoilState = spoilState;
WorldObject::Update(other);
m_IsHostile = casted->m_IsHostile;
m_NpcId = casted->m_NpcId;
m_SpoilState = casted->m_SpoilState;
m_FullName = casted->m_FullName;
m_VitalStats = casted->m_VitalStats;
} }
void SaveState() override
{ void Update(
WorldObject::SaveState(); const ValueObjects::Transform& transform,
m_PrevState = const bool isHostile,
{ const uint32_t npcId,
m_FullName, const ValueObjects::FullName& fullName,
m_SpoilState, const ValueObjects::VitalStats& vitalStats
m_VitalStats, ) {
false WorldObject::Update(transform);
};
m_IsHostile = isHostile;
m_NpcId = npcId;
m_FullName = fullName;
m_VitalStats = vitalStats;
} }
const bool IsEqual(const EntityInterface* other) const override const size_t GetHash() const override
{ {
const NPC* casted = static_cast<const NPC*>(other); return Helpers::CombineHashes({
return WorldObject::IsEqual(other) && WorldObject::GetHash(),
m_IsHostile == casted->m_IsHostile && std::hash<bool>{}(m_IsHostile),
m_NpcId == casted->m_NpcId && std::hash<uint32_t>{}(m_NpcId),
m_SpoilState == casted->m_SpoilState && std::hash<Enums::SpoilStateEnum>{}(m_SpoilState),
m_FullName.IsEqual(&casted->m_FullName) && m_FullName.GetHash(),
m_VitalStats.IsEqual(&casted->m_VitalStats); m_VitalStats.GetHash()
});
}
const std::string GetEntityName() const override
{
return "npc";
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override
{ {
std::vector<Serializers::Node> result = WorldObject::BuildSerializationNodes(); std::vector<Serializers::Node> result = WorldObject::BuildSerializationNodes();
if (m_PrevState.isNewState || !m_FullName.IsEqual(&m_PrevState.fullName))
{
result.push_back({ L"fullName", m_FullName.BuildSerializationNodes() }); result.push_back({ L"fullName", m_FullName.BuildSerializationNodes() });
}
if (m_PrevState.isNewState)
{
result.push_back({ L"isHostile", std::to_wstring(m_IsHostile) }); result.push_back({ L"isHostile", std::to_wstring(m_IsHostile) });
result.push_back({ L"npcId", std::to_wstring(m_NpcId) }); result.push_back({ L"npcId", std::to_wstring(m_NpcId) });
}
if (m_PrevState.isNewState || m_SpoilState != m_PrevState.spoilState)
{
result.push_back({ L"spoilState", std::to_wstring(static_cast<uint32_t>(m_SpoilState)) }); result.push_back({ L"spoilState", std::to_wstring(static_cast<uint32_t>(m_SpoilState)) });
}
if (m_PrevState.isNewState || !m_VitalStats.IsEqual(&m_PrevState.vitalStats))
{
result.push_back({ L"vitalStats", m_VitalStats.BuildSerializationNodes() }); result.push_back({ L"vitalStats", m_VitalStats.BuildSerializationNodes() });
}
return result; return result;
} }
NPC( NPC(
const uint32_t id, const uint32_t id,
const ValueObjects::Transform transform, const ValueObjects::Transform& transform,
const bool isHostile, const bool isHostile,
const uint32_t npcId, const uint32_t npcId,
const Enums::SpoilStateEnum spoilState, const ValueObjects::FullName& fullName,
const ValueObjects::FullName fullName, const ValueObjects::VitalStats& vitalStats
const ValueObjects::VitalStats vitalStats
) : ) :
WorldObject(id, transform), WorldObject(id, transform),
m_IsHostile(isHostile), m_IsHostile(isHostile),
m_NpcId(npcId), m_NpcId(npcId),
m_SpoilState(spoilState),
m_FullName(fullName), m_FullName(fullName),
m_VitalStats(vitalStats) m_VitalStats(vitalStats)
{ {
@@ -90,22 +80,11 @@ namespace L2Bot::Domain::Entities
NPC() = default; NPC() = default;
virtual ~NPC() = default; virtual ~NPC() = default;
private:
struct GetState
{
ValueObjects::FullName fullName = ValueObjects::FullName();
Enums::SpoilStateEnum spoilState = Enums::SpoilStateEnum::none;
ValueObjects::VitalStats vitalStats = ValueObjects::VitalStats();
bool isNewState = true;
};
private: private:
bool m_IsHostile = false; bool m_IsHostile = false;
uint32_t m_NpcId = 0; uint32_t m_NpcId = 0;
Enums::SpoilStateEnum m_SpoilState = Enums::SpoilStateEnum::none; Enums::SpoilStateEnum m_SpoilState = Enums::SpoilStateEnum::none;
ValueObjects::FullName m_FullName = ValueObjects::FullName(); ValueObjects::FullName m_FullName = ValueObjects::FullName();
ValueObjects::VitalStats m_VitalStats = ValueObjects::VitalStats(); ValueObjects::VitalStats m_VitalStats = ValueObjects::VitalStats();
GetState m_PrevState = GetState();
}; };
} }

View File

@@ -9,60 +9,49 @@ namespace L2Bot::Domain::Entities
class Player : public WorldObject class Player : public WorldObject
{ {
public: public:
void Update(const EntityInterface* other) override void Update(
{ const ValueObjects::Transform& transform,
const Player* casted = static_cast<const Player*>(other); const ValueObjects::FullName& fullName,
WorldObject::Update(other); const ValueObjects::Phenotype& phenotype,
m_FullName = casted->m_FullName; const ValueObjects::VitalStats& vitalStats
m_Phenotype = casted->m_Phenotype; ) {
m_VitalStats = casted->m_VitalStats; WorldObject::Update(transform);
m_FullName = fullName;
m_Phenotype = phenotype;
m_VitalStats = vitalStats;
} }
void SaveState() override const size_t GetHash() const override
{ {
WorldObject::SaveState(); return Helpers::CombineHashes({
m_PrevState = WorldObject::GetHash(),
{ m_FullName.GetHash(),
m_FullName, m_Phenotype.GetHash(),
m_Phenotype, m_VitalStats.GetHash()
m_VitalStats, });
false
};
} }
const bool IsEqual(const EntityInterface* other) const override const std::string GetEntityName() const override
{ {
const Player* casted = static_cast<const Player*>(other); return "player";
return WorldObject::IsEqual(other) &&
m_FullName.IsEqual(&casted->m_FullName) &&
m_Phenotype.IsEqual(&casted->m_Phenotype) &&
m_VitalStats.IsEqual(&casted->m_VitalStats);
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override
{ {
std::vector<Serializers::Node> result = WorldObject::BuildSerializationNodes(); std::vector<Serializers::Node> result = WorldObject::BuildSerializationNodes();
if (m_PrevState.isNewState || !m_FullName.IsEqual(&m_PrevState.fullName))
{
result.push_back({ L"fullName", m_FullName.BuildSerializationNodes() }); result.push_back({ L"fullName", m_FullName.BuildSerializationNodes() });
}
if (m_PrevState.isNewState || !m_Phenotype.IsEqual(&m_PrevState.phenotype))
{
result.push_back({ L"phenotype", m_Phenotype.BuildSerializationNodes() }); result.push_back({ L"phenotype", m_Phenotype.BuildSerializationNodes() });
}
if (m_PrevState.isNewState || !m_VitalStats.IsEqual(&m_PrevState.vitalStats))
{
result.push_back({ L"vitalStats", m_VitalStats.BuildSerializationNodes() }); result.push_back({ L"vitalStats", m_VitalStats.BuildSerializationNodes() });
}
return result; return result;
} }
Player( Player(
const uint32_t id, const uint32_t id,
const ValueObjects::Transform transform, const ValueObjects::Transform& transform,
const ValueObjects::FullName fullName, const ValueObjects::FullName& fullName,
const ValueObjects::Phenotype phenotype, const ValueObjects::Phenotype& phenotype,
const ValueObjects::VitalStats vitalStats const ValueObjects::VitalStats& vitalStats
) : ) :
WorldObject(id, transform), WorldObject(id, transform),
m_FullName(fullName), m_FullName(fullName),
@@ -74,20 +63,9 @@ namespace L2Bot::Domain::Entities
Player() = default; Player() = default;
virtual ~Player() = default; virtual ~Player() = default;
private:
struct GetState
{
ValueObjects::FullName fullName = ValueObjects::FullName();
ValueObjects::Phenotype phenotype = ValueObjects::Phenotype();
ValueObjects::VitalStats vitalStats = ValueObjects::VitalStats();
bool isNewState = true;
};
private: private:
ValueObjects::FullName m_FullName = ValueObjects::FullName(); ValueObjects::FullName m_FullName = ValueObjects::FullName();
ValueObjects::Phenotype m_Phenotype = ValueObjects::Phenotype(); ValueObjects::Phenotype m_Phenotype = ValueObjects::Phenotype();
ValueObjects::VitalStats m_VitalStats = ValueObjects::VitalStats(); ValueObjects::VitalStats m_VitalStats = ValueObjects::VitalStats();
GetState m_PrevState = GetState();
}; };
} }

View File

@@ -2,73 +2,62 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
#include <functional>
#include "BaseItem.h" #include "BaseItem.h"
#include "../Enums/CrystalTypeEnum.h" #include "../Enums/CrystalTypeEnum.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::Entities namespace L2Bot::Domain::Entities
{ {
class ShieldItem : public BaseItem class ShieldItem : public BaseItem
{ {
public: public:
void Update(const EntityInterface* other) override void Update(
{ const uint32_t itemId,
const ShieldItem* casted = static_cast<const ShieldItem*>(other); const int32_t mana,
const std::wstring& name,
const std::wstring& iconName,
const std::wstring& description,
const uint16_t weight,
const bool isEquipped,
const uint16_t enchantLevel,
const Enums::CrystalTypeEnum crystalType,
const int16_t evasion,
const uint32_t pDefense,
const uint16_t defRate
) {
BaseItem::Update(itemId, mana, name, iconName, description, weight);
BaseItem::Update(other); m_IsEquipped = isEquipped;
m_EnchantLevel = enchantLevel;
m_IsEquipped = casted->m_IsEquipped; m_CrystalType = crystalType;
m_EnchantLevel = casted->m_EnchantLevel; m_Evasion = evasion;
m_CrystalType = casted->m_CrystalType; m_PDefense = pDefense;
m_Evasion = casted->m_Evasion; m_DefRate = defRate;
m_PDefense = casted->m_PDefense;
m_DefRate = casted->m_DefRate;
} }
void SaveState() override const size_t GetHash() const override
{ {
BaseItem::SaveState(); return Helpers::CombineHashes({
m_PrevState = BaseItem::GetHash(),
{ std::hash<bool>{}(m_IsEquipped),
m_IsEquipped, std::hash<uint16_t>{}(m_EnchantLevel),
m_EnchantLevel, std::hash<Enums::CrystalTypeEnum>{}(m_CrystalType),
m_PDefense, std::hash<int16_t>{}(m_Evasion),
false std::hash<uint32_t>{}(m_PDefense),
}; std::hash<uint16_t>{}(m_DefRate)
} });
const bool IsEqual(const EntityInterface* other) const override
{
const ShieldItem* casted = static_cast<const ShieldItem*>(other);
return BaseItem::IsEqual(other) &&
m_IsEquipped == casted->m_IsEquipped &&
m_EnchantLevel == casted->m_EnchantLevel &&
m_CrystalType == casted->m_CrystalType &&
m_Evasion == casted->m_Evasion &&
m_PDefense == casted->m_PDefense &&
m_DefRate == casted->m_DefRate;
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override
{ {
std::vector<Serializers::Node> result = BaseItem::BuildSerializationNodes(); std::vector<Serializers::Node> result = BaseItem::BuildSerializationNodes();
if (m_PrevState.isNewState)
{
result.push_back({ L"crystalType", std::to_wstring(static_cast<int8_t>(m_CrystalType)) }); result.push_back({ L"crystalType", std::to_wstring(static_cast<int8_t>(m_CrystalType)) });
result.push_back({ L"evasion", std::to_wstring(m_Evasion) }); result.push_back({ L"evasion", std::to_wstring(m_Evasion) });
result.push_back({ L"defRate", std::to_wstring(m_DefRate) }); result.push_back({ L"defRate", std::to_wstring(m_DefRate) });
}
if (m_PrevState.isNewState || m_IsEquipped != m_PrevState.isEquipped)
{
result.push_back({ L"isEquipped", std::to_wstring(m_IsEquipped) }); result.push_back({ L"isEquipped", std::to_wstring(m_IsEquipped) });
}
if (m_PrevState.isNewState || m_EnchantLevel != m_PrevState.enchantLevel)
{
result.push_back({ L"enchantLevel", std::to_wstring(m_EnchantLevel) }); result.push_back({ L"enchantLevel", std::to_wstring(m_EnchantLevel) });
}
if (m_PrevState.isNewState || m_PDefense != m_PrevState.pDefense)
{
result.push_back({ L"pDefense", std::to_wstring(m_PDefense) }); result.push_back({ L"pDefense", std::to_wstring(m_PDefense) });
}
return result; return result;
} }
@@ -108,31 +97,9 @@ namespace L2Bot::Domain::Entities
{ {
} }
ShieldItem(const ShieldItem* other) :
BaseItem(other),
m_IsEquipped(other->m_IsEquipped),
m_EnchantLevel(other->m_EnchantLevel),
m_CrystalType(other->m_CrystalType),
m_Evasion(other->m_Evasion),
m_PDefense(other->m_PDefense),
m_DefRate(other->m_DefRate)
{
}
ShieldItem() = default; ShieldItem() = default;
virtual ~ShieldItem() = default; virtual ~ShieldItem() = default;
private:
struct GetState
{
bool isEquipped = 0;
uint16_t enchantLevel = 0;
uint32_t pDefense = 0;
bool isNewState = true;
};
private: private:
bool m_IsEquipped = 0; bool m_IsEquipped = 0;
uint16_t m_EnchantLevel = 0; uint16_t m_EnchantLevel = 0;
@@ -140,7 +107,5 @@ namespace L2Bot::Domain::Entities
int16_t m_Evasion = 0; int16_t m_Evasion = 0;
uint32_t m_PDefense = 0; uint32_t m_PDefense = 0;
uint16_t m_DefRate = 0; uint16_t m_DefRate = 0;
GetState m_PrevState = GetState();
}; };
} }

View File

@@ -2,25 +2,14 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
#include <functional>
#include "EntityInterface.h" #include "EntityInterface.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::Entities namespace L2Bot::Domain::Entities
{ {
class Skill : public EntityInterface class Skill : public EntityInterface
{ {
public:
struct Data
{
uint32_t skillId;
uint8_t level;
bool isActive;
uint8_t cost;
int16_t range;
std::wstring name;
std::wstring description;
std::wstring iconName;
};
public: public:
const uint32_t GetId() const override const uint32_t GetId() const override
{ {
@@ -59,180 +48,89 @@ namespace L2Bot::Domain::Entities
{ {
m_IsToggled = false; m_IsToggled = false;
} }
void Update(const Data &data) { void Update(
m_Level = data.level; const uint8_t level,
m_IsActive = data.isActive; const bool isActive,
m_Cost = data.cost; const uint8_t cost,
m_Range = data.range; const int16_t range,
m_Name = data.name; const std::wstring& name,
m_Description = data.description; const std::wstring& description,
m_IconName = data.iconName; const std::wstring& iconName
) {
m_Level = level;
m_IsActive = isActive;
m_Cost = cost;
m_Range = range;
m_Name = name;
m_Description = description;
m_IconName = iconName;
}
const size_t GetHash() const override
{
return Helpers::CombineHashes({
std::hash<uint32_t>{}(m_SkillId),
std::hash<uint8_t>{}(m_Level),
std::hash<bool>{}(m_IsActive),
std::hash<uint8_t>{}(m_Cost),
std::hash<int16_t>{}(m_Range),
std::hash<std::wstring>{}(m_Name),
std::hash<std::wstring>{}(m_Description),
std::hash<std::wstring>{}(m_IconName),
std::hash<bool>{}(m_IsToggled),
std::hash<bool>{}(m_IsCasting),
std::hash<bool>{}(m_IsReloading)
});
}
const std::string GetEntityName() const override
{
return "skill";
} }
/**
* @deprecated
**/
void Update(const EntityInterface* other) override
{
const Skill* casted = static_cast<const Skill*>(other);
SaveState();
m_SkillId = casted->m_SkillId;
m_Level = casted->m_Level;
m_IsActive = casted->m_IsActive;
m_Cost = casted->m_Cost;
m_Range = casted->m_Range;
m_Name = casted->m_Name;
m_Description = casted->m_Description;
m_IconName = casted->m_IconName;
m_IsToggled = casted->m_IsToggled;
m_IsCasting = casted->m_IsCasting;
m_IsReloading = casted->m_IsReloading;
}
/**
* @deprecated
**/
void SaveState() override
{
m_PrevState =
{
m_Name,
m_IconName,
m_Cost,
m_Range,
m_Description,
m_IsToggled,
m_IsCasting,
m_IsReloading,
IsReadyToUse(),
false
};
}
/**
* @deprecated
**/
const bool IsEqual(const EntityInterface* other) const override
{
const Skill* casted = static_cast<const Skill*>(other);
return m_SkillId == casted->m_SkillId &&
m_Level == casted->m_Level &&
m_IsActive == casted->m_IsActive &&
m_Cost == casted->m_Cost &&
m_Range == casted->m_Range &&
m_Name == casted->m_Name &&
m_Description == casted->m_Description &&
m_IconName == casted->m_IconName &&
m_IsToggled == casted->m_IsToggled &&
m_IsCasting == casted->m_IsCasting &&
m_IsReloading == casted->m_IsReloading;
}
/**
* @deprecated
**/
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override
{ {
std::vector<Serializers::Node> result; std::vector<Serializers::Node> result;
result.push_back({ L"id", std::to_wstring(m_SkillId) }); result.push_back({ L"id", std::to_wstring(m_SkillId) });
result.push_back({ L"level", std::to_wstring(m_Level) }); result.push_back({ L"level", std::to_wstring(m_Level) });
if (m_PrevState.isNewState)
{
result.push_back({ L"isActive", std::to_wstring(m_IsActive) }); result.push_back({ L"isActive", std::to_wstring(m_IsActive) });
}
if (m_PrevState.isNewState || m_Name != m_PrevState.name)
{
result.push_back({ L"name", m_Name }); result.push_back({ L"name", m_Name });
}
if (m_PrevState.isNewState || m_IconName != m_PrevState.iconName)
{
result.push_back({ L"iconName", m_IconName }); result.push_back({ L"iconName", m_IconName });
}
if (m_PrevState.isNewState || m_Description != m_PrevState.description)
{
result.push_back({ L"description", m_Description }); result.push_back({ L"description", m_Description });
}
if (m_PrevState.isNewState || m_Cost != m_PrevState.cost)
{
result.push_back({ L"cost", std::to_wstring(m_Cost) }); result.push_back({ L"cost", std::to_wstring(m_Cost) });
}
if (m_PrevState.isNewState || m_Range != m_PrevState.range)
{
result.push_back({ L"range", std::to_wstring(m_Range) }); result.push_back({ L"range", std::to_wstring(m_Range) });
}
if (m_PrevState.isNewState || m_IsToggled != m_PrevState.isToggled)
{
result.push_back({ L"isToggled", std::to_wstring(m_IsToggled) }); result.push_back({ L"isToggled", std::to_wstring(m_IsToggled) });
}
if (m_PrevState.isNewState || m_IsCasting != m_PrevState.isCasting)
{
result.push_back({ L"isCasting", std::to_wstring(m_IsCasting) }); result.push_back({ L"isCasting", std::to_wstring(m_IsCasting) });
}
if (m_PrevState.isNewState || m_IsReloading != m_PrevState.isReloading)
{
result.push_back({ L"isReloading", std::to_wstring(m_IsReloading) }); result.push_back({ L"isReloading", std::to_wstring(m_IsReloading) });
}
if (m_PrevState.isNewState || IsReadyToUse() != m_PrevState.isReadyToUse)
{
result.push_back({ L"isReadyToUse", std::to_wstring(IsReadyToUse()) }); result.push_back({ L"isReadyToUse", std::to_wstring(IsReadyToUse()) });
}
return result; return result;
} }
Skill(const Data &data) : Skill(
m_SkillId(data.skillId), const uint32_t skillId,
m_Level(data.level), const uint8_t level,
m_IsActive(data.isActive), const bool isActive,
m_Cost(data.cost), const uint8_t cost,
m_Range(data.range), const int16_t range,
m_Name(data.name), const std::wstring& name,
m_Description(data.description), const std::wstring& description,
m_IconName(data.iconName) const std::wstring& iconName
) :
m_SkillId(skillId),
m_Level(level),
m_IsActive(isActive),
m_Cost(cost),
m_Range(range),
m_Name(name),
m_Description(description),
m_IconName(iconName)
{ {
} }
/** Skill() = default;
* @deprecated
**/
Skill(const Skill* other) :
m_SkillId(other->m_SkillId),
m_Level(other->m_Level),
m_IsActive(other->m_IsActive),
m_Cost(other->m_Cost),
m_Range(other->m_Range),
m_Name(other->m_Name),
m_Description(other->m_Description),
m_IconName(other->m_IconName),
m_IsToggled(other->m_IsToggled),
m_IsCasting(other->m_IsCasting),
m_IsReloading(other->m_IsReloading)
{
}
virtual ~Skill() = default; virtual ~Skill() = default;
private:
/**
* @deprecated
**/
struct GetState
{
std::wstring name = L"";
std::wstring iconName = L"";
uint8_t cost = 0;
int16_t range = 0;
std::wstring description = L"";
bool isToggled = false;
bool isCasting = false;
bool isReloading = false;
bool isReadyToUse = true;
bool isNewState = true;
};
private: private:
uint32_t m_SkillId = 0; uint32_t m_SkillId = 0;
uint8_t m_Level = 0; uint8_t m_Level = 0;
@@ -245,6 +143,5 @@ namespace L2Bot::Domain::Entities
bool m_IsToggled = false; bool m_IsToggled = false;
bool m_IsCasting = false; bool m_IsCasting = false;
bool m_IsReloading = false; bool m_IsReloading = false;
GetState m_PrevState = GetState();
}; };
} }

View File

@@ -2,72 +2,78 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
#include <functional>
#include "BaseItem.h" #include "BaseItem.h"
#include "../Enums/WeaponTypeEnum.h" #include "../Enums/WeaponTypeEnum.h"
#include "../Enums/CrystalTypeEnum.h" #include "../Enums/CrystalTypeEnum.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::Entities namespace L2Bot::Domain::Entities
{ {
class WeaponItem : public BaseItem class WeaponItem : public BaseItem
{ {
public: public:
void Update(const EntityInterface* other) override void Update(
{ const uint32_t itemId,
const WeaponItem* casted = static_cast<const WeaponItem*>(other); const int32_t mana,
const std::wstring& name,
const std::wstring& iconName,
const std::wstring& description,
const uint16_t weight,
const bool isEquipped,
const uint16_t enchantLevel,
const Enums::WeaponTypeEnum weaponType,
const Enums::CrystalTypeEnum crystalType,
const uint8_t rndDamage,
const uint32_t pAttack,
const uint32_t mAttack,
const uint16_t critical,
const int8_t hitModify,
const uint16_t attackSpeed,
const uint8_t mpConsume,
const uint8_t soulshotCount,
const uint8_t spiritshotCount
) {
BaseItem::Update(itemId, mana, name, iconName, description, weight);
BaseItem::Update(other); m_IsEquipped = isEquipped;
m_EnchantLevel = enchantLevel;
m_IsEquipped = casted->m_IsEquipped; m_WeaponType = weaponType;
m_EnchantLevel = casted->m_EnchantLevel; m_CrystalType = crystalType;
m_WeaponType = casted->m_WeaponType; m_RndDamage = rndDamage;
m_CrystalType = casted->m_CrystalType; m_PAttack = pAttack;
m_PAttack = casted->m_PAttack; m_MAttack = mAttack;
m_MAttack = casted->m_MAttack; m_Critical = critical;
m_RndDamage = casted->m_RndDamage; m_HitModify = hitModify;
m_Critical = casted->m_Critical; m_AttackSpeed = attackSpeed;
m_HitModify = casted->m_HitModify; m_MpConsume = mpConsume;
m_AttackSpeed = casted->m_AttackSpeed; m_SoulshotCount = soulshotCount;
m_MpConsume = casted->m_MpConsume; m_SpiritshotCount = spiritshotCount;
m_SoulshotCount = casted->m_SoulshotCount;
m_SpiritshotCount = casted->m_SpiritshotCount;
} }
void SaveState() override const size_t GetHash() const override
{ {
BaseItem::SaveState(); return Helpers::CombineHashes({
m_PrevState = BaseItem::GetHash(),
{ std::hash<bool>{}(m_IsEquipped),
m_IsEquipped, std::hash<uint16_t>{}(m_EnchantLevel),
m_EnchantLevel, std::hash<Enums::WeaponTypeEnum>{}(m_WeaponType),
m_PAttack, std::hash<Enums::CrystalTypeEnum>{}(m_CrystalType),
m_MAttack, std::hash<uint8_t>{}(m_RndDamage),
false std::hash<uint32_t>{}(m_PAttack),
}; std::hash<uint32_t>{}(m_MAttack),
} std::hash<uint16_t>{}(m_Critical),
const bool IsEqual(const EntityInterface* other) const override std::hash<int8_t>{}(m_HitModify),
{ std::hash<uint16_t>{}(m_AttackSpeed),
const WeaponItem* casted = static_cast<const WeaponItem*>(other); std::hash<uint8_t>{}(m_MpConsume),
return BaseItem::IsEqual(other) && std::hash<uint8_t>{}(m_SoulshotCount),
m_IsEquipped == casted->m_IsEquipped && std::hash<uint8_t>{}(m_SpiritshotCount)
m_EnchantLevel == casted->m_EnchantLevel && });
m_WeaponType == casted->m_WeaponType &&
m_CrystalType == casted->m_CrystalType &&
m_PAttack == casted->m_PAttack &&
m_MAttack == casted->m_MAttack &&
m_RndDamage == casted->m_RndDamage &&
m_Critical == casted->m_Critical &&
m_HitModify == casted->m_HitModify &&
m_AttackSpeed == casted->m_AttackSpeed &&
m_MpConsume == casted->m_MpConsume &&
m_SoulshotCount == casted->m_SoulshotCount &&
m_SpiritshotCount == casted->m_SpiritshotCount;
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override
{ {
std::vector<Serializers::Node> result = BaseItem::BuildSerializationNodes(); std::vector<Serializers::Node> result = BaseItem::BuildSerializationNodes();
if (m_PrevState.isNewState)
{
result.push_back({ L"weaponType", std::to_wstring(static_cast<uint8_t>(m_WeaponType)) }); result.push_back({ L"weaponType", std::to_wstring(static_cast<uint8_t>(m_WeaponType)) });
result.push_back({ L"crystalType", std::to_wstring(static_cast<int8_t>(m_CrystalType)) }); result.push_back({ L"crystalType", std::to_wstring(static_cast<int8_t>(m_CrystalType)) });
result.push_back({ L"rndDamage", std::to_wstring(m_RndDamage) }); result.push_back({ L"rndDamage", std::to_wstring(m_RndDamage) });
@@ -77,24 +83,10 @@ namespace L2Bot::Domain::Entities
result.push_back({ L"mpConsume", std::to_wstring(m_MpConsume) }); result.push_back({ L"mpConsume", std::to_wstring(m_MpConsume) });
result.push_back({ L"soulshotCount", std::to_wstring(m_SoulshotCount) }); result.push_back({ L"soulshotCount", std::to_wstring(m_SoulshotCount) });
result.push_back({ L"spiritshotCount", std::to_wstring(m_SpiritshotCount) }); result.push_back({ L"spiritshotCount", std::to_wstring(m_SpiritshotCount) });
}
if (m_PrevState.isNewState || m_IsEquipped != m_PrevState.isEquipped)
{
result.push_back({ L"isEquipped", std::to_wstring(m_IsEquipped) }); result.push_back({ L"isEquipped", std::to_wstring(m_IsEquipped) });
}
if (m_PrevState.isNewState || m_EnchantLevel != m_PrevState.enchantLevel)
{
result.push_back({ L"enchantLevel", std::to_wstring(m_EnchantLevel) }); result.push_back({ L"enchantLevel", std::to_wstring(m_EnchantLevel) });
}
if (m_PrevState.isNewState || m_PAttack != m_PrevState.pAttack)
{
result.push_back({ L"pAttack", std::to_wstring(m_PAttack) }); result.push_back({ L"pAttack", std::to_wstring(m_PAttack) });
}
if (m_PrevState.isNewState || m_MAttack != m_PrevState.mAttack)
{
result.push_back({ L"mAttack", std::to_wstring(m_MAttack) }); result.push_back({ L"mAttack", std::to_wstring(m_MAttack) });
}
return result; return result;
} }
@@ -116,7 +108,7 @@ namespace L2Bot::Domain::Entities
const uint32_t mAttack, const uint32_t mAttack,
const uint16_t critical, const uint16_t critical,
const int8_t hitModify, const int8_t hitModify,
const uint16_t atkSpd, const uint16_t attackSpeed,
const uint8_t mpConsume, const uint8_t mpConsume,
const uint8_t soulshotCount, const uint8_t soulshotCount,
const uint8_t spiritshotCount const uint8_t spiritshotCount
@@ -141,46 +133,16 @@ namespace L2Bot::Domain::Entities
m_MAttack(mAttack), m_MAttack(mAttack),
m_Critical(critical), m_Critical(critical),
m_HitModify(hitModify), m_HitModify(hitModify),
m_AttackSpeed(atkSpd), m_AttackSpeed(attackSpeed),
m_MpConsume(mpConsume), m_MpConsume(mpConsume),
m_SoulshotCount(soulshotCount), m_SoulshotCount(soulshotCount),
m_SpiritshotCount(spiritshotCount) m_SpiritshotCount(spiritshotCount)
{ {
} }
WeaponItem(const WeaponItem* other) :
BaseItem(other),
m_IsEquipped(other->m_IsEquipped),
m_EnchantLevel(other->m_EnchantLevel),
m_WeaponType(other->m_WeaponType),
m_CrystalType(other->m_CrystalType),
m_RndDamage(other->m_RndDamage),
m_PAttack(other->m_PAttack),
m_MAttack(other->m_MAttack),
m_Critical(other->m_Critical),
m_HitModify(other->m_HitModify),
m_AttackSpeed(other->m_AttackSpeed),
m_MpConsume(other->m_MpConsume),
m_SoulshotCount(other->m_SoulshotCount),
m_SpiritshotCount(other->m_SpiritshotCount)
{
}
WeaponItem() = default; WeaponItem() = default;
virtual ~WeaponItem() = default; virtual ~WeaponItem() = default;
private:
struct GetState
{
bool isEquipped = 0;
uint16_t enchantLevel = 0;
uint32_t pAttack = 0;
uint32_t mAttack = 0;
bool isNewState = true;
};
private: private:
bool m_IsEquipped = 0; bool m_IsEquipped = 0;
uint16_t m_EnchantLevel = 0; uint16_t m_EnchantLevel = 0;
@@ -195,7 +157,5 @@ namespace L2Bot::Domain::Entities
uint8_t m_MpConsume = 0; uint8_t m_MpConsume = 0;
uint8_t m_SoulshotCount = 0; uint8_t m_SoulshotCount = 0;
uint8_t m_SpiritshotCount = 0; uint8_t m_SpiritshotCount = 0;
GetState m_PrevState = GetState();
}; };
} }

View File

@@ -1,7 +1,9 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <functional>
#include "../ValueObjects/Transform.h" #include "../ValueObjects/Transform.h"
#include "EntityInterface.h" #include "EntityInterface.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::Entities namespace L2Bot::Domain::Entities
{ {
@@ -12,22 +14,16 @@ namespace L2Bot::Domain::Entities
{ {
return m_Id; return m_Id;
} }
virtual void Update(const EntityInterface* other) override virtual void Update(const ValueObjects::Transform& transform)
{ {
SaveState(); m_Transform = transform;
const WorldObject* casted = static_cast<const WorldObject*>(other);
m_Id = casted->m_Id;
m_Transform = casted->m_Transform;
} }
virtual void SaveState() override virtual const size_t GetHash() const override
{ {
m_PrevState = { m_Transform, false }; return Helpers::CombineHashes({
} std::hash<uint32_t>{}(m_Id),
virtual const bool IsEqual(const EntityInterface* other) const override m_Transform.GetHash()
{ });
const WorldObject* casted = static_cast<const WorldObject*>(other);
return m_Id == casted->m_Id && m_Transform.IsEqual(&casted->m_Transform);
} }
virtual const std::vector<Serializers::Node> BuildSerializationNodes() const override virtual const std::vector<Serializers::Node> BuildSerializationNodes() const override
@@ -35,15 +31,12 @@ namespace L2Bot::Domain::Entities
std::vector<Serializers::Node> result; std::vector<Serializers::Node> result;
result.push_back({ L"id", std::to_wstring(GetId()) }); result.push_back({ L"id", std::to_wstring(GetId()) });
if (m_PrevState.isNewState || !m_Transform.IsEqual(&m_PrevState.transform))
{
result.push_back({ L"transform", m_Transform.BuildSerializationNodes() }); result.push_back({ L"transform", m_Transform.BuildSerializationNodes() });
}
return result; return result;
} }
WorldObject(const uint32_t id, const ValueObjects::Transform transform) : WorldObject(const uint32_t id, const ValueObjects::Transform& transform) :
m_Id(id), m_Transform(transform) m_Id(id), m_Transform(transform)
{ {
@@ -51,18 +44,9 @@ namespace L2Bot::Domain::Entities
WorldObject() = default; WorldObject() = default;
virtual ~WorldObject() = default; virtual ~WorldObject() = default;
private:
private:
struct GetState
{
ValueObjects::Transform transform = ValueObjects::Transform();
bool isNewState = true;
};
private: private:
uint32_t m_Id = 0; uint32_t m_Id = 0;
ValueObjects::Transform m_Transform = ValueObjects::Transform(); ValueObjects::Transform m_Transform = ValueObjects::Transform();
GetState m_PrevState = GetState();
}; };
} }

View File

@@ -0,0 +1,14 @@
#include "..\..\pch.h"
#include "HashCombiner.h"
namespace L2Bot::Domain::Helpers
{
const size_t CombineHashes(const std::vector<size_t> hashes, size_t seed)
{
for (const auto hash : hashes) {
seed = hash + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
return seed;
}
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include <vector>
namespace L2Bot::Domain::Helpers
{
const size_t CombineHashes(const std::vector<size_t> hashes, size_t seed = 0);
}

View File

@@ -1,12 +0,0 @@
#pragma once
#include <vector>
#include "../ValueObjects/ChatMessage.h"
namespace L2Bot::Domain::Repositories
{
class ChatMessageRepositoryInterface
{
public:
virtual const std::vector<ValueObjects::ChatMessage> GetMessages() = 0;
};
}

View File

@@ -1,15 +1,13 @@
#pragma once #pragma once
#include <vector> #include <unordered_map>
#include <memory> #include "../Entities/EntityInterface.h"
#include "../Entities/WorldObject.h"
#include "../DTO/EntityState.h"
namespace L2Bot::Domain::Repositories namespace L2Bot::Domain::Repositories
{ {
class EntityRepositoryInterface class EntityRepositoryInterface
{ {
public: public:
virtual const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() = 0; virtual const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() = 0;
virtual void Reset() = 0; virtual void Reset() = 0;
}; };
} }

View File

@@ -1,25 +0,0 @@
#pragma once
#include <vector>
#include "../Repositories/ChatMessageRepositoryInterface.h"
namespace L2Bot::Domain::Services
{
class ChatMessageHandler
{
public:
ChatMessageHandler(Repositories::ChatMessageRepositoryInterface& repository) : m_Repository(repository)
{
}
ChatMessageHandler() = delete;
virtual ~ChatMessageHandler() = default;
virtual const std::vector<ValueObjects::ChatMessage> GetMessages()
{
return m_Repository.GetMessages();
}
private:
Repositories::ChatMessageRepositoryInterface& m_Repository;
};
}

View File

@@ -1,34 +0,0 @@
#pragma once
#include <cstdint>
#include <map>
#include <vector>
#include <math.h>
#include "../DTO/EntityState.h"
#include "../Entities/WorldObject.h"
#include "../Repositories/EntityRepositoryInterface.h"
namespace L2Bot::Domain::Services
{
class EntityHandler
{
public:
EntityHandler(Repositories::EntityRepositoryInterface& repository) : m_Repository(repository)
{
}
EntityHandler() = delete;
virtual ~EntityHandler() = default;
virtual const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities()
{
return m_Repository.GetEntities();
}
void Invalidate()
{
m_Repository.Reset();
}
private:
Repositories::EntityRepositoryInterface& m_Repository;
};
}

View File

@@ -0,0 +1,61 @@
#pragma once
#include <unordered_map>
#include <vector>
#include <memory>
#include <string>
#include <tuple>
#include "../Entities/EntityInterface.h"
#include "../Enums/EntityStateEnum.h"
namespace L2Bot::Domain::Services
{
class UnitOfWork
{
public:
const std::unordered_map<uint32_t, Enums::EntityStateEnum> ConnectEntities(const std::wstring& name, const std::unordered_map<uint32_t, std::shared_ptr<Entities::EntityInterface>>& entites)
{
std::unordered_map<uint32_t, Enums::EntityStateEnum> result;
auto& hashes = m_Hashes[name];
for (const auto& kvp : entites) {
const auto &entity = kvp.second;
if (hashes.size() == 0) {
result[entity->GetId()] = Enums::EntityStateEnum::created;
}
else
{
if (hashes.find(entity->GetId()) == hashes.end()) {
result[entity->GetId()] = Enums::EntityStateEnum::created;
}
else if (hashes[entity->GetId()] != entity->GetHash()) {
result[entity->GetId()] = Enums::EntityStateEnum::updated;
}
}
hashes[entity->GetId()] = entity->GetHash();
}
for (auto it = hashes.begin(); it != hashes.end();)
{
if (entites.find(it->first) == entites.end())
{
result[it->first] = Enums::EntityStateEnum::deleted;
it = hashes.erase(it);
}
else
{
++it;
}
}
return result;
}
private:
std::unordered_map <std::wstring, std::unordered_map<uint32_t, size_t>> m_Hashes;
};
}

View File

@@ -1,10 +1,13 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <functional>
#include "../Serializers/Serializable.h" #include "../Serializers/Serializable.h"
#include "../Entities/Hashable.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::ValueObjects namespace L2Bot::Domain::ValueObjects
{ {
class ExperienceInfo : public Serializers::Serializable class ExperienceInfo : public Serializers::Serializable, public Entities::Hashable
{ {
public: public:
const uint8_t GetLevel() const const uint8_t GetLevel() const
@@ -19,9 +22,13 @@ namespace L2Bot::Domain::ValueObjects
{ {
return m_Sp; return m_Sp;
} }
const bool IsEqual(const ExperienceInfo* other) const const size_t GetHash() const override
{ {
return m_Level == other->m_Level && m_Exp == other->m_Exp && m_Sp == other->m_Sp; return Helpers::CombineHashes({
std::hash<uint8_t>{}(m_Level),
std::hash<uint32_t>{}(m_Exp),
std::hash<uint32_t>{}(m_Sp)
});
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override

View File

@@ -1,10 +1,13 @@
#pragma once #pragma once
#include <string> #include <string>
#include <functional>
#include "../Serializers/Serializable.h" #include "../Serializers/Serializable.h"
#include "../Entities/Hashable.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::ValueObjects namespace L2Bot::Domain::ValueObjects
{ {
class FullName : public Serializers::Serializable class FullName : public Serializers::Serializable, public Entities::Hashable
{ {
public: public:
const std::wstring& GetNickname() const const std::wstring& GetNickname() const
@@ -15,9 +18,12 @@ namespace L2Bot::Domain::ValueObjects
{ {
return m_Title; return m_Title;
} }
const bool IsEqual(const FullName* other) const const size_t GetHash() const override
{ {
return m_Nickname == other->m_Nickname && m_Title == other->m_Title; return Helpers::CombineHashes({
std::hash<std::wstring>{}(m_Nickname),
std::hash<std::wstring>{}(m_Title)
});
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override

View File

@@ -1,10 +1,13 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <functional>
#include "../Serializers/Serializable.h" #include "../Serializers/Serializable.h"
#include "../Entities/Hashable.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::ValueObjects namespace L2Bot::Domain::ValueObjects
{ {
class InventoryInfo : public Serializers::Serializable class InventoryInfo : public Serializers::Serializable, public Entities::Hashable
{ {
public: public:
const uint32_t GetMaxWeight() const const uint32_t GetMaxWeight() const
@@ -19,11 +22,13 @@ namespace L2Bot::Domain::ValueObjects
{ {
return m_Slots; return m_Slots;
} }
const bool IsEqual(const InventoryInfo* other) const const size_t GetHash() const override
{ {
return m_MaxWeight == other->m_MaxWeight && return Helpers::CombineHashes({
m_Weight == other->m_Weight && std::hash<uint32_t>{}(m_MaxWeight),
m_Slots == other->m_Slots; std::hash<uint32_t>{}(m_Weight),
std::hash<uint16_t>{}(m_Slots)
});
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override

View File

@@ -1,10 +1,13 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <functional>
#include "../Serializers/Serializable.h" #include "../Serializers/Serializable.h"
#include "../Entities/Hashable.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::ValueObjects namespace L2Bot::Domain::ValueObjects
{ {
class PermanentStats : public Serializers::Serializable class PermanentStats : public Serializers::Serializable, public Entities::Hashable
{ {
public: public:
const uint16_t GetStr() const const uint16_t GetStr() const
@@ -31,14 +34,16 @@ namespace L2Bot::Domain::ValueObjects
{ {
return m_Wit; return m_Wit;
} }
const bool IsEqual(const PermanentStats* other) const const size_t GetHash() const override
{ {
return m_Str == other->m_Str && return Helpers::CombineHashes({
m_Dex == other->m_Dex && std::hash<uint16_t>{}(m_Str),
m_Con == other->m_Con && std::hash<uint16_t>{}(m_Dex),
m_Int == other->m_Int && std::hash<uint16_t>{}(m_Con),
m_Men == other->m_Men && std::hash<uint16_t>{}(m_Int),
m_Wit == other->m_Wit; std::hash<uint16_t>{}(m_Men),
std::hash<uint16_t>{}(m_Wit)
});
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override

View File

@@ -1,11 +1,14 @@
#pragma once #pragma once
#include <functional>
#include "../Enums/RaceEnum.h" #include "../Enums/RaceEnum.h"
#include "../Enums/ClassEnum.h" #include "../Enums/ClassEnum.h"
#include "../Serializers/Serializable.h" #include "../Serializers/Serializable.h"
#include "../Entities/Hashable.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::ValueObjects namespace L2Bot::Domain::ValueObjects
{ {
class Phenotype : public Serializers::Serializable class Phenotype : public Serializers::Serializable, public Entities::Hashable
{ {
public: public:
const bool IsSubClass() const const bool IsSubClass() const
@@ -28,12 +31,14 @@ namespace L2Bot::Domain::ValueObjects
{ {
return m_ActiveClass; return m_ActiveClass;
} }
const bool IsEqual(const Phenotype* other) const const size_t GetHash() const override
{ {
return m_Race == other->m_Race && return Helpers::CombineHashes({
m_IsMale == other->m_IsMale && std::hash<Enums::RaceEnum>{}(m_Race),
m_Class == other->m_Class && std::hash<bool>{}(m_IsMale),
m_ActiveClass == other->m_ActiveClass; std::hash<Enums::ClassEnum>{}(m_Class),
std::hash<Enums::ClassEnum>{}(m_ActiveClass)
});
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override

View File

@@ -1,10 +1,13 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <functional>
#include "../Serializers/Serializable.h" #include "../Serializers/Serializable.h"
#include "../Entities/Hashable.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::ValueObjects namespace L2Bot::Domain::ValueObjects
{ {
class Reputation : public Serializers::Serializable class Reputation : public Serializers::Serializable, public Entities::Hashable
{ {
public: public:
const bool IsPlayerKiller() const const bool IsPlayerKiller() const
@@ -31,13 +34,15 @@ namespace L2Bot::Domain::ValueObjects
{ {
return m_EvalScore; return m_EvalScore;
} }
const bool IsEqual(const Reputation* other) const const size_t GetHash() const override
{ {
return m_Karma == other->m_Karma && return Helpers::CombineHashes({
m_PkKills == other->m_PkKills && std::hash<uint16_t>{}(m_Karma),
m_PvpKills == other->m_PvpKills && std::hash<uint16_t>{}(m_PkKills),
m_RecRemaining == other->m_RecRemaining && std::hash<uint16_t>{}(m_PvpKills),
m_EvalScore == other->m_EvalScore; std::hash<uint8_t>{}(m_RecRemaining),
std::hash<uint8_t>{}(m_EvalScore)
});
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override

View File

@@ -1,10 +1,12 @@
#pragma once #pragma once
#include "../ValueObjects/Vector3.h" #include "../ValueObjects/Vector3.h"
#include "../Serializers/Serializable.h" #include "../Serializers/Serializable.h"
#include "../Entities/Hashable.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::ValueObjects namespace L2Bot::Domain::ValueObjects
{ {
class Transform : public Serializers::Serializable class Transform : public Serializers::Serializable, public Entities::Hashable
{ {
public: public:
const Vector3& GetPosition() const const Vector3& GetPosition() const
@@ -23,12 +25,14 @@ namespace L2Bot::Domain::ValueObjects
{ {
return m_Acceleration; return m_Acceleration;
} }
const bool IsEqual(const Transform* other) const const size_t GetHash() const override
{ {
return m_Position.IsEqual(&other->m_Position) && return Helpers::CombineHashes({
m_Rotation.IsEqual(&other->m_Rotation) && m_Position.GetHash(),
m_Velocity.IsEqual(&other->m_Velocity) && m_Rotation.GetHash(),
m_Acceleration.IsEqual(&other->m_Acceleration); m_Velocity.GetHash(),
m_Acceleration.GetHash()
});
} }
const float_t GetSqrDistance(const Transform& other) const const float_t GetSqrDistance(const Transform& other) const
{ {

View File

@@ -1,10 +1,13 @@
#pragma once #pragma once
#include <functional>
#include <cstdint> #include <cstdint>
#include "../Serializers/Serializable.h" #include "../Serializers/Serializable.h"
#include "../Entities/Hashable.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::ValueObjects namespace L2Bot::Domain::ValueObjects
{ {
class VariableStats : public Serializers::Serializable class VariableStats : public Serializers::Serializable, public Entities::Hashable
{ {
public: public:
const uint16_t GetAccuracy() const const uint16_t GetAccuracy() const
@@ -43,17 +46,19 @@ namespace L2Bot::Domain::ValueObjects
{ {
return m_CastingSpeed; return m_CastingSpeed;
} }
const bool IsEqual(const VariableStats* other) const const size_t GetHash() const override
{ {
return m_Accuracy == other->m_Accuracy && return Helpers::CombineHashes({
m_CritRate == other->m_CritRate && std::hash<uint16_t>{}(m_Accuracy),
m_PAttack == other->m_PAttack && std::hash<uint16_t>{}(m_CritRate),
m_AttackSpeed == other->m_AttackSpeed && std::hash<uint32_t>{}(m_PAttack),
m_PDefense == other->m_PDefense && std::hash<uint16_t>{}(m_AttackSpeed),
m_Evasion == other->m_Evasion && std::hash<uint32_t>{}(m_PDefense),
m_MAttack == other->m_MAttack && std::hash<uint16_t>{}(m_Evasion),
m_MDefense == other->m_MDefense && std::hash<uint32_t>{}(m_MAttack),
m_CastingSpeed == other->m_CastingSpeed; std::hash<uint32_t>{}(m_MDefense),
std::hash<uint16_t>{}(m_CastingSpeed)
});
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override

View File

@@ -1,10 +1,13 @@
#pragma once #pragma once
#include <math.h> #include <math.h>
#include <functional>
#include "../Serializers/Serializable.h" #include "../Serializers/Serializable.h"
#include "../Entities/Hashable.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::ValueObjects namespace L2Bot::Domain::ValueObjects
{ {
class Vector3 : public Serializers::Serializable class Vector3 : public Serializers::Serializable, public Entities::Hashable
{ {
public: public:
const float_t GetX() const const float_t GetX() const
@@ -19,12 +22,17 @@ namespace L2Bot::Domain::ValueObjects
{ {
return m_Z; return m_Z;
} }
const bool IsEqual(const Vector3* other) const const size_t GetHash() const override
{ {
float_t epsilon = 0.0001f; const auto x = std::round(m_X * 10000.0f) / 10000.0f;
return fabsf(m_X - other->m_X) < epsilon && const auto y = std::round(m_Y * 10000.0f) / 10000.0f;
fabsf(m_Y - other->m_Y) < epsilon && const auto z = std::round(m_Z * 10000.0f) / 10000.0f;
fabsf(m_Z - other->m_Z) < epsilon;
return Helpers::CombineHashes({
std::hash<float_t>{}(m_X),
std::hash<float_t>{}(m_Y),
std::hash<float_t>{}(m_Z)
});
} }
const float_t GetSqrDistance(const Vector3& other) const const float_t GetSqrDistance(const Vector3& other) const
{ {

View File

@@ -1,10 +1,13 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <functional>
#include "../Serializers/Serializable.h" #include "../Serializers/Serializable.h"
#include "../Entities/Hashable.h"
#include "../Helpers/HashCombiner.h"
namespace L2Bot::Domain::ValueObjects namespace L2Bot::Domain::ValueObjects
{ {
class VitalStats : public Serializers::Serializable class VitalStats : public Serializers::Serializable, public Entities::Hashable
{ {
public: public:
const bool IsAlive() const const bool IsAlive() const
@@ -35,14 +38,16 @@ namespace L2Bot::Domain::ValueObjects
{ {
return m_Cp; return m_Cp;
} }
const bool IsEqual(const VitalStats* other) const const size_t GetHash() const override
{ {
return m_MaxHp == other->m_MaxHp && return Helpers::CombineHashes({
m_Hp == other->m_Hp && std::hash<uint32_t>{}(m_MaxHp),
m_MaxMp == other->m_MaxMp && std::hash<uint32_t>{}(m_Hp),
m_Mp == other->m_Mp && std::hash<uint32_t>{}(m_MaxMp),
m_MaxCp == other->m_MaxCp && std::hash<uint32_t>{}(m_Mp),
m_Cp == other->m_Cp; std::hash<uint32_t>{}(m_MaxCp),
std::hash<uint32_t>{}(m_Cp)
});
} }
const std::vector<Serializers::Node> BuildSerializationNodes() const override const std::vector<Serializers::Node> BuildSerializationNodes() const override

View File

@@ -166,6 +166,7 @@
<ClInclude Include="Domain\Entities\EntityInterface.h" /> <ClInclude Include="Domain\Entities\EntityInterface.h" />
<ClInclude Include="Domain\Entities\BaseItem.h" /> <ClInclude Include="Domain\Entities\BaseItem.h" />
<ClInclude Include="Domain\Entities\EtcItem.h" /> <ClInclude Include="Domain\Entities\EtcItem.h" />
<ClInclude Include="Domain\Entities\Hashable.h" />
<ClInclude Include="Domain\Entities\ShieldItem.h" /> <ClInclude Include="Domain\Entities\ShieldItem.h" />
<ClInclude Include="Domain\Entities\Skill.h" /> <ClInclude Include="Domain\Entities\Skill.h" />
<ClInclude Include="Domain\Entities\WeaponItem.h" /> <ClInclude Include="Domain\Entities\WeaponItem.h" />
@@ -174,12 +175,11 @@
<ClInclude Include="Domain\Enums\ChatChannelEnum.h" /> <ClInclude Include="Domain\Enums\ChatChannelEnum.h" />
<ClInclude Include="Domain\Enums\ItemTypeEnum.h" /> <ClInclude Include="Domain\Enums\ItemTypeEnum.h" />
<ClInclude Include="Domain\Enums\WeaponTypeEnum.h" /> <ClInclude Include="Domain\Enums\WeaponTypeEnum.h" />
<ClInclude Include="Domain\Repositories\ChatMessageRepositoryInterface.h" />
<ClInclude Include="Domain\Serializers\IncomingMessageFactoryInterface.h" /> <ClInclude Include="Domain\Serializers\IncomingMessageFactoryInterface.h" />
<ClInclude Include="Domain\Serializers\IncomingMessage.h" /> <ClInclude Include="Domain\Serializers\IncomingMessage.h" />
<ClInclude Include="Domain\Services\ChatMessageHandler.h" />
<ClInclude Include="Domain\Services\HeroServiceInterface.h" /> <ClInclude Include="Domain\Services\HeroServiceInterface.h" />
<ClInclude Include="Domain\ValueObjects\ChatMessage.h" /> <ClInclude Include="Domain\Entities\ChatMessage.h" />
<ClInclude Include="Domain\Services\UnitOfWork.h" />
<ClInclude Include="Domain\ValueObjects\Vector3.h" /> <ClInclude Include="Domain\ValueObjects\Vector3.h" />
<ClInclude Include="Domain\Enums\SpoilStateEnum.h" /> <ClInclude Include="Domain\Enums\SpoilStateEnum.h" />
<ClInclude Include="Domain\Transports\TransportInterface.h" /> <ClInclude Include="Domain\Transports\TransportInterface.h" />
@@ -195,7 +195,6 @@
<ClInclude Include="Domain\Serializers\Node.h" /> <ClInclude Include="Domain\Serializers\Node.h" />
<ClInclude Include="Domain\Serializers\Serializable.h" /> <ClInclude Include="Domain\Serializers\Serializable.h" />
<ClInclude Include="Domain\Serializers\SerializerInterface.h" /> <ClInclude Include="Domain\Serializers\SerializerInterface.h" />
<ClInclude Include="Domain\Services\EntityHandler.h" />
<ClInclude Include="Domain\ValueObjects\ExperienceInfo.h" /> <ClInclude Include="Domain\ValueObjects\ExperienceInfo.h" />
<ClInclude Include="Domain\ValueObjects\FullName.h" /> <ClInclude Include="Domain\ValueObjects\FullName.h" />
<ClInclude Include="Domain\ValueObjects\InventoryInfo.h" /> <ClInclude Include="Domain\ValueObjects\InventoryInfo.h" />
@@ -206,9 +205,16 @@
<ClInclude Include="Domain\ValueObjects\VariableStats.h" /> <ClInclude Include="Domain\ValueObjects\VariableStats.h" />
<ClInclude Include="Domain\ValueObjects\VitalStats.h" /> <ClInclude Include="Domain\ValueObjects\VitalStats.h" />
<ClInclude Include="framework.h" /> <ClInclude Include="framework.h" />
<ClInclude Include="Domain\Helpers\HashCombiner.h" />
<ClInclude Include="pch.h" /> <ClInclude Include="pch.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Domain\Entities\ChatMessage.cpp">
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\pch.h</PrecompiledHeaderFile>
</ClCompile>
<ClCompile Include="Domain\Helpers\HashCombiner.cpp">
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\pch.h</PrecompiledHeaderFile>
</ClCompile>
<ClCompile Include="pch.cpp"> <ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>

View File

@@ -72,9 +72,6 @@
<ClInclude Include="Domain\ValueObjects\VitalStats.h"> <ClInclude Include="Domain\ValueObjects\VitalStats.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Domain\Services\EntityHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Repositories\EntityRepositoryInterface.h"> <ClInclude Include="Domain\Repositories\EntityRepositoryInterface.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
@@ -138,13 +135,7 @@
<ClInclude Include="Domain\Enums\ChatChannelEnum.h"> <ClInclude Include="Domain\Enums\ChatChannelEnum.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Domain\ValueObjects\ChatMessage.h"> <ClInclude Include="Domain\Entities\ChatMessage.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Services\ChatMessageHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Repositories\ChatMessageRepositoryInterface.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Domain\DTO\Message.h"> <ClInclude Include="Domain\DTO\Message.h">
@@ -159,10 +150,25 @@
<ClInclude Include="Domain\Services\HeroServiceInterface.h"> <ClInclude Include="Domain\Services\HeroServiceInterface.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Domain\Entities\Hashable.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Helpers\HashCombiner.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Domain\Services\UnitOfWork.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="pch.cpp"> <ClCompile Include="pch.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Domain\Helpers\HashCombiner.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Domain\Entities\ChatMessage.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -188,7 +188,6 @@
<ClInclude Include="Serializers\JsonSerializer.h" /> <ClInclude Include="Serializers\JsonSerializer.h" />
<ClInclude Include="Versions\Interlude\Services\HeroService.h" /> <ClInclude Include="Versions\Interlude\Services\HeroService.h" />
<ClInclude Include="Services\WorldHandler.h" /> <ClInclude Include="Services\WorldHandler.h" />
<ClInclude Include="Services\EntityFinder.h" />
<ClInclude Include="ThirdParty\json.hpp" /> <ClInclude Include="ThirdParty\json.hpp" />
<ClInclude Include="Versions\GameStructs\FNameInterface.h" /> <ClInclude Include="Versions\GameStructs\FNameInterface.h" />
<ClInclude Include="Versions\GameStructs\GameEngineInterface.h" /> <ClInclude Include="Versions\GameStructs\GameEngineInterface.h" />

View File

@@ -126,9 +126,6 @@
<ClInclude Include="Serializers\JsonSerializer.h"> <ClInclude Include="Serializers\JsonSerializer.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Services\EntityFinder.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Versions\Interlude\Factories\HeroFactory.h"> <ClInclude Include="Versions\Interlude\Factories\HeroFactory.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>

View File

@@ -1,85 +0,0 @@
#pragma once
#include <map>
#include <functional>
#include <memory>
#include "Domain/Repositories/EntityRepositoryInterface.h"
#include "Domain/DTO/EntityState.h"
using namespace L2Bot::Domain;
class EntityFinder
{
public:
template<typename T>
const std::map<uint32_t, std::shared_ptr<DTO::EntityState>>& FindEntities(const std::map<uint32_t, T> items, std::function<std::shared_ptr<Entities::EntityInterface>(T)> callback)
{
RemoveOutdatedStates();
for (const auto& kvp : items)
{
const auto item = kvp.second;
auto newObject = callback(item);
if (m_Objects.contains(newObject->GetId()))
{
if (!m_Objects[kvp.first]->GetEntity()->IsEqual(newObject.get())) {
m_Objects[kvp.first]->GetEntity()->Update(newObject.get());
m_Objects[kvp.first]->UpdateState(Enums::EntityStateEnum::updated);
}
else
{
m_Objects[kvp.first]->UpdateState(Enums::EntityStateEnum::none);
}
}
else
{
const auto objectId = newObject->GetId();
m_Objects.emplace(
objectId,
std::make_shared<DTO::EntityState>(newObject, Enums::EntityStateEnum::created)
);
}
}
for (auto& kvp : m_Objects)
{
if (!items.contains(kvp.second->GetEntity()->GetId()))
{
m_Objects[kvp.first]->GetEntity()->SaveState();
kvp.second->UpdateState(Enums::EntityStateEnum::deleted);
}
}
return m_Objects;
}
void Reset()
{
m_Objects.clear();
}
EntityFinder() = default;
virtual ~EntityFinder()
{
Reset();
}
private:
void RemoveOutdatedStates()
{
auto it = m_Objects.begin();
while (it != m_Objects.end())
{
if (it->second->GetState() == Enums::EntityStateEnum::deleted)
{
m_Objects.erase(it++);
}
else
{
it++;
}
}
}
private:
std::map<uint32_t, std::shared_ptr<DTO::EntityState>> m_Objects;
};

View File

@@ -4,14 +4,13 @@
#include <thread> #include <thread>
#include <memory> #include <memory>
#include <Windows.h> #include <Windows.h>
#include "Domain/Services/EntityHandler.h"
#include "Domain/Services/ChatMessageHandler.h"
#include "Domain/Services/HeroServiceInterface.h" #include "Domain/Services/HeroServiceInterface.h"
#include "Domain/Serializers/SerializerInterface.h" #include "Domain/Serializers/SerializerInterface.h"
#include "Domain/Serializers/IncomingMessageFactoryInterface.h" #include "Domain/Serializers/IncomingMessageFactoryInterface.h"
#include "Domain/Repositories/EntityRepositoryInterface.h" #include "Domain/Repositories/EntityRepositoryInterface.h"
#include "Domain/Transports/TransportInterface.h" #include "Domain/Transports/TransportInterface.h"
#include "Domain/DTO/Message.h" #include "Domain/DTO/Message.h"
#include "Domain/Services/UnitOfWork.h"
using namespace L2Bot::Domain; using namespace L2Bot::Domain;
@@ -26,20 +25,20 @@ public:
Repositories::EntityRepositoryInterface& skillRepository, Repositories::EntityRepositoryInterface& skillRepository,
Repositories::EntityRepositoryInterface& itemRepository, Repositories::EntityRepositoryInterface& itemRepository,
Repositories::EntityRepositoryInterface& abnormalEffectRepository, Repositories::EntityRepositoryInterface& abnormalEffectRepository,
Repositories::ChatMessageRepositoryInterface& chatMessageRepository, Repositories::EntityRepositoryInterface& chatMessageRepository,
const Serializers::SerializerInterface& serializer, const Serializers::SerializerInterface& serializer,
const Serializers::IncomingMessageFactoryInterface& incomingMessageFactory, const Serializers::IncomingMessageFactoryInterface& incomingMessageFactory,
Services::HeroServiceInterface& heroService, Services::HeroServiceInterface& heroService,
Transports::TransportInterface& transport Transports::TransportInterface& transport
) : ) :
m_HeroHandler(Services::EntityHandler(heroRepository)), m_HeroRepository(heroRepository),
m_DropHandler(Services::EntityHandler(dropRepository)), m_DropRepository(dropRepository),
m_NPCHandler(Services::EntityHandler(npcRepository)), m_NPCRepository(npcRepository),
m_PlayerHandler(Services::EntityHandler(playerRepository)), m_PlayerRepository(playerRepository),
m_SkillHandler(Services::EntityHandler(skillRepository)), m_SkillRepository(skillRepository),
m_ItemHandler(Services::EntityHandler(itemRepository)), m_ItemRepository(itemRepository),
m_AbnormalEffectHandler(Services::EntityHandler(abnormalEffectRepository)), m_AbnormalEffectRepository(abnormalEffectRepository),
m_ChatMessageHandler(Services::ChatMessageHandler(chatMessageRepository)), m_ChatMessageRepository(chatMessageRepository),
m_Serializer(serializer), m_Serializer(serializer),
m_IncomingMessageFactory(incomingMessageFactory), m_IncomingMessageFactory(incomingMessageFactory),
m_HeroService(heroService), m_HeroService(heroService),
@@ -157,34 +156,56 @@ private:
const std::vector<std::vector<Serializers::Node>> GetData() const std::vector<std::vector<Serializers::Node>> GetData()
{ {
std::map<std::wstring, Services::EntityHandler> handlers std::map<std::wstring, Repositories::EntityRepositoryInterface&> handlers
{ {
{L"hero", m_HeroHandler}, {L"hero", m_HeroRepository},
{L"drop", m_DropHandler}, {L"drop", m_DropRepository},
{L"npc", m_NPCHandler}, {L"npc", m_NPCRepository},
{L"player", m_PlayerHandler}, {L"player", m_PlayerRepository},
{L"skill", m_SkillHandler}, {L"skill", m_SkillRepository},
{L"item", m_ItemHandler}, {L"item", m_ItemRepository},
{L"abnormalEffect", m_AbnormalEffectHandler} {L"abnormalEffect", m_AbnormalEffectRepository},
{L"chat", m_ChatMessageRepository}
}; };
std::vector<std::vector<Serializers::Node>> result; std::vector<std::vector<Serializers::Node>> result;
for (auto& kvp : handlers) for (const auto& kvp : handlers)
{ {
for (const auto& entity : kvp.second.GetEntities()) auto& entities = kvp.second.GetEntities();
const auto& changes = m_UnitOfWork.ConnectEntities(kvp.first, entities);
for (const auto &changeKvp : changes) {
const auto id = changeKvp.first;
std::wstring operation = L"none";
switch (changeKvp.second)
{ {
if (entity->GetState() != Enums::EntityStateEnum::none) case Enums::EntityStateEnum::created:
{ operation = L"create";
const auto message = DTO::Message{ kvp.first, entity->GetState(), *entity->GetEntity().get() }; break;
result.push_back(message.BuildSerializationNodes()); case Enums::EntityStateEnum::updated:
operation = L"update";
break;
case Enums::EntityStateEnum::deleted:
operation = L"delete";
}
if (entities.find(id) != entities.end()) {
result.push_back({
Serializers::Node{ L"type", kvp.first },
Serializers::Node{ L"operation", operation },
Serializers::Node{ L"content", entities.at(id)->BuildSerializationNodes()}
});
}
else {
result.push_back({
Serializers::Node{ L"type", kvp.first },
Serializers::Node{ L"operation", operation },
Serializers::Node{ L"content", {Serializers::Node{ L"id", std::to_wstring(id) }}}
});
} }
};
} }
for (const auto& chatMessage : m_ChatMessageHandler.GetMessages())
{
const auto message = DTO::Message{ L"chat", Enums::EntityStateEnum::created, chatMessage };
result.push_back(message.BuildSerializationNodes());
} }
return result; return result;
@@ -192,24 +213,24 @@ private:
void Invalidate() void Invalidate()
{ {
m_DropHandler.Invalidate(); m_DropRepository.Reset();
m_HeroHandler.Invalidate(); m_HeroRepository.Reset();
m_NPCHandler.Invalidate(); m_NPCRepository.Reset();
m_PlayerHandler.Invalidate(); m_PlayerRepository.Reset();
m_SkillHandler.Invalidate(); m_SkillRepository.Reset();
m_ItemHandler.Invalidate(); m_ItemRepository.Reset();
m_AbnormalEffectHandler.Invalidate(); m_AbnormalEffectRepository.Reset();
} }
private: private:
Services::EntityHandler m_DropHandler; Repositories::EntityRepositoryInterface& m_DropRepository;
Services::EntityHandler m_HeroHandler; Repositories::EntityRepositoryInterface& m_HeroRepository;
Services::EntityHandler m_NPCHandler; Repositories::EntityRepositoryInterface& m_NPCRepository;
Services::EntityHandler m_PlayerHandler; Repositories::EntityRepositoryInterface& m_PlayerRepository;
Services::EntityHandler m_SkillHandler; Repositories::EntityRepositoryInterface& m_SkillRepository;
Services::EntityHandler m_ItemHandler; Repositories::EntityRepositoryInterface& m_ItemRepository;
Services::EntityHandler m_AbnormalEffectHandler; Repositories::EntityRepositoryInterface& m_AbnormalEffectRepository;
Services::ChatMessageHandler m_ChatMessageHandler; Repositories::EntityRepositoryInterface& m_ChatMessageRepository;
const Serializers::SerializerInterface& m_Serializer; const Serializers::SerializerInterface& m_Serializer;
const Serializers::IncomingMessageFactoryInterface& m_IncomingMessageFactory; const Serializers::IncomingMessageFactoryInterface& m_IncomingMessageFactory;
Services::HeroServiceInterface& m_HeroService; Services::HeroServiceInterface& m_HeroService;
@@ -218,4 +239,6 @@ private:
std::thread m_ConnectingThread; std::thread m_ConnectingThread;
std::thread m_SendingThread; std::thread m_SendingThread;
std::thread m_ReceivingThread; std::thread m_ReceivingThread;
Services::UnitOfWork m_UnitOfWork;
}; };

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <map> #include <unordered_map>
#include <math.h> #include <math.h>
#include <functional> #include <functional>
#include "GameStructs.h" #include "GameStructs.h"
@@ -9,9 +9,9 @@ class FindObjectsTrait
{ {
public: public:
template <typename T> template <typename T>
std::map<uint32_t, T> FindAllObjects(float_t radius, std::function<const T(float_t, int32_t)> getNextObject) const std::unordered_map<uint32_t, T> FindAllObjects(float_t radius, std::function<const T(float_t, int32_t)> getNextObject) const
{ {
std::map<uint32_t, T> result; std::unordered_map<uint32_t, T> result;
auto object = getNextObject(radius, -1); auto object = getNextObject(radius, -1);

View File

@@ -22,7 +22,6 @@
#include "GameStructs/GameEngineWrapper.h" #include "GameStructs/GameEngineWrapper.h"
#include "GameStructs/L2GameDataWrapper.h" #include "GameStructs/L2GameDataWrapper.h"
#include "GameStructs/FName.h" #include "GameStructs/FName.h"
#include "../../Services/EntityFinder.h"
#include "Helpers/EnchantHelper.h" #include "Helpers/EnchantHelper.h"
namespace Interlude namespace Interlude
@@ -41,22 +40,18 @@ namespace Interlude
HeroRepository& GetHeroRepository() const override HeroRepository& GetHeroRepository() const override
{ {
static auto factory = HeroFactory(); static auto factory = HeroFactory();
static EntityFinder finder;
static auto result = HeroRepository( static auto result = HeroRepository(
GetNetworkHandler(), GetNetworkHandler(),
factory, factory
finder
); );
return result; return result;
} }
DropRepository& GetDropRepository() const override DropRepository& GetDropRepository() const override
{ {
static auto factory = DropFactory(GetL2GameData(), GetFName()); static auto factory = DropFactory(GetL2GameData(), GetFName());
static EntityFinder finder;
static auto result = DropRepository( static auto result = DropRepository(
GetNetworkHandler(), GetNetworkHandler(),
factory, factory,
finder,
m_Radius m_Radius
); );
return result; return result;
@@ -64,11 +59,9 @@ namespace Interlude
NPCRepository& GetNPCRepository() const override NPCRepository& GetNPCRepository() const override
{ {
static auto factory = NPCFactory(); static auto factory = NPCFactory();
static EntityFinder finder;
static auto result = NPCRepository( static auto result = NPCRepository(
GetNetworkHandler(), GetNetworkHandler(),
factory, factory,
finder,
m_Radius m_Radius
); );
return result; return result;
@@ -76,11 +69,9 @@ namespace Interlude
PlayerRepository& GetPlayerRepository() const override PlayerRepository& GetPlayerRepository() const override
{ {
static auto factory = PlayerFactory(); static auto factory = PlayerFactory();
static EntityFinder finder;
static auto result = PlayerRepository( static auto result = PlayerRepository(
GetNetworkHandler(), GetNetworkHandler(),
factory, factory,
finder,
m_Radius m_Radius
); );
return result; return result;
@@ -88,11 +79,9 @@ namespace Interlude
SkillRepository& GetSkillRepository() const override SkillRepository& GetSkillRepository() const override
{ {
static auto factory = SkillFactory(GetL2GameData(), GetFName()); static auto factory = SkillFactory(GetL2GameData(), GetFName());
static EntityFinder finder;
static auto result = SkillRepository( static auto result = SkillRepository(
GetNetworkHandler(), GetNetworkHandler(),
factory, factory
finder
); );
return result; return result;
} }
@@ -100,22 +89,16 @@ namespace Interlude
{ {
static EnchantHelper enchantHelper; static EnchantHelper enchantHelper;
static auto factory = ItemFactory(GetL2GameData(), GetFName(), enchantHelper); static auto factory = ItemFactory(GetL2GameData(), GetFName(), enchantHelper);
static EntityFinder finder;
static auto result = ItemRepository( static auto result = ItemRepository(
GetNetworkHandler(), GetNetworkHandler(),
factory, factory
finder
); );
return result; return result;
} }
AbnormalEffectRepository& GetAbnormalEffectRepository() const override AbnormalEffectRepository& GetAbnormalEffectRepository() const override
{ {
static auto factory = AbnormalEffectFactory(GetL2GameData(), GetFName()); static auto factory = AbnormalEffectFactory(GetL2GameData(), GetFName());
static EntityFinder finder; static auto result = AbnormalEffectRepository(factory);
static auto result = AbnormalEffectRepository(
factory,
finder
);
return result; return result;
} }
ChatMessageRepository& GetChatMessageRepository() const override ChatMessageRepository& GetChatMessageRepository() const override

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Domain/ValueObjects/ChatMessage.h" #include "Domain/Entities/ChatMessage.h"
#include "../../../DTO/ChatMessage.h" #include "../../../DTO/ChatMessage.h"
using namespace L2Bot::Domain; using namespace L2Bot::Domain;
@@ -13,14 +13,14 @@ namespace Interlude
ChatMessageFactory() = default; ChatMessageFactory() = default;
virtual ~ChatMessageFactory() = default; virtual ~ChatMessageFactory() = default;
ValueObjects::ChatMessage Create(const ChatMessage& message) const std::shared_ptr<Entities::ChatMessage> Create(const ChatMessage& message) const
{ {
return ValueObjects::ChatMessage{ return std::make_shared<Entities::ChatMessage>(
message.objectId, message.objectId,
static_cast<Enums::ChatChannelEnum>(message.channel), static_cast<Enums::ChatChannelEnum>(message.channel),
message.name, message.name,
message.text message.text
}; );
} }
}; };
} }

View File

@@ -11,6 +11,17 @@ namespace Interlude
{ {
class DropFactory class DropFactory
{ {
private:
struct Data
{
uint32_t id;
ValueObjects::Transform transform;
uint32_t itemId;
uint32_t amount;
std::wstring name;
std::wstring iconName;
};
public: public:
DropFactory(const L2GameDataWrapper& l2GameData, const FName& fName) : DropFactory(const L2GameDataWrapper& l2GameData, const FName& fName) :
m_L2GameData(l2GameData), m_L2GameData(l2GameData),
@@ -22,12 +33,40 @@ namespace Interlude
virtual ~DropFactory() = default; virtual ~DropFactory() = default;
std::shared_ptr<Entities::Drop> Create(const Item* item) const std::shared_ptr<Entities::Drop> Create(const Item* item) const
{
const auto &data = GetData(item);
return std::make_shared<Entities::Drop>(
data.id,
data.transform,
data.itemId,
data.amount,
data.name,
data.iconName
);
}
void Update(std::shared_ptr<Entities::Drop>& drop, const Item* item) const
{
const auto& data = GetData(item);
drop->Update(
data.transform,
data.itemId,
data.amount,
data.name,
data.iconName
);
}
private:
const Data GetData(const Item* item) const
{ {
const auto itemData = m_L2GameData.GetItemData(item->itemId); const auto itemData = m_L2GameData.GetItemData(item->itemId);
const auto nameEntry = itemData ? m_FName.GetEntry(itemData->nameIndex) : nullptr; const auto nameEntry = itemData ? m_FName.GetEntry(itemData->nameIndex) : nullptr;
const auto iconEntry = itemData ? m_FName.GetEntry(itemData->iconNameIndex) : nullptr; const auto iconEntry = itemData ? m_FName.GetEntry(itemData->iconNameIndex) : nullptr;
return std::make_shared<Entities::Drop>( return {
item->objectId, item->objectId,
ValueObjects::Transform( ValueObjects::Transform(
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z), ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
@@ -43,7 +82,7 @@ namespace Interlude
item->amount, item->amount,
nameEntry ? std::wstring(nameEntry->value) : L"", nameEntry ? std::wstring(nameEntry->value) : L"",
iconEntry ? std::wstring(iconEntry->value) : L"" iconEntry ? std::wstring(iconEntry->value) : L""
); };
} }
private: private:

View File

@@ -9,15 +9,72 @@ namespace Interlude
{ {
class HeroFactory class HeroFactory
{ {
private:
struct Data
{
uint32_t id;
ValueObjects::Transform transform;
ValueObjects::FullName fullName;
ValueObjects::VitalStats vitalStats;
ValueObjects::Phenotype phenotype;
ValueObjects::ExperienceInfo experienceInfo;
ValueObjects::PermanentStats permanentStats;
ValueObjects::VariableStats variableStats;
ValueObjects::Reputation reputation;
ValueObjects::InventoryInfo inventoryInfo;
uint32_t targetId;
bool isStanding;
};
public: public:
HeroFactory() = default; HeroFactory() = default;
virtual ~HeroFactory() = default; virtual ~HeroFactory() = default;
std::shared_ptr<Entities::Hero> Create(const User* item) const std::shared_ptr<Entities::Hero> Create(const User* item) const
{ {
const auto playerController = item->pawn ? item->pawn->lineagePlayerController : nullptr; const auto& data = GetData(item);
return std::make_shared<Entities::Hero>( return std::make_shared<Entities::Hero>(
data.id,
data.transform,
data.fullName,
data.vitalStats,
data.phenotype,
data.experienceInfo,
data.permanentStats,
data.variableStats,
data.reputation,
data.inventoryInfo,
data.targetId,
data.isStanding
);
}
void Update(std::shared_ptr<Entities::Hero>& hero, const User* item) const
{
const auto& data = GetData(item);
hero->Update(
data.transform,
data.fullName,
data.vitalStats,
data.phenotype,
data.experienceInfo,
data.permanentStats,
data.variableStats,
data.reputation,
data.inventoryInfo,
data.targetId,
data.isStanding
);
}
private:
const Data GetData(const User* item) const
{
const auto playerController = item->pawn ? item->pawn->lineagePlayerController : nullptr;
return {
item->objectId, item->objectId,
ValueObjects::Transform( ValueObjects::Transform(
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z), ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
@@ -82,7 +139,7 @@ namespace Interlude
), ),
playerController ? playerController->targetObjectId : 0, playerController ? playerController->targetObjectId : 0,
playerController ? playerController->isStanding == 1 : true playerController ? playerController->isStanding == 1 : true
); };
} }
}; };
} }

View File

@@ -19,6 +19,64 @@ namespace Interlude
{ {
class ItemFactory class ItemFactory
{ {
private:
struct BaseData
{
uint32_t objectId;
uint32_t itemId;
int32_t mana;
std::wstring name;
std::wstring iconName;
std::wstring description;
uint16_t weight;
};
struct EtcData : public BaseData
{
uint32_t amount;
bool isQuest;
};
struct ArmorData : public BaseData
{
bool isEquipped;
uint16_t enchantLevel;
Enums::ArmorTypeEnum armorType;
Enums::CrystalTypeEnum crystalType;
uint32_t pDefense;
uint32_t mDefense;
std::wstring setEffect;
std::wstring addSetEffect;
std::wstring enchantEffect;
};
struct ShieldData : public BaseData
{
bool isEquipped;
uint16_t enchantLevel;
Enums::CrystalTypeEnum crystalType;
int16_t evasion;
uint32_t pDefense;
uint16_t defRate;
};
struct WeaponData : public BaseData
{
bool isEquipped;
uint16_t enchantLevel;
Enums::WeaponTypeEnum weaponType;
Enums::CrystalTypeEnum crystalType;
uint8_t rndDamage;
uint32_t pAttack;
uint32_t mAttack;
uint16_t critical;
int8_t hitModify;
uint16_t atkSpd;
uint8_t mpConsume;
uint8_t soulshotCount;
uint8_t spiritshotCount;
};
public: public:
ItemFactory(const L2GameDataWrapper& l2GameData, const FName& fName, const EnchantHelper& enchantHelper) : ItemFactory(const L2GameDataWrapper& l2GameData, const FName& fName, const EnchantHelper& enchantHelper) :
m_L2GameData(l2GameData), m_L2GameData(l2GameData),
@@ -33,7 +91,237 @@ namespace Interlude
std::shared_ptr<Entities::BaseItem> Create(const ItemData& itemInfo) const std::shared_ptr<Entities::BaseItem> Create(const ItemData& itemInfo) const
{ {
//FIXME during first start data may be undefined //FIXME during first start data may be undefined
const auto data = m_L2GameData.GetItemData(itemInfo.itemId); const auto data = GetItemData(itemInfo.itemId);
if (data)
{
switch (data->dataType)
{
case L2::ItemDataType::ARMOR:
return CreateArmor(itemInfo);
case L2::ItemDataType::WEAPON:
return CreateWeaponOrShield(itemInfo);
}
return CreateEtc(itemInfo);
}
return nullptr;
}
void Update(std::shared_ptr<Entities::BaseItem>& item, const ItemData& itemInfo) const
{
//FIXME during first start data may be undefined
const auto data = GetItemData(itemInfo.itemId);
if (data)
{
switch (data->dataType)
{
case L2::ItemDataType::ARMOR:
UpdateArmor(item, itemInfo);
return;
case L2::ItemDataType::WEAPON:
UpdateWeaponOrShield(item, itemInfo);
return;
}
}
UpdateEtc(item, itemInfo);
}
private:
std::shared_ptr<Entities::BaseItem> CreateEtc(const ItemData& itemInfo) const
{
const auto& data = GetEtcData(itemInfo);
return std::make_shared<Entities::EtcItem>(
data.objectId,
data.itemId,
data.mana,
data.name,
data.iconName,
data.description,
data.weight,
data.amount,
data.isQuest
);
}
void UpdateEtc(std::shared_ptr<Entities::BaseItem> &item, const ItemData& itemInfo) const
{
auto etcItem = std::dynamic_pointer_cast<Entities::EtcItem>(item);
const auto& data = GetEtcData(itemInfo);
etcItem->Update(
data.itemId,
data.mana,
data.name,
data.iconName,
data.description,
data.weight,
data.amount,
data.isQuest
);
}
std::shared_ptr<Entities::BaseItem> CreateArmor(const ItemData& itemInfo) const
{
const auto& data = GetArmorData(itemInfo);
return std::make_shared<Entities::ArmorItem>(
data.objectId,
data.itemId,
data.mana,
data.name,
data.iconName,
data.description,
data.weight,
data.isEquipped,
data.enchantLevel,
data.armorType,
data.crystalType,
data.pDefense,
data.mDefense,
data.setEffect,
data.addSetEffect,
data.enchantEffect
);
}
void UpdateArmor(std::shared_ptr<Entities::BaseItem>& item, const ItemData& itemInfo) const
{
auto armorItem = std::dynamic_pointer_cast<Entities::ArmorItem>(item);
const auto& data = GetArmorData(itemInfo);
armorItem->Update(
data.itemId,
data.mana,
data.name,
data.iconName,
data.description,
data.weight,
data.isEquipped,
data.enchantLevel,
data.armorType,
data.crystalType,
data.pDefense,
data.mDefense,
data.setEffect,
data.addSetEffect,
data.enchantEffect
);
}
std::shared_ptr<Entities::BaseItem> CreateWeaponOrShield(const ItemData& itemInfo) const
{
const auto itemData = static_cast<const FL2WeaponItemData*>(GetItemData(itemInfo.itemId));
if (itemData->weaponType != L2::WeaponType::SHIELD)
{
const auto& data = GetWeaponData(itemInfo, itemData);
return std::make_shared<Entities::WeaponItem>(
data.objectId,
data.itemId,
data.mana,
data.name,
data.iconName,
data.description,
data.weight,
data.isEquipped,
data.enchantLevel,
data.weaponType,
data.crystalType,
data.rndDamage,
data.pAttack,
data.mAttack,
data.critical,
data.hitModify,
data.atkSpd,
data.mpConsume,
data.soulshotCount,
data.spiritshotCount
);
}
const auto& data = GetShieldData(itemInfo, itemData);
return std::make_shared<Entities::ShieldItem>(
data.objectId,
data.itemId,
data.mana,
data.name,
data.iconName,
data.description,
data.weight,
data.isEquipped,
data.enchantLevel,
data.crystalType,
data.evasion,
data.pDefense,
data.defRate
);
}
void UpdateWeaponOrShield(std::shared_ptr<Entities::BaseItem>& item, const ItemData& itemInfo) const
{
const auto itemData = static_cast<const FL2WeaponItemData*>(GetItemData(itemInfo.itemId));
if (itemData->weaponType != L2::WeaponType::SHIELD)
{
auto weaponItem = std::dynamic_pointer_cast<Entities::WeaponItem>(item);
const auto& data = GetWeaponData(itemInfo, itemData);
weaponItem->Update(
data.itemId,
data.mana,
data.name,
data.iconName,
data.description,
data.weight,
data.isEquipped,
data.enchantLevel,
data.weaponType,
data.crystalType,
data.rndDamage,
data.pAttack,
data.mAttack,
data.critical,
data.hitModify,
data.atkSpd,
data.mpConsume,
data.soulshotCount,
data.spiritshotCount
);
return;
}
auto shieldItem = std::dynamic_pointer_cast<Entities::ShieldItem>(item);
const auto& data = GetShieldData(itemInfo, itemData);
shieldItem->Update(
data.itemId,
data.mana,
data.name,
data.iconName,
data.description,
data.weight,
data.isEquipped,
data.enchantLevel,
data.crystalType,
data.evasion,
data.pDefense,
data.defRate
);
}
const BaseData GetBaseData(const ItemData& itemInfo) const
{
const auto data = GetItemData(itemInfo.itemId);
const auto nameEntry = data ? m_FName.GetEntry(data->nameIndex) : nullptr; const auto nameEntry = data ? m_FName.GetEntry(data->nameIndex) : nullptr;
const auto name = nameEntry ? std::wstring(nameEntry->value) : L""; const auto name = nameEntry ? std::wstring(nameEntry->value) : L"";
@@ -41,99 +329,52 @@ namespace Interlude
const auto icon = iconEntry ? std::wstring(iconEntry->value) : L""; const auto icon = iconEntry ? std::wstring(iconEntry->value) : L"";
const auto description = data && data->description ? std::wstring(data->description) : L""; const auto description = data && data->description ? std::wstring(data->description) : L"";
if (data) return {
{
switch (data->dataType)
{
case L2::ItemDataType::ARMOR:
return CreateArmor(itemInfo, data, name, icon, description);
case L2::ItemDataType::WEAPON:
return CreateWeaponOrShield(itemInfo, data, name, icon, description);
}
}
return CreateEtc(itemInfo, data, name, icon, description);
}
std::shared_ptr<Entities::BaseItem> Copy(std::shared_ptr<Entities::BaseItem> other) const
{
auto otherPtr = other.get();
{
const auto object = dynamic_cast<const Entities::EtcItem*>(otherPtr);
if (object)
{
return std::make_shared<Entities::EtcItem>(object);
}
}
{
const auto object = dynamic_cast<const Entities::ArmorItem*>(otherPtr);
if (object)
{
return std::make_shared<Entities::ArmorItem>(object);
}
}
{
const auto object = dynamic_cast<const Entities::WeaponItem*>(otherPtr);
if (object)
{
return std::make_shared<Entities::WeaponItem>(object);
}
}
{
const auto object = dynamic_cast<const Entities::ShieldItem*>(otherPtr);
if (object)
{
return std::make_shared<Entities::ShieldItem>(object);
}
}
return std::make_shared<Entities::BaseItem>(otherPtr);
}
private:
std::shared_ptr<Entities::BaseItem> CreateEtc(
const ItemData& itemInfo,
const FL2ItemDataBase* itemData,
const std::wstring& name,
const std::wstring& icon,
const std::wstring& description
) const
{
return std::make_shared<Entities::EtcItem>(
itemInfo.objectId, itemInfo.objectId,
itemInfo.itemId, itemInfo.itemId,
itemInfo.mana, itemInfo.mana,
name, name,
icon, icon,
description, description,
itemData ? itemData->weight : 0, (uint16_t)(data ? data->weight : 0)
itemInfo.amount, };
itemInfo.isQuest
);
} }
std::shared_ptr<Entities::BaseItem> CreateArmor( const EtcData GetEtcData(const ItemData& itemInfo) const
const ItemData& itemInfo,
const FL2ItemDataBase* itemData,
const std::wstring& name,
const std::wstring& icon,
const std::wstring& description
) const
{ {
const auto casted = static_cast<const FL2ArmorItemData*>(itemData); const auto& baseData = GetBaseData(itemInfo);
return {
baseData.objectId,
baseData.itemId,
baseData.mana,
baseData.name,
baseData.iconName,
baseData.description,
baseData.weight,
itemInfo.amount,
itemInfo.isQuest
};
}
const ArmorData GetArmorData(const ItemData& itemInfo) const
{
const auto& baseData = GetBaseData(itemInfo);
const auto casted = static_cast<const FL2ArmorItemData*>(GetItemData(itemInfo.itemId));
const auto setEffect = casted && casted->setEffect ? std::wstring(casted->setEffect) : L""; const auto setEffect = casted && casted->setEffect ? std::wstring(casted->setEffect) : L"";
const auto addSetEffect = casted && casted->setEffect ? std::wstring(casted->setEffect) : L""; const auto addSetEffect = casted && casted->setEffect ? std::wstring(casted->setEffect) : L"";
const auto enchantEffect = casted && casted->enchantEffect ? std::wstring(casted->enchantEffect) : L""; const auto enchantEffect = casted && casted->enchantEffect ? std::wstring(casted->enchantEffect) : L"";
return std::make_shared<Entities::ArmorItem>( return {
itemInfo.objectId, baseData.objectId,
itemInfo.itemId, baseData.itemId,
itemInfo.mana, baseData.mana,
name, baseData.name,
icon, baseData.iconName,
description, baseData.description,
itemData ? itemData->weight : 0, baseData.weight,
itemInfo.isEquipped > 0, itemInfo.isEquipped > 0,
itemInfo.enchantLevel, itemInfo.enchantLevel,
casted ? static_cast<Enums::ArmorTypeEnum>(casted->armorType) : Enums::ArmorTypeEnum::none, casted ? static_cast<Enums::ArmorTypeEnum>(casted->armorType) : Enums::ArmorTypeEnum::none,
@@ -143,60 +384,61 @@ namespace Interlude
setEffect, setEffect,
addSetEffect, addSetEffect,
enchantEffect enchantEffect
); };
} }
std::shared_ptr<Entities::BaseItem> CreateWeaponOrShield( const ShieldData GetShieldData(const ItemData& itemInfo, const FL2WeaponItemData* itemData) const
const ItemData& itemInfo,
const FL2ItemDataBase* itemData,
const std::wstring& name,
const std::wstring& icon,
const std::wstring& description
) const
{ {
const auto casted = static_cast<const FL2WeaponItemData*>(itemData); const auto& baseData = GetBaseData(itemInfo);
if (casted->weaponType != L2::WeaponType::SHIELD) return {
{ baseData.objectId,
return std::make_shared<Entities::WeaponItem>( baseData.itemId,
itemInfo.objectId, baseData.mana,
itemInfo.itemId, baseData.name,
itemInfo.mana, baseData.iconName,
name, baseData.description,
icon, baseData.weight,
description,
itemData ? itemData->weight : 0,
itemInfo.isEquipped > 0, itemInfo.isEquipped > 0,
itemInfo.enchantLevel, itemInfo.enchantLevel,
casted ? static_cast<Enums::WeaponTypeEnum>(casted->weaponType) : Enums::WeaponTypeEnum::none, itemData ? static_cast<Enums::CrystalTypeEnum>(itemData->crystalType) : Enums::CrystalTypeEnum::none,
casted ? static_cast<Enums::CrystalTypeEnum>(casted->crystalType) : Enums::CrystalTypeEnum::none, (int16_t)(itemData ? itemData->shieldEvasion : 0),
casted ? casted->rndDamage : 0, m_EnchantHelper.GetDefenseEnchantValue(itemData ? itemData->shieldPdef : 0, itemInfo.enchantLevel),
m_EnchantHelper.GetPAttackEnchantValue(casted->weaponType, itemInfo.isTwoHanded, casted->crystalType, casted ? casted->pAttack : 0, itemInfo.enchantLevel), (uint16_t)(itemData ? itemData->shieldDefRate : 0)
m_EnchantHelper.GetMAttackEnchantValue(casted->crystalType, casted ? casted->mAttack : 0, itemInfo.enchantLevel), };
casted ? casted->critical : 0,
casted ? casted->hitModify : 0,
casted ? casted->atkSpd : 0,
casted ? casted->mpConsume : 0,
casted ? casted->soulshotCount : 0,
casted ? casted->spiritshotCount : 0
);
} }
return std::make_shared<Entities::ShieldItem>( const WeaponData GetWeaponData(const ItemData& itemInfo, const FL2WeaponItemData* itemData) const
itemInfo.objectId, {
itemInfo.itemId, const auto& baseData = GetBaseData(itemInfo);
itemInfo.mana,
name, return {
icon, baseData.objectId,
description, baseData.itemId,
itemData ? itemData->weight : 0, baseData.mana,
baseData.name,
baseData.iconName,
baseData.description,
baseData.weight,
itemInfo.isEquipped > 0, itemInfo.isEquipped > 0,
itemInfo.enchantLevel, itemInfo.enchantLevel,
casted ? static_cast<Enums::CrystalTypeEnum>(casted->crystalType) : Enums::CrystalTypeEnum::none, itemData ? static_cast<Enums::WeaponTypeEnum>(itemData->weaponType) : Enums::WeaponTypeEnum::none,
casted ? casted->shieldEvasion : 0, itemData ? static_cast<Enums::CrystalTypeEnum>(itemData->crystalType) : Enums::CrystalTypeEnum::none,
m_EnchantHelper.GetDefenseEnchantValue(casted ? casted->shieldPdef : 0, itemInfo.enchantLevel), (uint8_t)(itemData ? itemData->rndDamage : 0),
casted ? casted->shieldDefRate : 0 m_EnchantHelper.GetPAttackEnchantValue(itemData->weaponType, itemInfo.isTwoHanded, itemData->crystalType, itemData ? itemData->pAttack : 0, itemInfo.enchantLevel),
); m_EnchantHelper.GetMAttackEnchantValue(itemData->crystalType, itemData ? itemData->mAttack : 0, itemInfo.enchantLevel),
(uint16_t)(itemData ? itemData->critical : 0),
(int8_t)(itemData ? itemData->hitModify : 0),
(uint16_t)(itemData ? itemData->atkSpd : 0),
(uint8_t)(itemData ? itemData->mpConsume : 0),
(uint8_t)(itemData ? itemData->soulshotCount : 0),
(uint8_t)(itemData ? itemData->spiritshotCount : 0)
};
}
const FL2ItemDataBase* GetItemData(const uint32_t itemId) const
{
return m_L2GameData.GetItemData(itemId);
} }
private: private:

View File

@@ -8,13 +8,52 @@ namespace Interlude
{ {
class NPCFactory class NPCFactory
{ {
private:
struct Data
{
uint32_t id;
ValueObjects::Transform transform;
bool isHostile;
uint32_t npcId;
ValueObjects::FullName fullName;
ValueObjects::VitalStats vitalStats;
};
public: public:
NPCFactory() = default; NPCFactory() = default;
virtual ~NPCFactory() = default; virtual ~NPCFactory() = default;
std::shared_ptr<Entities::NPC> Create(const User* item, const Enums::SpoilStateEnum spoiledState) const std::shared_ptr<Entities::NPC> Create(const User* item) const
{ {
const auto& data = GetData(item);
return std::make_shared<Entities::NPC>( return std::make_shared<Entities::NPC>(
data.id,
data.transform,
data.isHostile,
data.npcId,
data.fullName,
data.vitalStats
);
}
void Update(std::shared_ptr<Entities::NPC>& npc, const User* item) const
{
const auto& data = GetData(item);
npc->Update(
data.transform,
data.isHostile,
data.npcId,
data.fullName,
data.vitalStats
);
}
private:
const Data GetData(const User* item) const
{
return {
item->objectId, item->objectId,
ValueObjects::Transform( ValueObjects::Transform(
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z), ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
@@ -28,7 +67,6 @@ namespace Interlude
), ),
item->isMob != 0, item->isMob != 0,
item->npcId, item->npcId,
spoiledState,
ValueObjects::FullName( ValueObjects::FullName(
std::wstring(item->nickname), std::wstring(item->nickname),
std::wstring(item->title) std::wstring(item->title)
@@ -38,7 +76,7 @@ namespace Interlude
item->maxMp, item->mp, item->maxMp, item->mp,
item->maxCp, item->cp item->maxCp, item->cp
) )
); };
} }
}; };
} }

View File

@@ -8,13 +8,49 @@ namespace Interlude
{ {
class PlayerFactory class PlayerFactory
{ {
private:
struct Data
{
uint32_t id;
ValueObjects::Transform transform;
ValueObjects::FullName fullName;
ValueObjects::Phenotype phenotype;
ValueObjects::VitalStats vitalStats;
};
public: public:
PlayerFactory() = default; PlayerFactory() = default;
virtual ~PlayerFactory() = default; virtual ~PlayerFactory() = default;
std::shared_ptr<Entities::Player> Create(const User* item) const std::shared_ptr<Entities::Player> Create(const User* item) const
{ {
const auto& data = GetData(item);
return std::make_shared<Entities::Player>( return std::make_shared<Entities::Player>(
data.id,
data.transform,
data.fullName,
data.phenotype,
data.vitalStats
);
}
void Update(std::shared_ptr<Entities::Player> &player, const User* item) const
{
const auto& data = GetData(item);
player->Update(
data.transform,
data.fullName,
data.phenotype,
data.vitalStats
);
}
private:
const Data GetData(const User* item) const
{
return {
item->objectId, item->objectId,
ValueObjects::Transform( ValueObjects::Transform(
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z), ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
@@ -41,7 +77,7 @@ namespace Interlude
item->maxMp, item->mp, item->maxMp, item->mp,
item->maxCp, item->cp item->maxCp, item->cp
) )
); };
} }
}; };
} }

View File

@@ -14,6 +14,19 @@ namespace Interlude
{ {
class SkillFactory class SkillFactory
{ {
private:
struct Data
{
uint32_t skillId;
uint8_t level;
bool isActive;
uint8_t cost;
int16_t range;
std::wstring name;
std::wstring description;
std::wstring iconName;
};
public: public:
SkillFactory(const L2GameDataWrapper& l2GameData, const FName& fName) : SkillFactory(const L2GameDataWrapper& l2GameData, const FName& fName) :
m_L2GameData(l2GameData), m_L2GameData(l2GameData),
@@ -26,16 +39,37 @@ namespace Interlude
std::shared_ptr<Entities::Skill> Create(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const std::shared_ptr<Entities::Skill> Create(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
{ {
return std::make_shared<Entities::Skill>(BuildSkillData(skillId, level, isActive)); const auto& data = GetData(skillId, level, isActive);
return std::make_shared<Entities::Skill>(
data.skillId,
data.level,
data.isActive,
data.cost,
data.range,
data.name,
data.description,
data.iconName
);
} }
void Update(std::shared_ptr<Entities::Skill>& skill, const uint32_t skillId, const uint32_t level, const uint32_t isActive) const void Update(std::shared_ptr<Entities::Skill>& skill, const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
{ {
skill->Update(BuildSkillData(skillId, level, isActive)); const auto& data = GetData(skillId, level, isActive);
skill->Update(
data.level,
data.isActive,
data.cost,
data.range,
data.name,
data.description,
data.iconName
);
} }
private: private:
const Entities::Skill::Data BuildSkillData(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const const Data GetData(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
{ {
const auto data = m_L2GameData.GetMSData(skillId, level); const auto data = m_L2GameData.GetMSData(skillId, level);

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <map> #include <unordered_map>
#include <chrono> #include <chrono>
#include <shared_mutex> #include <shared_mutex>
#include "Domain/Repositories/EntityRepositoryInterface.h" #include "Domain/Repositories/EntityRepositoryInterface.h"
@@ -9,7 +9,6 @@
#include "../../../Events/HeroDeletedEvent.h" #include "../../../Events/HeroDeletedEvent.h"
#include "../../../Events/EventDispatcher.h" #include "../../../Events/EventDispatcher.h"
#include "../GameStructs/NetworkHandlerWrapper.h" #include "../GameStructs/NetworkHandlerWrapper.h"
#include "../../../Services/EntityFinder.h"
using namespace L2Bot::Domain; using namespace L2Bot::Domain;
@@ -18,27 +17,15 @@ namespace Interlude
class AbnormalEffectRepository : public Repositories::EntityRepositoryInterface class AbnormalEffectRepository : public Repositories::EntityRepositoryInterface
{ {
public: public:
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
{ {
std::unique_lock<std::shared_timed_mutex>(m_Mutex); std::unique_lock<std::shared_timed_mutex>(m_Mutex);
const auto objects = m_EntityFinder.FindEntities<std::shared_ptr<Entities::AbnormalEffect>>(m_Effects, [this](std::shared_ptr<Entities::AbnormalEffect> item) { return m_Effects;
return std::make_shared<Entities::AbnormalEffect>(item.get());
});
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
for (const auto kvp : objects)
{
result.push_back(kvp.second);
} }
return result; AbnormalEffectRepository(const AbnormalEffectFactory& factory) :
} m_Factory(factory)
AbnormalEffectRepository(const AbnormalEffectFactory& factory, EntityFinder& finder) :
m_Factory(factory),
m_EntityFinder(finder)
{ {
EventDispatcher::GetInstance().Subscribe(AbnormalEffectChangedEvent::name, [this](const Event& evt) { EventDispatcher::GetInstance().Subscribe(AbnormalEffectChangedEvent::name, [this](const Event& evt) {
OnEffectToggled(evt); OnEffectToggled(evt);
@@ -75,25 +62,35 @@ namespace Interlude
if (evt.GetName() == AbnormalEffectChangedEvent::name) if (evt.GetName() == AbnormalEffectChangedEvent::name)
{ {
const auto casted = static_cast<const AbnormalEffectChangedEvent&>(evt); const auto casted = static_cast<const AbnormalEffectChangedEvent&>(evt);
const auto skillInfo = casted.GetSkillInfo();
std::map<uint32_t, int32_t> ids; const auto &actualIds = Create(casted.GetSkillInfo());
Delete(actualIds);
}
}
private:
const std::unordered_map<uint32_t, int32_t> Create(const std::vector<int32_t> &skillInfo)
{
std::unordered_map<uint32_t, int32_t> ids;
for (size_t i = 0; i < skillInfo.size(); i += 3) for (size_t i = 0; i < skillInfo.size(); i += 3)
{ {
const auto effectId = skillInfo[i]; const auto effectId = skillInfo[i];
const auto level = skillInfo[i + 1]; const auto level = skillInfo[i + 1];
auto effect = m_Factory.Create(effectId, level); m_Effects[effectId] = m_Factory.Create(effectId, level);
m_Effects.emplace(effect->GetId(), effect);
ids[effectId] = effectId; ids[effectId] = effectId;
} }
return ids;
}
void Delete(const std::unordered_map<uint32_t, int32_t> &actualIds)
{
for (auto it = m_Effects.begin(); it != m_Effects.end();) for (auto it = m_Effects.begin(); it != m_Effects.end();)
{ {
const auto& effect = it->second; if (actualIds.find(it->second->GetId()) == actualIds.end())
if (ids.find(effect->GetId()) == ids.end())
{ {
it = m_Effects.erase(it); it = m_Effects.erase(it);
} }
@@ -103,12 +100,10 @@ namespace Interlude
} }
} }
} }
}
private: private:
const AbnormalEffectFactory& m_Factory; const AbnormalEffectFactory& m_Factory;
std::map<uint32_t, std::shared_ptr<Entities::AbnormalEffect>> m_Effects; std::unordered_map<uint32_t, std::shared_ptr<Entities::EntityInterface>> m_Effects;
std::shared_timed_mutex m_Mutex; std::shared_timed_mutex m_Mutex;
EntityFinder& m_EntityFinder;
}; };
} }

View File

@@ -2,7 +2,6 @@
#include <vector> #include <vector>
#include <shared_mutex> #include <shared_mutex>
#include "Domain/Repositories/ChatMessageRepositoryInterface.h"
#include "../Factories/ChatMessageFactory.h" #include "../Factories/ChatMessageFactory.h"
#include "../../../Events/ChatMessageCreatedEvent.h" #include "../../../Events/ChatMessageCreatedEvent.h"
#include "../../../Events/EventDispatcher.h" #include "../../../Events/EventDispatcher.h"
@@ -11,17 +10,20 @@ using namespace L2Bot::Domain;
namespace Interlude namespace Interlude
{ {
class ChatMessageRepository : public Repositories::ChatMessageRepositoryInterface class ChatMessageRepository : public Repositories::EntityRepositoryInterface
{ {
public: public:
const std::vector<ValueObjects::ChatMessage> GetMessages() override const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
{ {
std::unique_lock<std::shared_timed_mutex>(m_Mutex); std::unique_lock<std::shared_timed_mutex>(m_Mutex);
const auto result = m_Messages; return m_Messages;
m_Messages.clear(); }
return result; void Reset()
{
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
m_Messages.clear();
} }
ChatMessageRepository(const ChatMessageFactory& factory) : ChatMessageRepository(const ChatMessageFactory& factory) :
@@ -39,7 +41,8 @@ namespace Interlude
{ {
const auto casted = static_cast<const ChatMessageCreatedEvent&>(evt); const auto casted = static_cast<const ChatMessageCreatedEvent&>(evt);
m_Messages.push_back(m_Factory.Create(casted.GetChatMessage())); const auto message = m_Factory.Create(casted.GetChatMessage());
m_Messages[message->GetId()] = message;
} }
} }
@@ -48,7 +51,7 @@ namespace Interlude
private: private:
const ChatMessageFactory& m_Factory; const ChatMessageFactory& m_Factory;
std::vector<ValueObjects::ChatMessage> m_Messages; std::unordered_map<uint32_t, std::shared_ptr<Entities::EntityInterface>> m_Messages;
std::shared_timed_mutex m_Mutex; std::shared_timed_mutex m_Mutex;
}; };
} }

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <map> #include <unordered_map>
#include <memory> #include <memory>
#include <shared_mutex> #include <shared_mutex>
#include "Domain/Repositories/EntityRepositoryInterface.h" #include "Domain/Repositories/EntityRepositoryInterface.h"
@@ -8,7 +8,6 @@
#include "../Factories/DropFactory.h" #include "../Factories/DropFactory.h"
#include "../../GameStructs/FindObjectsTrait.h" #include "../../GameStructs/FindObjectsTrait.h"
#include "../GameStructs/NetworkHandlerWrapper.h" #include "../GameStructs/NetworkHandlerWrapper.h"
#include "../../../Services/EntityFinder.h"
using namespace L2Bot::Domain; using namespace L2Bot::Domain;
@@ -17,22 +16,25 @@ namespace Interlude
class DropRepository : public Repositories::EntityRepositoryInterface, public FindObjectsTrait class DropRepository : public Repositories::EntityRepositoryInterface, public FindObjectsTrait
{ {
public: public:
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
{ {
std::unique_lock<std::shared_timed_mutex>(m_Mutex); std::unique_lock<std::shared_timed_mutex>(m_Mutex);
const std::map<uint32_t, Item*> items = FindAllObjects<Item*>(m_Radius, [this](float_t radius, int32_t prevId) { const auto allItems = FindAllObjects<Item*>(m_Radius, [this](float_t radius, int32_t prevId) {
return m_NetworkHandler.GetNextItem(radius, prevId); return m_NetworkHandler.GetNextItem(radius, prevId);
}); });
const auto objects = m_EntityFinder.FindEntities<Item*>(items, [this](Item* item) {
return m_Factory.Create(item);
});
auto result = std::vector<std::shared_ptr<DTO::EntityState>>(); std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> result;
for (const auto kvp : allItems) {
for (const auto kvp : objects) const auto item = kvp.second;
if (m_Drops.find(item->objectId) == m_Drops.end()) {
m_Drops[item->objectId] = m_Factory.Create(item);
}
else
{ {
result.push_back(kvp.second); m_Factory.Update(m_Drops[item->objectId], item);
}
result[item->objectId] = m_Drops[item->objectId];
} }
return result; return result;
@@ -41,14 +43,13 @@ namespace Interlude
void Reset() override void Reset() override
{ {
std::shared_lock<std::shared_timed_mutex>(m_Mutex); std::shared_lock<std::shared_timed_mutex>(m_Mutex);
m_EntityFinder.Reset(); m_Drops.clear();
} }
DropRepository(const NetworkHandlerWrapper& networkHandler, const DropFactory& factory, EntityFinder& finder, const uint16_t radius) : DropRepository(const NetworkHandlerWrapper& networkHandler, const DropFactory& factory, const uint16_t radius) :
m_NetworkHandler(networkHandler), m_NetworkHandler(networkHandler),
m_Factory(factory), m_Factory(factory),
m_Radius(radius), m_Radius(radius)
m_EntityFinder(finder)
{ {
} }
@@ -60,7 +61,7 @@ namespace Interlude
const NetworkHandlerWrapper& m_NetworkHandler; const NetworkHandlerWrapper& m_NetworkHandler;
const DropFactory& m_Factory; const DropFactory& m_Factory;
const uint16_t m_Radius; const uint16_t m_Radius;
EntityFinder& m_EntityFinder;
std::shared_timed_mutex m_Mutex; std::shared_timed_mutex m_Mutex;
std::unordered_map<uint32_t, std::shared_ptr<Entities::Drop>> m_Drops;
}; };
} }

View File

@@ -7,7 +7,6 @@
#include "../../../Events/HeroCreatedEvent.h" #include "../../../Events/HeroCreatedEvent.h"
#include "../../../Events/HeroDeletedEvent.h" #include "../../../Events/HeroDeletedEvent.h"
#include "../GameStructs/NetworkHandlerWrapper.h" #include "../GameStructs/NetworkHandlerWrapper.h"
#include "../../../Services/EntityFinder.h"
using namespace L2Bot::Domain; using namespace L2Bot::Domain;
@@ -16,39 +15,28 @@ namespace Interlude
class HeroRepository : public Repositories::EntityRepositoryInterface class HeroRepository : public Repositories::EntityRepositoryInterface
{ {
public: public:
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
{ {
std::unique_lock<std::shared_timed_mutex>(m_Mutex); std::unique_lock<std::shared_timed_mutex>(m_Mutex);
auto hero = m_NetworkHandler.GetHero(); const auto hero = m_NetworkHandler.GetHero();
if (hero != nullptr && m_PrevHero == nullptr) std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> result;
{ if (hero) {
if (!m_Hero) {
m_Hero = m_Factory.Create(hero);
EventDispatcher::GetInstance().Dispatch(HeroCreatedEvent{}); EventDispatcher::GetInstance().Dispatch(HeroCreatedEvent{});
} }
if (hero == nullptr && m_PrevHero != nullptr) else
{ {
m_Factory.Update(m_Hero, hero);
}
result[hero->objectId] = m_Hero;
}
else {
m_Hero = nullptr;
EventDispatcher::GetInstance().Dispatch(HeroDeletedEvent{}); EventDispatcher::GetInstance().Dispatch(HeroDeletedEvent{});
} }
m_PrevHero = hero;
std::map<uint32_t, User*> items;
if (hero)
{
items.emplace(hero->objectId, hero);
}
const auto objects = m_EntityFinder.FindEntities<User*>(items, [this](User* item) {
return m_Factory.Create(item);
});
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
for (const auto kvp : objects)
{
result.push_back(kvp.second);
}
return result; return result;
} }
@@ -56,13 +44,12 @@ namespace Interlude
void Reset() override void Reset() override
{ {
std::shared_lock<std::shared_timed_mutex>(m_Mutex); std::shared_lock<std::shared_timed_mutex>(m_Mutex);
m_EntityFinder.Reset(); m_Hero = nullptr;
} }
HeroRepository(const NetworkHandlerWrapper& networkHandler, const HeroFactory& factory, EntityFinder& finder) : HeroRepository(const NetworkHandlerWrapper& networkHandler, const HeroFactory& factory) :
m_NetworkHandler(networkHandler), m_NetworkHandler(networkHandler),
m_Factory(factory), m_Factory(factory)
m_EntityFinder(finder)
{ {
} }
@@ -73,8 +60,6 @@ namespace Interlude
private: private:
const HeroFactory& m_Factory; const HeroFactory& m_Factory;
const NetworkHandlerWrapper& m_NetworkHandler; const NetworkHandlerWrapper& m_NetworkHandler;
User* m_PrevHero = nullptr; std::shared_ptr<Entities::Hero> m_Hero;
EntityFinder& m_EntityFinder;
std::shared_timed_mutex m_Mutex;
}; };
} }

View File

@@ -1,12 +1,11 @@
#pragma once #pragma once
#include <map> #include <unordered_map>
#include <chrono> #include <chrono>
#include <shared_mutex> #include <shared_mutex>
#include "Domain/Repositories/EntityRepositoryInterface.h" #include "Domain/Repositories/EntityRepositoryInterface.h"
#include "../Factories/ItemFactory.h" #include "../Factories/ItemFactory.h"
#include "../GameStructs/NetworkHandlerWrapper.h" #include "../GameStructs/NetworkHandlerWrapper.h"
#include "../../../Services/EntityFinder.h"
#include "../../../Events/ItemCreatedEvent.h" #include "../../../Events/ItemCreatedEvent.h"
#include "../../../Events/ItemUpdatedEvent.h" #include "../../../Events/ItemUpdatedEvent.h"
#include "../../../Events/ItemDeletedEvent.h" #include "../../../Events/ItemDeletedEvent.h"
@@ -22,21 +21,11 @@ namespace Interlude
class ItemRepository : public Repositories::EntityRepositoryInterface class ItemRepository : public Repositories::EntityRepositoryInterface
{ {
public: public:
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
{ {
std::unique_lock<std::shared_timed_mutex>(m_Mutex); std::unique_lock<std::shared_timed_mutex>(m_Mutex);
const auto objects = m_EntityFinder.FindEntities<std::shared_ptr<Entities::BaseItem>>(m_Items, [this](std::shared_ptr<Entities::BaseItem> item) { std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> result(m_Items.begin(), m_Items.end());
return m_Factory.Copy(item);
});
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
for (const auto kvp : objects)
{
result.push_back(kvp.second);
}
return result; return result;
} }
@@ -51,10 +40,9 @@ namespace Interlude
return nullptr; return nullptr;
} }
ItemRepository(const NetworkHandlerWrapper& networkHandler, const ItemFactory& factory, EntityFinder& finder) : ItemRepository(const NetworkHandlerWrapper& networkHandler, const ItemFactory& factory) :
m_NetworkHandler(networkHandler), m_NetworkHandler(networkHandler),
m_Factory(factory), m_Factory(factory)
m_EntityFinder(finder)
{ {
EventDispatcher::GetInstance().Subscribe(ItemCreatedEvent::name, [this](const Event& evt) { EventDispatcher::GetInstance().Subscribe(ItemCreatedEvent::name, [this](const Event& evt) {
OnItemCreated(evt); OnItemCreated(evt);
@@ -121,10 +109,13 @@ namespace Interlude
{ {
if (kvp.second->GetItemId() == itemId) if (kvp.second->GetItemId() == itemId)
{ {
auto ptr = dynamic_cast<Entities::EtcItem*>(kvp.second.get()); auto casted = std::dynamic_pointer_cast<Entities::EtcItem>(kvp.second);
if (ptr) if (isEnabled) {
casted->StartAutouse();
}
else
{ {
ptr->Autouse(isEnabled); casted->StopAutouse();
} }
} }
} }
@@ -145,15 +136,18 @@ namespace Interlude
const auto casted = static_cast<const ItemCreatedEvent&>(evt); const auto casted = static_cast<const ItemCreatedEvent&>(evt);
const auto& data = casted.GetItemData(); const auto& data = casted.GetItemData();
auto item = m_Factory.Create(data);
if (m_Items.find(data.objectId) == m_Items.end()) if (m_Items.find(data.objectId) == m_Items.end())
{ {
m_Items.emplace(data.objectId, item); auto item = m_Factory.Create(data);
if (item) {
m_Items[data.objectId] = item;
}
} }
else else
{ {
// When equip/unequip accessories // When equip/unequip accessories
m_Items[data.objectId]->Update(item.get()); m_Factory.Update(m_Items[data.objectId], data);
} }
m_NewItems[data.objectId] = data.objectId; m_NewItems[data.objectId] = data.objectId;
} }
@@ -173,8 +167,7 @@ namespace Interlude
return; return;
} }
auto item = m_Factory.Create(data); m_Factory.Update(m_Items[data.objectId], data);
m_Items[data.objectId]->Update(item.get());
} }
} }
@@ -207,12 +200,11 @@ namespace Interlude
private: private:
const ItemFactory& m_Factory; const ItemFactory& m_Factory;
std::map<uint32_t, std::shared_ptr<Entities::BaseItem>> m_Items; std::unordered_map<std::uint32_t, std::shared_ptr<Entities::BaseItem>> m_Items;
std::map<uint32_t, uint32_t> m_NewItems; std::unordered_map<std::uint32_t, std::uint32_t> m_NewItems;
bool m_IsNewCycle = true; bool m_IsNewCycle = true;
uint32_t m_UsedSkillId = 0; std::uint32_t m_UsedSkillId = 0;
const NetworkHandlerWrapper& m_NetworkHandler; const NetworkHandlerWrapper& m_NetworkHandler;
std::shared_timed_mutex m_Mutex; std::shared_timed_mutex m_Mutex;
EntityFinder& m_EntityFinder;
}; };
} }

View File

@@ -9,7 +9,6 @@
#include "../../../Events/SpoiledEvent.h" #include "../../../Events/SpoiledEvent.h"
#include "../../../Events/CreatureDiedEvent.h" #include "../../../Events/CreatureDiedEvent.h"
#include "../../GameStructs/FindObjectsTrait.h" #include "../../GameStructs/FindObjectsTrait.h"
#include "../../../Services/EntityFinder.h"
using namespace L2Bot::Domain; using namespace L2Bot::Domain;
@@ -18,33 +17,33 @@ namespace Interlude
class NPCRepository : public Repositories::EntityRepositoryInterface, public FindObjectsTrait class NPCRepository : public Repositories::EntityRepositoryInterface, public FindObjectsTrait
{ {
public: public:
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
{ {
std::unique_lock<std::shared_timed_mutex>(m_Mutex); std::unique_lock<std::shared_timed_mutex>(m_Mutex);
const auto creatures = FindAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) { const auto allCreatures = FindAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
return m_NetworkHandler.GetNextCreature(radius, prevId); return m_NetworkHandler.GetNextCreature(radius, prevId);
}); });
std::map<uint32_t, User*> items; std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> result;
for (const auto& kvp : creatures) for (const auto kvp : allCreatures) {
{
const auto creature = kvp.second; const auto creature = kvp.second;
if (creature->userType == L2::UserType::NPC) { if (creature->userType != L2::UserType::NPC) {
items.emplace(creature->objectId, creature); continue;
}
} }
const auto objects = m_EntityFinder.FindEntities<User*>(items, [this](User* item) { if (m_Npcs.find(creature->objectId) == m_Npcs.end()) {
const auto spoilState = m_Spoiled.find(item->objectId) == m_Spoiled.end() ? Enums::SpoilStateEnum::none : m_Spoiled.at(item->objectId); m_Npcs[creature->objectId] = m_Factory.Create(creature);
return m_Factory.Create(item, spoilState); }
}); else
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
for (const auto kvp : objects)
{ {
result.push_back(kvp.second); m_Factory.Update(m_Npcs[creature->objectId], creature);
}
const auto spoilState = m_Spoiled.find(creature->objectId) == m_Spoiled.end() ? Enums::SpoilStateEnum::none : m_Spoiled[creature->objectId];
m_Npcs[creature->objectId]->UpdateSpoilState(spoilState);
result[creature->objectId] = m_Npcs[creature->objectId];
} }
return result; return result;
@@ -53,14 +52,13 @@ namespace Interlude
void Reset() override void Reset() override
{ {
std::shared_lock<std::shared_timed_mutex>(m_Mutex); std::shared_lock<std::shared_timed_mutex>(m_Mutex);
m_EntityFinder.Reset(); m_Npcs.clear();
} }
NPCRepository(const NetworkHandlerWrapper& networkHandler, const NPCFactory& factory, EntityFinder& finder, const uint16_t radius) : NPCRepository(const NetworkHandlerWrapper& networkHandler, const NPCFactory& factory, const uint16_t radius) :
m_NetworkHandler(networkHandler), m_NetworkHandler(networkHandler),
m_Factory(factory), m_Factory(factory),
m_Radius(radius), m_Radius(radius)
m_EntityFinder(finder)
{ {
EventDispatcher::GetInstance().Subscribe(SpoiledEvent::name, [this](const Event& evt) { EventDispatcher::GetInstance().Subscribe(SpoiledEvent::name, [this](const Event& evt) {
OnSpoiled(evt); OnSpoiled(evt);
@@ -75,6 +73,7 @@ namespace Interlude
void OnSpoiled(const Event& evt) void OnSpoiled(const Event& evt)
{ {
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == SpoiledEvent::name) if (evt.GetName() == SpoiledEvent::name)
{ {
const auto casted = static_cast<const SpoiledEvent&>(evt); const auto casted = static_cast<const SpoiledEvent&>(evt);
@@ -92,6 +91,7 @@ namespace Interlude
void OnCreatureDied(const Event& evt) void OnCreatureDied(const Event& evt)
{ {
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
if (evt.GetName() == CreatureDiedEvent::name) if (evt.GetName() == CreatureDiedEvent::name)
{ {
const auto casted = static_cast<const CreatureDiedEvent&>(evt); const auto casted = static_cast<const CreatureDiedEvent&>(evt);
@@ -115,7 +115,7 @@ namespace Interlude
std::map<uint32_t, Enums::SpoilStateEnum> m_Spoiled; std::map<uint32_t, Enums::SpoilStateEnum> m_Spoiled;
const NetworkHandlerWrapper& m_NetworkHandler; const NetworkHandlerWrapper& m_NetworkHandler;
const uint16_t m_Radius = 0; const uint16_t m_Radius = 0;
EntityFinder& m_EntityFinder;
std::shared_timed_mutex m_Mutex; std::shared_timed_mutex m_Mutex;
std::unordered_map<uint32_t, std::shared_ptr<Entities::NPC>> m_Npcs;
}; };
} }

View File

@@ -1,11 +1,9 @@
#pragma once #pragma once
#include <map> #include <unordered_map>
#include <shared_mutex>
#include "Domain/Repositories/EntityRepositoryInterface.h" #include "Domain/Repositories/EntityRepositoryInterface.h"
#include "../Factories/PlayerFactory.h" #include "../Factories/PlayerFactory.h"
#include "../../GameStructs/FindObjectsTrait.h" #include "../../GameStructs/FindObjectsTrait.h"
#include "../GameStructs/NetworkHandlerWrapper.h" #include "../GameStructs/NetworkHandlerWrapper.h"
#include "../../../Services/EntityFinder.h"
using namespace L2Bot::Domain; using namespace L2Bot::Domain;
@@ -14,32 +12,29 @@ namespace Interlude
class PlayerRepository : public Repositories::EntityRepositoryInterface, public FindObjectsTrait class PlayerRepository : public Repositories::EntityRepositoryInterface, public FindObjectsTrait
{ {
public: public:
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
{ {
std::unique_lock<std::shared_timed_mutex>(m_Mutex); const auto allCreatures = FindAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
const auto creatures = FindAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
return m_NetworkHandler.GetNextCreature(radius, prevId); return m_NetworkHandler.GetNextCreature(radius, prevId);
}); });
std::map<uint32_t, User*> items; std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> result;
for (const auto& kvp : creatures) for (const auto& kvp : allCreatures)
{ {
const auto creature = kvp.second; const auto &creature = kvp.second;
if (creature->userType == L2::UserType::USER && creature->lvl == 0) { if (creature->userType != L2::UserType::USER || creature->lvl != 0) {
items.emplace(creature->objectId, creature); continue;
}
} }
const auto objects = m_EntityFinder.FindEntities<User*>(items, [this](User* item) { if (m_Players.find(creature->objectId) == m_Players.end()) {
return m_Factory.Create(item); m_Players[creature->objectId] = m_Factory.Create(creature);
}); }
else
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
for (const auto kvp : objects)
{ {
result.push_back(kvp.second); m_Factory.Update(m_Players[creature->objectId], creature);
}
result[creature->objectId] = m_Players[creature->objectId];
} }
return result; return result;
@@ -48,14 +43,13 @@ namespace Interlude
void Reset() override void Reset() override
{ {
std::shared_lock<std::shared_timed_mutex>(m_Mutex); std::shared_lock<std::shared_timed_mutex>(m_Mutex);
m_EntityFinder.Reset(); m_Players.clear();
} }
PlayerRepository(const NetworkHandlerWrapper& networkHandler, const PlayerFactory& factory, EntityFinder& finder, const uint16_t radius) : PlayerRepository(const NetworkHandlerWrapper& networkHandler, const PlayerFactory& factory, const uint16_t radius) :
m_NetworkHandler(networkHandler), m_NetworkHandler(networkHandler),
m_Factory(factory), m_Factory(factory),
m_Radius(radius), m_Radius(radius)
m_EntityFinder(finder)
{ {
} }
@@ -67,7 +61,6 @@ namespace Interlude
const PlayerFactory& m_Factory; const PlayerFactory& m_Factory;
const NetworkHandlerWrapper& m_NetworkHandler; const NetworkHandlerWrapper& m_NetworkHandler;
const uint16_t m_Radius; const uint16_t m_Radius;
EntityFinder& m_EntityFinder; std::unordered_map<uint32_t, std::shared_ptr<Entities::Player>> m_Players;
std::shared_timed_mutex m_Mutex;
}; };
} }

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <map> #include <unordered_map>
#include <chrono> #include <chrono>
#include <shared_mutex> #include <shared_mutex>
#include "Domain/Repositories/EntityRepositoryInterface.h" #include "Domain/Repositories/EntityRepositoryInterface.h"
@@ -14,7 +14,6 @@
#include "../../../Events/EventDispatcher.h" #include "../../../Events/EventDispatcher.h"
#include "../GameStructs/NetworkHandlerWrapper.h" #include "../GameStructs/NetworkHandlerWrapper.h"
#include "../../../Common/TimerMap.h" #include "../../../Common/TimerMap.h"
#include "../../../Services/EntityFinder.h"
using namespace L2Bot::Domain; using namespace L2Bot::Domain;
@@ -23,28 +22,17 @@ namespace Interlude
class SkillRepository : public Repositories::EntityRepositoryInterface class SkillRepository : public Repositories::EntityRepositoryInterface
{ {
public: public:
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
{ {
std::unique_lock<std::shared_timed_mutex>(m_Mutex); std::unique_lock<std::shared_timed_mutex>(m_Mutex);
const auto objects = m_EntityFinder.FindEntities<std::shared_ptr<Entities::Skill>>(m_Skills, [this](std::shared_ptr<Entities::Skill> item) { std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> result(m_Skills.begin(), m_Skills.end());
return std::make_shared<Entities::Skill>(item.get());
});
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
for (const auto kvp : objects)
{
result.push_back(kvp.second);
}
return result; return result;
} }
SkillRepository(const NetworkHandlerWrapper& networkHandler, const SkillFactory& factory, EntityFinder& finder) : SkillRepository(const NetworkHandlerWrapper& networkHandler, const SkillFactory& factory) :
m_NetworkHandler(networkHandler), m_NetworkHandler(networkHandler),
m_Factory(factory), m_Factory(factory)
m_EntityFinder(finder)
{ {
EventDispatcher::GetInstance().Subscribe(SkillCreatedEvent::name, [this](const Event& evt) { EventDispatcher::GetInstance().Subscribe(SkillCreatedEvent::name, [this](const Event& evt) {
OnSkillCreated(evt); OnSkillCreated(evt);
@@ -130,17 +118,17 @@ namespace Interlude
if (m_Skills.find(skillId) == m_Skills.end()) if (m_Skills.find(skillId) == m_Skills.end())
{ {
auto skill = m_Factory.Create( m_Skills[skillId] = m_Factory.Create(
skillInfo[2], skillInfo[2],
skillInfo[1], skillInfo[1],
skillInfo[0] skillInfo[0]
); );
m_Skills[skill->GetId()] = skill;
} }
else else
{ {
auto skill = m_Skills[skillId];
m_Factory.Update( m_Factory.Update(
m_Skills[skillId], skill,
skillInfo[2], skillInfo[2],
skillInfo[1], skillInfo[1],
skillInfo[0] skillInfo[0]
@@ -198,10 +186,8 @@ namespace Interlude
return; return;
} }
const auto& skill = m_Skills[m_UsedSkillId]; m_Skills[m_UsedSkillId]->StopCasting();
m_CastingTimers.StopTimer(m_UsedSkillId);
skill->StopCasting();
m_CastingTimers.StopTimer(skill->GetId());
m_UsedSkillId = 0; m_UsedSkillId = 0;
} }
@@ -215,7 +201,7 @@ namespace Interlude
const auto casted = static_cast<const AbnormalEffectChangedEvent&>(evt); const auto casted = static_cast<const AbnormalEffectChangedEvent&>(evt);
const auto skillInfo = casted.GetSkillInfo(); const auto skillInfo = casted.GetSkillInfo();
std::map<uint32_t, int32_t> ids; std::unordered_map<uint32_t, int32_t> ids;
for (size_t i = 0; i < skillInfo.size(); i += 3) for (size_t i = 0; i < skillInfo.size(); i += 3)
{ {
@@ -244,14 +230,13 @@ namespace Interlude
private: private:
const SkillFactory& m_Factory; const SkillFactory& m_Factory;
std::map<uint32_t, std::shared_ptr<Entities::Skill>> m_Skills; std::unordered_map<std::uint32_t, std::shared_ptr<Entities::Skill>> m_Skills;
std::map<uint32_t, uint32_t> m_NewSkills; std::unordered_map<std::uint32_t, std::uint32_t> m_NewSkills;
bool m_IsNewCycle = true; bool m_IsNewCycle = true;
uint32_t m_UsedSkillId = 0; uint32_t m_UsedSkillId = 0;
const NetworkHandlerWrapper& m_NetworkHandler; const NetworkHandlerWrapper& m_NetworkHandler;
TimerMap m_ReloadingTimers; TimerMap m_ReloadingTimers;
TimerMap m_CastingTimers; TimerMap m_CastingTimers;
std::shared_timed_mutex m_Mutex; std::shared_timed_mutex m_Mutex;
EntityFinder& m_EntityFinder;
}; };
} }

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include "Domain/Repositories/EntityRepositoryInterface.h" #include "Domain/Repositories/EntityRepositoryInterface.h"
#include "Domain/Repositories/ChatMessageRepositoryInterface.h"
#include "Domain/Services/HeroServiceInterface.h" #include "Domain/Services/HeroServiceInterface.h"
#include "GameStructs/NetworkHandlerInterface.h" #include "GameStructs/NetworkHandlerInterface.h"
#include "GameStructs/GameEngineInterface.h" #include "GameStructs/GameEngineInterface.h"
@@ -25,7 +24,7 @@ public:
virtual Repositories::EntityRepositoryInterface& GetSkillRepository() const = 0; virtual Repositories::EntityRepositoryInterface& GetSkillRepository() const = 0;
virtual Repositories::EntityRepositoryInterface& GetItemRepository() const = 0; virtual Repositories::EntityRepositoryInterface& GetItemRepository() const = 0;
virtual Repositories::EntityRepositoryInterface& GetAbnormalEffectRepository() const = 0; virtual Repositories::EntityRepositoryInterface& GetAbnormalEffectRepository() const = 0;
virtual Repositories::ChatMessageRepositoryInterface& GetChatMessageRepository() const = 0; virtual Repositories::EntityRepositoryInterface& GetChatMessageRepository() const = 0;
virtual Services::HeroServiceInterface& GetHeroService() const = 0; virtual Services::HeroServiceInterface& GetHeroService() const = 0;
virtual NetworkHandlerInterface& GetNetworkHandler() const = 0; virtual NetworkHandlerInterface& GetNetworkHandler() const = 0;
virtual GameEngineInterface& GetGameEngine() const = 0; virtual GameEngineInterface& GetGameEngine() const = 0;