feat: change dtos to entities
This commit is contained in:
@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include "WorldObject.h"
|
||||
|
||||
namespace L2Bot::Domain::DTO
|
||||
{
|
||||
struct BaseItem
|
||||
{
|
||||
public:
|
||||
const uint32_t itemId = 0;
|
||||
const uint32_t amount = 0;
|
||||
const bool isEquipped = 0;
|
||||
const uint16_t enchantLevel = 0;
|
||||
const int32_t mana = -1;
|
||||
const std::string name = "";
|
||||
const std::string iconName = "";
|
||||
const std::string description = "";
|
||||
const uint16_t weight = 0;
|
||||
};
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include "WorldObject.h"
|
||||
|
||||
namespace L2Bot::Domain::DTO
|
||||
{
|
||||
struct Drop : public WorldObject
|
||||
{
|
||||
public:
|
||||
const uint32_t itemId = 0;
|
||||
const uint32_t amount = 0;
|
||||
const std::string name = "";
|
||||
const std::string iconName = "";
|
||||
};
|
||||
}
|
43
L2BotCore/Domain/DTO/EntityState.h
Normal file
43
L2BotCore/Domain/DTO/EntityState.h
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Entities/EntityInterface.h"
|
||||
#include "../Enums/EntityStateEnum.h"
|
||||
|
||||
namespace L2Bot::Domain::DTO
|
||||
{
|
||||
class EntityState
|
||||
{
|
||||
public:
|
||||
Entities::EntityInterface* GetEntity() const
|
||||
{
|
||||
return m_Entity;
|
||||
}
|
||||
const Enums::EntityStateEnum GetState() const
|
||||
{
|
||||
return m_State;
|
||||
}
|
||||
void UpdateState(const Enums::EntityStateEnum state)
|
||||
{
|
||||
m_State = state;
|
||||
}
|
||||
|
||||
EntityState(Entities::EntityInterface* object, Enums::EntityStateEnum state) :
|
||||
m_Entity(object),
|
||||
m_State(state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
EntityState() = default;
|
||||
virtual ~EntityState()
|
||||
{
|
||||
if (m_Entity != nullptr)
|
||||
{
|
||||
delete m_Entity;
|
||||
}
|
||||
}
|
||||
private:
|
||||
Entities::EntityInterface* m_Entity = nullptr;
|
||||
Enums::EntityStateEnum m_State = Enums::EntityStateEnum::none;
|
||||
};
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
#pragma once
|
||||
#include "WorldObject.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::DTO
|
||||
{
|
||||
struct Hero : public WorldObject
|
||||
{
|
||||
public:
|
||||
const ValueObjects::FullName fullName = ValueObjects::FullName();
|
||||
const ValueObjects::VitalStats vitalStats = ValueObjects::VitalStats();
|
||||
const ValueObjects::Phenotype phenotype = ValueObjects::Phenotype();
|
||||
const ValueObjects::ExperienceInfo experienceInfo = ValueObjects::ExperienceInfo();
|
||||
const ValueObjects::PermanentStats permanentStats = ValueObjects::PermanentStats();
|
||||
const ValueObjects::VariableStats variableStats = ValueObjects::VariableStats();
|
||||
const ValueObjects::Reputation reputation = ValueObjects::Reputation();
|
||||
const ValueObjects::InventoryInfo inventoryInfo = ValueObjects::InventoryInfo();
|
||||
const uint32_t targetId = 0;
|
||||
const bool isStanding = true;
|
||||
};
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include "WorldObject.h"
|
||||
#include "../ValueObjects/FullName.h"
|
||||
#include "../ValueObjects/VitalStats.h"
|
||||
#include "../Enums/SpoilStateEnum.h"
|
||||
|
||||
namespace L2Bot::Domain::DTO
|
||||
{
|
||||
struct NPC : public WorldObject
|
||||
{
|
||||
public:
|
||||
const bool isHostile = false;
|
||||
const uint32_t npcId = 0;
|
||||
const Enums::SpoilStateEnum spoilState = Enums::SpoilStateEnum::none;
|
||||
const ValueObjects::FullName fullName = ValueObjects::FullName();
|
||||
const ValueObjects::VitalStats vitalStats = ValueObjects::VitalStats();
|
||||
};
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
#include "../Enums/ObjectStateEnum.h"
|
||||
|
||||
namespace L2Bot::Domain::DTO
|
||||
{
|
||||
template <typename T>
|
||||
struct ObjectState
|
||||
{
|
||||
public:
|
||||
T object;
|
||||
Enums::ObjectStateEnum state = Enums::ObjectStateEnum::none;
|
||||
};
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include "WorldObject.h"
|
||||
#include "../ValueObjects/FullName.h"
|
||||
#include "../ValueObjects/VitalStats.h"
|
||||
#include "../ValueObjects/Phenotype.h"
|
||||
namespace L2Bot::Domain::DTO
|
||||
{
|
||||
struct Player : public WorldObject
|
||||
{
|
||||
public:
|
||||
const ValueObjects::FullName fullName = ValueObjects::FullName();
|
||||
const ValueObjects::Phenotype phenotype = ValueObjects::Phenotype();
|
||||
};
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace L2Bot::Domain::DTO
|
||||
{
|
||||
struct Skill
|
||||
{
|
||||
public:
|
||||
const uint32_t skillId = 0;
|
||||
const uint8_t level = 0;
|
||||
const bool isActive = false;
|
||||
const uint8_t cost = 0;
|
||||
const int16_t range = 0;
|
||||
const std::string name = "";
|
||||
const std::string description = "";
|
||||
const std::string iconName = "";
|
||||
const bool isToggled = false;
|
||||
const bool isCasting = false;
|
||||
const bool isReloading = false;
|
||||
};
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include "../ValueObjects/Transform.h"
|
||||
|
||||
namespace L2Bot::Domain::DTO
|
||||
{
|
||||
struct WorldObject
|
||||
{
|
||||
public:
|
||||
const uint32_t id = 0;
|
||||
const ValueObjects::Transform transform = ValueObjects::Transform();
|
||||
};
|
||||
}
|
@ -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
|
||||
|
19
L2BotCore/Domain/Entities/EntityInterface.h
Normal file
19
L2BotCore/Domain/Entities/EntityInterface.h
Normal 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;
|
||||
};
|
||||
}
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
@ -2,16 +2,14 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../DTO/Skill.h"
|
||||
#include "../Serializers/Serializable.h"
|
||||
#include "../Serializers/Node.h"
|
||||
#include "WorldObject.h"
|
||||
|
||||
namespace L2Bot::Domain::ValueObjects
|
||||
namespace L2Bot::Domain::Entities
|
||||
{
|
||||
class Skill : public Serializers::Serializable
|
||||
class Skill : public EntityInterface
|
||||
{
|
||||
public:
|
||||
const uint32_t GetId() const
|
||||
const uint32_t GetId() const override
|
||||
{
|
||||
return m_SkillId;
|
||||
}
|
||||
@ -19,23 +17,46 @@ namespace L2Bot::Domain::ValueObjects
|
||||
{
|
||||
return !m_IsCasting && !m_IsReloading;
|
||||
}
|
||||
void UpdateFromDTO(const DTO::Skill* dto)
|
||||
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 = dto->skillId;
|
||||
m_Level = dto->level;
|
||||
m_IsActive = dto->isActive;
|
||||
m_Cost = dto->cost;
|
||||
m_Range = dto->range;
|
||||
m_Name = dto->name;
|
||||
m_Description = dto->description;
|
||||
m_IconName = dto->iconName;
|
||||
m_IsToggled = dto->isToggled;
|
||||
m_IsCasting = dto->isCasting;
|
||||
m_IsReloading = dto->isReloading;
|
||||
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()
|
||||
void SaveState() override
|
||||
{
|
||||
m_PrevState =
|
||||
{
|
||||
@ -49,35 +70,20 @@ namespace L2Bot::Domain::ValueObjects
|
||||
false
|
||||
};
|
||||
}
|
||||
const static Skill CreateFromDTO(const DTO::Skill& dto)
|
||||
const bool IsEqual(const EntityInterface* other) const override
|
||||
{
|
||||
return Skill(
|
||||
dto.skillId,
|
||||
dto.level,
|
||||
dto.isActive,
|
||||
dto.cost,
|
||||
dto.range,
|
||||
dto.name,
|
||||
dto.description,
|
||||
dto.iconName,
|
||||
dto.isToggled,
|
||||
dto.isCasting,
|
||||
dto.isReloading
|
||||
);
|
||||
}
|
||||
const bool IsEqual(const DTO::Skill* dto) const
|
||||
{
|
||||
return m_SkillId == dto->skillId &&
|
||||
m_Level == dto->level &&
|
||||
m_IsActive == dto->isActive &&
|
||||
m_Cost == dto->cost &&
|
||||
m_Range == dto->range &&
|
||||
m_Name == dto->name &&
|
||||
m_Description == dto->description &&
|
||||
m_IconName == dto->iconName &&
|
||||
m_IsToggled == dto->isToggled &&
|
||||
m_IsCasting == dto->isCasting &&
|
||||
m_IsReloading == dto->isReloading;
|
||||
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
|
||||
@ -154,11 +160,26 @@ namespace L2Bot::Domain::ValueObjects
|
||||
|
||||
}
|
||||
|
||||
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 State
|
||||
struct GetState
|
||||
{
|
||||
uint8_t cost = 0;
|
||||
int16_t range = 0;
|
||||
@ -183,6 +204,6 @@ namespace L2Bot::Domain::ValueObjects
|
||||
bool m_IsToggled = false;
|
||||
bool m_IsCasting = false;
|
||||
bool m_IsReloading = false;
|
||||
State m_PrevState = State();
|
||||
GetState m_PrevState = GetState();
|
||||
};
|
||||
}
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace L2Bot::Domain::Enums
|
||||
{
|
||||
enum class ObjectStateEnum
|
||||
enum class EntityStateEnum
|
||||
{
|
||||
none,
|
||||
created,
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "ObjectRepositoryInterface.h"
|
||||
#include "../DTO/Drop.h"
|
||||
|
||||
namespace L2Bot::Domain::Repositories
|
||||
{
|
||||
class DropRepositoryInterface : public ObjectRepositoryInterface<DTO::Drop>
|
||||
{
|
||||
public:
|
||||
virtual const std::map<uint32_t, DTO::Drop> GetObjects() override = 0;
|
||||
};
|
||||
}
|
14
L2BotCore/Domain/Repositories/EntityRepositoryInterface.h
Normal file
14
L2BotCore/Domain/Repositories/EntityRepositoryInterface.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "../Entities/WorldObject.h"
|
||||
#include "../DTO/EntityState.h"
|
||||
|
||||
namespace L2Bot::Domain::Repositories
|
||||
{
|
||||
class EntityRepositoryInterface
|
||||
{
|
||||
public:
|
||||
virtual const std::vector<DTO::EntityState*> GetEntities() = 0;
|
||||
virtual void Reset() = 0;
|
||||
};
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "ObjectRepositoryInterface.h"
|
||||
#include "../DTO/Hero.h"
|
||||
|
||||
namespace L2Bot::Domain::Repositories
|
||||
{
|
||||
class HeroRepositoryInterface : public ObjectRepositoryInterface<DTO::Hero>
|
||||
{
|
||||
public:
|
||||
virtual const std::map<uint32_t, DTO::Hero> GetObjects() override = 0;
|
||||
};
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "ObjectRepositoryInterface.h"
|
||||
#include "../DTO/BaseItem.h"
|
||||
|
||||
namespace L2Bot::Domain::Repositories
|
||||
{
|
||||
class ItemRepositoryInterface : public ObjectRepositoryInterface<DTO::BaseItem>
|
||||
{
|
||||
public:
|
||||
virtual const std::map<uint32_t, DTO::BaseItem> GetObjects() override = 0;
|
||||
};
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "ObjectRepositoryInterface.h"
|
||||
#include "../DTO/NPC.h"
|
||||
|
||||
namespace L2Bot::Domain::Repositories
|
||||
{
|
||||
class NPCRepositoryInterface : public ObjectRepositoryInterface<DTO::NPC>
|
||||
{
|
||||
public:
|
||||
virtual const std::map<uint32_t, DTO::NPC> GetObjects() override = 0;
|
||||
};
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
|
||||
namespace L2Bot::Domain::Repositories
|
||||
{
|
||||
template <typename T>
|
||||
class ObjectRepositoryInterface
|
||||
{
|
||||
public:
|
||||
virtual const std::map<uint32_t, T> GetObjects() = 0;
|
||||
};
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "ObjectRepositoryInterface.h"
|
||||
#include "../DTO/Player.h"
|
||||
|
||||
namespace L2Bot::Domain::Repositories
|
||||
{
|
||||
class PlayerRepositoryInterface : public ObjectRepositoryInterface<DTO::Player>
|
||||
{
|
||||
public:
|
||||
virtual const std::map<uint32_t, DTO::Player> GetObjects() override = 0;
|
||||
};
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "ObjectRepositoryInterface.h"
|
||||
#include "../DTO/Skill.h"
|
||||
|
||||
namespace L2Bot::Domain::Repositories
|
||||
{
|
||||
class SkillRepositoryInterface : public ObjectRepositoryInterface<DTO::Skill>
|
||||
{
|
||||
public:
|
||||
virtual const std::map<uint32_t, DTO::Skill> GetObjects() override = 0;
|
||||
};
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "../DTO/ObjectState.h"
|
||||
#include "../DTO/EntityState.h"
|
||||
#include "Serializable.h"
|
||||
|
||||
namespace L2Bot::Domain::Serializers
|
||||
{
|
||||
template <typename T>
|
||||
class SerializableStateContainer : public Serializers::Serializable
|
||||
{
|
||||
public:
|
||||
@ -16,15 +15,15 @@ namespace L2Bot::Domain::Serializers
|
||||
for (const auto& kvp : m_Objects)
|
||||
{
|
||||
std::string operationName = "";
|
||||
switch (kvp.state)
|
||||
switch (kvp->GetState())
|
||||
{
|
||||
case Enums::ObjectStateEnum::created:
|
||||
case Enums::EntityStateEnum::created:
|
||||
operationName = "created";
|
||||
break;
|
||||
case Enums::ObjectStateEnum::updated:
|
||||
case Enums::EntityStateEnum::updated:
|
||||
operationName = "updated";
|
||||
break;
|
||||
case Enums::ObjectStateEnum::deleted:
|
||||
case Enums::EntityStateEnum::deleted:
|
||||
operationName = "deleted";
|
||||
break;
|
||||
}
|
||||
@ -34,7 +33,7 @@ namespace L2Bot::Domain::Serializers
|
||||
result.push_back(
|
||||
{
|
||||
m_ContainerName,
|
||||
std::vector<Serializers::Node>{ { operationName, kvp.object.BuildSerializationNodes() } }
|
||||
std::vector<Serializers::Node>{ { operationName, kvp->GetEntity()->BuildSerializationNodes() } }
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -43,7 +42,7 @@ namespace L2Bot::Domain::Serializers
|
||||
return result;
|
||||
}
|
||||
|
||||
SerializableStateContainer(const std::vector<DTO::ObjectState<T>> objects, const std::string containerName) :
|
||||
SerializableStateContainer(const std::vector<DTO::EntityState*> objects, const std::string containerName) :
|
||||
m_Objects(objects), m_ContainerName(containerName)
|
||||
{
|
||||
|
||||
@ -51,7 +50,7 @@ namespace L2Bot::Domain::Serializers
|
||||
SerializableStateContainer() = delete;
|
||||
virtual ~SerializableStateContainer() = default;
|
||||
private:
|
||||
const std::vector<DTO::ObjectState<T>> m_Objects;
|
||||
const std::vector<DTO::EntityState*> m_Objects;
|
||||
const std::string m_ContainerName;
|
||||
};
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "../DTO/ObjectState.h"
|
||||
#include "Serializable.h"
|
||||
|
||||
namespace L2Bot::Domain::Serializers
|
||||
{
|
||||
template <typename T>
|
||||
class SerializableStateContainerPtr : public Serializers::Serializable
|
||||
{
|
||||
public:
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
std::vector<Serializers::Node> result;
|
||||
|
||||
for (const auto& kvp : m_Objects)
|
||||
{
|
||||
std::string operationName = "";
|
||||
switch (kvp.state)
|
||||
{
|
||||
case Enums::ObjectStateEnum::created:
|
||||
operationName = "created";
|
||||
break;
|
||||
case Enums::ObjectStateEnum::updated:
|
||||
operationName = "updated";
|
||||
break;
|
||||
case Enums::ObjectStateEnum::deleted:
|
||||
operationName = "deleted";
|
||||
break;
|
||||
}
|
||||
|
||||
if (operationName != "")
|
||||
{
|
||||
result.push_back(
|
||||
{
|
||||
m_ContainerName,
|
||||
std::vector<Serializers::Node>{ { operationName, kvp.object->BuildSerializationNodes() } }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
SerializableStateContainerPtr(const std::vector<DTO::ObjectState<T>> objects, const std::string containerName) :
|
||||
m_Objects(objects), m_ContainerName(containerName)
|
||||
{
|
||||
|
||||
}
|
||||
SerializableStateContainerPtr() = delete;
|
||||
virtual ~SerializableStateContainerPtr() = default;
|
||||
private:
|
||||
const std::vector<DTO::ObjectState<T>> m_Objects;
|
||||
const std::string m_ContainerName;
|
||||
};
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "ObjectService.h"
|
||||
#include "../DTO/Drop.h"
|
||||
#include "../Entities/Drop.h"
|
||||
#include "../Repositories/DropRepositoryInterface.h"
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
class DropService : public ObjectService<Entities::Drop, DTO::Drop>
|
||||
{
|
||||
public:
|
||||
DropService(Repositories::DropRepositoryInterface& repository) : ObjectService(repository)
|
||||
{
|
||||
|
||||
}
|
||||
virtual ~DropService() override = default;
|
||||
};
|
||||
}
|
34
L2BotCore/Domain/Services/EntityService.h
Normal file
34
L2BotCore/Domain/Services/EntityService.h
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <math.h>
|
||||
#include "../DTO/EntityState.h"
|
||||
#include "../Entities/WorldObject.h"
|
||||
#include "../Repositories/EntityRepositoryInterface.h"
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
class EntityService
|
||||
{
|
||||
public:
|
||||
EntityService(Repositories::EntityRepositoryInterface& repository) : m_Repository(repository)
|
||||
{
|
||||
|
||||
}
|
||||
EntityService() = delete;
|
||||
virtual ~EntityService() = default;
|
||||
|
||||
virtual const std::vector<DTO::EntityState*> GetEntities()
|
||||
{
|
||||
return m_Repository.GetEntities();
|
||||
}
|
||||
|
||||
void Invalidate()
|
||||
{
|
||||
m_Repository.Reset();
|
||||
}
|
||||
private:
|
||||
Repositories::EntityRepositoryInterface& m_Repository;
|
||||
};
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "ObjectService.h"
|
||||
#include "../DTO/Hero.h"
|
||||
#include "../Entities/Hero.h"
|
||||
#include "../Repositories/HeroRepositoryInterface.h"
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
class HeroService : public ObjectService<Entities::Hero, DTO::Hero>
|
||||
{
|
||||
public:
|
||||
const DTO::ObjectState<Entities::Hero> GetHero()
|
||||
{
|
||||
const auto map = GetObjects();
|
||||
if (map.size() == 0)
|
||||
{
|
||||
return DTO::ObjectState <Entities::Hero>{};
|
||||
}
|
||||
|
||||
return map[0];
|
||||
}
|
||||
|
||||
HeroService(Repositories::HeroRepositoryInterface& repository) : ObjectService(repository)
|
||||
{
|
||||
|
||||
}
|
||||
virtual ~HeroService() override = default;
|
||||
};
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "ObjectService.h"
|
||||
#include "../DTO/BaseItem.h"
|
||||
#include "../ValueObjects/BaseItem.h"
|
||||
#include "../Repositories/ItemRepositoryInterface.h"
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
class ItemService : public ObjectService<ValueObjects::BaseItem, DTO::BaseItem>
|
||||
{
|
||||
public:
|
||||
ItemService(Repositories::ItemRepositoryInterface& repository) : ObjectService(repository)
|
||||
{
|
||||
|
||||
}
|
||||
virtual ~ItemService() override = default;
|
||||
};
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "ObjectService.h"
|
||||
#include "../DTO/NPC.h"
|
||||
#include "../Entities/NPC.h"
|
||||
#include "../Repositories/NPCRepositoryInterface.h"
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
class NPCService : public ObjectService<Entities::NPC, DTO::NPC>
|
||||
{
|
||||
public:
|
||||
NPCService(Repositories::NPCRepositoryInterface& repository) : ObjectService(repository)
|
||||
{
|
||||
|
||||
}
|
||||
virtual ~NPCService() override = default;
|
||||
};
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <math.h>
|
||||
#include "../DTO/ObjectState.h"
|
||||
#include "../Entities/Hero.h"
|
||||
#include "../Repositories/ObjectRepositoryInterface.h"
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
template <typename T, typename U>
|
||||
class ObjectService
|
||||
{
|
||||
public:
|
||||
ObjectService(Repositories::ObjectRepositoryInterface<U>& repository) : m_Repository(repository)
|
||||
{
|
||||
|
||||
}
|
||||
ObjectService() = delete;
|
||||
virtual ~ObjectService() = default;
|
||||
|
||||
virtual const std::vector<DTO::ObjectState<T>> GetObjects()
|
||||
{
|
||||
UpdateObjectsFromRepository();
|
||||
|
||||
std::vector<DTO::ObjectState<T>> objects;
|
||||
|
||||
for (const auto& kvp : m_ObjectStates) {
|
||||
objects.push_back(kvp.second);
|
||||
}
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
||||
void Invalidate()
|
||||
{
|
||||
m_ObjectStates.clear();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void UpdateObjectsFromRepository()
|
||||
{
|
||||
auto objects = m_Repository.GetObjects();
|
||||
|
||||
RemoveOutdatedStates();
|
||||
|
||||
|
||||
for (const auto& kvp : objects)
|
||||
{
|
||||
const auto& dto = kvp.second;
|
||||
if (m_ObjectStates.contains(kvp.first))
|
||||
{
|
||||
if (!m_ObjectStates[kvp.first].object.IsEqual(&dto)) {
|
||||
m_ObjectStates[kvp.first].object.UpdateFromDTO(&dto);
|
||||
m_ObjectStates[kvp.first].state = Enums::ObjectStateEnum::updated;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ObjectStates[kvp.first].state = Enums::ObjectStateEnum::none;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ObjectStates.emplace(kvp.first, DTO::ObjectState<T>{ T::CreateFromDTO(dto), Enums::ObjectStateEnum::created });
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& kvp : m_ObjectStates)
|
||||
{
|
||||
if (!objects.contains(kvp.second.object.GetId()))
|
||||
{
|
||||
m_ObjectStates[kvp.first].object.SaveState();
|
||||
kvp.second.state = Enums::ObjectStateEnum::deleted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void RemoveOutdatedStates()
|
||||
{
|
||||
auto it = m_ObjectStates.begin();
|
||||
while (it != m_ObjectStates.end())
|
||||
{
|
||||
if (it->second.state == Enums::ObjectStateEnum::deleted)
|
||||
{
|
||||
m_ObjectStates.erase(it++);
|
||||
}
|
||||
else
|
||||
{
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Repositories::ObjectRepositoryInterface<U>& m_Repository;
|
||||
std::map<uint32_t, DTO::ObjectState<T>> m_ObjectStates;
|
||||
};
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <math.h>
|
||||
#include "../DTO/ObjectState.h"
|
||||
#include "../Entities/Hero.h"
|
||||
#include "../Repositories/ObjectRepositoryInterface.h"
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
template <typename T, typename U>
|
||||
class ObjectServicePtr
|
||||
{
|
||||
public:
|
||||
ObjectServicePtr(Repositories::ObjectRepositoryInterface<U>& repository) : m_Repository(repository)
|
||||
{
|
||||
|
||||
}ObjectServicePtr() = delete;
|
||||
virtual ~ObjectServicePtr() = default;
|
||||
|
||||
virtual const std::vector<DTO::ObjectState<T>> GetObjects()
|
||||
{
|
||||
UpdateObjectsFromRepository();
|
||||
|
||||
std::vector<DTO::ObjectState<T>> objects;
|
||||
|
||||
for (const auto& kvp : m_ObjectStates) {
|
||||
objects.push_back(kvp.second);
|
||||
}
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
||||
void Invalidate()
|
||||
{
|
||||
m_ObjectStates.clear();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void UpdateObjectsFromRepository()
|
||||
{
|
||||
auto objects = m_Repository.GetObjects();
|
||||
|
||||
RemoveOutdatedStates();
|
||||
|
||||
|
||||
for (const auto& kvp : objects)
|
||||
{
|
||||
const auto& dto = kvp.second;
|
||||
if (m_ObjectStates.contains(kvp.first))
|
||||
{
|
||||
if (!m_ObjectStates[kvp.first].object->IsEqual(dto.get())) {
|
||||
m_ObjectStates[kvp.first].object->UpdateFromDTO(dto.get());
|
||||
m_ObjectStates[kvp.first].state = Enums::ObjectStateEnum::updated;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ObjectStates[kvp.first].state = Enums::ObjectStateEnum::none;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//m_ObjectStates.emplace(kvp.first, DTO::ObjectState<T>{ T::CreateFromDTO(dto), Enums::ObjectStateEnum::created });
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& kvp : m_ObjectStates)
|
||||
{
|
||||
if (!objects.contains(kvp.second.object->GetId()))
|
||||
{
|
||||
m_ObjectStates[kvp.first].object->SaveState();
|
||||
kvp.second.state = Enums::ObjectStateEnum::deleted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void RemoveOutdatedStates()
|
||||
{
|
||||
auto it = m_ObjectStates.begin();
|
||||
while (it != m_ObjectStates.end())
|
||||
{
|
||||
if (it->second.state == Enums::ObjectStateEnum::deleted)
|
||||
{
|
||||
m_ObjectStates.erase(it++);
|
||||
}
|
||||
else
|
||||
{
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Repositories::ObjectRepositoryInterface<U>& m_Repository;
|
||||
std::map<uint32_t, DTO::ObjectState<T>> m_ObjectStates;
|
||||
};
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "ObjectService.h"
|
||||
#include "../DTO/Player.h"
|
||||
#include "../Entities/Player.h"
|
||||
#include "../Repositories/PlayerRepositoryInterface.h"
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
class PlayerService : public ObjectService<Entities::Player, DTO::Player>
|
||||
{
|
||||
public:
|
||||
PlayerService(Repositories::PlayerRepositoryInterface& repository) : ObjectService(repository)
|
||||
{
|
||||
|
||||
}
|
||||
virtual ~PlayerService() override = default;
|
||||
};
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "ObjectService.h"
|
||||
#include "../DTO/Skill.h"
|
||||
#include "../ValueObjects/Skill.h"
|
||||
#include "../Repositories/SkillRepositoryInterface.h"
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
class SkillService : public ObjectService<ValueObjects::Skill, DTO::Skill>
|
||||
{
|
||||
public:
|
||||
SkillService(Repositories::SkillRepositoryInterface& repository) : ObjectService(repository)
|
||||
{
|
||||
|
||||
}
|
||||
virtual ~SkillService() override = default;
|
||||
};
|
||||
}
|
@ -15,19 +15,19 @@ namespace L2Bot::Domain::ValueObjects
|
||||
{
|
||||
return m_ItemId;
|
||||
}
|
||||
void UpdateFromDTO(const DTO::BaseItem* dto)
|
||||
void Update(const BaseItem* other)
|
||||
{
|
||||
SaveState();
|
||||
|
||||
m_ItemId = dto->itemId;
|
||||
m_Amount = dto->amount;
|
||||
m_IsEquipped = dto->isEquipped;
|
||||
m_EnchantLevel = dto->enchantLevel;
|
||||
m_Mana = dto->mana;
|
||||
m_Name = dto->name;
|
||||
m_IconName = dto->iconName;
|
||||
m_Description = dto->description;
|
||||
m_Weight = dto->weight;
|
||||
m_ItemId = other->m_ItemId;
|
||||
m_Amount = other->m_Amount;
|
||||
m_IsEquipped = other->m_IsEquipped;
|
||||
m_EnchantLevel = other->m_EnchantLevel;
|
||||
m_Mana = other->m_Mana;
|
||||
m_Name = other->m_Name;
|
||||
m_IconName = other->m_IconName;
|
||||
m_Description = other->m_Description;
|
||||
m_Weight = other->m_Weight;
|
||||
}
|
||||
void SaveState()
|
||||
{
|
||||
@ -41,31 +41,17 @@ namespace L2Bot::Domain::ValueObjects
|
||||
false
|
||||
};
|
||||
}
|
||||
const static BaseItem CreateFromDTO(const DTO::BaseItem& dto)
|
||||
const bool IsEqual(const BaseItem* other) const
|
||||
{
|
||||
return BaseItem(
|
||||
dto.itemId,
|
||||
dto.amount,
|
||||
dto.isEquipped,
|
||||
dto.enchantLevel,
|
||||
dto.mana,
|
||||
dto.name,
|
||||
dto.iconName,
|
||||
dto.description,
|
||||
dto.weight
|
||||
);
|
||||
}
|
||||
const bool IsEqual(const DTO::BaseItem* dto) const
|
||||
{
|
||||
return m_ItemId == dto->itemId &&
|
||||
m_Amount == dto->amount &&
|
||||
m_IsEquipped == dto->isEquipped &&
|
||||
m_EnchantLevel == dto->enchantLevel &&
|
||||
m_Mana == dto->mana &&
|
||||
m_Name == dto->name &&
|
||||
m_IconName == dto->iconName &&
|
||||
m_Description == dto->description &&
|
||||
m_Weight == dto->weight;
|
||||
return m_ItemId == other->m_ItemId &&
|
||||
m_Amount == other->m_Amount &&
|
||||
m_IsEquipped == other->m_IsEquipped &&
|
||||
m_EnchantLevel == other->m_EnchantLevel &&
|
||||
m_Mana == other->m_Mana &&
|
||||
m_Name == other->m_Name &&
|
||||
m_IconName == other->m_IconName &&
|
||||
m_Description == other->m_Description &&
|
||||
m_Weight == other->m_Weight;
|
||||
}
|
||||
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
@ -132,7 +118,7 @@ namespace L2Bot::Domain::ValueObjects
|
||||
virtual ~BaseItem() = default;
|
||||
|
||||
private:
|
||||
struct State
|
||||
struct GetState
|
||||
{
|
||||
uint32_t amount = 0;
|
||||
bool isEquipped = 0;
|
||||
@ -153,6 +139,6 @@ namespace L2Bot::Domain::ValueObjects
|
||||
std::string m_IconName = "";
|
||||
std::string m_Description = "";
|
||||
uint16_t m_Weight = 0;
|
||||
State m_PrevState = State();
|
||||
GetState m_PrevState = GetState();
|
||||
};
|
||||
}
|
||||
|
@ -159,46 +159,26 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Domain\DTO\BaseItem.h" />
|
||||
<ClInclude Include="Domain\DTO\Skill.h" />
|
||||
<ClInclude Include="Domain\Repositories\ItemRepositoryInterface.h" />
|
||||
<ClInclude Include="Domain\Repositories\SkillRepositoryInterface.h" />
|
||||
<ClInclude Include="Domain\Serializers\SerializableStateContainerPtr.h" />
|
||||
<ClInclude Include="Domain\Services\ItemService.h" />
|
||||
<ClInclude Include="Domain\Services\ObjectServicePtr.h" />
|
||||
<ClInclude Include="Domain\Services\SkillService.h" />
|
||||
<ClInclude Include="Domain\DTO\EntityState.h" />
|
||||
<ClInclude Include="Domain\Entities\EntityInterface.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\BaseItem.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\Skill.h" />
|
||||
<ClInclude Include="Domain\Entities\Skill.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\Vector3.h" />
|
||||
<ClInclude Include="Domain\Enums\SpoilStateEnum.h" />
|
||||
<ClInclude Include="Domain\Transports\TransportInterface.h" />
|
||||
<ClInclude Include="Domain\DTO\Drop.h" />
|
||||
<ClInclude Include="Domain\DTO\Hero.h" />
|
||||
<ClInclude Include="Domain\DTO\NPC.h" />
|
||||
<ClInclude Include="Domain\DTO\ObjectState.h" />
|
||||
<ClInclude Include="Domain\DTO\Player.h" />
|
||||
<ClInclude Include="Domain\DTO\WorldObject.h" />
|
||||
<ClInclude Include="Domain\Entities\Drop.h" />
|
||||
<ClInclude Include="Domain\Entities\Hero.h" />
|
||||
<ClInclude Include="Domain\Entities\NPC.h" />
|
||||
<ClInclude Include="Domain\Entities\Player.h" />
|
||||
<ClInclude Include="Domain\Entities\WorldObject.h" />
|
||||
<ClInclude Include="Domain\Enums\ClassEnum.h" />
|
||||
<ClInclude Include="Domain\Enums\ObjectStateEnum.h" />
|
||||
<ClInclude Include="Domain\Enums\EntityStateEnum.h" />
|
||||
<ClInclude Include="Domain\Enums\RaceEnum.h" />
|
||||
<ClInclude Include="Domain\Repositories\DropRepositoryInterface.h" />
|
||||
<ClInclude Include="Domain\Repositories\HeroRepositoryInterface.h" />
|
||||
<ClInclude Include="Domain\Repositories\NPCRepositoryInterface.h" />
|
||||
<ClInclude Include="Domain\Repositories\ObjectRepositoryInterface.h" />
|
||||
<ClInclude Include="Domain\Repositories\PlayerRepositoryInterface.h" />
|
||||
<ClInclude Include="Domain\Repositories\EntityRepositoryInterface.h" />
|
||||
<ClInclude Include="Domain\Serializers\Node.h" />
|
||||
<ClInclude Include="Domain\Serializers\Serializable.h" />
|
||||
<ClInclude Include="Domain\Serializers\SerializerInterface.h" />
|
||||
<ClInclude Include="Domain\Services\DropService.h" />
|
||||
<ClInclude Include="Domain\Services\HeroService.h" />
|
||||
<ClInclude Include="Domain\Services\NPCService.h" />
|
||||
<ClInclude Include="Domain\Services\ObjectService.h" />
|
||||
<ClInclude Include="Domain\Services\PlayerService.h" />
|
||||
<ClInclude Include="Domain\Services\EntityService.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\ExperienceInfo.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\FullName.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\InventoryInfo.h" />
|
||||
|
@ -24,12 +24,6 @@
|
||||
<ClInclude Include="Domain\ValueObjects\Vector3.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\DTO\Drop.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\DTO\WorldObject.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Entities\Drop.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -51,12 +45,6 @@
|
||||
<ClInclude Include="Domain\Enums\RaceEnum.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Repositories\DropRepositoryInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Services\DropService.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\ValueObjects\ExperienceInfo.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -84,43 +72,13 @@
|
||||
<ClInclude Include="Domain\ValueObjects\VitalStats.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\DTO\Hero.h">
|
||||
<ClInclude Include="Domain\Services\EntityService.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\DTO\NPC.h">
|
||||
<ClInclude Include="Domain\Repositories\EntityRepositoryInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\DTO\Player.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Services\ObjectService.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Repositories\ObjectRepositoryInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Services\NPCService.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Repositories\NPCRepositoryInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Repositories\PlayerRepositoryInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Services\PlayerService.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Repositories\HeroRepositoryInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Services\HeroService.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Enums\ObjectStateEnum.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\DTO\ObjectState.h">
|
||||
<ClInclude Include="Domain\Enums\EntityStateEnum.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Serializers\Serializable.h">
|
||||
@ -141,34 +99,16 @@
|
||||
<ClInclude Include="Domain\Enums\SpoilStateEnum.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\DTO\Skill.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\ValueObjects\Skill.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Repositories\SkillRepositoryInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Services\SkillService.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\DTO\BaseItem.h">
|
||||
<ClInclude Include="Domain\Entities\Skill.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\ValueObjects\BaseItem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Repositories\ItemRepositoryInterface.h">
|
||||
<ClInclude Include="Domain\DTO\EntityState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Services\ItemService.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Serializers\SerializableStateContainerPtr.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Services\ObjectServicePtr.h">
|
||||
<ClInclude Include="Domain\Entities\EntityInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <string>
|
||||
|
||||
#include "Services/WorldHandler.h"
|
||||
#include "Domain/Repositories/SkillRepositoryInterface.h"
|
||||
#include "Serializers/JsonSerializer.h"
|
||||
#include "Transports/NamedPipeTransport.h"
|
||||
|
||||
|
@ -176,11 +176,14 @@
|
||||
<ClInclude Include="Events\SpoiledEvent.h" />
|
||||
<ClInclude Include="Application.h" />
|
||||
<ClInclude Include="Serializers\JsonSerializer.h" />
|
||||
<ClInclude Include="Versions\Interlude\Repositories\SkillRepository.h" />
|
||||
<ClInclude Include="Services\WorldHandler.h" />
|
||||
<ClInclude Include="Services\EntityHandler.h" />
|
||||
<ClInclude Include="Versions\GameStructs\FNameInterface.h" />
|
||||
<ClInclude Include="Versions\GameStructs\GameEngineInterface.h" />
|
||||
<ClInclude Include="Versions\GameStructs\L2GameDataInterface.h" />
|
||||
<ClInclude Include="Versions\Interlude\Factories\HeroFactory.h" />
|
||||
<ClInclude Include="Versions\Interlude\Factories\NPCFactory.h" />
|
||||
<ClInclude Include="Versions\Interlude\Factories\PlayerFactory.h" />
|
||||
<ClInclude Include="Versions\Interlude\Factories\SkillFactory.h" />
|
||||
<ClInclude Include="Versions\Interlude\GameStructs\GameEngineWrapper.h" />
|
||||
<ClInclude Include="Versions\Interlude\GameStructs\L2GameDataWrapper.h" />
|
||||
@ -192,19 +195,17 @@
|
||||
<ClInclude Include="Versions\GameStructs\GameStructs.h" />
|
||||
<ClInclude Include="Transports\NamedPipe.h" />
|
||||
<ClInclude Include="Transports\NamedPipeTransport.h" />
|
||||
<ClInclude Include="Versions\Interlude\Repositories\NPCRepository.h" />
|
||||
<ClInclude Include="Versions\Interlude\Repositories\HeroRepository.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="Versions\Interlude\Repositories\PlayerRepository.h" />
|
||||
<ClInclude Include="Versions\Interlude\GameStructs\GameStructs.h" />
|
||||
<ClInclude Include="Versions\Interlude\GameStructs\L2ParamStack.h" />
|
||||
<ClInclude Include="Versions\Interlude\GameStructs\NetworkHandlerWrapper.h" />
|
||||
<ClInclude Include="Versions\GameStructs\NetworkHandlerInterface.h" />
|
||||
<ClInclude Include="Versions\Interlude\Factories\DropFactory.h" />
|
||||
<ClInclude Include="Versions\Interlude\Factories\HeroFactory.h" />
|
||||
<ClInclude Include="Versions\Interlude\AbstractFactory.h" />
|
||||
<ClInclude Include="Versions\Interlude\Factories\NPCFactory.h" />
|
||||
<ClInclude Include="Versions\Interlude\Factories\PlayerFactory.h" />
|
||||
<ClInclude Include="Versions\Interlude\Repositories\HeroRepository.h" />
|
||||
<ClInclude Include="Versions\Interlude\Repositories\NPCRepository.h" />
|
||||
<ClInclude Include="Versions\Interlude\Repositories\PlayerRepository.h" />
|
||||
<ClInclude Include="Versions\Interlude\Repositories\SkillRepository.h" />
|
||||
<ClInclude Include="Versions\VersionAbstractFactory.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -30,21 +30,12 @@
|
||||
<ClInclude Include="Versions\Interlude\GameStructs\NetworkHandlerWrapper.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Repositories\HeroRepository.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Repositories\NPCRepository.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Repositories\DropRepository.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Transports\DebugViewTransport.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Repositories\PlayerRepository.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Transports\NamedPipeTransport.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -66,15 +57,6 @@
|
||||
<ClInclude Include="Versions\Interlude\Factories\DropFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Factories\HeroFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Factories\NPCFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Factories\PlayerFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\AbstractFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -111,12 +93,6 @@
|
||||
<ClInclude Include="Services\WorldHandler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Factories\SkillFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Repositories\SkillRepository.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\GameStructs\GameEngineInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -150,6 +126,33 @@
|
||||
<ClInclude Include="Serializers\JsonSerializer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Services\EntityHandler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Factories\HeroFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Repositories\HeroRepository.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Factories\NPCFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Repositories\NPCRepository.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Factories\PlayerFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Repositories\PlayerRepository.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Factories\SkillFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Repositories\SkillRepository.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp">
|
||||
|
89
L2BotDll/Services/EntityHandler.h
Normal file
89
L2BotDll/Services/EntityHandler.h
Normal file
@ -0,0 +1,89 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
#include "Domain/DTO/EntityState.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
class EntityHandler
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
const std::map<uint32_t, DTO::EntityState*> GetEntities(const std::map<uint32_t, T> items, std::function<Entities::EntityInterface*(T)> callback)
|
||||
{
|
||||
RemoveOutdatedStates();
|
||||
|
||||
for (const auto& kvp : items)
|
||||
{
|
||||
const auto item = kvp.second;
|
||||
const auto newObject = callback(item);
|
||||
if (m_Objects.contains(newObject->GetId()))
|
||||
{
|
||||
if (!m_Objects[kvp.first]->GetEntity()->IsEqual(newObject)) {
|
||||
m_Objects[kvp.first]->GetEntity()->Update(newObject);
|
||||
m_Objects[kvp.first]->UpdateState(Enums::EntityStateEnum::updated);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Objects[kvp.first]->UpdateState(Enums::EntityStateEnum::none);
|
||||
}
|
||||
delete newObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Objects.emplace(
|
||||
newObject->GetId(),
|
||||
new DTO::EntityState{ newObject, Enums::EntityStateEnum::created }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& kvp : m_Objects)
|
||||
{
|
||||
if (!items.contains(kvp.second->GetEntity()->GetId()))
|
||||
{
|
||||
m_Objects[kvp.first]->GetEntity()->SaveState();
|
||||
kvp.second->UpdateState(Enums::EntityStateEnum::deleted);
|
||||
}
|
||||
}
|
||||
|
||||
return m_Objects;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
for (const auto& object : m_Objects)
|
||||
{
|
||||
delete object.second;
|
||||
}
|
||||
m_Objects.clear();
|
||||
}
|
||||
|
||||
EntityHandler() = default;
|
||||
virtual ~EntityHandler()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
private:
|
||||
void RemoveOutdatedStates()
|
||||
{
|
||||
auto it = m_Objects.begin();
|
||||
while (it != m_Objects.end())
|
||||
{
|
||||
if (it->second->GetState() == Enums::EntityStateEnum::deleted)
|
||||
{
|
||||
delete it->second;
|
||||
m_Objects.erase(it++);
|
||||
}
|
||||
else
|
||||
{
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<uint32_t, DTO::EntityState*> m_Objects;
|
||||
};
|
@ -1,16 +1,11 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <thread>
|
||||
#include <Windows.h>
|
||||
#include "Domain/Services/DropService.h"
|
||||
#include "Domain/Services/HeroService.h"
|
||||
#include "Domain/Services/NPCService.h"
|
||||
#include "Domain/Services/PlayerService.h"
|
||||
#include "Domain/Services/SkillService.h"
|
||||
#include "Domain/Services/EntityService.h"
|
||||
#include "Domain/Serializers/SerializableStateContainer.h"
|
||||
#include "Domain/Serializers/SerializerInterface.h"
|
||||
#include "Domain/Repositories/DropRepositoryInterface.h"
|
||||
#include "Domain/Repositories/SkillRepositoryInterface.h"
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
#include "Domain/Transports/TransportInterface.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
@ -19,19 +14,19 @@ class WorldHandler
|
||||
{
|
||||
public:
|
||||
WorldHandler(
|
||||
Repositories::HeroRepositoryInterface& heroRepository,
|
||||
Repositories::DropRepositoryInterface& dropRepository,
|
||||
Repositories::NPCRepositoryInterface& npcRepository,
|
||||
Repositories::PlayerRepositoryInterface& playerRepository,
|
||||
Repositories::SkillRepositoryInterface& skillRepository,
|
||||
Repositories::EntityRepositoryInterface& heroRepository,
|
||||
Repositories::EntityRepositoryInterface& dropRepository,
|
||||
Repositories::EntityRepositoryInterface& npcRepository,
|
||||
Repositories::EntityRepositoryInterface& playerRepository,
|
||||
Repositories::EntityRepositoryInterface& skillRepository,
|
||||
const Serializers::SerializerInterface& serializer,
|
||||
Transports::TransportInterface& transport
|
||||
) :
|
||||
m_DropService(Services::DropService(dropRepository)),
|
||||
m_HeroService(Services::HeroService(heroRepository)),
|
||||
m_NPCService(Services::NPCService(npcRepository)),
|
||||
m_PlayerService(Services::PlayerService(playerRepository)),
|
||||
m_SkillService(Services::SkillService(skillRepository)),
|
||||
m_HeroService(Services::EntityService(heroRepository)),
|
||||
m_DropService(Services::EntityService(dropRepository)),
|
||||
m_NPCService(Services::EntityService(npcRepository)),
|
||||
m_PlayerService(Services::EntityService(playerRepository)),
|
||||
m_SkillService(Services::EntityService(skillRepository)),
|
||||
m_Serializer(serializer),
|
||||
m_Transport(transport)
|
||||
{
|
||||
@ -120,11 +115,11 @@ private:
|
||||
{
|
||||
std::vector<Serializers::Serializable*> items
|
||||
{
|
||||
new Serializers::SerializableStateContainer<Entities::Hero>(m_HeroService.GetObjects(), "hero"),
|
||||
new Serializers::SerializableStateContainer<Entities::Drop>(m_DropService.GetObjects(), "drop"),
|
||||
new Serializers::SerializableStateContainer<Entities::NPC>(m_NPCService.GetObjects(), "npc"),
|
||||
new Serializers::SerializableStateContainer<Entities::Player>(m_PlayerService.GetObjects(), "player"),
|
||||
new Serializers::SerializableStateContainer<ValueObjects::Skill>(m_SkillService.GetObjects(), "skill")
|
||||
new Serializers::SerializableStateContainer(m_HeroService.GetEntities(), "hero"),
|
||||
new Serializers::SerializableStateContainer(m_DropService.GetEntities(), "drop"),
|
||||
new Serializers::SerializableStateContainer(m_NPCService.GetEntities(), "npc"),
|
||||
new Serializers::SerializableStateContainer(m_PlayerService.GetEntities(), "player"),
|
||||
new Serializers::SerializableStateContainer(m_SkillService.GetEntities(), "skill"),
|
||||
};
|
||||
|
||||
std::vector<Serializers::Node> result;
|
||||
@ -146,19 +141,19 @@ private:
|
||||
|
||||
void Invalidate()
|
||||
{
|
||||
m_HeroService.Invalidate();
|
||||
m_DropService.Invalidate();
|
||||
m_HeroService.Invalidate();
|
||||
m_NPCService.Invalidate();
|
||||
m_PlayerService.Invalidate();
|
||||
m_SkillService.Invalidate();
|
||||
}
|
||||
|
||||
private:
|
||||
Services::DropService m_DropService;
|
||||
Services::HeroService m_HeroService;
|
||||
Services::NPCService m_NPCService;
|
||||
Services::PlayerService m_PlayerService;
|
||||
Services::SkillService m_SkillService;
|
||||
Services::EntityService m_DropService;
|
||||
Services::EntityService m_HeroService;
|
||||
Services::EntityService m_NPCService;
|
||||
Services::EntityService m_PlayerService;
|
||||
Services::EntityService m_SkillService;
|
||||
const Serializers::SerializerInterface& m_Serializer;
|
||||
Transports::TransportInterface& m_Transport;
|
||||
bool m_Stopped = false;
|
||||
|
@ -9,7 +9,7 @@ class FindObjectsTrait
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
std::map<uint32_t, T> GetAllObjects(float_t radius, std::function<const T(float_t, int32_t)> getNextObject) const
|
||||
std::map<uint32_t, T> FindAllObjects(float_t radius, std::function<const T(float_t, int32_t)> getNextObject) const
|
||||
{
|
||||
std::map<uint32_t, T> result;
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "../VersionAbstractFactory.h"
|
||||
#include "Factories/HeroFactory.h"
|
||||
#include "Factories/DropFactory.h"
|
||||
#include "Factories/HeroFactory.h"
|
||||
#include "Factories/NPCFactory.h"
|
||||
#include "Factories/PlayerFactory.h"
|
||||
#include "Factories/SkillFactory.h"
|
||||
#include "Repositories/HeroRepository.h"
|
||||
#include "Repositories/DropRepository.h"
|
||||
#include "Repositories/HeroRepository.h"
|
||||
#include "Repositories/NPCRepository.h"
|
||||
#include "Repositories/PlayerRepository.h"
|
||||
#include "Repositories/SkillRepository.h"
|
||||
@ -15,6 +15,7 @@
|
||||
#include "GameStructs/GameEngineWrapper.h"
|
||||
#include "GameStructs/L2GameDataWrapper.h"
|
||||
#include "GameStructs/FName.h"
|
||||
#include "../../Services/EntityHandler.h"
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
@ -32,18 +33,22 @@ namespace Interlude
|
||||
HeroRepository& GetHeroRepository() const override
|
||||
{
|
||||
static auto factory = HeroFactory();
|
||||
static EntityHandler handler;
|
||||
static auto result = HeroRepository(
|
||||
GetNetworkHandler(),
|
||||
factory
|
||||
factory,
|
||||
handler
|
||||
);
|
||||
return result;
|
||||
}
|
||||
DropRepository& GetDropRepository() const override
|
||||
{
|
||||
static auto factory = DropFactory(GetL2GameData(), GetFName());
|
||||
static EntityHandler handler;
|
||||
static auto result = DropRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
handler,
|
||||
m_Radius
|
||||
);
|
||||
return result;
|
||||
@ -51,19 +56,36 @@ namespace Interlude
|
||||
NPCRepository& GetNPCRepository() const override
|
||||
{
|
||||
static auto factory = NPCFactory();
|
||||
static auto result = NPCRepository(GetNetworkHandler(), factory, m_Radius);
|
||||
static EntityHandler handler;
|
||||
static auto result = NPCRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
handler,
|
||||
m_Radius
|
||||
);
|
||||
return result;
|
||||
}
|
||||
PlayerRepository& GetPlayerRepository() const override
|
||||
{
|
||||
static auto factory = PlayerFactory();
|
||||
static auto result = PlayerRepository(GetNetworkHandler(), factory, m_Radius);
|
||||
static EntityHandler handler;
|
||||
static auto result = PlayerRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
handler,
|
||||
m_Radius
|
||||
);
|
||||
return result;
|
||||
}
|
||||
SkillRepository& GetSkillRepository() const override
|
||||
{
|
||||
static auto factory = SkillFactory(GetL2GameData(), GetFName());
|
||||
static auto result = SkillRepository(GetNetworkHandler(), factory);
|
||||
static EntityHandler handler;
|
||||
static auto result = SkillRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
handler
|
||||
);
|
||||
return result;
|
||||
}
|
||||
NetworkHandlerWrapper& GetNetworkHandler() const override
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
#include "../GameStructs/L2GameDataWrapper.h"
|
||||
#include "../GameStructs/FName.h"
|
||||
#include "../GameStructs/GameStructs.h"
|
||||
#include "../../../Common/Common.h"
|
||||
#include "Domain/Entities/Drop.h"
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
@ -18,13 +20,13 @@ namespace Interlude
|
||||
DropFactory() = delete;
|
||||
virtual ~DropFactory() = default;
|
||||
|
||||
const DTO::Drop Create(const Item* item) const
|
||||
Entities::EntityInterface* Create(const Item* item) const
|
||||
{
|
||||
const auto itemData = m_L2GameData.GetItemData(item->itemId);
|
||||
const auto nameEntry = itemData ? m_FName.GetEntry(itemData->nameIndex) : nullptr;
|
||||
const auto iconEntry = itemData ? m_FName.GetEntry(itemData->iconNameIndex) : nullptr;
|
||||
|
||||
return DTO::Drop{
|
||||
return new Entities::Drop{
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
|
||||
|
@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../GameStructs/GameStructs.h"
|
||||
#include "../../../Common/Common.h"
|
||||
#include "Domain/Entities/Hero.h"
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
@ -11,11 +12,11 @@ namespace Interlude
|
||||
HeroFactory() = default;
|
||||
virtual ~HeroFactory() = default;
|
||||
|
||||
const DTO::Hero Create(const User* item) const
|
||||
Entities::EntityInterface* Create(const User* item) const
|
||||
{
|
||||
const auto playerController = item->pawn ? item->pawn->lineagePlayerController : nullptr;
|
||||
|
||||
return DTO::Hero{
|
||||
return new Entities::Hero{
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "../../../Common/Common.h"
|
||||
#include "Domain/Entities/NPC.h"
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
@ -11,9 +11,9 @@ namespace Interlude
|
||||
NPCFactory() = default;
|
||||
virtual ~NPCFactory() = default;
|
||||
|
||||
const DTO::NPC Create(const User* item, const Enums::SpoilStateEnum spoiledState) const
|
||||
Entities::EntityInterface* Create(const User* item, const Enums::SpoilStateEnum spoiledState) const
|
||||
{
|
||||
return DTO::NPC{
|
||||
return new Entities::NPC{
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../Common/Common.h"
|
||||
#include "Domain/Entities/Player.h"
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
@ -10,9 +11,9 @@ namespace Interlude
|
||||
PlayerFactory() = default;
|
||||
virtual ~PlayerFactory() = default;
|
||||
|
||||
const DTO::Player Create(const User* item) const
|
||||
Entities::EntityInterface* Create(const User* item) const
|
||||
{
|
||||
return DTO::Player{
|
||||
return new Entities::Player{
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
|
||||
|
@ -5,6 +5,9 @@
|
||||
#include "../GameStructs/L2GameDataWrapper.h"
|
||||
#include "../GameStructs/FName.h"
|
||||
#include "../../../Common/Common.h"
|
||||
#include "Domain/Entities/Skill.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
@ -20,7 +23,7 @@ namespace Interlude
|
||||
SkillFactory() = delete;
|
||||
virtual ~SkillFactory() = default;
|
||||
|
||||
const DTO::Skill Create(const DTO::Skill source, const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
|
||||
Entities::Skill* Create(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
|
||||
{
|
||||
const auto data = m_L2GameData.GetMSData(skillId, level);
|
||||
|
||||
@ -30,7 +33,7 @@ namespace Interlude
|
||||
const auto description = data ? data->description : L"";
|
||||
const auto iconEntry = data ? m_FName.GetEntry(data->iconNameIndex) : nullptr;
|
||||
|
||||
return DTO::Skill
|
||||
return new Entities::Skill
|
||||
{
|
||||
skillId,
|
||||
static_cast<uint8_t>(level),
|
||||
@ -40,63 +43,9 @@ namespace Interlude
|
||||
ConvertFromWideChar(name),
|
||||
ConvertFromWideChar(description),
|
||||
iconEntry ? ConvertFromWideChar(iconEntry->value) : "",
|
||||
source.isToggled,
|
||||
source.isCasting,
|
||||
source.isReloading
|
||||
};
|
||||
}
|
||||
|
||||
const DTO::Skill UpdateToggle(const DTO::Skill source, const bool isToggled) const
|
||||
{
|
||||
return DTO::Skill
|
||||
{
|
||||
source.skillId,
|
||||
source.level,
|
||||
source.isActive,
|
||||
source.cost,
|
||||
source.range,
|
||||
source.name,
|
||||
source.description,
|
||||
source.iconName,
|
||||
isToggled,
|
||||
source.isCasting,
|
||||
source.isReloading
|
||||
};
|
||||
}
|
||||
|
||||
const DTO::Skill UpdateCastingState(const DTO::Skill source, const bool isCasting) const
|
||||
{
|
||||
return DTO::Skill
|
||||
{
|
||||
source.skillId,
|
||||
source.level,
|
||||
source.isActive,
|
||||
source.cost,
|
||||
source.range,
|
||||
source.name,
|
||||
source.description,
|
||||
source.iconName,
|
||||
source.isToggled,
|
||||
isCasting,
|
||||
source.isReloading
|
||||
};
|
||||
}
|
||||
|
||||
const DTO::Skill UpdateReloadingState(const DTO::Skill source, const bool isReloading) const
|
||||
{
|
||||
return DTO::Skill
|
||||
{
|
||||
source.skillId,
|
||||
source.level,
|
||||
source.isActive,
|
||||
source.cost,
|
||||
source.range,
|
||||
source.name,
|
||||
source.description,
|
||||
source.iconName,
|
||||
source.isToggled,
|
||||
source.isCasting,
|
||||
isReloading
|
||||
false,
|
||||
false,
|
||||
false
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ namespace Interlude
|
||||
|
||||
User* NetworkHandlerWrapper::GetHero() const
|
||||
{
|
||||
const auto creatures = GetAllObjects<User*>(0.1f, [this](float_t radius, int32_t prevId) {
|
||||
const auto creatures = FindAllObjects<User*>(0.1f, [this](float_t radius, int32_t prevId) {
|
||||
return GetNextCreature(radius, prevId);
|
||||
});
|
||||
|
||||
|
@ -1,38 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include "Domain/Repositories/DropRepositoryInterface.h"
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
#include "Domain/DTO/EntityState.h"
|
||||
#include "../Factories/DropFactory.h"
|
||||
#include "../../GameStructs/FindObjectsTrait.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Services/EntityHandler.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
class DropRepository : public Repositories::DropRepositoryInterface, public FindObjectsTrait
|
||||
class DropRepository : public Repositories::EntityRepositoryInterface, public FindObjectsTrait
|
||||
{
|
||||
public:
|
||||
const std::map<uint32_t, DTO::Drop> GetObjects() override
|
||||
const std::vector<DTO::EntityState*> GetEntities() override
|
||||
{
|
||||
const auto items = GetAllObjects<Item*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
const std::map<uint32_t, Item*> items = FindAllObjects<Item*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
return m_NetworkHandler.GetNextItem(radius, prevId);
|
||||
});
|
||||
const auto objects = m_Container.GetEntities<Item*>(items, [this](Item* item) {
|
||||
return m_Factory.Create(item);
|
||||
});
|
||||
|
||||
std::map<uint32_t, DTO::Drop> map;
|
||||
auto result = std::vector<DTO::EntityState*>();
|
||||
|
||||
for (const auto& kvp : items)
|
||||
for (const auto kvp : objects)
|
||||
{
|
||||
const auto item = kvp.second;
|
||||
map.emplace(item->objectId, m_Factory.Create(item));
|
||||
result.push_back(kvp.second);
|
||||
}
|
||||
|
||||
return map;
|
||||
return result;
|
||||
}
|
||||
|
||||
DropRepository(const NetworkHandlerWrapper& networkHandler, const DropFactory& factory, const uint16_t radius) :
|
||||
void Reset() override
|
||||
{
|
||||
m_Container.Reset();
|
||||
}
|
||||
|
||||
DropRepository(const NetworkHandlerWrapper& networkHandler, const DropFactory& factory, EntityHandler& handler, const uint16_t radius) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_Radius(radius)
|
||||
m_Radius(radius),
|
||||
m_Container(handler)
|
||||
{
|
||||
|
||||
}
|
||||
@ -44,5 +55,6 @@ namespace Interlude
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
const DropFactory& m_Factory;
|
||||
const uint16_t m_Radius;
|
||||
EntityHandler& m_Container;
|
||||
};
|
||||
}
|
||||
|
@ -1,26 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "Domain/Repositories/HeroRepositoryInterface.h"
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
#include "../Factories/HeroFactory.h"
|
||||
#include "../../../Events/EventDispatcher.h"
|
||||
#include "../../../Events/HeroCreatedEvent.h"
|
||||
#include "../../../Events/HeroDeletedEvent.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Services/EntityHandler.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
class HeroRepository : public Repositories::HeroRepositoryInterface
|
||||
class HeroRepository : public Repositories::EntityRepositoryInterface
|
||||
{
|
||||
public:
|
||||
const std::map<uint32_t, DTO::Hero> GetObjects() override
|
||||
const std::vector<DTO::EntityState*> GetEntities() override
|
||||
{
|
||||
std::map<uint32_t, DTO::Hero> map;
|
||||
const auto hero = m_NetworkHandler.GetHero();
|
||||
if (hero)
|
||||
{
|
||||
map.emplace(hero->objectId, m_Factory.Create(hero));
|
||||
}
|
||||
|
||||
auto hero = m_NetworkHandler.GetHero();
|
||||
|
||||
if (hero != nullptr && m_PrevHero == nullptr)
|
||||
{
|
||||
@ -30,15 +28,38 @@ namespace Interlude
|
||||
{
|
||||
EventDispatcher::GetInstance().Dispatch(HeroDeletedEvent{});
|
||||
}
|
||||
|
||||
m_PrevHero = hero;
|
||||
|
||||
return map;
|
||||
std::map<uint32_t, User*> items;
|
||||
|
||||
if (hero)
|
||||
{
|
||||
items.emplace(hero->objectId, hero);
|
||||
}
|
||||
|
||||
const auto objects = m_EntityHandler.GetEntities<User*>(items, [this](User* item) {
|
||||
return m_Factory.Create(item);
|
||||
});
|
||||
|
||||
auto result = std::vector<DTO::EntityState*>();
|
||||
|
||||
for (const auto kvp : objects)
|
||||
{
|
||||
result.push_back(kvp.second);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
HeroRepository(const NetworkHandlerWrapper& networkHandler, const HeroFactory& factory) :
|
||||
void Reset() override
|
||||
{
|
||||
m_EntityHandler.Reset();
|
||||
}
|
||||
|
||||
HeroRepository(const NetworkHandlerWrapper& networkHandler, const HeroFactory& factory, EntityHandler& handler) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory)
|
||||
m_Factory(factory),
|
||||
m_EntityHandler(handler)
|
||||
{
|
||||
|
||||
}
|
||||
@ -50,5 +71,6 @@ namespace Interlude
|
||||
const HeroFactory& m_Factory;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
User* m_PrevHero = nullptr;
|
||||
EntityHandler& m_EntityHandler;
|
||||
};
|
||||
}
|
@ -2,44 +2,61 @@
|
||||
|
||||
#include <map>
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "Domain/Repositories/NPCRepositoryInterface.h"
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
#include "../Factories/NPCFactory.h"
|
||||
#include "../../../Events/EventDispatcher.h"
|
||||
#include "../../../Events/SpoiledEvent.h"
|
||||
#include "../../../Events/CreatureDiedEvent.h"
|
||||
#include "../../GameStructs/FindObjectsTrait.h"
|
||||
#include "../../../Services/EntityHandler.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
class NPCRepository : public Repositories::NPCRepositoryInterface, public FindObjectsTrait
|
||||
class NPCRepository : public Repositories::EntityRepositoryInterface, public FindObjectsTrait
|
||||
{
|
||||
public:
|
||||
const std::map<uint32_t, DTO::NPC> GetObjects() override
|
||||
const std::vector<DTO::EntityState*> GetEntities() override
|
||||
{
|
||||
const auto creatures = GetAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
const auto creatures = FindAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
return m_NetworkHandler.GetNextCreature(radius, prevId);
|
||||
});
|
||||
|
||||
std::map<uint32_t, DTO::NPC> map;
|
||||
|
||||
std::map<uint32_t, User*> items;
|
||||
for (const auto& kvp : creatures)
|
||||
{
|
||||
const auto creature = kvp.second;
|
||||
if (creature->userType == L2::UserType::NPC) {
|
||||
const auto spoilState = m_Spoiled.find(creature->objectId) == m_Spoiled.end() ? Enums::SpoilStateEnum::none : m_Spoiled.at(creature->objectId);
|
||||
map.emplace(creature->objectId, m_Factory.Create(creature, spoilState));
|
||||
items.emplace(creature->objectId, creature);
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
const auto objects = m_EntityHandler.GetEntities<User*>(items, [this](User* item) {
|
||||
const auto spoilState = m_Spoiled.find(item->objectId) == m_Spoiled.end() ? Enums::SpoilStateEnum::none : m_Spoiled.at(item->objectId);
|
||||
return m_Factory.Create(item, spoilState);
|
||||
});
|
||||
|
||||
auto result = std::vector<DTO::EntityState*>();
|
||||
|
||||
for (const auto kvp : objects)
|
||||
{
|
||||
result.push_back(kvp.second);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NPCRepository(const NetworkHandlerWrapper& networkHandler, const NPCFactory& factory, const uint16_t radius) :
|
||||
void Reset() override
|
||||
{
|
||||
m_EntityHandler.Reset();
|
||||
}
|
||||
|
||||
NPCRepository(const NetworkHandlerWrapper& networkHandler, const NPCFactory& factory, EntityHandler& handler, const uint16_t radius) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_Radius(radius)
|
||||
m_Radius(radius),
|
||||
m_EntityHandler(handler)
|
||||
{
|
||||
EventDispatcher::GetInstance().Subscribe(SpoiledEvent::name, [this](const Event& evt) {
|
||||
OnSpoiled(evt);
|
||||
@ -93,5 +110,6 @@ namespace Interlude
|
||||
std::map<uint32_t, Enums::SpoilStateEnum> m_Spoiled;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
const uint16_t m_Radius = 0;
|
||||
EntityHandler& m_EntityHandler;
|
||||
};
|
||||
}
|
@ -1,40 +1,57 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include "Domain/Repositories/PlayerRepositoryInterface.h"
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
#include "../Factories/PlayerFactory.h"
|
||||
#include "../../GameStructs/FindObjectsTrait.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Services/EntityHandler.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
class PlayerRepository : public Repositories::PlayerRepositoryInterface, public FindObjectsTrait
|
||||
class PlayerRepository : public Repositories::EntityRepositoryInterface, public FindObjectsTrait
|
||||
{
|
||||
public:
|
||||
const std::map<uint32_t, DTO::Player> GetObjects() override
|
||||
const std::vector<DTO::EntityState*> GetEntities() override
|
||||
{
|
||||
const auto creatures = GetAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
const auto creatures = FindAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
return m_NetworkHandler.GetNextCreature(radius, prevId);
|
||||
});
|
||||
|
||||
std::map<uint32_t, DTO::Player> map;
|
||||
|
||||
std::map<uint32_t, User*> items;
|
||||
for (const auto& kvp : creatures)
|
||||
{
|
||||
const auto creature = kvp.second;
|
||||
if (creature->userType == L2::UserType::USER && creature->lvl == 0) {
|
||||
map.emplace(creature->objectId, m_Factory.Create(creature));
|
||||
items.emplace(creature->objectId, creature);
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
const auto objects = m_EntityHandler.GetEntities<User*>(items, [this](User* item) {
|
||||
return m_Factory.Create(item);
|
||||
});
|
||||
|
||||
auto result = std::vector<DTO::EntityState*>();
|
||||
|
||||
for (const auto kvp : objects)
|
||||
{
|
||||
result.push_back(kvp.second);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PlayerRepository(const NetworkHandlerWrapper& networkHandler, const PlayerFactory& factory, const uint16_t radius) :
|
||||
void Reset() override
|
||||
{
|
||||
m_EntityHandler.Reset();
|
||||
}
|
||||
|
||||
PlayerRepository(const NetworkHandlerWrapper& networkHandler, const PlayerFactory& factory, EntityHandler& handler, const uint16_t radius) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_Radius(radius)
|
||||
m_Radius(radius),
|
||||
m_EntityHandler(handler)
|
||||
{
|
||||
|
||||
}
|
||||
@ -46,5 +63,6 @@ namespace Interlude
|
||||
const PlayerFactory& m_Factory;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
const uint16_t m_Radius;
|
||||
EntityHandler& m_EntityHandler;
|
||||
};
|
||||
}
|
@ -3,32 +3,47 @@
|
||||
#include <map>
|
||||
#include <chrono>
|
||||
#include <shared_mutex>
|
||||
#include "Domain/Repositories/SkillRepositoryInterface.h"
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
#include "../Factories/SkillFactory.h"
|
||||
#include "../../../Events/SkillCreatedEvent.h"
|
||||
#include "../../../Events/SkillUsedEvent.h"
|
||||
#include "../../../Events/SkillCancelledEvent.h"
|
||||
#include "../../../Events/AbnormalEffectChangedEvent.h"
|
||||
#include "../../../Events/HeroDeletedEvent.h"
|
||||
#include "../../../Events/EventDispatcher.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Common/TimerMap.h"
|
||||
#include "../../../Services/EntityHandler.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
class SkillRepository : public Repositories::SkillRepositoryInterface
|
||||
class SkillRepository : public Repositories::EntityRepositoryInterface
|
||||
{
|
||||
public:
|
||||
const std::map<uint32_t, DTO::Skill> GetObjects() override
|
||||
const std::vector<DTO::EntityState*> GetEntities() override
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
return m_Skills;
|
||||
|
||||
const auto objects = m_EntityHandler.GetEntities<Entities::Skill*>(m_Skills, [this](Entities::Skill* item) {
|
||||
return new Entities::Skill(item);
|
||||
});
|
||||
|
||||
auto result = std::vector<DTO::EntityState*>();
|
||||
|
||||
for (const auto kvp : objects)
|
||||
{
|
||||
result.push_back(kvp.second);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
SkillRepository(const NetworkHandlerWrapper& networkHandler, const SkillFactory& factory) :
|
||||
SkillRepository(const NetworkHandlerWrapper& networkHandler, const SkillFactory& factory, EntityHandler& handler) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory)
|
||||
m_Factory(factory),
|
||||
m_EntityHandler(handler)
|
||||
{
|
||||
EventDispatcher::GetInstance().Subscribe(SkillCreatedEvent::name, [this](const Event& evt) {
|
||||
OnSkillCreated(evt);
|
||||
@ -45,17 +60,31 @@ namespace Interlude
|
||||
EventDispatcher::GetInstance().Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
|
||||
OnHeroDeleted(evt);
|
||||
});
|
||||
// TODO delete outdated skills: on hero change subclass?
|
||||
}
|
||||
|
||||
SkillRepository() = delete;
|
||||
virtual ~SkillRepository() = default;
|
||||
virtual ~SkillRepository()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
void Reset() override
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
for (const auto kvp : m_Skills)
|
||||
{
|
||||
delete kvp.second;
|
||||
}
|
||||
m_Skills.clear();
|
||||
}
|
||||
|
||||
void OnHeroDeleted(const Event& evt)
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
if (evt.GetName() == HeroDeletedEvent::name)
|
||||
{
|
||||
m_Skills.clear();
|
||||
Reset();
|
||||
m_CastingTimers.StopAll();
|
||||
m_ReloadingTimers.StopAll();
|
||||
}
|
||||
@ -69,16 +98,20 @@ namespace Interlude
|
||||
const auto skillInfo = casted.GetSkillInfo();
|
||||
const auto skillId = skillInfo[2];
|
||||
|
||||
const auto alreadyExists = m_Skills.find(skillId) != m_Skills.end();
|
||||
if (m_Skills.find(skillId) == m_Skills.end())
|
||||
{
|
||||
auto skill = m_Factory.Create(
|
||||
skillInfo[2],
|
||||
skillInfo[1],
|
||||
skillInfo[0]
|
||||
);
|
||||
|
||||
auto skill = m_Factory.Create(
|
||||
alreadyExists ? m_Skills[skillId] : DTO::Skill(),
|
||||
skillInfo[2],
|
||||
skillInfo[1],
|
||||
skillInfo[0]
|
||||
);
|
||||
|
||||
UpdateSkill(skill);
|
||||
m_Skills.emplace(skill->GetId(), skill);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Skills[skillId]->UpdateLevel(skillInfo[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
void OnSkillUsed(const Event& evt)
|
||||
@ -96,32 +129,19 @@ namespace Interlude
|
||||
return;
|
||||
}
|
||||
|
||||
auto skill = m_Factory.UpdateReloadingState(
|
||||
m_Factory.UpdateCastingState(
|
||||
m_Skills[skillId],
|
||||
true
|
||||
),
|
||||
true
|
||||
);
|
||||
auto skill = m_Skills[skillId];
|
||||
skill->UpdateReloadingState(true);
|
||||
skill->UpdateCastingState(true);
|
||||
|
||||
UpdateSkill(skill);
|
||||
m_UsedSkillId = skill.skillId;
|
||||
m_UsedSkillId = skill->GetId();
|
||||
|
||||
m_ReloadingTimers.StartTimer(skill.skillId, skillInfo[3], [this] (uint32_t skillId) {
|
||||
m_ReloadingTimers.StartTimer(skill->GetId(), skillInfo[3], [this] (uint32_t skillId) {
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
auto skill = m_Factory.UpdateReloadingState(
|
||||
m_Skills[skillId],
|
||||
false
|
||||
);
|
||||
UpdateSkill(skill);
|
||||
m_Skills[skillId]->UpdateReloadingState(false);
|
||||
});
|
||||
m_CastingTimers.StartTimer(skill.skillId, skillInfo[2], [this] (uint32_t skillId) {
|
||||
m_CastingTimers.StartTimer(skill->GetId(), skillInfo[2], [this] (uint32_t skillId) {
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
auto skill = m_Factory.UpdateCastingState(
|
||||
m_Skills[m_UsedSkillId],
|
||||
false
|
||||
);
|
||||
UpdateSkill(skill);
|
||||
m_Skills[skillId]->UpdateCastingState(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -141,16 +161,12 @@ namespace Interlude
|
||||
//todo exception?
|
||||
return;
|
||||
}
|
||||
auto skill = m_Skills[m_UsedSkillId];
|
||||
skill->UpdateCastingState(false);
|
||||
|
||||
auto skill = m_Factory.UpdateCastingState(
|
||||
m_Skills[m_UsedSkillId],
|
||||
false
|
||||
);
|
||||
|
||||
UpdateSkill(skill);
|
||||
m_UsedSkillId = 0;
|
||||
|
||||
m_CastingTimers.StopTimer(skill.skillId);
|
||||
m_CastingTimers.StopTimer(skill->GetId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -171,21 +187,19 @@ namespace Interlude
|
||||
|
||||
for (auto it = m_Skills.begin(); it != m_Skills.end();)
|
||||
{
|
||||
const auto needToToggle = ids.find(it->second.skillId) != ids.end();
|
||||
// buff time less than zero means this is a aura
|
||||
const auto isAura = needToToggle ? ids[it->second.skillId] < 0 : false;
|
||||
auto skill = it->second;
|
||||
|
||||
if (it->second.isToggled && !needToToggle)
|
||||
const auto needToToggle = ids.find(skill->GetId()) != ids.end();
|
||||
// buff time less than zero means this is a aura
|
||||
const auto isAura = needToToggle ? ids[skill->GetId()] < 0 : false;
|
||||
|
||||
if (skill->IsToggled() && !needToToggle)
|
||||
{
|
||||
auto skill = m_Factory.UpdateToggle(it->second, false);
|
||||
it = m_Skills.erase(it);
|
||||
m_Skills.emplace(skill.skillId, skill);
|
||||
skill->UpdateToggle(false);
|
||||
}
|
||||
else if (!it->second.isToggled && needToToggle && isAura)
|
||||
else if (!skill->IsToggled() && needToToggle && isAura)
|
||||
{
|
||||
auto skill = m_Factory.UpdateToggle(it->second, true);
|
||||
it = m_Skills.erase(it);
|
||||
m_Skills.emplace(skill.skillId, skill);
|
||||
skill->UpdateToggle(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -195,20 +209,14 @@ namespace Interlude
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void UpdateSkill(const DTO::Skill skill)
|
||||
{
|
||||
m_Skills.erase(skill.skillId);
|
||||
m_Skills.emplace(skill.skillId, skill);
|
||||
}
|
||||
|
||||
private:
|
||||
const SkillFactory& m_Factory;
|
||||
std::map<uint32_t, DTO::Skill> m_Skills;
|
||||
std::map<uint32_t, Entities::Skill*> m_Skills;
|
||||
uint32_t m_UsedSkillId = 0;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
TimerMap m_ReloadingTimers;
|
||||
TimerMap m_CastingTimers;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
EntityHandler& m_EntityHandler;
|
||||
};
|
||||
}
|
@ -1,10 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Domain/Repositories/HeroRepositoryInterface.h"
|
||||
#include "Domain/Repositories/DropRepositoryInterface.h"
|
||||
#include "Domain/Repositories/NPCRepositoryInterface.h"
|
||||
#include "Domain/Repositories/PlayerRepositoryInterface.h"
|
||||
#include "Domain/Repositories/SkillRepositoryInterface.h"
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
#include "GameStructs/NetworkHandlerInterface.h"
|
||||
#include "GameStructs/GameEngineInterface.h"
|
||||
#include "GameStructs/L2GameDataInterface.h"
|
||||
@ -20,11 +16,11 @@ public:
|
||||
interlude
|
||||
};
|
||||
|
||||
virtual Repositories::HeroRepositoryInterface& GetHeroRepository() const = 0;
|
||||
virtual Repositories::DropRepositoryInterface& GetDropRepository() const = 0;
|
||||
virtual Repositories::NPCRepositoryInterface& GetNPCRepository() const = 0;
|
||||
virtual Repositories::PlayerRepositoryInterface& GetPlayerRepository() const = 0;
|
||||
virtual Repositories::SkillRepositoryInterface& GetSkillRepository() const = 0;
|
||||
virtual Repositories::EntityRepositoryInterface& GetHeroRepository() const = 0;
|
||||
virtual Repositories::EntityRepositoryInterface& GetDropRepository() const = 0;
|
||||
virtual Repositories::EntityRepositoryInterface& GetNPCRepository() const = 0;
|
||||
virtual Repositories::EntityRepositoryInterface& GetPlayerRepository() const = 0;
|
||||
virtual Repositories::EntityRepositoryInterface& GetSkillRepository() const = 0;
|
||||
virtual NetworkHandlerInterface& GetNetworkHandler() const = 0;
|
||||
virtual GameEngineInterface& GetGameEngine() const = 0;
|
||||
virtual L2GameDataInterface& GetL2GameData() const = 0;
|
||||
|
Reference in New Issue
Block a user