feat: change dtos to entities
This commit is contained in:
@@ -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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user