refactor: remove unnecessary classes
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include "EntityInterface.h"
|
||||
#include "../Helpers/HashCombiner.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
@@ -14,29 +16,30 @@ namespace L2Bot::Domain::Entities
|
||||
return m_SkillId;
|
||||
}
|
||||
|
||||
void Update(const EntityInterface* other) override
|
||||
{
|
||||
const AbnormalEffect* casted = static_cast<const AbnormalEffect*>(other);
|
||||
SaveState();
|
||||
|
||||
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;
|
||||
void Update(
|
||||
const uint8_t level,
|
||||
const std::wstring& name,
|
||||
const std::wstring& description,
|
||||
const std::wstring& iconName
|
||||
) {
|
||||
m_Level = level;
|
||||
m_Name = name;
|
||||
m_Description = description;
|
||||
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 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;
|
||||
return "abnormalEffect";
|
||||
}
|
||||
|
||||
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"level", std::to_wstring(m_Level) });
|
||||
|
||||
if (m_IsNewState)
|
||||
{
|
||||
result.push_back({ L"name", m_Name });
|
||||
result.push_back({ L"iconName", m_IconName });
|
||||
result.push_back({ L"description", m_Description });
|
||||
}
|
||||
result.push_back({ L"name", m_Name });
|
||||
result.push_back({ L"iconName", m_IconName });
|
||||
result.push_back({ L"description", m_Description });
|
||||
|
||||
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;
|
||||
virtual ~AbnormalEffect() = default;
|
||||
|
||||
@@ -90,6 +80,5 @@ namespace L2Bot::Domain::Entities
|
||||
std::wstring m_Name = L"";
|
||||
std::wstring m_Description = L"";
|
||||
std::wstring m_IconName = L"";
|
||||
bool m_IsNewState = true;
|
||||
};
|
||||
}
|
||||
|
@@ -2,87 +2,75 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include "BaseItem.h"
|
||||
#include "../Enums/ArmorTypeEnum.h"
|
||||
#include "../Enums/CrystalTypeEnum.h"
|
||||
#include "../Helpers/HashCombiner.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
class ArmorItem : public BaseItem
|
||||
{
|
||||
public:
|
||||
void Update(const EntityInterface* other) override
|
||||
{
|
||||
const ArmorItem* casted = static_cast<const ArmorItem*>(other);
|
||||
void Update(
|
||||
const uint32_t itemId,
|
||||
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 = 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;
|
||||
m_IsEquipped = isEquipped;
|
||||
m_EnchantLevel = enchantLevel;
|
||||
m_ArmorType = armorType;
|
||||
m_CrystalType = crystalType;
|
||||
m_PDefense = pDefense;
|
||||
m_MDefense = mDefense;
|
||||
m_SetEffect = setEffect;
|
||||
m_AddSetEffect = addSetEffect;
|
||||
m_EnchantEffect = enchantEffect;
|
||||
}
|
||||
void SaveState() override
|
||||
const size_t GetHash() const override
|
||||
{
|
||||
BaseItem::SaveState();
|
||||
m_PrevState =
|
||||
{
|
||||
m_IsEquipped,
|
||||
m_EnchantLevel,
|
||||
m_PDefense,
|
||||
m_MDefense,
|
||||
false
|
||||
};
|
||||
}
|
||||
const bool IsEqual(const EntityInterface* other) const override
|
||||
{
|
||||
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;
|
||||
return Helpers::CombineHashes({
|
||||
BaseItem::GetHash(),
|
||||
std::hash<bool>{}(m_IsEquipped),
|
||||
std::hash<uint16_t>{}(m_EnchantLevel),
|
||||
std::hash<Enums::ArmorTypeEnum>{}(m_ArmorType),
|
||||
std::hash<Enums::CrystalTypeEnum>{}(m_CrystalType),
|
||||
std::hash<uint32_t>{}(m_PDefense),
|
||||
std::hash<uint32_t>{}(m_MDefense),
|
||||
std::hash<std::wstring>{}(m_SetEffect),
|
||||
std::hash<std::wstring>{}(m_AddSetEffect),
|
||||
std::hash<std::wstring>{}(m_EnchantEffect)
|
||||
});
|
||||
}
|
||||
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
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"crystalType", std::to_wstring(static_cast<int8_t>(m_CrystalType)) });
|
||||
result.push_back({ L"setEffect", m_SetEffect });
|
||||
result.push_back({ L"addSetEffect", m_AddSetEffect });
|
||||
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) });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_EnchantLevel != m_PrevState.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) });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_MDefense != m_PrevState.mDefense)
|
||||
{
|
||||
result.push_back({ L"mDefense", std::to_wstring(m_MDefense) });
|
||||
}
|
||||
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"setEffect", m_SetEffect });
|
||||
result.push_back({ L"addSetEffect", m_AddSetEffect });
|
||||
result.push_back({ L"enchantEffect", m_EnchantEffect });
|
||||
result.push_back({ L"isEquipped", std::to_wstring(m_IsEquipped) });
|
||||
result.push_back({ L"enchantLevel", std::to_wstring(m_EnchantLevel) });
|
||||
result.push_back({ L"pDefense", std::to_wstring(m_PDefense) });
|
||||
result.push_back({ L"mDefense", std::to_wstring(m_MDefense) });
|
||||
|
||||
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;
|
||||
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:
|
||||
bool m_IsEquipped = 0;
|
||||
uint16_t m_EnchantLevel = 0;
|
||||
@@ -166,6 +129,5 @@ namespace L2Bot::Domain::Entities
|
||||
std::wstring m_SetEffect = L"";
|
||||
std::wstring m_AddSetEffect = L"";
|
||||
std::wstring m_EnchantEffect = L"";
|
||||
GetState m_PrevState = GetState();
|
||||
};
|
||||
}
|
||||
|
@@ -2,8 +2,10 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include "EntityInterface.h"
|
||||
#include "../Enums/ItemTypeEnum.h"
|
||||
#include "../Helpers/HashCombiner.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
@@ -18,40 +20,36 @@ namespace L2Bot::Domain::Entities
|
||||
{
|
||||
return m_ItemId;
|
||||
}
|
||||
virtual void Update(const EntityInterface* other) override
|
||||
{
|
||||
const BaseItem* casted = static_cast<const BaseItem*>(other);
|
||||
SaveState();
|
||||
|
||||
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;
|
||||
void Update(
|
||||
const uint32_t itemId,
|
||||
const int32_t mana,
|
||||
const std::wstring& name,
|
||||
const std::wstring& iconName,
|
||||
const std::wstring& description,
|
||||
const uint16_t weight
|
||||
) {
|
||||
m_ItemId = itemId;
|
||||
m_Mana = mana;
|
||||
m_Name = name;
|
||||
m_IconName = iconName;
|
||||
m_Description = description;
|
||||
m_Weight = weight;
|
||||
}
|
||||
virtual void SaveState() override
|
||||
virtual const size_t GetHash() const override
|
||||
{
|
||||
m_PrevState =
|
||||
{
|
||||
m_Mana,
|
||||
m_Weight,
|
||||
false
|
||||
};
|
||||
return Helpers::CombineHashes({
|
||||
std::hash<uint32_t>{}(m_ObjectId),
|
||||
std::hash<uint32_t>{}(m_ItemId),
|
||||
std::hash<uint32_t>{}(m_Mana),
|
||||
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 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;
|
||||
return "item";
|
||||
}
|
||||
|
||||
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"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"name", m_Name });
|
||||
result.push_back({ L"iconName", m_IconName });
|
||||
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) });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_Weight != m_PrevState.weight)
|
||||
{
|
||||
result.push_back({ L"weight", std::to_wstring(m_Weight) });
|
||||
}
|
||||
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"iconName", m_IconName });
|
||||
result.push_back({ L"description", m_Description });
|
||||
result.push_back({ L"mana", std::to_wstring(m_Mana) });
|
||||
result.push_back({ L"weight", std::to_wstring(m_Weight) });
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -117,15 +104,6 @@ namespace L2Bot::Domain::Entities
|
||||
BaseItem() = default;
|
||||
virtual ~BaseItem() = default;
|
||||
|
||||
private:
|
||||
struct GetState
|
||||
{
|
||||
int32_t mana = -1;
|
||||
uint16_t weight = 0;
|
||||
|
||||
bool isNewState = true;
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t m_ObjectId = 0;
|
||||
uint32_t m_ItemId = 0;
|
||||
@@ -135,6 +113,5 @@ namespace L2Bot::Domain::Entities
|
||||
std::wstring m_Description = L"";
|
||||
uint16_t m_Weight = 0;
|
||||
Enums::ItemTypeEnum m_Type = Enums::ItemTypeEnum::none;
|
||||
GetState m_PrevState = GetState();
|
||||
};
|
||||
}
|
||||
|
7
L2BotCore/Domain/Entities/ChatMessage.cpp
Normal file
7
L2BotCore/Domain/Entities/ChatMessage.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "..\..\pch.h"
|
||||
#include "ChatMessage.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
uint32_t ChatMessage::m_ChatGlobalId = 0;
|
||||
}
|
66
L2BotCore/Domain/Entities/ChatMessage.h
Normal file
66
L2BotCore/Domain/Entities/ChatMessage.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include "EntityInterface.h"
|
||||
#include "../Enums/ChatChannelEnum.h"
|
||||
#include "../Helpers/HashCombiner.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
class ChatMessage : public EntityInterface
|
||||
{
|
||||
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
|
||||
{
|
||||
return std::vector<Serializers::Node>
|
||||
{
|
||||
{ L"objectId", std::to_wstring(m_ObjectId) },
|
||||
{ L"channel", std::to_wstring(static_cast<uint8_t>(m_Channel)) },
|
||||
{ L"name", m_Name },
|
||||
{ L"text", m_Text }
|
||||
};
|
||||
}
|
||||
|
||||
ChatMessage(
|
||||
const uint32_t objectId,
|
||||
const Enums::ChatChannelEnum channel,
|
||||
const std::wstring& name,
|
||||
const std::wstring& text
|
||||
) :
|
||||
m_Id(++m_ChatGlobalId),
|
||||
m_ObjectId(objectId),
|
||||
m_Channel(channel),
|
||||
m_Name(name),
|
||||
m_Text(text)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~ChatMessage() = default;
|
||||
private:
|
||||
uint32_t m_Id = 0;
|
||||
uint32_t m_ObjectId = 0;
|
||||
Enums::ChatChannelEnum m_Channel = Enums::ChatChannelEnum::all;
|
||||
std::wstring m_Name = L"";
|
||||
std::wstring m_Text = L"";
|
||||
static uint32_t m_ChatGlobalId;
|
||||
};
|
||||
}
|
@@ -8,48 +8,49 @@ namespace L2Bot::Domain::Entities
|
||||
class Drop : public WorldObject
|
||||
{
|
||||
public:
|
||||
void Update(const EntityInterface* other) override
|
||||
{
|
||||
const Drop* casted = static_cast<const Drop*>(other);
|
||||
WorldObject::Update(other);
|
||||
m_ItemId = casted->m_ItemId;
|
||||
m_Amount = casted->m_Amount;
|
||||
m_Name = casted->m_Name;
|
||||
m_IconName = casted->m_IconName;
|
||||
void Update(
|
||||
const ValueObjects::Transform &transform,
|
||||
const uint32_t itemId,
|
||||
const uint32_t amount,
|
||||
const std::wstring& name,
|
||||
const std::wstring& 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();
|
||||
m_IsNewState = false;
|
||||
return Helpers::CombineHashes({
|
||||
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 WorldObject::IsEqual(other) &&
|
||||
m_ItemId == casted->m_ItemId &&
|
||||
m_Amount == casted->m_Amount &&
|
||||
m_Name == casted->m_Name &&
|
||||
m_IconName == casted->m_IconName;
|
||||
return "drop";
|
||||
}
|
||||
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
std::vector<Serializers::Node> result = WorldObject::BuildSerializationNodes();
|
||||
|
||||
if (m_IsNewState)
|
||||
{
|
||||
result.push_back({ L"itemId", std::to_wstring(m_ItemId) });
|
||||
result.push_back({ L"amount", std::to_wstring(m_Amount) });
|
||||
result.push_back({ L"name", m_Name });
|
||||
result.push_back({ L"iconName", m_IconName });
|
||||
}
|
||||
result.push_back({ L"itemId", std::to_wstring(m_ItemId) });
|
||||
result.push_back({ L"amount", std::to_wstring(m_Amount) });
|
||||
result.push_back({ L"name", m_Name });
|
||||
result.push_back({ L"iconName", m_IconName });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Drop(
|
||||
const uint32_t id,
|
||||
const ValueObjects::Transform transform,
|
||||
const ValueObjects::Transform &transform,
|
||||
const uint32_t itemId,
|
||||
const uint32_t amount,
|
||||
const std::wstring& name,
|
||||
@@ -71,6 +72,5 @@ namespace L2Bot::Domain::Entities
|
||||
uint32_t m_Amount = 0;
|
||||
std::wstring m_Name = L"";
|
||||
std::wstring m_IconName = L"";
|
||||
bool m_IsNewState = true;
|
||||
};
|
||||
}
|
||||
|
@@ -2,17 +2,17 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "../Serializers/Serializable.h"
|
||||
#include "Hashable.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
class EntityInterface : public Serializers::Serializable
|
||||
class EntityInterface : public Serializers::Serializable, public Hashable
|
||||
{
|
||||
public:
|
||||
virtual const uint32_t GetId() const = 0;
|
||||
virtual void Update(const EntityInterface* other) = 0;
|
||||
virtual void SaveState() = 0;
|
||||
virtual const bool IsEqual(const EntityInterface* other) const = 0;
|
||||
virtual const std::string GetEntityName() const = 0;
|
||||
|
||||
EntityInterface() = default;
|
||||
virtual ~EntityInterface() = default;
|
||||
|
@@ -2,68 +2,59 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include "BaseItem.h"
|
||||
#include "../Helpers/HashCombiner.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
class EtcItem : public BaseItem
|
||||
{
|
||||
public:
|
||||
void Autouse(bool enabled)
|
||||
void StartAutouse()
|
||||
{
|
||||
m_IsAutoused = enabled;
|
||||
m_IsAutoused = true;
|
||||
}
|
||||
void StopAutouse()
|
||||
{
|
||||
m_IsAutoused = true;
|
||||
}
|
||||
const bool IsAutoused() const
|
||||
{
|
||||
return m_IsAutoused;
|
||||
}
|
||||
|
||||
void Update(const EntityInterface* other) override
|
||||
{
|
||||
const EtcItem* casted = static_cast<const EtcItem*>(other);
|
||||
|
||||
BaseItem::Update(other);
|
||||
void Update(
|
||||
const uint32_t itemId,
|
||||
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);
|
||||
|
||||
m_Amount = casted->m_Amount;
|
||||
m_IsQuest = casted->m_IsQuest;
|
||||
m_IsAutoused = casted->m_IsAutoused;
|
||||
m_Amount = amount;
|
||||
m_IsQuest = isQuest;
|
||||
}
|
||||
void SaveState() override
|
||||
const size_t GetHash() const override
|
||||
{
|
||||
BaseItem::SaveState();
|
||||
m_PrevState =
|
||||
{
|
||||
m_Amount,
|
||||
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;
|
||||
return Helpers::CombineHashes({
|
||||
BaseItem::GetHash(),
|
||||
std::hash<uint32_t>{}(m_Amount),
|
||||
std::hash<bool>{}(m_IsQuest)
|
||||
});
|
||||
}
|
||||
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
std::vector<Serializers::Node> result = BaseItem::BuildSerializationNodes();
|
||||
|
||||
if (m_PrevState.isNewState)
|
||||
{
|
||||
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) });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_IsAutoused != m_PrevState.isAutoused)
|
||||
{
|
||||
result.push_back({ L"isAutoused", std::to_wstring(m_IsAutoused) });
|
||||
}
|
||||
result.push_back({ L"isQuest", std::to_wstring(m_IsQuest) });
|
||||
result.push_back({ L"amount", std::to_wstring(m_Amount) });
|
||||
result.push_back({ L"isAutoused", std::to_wstring(m_IsAutoused) });
|
||||
|
||||
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;
|
||||
virtual ~EtcItem() = default;
|
||||
|
||||
private:
|
||||
struct GetState
|
||||
{
|
||||
uint32_t amount = 0;
|
||||
bool isAutoused = false;
|
||||
|
||||
bool isNewState = true;
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t m_Amount = 0;
|
||||
bool m_IsQuest = false;
|
||||
bool m_IsAutoused = false;
|
||||
GetState m_PrevState = GetState();
|
||||
};
|
||||
}
|
||||
|
15
L2BotCore/Domain/Entities/Hashable.h
Normal file
15
L2BotCore/Domain/Entities/Hashable.h
Normal 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;
|
||||
};
|
||||
}
|
@@ -15,114 +15,82 @@ namespace L2Bot::Domain::Entities
|
||||
class Hero : public WorldObject
|
||||
{
|
||||
public:
|
||||
void Update(const EntityInterface* other) override
|
||||
{
|
||||
const Hero* casted = static_cast<const Hero*>(other);
|
||||
WorldObject::Update(other);
|
||||
m_FullName = casted->m_FullName;
|
||||
m_VitalStats = casted->m_VitalStats;
|
||||
m_Phenotype = casted->m_Phenotype;
|
||||
m_ExperienceInfo = casted->m_ExperienceInfo;
|
||||
m_PermanentStats = casted->m_PermanentStats;
|
||||
m_VariableStats = casted->m_VariableStats;
|
||||
m_Reputation = casted->m_Reputation;
|
||||
m_InventoryInfo = casted->m_InventoryInfo;
|
||||
m_TargetId = casted->m_TargetId;
|
||||
m_IsStanding = casted->m_IsStanding;
|
||||
void Update(
|
||||
const ValueObjects::Transform& transform,
|
||||
const ValueObjects::FullName& fullName,
|
||||
const ValueObjects::VitalStats& vitalStats,
|
||||
const ValueObjects::Phenotype& phenotype,
|
||||
const ValueObjects::ExperienceInfo& experienceInfo,
|
||||
const ValueObjects::PermanentStats& permanentStats,
|
||||
const ValueObjects::VariableStats& variableStats,
|
||||
const ValueObjects::Reputation& reputation,
|
||||
const ValueObjects::InventoryInfo& inventoryInfo,
|
||||
const uint32_t targetId,
|
||||
const bool 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();
|
||||
m_PrevState =
|
||||
{
|
||||
m_FullName,
|
||||
m_VitalStats,
|
||||
m_Phenotype,
|
||||
m_ExperienceInfo,
|
||||
m_PermanentStats,
|
||||
m_VariableStats,
|
||||
m_Reputation,
|
||||
m_InventoryInfo,
|
||||
m_TargetId,
|
||||
m_IsStanding,
|
||||
false
|
||||
};
|
||||
return Helpers::CombineHashes({
|
||||
WorldObject::GetHash(),
|
||||
m_FullName.GetHash(),
|
||||
m_VitalStats.GetHash(),
|
||||
m_Phenotype.GetHash(),
|
||||
m_ExperienceInfo.GetHash(),
|
||||
m_PermanentStats.GetHash(),
|
||||
m_VariableStats.GetHash(),
|
||||
m_Reputation.GetHash(),
|
||||
m_InventoryInfo.GetHash(),
|
||||
std::hash<uint32_t>{}(m_TargetId),
|
||||
std::hash<uint32_t>{}(m_IsStanding)
|
||||
});
|
||||
}
|
||||
const bool IsEqual(const EntityInterface* other) const override
|
||||
const std::string GetEntityName() const override
|
||||
{
|
||||
const Hero* casted = static_cast<const Hero*>(other);
|
||||
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;
|
||||
return "hero";
|
||||
}
|
||||
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
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() });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_VitalStats.IsEqual(&m_PrevState.vitalStats))
|
||||
{
|
||||
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() });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_ExperienceInfo.IsEqual(&m_PrevState.experienceInfo))
|
||||
{
|
||||
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() });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_VariableStats.IsEqual(&m_PrevState.variableStats))
|
||||
{
|
||||
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() });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_InventoryInfo.IsEqual(&m_PrevState.inventoryInfo))
|
||||
{
|
||||
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) });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_IsStanding != m_PrevState.isStanding)
|
||||
{
|
||||
result.push_back({ L"isStanding", std::to_wstring(m_IsStanding) });
|
||||
}
|
||||
result.push_back({ L"fullName", m_FullName.BuildSerializationNodes() });
|
||||
result.push_back({ L"vitalStats", m_VitalStats.BuildSerializationNodes() });
|
||||
result.push_back({ L"phenotype", m_Phenotype.BuildSerializationNodes() });
|
||||
result.push_back({ L"experienceInfo", m_ExperienceInfo.BuildSerializationNodes() });
|
||||
result.push_back({ L"permanentStats", m_PermanentStats.BuildSerializationNodes() });
|
||||
result.push_back({ L"variableStats", m_VariableStats.BuildSerializationNodes() });
|
||||
result.push_back({ L"reputation", m_Reputation.BuildSerializationNodes() });
|
||||
result.push_back({ L"inventoryInfo", m_InventoryInfo.BuildSerializationNodes() });
|
||||
result.push_back({ L"targetId", std::to_wstring(m_TargetId) });
|
||||
result.push_back({ L"isStanding", std::to_wstring(m_IsStanding) });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Hero(
|
||||
const uint32_t id,
|
||||
const ValueObjects::Transform transform,
|
||||
const ValueObjects::FullName fullName,
|
||||
const ValueObjects::VitalStats vitalStats,
|
||||
const ValueObjects::Phenotype phenotype,
|
||||
const ValueObjects::ExperienceInfo experienceInfo,
|
||||
const ValueObjects::PermanentStats permanentStats,
|
||||
const ValueObjects::VariableStats variableStats,
|
||||
const ValueObjects::Reputation reputation,
|
||||
const ValueObjects::InventoryInfo inventoryInfo,
|
||||
const ValueObjects::Transform& transform,
|
||||
const ValueObjects::FullName& fullName,
|
||||
const ValueObjects::VitalStats& vitalStats,
|
||||
const ValueObjects::Phenotype& phenotype,
|
||||
const ValueObjects::ExperienceInfo& experienceInfo,
|
||||
const ValueObjects::PermanentStats& permanentStats,
|
||||
const ValueObjects::VariableStats& variableStats,
|
||||
const ValueObjects::Reputation& reputation,
|
||||
const ValueObjects::InventoryInfo& inventoryInfo,
|
||||
const uint32_t targetId,
|
||||
const bool isStanding
|
||||
) :
|
||||
@@ -144,23 +112,6 @@ namespace L2Bot::Domain::Entities
|
||||
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:
|
||||
ValueObjects::FullName m_FullName = ValueObjects::FullName();
|
||||
ValueObjects::VitalStats m_VitalStats = ValueObjects::VitalStats();
|
||||
@@ -172,6 +123,5 @@ namespace L2Bot::Domain::Entities
|
||||
ValueObjects::InventoryInfo m_InventoryInfo = ValueObjects::InventoryInfo();
|
||||
uint32_t m_TargetId = 0;
|
||||
bool m_IsStanding = true;
|
||||
GetState m_PrevState = GetState();
|
||||
};
|
||||
}
|
||||
|
@@ -11,76 +11,66 @@ namespace L2Bot::Domain::Entities
|
||||
class NPC : public WorldObject
|
||||
{
|
||||
public:
|
||||
void Update(const EntityInterface* other) override
|
||||
void UpdateSpoilState(const Enums::SpoilStateEnum spoilState)
|
||||
{
|
||||
const NPC* casted = static_cast<const NPC*>(other);
|
||||
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;
|
||||
m_SpoilState = spoilState;
|
||||
}
|
||||
void SaveState() override
|
||||
{
|
||||
WorldObject::SaveState();
|
||||
m_PrevState =
|
||||
{
|
||||
m_FullName,
|
||||
m_SpoilState,
|
||||
m_VitalStats,
|
||||
false
|
||||
};
|
||||
|
||||
void Update(
|
||||
const ValueObjects::Transform& transform,
|
||||
const bool isHostile,
|
||||
const uint32_t npcId,
|
||||
const ValueObjects::FullName& fullName,
|
||||
const ValueObjects::VitalStats& vitalStats
|
||||
) {
|
||||
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 WorldObject::IsEqual(other) &&
|
||||
m_IsHostile == casted->m_IsHostile &&
|
||||
m_NpcId == casted->m_NpcId &&
|
||||
m_SpoilState == casted->m_SpoilState &&
|
||||
m_FullName.IsEqual(&casted->m_FullName) &&
|
||||
m_VitalStats.IsEqual(&casted->m_VitalStats);
|
||||
return Helpers::CombineHashes({
|
||||
WorldObject::GetHash(),
|
||||
std::hash<bool>{}(m_IsHostile),
|
||||
std::hash<uint32_t>{}(m_NpcId),
|
||||
std::hash<Enums::SpoilStateEnum>{}(m_SpoilState),
|
||||
m_FullName.GetHash(),
|
||||
m_VitalStats.GetHash()
|
||||
});
|
||||
}
|
||||
const std::string GetEntityName() const override
|
||||
{
|
||||
return "npc";
|
||||
}
|
||||
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
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() });
|
||||
}
|
||||
if (m_PrevState.isNewState)
|
||||
{
|
||||
result.push_back({ L"isHostile", std::to_wstring(m_IsHostile) });
|
||||
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)) });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_VitalStats.IsEqual(&m_PrevState.vitalStats))
|
||||
{
|
||||
result.push_back({ L"vitalStats", m_VitalStats.BuildSerializationNodes() });
|
||||
}
|
||||
result.push_back({ L"fullName", m_FullName.BuildSerializationNodes() });
|
||||
result.push_back({ L"isHostile", std::to_wstring(m_IsHostile) });
|
||||
result.push_back({ L"npcId", std::to_wstring(m_NpcId) });
|
||||
result.push_back({ L"spoilState", std::to_wstring(static_cast<uint32_t>(m_SpoilState)) });
|
||||
result.push_back({ L"vitalStats", m_VitalStats.BuildSerializationNodes() });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
NPC(
|
||||
const uint32_t id,
|
||||
const ValueObjects::Transform transform,
|
||||
const ValueObjects::Transform& transform,
|
||||
const bool isHostile,
|
||||
const uint32_t npcId,
|
||||
const Enums::SpoilStateEnum spoilState,
|
||||
const ValueObjects::FullName fullName,
|
||||
const ValueObjects::VitalStats vitalStats
|
||||
const ValueObjects::FullName& fullName,
|
||||
const ValueObjects::VitalStats& vitalStats
|
||||
) :
|
||||
WorldObject(id, transform),
|
||||
m_IsHostile(isHostile),
|
||||
m_NpcId(npcId),
|
||||
m_SpoilState(spoilState),
|
||||
m_FullName(fullName),
|
||||
m_VitalStats(vitalStats)
|
||||
{
|
||||
@@ -90,22 +80,11 @@ namespace L2Bot::Domain::Entities
|
||||
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:
|
||||
bool m_IsHostile = false;
|
||||
uint32_t m_NpcId = 0;
|
||||
Enums::SpoilStateEnum m_SpoilState = Enums::SpoilStateEnum::none;
|
||||
ValueObjects::FullName m_FullName = ValueObjects::FullName();
|
||||
ValueObjects::VitalStats m_VitalStats = ValueObjects::VitalStats();
|
||||
GetState m_PrevState = GetState();
|
||||
};
|
||||
}
|
||||
|
@@ -9,60 +9,49 @@ namespace L2Bot::Domain::Entities
|
||||
class Player : public WorldObject
|
||||
{
|
||||
public:
|
||||
void Update(const EntityInterface* other) override
|
||||
{
|
||||
const Player* casted = static_cast<const Player*>(other);
|
||||
WorldObject::Update(other);
|
||||
m_FullName = casted->m_FullName;
|
||||
m_Phenotype = casted->m_Phenotype;
|
||||
m_VitalStats = casted->m_VitalStats;
|
||||
void Update(
|
||||
const ValueObjects::Transform& transform,
|
||||
const ValueObjects::FullName& fullName,
|
||||
const ValueObjects::Phenotype& phenotype,
|
||||
const ValueObjects::VitalStats& vitalStats
|
||||
) {
|
||||
WorldObject::Update(transform);
|
||||
|
||||
m_FullName = fullName;
|
||||
m_Phenotype = phenotype;
|
||||
m_VitalStats = vitalStats;
|
||||
}
|
||||
void SaveState() override
|
||||
const size_t GetHash() const override
|
||||
{
|
||||
WorldObject::SaveState();
|
||||
m_PrevState =
|
||||
{
|
||||
m_FullName,
|
||||
m_Phenotype,
|
||||
m_VitalStats,
|
||||
false
|
||||
};
|
||||
return Helpers::CombineHashes({
|
||||
WorldObject::GetHash(),
|
||||
m_FullName.GetHash(),
|
||||
m_Phenotype.GetHash(),
|
||||
m_VitalStats.GetHash()
|
||||
});
|
||||
}
|
||||
const bool IsEqual(const EntityInterface* other) const override
|
||||
const std::string GetEntityName() const override
|
||||
{
|
||||
const Player* casted = static_cast<const Player*>(other);
|
||||
return WorldObject::IsEqual(other) &&
|
||||
m_FullName.IsEqual(&casted->m_FullName) &&
|
||||
m_Phenotype.IsEqual(&casted->m_Phenotype) &&
|
||||
m_VitalStats.IsEqual(&casted->m_VitalStats);
|
||||
return "player";
|
||||
}
|
||||
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
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() });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_Phenotype.IsEqual(&m_PrevState.phenotype))
|
||||
{
|
||||
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"fullName", m_FullName.BuildSerializationNodes() });
|
||||
result.push_back({ L"phenotype", m_Phenotype.BuildSerializationNodes() });
|
||||
result.push_back({ L"vitalStats", m_VitalStats.BuildSerializationNodes() });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Player(
|
||||
const uint32_t id,
|
||||
const ValueObjects::Transform transform,
|
||||
const ValueObjects::FullName fullName,
|
||||
const ValueObjects::Phenotype phenotype,
|
||||
const ValueObjects::VitalStats vitalStats
|
||||
const ValueObjects::Transform& transform,
|
||||
const ValueObjects::FullName& fullName,
|
||||
const ValueObjects::Phenotype& phenotype,
|
||||
const ValueObjects::VitalStats& vitalStats
|
||||
) :
|
||||
WorldObject(id, transform),
|
||||
m_FullName(fullName),
|
||||
@@ -74,20 +63,9 @@ namespace L2Bot::Domain::Entities
|
||||
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:
|
||||
ValueObjects::FullName m_FullName = ValueObjects::FullName();
|
||||
ValueObjects::Phenotype m_Phenotype = ValueObjects::Phenotype();
|
||||
ValueObjects::VitalStats m_VitalStats = ValueObjects::VitalStats();
|
||||
GetState m_PrevState = GetState();
|
||||
};
|
||||
}
|
||||
|
@@ -2,73 +2,62 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include "BaseItem.h"
|
||||
#include "../Enums/CrystalTypeEnum.h"
|
||||
#include "../Helpers/HashCombiner.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
class ShieldItem : public BaseItem
|
||||
{
|
||||
public:
|
||||
void Update(const EntityInterface* other) override
|
||||
{
|
||||
const ShieldItem* casted = static_cast<const ShieldItem*>(other);
|
||||
void Update(
|
||||
const uint32_t itemId,
|
||||
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 = 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;
|
||||
m_IsEquipped = isEquipped;
|
||||
m_EnchantLevel = enchantLevel;
|
||||
m_CrystalType = crystalType;
|
||||
m_Evasion = evasion;
|
||||
m_PDefense = pDefense;
|
||||
m_DefRate = defRate;
|
||||
}
|
||||
void SaveState() override
|
||||
const size_t GetHash() const override
|
||||
{
|
||||
BaseItem::SaveState();
|
||||
m_PrevState =
|
||||
{
|
||||
m_IsEquipped,
|
||||
m_EnchantLevel,
|
||||
m_PDefense,
|
||||
false
|
||||
};
|
||||
}
|
||||
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;
|
||||
return Helpers::CombineHashes({
|
||||
BaseItem::GetHash(),
|
||||
std::hash<bool>{}(m_IsEquipped),
|
||||
std::hash<uint16_t>{}(m_EnchantLevel),
|
||||
std::hash<Enums::CrystalTypeEnum>{}(m_CrystalType),
|
||||
std::hash<int16_t>{}(m_Evasion),
|
||||
std::hash<uint32_t>{}(m_PDefense),
|
||||
std::hash<uint16_t>{}(m_DefRate)
|
||||
});
|
||||
}
|
||||
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
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"evasion", std::to_wstring(m_Evasion) });
|
||||
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) });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_EnchantLevel != m_PrevState.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"crystalType", std::to_wstring(static_cast<int8_t>(m_CrystalType)) });
|
||||
result.push_back({ L"evasion", std::to_wstring(m_Evasion) });
|
||||
result.push_back({ L"defRate", std::to_wstring(m_DefRate) });
|
||||
result.push_back({ L"isEquipped", std::to_wstring(m_IsEquipped) });
|
||||
result.push_back({ L"enchantLevel", std::to_wstring(m_EnchantLevel) });
|
||||
result.push_back({ L"pDefense", std::to_wstring(m_PDefense) });
|
||||
|
||||
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;
|
||||
virtual ~ShieldItem() = default;
|
||||
|
||||
private:
|
||||
struct GetState
|
||||
{
|
||||
bool isEquipped = 0;
|
||||
uint16_t enchantLevel = 0;
|
||||
uint32_t pDefense = 0;
|
||||
|
||||
bool isNewState = true;
|
||||
};
|
||||
|
||||
private:
|
||||
bool m_IsEquipped = 0;
|
||||
uint16_t m_EnchantLevel = 0;
|
||||
@@ -140,7 +107,5 @@ namespace L2Bot::Domain::Entities
|
||||
int16_t m_Evasion = 0;
|
||||
uint32_t m_PDefense = 0;
|
||||
uint16_t m_DefRate = 0;
|
||||
|
||||
GetState m_PrevState = GetState();
|
||||
};
|
||||
}
|
||||
|
@@ -2,25 +2,14 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include "EntityInterface.h"
|
||||
#include "../Helpers/HashCombiner.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
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:
|
||||
const uint32_t GetId() const override
|
||||
{
|
||||
@@ -59,180 +48,89 @@ namespace L2Bot::Domain::Entities
|
||||
{
|
||||
m_IsToggled = false;
|
||||
}
|
||||
void Update(const Data &data) {
|
||||
m_Level = data.level;
|
||||
m_IsActive = data.isActive;
|
||||
m_Cost = data.cost;
|
||||
m_Range = data.range;
|
||||
m_Name = data.name;
|
||||
m_Description = data.description;
|
||||
m_IconName = data.iconName;
|
||||
void Update(
|
||||
const uint8_t level,
|
||||
const bool isActive,
|
||||
const uint8_t cost,
|
||||
const int16_t range,
|
||||
const std::wstring& name,
|
||||
const std::wstring& description,
|
||||
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
|
||||
{
|
||||
std::vector<Serializers::Node> result;
|
||||
|
||||
result.push_back({ L"id", std::to_wstring(m_SkillId) });
|
||||
result.push_back({ L"level", std::to_wstring(m_Level) });
|
||||
|
||||
if (m_PrevState.isNewState)
|
||||
{
|
||||
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 });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_IconName != m_PrevState.iconName)
|
||||
{
|
||||
result.push_back({ L"iconName", m_IconName });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_Description != m_PrevState.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) });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_Range != m_PrevState.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) });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_IsCasting != m_PrevState.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) });
|
||||
}
|
||||
if (m_PrevState.isNewState || IsReadyToUse() != m_PrevState.isReadyToUse)
|
||||
{
|
||||
result.push_back({ L"isReadyToUse", std::to_wstring(IsReadyToUse()) });
|
||||
}
|
||||
result.push_back({ L"isActive", std::to_wstring(m_IsActive) });
|
||||
result.push_back({ L"name", m_Name });
|
||||
result.push_back({ L"iconName", m_IconName });
|
||||
result.push_back({ L"description", m_Description });
|
||||
result.push_back({ L"cost", std::to_wstring(m_Cost) });
|
||||
result.push_back({ L"range", std::to_wstring(m_Range) });
|
||||
result.push_back({ L"isToggled", std::to_wstring(m_IsToggled) });
|
||||
result.push_back({ L"isCasting", std::to_wstring(m_IsCasting) });
|
||||
result.push_back({ L"isReloading", std::to_wstring(m_IsReloading) });
|
||||
result.push_back({ L"isReadyToUse", std::to_wstring(IsReadyToUse()) });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Skill(const Data &data) :
|
||||
m_SkillId(data.skillId),
|
||||
m_Level(data.level),
|
||||
m_IsActive(data.isActive),
|
||||
m_Cost(data.cost),
|
||||
m_Range(data.range),
|
||||
m_Name(data.name),
|
||||
m_Description(data.description),
|
||||
m_IconName(data.iconName)
|
||||
Skill(
|
||||
const uint32_t skillId,
|
||||
const uint8_t level,
|
||||
const bool isActive,
|
||||
const uint8_t cost,
|
||||
const int16_t range,
|
||||
const std::wstring& name,
|
||||
const std::wstring& description,
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
}
|
||||
|
||||
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:
|
||||
uint32_t m_SkillId = 0;
|
||||
uint8_t m_Level = 0;
|
||||
@@ -245,6 +143,5 @@ namespace L2Bot::Domain::Entities
|
||||
bool m_IsToggled = false;
|
||||
bool m_IsCasting = false;
|
||||
bool m_IsReloading = false;
|
||||
GetState m_PrevState = GetState();
|
||||
};
|
||||
}
|
||||
|
@@ -2,99 +2,91 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include "BaseItem.h"
|
||||
#include "../Enums/WeaponTypeEnum.h"
|
||||
#include "../Enums/CrystalTypeEnum.h"
|
||||
#include "../Helpers/HashCombiner.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
class WeaponItem : public BaseItem
|
||||
{
|
||||
public:
|
||||
void Update(const EntityInterface* other) override
|
||||
{
|
||||
const WeaponItem* casted = static_cast<const WeaponItem*>(other);
|
||||
void Update(
|
||||
const uint32_t itemId,
|
||||
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 = casted->m_IsEquipped;
|
||||
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;
|
||||
m_IsEquipped = isEquipped;
|
||||
m_EnchantLevel = enchantLevel;
|
||||
m_WeaponType = weaponType;
|
||||
m_CrystalType = crystalType;
|
||||
m_RndDamage = rndDamage;
|
||||
m_PAttack = pAttack;
|
||||
m_MAttack = mAttack;
|
||||
m_Critical = critical;
|
||||
m_HitModify = hitModify;
|
||||
m_AttackSpeed = attackSpeed;
|
||||
m_MpConsume = mpConsume;
|
||||
m_SoulshotCount = soulshotCount;
|
||||
m_SpiritshotCount = spiritshotCount;
|
||||
}
|
||||
void SaveState() override
|
||||
const size_t GetHash() const override
|
||||
{
|
||||
BaseItem::SaveState();
|
||||
m_PrevState =
|
||||
{
|
||||
m_IsEquipped,
|
||||
m_EnchantLevel,
|
||||
m_PAttack,
|
||||
m_MAttack,
|
||||
false
|
||||
};
|
||||
}
|
||||
const bool IsEqual(const EntityInterface* other) const override
|
||||
{
|
||||
const WeaponItem* casted = static_cast<const WeaponItem*>(other);
|
||||
return BaseItem::IsEqual(other) &&
|
||||
m_IsEquipped == casted->m_IsEquipped &&
|
||||
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;
|
||||
return Helpers::CombineHashes({
|
||||
BaseItem::GetHash(),
|
||||
std::hash<bool>{}(m_IsEquipped),
|
||||
std::hash<uint16_t>{}(m_EnchantLevel),
|
||||
std::hash<Enums::WeaponTypeEnum>{}(m_WeaponType),
|
||||
std::hash<Enums::CrystalTypeEnum>{}(m_CrystalType),
|
||||
std::hash<uint8_t>{}(m_RndDamage),
|
||||
std::hash<uint32_t>{}(m_PAttack),
|
||||
std::hash<uint32_t>{}(m_MAttack),
|
||||
std::hash<uint16_t>{}(m_Critical),
|
||||
std::hash<int8_t>{}(m_HitModify),
|
||||
std::hash<uint16_t>{}(m_AttackSpeed),
|
||||
std::hash<uint8_t>{}(m_MpConsume),
|
||||
std::hash<uint8_t>{}(m_SoulshotCount),
|
||||
std::hash<uint8_t>{}(m_SpiritshotCount)
|
||||
});
|
||||
}
|
||||
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
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"crystalType", std::to_wstring(static_cast<int8_t>(m_CrystalType)) });
|
||||
result.push_back({ L"rndDamage", std::to_wstring(m_RndDamage) });
|
||||
result.push_back({ L"critical", std::to_wstring(m_Critical) });
|
||||
result.push_back({ L"hitModify", std::to_wstring(m_HitModify) });
|
||||
result.push_back({ L"attackSpeed", std::to_wstring(m_AttackSpeed) });
|
||||
result.push_back({ L"mpConsume", std::to_wstring(m_MpConsume) });
|
||||
result.push_back({ L"soulshotCount", std::to_wstring(m_SoulshotCount) });
|
||||
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) });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_EnchantLevel != m_PrevState.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) });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_MAttack != m_PrevState.mAttack)
|
||||
{
|
||||
result.push_back({ L"mAttack", std::to_wstring(m_MAttack) });
|
||||
}
|
||||
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"rndDamage", std::to_wstring(m_RndDamage) });
|
||||
result.push_back({ L"critical", std::to_wstring(m_Critical) });
|
||||
result.push_back({ L"hitModify", std::to_wstring(m_HitModify) });
|
||||
result.push_back({ L"attackSpeed", std::to_wstring(m_AttackSpeed) });
|
||||
result.push_back({ L"mpConsume", std::to_wstring(m_MpConsume) });
|
||||
result.push_back({ L"soulshotCount", std::to_wstring(m_SoulshotCount) });
|
||||
result.push_back({ L"spiritshotCount", std::to_wstring(m_SpiritshotCount) });
|
||||
result.push_back({ L"isEquipped", std::to_wstring(m_IsEquipped) });
|
||||
result.push_back({ L"enchantLevel", std::to_wstring(m_EnchantLevel) });
|
||||
result.push_back({ L"pAttack", std::to_wstring(m_PAttack) });
|
||||
result.push_back({ L"mAttack", std::to_wstring(m_MAttack) });
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -116,7 +108,7 @@ namespace L2Bot::Domain::Entities
|
||||
const uint32_t mAttack,
|
||||
const uint16_t critical,
|
||||
const int8_t hitModify,
|
||||
const uint16_t atkSpd,
|
||||
const uint16_t attackSpeed,
|
||||
const uint8_t mpConsume,
|
||||
const uint8_t soulshotCount,
|
||||
const uint8_t spiritshotCount
|
||||
@@ -141,46 +133,16 @@ namespace L2Bot::Domain::Entities
|
||||
m_MAttack(mAttack),
|
||||
m_Critical(critical),
|
||||
m_HitModify(hitModify),
|
||||
m_AttackSpeed(atkSpd),
|
||||
m_AttackSpeed(attackSpeed),
|
||||
m_MpConsume(mpConsume),
|
||||
m_SoulshotCount(soulshotCount),
|
||||
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;
|
||||
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:
|
||||
bool m_IsEquipped = 0;
|
||||
uint16_t m_EnchantLevel = 0;
|
||||
@@ -195,7 +157,5 @@ namespace L2Bot::Domain::Entities
|
||||
uint8_t m_MpConsume = 0;
|
||||
uint8_t m_SoulshotCount = 0;
|
||||
uint8_t m_SpiritshotCount = 0;
|
||||
|
||||
GetState m_PrevState = GetState();
|
||||
};
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include "../ValueObjects/Transform.h"
|
||||
#include "EntityInterface.h"
|
||||
#include "../Helpers/HashCombiner.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
@@ -12,22 +14,16 @@ namespace L2Bot::Domain::Entities
|
||||
{
|
||||
return m_Id;
|
||||
}
|
||||
virtual void Update(const EntityInterface* other) override
|
||||
virtual void Update(const ValueObjects::Transform& transform)
|
||||
{
|
||||
SaveState();
|
||||
|
||||
const WorldObject* casted = static_cast<const WorldObject*>(other);
|
||||
m_Id = casted->m_Id;
|
||||
m_Transform = casted->m_Transform;
|
||||
m_Transform = transform;
|
||||
}
|
||||
virtual void SaveState() override
|
||||
virtual const size_t GetHash() const override
|
||||
{
|
||||
m_PrevState = { m_Transform, false };
|
||||
}
|
||||
virtual const bool IsEqual(const EntityInterface* other) const override
|
||||
{
|
||||
const WorldObject* casted = static_cast<const WorldObject*>(other);
|
||||
return m_Id == casted->m_Id && m_Transform.IsEqual(&casted->m_Transform);
|
||||
return Helpers::CombineHashes({
|
||||
std::hash<uint32_t>{}(m_Id),
|
||||
m_Transform.GetHash()
|
||||
});
|
||||
}
|
||||
|
||||
virtual const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
@@ -35,15 +31,12 @@ namespace L2Bot::Domain::Entities
|
||||
std::vector<Serializers::Node> result;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
WorldObject(const uint32_t id, const ValueObjects::Transform transform) :
|
||||
WorldObject(const uint32_t id, const ValueObjects::Transform& transform) :
|
||||
m_Id(id), m_Transform(transform)
|
||||
{
|
||||
|
||||
@@ -51,18 +44,9 @@ namespace L2Bot::Domain::Entities
|
||||
|
||||
WorldObject() = default;
|
||||
virtual ~WorldObject() = default;
|
||||
private:
|
||||
private:
|
||||
struct GetState
|
||||
{
|
||||
ValueObjects::Transform transform = ValueObjects::Transform();
|
||||
|
||||
bool isNewState = true;
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t m_Id = 0;
|
||||
ValueObjects::Transform m_Transform = ValueObjects::Transform();
|
||||
GetState m_PrevState = GetState();
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user