feat: change dtos to entities

This commit is contained in:
k0t9i
2023-01-21 13:15:11 +04:00
parent 3c20df7683
commit 7637260d19
58 changed files with 704 additions and 1310 deletions

View File

@@ -2,55 +2,34 @@
#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
void Update(const EntityInterface* other) override
{
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;
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 SaveState() override
{
WorldObject::SaveState();
m_IsNewState = false;
}
const static Drop CreateFromDTO(const DTO::Drop& dto)
const bool IsEqual(const EntityInterface* other) const override
{
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 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;
}
const std::vector<Serializers::Node> BuildSerializationNodes() const override

View File

@@ -0,0 +1,19 @@
#pragma once
#include <cstdint>
#include "../Serializers/Serializable.h"
namespace L2Bot::Domain::Entities
{
class EntityInterface : public Serializers::Serializable
{
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;
EntityInterface() = default;
virtual ~EntityInterface() = default;
};
}

View File

@@ -1,6 +1,5 @@
#pragma once
#include "WorldObject.h"
#include "../DTO/Hero.h"
#include "../ValueObjects/FullName.h"
#include "../ValueObjects/VitalStats.h"
#include "../ValueObjects/Phenotype.h"
@@ -16,60 +15,20 @@ namespace L2Bot::Domain::Entities
class Hero : public WorldObject
{
public:
const ValueObjects::FullName& GetFullName() const
void Update(const EntityInterface* other) override
{
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;
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 SaveState() override
{
@@ -89,37 +48,20 @@ namespace L2Bot::Domain::Entities
false
};
}
const static Hero CreateFromDTO(const DTO::Hero& dto)
const bool IsEqual(const EntityInterface* other) const override
{
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 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;
}
const std::vector<Serializers::Node> BuildSerializationNodes() const override
@@ -203,7 +145,7 @@ namespace L2Bot::Domain::Entities
virtual ~Hero() = default;
private:
struct State
struct GetState
{
ValueObjects::FullName fullName = ValueObjects::FullName();
ValueObjects::VitalStats vitalStats = ValueObjects::VitalStats();
@@ -230,6 +172,6 @@ namespace L2Bot::Domain::Entities
ValueObjects::InventoryInfo m_InventoryInfo = ValueObjects::InventoryInfo();
uint32_t m_TargetId = 0;
bool m_IsStanding = true;
State m_PrevState = State();
GetState m_PrevState = GetState();
};
}

View File

@@ -1,7 +1,6 @@
#pragma once
#include <cstdint>
#include "WorldObject.h"
#include "../DTO/NPC.h"
#include "../ValueObjects/FullName.h"
#include "../ValueObjects/VitalStats.h"
#include "../Serializers/Serializable.h"
@@ -12,40 +11,15 @@ namespace L2Bot::Domain::Entities
class NPC : public WorldObject
{
public:
const bool IsHostile() const
void Update(const EntityInterface* other) override
{
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;
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;
}
void SaveState() override
{
@@ -58,27 +32,15 @@ namespace L2Bot::Domain::Entities
false
};
}
const static NPC CreateFromDTO(const DTO::NPC& dto)
const bool IsEqual(const EntityInterface* other) const override
{
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 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);
}
const std::vector<Serializers::Node> BuildSerializationNodes() const override
@@ -129,7 +91,7 @@ namespace L2Bot::Domain::Entities
virtual ~NPC() = default;
private:
struct State
struct GetState
{
ValueObjects::FullName fullName = ValueObjects::FullName();
Enums::SpoilStateEnum spoilState = Enums::SpoilStateEnum::none;
@@ -144,6 +106,6 @@ namespace L2Bot::Domain::Entities
Enums::SpoilStateEnum m_SpoilState = Enums::SpoilStateEnum::none;
ValueObjects::FullName m_FullName = ValueObjects::FullName();
ValueObjects::VitalStats m_VitalStats = ValueObjects::VitalStats();
State m_PrevState = State();
GetState m_PrevState = GetState();
};
}

