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,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();
};
}