feat: use unique_ptr in skill repository
This commit is contained in:
parent
c01d1c3549
commit
3ccdf1d9e4
@ -10,27 +10,10 @@ namespace L2Bot::Domain::DTO
|
||||
class EntityState
|
||||
{
|
||||
public:
|
||||
const uint32_t GetId() const
|
||||
const std::unique_ptr<Entities::EntityInterface>& GetEntity() const
|
||||
{
|
||||
return m_Entity->GetId();
|
||||
return m_Entity;
|
||||
}
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const
|
||||
{
|
||||
return m_Entity->BuildSerializationNodes();
|
||||
}
|
||||
void SaveEntityState()
|
||||
{
|
||||
m_Entity->SaveState();
|
||||
}
|
||||
const bool IsEntityEqual(const Entities::EntityInterface* other) const
|
||||
{
|
||||
return m_Entity->IsEqual(other);
|
||||
}
|
||||
void UpdateEntity(const Entities::EntityInterface* other)
|
||||
{
|
||||
m_Entity->Update(other);
|
||||
}
|
||||
|
||||
const Enums::EntityStateEnum GetState() const
|
||||
{
|
||||
return m_State;
|
||||
|
@ -33,7 +33,7 @@ namespace L2Bot::Domain::Serializers
|
||||
result.push_back(
|
||||
{
|
||||
m_ContainerName,
|
||||
std::vector<Serializers::Node>{ { operationName, kvp->BuildSerializationNodes() } }
|
||||
std::vector<Serializers::Node>{ { operationName, kvp->GetEntity()->BuildSerializationNodes() } }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -22,20 +22,20 @@ public:
|
||||
auto newObject = callback(item);
|
||||
if (m_Objects.contains(newObject->GetId()))
|
||||
{
|
||||
if (!m_Objects[kvp.first]->IsEntityEqual(newObject.get())) {
|
||||
m_Objects[kvp.first]->UpdateEntity(newObject.get());
|
||||
if (!m_Objects[kvp.first]->GetEntity()->IsEqual(newObject.get())) {
|
||||
m_Objects[kvp.first]->GetEntity()->Update(newObject.get());
|
||||
m_Objects[kvp.first]->UpdateState(Enums::EntityStateEnum::updated);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Objects[kvp.first]->UpdateState(Enums::EntityStateEnum::none);
|
||||
}
|
||||
//delete newObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto objectId = newObject->GetId();
|
||||
m_Objects.emplace(
|
||||
newObject->GetId(),
|
||||
objectId,
|
||||
new DTO::EntityState{ std::move(newObject), Enums::EntityStateEnum::created }
|
||||
);
|
||||
}
|
||||
@ -43,9 +43,9 @@ public:
|
||||
|
||||
for (auto& kvp : m_Objects)
|
||||
{
|
||||
if (!items.contains(kvp.second->GetId()))
|
||||
if (!items.contains(kvp.second->GetEntity()->GetId()))
|
||||
{
|
||||
m_Objects[kvp.first]->SaveEntityState();
|
||||
m_Objects[kvp.first]->GetEntity()->SaveState();
|
||||
kvp.second->UpdateState(Enums::EntityStateEnum::deleted);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace Interlude
|
||||
DropFactory() = delete;
|
||||
virtual ~DropFactory() = default;
|
||||
|
||||
std::unique_ptr<Entities::EntityInterface> Create(const Item* item) const
|
||||
std::unique_ptr<Entities::Drop> Create(const Item* item) const
|
||||
{
|
||||
const auto itemData = m_L2GameData.GetItemData(item->itemId);
|
||||
const auto nameEntry = itemData ? m_FName.GetEntry(itemData->nameIndex) : nullptr;
|
||||
|
@ -13,7 +13,7 @@ namespace Interlude
|
||||
HeroFactory() = default;
|
||||
virtual ~HeroFactory() = default;
|
||||
|
||||
std::unique_ptr<Entities::EntityInterface> Create(const User* item) const
|
||||
std::unique_ptr<Entities::Hero> Create(const User* item) const
|
||||
{
|
||||
const auto playerController = item->pawn ? item->pawn->lineagePlayerController : nullptr;
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace Interlude
|
||||
NPCFactory() = default;
|
||||
virtual ~NPCFactory() = default;
|
||||
|
||||
std::unique_ptr<Entities::EntityInterface> Create(const User* item, const Enums::SpoilStateEnum spoiledState) const
|
||||
std::unique_ptr<Entities::NPC> Create(const User* item, const Enums::SpoilStateEnum spoiledState) const
|
||||
{
|
||||
return std::make_unique<Entities::NPC>(
|
||||
item->objectId,
|
||||
|
@ -12,7 +12,7 @@ namespace Interlude
|
||||
PlayerFactory() = default;
|
||||
virtual ~PlayerFactory() = default;
|
||||
|
||||
std::unique_ptr<Entities::EntityInterface> Create(const User* item) const
|
||||
std::unique_ptr<Entities::Player> Create(const User* item) const
|
||||
{
|
||||
return std::make_unique<Entities::Player>(
|
||||
item->objectId,
|
||||
|
@ -24,7 +24,7 @@ namespace Interlude
|
||||
SkillFactory() = delete;
|
||||
virtual ~SkillFactory() = default;
|
||||
|
||||
std::unique_ptr<Entities::EntityInterface> Create(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
|
||||
std::unique_ptr<Entities::Skill> Create(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
|
||||
{
|
||||
const auto data = m_L2GameData.GetMSData(skillId, level);
|
||||
|
||||
|
@ -26,7 +26,13 @@ namespace Interlude
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
|
||||
const auto objects = m_EntityHandler.GetEntities<Entities::Skill*>(m_Skills, [this](Entities::Skill* item) {
|
||||
std::map<uint32_t, Entities::Skill*> skillPtrs;
|
||||
for (const auto& kvp : m_Skills)
|
||||
{
|
||||
skillPtrs[kvp.first] = kvp.second.get();
|
||||
}
|
||||
|
||||
const auto objects = m_EntityHandler.GetEntities<Entities::Skill*>(skillPtrs, [this](Entities::Skill* item) {
|
||||
return std::make_unique<Entities::Skill>(item);
|
||||
});
|
||||
|
||||
@ -72,10 +78,6 @@ namespace Interlude
|
||||
void Reset() override
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
for (const auto kvp : m_Skills)
|
||||
{
|
||||
delete kvp.second;
|
||||
}
|
||||
m_Skills.clear();
|
||||
}
|
||||
|
||||
@ -106,8 +108,7 @@ namespace Interlude
|
||||
skillInfo[0]
|
||||
);
|
||||
|
||||
auto test = static_cast<Entities::Skill*>(skill.get());
|
||||
m_Skills.emplace(skill->GetId(), test);
|
||||
m_Skills.emplace(skill->GetId(), std::move(skill));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -130,7 +131,8 @@ namespace Interlude
|
||||
return;
|
||||
}
|
||||
|
||||
auto skill = m_Skills[skillId];
|
||||
const auto& skill = m_Skills[skillId];
|
||||
|
||||
skill->UpdateReloadingState(true);
|
||||
skill->UpdateCastingState(true);
|
||||
|
||||
@ -162,12 +164,13 @@ namespace Interlude
|
||||
//todo exception?
|
||||
return;
|
||||
}
|
||||
auto skill = m_Skills[m_UsedSkillId];
|
||||
|
||||
const auto& skill = m_Skills[m_UsedSkillId];
|
||||
|
||||
skill->UpdateCastingState(false);
|
||||
m_CastingTimers.StopTimer(skill->GetId());
|
||||
|
||||
m_UsedSkillId = 0;
|
||||
|
||||
m_CastingTimers.StopTimer(skill->GetId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -188,7 +191,7 @@ namespace Interlude
|
||||
|
||||
for (auto it = m_Skills.begin(); it != m_Skills.end();)
|
||||
{
|
||||
auto skill = it->second;
|
||||
const auto& skill = it->second;
|
||||
|
||||
const auto needToToggle = ids.find(skill->GetId()) != ids.end();
|
||||
// buff time less than zero means this is a aura
|
||||
@ -212,7 +215,7 @@ namespace Interlude
|
||||
|
||||
private:
|
||||
const SkillFactory& m_Factory;
|
||||
std::map<uint32_t, Entities::Skill*> m_Skills;
|
||||
std::map<uint32_t, std::unique_ptr<Entities::Skill>> m_Skills;
|
||||
uint32_t m_UsedSkillId = 0;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
TimerMap m_ReloadingTimers;
|
||||
|
Loading…
Reference in New Issue
Block a user