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