refactor: remove unnecessary classes
This commit is contained in:
@@ -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();
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user