Add project files.
This commit is contained in:
97
L2BotCore/Domain/Entities/Drop.h
Normal file
97
L2BotCore/Domain/Entities/Drop.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include "WorldObject.h"
|
||||
#include "../DTO/Drop.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
class Drop : public WorldObject
|
||||
{
|
||||
public:
|
||||
const uint32_t GetItemId() const
|
||||
{
|
||||
return m_ItemId;
|
||||
}
|
||||
const uint32_t GetAmount() const
|
||||
{
|
||||
return m_Amount;
|
||||
}
|
||||
const std::string GetName() const
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
const std::string GetIconName() const
|
||||
{
|
||||
return m_IconName;
|
||||
}
|
||||
void UpdateFromDTO(const DTO::WorldObject* dto) override
|
||||
{
|
||||
const DTO::Drop* castedDto = static_cast<const DTO::Drop*>(dto);
|
||||
WorldObject::UpdateFromDTO(dto);
|
||||
m_ItemId = castedDto->itemId;
|
||||
m_Amount = castedDto->amount;
|
||||
m_Name = castedDto->name;
|
||||
m_IconName = castedDto->iconName;
|
||||
}
|
||||
void SaveState() override
|
||||
{
|
||||
WorldObject::SaveState();
|
||||
m_IsNewState = false;
|
||||
}
|
||||
const static Drop CreateFromDTO(const DTO::Drop& dto)
|
||||
{
|
||||
return Drop(dto.id, dto.transform, dto.itemId, dto.amount, dto.name, dto.iconName);
|
||||
}
|
||||
const bool IsEqual(const DTO::WorldObject* dto) const override
|
||||
{
|
||||
const DTO::Drop* castedDto = static_cast<const DTO::Drop*>(dto);
|
||||
return WorldObject::IsEqual(dto) &&
|
||||
m_ItemId == castedDto->itemId &&
|
||||
m_Amount == castedDto->amount &&
|
||||
m_Name == castedDto->name &&
|
||||
m_IconName == castedDto->iconName;
|
||||
}
|
||||
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
std::vector<Serializers::Node> result = WorldObject::BuildSerializationNodes();
|
||||
|
||||
if (m_IsNewState)
|
||||
{
|
||||
result.push_back({ "itemId", std::to_string(m_ItemId) });
|
||||
result.push_back({ "amount", std::to_string(m_Amount) });
|
||||
result.push_back({ "name", m_Name });
|
||||
result.push_back({ "iconName", m_IconName });
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Drop(
|
||||
const uint32_t id,
|
||||
const ValueObjects::Transform transform,
|
||||
const uint32_t itemId,
|
||||
const uint32_t amount,
|
||||
const std::string name,
|
||||
const std::string iconName
|
||||
) :
|
||||
WorldObject(id, transform),
|
||||
m_ItemId(itemId),
|
||||
m_Amount(amount),
|
||||
m_Name(name),
|
||||
m_IconName(iconName)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Drop() = default;
|
||||
virtual ~Drop() = default;
|
||||
private:
|
||||
uint32_t m_ItemId = 0;
|
||||
uint32_t m_Amount = 0;
|
||||
std::string m_Name = "";
|
||||
std::string m_IconName = "";
|
||||
bool m_IsNewState = true;
|
||||
};
|
||||
}
|
235
L2BotCore/Domain/Entities/Hero.h
Normal file
235
L2BotCore/Domain/Entities/Hero.h
Normal file
@@ -0,0 +1,235 @@
|
||||
#pragma once
|
||||
#include "WorldObject.h"
|
||||
#include "../DTO/Hero.h"
|
||||
#include "../ValueObjects/FullName.h"
|
||||
#include "../ValueObjects/VitalStats.h"
|
||||
#include "../ValueObjects/Phenotype.h"
|
||||
#include "../ValueObjects/ExperienceInfo.h"
|
||||
#include "../ValueObjects/PermanentStats.h"
|
||||
#include "../ValueObjects/VariableStats.h"
|
||||
#include "../ValueObjects/Reputation.h"
|
||||
#include "../ValueObjects/InventoryInfo.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
class Hero : public WorldObject
|
||||
{
|
||||
public:
|
||||
const ValueObjects::FullName& GetFullName() const
|
||||
{
|
||||
return m_FullName;
|
||||
}
|
||||
const ValueObjects::VitalStats& GetVitalStats() const
|
||||
{
|
||||
return m_VitalStats;
|
||||
}
|
||||
const ValueObjects::Phenotype& GetPhenotype() const
|
||||
{
|
||||
return m_Phenotype;
|
||||
}
|
||||
const ValueObjects::ExperienceInfo& GetExperienceInfo() const
|
||||
{
|
||||
return m_ExperienceInfo;
|
||||
}
|
||||
const ValueObjects::PermanentStats& GetPermanentStats() const
|
||||
{
|
||||
return m_PermanentStats;
|
||||
}
|
||||
const ValueObjects::VariableStats& GetVariableStats() const
|
||||
{
|
||||
return m_VariableStats;
|
||||
}
|
||||
const ValueObjects::Reputation& GetReputation() const
|
||||
{
|
||||
return m_Reputation;
|
||||
}
|
||||
const ValueObjects::InventoryInfo& GetInventoryInfo() const
|
||||
{
|
||||
return m_InventoryInfo;
|
||||
}
|
||||
const uint32_t GetTargetId() const
|
||||
{
|
||||
return m_TargetId;
|
||||
}
|
||||
const bool IsStanding() const
|
||||
{
|
||||
return m_IsStanding;
|
||||
}
|
||||
void UpdateFromDTO(const DTO::WorldObject* dto) override
|
||||
{
|
||||
const DTO::Hero* castedDto = static_cast<const DTO::Hero*>(dto);
|
||||
WorldObject::UpdateFromDTO(dto);
|
||||
m_FullName = castedDto->fullName;
|
||||
m_VitalStats = castedDto->vitalStats;
|
||||
m_Phenotype = castedDto->phenotype;
|
||||
m_ExperienceInfo = castedDto->experienceInfo;
|
||||
m_PermanentStats = castedDto->permanentStats;
|
||||
m_VariableStats = castedDto->variableStats;
|
||||
m_Reputation = castedDto->reputation;
|
||||
m_InventoryInfo = castedDto->inventoryInfo;
|
||||
m_TargetId = castedDto->targetId;
|
||||
m_IsStanding = castedDto->isStanding;
|
||||
}
|
||||
void SaveState() 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
|
||||
};
|
||||
}
|
||||
const static Hero CreateFromDTO(const DTO::Hero& dto)
|
||||
{
|
||||
return Hero(
|
||||
dto.id,
|
||||
dto.transform,
|
||||
dto.fullName,
|
||||
dto.vitalStats,
|
||||
dto.phenotype,
|
||||
dto.experienceInfo,
|
||||
dto.permanentStats,
|
||||
dto.variableStats,
|
||||
dto.reputation,
|
||||
dto.inventoryInfo,
|
||||
dto.targetId,
|
||||
dto.isStanding
|
||||
);
|
||||
}
|
||||
const bool IsEqual(const DTO::WorldObject* dto) const override
|
||||
{
|
||||
const DTO::Hero* castedDto = static_cast<const DTO::Hero*>(dto);
|
||||
return WorldObject::IsEqual(dto) &&
|
||||
m_FullName.IsEqual(&castedDto->fullName) &&
|
||||
m_VitalStats.IsEqual(&castedDto->vitalStats) &&
|
||||
m_Phenotype.IsEqual(&castedDto->phenotype) &&
|
||||
m_ExperienceInfo.IsEqual(&castedDto->experienceInfo) &&
|
||||
m_PermanentStats.IsEqual(&castedDto->permanentStats) &&
|
||||
m_VariableStats.IsEqual(&castedDto->variableStats) &&
|
||||
m_Reputation.IsEqual(&castedDto->reputation) &&
|
||||
m_InventoryInfo.IsEqual(&castedDto->inventoryInfo) &&
|
||||
m_TargetId == castedDto->targetId &&
|
||||
m_IsStanding == castedDto->isStanding;
|
||||
}
|
||||
|
||||
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({ "fullName", m_FullName.BuildSerializationNodes() });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_VitalStats.IsEqual(&m_PrevState.vitalStats))
|
||||
{
|
||||
result.push_back({ "vitalStats", m_VitalStats.BuildSerializationNodes() });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_Phenotype.IsEqual(&m_PrevState.phenotype))
|
||||
{
|
||||
result.push_back({ "phenotype", m_Phenotype.BuildSerializationNodes() });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_ExperienceInfo.IsEqual(&m_PrevState.experienceInfo))
|
||||
{
|
||||
result.push_back({ "experienceInfo", m_ExperienceInfo.BuildSerializationNodes() });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_PermanentStats.IsEqual(&m_PrevState.permanentStats))
|
||||
{
|
||||
result.push_back({ "permanentStats", m_PermanentStats.BuildSerializationNodes() });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_VariableStats.IsEqual(&m_PrevState.variableStats))
|
||||
{
|
||||
result.push_back({ "variableStats", m_VariableStats.BuildSerializationNodes() });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_Reputation.IsEqual(&m_PrevState.reputation))
|
||||
{
|
||||
result.push_back({ "reputation", m_Reputation.BuildSerializationNodes() });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_InventoryInfo.IsEqual(&m_PrevState.inventoryInfo))
|
||||
{
|
||||
result.push_back({ "inventoryInfo", m_InventoryInfo.BuildSerializationNodes() });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_TargetId != m_PrevState.targetId)
|
||||
{
|
||||
result.push_back({ "targetId", std::to_string(m_TargetId) });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_IsStanding != m_PrevState.isStanding)
|
||||
{
|
||||
result.push_back({ "isStanding", std::to_string(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 uint32_t targetId,
|
||||
const bool isStanding
|
||||
) :
|
||||
WorldObject(id, 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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Hero() = default;
|
||||
virtual ~Hero() = default;
|
||||
|
||||
private:
|
||||
struct State
|
||||
{
|
||||
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();
|
||||
ValueObjects::Phenotype m_Phenotype = ValueObjects::Phenotype();
|
||||
ValueObjects::ExperienceInfo m_ExperienceInfo = ValueObjects::ExperienceInfo();
|
||||
ValueObjects::PermanentStats m_PermanentStats = ValueObjects::PermanentStats();
|
||||
ValueObjects::VariableStats m_VariableStats = ValueObjects::VariableStats();
|
||||
ValueObjects::Reputation m_Reputation = ValueObjects::Reputation();
|
||||
ValueObjects::InventoryInfo m_InventoryInfo = ValueObjects::InventoryInfo();
|
||||
uint32_t m_TargetId = 0;
|
||||
bool m_IsStanding = true;
|
||||
State m_PrevState = State();
|
||||
};
|
||||
}
|
149
L2BotCore/Domain/Entities/NPC.h
Normal file
149
L2BotCore/Domain/Entities/NPC.h
Normal file
@@ -0,0 +1,149 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include "WorldObject.h"
|
||||
#include "../DTO/NPC.h"
|
||||
#include "../ValueObjects/FullName.h"
|
||||
#include "../ValueObjects/VitalStats.h"
|
||||
#include "../Serializers/Serializable.h"
|
||||
#include "../Enums/SpoilStateEnum.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
class NPC : public WorldObject
|
||||
{
|
||||
public:
|
||||
const bool IsHostile() const
|
||||
{
|
||||
return m_IsHostile;
|
||||
}
|
||||
const uint32_t GetNpcId() const
|
||||
{
|
||||
return m_NpcId;
|
||||
}
|
||||
const bool IsSpoiled() const
|
||||
{
|
||||
return m_SpoilState == Enums::SpoilStateEnum::spoiled;
|
||||
}
|
||||
const bool CanBeSweeped() const
|
||||
{
|
||||
return !m_VitalStats.IsAlive() && m_SpoilState == Enums::SpoilStateEnum::sweepable;
|
||||
}
|
||||
const ValueObjects::FullName& GetFullName() const
|
||||
{
|
||||
return m_FullName;
|
||||
}
|
||||
const ValueObjects::VitalStats& GetVitalStats() const
|
||||
{
|
||||
return m_VitalStats;
|
||||
}
|
||||
|
||||
void UpdateFromDTO(const DTO::WorldObject* dto) override
|
||||
{
|
||||
const DTO::NPC* castedDto = static_cast<const DTO::NPC*>(dto);
|
||||
WorldObject::UpdateFromDTO(dto);
|
||||
m_IsHostile = castedDto->isHostile;
|
||||
m_NpcId = castedDto->npcId;
|
||||
m_SpoilState = castedDto->spoilState;
|
||||
m_FullName = castedDto->fullName;
|
||||
m_VitalStats = castedDto->vitalStats;
|
||||
}
|
||||
void SaveState() override
|
||||
{
|
||||
WorldObject::SaveState();
|
||||
m_PrevState =
|
||||
{
|
||||
m_FullName,
|
||||
m_SpoilState,
|
||||
m_VitalStats,
|
||||
false
|
||||
};
|
||||
}
|
||||
const static NPC CreateFromDTO(const DTO::NPC& dto)
|
||||
{
|
||||
return NPC(
|
||||
dto.id,
|
||||
dto.transform,
|
||||
dto.isHostile,
|
||||
dto.npcId,
|
||||
dto.spoilState,
|
||||
dto.fullName,
|
||||
dto.vitalStats
|
||||
);
|
||||
}
|
||||
const bool IsEqual(const DTO::WorldObject* dto) const override
|
||||
{
|
||||
const DTO::NPC* castedDto = static_cast<const DTO::NPC*>(dto);
|
||||
return WorldObject::IsEqual(dto) &&
|
||||
m_IsHostile == castedDto->isHostile &&
|
||||
m_NpcId == castedDto->npcId &&
|
||||
m_SpoilState == castedDto->spoilState &&
|
||||
m_FullName.IsEqual(&castedDto->fullName) &&
|
||||
m_VitalStats.IsEqual(&castedDto->vitalStats);
|
||||
}
|
||||
|
||||
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({ "fullName", m_FullName.BuildSerializationNodes() });
|
||||
}
|
||||
if (m_PrevState.isNewState)
|
||||
{
|
||||
result.push_back({ "isHostile", std::to_string(m_IsHostile) });
|
||||
result.push_back({ "npcId", std::to_string(m_NpcId) });
|
||||
}
|
||||
if (m_PrevState.isNewState || m_SpoilState != m_PrevState.spoilState)
|
||||
{
|
||||
result.push_back({ "spoilState", std::to_string(static_cast<uint32_t>(m_SpoilState)) });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_VitalStats.IsEqual(&m_PrevState.vitalStats))
|
||||
{
|
||||
result.push_back({ "vitalStats", m_VitalStats.BuildSerializationNodes() });
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NPC(
|
||||
const uint32_t id,
|
||||
const ValueObjects::Transform transform,
|
||||
const bool isHostile,
|
||||
const uint32_t npcId,
|
||||
const Enums::SpoilStateEnum spoilState,
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NPC() = default;
|
||||
virtual ~NPC() = default;
|
||||
|
||||
private:
|
||||
struct State
|
||||
{
|
||||
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();
|
||||
State m_PrevState = State();
|
||||
};
|
||||
}
|
101
L2BotCore/Domain/Entities/Player.h
Normal file
101
L2BotCore/Domain/Entities/Player.h
Normal file
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
#include "WorldObject.h"
|
||||
#include "../DTO/Player.h"
|
||||
#include "../ValueObjects/FullName.h"
|
||||
#include "../ValueObjects/VitalStats.h"
|
||||
#include "../ValueObjects/Phenotype.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
class Player : public WorldObject
|
||||
{
|
||||
public:
|
||||
const ValueObjects::FullName& GetFullName() const
|
||||
{
|
||||
return m_FullName;
|
||||
}
|
||||
const ValueObjects::Phenotype& GetPhenotype() const
|
||||
{
|
||||
return m_Phenotype;
|
||||
}
|
||||
|
||||
void UpdateFromDTO(const DTO::WorldObject* dto) override
|
||||
{
|
||||
const DTO::Player* castedDto = static_cast<const DTO::Player*>(dto);
|
||||
WorldObject::UpdateFromDTO(dto);
|
||||
m_FullName = castedDto->fullName;
|
||||
m_Phenotype = castedDto->phenotype;
|
||||
}
|
||||
void SaveState() override
|
||||
{
|
||||
WorldObject::SaveState();
|
||||
m_PrevState =
|
||||
{
|
||||
m_FullName,
|
||||
m_Phenotype
|
||||
};
|
||||
}
|
||||
const static Player CreateFromDTO(const DTO::Player& dto)
|
||||
{
|
||||
return Player(
|
||||
dto.id,
|
||||
dto.transform,
|
||||
dto.fullName,
|
||||
dto.phenotype
|
||||
);
|
||||
}
|
||||
const bool IsEqual(const DTO::WorldObject* dto) const override
|
||||
{
|
||||
const DTO::Player* castedDto = static_cast<const DTO::Player*>(dto);
|
||||
return WorldObject::IsEqual(dto) &&
|
||||
m_FullName.IsEqual(&castedDto->fullName) &&
|
||||
m_Phenotype.IsEqual(&castedDto->phenotype);
|
||||
}
|
||||
|
||||
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({ "fullName", m_FullName.BuildSerializationNodes() });
|
||||
}
|
||||
if (m_PrevState.isNewState || !m_Phenotype.IsEqual(&m_PrevState.phenotype))
|
||||
{
|
||||
result.push_back({ "phenotype", m_Phenotype.BuildSerializationNodes() });
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Player(
|
||||
const uint32_t id,
|
||||
const ValueObjects::Transform transform,
|
||||
const ValueObjects::FullName fullName,
|
||||
const ValueObjects::Phenotype phenotype
|
||||
) :
|
||||
WorldObject(id, transform),
|
||||
m_FullName(fullName),
|
||||
m_Phenotype(phenotype)
|
||||
{
|
||||
SaveState();
|
||||
}
|
||||
|
||||
Player() = default;
|
||||
virtual ~Player() = default;
|
||||
|
||||
private:
|
||||
struct State
|
||||
{
|
||||
ValueObjects::FullName fullName = ValueObjects::FullName();
|
||||
ValueObjects::Phenotype phenotype = ValueObjects::Phenotype();
|
||||
|
||||
bool isNewState = true;
|
||||
};
|
||||
|
||||
private:
|
||||
ValueObjects::FullName m_FullName = ValueObjects::FullName();
|
||||
ValueObjects::Phenotype m_Phenotype = ValueObjects::Phenotype();
|
||||
State m_PrevState = State();
|
||||
};
|
||||
}
|
79
L2BotCore/Domain/Entities/WorldObject.h
Normal file
79
L2BotCore/Domain/Entities/WorldObject.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include "../ValueObjects/Transform.h"
|
||||
#include "../DTO/WorldObject.h"
|
||||
#include "../Serializers/Serializable.h"
|
||||
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
class WorldObject : public Serializers::Serializable
|
||||
{
|
||||
public:
|
||||
const uint32_t GetId() const
|
||||
{
|
||||
return m_Id;
|
||||
}
|
||||
const ValueObjects::Transform& GetTransform() const
|
||||
{
|
||||
return m_Transform;
|
||||
}
|
||||
virtual void UpdateFromDTO(const DTO::WorldObject* dto)
|
||||
{
|
||||
SaveState();
|
||||
|
||||
m_Id = dto->id;
|
||||
m_Transform = dto->transform;
|
||||
}
|
||||
virtual void SaveState()
|
||||
{
|
||||
m_PrevState = { m_Transform, false };
|
||||
}
|
||||
virtual const bool IsEqual(const DTO::WorldObject* dto) const
|
||||
{
|
||||
return m_Id == dto->id && m_Transform.IsEqual(&dto->transform);
|
||||
}
|
||||
const float_t GetSqrDistance(const WorldObject& other) const
|
||||
{
|
||||
return m_Transform.GetSqrDistance(other.m_Transform);
|
||||
}
|
||||
const float_t GetHorizontalSqrDistance(const WorldObject& other) const
|
||||
{
|
||||
return m_Transform.GetHorizontalSqrDistance(other.m_Transform);
|
||||
}
|
||||
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
std::vector<Serializers::Node> result;
|
||||
|
||||
result.push_back({ "id", std::to_string(GetId()) });
|
||||
if (m_PrevState.isNewState || !GetTransform().IsEqual(&m_PrevState.transform))
|
||||
{
|
||||
result.push_back({ "transform", GetTransform().BuildSerializationNodes() });
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
WorldObject(const uint32_t id, const ValueObjects::Transform transform) :
|
||||
m_Id(id), m_Transform(transform)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
WorldObject() = default;
|
||||
virtual ~WorldObject() = default;
|
||||
private:
|
||||
private:
|
||||
struct State
|
||||
{
|
||||
ValueObjects::Transform transform = ValueObjects::Transform();
|
||||
|
||||
bool isNewState = true;
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t m_Id = 0;
|
||||
ValueObjects::Transform m_Transform = ValueObjects::Transform();
|
||||
State m_PrevState = State();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user