Add project files.
This commit is contained in:
48
L2BotDll/Versions/Interlude/Repositories/DropRepository.h
Normal file
48
L2BotDll/Versions/Interlude/Repositories/DropRepository.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include "Domain/Repositories/DropRepositoryInterface.h"
|
||||
#include "../Factories/DropFactory.h"
|
||||
#include "../../GameStructs/FindObjectsTrait.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
class DropRepository : public Repositories::DropRepositoryInterface, public FindObjectsTrait
|
||||
{
|
||||
public:
|
||||
const std::map<uint32_t, DTO::Drop> GetObjects() override
|
||||
{
|
||||
const auto items = GetAllObjects<Item*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
return m_NetworkHandler.GetNextItem(radius, prevId);
|
||||
});
|
||||
|
||||
std::map<uint32_t, DTO::Drop> map;
|
||||
|
||||
for (const auto& kvp : items)
|
||||
{
|
||||
const auto item = kvp.second;
|
||||
map.emplace(item->objectId, m_Factory.Create(item));
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
DropRepository(const NetworkHandlerWrapper& networkHandler, const DropFactory& factory, const uint16_t radius) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_Radius(radius)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DropRepository() = delete;
|
||||
virtual ~DropRepository() = default;
|
||||
|
||||
private:
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
const DropFactory& m_Factory;
|
||||
const uint16_t m_Radius;
|
||||
};
|
||||
}
|
54
L2BotDll/Versions/Interlude/Repositories/HeroRepository.h
Normal file
54
L2BotDll/Versions/Interlude/Repositories/HeroRepository.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include "Domain/Repositories/HeroRepositoryInterface.h"
|
||||
#include "../Factories/HeroFactory.h"
|
||||
#include "../../../Events/EventDispatcher.h"
|
||||
#include "../../../Events/HeroCreatedEvent.h"
|
||||
#include "../../../Events/HeroDeletedEvent.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
class HeroRepository : public Repositories::HeroRepositoryInterface
|
||||
{
|
||||
public:
|
||||
const std::map<uint32_t, DTO::Hero> GetObjects() override
|
||||
{
|
||||
std::map<uint32_t, DTO::Hero> map;
|
||||
const auto hero = m_NetworkHandler.GetHero();
|
||||
if (hero)
|
||||
{
|
||||
map.emplace(hero->objectId, m_Factory.Create(hero));
|
||||
}
|
||||
|
||||
if (hero != nullptr && m_PrevHero == nullptr)
|
||||
{
|
||||
EventDispatcher::GetInstance().Dispatch(HeroCreatedEvent{});
|
||||
}
|
||||
if (hero == nullptr && m_PrevHero != nullptr)
|
||||
{
|
||||
EventDispatcher::GetInstance().Dispatch(HeroDeletedEvent{});
|
||||
}
|
||||
|
||||
m_PrevHero = hero;
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
HeroRepository(const NetworkHandlerWrapper& networkHandler, const HeroFactory& factory) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
HeroRepository() = delete;
|
||||
virtual ~HeroRepository() = default;
|
||||
|
||||
private:
|
||||
const HeroFactory& m_Factory;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
User* m_PrevHero = nullptr;
|
||||
};
|
||||
}
|
97
L2BotDll/Versions/Interlude/Repositories/NPCRepository.h
Normal file
97
L2BotDll/Versions/Interlude/Repositories/NPCRepository.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "Domain/Repositories/NPCRepositoryInterface.h"
|
||||
#include "../Factories/NPCFactory.h"
|
||||
#include "../../../Events/EventDispatcher.h"
|
||||
#include "../../../Events/SpoiledEvent.h"
|
||||
#include "../../../Events/CreatureDiedEvent.h"
|
||||
#include "../../GameStructs/FindObjectsTrait.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
class NPCRepository : public Repositories::NPCRepositoryInterface, public FindObjectsTrait
|
||||
{
|
||||
public:
|
||||
const std::map<uint32_t, DTO::NPC> GetObjects() override
|
||||
{
|
||||
const auto creatures = GetAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
return m_NetworkHandler.GetNextCreature(radius, prevId);
|
||||
});
|
||||
|
||||
std::map<uint32_t, DTO::NPC> map;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
NPCRepository(const NetworkHandlerWrapper& networkHandler, const NPCFactory& factory, const uint16_t radius) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_Radius(radius)
|
||||
{
|
||||
EventDispatcher::GetInstance().Subscribe(SpoiledEvent::name, [this](const Event& evt) {
|
||||
OnSpoiled(evt);
|
||||
});
|
||||
EventDispatcher::GetInstance().Subscribe(CreatureDiedEvent::name, [this](const Event& evt) {
|
||||
OnCreatureDied(evt);
|
||||
});
|
||||
}
|
||||
|
||||
NPCRepository() = delete;
|
||||
virtual ~NPCRepository() = default;
|
||||
|
||||
void OnSpoiled(const Event& evt)
|
||||
{
|
||||
if (evt.GetName() == SpoiledEvent::name)
|
||||
{
|
||||
const auto casted = static_cast<const SpoiledEvent&>(evt);
|
||||
const auto hero = m_NetworkHandler.GetHero();
|
||||
if (hero && hero->pawn && hero->pawn->lineagePlayerController)
|
||||
{
|
||||
const auto targetId = hero->pawn->lineagePlayerController->targetObjectId;
|
||||
if (targetId)
|
||||
{
|
||||
m_Spoiled[targetId] = Enums::SpoilStateEnum::spoiled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnCreatureDied(const Event& evt)
|
||||
{
|
||||
if (evt.GetName() == CreatureDiedEvent::name)
|
||||
{
|
||||
const auto casted = static_cast<const CreatureDiedEvent&>(evt);
|
||||
if (m_Spoiled.find(casted.GetCreatureId()) != m_Spoiled.end())
|
||||
{
|
||||
if (m_Spoiled[casted.GetCreatureId()] == Enums::SpoilStateEnum::spoiled)
|
||||
{
|
||||
m_Spoiled[casted.GetCreatureId()] = Enums::SpoilStateEnum::sweepable;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Spoiled[casted.GetCreatureId()] = Enums::SpoilStateEnum::none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const NPCFactory& m_Factory;
|
||||
std::map<uint32_t, Enums::SpoilStateEnum> m_Spoiled;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
const uint16_t m_Radius = 0;
|
||||
};
|
||||
}
|
50
L2BotDll/Versions/Interlude/Repositories/PlayerRepository.h
Normal file
50
L2BotDll/Versions/Interlude/Repositories/PlayerRepository.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include "Domain/Repositories/PlayerRepositoryInterface.h"
|
||||
#include "../Factories/PlayerFactory.h"
|
||||
#include "../../GameStructs/FindObjectsTrait.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
class PlayerRepository : public Repositories::PlayerRepositoryInterface, public FindObjectsTrait
|
||||
{
|
||||
public:
|
||||
const std::map<uint32_t, DTO::Player> GetObjects() override
|
||||
{
|
||||
const auto creatures = GetAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
return m_NetworkHandler.GetNextCreature(radius, prevId);
|
||||
});
|
||||
|
||||
std::map<uint32_t, DTO::Player> map;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
PlayerRepository(const NetworkHandlerWrapper& networkHandler, const PlayerFactory& factory, const uint16_t radius) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_Radius(radius)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PlayerRepository() = delete;
|
||||
virtual ~PlayerRepository() = default;
|
||||
|
||||
private:
|
||||
const PlayerFactory& m_Factory;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
const uint16_t m_Radius;
|
||||
};
|
||||
}
|
214
L2BotDll/Versions/Interlude/Repositories/SkillRepository.h
Normal file
214
L2BotDll/Versions/Interlude/Repositories/SkillRepository.h
Normal file
@@ -0,0 +1,214 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <chrono>
|
||||
#include <shared_mutex>
|
||||
#include "Domain/Repositories/SkillRepositoryInterface.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 "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Common/TimerMap.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
class SkillRepository : public Repositories::SkillRepositoryInterface
|
||||
{
|
||||
public:
|
||||
const std::map<uint32_t, DTO::Skill> GetObjects() override
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
return m_Skills;
|
||||
}
|
||||
|
||||
SkillRepository(const NetworkHandlerWrapper& networkHandler, const SkillFactory& factory) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory)
|
||||
{
|
||||
EventDispatcher::GetInstance().Subscribe(SkillCreatedEvent::name, [this](const Event& evt) {
|
||||
OnSkillCreated(evt);
|
||||
});
|
||||
EventDispatcher::GetInstance().Subscribe(SkillUsedEvent::name, [this](const Event& evt) {
|
||||
OnSkillUsed(evt);
|
||||
});
|
||||
EventDispatcher::GetInstance().Subscribe(SkillCancelledEvent::name, [this](const Event& evt) {
|
||||
OnSkillCancelled(evt);
|
||||
});
|
||||
EventDispatcher::GetInstance().Subscribe(AbnormalEffectChangedEvent::name, [this](const Event& evt) {
|
||||
OnSkillToggled(evt);
|
||||
});
|
||||
EventDispatcher::GetInstance().Subscribe(HeroDeletedEvent::name, [this](const Event& evt) {
|
||||
OnHeroDeleted(evt);
|
||||
});
|
||||
}
|
||||
|
||||
SkillRepository() = delete;
|
||||
virtual ~SkillRepository() = default;
|
||||
|
||||
void OnHeroDeleted(const Event& evt)
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
if (evt.GetName() == HeroDeletedEvent::name)
|
||||
{
|
||||
m_Skills.clear();
|
||||
m_CastingTimers.StopAll();
|
||||
m_ReloadingTimers.StopAll();
|
||||
}
|
||||
}
|
||||
void OnSkillCreated(const Event& evt)
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
if (evt.GetName() == SkillCreatedEvent::name)
|
||||
{
|
||||
const auto casted = static_cast<const SkillCreatedEvent&>(evt);
|
||||
const auto skillInfo = casted.GetSkillInfo();
|
||||
const auto skillId = skillInfo[2];
|
||||
|
||||
const auto alreadyExists = m_Skills.find(skillId) != m_Skills.end();
|
||||
|
||||
auto skill = m_Factory.Create(
|
||||
alreadyExists ? m_Skills[skillId] : DTO::Skill(),
|
||||
skillInfo[2],
|
||||
skillInfo[1],
|
||||
skillInfo[0]
|
||||
);
|
||||
|
||||
UpdateSkill(skill);
|
||||
}
|
||||
}
|
||||
void OnSkillUsed(const Event& evt)
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
if (evt.GetName() == SkillUsedEvent::name)
|
||||
{
|
||||
const auto casted = static_cast<const SkillUsedEvent&>(evt);
|
||||
const auto skillInfo = casted.GetSkillInfo();
|
||||
const auto skillId = skillInfo[0];
|
||||
|
||||
if (m_Skills.find(skillId) == m_Skills.end())
|
||||
{
|
||||
//todo exception?
|
||||
return;
|
||||
}
|
||||
|
||||
auto skill = m_Factory.UpdateReloadingState(
|
||||
m_Factory.UpdateCastingState(
|
||||
m_Skills[skillId],
|
||||
true
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
UpdateSkill(skill);
|
||||
m_UsedSkillId = skill.skillId;
|
||||
|
||||
m_ReloadingTimers.StartTimer(skill.skillId, 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_CastingTimers.StartTimer(skill.skillId, 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
void OnSkillCancelled(const Event& evt)
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
if (evt.GetName() == SkillCancelledEvent::name)
|
||||
{
|
||||
const auto casted = static_cast<const SkillCancelledEvent&>(evt);
|
||||
|
||||
const auto hero = m_NetworkHandler.GetHero();
|
||||
|
||||
if (hero && hero->objectId == casted.GetInitiatorId())
|
||||
{
|
||||
if (m_Skills.find(m_UsedSkillId) == m_Skills.end())
|
||||
{
|
||||
//todo exception?
|
||||
return;
|
||||
}
|
||||
|
||||
auto skill = m_Factory.UpdateCastingState(
|
||||
m_Skills[m_UsedSkillId],
|
||||
false
|
||||
);
|
||||
|
||||
UpdateSkill(skill);
|
||||
m_UsedSkillId = 0;
|
||||
|
||||
m_CastingTimers.StopTimer(skill.skillId);
|
||||
}
|
||||
}
|
||||
}
|
||||
void OnSkillToggled(const Event& evt)
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
if (evt.GetName() == AbnormalEffectChangedEvent::name)
|
||||
{
|
||||
const auto casted = static_cast<const AbnormalEffectChangedEvent&>(evt);
|
||||
const auto skillInfo = casted.GetSkillInfo();
|
||||
|
||||
std::map<uint32_t, int32_t> ids;
|
||||
|
||||
for (size_t i = 0; i < skillInfo.size(); i += 3)
|
||||
{
|
||||
ids[skillInfo[i]] = skillInfo[i + 2];
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (it->second.isToggled && !needToToggle)
|
||||
{
|
||||
auto skill = m_Factory.UpdateToggle(it->second, false);
|
||||
it = m_Skills.erase(it);
|
||||
m_Skills.emplace(skill.skillId, skill);
|
||||
}
|
||||
else if (!it->second.isToggled && needToToggle && isAura)
|
||||
{
|
||||
auto skill = m_Factory.UpdateToggle(it->second, true);
|
||||
it = m_Skills.erase(it);
|
||||
m_Skills.emplace(skill.skillId, skill);
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
uint32_t m_UsedSkillId = 0;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
TimerMap m_ReloadingTimers;
|
||||
TimerMap m_CastingTimers;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user