View File

@@ -1,6 +1,5 @@
#pragma once
#include "WorldObject.h"
#include "../DTO/Player.h"
#include "../ValueObjects/FullName.h"
#include "../ValueObjects/VitalStats.h"
#include "../ValueObjects/Phenotype.h"
@@ -10,21 +9,12 @@ namespace L2Bot::Domain::Entities
class Player : public WorldObject
{
public:
const ValueObjects::FullName& GetFullName() const
void Update(const EntityInterface* other) override
{
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;
const Player* casted = static_cast<const Player*>(other);
WorldObject::Update(other);
m_FullName = casted->m_FullName;
m_Phenotype = casted->m_Phenotype;
}
void SaveState() override
{
@@ -35,21 +25,12 @@ namespace L2Bot::Domain::Entities
m_Phenotype
};
}
const static Player CreateFromDTO(const DTO::Player& dto)
const bool IsEqual(const EntityInterface* other) const override
{
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 Player* casted = static_cast<const Player*>(other);
return WorldObject::IsEqual(other) &&
m_FullName.IsEqual(&casted->m_FullName) &&
m_Phenotype.IsEqual(&casted->m_Phenotype);
}
const std::vector<Serializers::Node> BuildSerializationNodes() const override
@@ -85,7 +66,7 @@ namespace L2Bot::Domain::Entities
virtual ~Player() = default;
private:
struct State
struct GetState
{
ValueObjects::FullName fullName = ValueObjects::FullName();
ValueObjects::Phenotype phenotype = ValueObjects::Phenotype();
@@ -96,6 +77,6 @@ namespace L2Bot::Domain::Entities
private:
ValueObjects::FullName m_FullName = ValueObjects::FullName();
ValueObjects::Phenotype m_Phenotype = ValueObjects::Phenotype();
State m_PrevState = State();
GetState m_PrevState = GetState();
};
}

View File

@@ -0,0 +1,209 @@
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include "WorldObject.h"
namespace L2Bot::Domain::Entities
{
class Skill : public EntityInterface
{
public:
const uint32_t GetId() const override
{
return m_SkillId;
}
const bool IsReadyToUse() const
{
return !m_IsCasting && !m_IsReloading;
}
const bool IsToggled() const
{
return m_IsToggled;
}
void UpdateReloadingState(const bool isReloading)
{
m_IsReloading = isReloading;
}
void UpdateCastingState(const bool isCasting)
{
m_IsCasting = isCasting;
}
void UpdateToggle(const bool isToggled)
{
m_IsToggled = isToggled;
}
void UpdateLevel(const uint8_t level)
{
m_Level = level;
}
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;
}
void SaveState() override
{
m_PrevState =
{
m_Cost,
m_Range,
m_Description,
m_IsToggled,
m_IsCasting,
m_IsReloading,
IsReadyToUse(),
false
};
}
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;
}
const std::vector<Serializers::Node> BuildSerializationNodes() const override
{
std::vector<Serializers::Node> result;
result.push_back({ "skillId", std::to_string(m_SkillId) });
result.push_back({ "level", std::to_string(m_Level) });
if (m_PrevState.isNewState)
{
result.push_back({ "isActive", std::to_string(m_IsActive) });
result.push_back({ "name", m_Name });
result.push_back({ "iconName", m_IconName });
}
if (m_PrevState.isNewState || m_Description != m_PrevState.description)
{
result.push_back({ "description", m_Description });
}
if (m_PrevState.isNewState || m_Cost != m_PrevState.cost)
{
result.push_back({ "cost", std::to_string(m_Cost) });
}
if (m_PrevState.isNewState || m_Range != m_PrevState.range)
{
result.push_back({ "range", std::to_string(m_Range) });
}
if (m_PrevState.isNewState || m_IsToggled != m_PrevState.isToggled)
{
result.push_back({ "isToggled", std::to_string(m_IsToggled) });
}
if (m_PrevState.isNewState || m_IsCasting != m_PrevState.isCasting)
{
result.push_back({ "isCasting", std::to_string(m_IsCasting) });
}
if (m_PrevState.isNewState || m_IsReloading != m_PrevState.isReloading)
{
result.push_back({ "isReloading", std::to_string(m_IsReloading) });
}
if (m_PrevState.isNewState || IsReadyToUse() != m_PrevState.isReadyToUse)
{
result.push_back({ "isReadyToUse", std::to_string(IsReadyToUse()) });
}
return result;
}
Skill(
const uint32_t skillId,
const uint8_t level,
const bool isActive,
const uint8_t cost,
const int16_t range,
const std::string& name,
const std::string& description,
const std::string& iconName,
const bool isToggled,
const bool isCasting,
const bool isReloading
) :
m_SkillId(skillId),
m_Level(level),
m_IsActive(isActive),
m_Cost(cost),
m_Range(range),
m_Name(name),
m_Description(description),
m_IconName(iconName),
m_IsToggled(isToggled),
m_IsCasting(isCasting),
m_IsReloading(isReloading)
{
}
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:
struct GetState
{
uint8_t cost = 0;
int16_t range = 0;
std::string description = "";
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;
bool m_IsActive = false;
uint8_t m_Cost = 0;
int16_t m_Range = 0;
std::string m_Name = "";
std::string m_Description = "";
std::string m_IconName = "";
bool m_IsToggled = false;
bool m_IsCasting = false;
bool m_IsReloading = false;
GetState m_PrevState = GetState();
};
}

