feat: add incoming messages to bot
This commit is contained in:
parent
130cdc6bca
commit
eefb5d40ae
@ -13,6 +13,10 @@ namespace L2Bot::Domain::Entities
|
||||
{
|
||||
m_IsAutoused = enabled;
|
||||
}
|
||||
const bool IsAutoused() const
|
||||
{
|
||||
return m_IsAutoused;
|
||||
}
|
||||
|
||||
void Update(const EntityInterface* other) override
|
||||
{
|
||||
|
62
L2BotCore/Domain/Serializers/IncomingMessage.h
Normal file
62
L2BotCore/Domain/Serializers/IncomingMessage.h
Normal file
@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace L2Bot::Domain::Serializers
|
||||
{
|
||||
class IncomingMessage
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
none,
|
||||
invalidate,
|
||||
move,
|
||||
acquireTarget,
|
||||
attack,
|
||||
pickup,
|
||||
useSkill,
|
||||
useItem,
|
||||
toggleSoulshot,
|
||||
sit,
|
||||
stand
|
||||
};
|
||||
|
||||
const Type GetType() const
|
||||
{
|
||||
return m_Type;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const auto GetContent() const
|
||||
{
|
||||
return std::static_pointer_cast<T>(m_Content);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T GetRawContent() const
|
||||
{
|
||||
return *std::static_pointer_cast<T>(m_Content).get();
|
||||
}
|
||||
|
||||
IncomingMessage(Type type, std::shared_ptr<void> content) :
|
||||
m_Type(type),
|
||||
m_Content(content)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
IncomingMessage(Type type) :
|
||||
m_Type(type)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
IncomingMessage() = default;
|
||||
virtual ~IncomingMessage() = default;
|
||||
|
||||
private:
|
||||
Type m_Type = Type::none;
|
||||
std::shared_ptr<void> m_Content;
|
||||
};
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "IncomingMessage.h"
|
||||
|
||||
namespace L2Bot::Domain::Serializers
|
||||
{
|
||||
class IncomingMessageFactoryInterface
|
||||
{
|
||||
public:
|
||||
virtual const IncomingMessage CreateMessage(std::wstring data) const = 0;
|
||||
};
|
||||
}
|
@ -5,15 +5,15 @@
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
class ChatMessageService
|
||||
class ChatMessageHandler
|
||||
{
|
||||
public:
|
||||
ChatMessageService(Repositories::ChatMessageRepositoryInterface& repository) : m_Repository(repository)
|
||||
ChatMessageHandler(Repositories::ChatMessageRepositoryInterface& repository) : m_Repository(repository)
|
||||
{
|
||||
|
||||
}
|
||||
ChatMessageService() = delete;
|
||||
virtual ~ChatMessageService() = default;
|
||||
ChatMessageHandler() = delete;
|
||||
virtual ~ChatMessageHandler() = default;
|
||||
|
||||
virtual const std::vector<ValueObjects::ChatMessage> GetMessages()
|
||||
{
|
@ -9,15 +9,15 @@
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
class EntityService
|
||||
class EntityHandler
|
||||
{
|
||||
public:
|
||||
EntityService(Repositories::EntityRepositoryInterface& repository) : m_Repository(repository)
|
||||
EntityHandler(Repositories::EntityRepositoryInterface& repository) : m_Repository(repository)
|
||||
{
|
||||
|
||||
}
|
||||
EntityService() = delete;
|
||||
virtual ~EntityService() = default;
|
||||
EntityHandler() = delete;
|
||||
virtual ~EntityHandler() = default;
|
||||
|
||||
virtual const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities()
|
||||
{
|
22
L2BotCore/Domain/Services/HeroServiceInterface.h
Normal file
22
L2BotCore/Domain/Services/HeroServiceInterface.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "../DTO/EntityState.h"
|
||||
#include "../ValueObjects/Vector3.h"
|
||||
|
||||
namespace L2Bot::Domain::Services
|
||||
{
|
||||
class HeroServiceInterface
|
||||
{
|
||||
public:
|
||||
virtual void Move(ValueObjects::Vector3 location) const = 0;
|
||||
virtual void AcquireTarget(int objectId) const = 0;
|
||||
virtual void Attack(int objectId) const = 0;
|
||||
virtual void Pickup(int objectId) const = 0;
|
||||
virtual void UseSkill(int skillId, bool isForced, bool isShiftPressed) const = 0;
|
||||
virtual void UseItem(int objectId) const = 0;
|
||||
virtual void ToggleAutouseSoulshot(int objectId) const = 0;
|
||||
virtual void Sit() const = 0;
|
||||
virtual void Stand() const = 0;
|
||||
};
|
||||
}
|
@ -175,7 +175,10 @@
|
||||
<ClInclude Include="Domain\Enums\ItemTypeEnum.h" />
|
||||
<ClInclude Include="Domain\Enums\WeaponTypeEnum.h" />
|
||||
<ClInclude Include="Domain\Repositories\ChatMessageRepositoryInterface.h" />
|
||||
<ClInclude Include="Domain\Services\ChatMessageService.h" />
|
||||
<ClInclude Include="Domain\Serializers\IncomingMessageFactoryInterface.h" />
|
||||
<ClInclude Include="Domain\Serializers\IncomingMessage.h" />
|
||||
<ClInclude Include="Domain\Services\ChatMessageHandler.h" />
|
||||
<ClInclude Include="Domain\Services\HeroServiceInterface.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\ChatMessage.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\Vector3.h" />
|
||||
<ClInclude Include="Domain\Enums\SpoilStateEnum.h" />
|
||||
@ -192,7 +195,7 @@
|
||||
<ClInclude Include="Domain\Serializers\Node.h" />
|
||||
<ClInclude Include="Domain\Serializers\Serializable.h" />
|
||||
<ClInclude Include="Domain\Serializers\SerializerInterface.h" />
|
||||
<ClInclude Include="Domain\Services\EntityService.h" />
|
||||
<ClInclude Include="Domain\Services\EntityHandler.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\ExperienceInfo.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\FullName.h" />
|
||||
<ClInclude Include="Domain\ValueObjects\InventoryInfo.h" />
|
||||
|
@ -72,7 +72,7 @@
|
||||
<ClInclude Include="Domain\ValueObjects\VitalStats.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Services\EntityService.h">
|
||||
<ClInclude Include="Domain\Services\EntityHandler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Repositories\EntityRepositoryInterface.h">
|
||||
@ -141,7 +141,7 @@
|
||||
<ClInclude Include="Domain\ValueObjects\ChatMessage.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Services\ChatMessageService.h">
|
||||
<ClInclude Include="Domain\Services\ChatMessageHandler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Repositories\ChatMessageRepositoryInterface.h">
|
||||
@ -150,6 +150,15 @@
|
||||
<ClInclude Include="Domain\DTO\Message.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Serializers\IncomingMessageFactoryInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Serializers\IncomingMessage.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Domain\Services\HeroServiceInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "Services/WorldHandler.h"
|
||||
#include "Serializers/JsonSerializer.h"
|
||||
#include "Serializers/JsonIncomingMessageFactory.h"
|
||||
#include "Transports/NamedPipeTransport.h"
|
||||
|
||||
#include "Versions/VersionAbstractFactory.h"
|
||||
@ -28,6 +29,8 @@ public:
|
||||
m_AbstractFactory.GetAbnormalEffectRepository(),
|
||||
m_AbstractFactory.GetChatMessageRepository(),
|
||||
m_Serializer,
|
||||
m_MessageFactory,
|
||||
m_AbstractFactory.GetHeroService(),
|
||||
m_Transport
|
||||
)
|
||||
{
|
||||
@ -60,6 +63,7 @@ private:
|
||||
const VersionAbstractFactory& m_AbstractFactory;
|
||||
WorldHandler m_WorldHandler;
|
||||
JsonSerializer m_Serializer;
|
||||
JsonIncomingMessageFactory m_MessageFactory;
|
||||
NamedPipeTransport m_Transport;
|
||||
|
||||
static const std::wstring PIPE_NAME;
|
||||
|
@ -184,9 +184,12 @@
|
||||
<ClInclude Include="Events\SkillUsedEvent.h" />
|
||||
<ClInclude Include="Events\SpoiledEvent.h" />
|
||||
<ClInclude Include="Application.h" />
|
||||
<ClInclude Include="Serializers\JsonIncomingMessageFactory.h" />
|
||||
<ClInclude Include="Serializers\JsonSerializer.h" />
|
||||
<ClInclude Include="Versions\Interlude\Services\HeroService.h" />
|
||||
<ClInclude Include="Services\WorldHandler.h" />
|
||||
<ClInclude Include="Services\EntityHandler.h" />
|
||||
<ClInclude Include="Services\EntityFinder.h" />
|
||||
<ClInclude Include="ThirdParty\json.hpp" />
|
||||
<ClInclude Include="Versions\GameStructs\FNameInterface.h" />
|
||||
<ClInclude Include="Versions\GameStructs\GameEngineInterface.h" />
|
||||
<ClInclude Include="Versions\GameStructs\L2GameDataInterface.h" />
|
||||
|
@ -126,7 +126,7 @@
|
||||
<ClInclude Include="Serializers\JsonSerializer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Services\EntityHandler.h">
|
||||
<ClInclude Include="Services\EntityFinder.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Factories\HeroFactory.h">
|
||||
@ -201,6 +201,15 @@
|
||||
<ClInclude Include="Events\OnEndItemListEvent.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ThirdParty\json.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Serializers\JsonIncomingMessageFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Versions\Interlude\Services\HeroService.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp">
|
||||
|
118
L2BotDll/Serializers/JsonIncomingMessageFactory.h
Normal file
118
L2BotDll/Serializers/JsonIncomingMessageFactory.h
Normal file
@ -0,0 +1,118 @@
|
||||
#pragma once
|
||||
|
||||
#include "Domain/Serializers/IncomingMessageFactoryInterface.h"
|
||||
#include "../ThirdParty/json.hpp"
|
||||
#include "Domain/ValueObjects/Vector3.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
using json = nlohmann::json;
|
||||
|
||||
class JsonIncomingMessageFactory : public Serializers::IncomingMessageFactoryInterface
|
||||
{
|
||||
public:
|
||||
JsonIncomingMessageFactory() = default;
|
||||
virtual ~JsonIncomingMessageFactory() = default;
|
||||
|
||||
const Serializers::IncomingMessage CreateMessage(std::wstring data) const override
|
||||
{
|
||||
try
|
||||
{
|
||||
auto jsonObject = json::parse(data);
|
||||
const auto type = jsonObject["Type"].get<std::string>();
|
||||
|
||||
return CreateConcreteMessage(type, jsonObject["Content"]);
|
||||
}
|
||||
catch (json::exception& e)
|
||||
{
|
||||
return Serializers::IncomingMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const Serializers::IncomingMessage CreateConcreteMessage(const std::string& type, const json& jsonObject) const
|
||||
{
|
||||
if (type == "Invalidate")
|
||||
{
|
||||
return Serializers::IncomingMessage
|
||||
{
|
||||
Serializers::IncomingMessage::Type::invalidate
|
||||
};
|
||||
}
|
||||
else if (type == "Move")
|
||||
{
|
||||
return Serializers::IncomingMessage
|
||||
{
|
||||
Serializers::IncomingMessage::Type::move,
|
||||
std::make_shared<ValueObjects::Vector3>(
|
||||
jsonObject["X"].get<float>(),
|
||||
jsonObject["Y"].get<float>(),
|
||||
jsonObject["Z"].get<float>()
|
||||
)
|
||||
};
|
||||
}
|
||||
else if (type == "AcquireTarget")
|
||||
{
|
||||
return Serializers::IncomingMessage
|
||||
{
|
||||
Serializers::IncomingMessage::Type::acquireTarget,
|
||||
std::make_shared<uint32_t>(jsonObject.get<uint32_t>())
|
||||
};
|
||||
}
|
||||
else if (type == "Attack")
|
||||
{
|
||||
return Serializers::IncomingMessage
|
||||
{
|
||||
Serializers::IncomingMessage::Type::attack,
|
||||
std::make_shared<uint32_t>(jsonObject.get<uint32_t>())
|
||||
};
|
||||
}
|
||||
else if (type == "Pickup")
|
||||
{
|
||||
return Serializers::IncomingMessage
|
||||
{
|
||||
Serializers::IncomingMessage::Type::pickup,
|
||||
std::make_shared<uint32_t>(jsonObject.get<uint32_t>())
|
||||
};
|
||||
}
|
||||
else if (type == "UseSkill")
|
||||
{
|
||||
return Serializers::IncomingMessage
|
||||
{
|
||||
Serializers::IncomingMessage::Type::useSkill,
|
||||
std::make_shared<uint32_t>(jsonObject.get<uint32_t>())
|
||||
};
|
||||
}
|
||||
else if (type == "UseItem")
|
||||
{
|
||||
return Serializers::IncomingMessage
|
||||
{
|
||||
Serializers::IncomingMessage::Type::useItem,
|
||||
std::make_shared<uint32_t>(jsonObject.get<uint32_t>())
|
||||
};
|
||||
}
|
||||
else if (type == "ToggleSoulshot")
|
||||
{
|
||||
return Serializers::IncomingMessage
|
||||
{
|
||||
Serializers::IncomingMessage::Type::toggleSoulshot,
|
||||
std::make_shared<uint32_t>(jsonObject.get<uint32_t>())
|
||||
};
|
||||
}
|
||||
else if (type == "Sit")
|
||||
{
|
||||
return Serializers::IncomingMessage
|
||||
{
|
||||
Serializers::IncomingMessage::Type::sit
|
||||
};
|
||||
}
|
||||
else if (type == "Stand")
|
||||
{
|
||||
return Serializers::IncomingMessage
|
||||
{
|
||||
Serializers::IncomingMessage::Type::stand
|
||||
};
|
||||
}
|
||||
|
||||
return Serializers::IncomingMessage();
|
||||
}
|
||||
};
|
@ -8,11 +8,11 @@
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
class EntityHandler
|
||||
class EntityFinder
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
const std::map<uint32_t, std::shared_ptr<DTO::EntityState>>& GetEntities(const std::map<uint32_t, T> items, std::function<std::unique_ptr<Entities::EntityInterface>(T)> callback)
|
||||
const std::map<uint32_t, std::shared_ptr<DTO::EntityState>>& FindEntities(const std::map<uint32_t, T> items, std::function<std::unique_ptr<Entities::EntityInterface>(T)> callback)
|
||||
{
|
||||
RemoveOutdatedStates();
|
||||
|
||||
@ -58,8 +58,8 @@ public:
|
||||
m_Objects.clear();
|
||||
}
|
||||
|
||||
EntityHandler() = default;
|
||||
virtual ~EntityHandler()
|
||||
EntityFinder() = default;
|
||||
virtual ~EntityFinder()
|
||||
{
|
||||
Reset();
|
||||
}
|
@ -4,9 +4,11 @@
|
||||
#include <thread>
|
||||
#include <memory>
|
||||
#include <Windows.h>
|
||||
#include "Domain/Services/EntityService.h"
|
||||
#include "Domain/Services/ChatMessageService.h"
|
||||
#include "Domain/Services/EntityHandler.h"
|
||||
#include "Domain/Services/ChatMessageHandler.h"
|
||||
#include "Domain/Services/HeroServiceInterface.h"
|
||||
#include "Domain/Serializers/SerializerInterface.h"
|
||||
#include "Domain/Serializers/IncomingMessageFactoryInterface.h"
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
#include "Domain/Transports/TransportInterface.h"
|
||||
#include "Domain/DTO/Message.h"
|
||||
@ -26,17 +28,21 @@ public:
|
||||
Repositories::EntityRepositoryInterface& abnormalEffectRepository,
|
||||
Repositories::ChatMessageRepositoryInterface& chatMessageRepository,
|
||||
const Serializers::SerializerInterface& serializer,
|
||||
const Serializers::IncomingMessageFactoryInterface& incomingMessageFactory,
|
||||
Services::HeroServiceInterface& heroService,
|
||||
Transports::TransportInterface& transport
|
||||
) :
|
||||
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_ItemService(Services::EntityService(itemRepository)),
|
||||
m_AbnormalEffectService(Services::EntityService(abnormalEffectRepository)),
|
||||
m_ChatMessageService(Services::ChatMessageService(chatMessageRepository)),
|
||||
m_HeroHandler(Services::EntityHandler(heroRepository)),
|
||||
m_DropHandler(Services::EntityHandler(dropRepository)),
|
||||
m_NPCHandler(Services::EntityHandler(npcRepository)),
|
||||
m_PlayerHandler(Services::EntityHandler(playerRepository)),
|
||||
m_SkillHandler(Services::EntityHandler(skillRepository)),
|
||||
m_ItemHandler(Services::EntityHandler(itemRepository)),
|
||||
m_AbnormalEffectHandler(Services::EntityHandler(abnormalEffectRepository)),
|
||||
m_ChatMessageHandler(Services::ChatMessageHandler(chatMessageRepository)),
|
||||
m_Serializer(serializer),
|
||||
m_IncomingMessageFactory(incomingMessageFactory),
|
||||
m_HeroService(heroService),
|
||||
m_Transport(transport)
|
||||
{
|
||||
|
||||
@ -98,10 +104,39 @@ private:
|
||||
{
|
||||
if (m_Transport.IsConnected())
|
||||
{
|
||||
const std::wstring& response = m_Transport.Receive();
|
||||
if (response == L"invalidate")
|
||||
const auto message = m_IncomingMessageFactory.CreateMessage(m_Transport.Receive());
|
||||
switch (message.GetType())
|
||||
{
|
||||
case Serializers::IncomingMessage::Type::invalidate:
|
||||
Invalidate();
|
||||
break;
|
||||
case Serializers::IncomingMessage::Type::move:
|
||||
m_HeroService.Move(message.GetRawContent<ValueObjects::Vector3>());
|
||||
break;
|
||||
case Serializers::IncomingMessage::Type::acquireTarget:
|
||||
m_HeroService.AcquireTarget(message.GetRawContent<uint32_t>());
|
||||
break;
|
||||
case Serializers::IncomingMessage::Type::attack:
|
||||
m_HeroService.Attack(message.GetRawContent<uint32_t>());
|
||||
break;
|
||||
case Serializers::IncomingMessage::Type::pickup:
|
||||
m_HeroService.Pickup(message.GetRawContent<uint32_t>());
|
||||
break;
|
||||
case Serializers::IncomingMessage::Type::useSkill:
|
||||
m_HeroService.UseSkill(message.GetRawContent<uint32_t>(), false, false);
|
||||
break;
|
||||
case Serializers::IncomingMessage::Type::useItem:
|
||||
m_HeroService.UseItem(message.GetRawContent<uint32_t>());
|
||||
break;
|
||||
case Serializers::IncomingMessage::Type::toggleSoulshot:
|
||||
m_HeroService.ToggleAutouseSoulshot(message.GetRawContent<uint32_t>());
|
||||
break;
|
||||
case Serializers::IncomingMessage::Type::sit:
|
||||
m_HeroService.Sit();
|
||||
break;
|
||||
case Serializers::IncomingMessage::Type::stand:
|
||||
m_HeroService.Stand();
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
@ -122,20 +157,20 @@ private:
|
||||
|
||||
const std::vector<std::vector<Serializers::Node>> GetData()
|
||||
{
|
||||
std::map<std::wstring, Services::EntityService> services
|
||||
std::map<std::wstring, Services::EntityHandler> handlers
|
||||
{
|
||||
{L"hero", m_HeroService},
|
||||
{L"drop", m_DropService},
|
||||
{L"npc", m_NPCService},
|
||||
{L"player", m_PlayerService},
|
||||
{L"skill", m_SkillService},
|
||||
{L"item", m_ItemService},
|
||||
{L"abnormalEffect", m_AbnormalEffectService}
|
||||
{L"hero", m_HeroHandler},
|
||||
{L"drop", m_DropHandler},
|
||||
{L"npc", m_NPCHandler},
|
||||
{L"player", m_PlayerHandler},
|
||||
{L"skill", m_SkillHandler},
|
||||
{L"item", m_ItemHandler},
|
||||
{L"abnormalEffect", m_AbnormalEffectHandler}
|
||||
};
|
||||
|
||||
std::vector<std::vector<Serializers::Node>> result;
|
||||
|
||||
for (auto& kvp : services)
|
||||
for (auto& kvp : handlers)
|
||||
{
|
||||
for (const auto& entity : kvp.second.GetEntities())
|
||||
{
|
||||
@ -146,7 +181,7 @@ private:
|
||||
}
|
||||
};
|
||||
}
|
||||
for (const auto& chatMessage : m_ChatMessageService.GetMessages())
|
||||
for (const auto& chatMessage : m_ChatMessageHandler.GetMessages())
|
||||
{
|
||||
const auto message = DTO::Message{ L"chat", Enums::EntityStateEnum::created, chatMessage };
|
||||
result.push_back(message.BuildSerializationNodes());
|
||||
@ -157,25 +192,27 @@ private:
|
||||
|
||||
void Invalidate()
|
||||
{
|
||||
m_DropService.Invalidate();
|
||||
m_HeroService.Invalidate();
|
||||
m_NPCService.Invalidate();
|
||||
m_PlayerService.Invalidate();
|
||||
m_SkillService.Invalidate();
|
||||
m_ItemService.Invalidate();
|
||||
m_AbnormalEffectService.Invalidate();
|
||||
m_DropHandler.Invalidate();
|
||||
m_HeroHandler.Invalidate();
|
||||
m_NPCHandler.Invalidate();
|
||||
m_PlayerHandler.Invalidate();
|
||||
m_SkillHandler.Invalidate();
|
||||
m_ItemHandler.Invalidate();
|
||||
m_AbnormalEffectHandler.Invalidate();
|
||||
}
|
||||
|
||||
private:
|
||||
Services::EntityService m_DropService;
|
||||
Services::EntityService m_HeroService;
|
||||
Services::EntityService m_NPCService;
|
||||
Services::EntityService m_PlayerService;
|
||||
Services::EntityService m_SkillService;
|
||||
Services::EntityService m_ItemService;
|
||||
Services::EntityService m_AbnormalEffectService;
|
||||
Services::ChatMessageService m_ChatMessageService;
|
||||
Services::EntityHandler m_DropHandler;
|
||||
Services::EntityHandler m_HeroHandler;
|
||||
Services::EntityHandler m_NPCHandler;
|
||||
Services::EntityHandler m_PlayerHandler;
|
||||
Services::EntityHandler m_SkillHandler;
|
||||
Services::EntityHandler m_ItemHandler;
|
||||
Services::EntityHandler m_AbnormalEffectHandler;
|
||||
Services::ChatMessageHandler m_ChatMessageHandler;
|
||||
const Serializers::SerializerInterface& m_Serializer;
|
||||
const Serializers::IncomingMessageFactoryInterface& m_IncomingMessageFactory;
|
||||
Services::HeroServiceInterface& m_HeroService;
|
||||
Transports::TransportInterface& m_Transport;
|
||||
bool m_Stopped = false;
|
||||
std::thread m_ConnectingThread;
|
||||
|
24639
L2BotDll/ThirdParty/json.hpp
vendored
Normal file
24639
L2BotDll/ThirdParty/json.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -17,11 +17,12 @@
|
||||
#include "Repositories/ItemRepository.h"
|
||||
#include "Repositories/AbnormalEffectRepository.h"
|
||||
#include "Repositories/ChatMessageRepository.h"
|
||||
#include "Services/HeroService.h"
|
||||
#include "GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "GameStructs/GameEngineWrapper.h"
|
||||
#include "GameStructs/L2GameDataWrapper.h"
|
||||
#include "GameStructs/FName.h"
|
||||
#include "../../Services/EntityHandler.h"
|
||||
#include "../../Services/EntityFinder.h"
|
||||
#include "Helpers/EnchantHelper.h"
|
||||
|
||||
namespace Interlude
|
||||
@ -40,22 +41,22 @@ namespace Interlude
|
||||
HeroRepository& GetHeroRepository() const override
|
||||
{
|
||||
static auto factory = HeroFactory();
|
||||
static EntityHandler handler;
|
||||
static EntityFinder finder;
|
||||
static auto result = HeroRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
handler
|
||||
finder
|
||||
);
|
||||
return result;
|
||||
}
|
||||
DropRepository& GetDropRepository() const override
|
||||
{
|
||||
static auto factory = DropFactory(GetL2GameData(), GetFName());
|
||||
static EntityHandler handler;
|
||||
static EntityFinder finder;
|
||||
static auto result = DropRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
handler,
|
||||
finder,
|
||||
m_Radius
|
||||
);
|
||||
return result;
|
||||
@ -63,11 +64,11 @@ namespace Interlude
|
||||
NPCRepository& GetNPCRepository() const override
|
||||
{
|
||||
static auto factory = NPCFactory();
|
||||
static EntityHandler handler;
|
||||
static EntityFinder finder;
|
||||
static auto result = NPCRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
handler,
|
||||
finder,
|
||||
m_Radius
|
||||
);
|
||||
return result;
|
||||
@ -75,11 +76,11 @@ namespace Interlude
|
||||
PlayerRepository& GetPlayerRepository() const override
|
||||
{
|
||||
static auto factory = PlayerFactory();
|
||||
static EntityHandler handler;
|
||||
static EntityFinder finder;
|
||||
static auto result = PlayerRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
handler,
|
||||
finder,
|
||||
m_Radius
|
||||
);
|
||||
return result;
|
||||
@ -87,11 +88,11 @@ namespace Interlude
|
||||
SkillRepository& GetSkillRepository() const override
|
||||
{
|
||||
static auto factory = SkillFactory(GetL2GameData(), GetFName());
|
||||
static EntityHandler handler;
|
||||
static EntityFinder finder;
|
||||
static auto result = SkillRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
handler
|
||||
finder
|
||||
);
|
||||
return result;
|
||||
}
|
||||
@ -99,21 +100,21 @@ namespace Interlude
|
||||
{
|
||||
static EnchantHelper enchantHelper;
|
||||
static auto factory = ItemFactory(GetL2GameData(), GetFName(), enchantHelper);
|
||||
static EntityHandler handler;
|
||||
static EntityFinder finder;
|
||||
static auto result = ItemRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
handler
|
||||
finder
|
||||
);
|
||||
return result;
|
||||
}
|
||||
AbnormalEffectRepository& GetAbnormalEffectRepository() const override
|
||||
{
|
||||
static auto factory = AbnormalEffectFactory(GetL2GameData(), GetFName());
|
||||
static EntityHandler handler;
|
||||
static EntityFinder finder;
|
||||
static auto result = AbnormalEffectRepository(
|
||||
factory,
|
||||
handler
|
||||
finder
|
||||
);
|
||||
return result;
|
||||
}
|
||||
@ -125,6 +126,15 @@ namespace Interlude
|
||||
);
|
||||
return result;
|
||||
}
|
||||
Services::HeroServiceInterface& GetHeroService() const override
|
||||
{
|
||||
static auto result = HeroService(
|
||||
GetNetworkHandler(),
|
||||
GetItemRepository(),
|
||||
GetL2GameData()
|
||||
);
|
||||
return result;
|
||||
}
|
||||
NetworkHandlerWrapper& GetNetworkHandler() const override
|
||||
{
|
||||
static NetworkHandlerWrapper result;
|
||||
|
@ -14,7 +14,15 @@ namespace Interlude
|
||||
Item* (__thiscall* NetworkHandlerWrapper::__GetNextItem)(NetworkHandler*, float, int) = 0;
|
||||
User* (__thiscall* NetworkHandlerWrapper::__GetNextCreature)(NetworkHandler*, float, int) = 0;
|
||||
int(__thiscall* NetworkHandlerWrapper::__AddNetworkQueue)(NetworkHandler*, L2::NetworkPacket*) = 0;
|
||||
int(__thiscall* NetworkHandlerWrapper::__RequestItemList)(NetworkHandler*);
|
||||
int(__thiscall* NetworkHandlerWrapper::__RequestItemList)(NetworkHandler*) = 0;
|
||||
User* (__thiscall* NetworkHandlerWrapper::__GetUser)(NetworkHandler*, int) = 0;
|
||||
Item* (__thiscall* NetworkHandlerWrapper::__GetItem)(NetworkHandler*, int) = 0;
|
||||
void(__thiscall* NetworkHandlerWrapper::__Action)(NetworkHandler*, int, L2::FVector, int) = 0;
|
||||
void(__thiscall* NetworkHandlerWrapper::__MTL)(NetworkHandler*, APawn*, L2::FVector, L2::FVector, void*, int) = 0;
|
||||
void(__thiscall* NetworkHandlerWrapper::__RequestMagicSkillUse)(NetworkHandler*, L2ParamStack&) = 0;
|
||||
int(__thiscall* NetworkHandlerWrapper::__RequestUseItem)(NetworkHandler*, L2ParamStack&) = 0;
|
||||
void(__thiscall* NetworkHandlerWrapper::__RequestAutoSoulShot)(NetworkHandler*, L2ParamStack&) = 0;
|
||||
void(__thiscall* NetworkHandlerWrapper::__ChangeWaitType)(NetworkHandler*, int) = 0;
|
||||
|
||||
//todo exception
|
||||
Item* NetworkHandlerWrapper::GetNextItem(float_t radius, int prevId) const
|
||||
@ -51,6 +59,65 @@ namespace Interlude
|
||||
return 0;
|
||||
}
|
||||
|
||||
User* NetworkHandlerWrapper::GetUser(int objectId) const
|
||||
{
|
||||
if (__GetUser && _target) {
|
||||
return (*__GetUser)(_target, objectId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Item* NetworkHandlerWrapper::GetItem(int objectId) const
|
||||
{
|
||||
if (__GetItem && _target) {
|
||||
return (*__GetItem)(_target, objectId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void NetworkHandlerWrapper::MTL(APawn* self, L2::FVector dst, L2::FVector src, void* terrainInfo, int unk1) const
|
||||
{
|
||||
if (__MTL && _target) {
|
||||
(*__MTL)(_target, self, dst, src, terrainInfo, unk1);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkHandlerWrapper::Action(int objectId, L2::FVector objectLocation, int unk) const
|
||||
{
|
||||
if (__Action && _target) {
|
||||
(*__Action)(_target, objectId, objectLocation, unk);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkHandlerWrapper::RequestMagicSkillUse(L2ParamStack& stack) const
|
||||
{
|
||||
if (__RequestMagicSkillUse && _target) {
|
||||
(*__RequestMagicSkillUse)(_target, stack);
|
||||
}
|
||||
}
|
||||
|
||||
int NetworkHandlerWrapper::RequestUseItem(L2ParamStack& stack) const
|
||||
{
|
||||
if (__RequestUseItem && _target) {
|
||||
return (*__RequestUseItem)(_target, stack);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void NetworkHandlerWrapper::RequestAutoSoulShot(L2ParamStack& stack) const
|
||||
{
|
||||
if (__RequestAutoSoulShot && _target) {
|
||||
(*__RequestAutoSoulShot)(_target, stack);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkHandlerWrapper::ChangeWaitType(int type) const
|
||||
{
|
||||
if (__ChangeWaitType && _target) {
|
||||
(*__ChangeWaitType)(_target, type);
|
||||
}
|
||||
}
|
||||
|
||||
int NetworkHandlerWrapper::RequestItemList() const
|
||||
{
|
||||
if (__RequestItemList && _target) {
|
||||
@ -68,7 +135,13 @@ namespace Interlude
|
||||
(FARPROC&)__GetNextItem = GetProcAddress(hModule, "?GetNextItem@UNetworkHandler@@UAEPAUItem@@MH@Z");
|
||||
(FARPROC&)__GetNextCreature = GetProcAddress(hModule, "?GetNextCreature@UNetworkHandler@@UAEPAUUser@@MH@Z");
|
||||
(FARPROC&)__RequestItemList = GetProcAddress(hModule, "?RequestItemList@UNetworkHandler@@UAEHXZ");
|
||||
|
||||
(FARPROC&)__GetUser = GetProcAddress(hModule, "?GetUser@UNetworkHandler@@UAEPAUUser@@H@Z");
|
||||
(FARPROC&)__MTL = GetProcAddress(hModule, "?MTL@UNetworkHandler@@UAEXPAVAActor@@VFVector@@10H@Z");
|
||||
(FARPROC&)__Action = GetProcAddress(hModule, "?Action@UNetworkHandler@@UAEXHVFVector@@H@Z");
|
||||
(FARPROC&)__RequestMagicSkillUse = GetProcAddress(hModule, "?RequestMagicSkillUse@UNetworkHandler@@UAEXAAVL2ParamStack@@@Z");
|
||||
(FARPROC&)__RequestUseItem = GetProcAddress(hModule, "?RequestUseItem@UNetworkHandler@@UAEHAAVL2ParamStack@@@Z");
|
||||
(FARPROC&)__RequestAutoSoulShot = GetProcAddress(hModule, "?RequestAutoSoulShot@UNetworkHandler@@UAEXAAVL2ParamStack@@@Z");
|
||||
(FARPROC&)__ChangeWaitType = GetProcAddress(hModule, "?ChangeWaitType@UNetworkHandler@@UAEXH@Z");
|
||||
|
||||
(FARPROC&)__AddNetworkQueue = (FARPROC)splice(
|
||||
GetProcAddress(hModule, "?AddNetworkQueue@UNetworkHandler@@UAEHPAUNetworkPacket@@@Z"), __AddNetworkQueue_hook
|
||||
|
@ -22,7 +22,15 @@ namespace Interlude
|
||||
Item* GetNextItem(float_t radius, int prevId) const;
|
||||
User* GetNextCreature(float_t radius, int prevId) const;
|
||||
User* GetHero() const;
|
||||
User* GetUser(int objectId) const;
|
||||
Item* GetItem(int objectId) const;
|
||||
int RequestItemList() const;
|
||||
void MTL(APawn* self, L2::FVector dst, L2::FVector src, void* terrainInfo, int unk1) const;
|
||||
void Action(int objectId, L2::FVector objectLocation, int unk) const;
|
||||
void RequestMagicSkillUse(L2ParamStack& stack) const;
|
||||
int RequestUseItem(L2ParamStack& stack) const;
|
||||
void RequestAutoSoulShot(L2ParamStack& stack) const;
|
||||
void ChangeWaitType(int type) const;
|
||||
private:
|
||||
|
||||
static void __fastcall __Init_hook(NetworkHandler* This, int /*edx*/, float unk);
|
||||
@ -33,6 +41,18 @@ namespace Interlude
|
||||
static User* (__thiscall* __GetNextCreature)(NetworkHandler*, float, int);
|
||||
static int(__thiscall* __AddNetworkQueue)(NetworkHandler*, L2::NetworkPacket*);
|
||||
static int(__thiscall* __RequestItemList)(NetworkHandler*);
|
||||
static User* (__thiscall* __GetUser)(NetworkHandler*, int);
|
||||
static Item* (__thiscall* __GetItem)(NetworkHandler*, int);
|
||||
static void(__thiscall* __MTL)(NetworkHandler*, APawn*, L2::FVector, L2::FVector, void*, int);
|
||||
static void(__thiscall* __Action)(NetworkHandler*, int, L2::FVector, int);
|
||||
//stack skillId, isForce, isShiftPressed
|
||||
static void(__thiscall* __RequestMagicSkillUse)(NetworkHandler*, L2ParamStack&);
|
||||
static int(__thiscall* __RequestUseItem)(NetworkHandler*, L2ParamStack&);
|
||||
//stack itemId, on/off
|
||||
static void(__thiscall* __RequestAutoSoulShot)(NetworkHandler*, L2ParamStack&);
|
||||
//params objectId, unk
|
||||
static void(__thiscall* __ChangeWaitType)(NetworkHandler*, int);
|
||||
|
||||
private:
|
||||
static void* originalInitAddress;
|
||||
static NetworkHandler* _target;
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "../../../Events/HeroDeletedEvent.h"
|
||||
#include "../../../Events/EventDispatcher.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Services/EntityHandler.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -28,7 +28,7 @@ namespace Interlude
|
||||
skillPtrs[kvp.first] = kvp.second.get();
|
||||
}
|
||||
|
||||
const auto objects = m_EntityHandler.GetEntities<Entities::AbnormalEffect*>(skillPtrs, [this](Entities::AbnormalEffect* item) {
|
||||
const auto objects = m_EntityFinder.FindEntities<Entities::AbnormalEffect*>(skillPtrs, [this](Entities::AbnormalEffect* item) {
|
||||
return std::make_unique<Entities::AbnormalEffect>(item);
|
||||
});
|
||||
|
||||
@ -42,9 +42,9 @@ namespace Interlude
|
||||
return result;
|
||||
}
|
||||
|
||||
AbnormalEffectRepository(const AbnormalEffectFactory& factory, EntityHandler& handler) :
|
||||
AbnormalEffectRepository(const AbnormalEffectFactory& factory, EntityFinder& finder) :
|
||||
m_Factory(factory),
|
||||
m_EntityHandler(handler)
|
||||
m_EntityFinder(finder)
|
||||
{
|
||||
EventDispatcher::GetInstance().Subscribe(AbnormalEffectChangedEvent::name, [this](const Event& evt) {
|
||||
OnEffectToggled(evt);
|
||||
@ -115,6 +115,6 @@ namespace Interlude
|
||||
const AbnormalEffectFactory& m_Factory;
|
||||
std::map<uint32_t, std::unique_ptr<Entities::AbnormalEffect>> m_Effects;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
EntityHandler& m_EntityHandler;
|
||||
EntityFinder& m_EntityFinder;
|
||||
};
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
#include "../Factories/DropFactory.h"
|
||||
#include "../../GameStructs/FindObjectsTrait.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Services/EntityHandler.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -24,7 +24,7 @@ namespace Interlude
|
||||
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) {
|
||||
const auto objects = m_EntityFinder.FindEntities<Item*>(items, [this](Item* item) {
|
||||
return m_Factory.Create(item);
|
||||
});
|
||||
|
||||
@ -41,14 +41,14 @@ namespace Interlude
|
||||
void Reset() override
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
m_Container.Reset();
|
||||
m_EntityFinder.Reset();
|
||||
}
|
||||
|
||||
DropRepository(const NetworkHandlerWrapper& networkHandler, const DropFactory& factory, EntityHandler& handler, const uint16_t radius) :
|
||||
DropRepository(const NetworkHandlerWrapper& networkHandler, const DropFactory& factory, EntityFinder& finder, const uint16_t radius) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_Radius(radius),
|
||||
m_Container(handler)
|
||||
m_EntityFinder(finder)
|
||||
{
|
||||
|
||||
}
|
||||
@ -60,7 +60,7 @@ namespace Interlude
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
const DropFactory& m_Factory;
|
||||
const uint16_t m_Radius;
|
||||
EntityHandler& m_Container;
|
||||
EntityFinder& m_EntityFinder;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
};
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "../../../Events/HeroCreatedEvent.h"
|
||||
#include "../../../Events/HeroDeletedEvent.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Services/EntityHandler.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -39,7 +39,7 @@ namespace Interlude
|
||||
items.emplace(hero->objectId, hero);
|
||||
}
|
||||
|
||||
const auto objects = m_EntityHandler.GetEntities<User*>(items, [this](User* item) {
|
||||
const auto objects = m_EntityFinder.FindEntities<User*>(items, [this](User* item) {
|
||||
return m_Factory.Create(item);
|
||||
});
|
||||
|
||||
@ -56,13 +56,13 @@ namespace Interlude
|
||||
void Reset() override
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
m_EntityHandler.Reset();
|
||||
m_EntityFinder.Reset();
|
||||
}
|
||||
|
||||
HeroRepository(const NetworkHandlerWrapper& networkHandler, const HeroFactory& factory, EntityHandler& handler) :
|
||||
HeroRepository(const NetworkHandlerWrapper& networkHandler, const HeroFactory& factory, EntityFinder& finder) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_EntityHandler(handler)
|
||||
m_EntityFinder(finder)
|
||||
{
|
||||
|
||||
}
|
||||
@ -74,7 +74,7 @@ namespace Interlude
|
||||
const HeroFactory& m_Factory;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
User* m_PrevHero = nullptr;
|
||||
EntityHandler& m_EntityHandler;
|
||||
EntityFinder& m_EntityFinder;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
};
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
#include "../Factories/ItemFactory.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Services/EntityHandler.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
#include "../../../Events/ItemCreatedEvent.h"
|
||||
#include "../../../Events/ItemUpdatedEvent.h"
|
||||
#include "../../../Events/ItemDeletedEvent.h"
|
||||
@ -32,7 +32,7 @@ namespace Interlude
|
||||
itemPtrs[kvp.first] = kvp.second.get();
|
||||
}
|
||||
|
||||
const auto objects = m_EntityHandler.GetEntities<Entities::BaseItem*>(itemPtrs, [this](Entities::BaseItem* item) {
|
||||
const auto objects = m_EntityFinder.FindEntities<Entities::BaseItem*>(itemPtrs, [this](Entities::BaseItem* item) {
|
||||
return m_Factory.CreateFromPointer(item);
|
||||
});
|
||||
|
||||
@ -46,10 +46,19 @@ namespace Interlude
|
||||
return result;
|
||||
}
|
||||
|
||||
ItemRepository(const NetworkHandlerWrapper& networkHandler, const ItemFactory& factory, EntityHandler& handler) :
|
||||
const Entities::BaseItem& GetItem(uint32_t objectId) const
|
||||
{
|
||||
if (m_Items.find(objectId) != m_Items.end())
|
||||
{
|
||||
return m_Items.at(objectId).get();
|
||||
}
|
||||
return Entities::BaseItem();
|
||||
}
|
||||
|
||||
ItemRepository(const NetworkHandlerWrapper& networkHandler, const ItemFactory& factory, EntityFinder& finder) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_EntityHandler(handler)
|
||||
m_EntityFinder(finder)
|
||||
{
|
||||
EventDispatcher::GetInstance().Subscribe(ItemCreatedEvent::name, [this](const Event& evt) {
|
||||
OnItemCreated(evt);
|
||||
@ -208,6 +217,6 @@ namespace Interlude
|
||||
uint32_t m_UsedSkillId = 0;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
EntityHandler& m_EntityHandler;
|
||||
EntityFinder& m_EntityFinder;
|
||||
};
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
#include "../../../Events/SpoiledEvent.h"
|
||||
#include "../../../Events/CreatureDiedEvent.h"
|
||||
#include "../../GameStructs/FindObjectsTrait.h"
|
||||
#include "../../../Services/EntityHandler.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -35,7 +35,7 @@ namespace Interlude
|
||||
}
|
||||
}
|
||||
|
||||
const auto objects = m_EntityHandler.GetEntities<User*>(items, [this](User* item) {
|
||||
const auto objects = m_EntityFinder.FindEntities<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);
|
||||
});
|
||||
@ -53,14 +53,14 @@ namespace Interlude
|
||||
void Reset() override
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
m_EntityHandler.Reset();
|
||||
m_EntityFinder.Reset();
|
||||
}
|
||||
|
||||
NPCRepository(const NetworkHandlerWrapper& networkHandler, const NPCFactory& factory, EntityHandler& handler, const uint16_t radius) :
|
||||
NPCRepository(const NetworkHandlerWrapper& networkHandler, const NPCFactory& factory, EntityFinder& finder, const uint16_t radius) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_Radius(radius),
|
||||
m_EntityHandler(handler)
|
||||
m_EntityFinder(finder)
|
||||
{
|
||||
EventDispatcher::GetInstance().Subscribe(SpoiledEvent::name, [this](const Event& evt) {
|
||||
OnSpoiled(evt);
|
||||
@ -115,7 +115,7 @@ namespace Interlude
|
||||
std::map<uint32_t, Enums::SpoilStateEnum> m_Spoiled;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
const uint16_t m_Radius = 0;
|
||||
EntityHandler& m_EntityHandler;
|
||||
EntityFinder& m_EntityFinder;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
};
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
#include "../Factories/PlayerFactory.h"
|
||||
#include "../../GameStructs/FindObjectsTrait.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Services/EntityHandler.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -31,7 +31,7 @@ namespace Interlude
|
||||
}
|
||||
}
|
||||
|
||||
const auto objects = m_EntityHandler.GetEntities<User*>(items, [this](User* item) {
|
||||
const auto objects = m_EntityFinder.FindEntities<User*>(items, [this](User* item) {
|
||||
return m_Factory.Create(item);
|
||||
});
|
||||
|
||||
@ -48,14 +48,14 @@ namespace Interlude
|
||||
void Reset() override
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
m_EntityHandler.Reset();
|
||||
m_EntityFinder.Reset();
|
||||
}
|
||||
|
||||
PlayerRepository(const NetworkHandlerWrapper& networkHandler, const PlayerFactory& factory, EntityHandler& handler, const uint16_t radius) :
|
||||
PlayerRepository(const NetworkHandlerWrapper& networkHandler, const PlayerFactory& factory, EntityFinder& finder, const uint16_t radius) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_Radius(radius),
|
||||
m_EntityHandler(handler)
|
||||
m_EntityFinder(finder)
|
||||
{
|
||||
|
||||
}
|
||||
@ -67,7 +67,7 @@ namespace Interlude
|
||||
const PlayerFactory& m_Factory;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
const uint16_t m_Radius;
|
||||
EntityHandler& m_EntityHandler;
|
||||
EntityFinder& m_EntityFinder;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
};
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
#include "../../../Events/EventDispatcher.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Common/TimerMap.h"
|
||||
#include "../../../Services/EntityHandler.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -33,7 +33,7 @@ namespace Interlude
|
||||
skillPtrs[kvp.first] = kvp.second.get();
|
||||
}
|
||||
|
||||
const auto objects = m_EntityHandler.GetEntities<Entities::Skill*>(skillPtrs, [this](Entities::Skill* item) {
|
||||
const auto objects = m_EntityFinder.FindEntities<Entities::Skill*>(skillPtrs, [this](Entities::Skill* item) {
|
||||
return std::make_unique<Entities::Skill>(item);
|
||||
});
|
||||
|
||||
@ -47,10 +47,10 @@ namespace Interlude
|
||||
return result;
|
||||
}
|
||||
|
||||
SkillRepository(const NetworkHandlerWrapper& networkHandler, const SkillFactory& factory, EntityHandler& handler) :
|
||||
SkillRepository(const NetworkHandlerWrapper& networkHandler, const SkillFactory& factory, EntityFinder& finder) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_EntityHandler(handler)
|
||||
m_EntityFinder(finder)
|
||||
{
|
||||
EventDispatcher::GetInstance().Subscribe(SkillCreatedEvent::name, [this](const Event& evt) {
|
||||
OnSkillCreated(evt);
|
||||
@ -253,6 +253,6 @@ namespace Interlude
|
||||
TimerMap m_ReloadingTimers;
|
||||
TimerMap m_CastingTimers;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
EntityHandler& m_EntityHandler;
|
||||
EntityFinder& m_EntityFinder;
|
||||
};
|
||||
}
|
132
L2BotDll/Versions/Interlude/Services/HeroService.h
Normal file
132
L2BotDll/Versions/Interlude/Services/HeroService.h
Normal file
@ -0,0 +1,132 @@
|
||||
#pragma once
|
||||
|
||||
#include "Domain/Services/HeroServiceInterface.h"
|
||||
#include "../Repositories/ItemRepository.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../GameStructs/L2GameDataWrapper.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
class HeroService : public Services::HeroServiceInterface
|
||||
{
|
||||
public:
|
||||
HeroService(const NetworkHandlerWrapper& networkHandler, const ItemRepository& itemRespository, const L2GameDataWrapper& l2GameData) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_ItemRespository(itemRespository),
|
||||
m_L2GameData(l2GameData)
|
||||
{
|
||||
|
||||
}
|
||||
HeroService() = delete;
|
||||
virtual ~HeroService() = default;
|
||||
|
||||
void Move(ValueObjects::Vector3 location) const override
|
||||
{
|
||||
auto hero = m_NetworkHandler.GetHero();
|
||||
|
||||
if (hero) {
|
||||
m_NetworkHandler.MTL(
|
||||
hero->pawn,
|
||||
{ location.GetX(), location.GetY(), location.GetZ() },
|
||||
hero->pawn->Location,
|
||||
hero->pawn->terrainInfo,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void AcquireTarget(int objectId) const override
|
||||
{
|
||||
auto target = m_NetworkHandler.GetUser(objectId);
|
||||
|
||||
if (target) {
|
||||
if (target->objectId == objectId) {
|
||||
auto hero = m_NetworkHandler.GetHero();
|
||||
// Reset target
|
||||
if (hero)
|
||||
{
|
||||
m_NetworkHandler.Action(hero->objectId, hero->pawn->Location, 0);
|
||||
}
|
||||
}
|
||||
m_NetworkHandler.Action(objectId, target->pawn->Location, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Attack(int objectId) const override
|
||||
{
|
||||
auto target = m_NetworkHandler.GetUser(objectId);
|
||||
|
||||
if (target) {
|
||||
// Acquire target
|
||||
m_NetworkHandler.Action(objectId, target->pawn->Location, 0);
|
||||
// Attack
|
||||
m_NetworkHandler.Action(objectId, target->pawn->Location, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Pickup(int objectId) const override
|
||||
{
|
||||
auto target = m_NetworkHandler.GetItem(objectId);
|
||||
|
||||
if (target) {
|
||||
m_NetworkHandler.Action(objectId, target->pawn->Location, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void UseSkill(int skillId, bool isForced, bool isShiftPressed) const override
|
||||
{
|
||||
L2ParamStack* stack = new L2ParamStack(3);
|
||||
stack->PushBack((void*)skillId);
|
||||
stack->PushBack((void*)(isForced ? 1 : 0));
|
||||
stack->PushBack((void*)(isShiftPressed ? 1 : 0));
|
||||
|
||||
m_NetworkHandler.RequestMagicSkillUse(*stack);
|
||||
|
||||
delete stack;
|
||||
}
|
||||
|
||||
void UseItem(int objectId) const override
|
||||
{
|
||||
L2ParamStack* stack = new L2ParamStack(1);
|
||||
stack->PushBack((void*)objectId);
|
||||
|
||||
m_NetworkHandler.RequestUseItem(*stack);
|
||||
|
||||
delete stack;
|
||||
}
|
||||
|
||||
void ToggleAutouseSoulshot(int objectId) const override
|
||||
{
|
||||
const auto item = m_ItemRespository.GetItem(objectId);
|
||||
if (item.GetId())
|
||||
{
|
||||
const auto etcItem = static_cast<const Entities::EtcItem&>(item);
|
||||
|
||||
L2ParamStack* stack = new L2ParamStack(2);
|
||||
stack->PushBack((void*)etcItem.GetItemId());
|
||||
stack->PushBack((void*)(etcItem.IsAutoused() ? 0 : 1));
|
||||
|
||||
m_NetworkHandler.RequestAutoSoulShot(*stack);
|
||||
|
||||
delete stack;
|
||||
}
|
||||
}
|
||||
|
||||
void Sit() const override
|
||||
{
|
||||
m_NetworkHandler.ChangeWaitType(0);
|
||||
}
|
||||
|
||||
void Stand() const override
|
||||
{
|
||||
m_NetworkHandler.ChangeWaitType(1);
|
||||
}
|
||||
|
||||
private:
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
const ItemRepository& m_ItemRespository;
|
||||
const L2GameDataWrapper& m_L2GameData;
|
||||
};
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
#include "Domain/Repositories/ChatMessageRepositoryInterface.h"
|
||||
#include "Domain/Services/HeroServiceInterface.h"
|
||||
#include "GameStructs/NetworkHandlerInterface.h"
|
||||
#include "GameStructs/GameEngineInterface.h"
|
||||
#include "GameStructs/L2GameDataInterface.h"
|
||||
@ -25,6 +26,7 @@ public:
|
||||
virtual Repositories::EntityRepositoryInterface& GetItemRepository() const = 0;
|
||||
virtual Repositories::EntityRepositoryInterface& GetAbnormalEffectRepository() const = 0;
|
||||
virtual Repositories::ChatMessageRepositoryInterface& GetChatMessageRepository() const = 0;
|
||||
virtual Services::HeroServiceInterface& GetHeroService() const = 0;
|
||||
virtual NetworkHandlerInterface& GetNetworkHandler() const = 0;
|
||||
virtual GameEngineInterface& GetGameEngine() const = 0;
|
||||
virtual L2GameDataInterface& GetL2GameData() const = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user