View File

@@ -1,54 +1,43 @@
#pragma once
#include <cstdint>
#include "../ValueObjects/Transform.h"
#include "../DTO/WorldObject.h"
#include "../Serializers/Serializable.h"
#include "EntityInterface.h"
namespace L2Bot::Domain::Entities
{
class WorldObject : public Serializers::Serializable
class WorldObject : public EntityInterface
{
public:
const uint32_t GetId() const
virtual const uint32_t GetId() const override
{
return m_Id;
}
const ValueObjects::Transform& GetTransform() const
{
return m_Transform;
}
virtual void UpdateFromDTO(const DTO::WorldObject* dto)
virtual void Update(const EntityInterface* other) override
{
SaveState();
m_Id = dto->id;
m_Transform = dto->transform;
const WorldObject* casted = static_cast<const WorldObject*>(other);
m_Id = casted->m_Id;
m_Transform = casted->m_Transform;
}
virtual void SaveState()
virtual void SaveState() override
{
m_PrevState = { m_Transform, false };
}
virtual const bool IsEqual(const DTO::WorldObject* dto) const
virtual const bool IsEqual(const EntityInterface* other) const override
{
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 WorldObject* casted = static_cast<const WorldObject*>(other);
return m_Id == casted->m_Id && m_Transform.IsEqual(&casted->m_Transform);
}
const std::vector<Serializers::Node> BuildSerializationNodes() const override
virtual 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))
if (m_PrevState.isNewState || !m_Transform.IsEqual(&m_PrevState.transform))
{
result.push_back({ "transform", GetTransform().BuildSerializationNodes() });
result.push_back({ "transform", m_Transform.BuildSerializationNodes() });
}
return result;
@@ -64,7 +53,7 @@ namespace L2Bot::Domain::Entities
virtual ~WorldObject() = default;
private:
private:
struct State
struct GetState
{
ValueObjects::Transform transform = ValueObjects::Transform();
@@ -74,6 +63,6 @@ namespace L2Bot::Domain::Entities
private:
uint32_t m_Id = 0;
ValueObjects::Transform m_Transform = ValueObjects::Transform();
State m_PrevState = State();
GetState m_PrevState = GetState();
};
}