refactor: remove unnecessary classes
This commit is contained in:
@ -22,7 +22,6 @@
|
||||
#include "GameStructs/GameEngineWrapper.h"
|
||||
#include "GameStructs/L2GameDataWrapper.h"
|
||||
#include "GameStructs/FName.h"
|
||||
#include "../../Services/EntityFinder.h"
|
||||
#include "Helpers/EnchantHelper.h"
|
||||
|
||||
namespace Interlude
|
||||
@ -41,22 +40,18 @@ namespace Interlude
|
||||
HeroRepository& GetHeroRepository() const override
|
||||
{
|
||||
static auto factory = HeroFactory();
|
||||
static EntityFinder finder;
|
||||
static auto result = HeroRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
finder
|
||||
factory
|
||||
);
|
||||
return result;
|
||||
}
|
||||
DropRepository& GetDropRepository() const override
|
||||
{
|
||||
static auto factory = DropFactory(GetL2GameData(), GetFName());
|
||||
static EntityFinder finder;
|
||||
static auto result = DropRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
finder,
|
||||
m_Radius
|
||||
);
|
||||
return result;
|
||||
@ -64,11 +59,9 @@ namespace Interlude
|
||||
NPCRepository& GetNPCRepository() const override
|
||||
{
|
||||
static auto factory = NPCFactory();
|
||||
static EntityFinder finder;
|
||||
static auto result = NPCRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
finder,
|
||||
m_Radius
|
||||
);
|
||||
return result;
|
||||
@ -76,11 +69,9 @@ namespace Interlude
|
||||
PlayerRepository& GetPlayerRepository() const override
|
||||
{
|
||||
static auto factory = PlayerFactory();
|
||||
static EntityFinder finder;
|
||||
static auto result = PlayerRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
finder,
|
||||
m_Radius
|
||||
);
|
||||
return result;
|
||||
@ -88,11 +79,9 @@ namespace Interlude
|
||||
SkillRepository& GetSkillRepository() const override
|
||||
{
|
||||
static auto factory = SkillFactory(GetL2GameData(), GetFName());
|
||||
static EntityFinder finder;
|
||||
static auto result = SkillRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
finder
|
||||
factory
|
||||
);
|
||||
return result;
|
||||
}
|
||||
@ -100,22 +89,16 @@ namespace Interlude
|
||||
{
|
||||
static EnchantHelper enchantHelper;
|
||||
static auto factory = ItemFactory(GetL2GameData(), GetFName(), enchantHelper);
|
||||
static EntityFinder finder;
|
||||
static auto result = ItemRepository(
|
||||
GetNetworkHandler(),
|
||||
factory,
|
||||
finder
|
||||
factory
|
||||
);
|
||||
return result;
|
||||
}
|
||||
AbnormalEffectRepository& GetAbnormalEffectRepository() const override
|
||||
{
|
||||
static auto factory = AbnormalEffectFactory(GetL2GameData(), GetFName());
|
||||
static EntityFinder finder;
|
||||
static auto result = AbnormalEffectRepository(
|
||||
factory,
|
||||
finder
|
||||
);
|
||||
static auto result = AbnormalEffectRepository(factory);
|
||||
return result;
|
||||
}
|
||||
ChatMessageRepository& GetChatMessageRepository() const override
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Domain/ValueObjects/ChatMessage.h"
|
||||
#include "Domain/Entities/ChatMessage.h"
|
||||
#include "../../../DTO/ChatMessage.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
@ -13,14 +13,14 @@ namespace Interlude
|
||||
ChatMessageFactory() = default;
|
||||
virtual ~ChatMessageFactory() = default;
|
||||
|
||||
ValueObjects::ChatMessage Create(const ChatMessage& message) const
|
||||
std::shared_ptr<Entities::ChatMessage> Create(const ChatMessage& message) const
|
||||
{
|
||||
return ValueObjects::ChatMessage{
|
||||
return std::make_shared<Entities::ChatMessage>(
|
||||
message.objectId,
|
||||
static_cast<Enums::ChatChannelEnum>(message.channel),
|
||||
message.name,
|
||||
message.text
|
||||
};
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
@ -11,6 +11,17 @@ namespace Interlude
|
||||
{
|
||||
class DropFactory
|
||||
{
|
||||
private:
|
||||
struct Data
|
||||
{
|
||||
uint32_t id;
|
||||
ValueObjects::Transform transform;
|
||||
uint32_t itemId;
|
||||
uint32_t amount;
|
||||
std::wstring name;
|
||||
std::wstring iconName;
|
||||
};
|
||||
|
||||
public:
|
||||
DropFactory(const L2GameDataWrapper& l2GameData, const FName& fName) :
|
||||
m_L2GameData(l2GameData),
|
||||
@ -22,12 +33,40 @@ namespace Interlude
|
||||
virtual ~DropFactory() = default;
|
||||
|
||||
std::shared_ptr<Entities::Drop> Create(const Item* item) const
|
||||
{
|
||||
const auto &data = GetData(item);
|
||||
|
||||
return std::make_shared<Entities::Drop>(
|
||||
data.id,
|
||||
data.transform,
|
||||
data.itemId,
|
||||
data.amount,
|
||||
data.name,
|
||||
data.iconName
|
||||
);
|
||||
}
|
||||
|
||||
void Update(std::shared_ptr<Entities::Drop>& drop, const Item* item) const
|
||||
{
|
||||
const auto& data = GetData(item);
|
||||
|
||||
drop->Update(
|
||||
data.transform,
|
||||
data.itemId,
|
||||
data.amount,
|
||||
data.name,
|
||||
data.iconName
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
const Data GetData(const Item* item) const
|
||||
{
|
||||
const auto itemData = m_L2GameData.GetItemData(item->itemId);
|
||||
const auto nameEntry = itemData ? m_FName.GetEntry(itemData->nameIndex) : nullptr;
|
||||
const auto iconEntry = itemData ? m_FName.GetEntry(itemData->iconNameIndex) : nullptr;
|
||||
|
||||
return std::make_shared<Entities::Drop>(
|
||||
return {
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
|
||||
@ -43,7 +82,7 @@ namespace Interlude
|
||||
item->amount,
|
||||
nameEntry ? std::wstring(nameEntry->value) : L"",
|
||||
iconEntry ? std::wstring(iconEntry->value) : L""
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -9,80 +9,137 @@ namespace Interlude
|
||||
{
|
||||
class HeroFactory
|
||||
{
|
||||
private:
|
||||
struct Data
|
||||
{
|
||||
uint32_t id;
|
||||
ValueObjects::Transform transform;
|
||||
ValueObjects::FullName fullName;
|
||||
ValueObjects::VitalStats vitalStats;
|
||||
ValueObjects::Phenotype phenotype;
|
||||
ValueObjects::ExperienceInfo experienceInfo;
|
||||
ValueObjects::PermanentStats permanentStats;
|
||||
ValueObjects::VariableStats variableStats;
|
||||
ValueObjects::Reputation reputation;
|
||||
ValueObjects::InventoryInfo inventoryInfo;
|
||||
uint32_t targetId;
|
||||
bool isStanding;
|
||||
};
|
||||
|
||||
public:
|
||||
HeroFactory() = default;
|
||||
virtual ~HeroFactory() = default;
|
||||
|
||||
std::shared_ptr<Entities::Hero> Create(const User* item) const
|
||||
{
|
||||
const auto playerController = item->pawn ? item->pawn->lineagePlayerController : nullptr;
|
||||
const auto& data = GetData(item);
|
||||
|
||||
return std::make_shared<Entities::Hero>(
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
|
||||
ValueObjects::Vector3(
|
||||
static_cast<float_t>(item->pawn->Rotation.Pitch),
|
||||
static_cast<float_t>(item->pawn->Rotation.Yaw),
|
||||
static_cast<float_t>(item->pawn->Rotation.Roll)
|
||||
),
|
||||
ValueObjects::Vector3(item->pawn->Velocity.x, item->pawn->Velocity.y, item->pawn->Velocity.z),
|
||||
ValueObjects::Vector3(item->pawn->Acceleration.x, item->pawn->Acceleration.y, item->pawn->Acceleration.z)
|
||||
),
|
||||
ValueObjects::FullName(
|
||||
std::wstring(item->nickname),
|
||||
std::wstring(item->title)
|
||||
),
|
||||
ValueObjects::VitalStats(
|
||||
item->maxHp, item->hp,
|
||||
item->maxMp, item->mp,
|
||||
item->maxCp, item->cp
|
||||
),
|
||||
ValueObjects::Phenotype(
|
||||
(Enums::RaceEnum)item->raceId,
|
||||
item->gender == L2::Gender::MALE,
|
||||
(Enums::ClassEnum)item->classId,
|
||||
(Enums::ClassEnum)item->activeClassId
|
||||
),
|
||||
ValueObjects::ExperienceInfo(
|
||||
item->lvl,
|
||||
item->exp,
|
||||
item->sp
|
||||
),
|
||||
ValueObjects::PermanentStats(
|
||||
item->str,
|
||||
item->dex,
|
||||
item->con,
|
||||
item->int_,
|
||||
item->men,
|
||||
item->wit
|
||||
),
|
||||
ValueObjects::VariableStats(
|
||||
item->accuracy,
|
||||
item->critRate,
|
||||
item->pAttack,
|
||||
item->attackSpeed,
|
||||
item->pDefense,
|
||||
item->evasion,
|
||||
item->mAttack,
|
||||
item->mDefense,
|
||||
item->castingSpeed
|
||||
),
|
||||
ValueObjects::Reputation(
|
||||
item->karma,
|
||||
item->pkKills,
|
||||
item->pvpKills,
|
||||
static_cast<uint8_t>(item->recRemaining),
|
||||
static_cast<uint8_t>(item->evalScore)
|
||||
),
|
||||
ValueObjects::InventoryInfo(
|
||||
item->maxWeight,
|
||||
item->weight,
|
||||
item->invSlotCount
|
||||
),
|
||||
playerController ? playerController->targetObjectId : 0,
|
||||
playerController ? playerController->isStanding == 1 : true
|
||||
data.id,
|
||||
data.transform,
|
||||
data.fullName,
|
||||
data.vitalStats,
|
||||
data.phenotype,
|
||||
data.experienceInfo,
|
||||
data.permanentStats,
|
||||
data.variableStats,
|
||||
data.reputation,
|
||||
data.inventoryInfo,
|
||||
data.targetId,
|
||||
data.isStanding
|
||||
);
|
||||
}
|
||||
|
||||
void Update(std::shared_ptr<Entities::Hero>& hero, const User* item) const
|
||||
{
|
||||
const auto& data = GetData(item);
|
||||
|
||||
hero->Update(
|
||||
data.transform,
|
||||
data.fullName,
|
||||
data.vitalStats,
|
||||
data.phenotype,
|
||||
data.experienceInfo,
|
||||
data.permanentStats,
|
||||
data.variableStats,
|
||||
data.reputation,
|
||||
data.inventoryInfo,
|
||||
data.targetId,
|
||||
data.isStanding
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
const Data GetData(const User* item) const
|
||||
{
|
||||
const auto playerController = item->pawn ? item->pawn->lineagePlayerController : nullptr;
|
||||
|
||||
return {
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
|
||||
ValueObjects::Vector3(
|
||||
static_cast<float_t>(item->pawn->Rotation.Pitch),
|
||||
static_cast<float_t>(item->pawn->Rotation.Yaw),
|
||||
static_cast<float_t>(item->pawn->Rotation.Roll)
|
||||
),
|
||||
ValueObjects::Vector3(item->pawn->Velocity.x, item->pawn->Velocity.y, item->pawn->Velocity.z),
|
||||
ValueObjects::Vector3(item->pawn->Acceleration.x, item->pawn->Acceleration.y, item->pawn->Acceleration.z)
|
||||
),
|
||||
ValueObjects::FullName(
|
||||
std::wstring(item->nickname),
|
||||
std::wstring(item->title)
|
||||
),
|
||||
ValueObjects::VitalStats(
|
||||
item->maxHp, item->hp,
|
||||
item->maxMp, item->mp,
|
||||
item->maxCp, item->cp
|
||||
),
|
||||
ValueObjects::Phenotype(
|
||||
(Enums::RaceEnum)item->raceId,
|
||||
item->gender == L2::Gender::MALE,
|
||||
(Enums::ClassEnum)item->classId,
|
||||
(Enums::ClassEnum)item->activeClassId
|
||||
),
|
||||
ValueObjects::ExperienceInfo(
|
||||
item->lvl,
|
||||
item->exp,
|
||||
item->sp
|
||||
),
|
||||
ValueObjects::PermanentStats(
|
||||
item->str,
|
||||
item->dex,
|
||||
item->con,
|
||||
item->int_,
|
||||
item->men,
|
||||
item->wit
|
||||
),
|
||||
ValueObjects::VariableStats(
|
||||
item->accuracy,
|
||||
item->critRate,
|
||||
item->pAttack,
|
||||
item->attackSpeed,
|
||||
item->pDefense,
|
||||
item->evasion,
|
||||
item->mAttack,
|
||||
item->mDefense,
|
||||
item->castingSpeed
|
||||
),
|
||||
ValueObjects::Reputation(
|
||||
item->karma,
|
||||
item->pkKills,
|
||||
item->pvpKills,
|
||||
static_cast<uint8_t>(item->recRemaining),
|
||||
static_cast<uint8_t>(item->evalScore)
|
||||
),
|
||||
ValueObjects::InventoryInfo(
|
||||
item->maxWeight,
|
||||
item->weight,
|
||||
item->invSlotCount
|
||||
),
|
||||
playerController ? playerController->targetObjectId : 0,
|
||||
playerController ? playerController->isStanding == 1 : true
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
@ -19,6 +19,64 @@ namespace Interlude
|
||||
{
|
||||
class ItemFactory
|
||||
{
|
||||
private:
|
||||
struct BaseData
|
||||
{
|
||||
uint32_t objectId;
|
||||
uint32_t itemId;
|
||||
int32_t mana;
|
||||
std::wstring name;
|
||||
std::wstring iconName;
|
||||
std::wstring description;
|
||||
uint16_t weight;
|
||||
};
|
||||
|
||||
struct EtcData : public BaseData
|
||||
{
|
||||
uint32_t amount;
|
||||
bool isQuest;
|
||||
};
|
||||
|
||||
struct ArmorData : public BaseData
|
||||
{
|
||||
bool isEquipped;
|
||||
uint16_t enchantLevel;
|
||||
Enums::ArmorTypeEnum armorType;
|
||||
Enums::CrystalTypeEnum crystalType;
|
||||
uint32_t pDefense;
|
||||
uint32_t mDefense;
|
||||
std::wstring setEffect;
|
||||
std::wstring addSetEffect;
|
||||
std::wstring enchantEffect;
|
||||
};
|
||||
|
||||
struct ShieldData : public BaseData
|
||||
{
|
||||
bool isEquipped;
|
||||
uint16_t enchantLevel;
|
||||
Enums::CrystalTypeEnum crystalType;
|
||||
int16_t evasion;
|
||||
uint32_t pDefense;
|
||||
uint16_t defRate;
|
||||
};
|
||||
|
||||
struct WeaponData : public BaseData
|
||||
{
|
||||
bool isEquipped;
|
||||
uint16_t enchantLevel;
|
||||
Enums::WeaponTypeEnum weaponType;
|
||||
Enums::CrystalTypeEnum crystalType;
|
||||
uint8_t rndDamage;
|
||||
uint32_t pAttack;
|
||||
uint32_t mAttack;
|
||||
uint16_t critical;
|
||||
int8_t hitModify;
|
||||
uint16_t atkSpd;
|
||||
uint8_t mpConsume;
|
||||
uint8_t soulshotCount;
|
||||
uint8_t spiritshotCount;
|
||||
};
|
||||
|
||||
public:
|
||||
ItemFactory(const L2GameDataWrapper& l2GameData, const FName& fName, const EnchantHelper& enchantHelper) :
|
||||
m_L2GameData(l2GameData),
|
||||
@ -33,7 +91,237 @@ namespace Interlude
|
||||
std::shared_ptr<Entities::BaseItem> Create(const ItemData& itemInfo) const
|
||||
{
|
||||
//FIXME during first start data may be undefined
|
||||
const auto data = m_L2GameData.GetItemData(itemInfo.itemId);
|
||||
const auto data = GetItemData(itemInfo.itemId);
|
||||
|
||||
if (data)
|
||||
{
|
||||
switch (data->dataType)
|
||||
{
|
||||
case L2::ItemDataType::ARMOR:
|
||||
return CreateArmor(itemInfo);
|
||||
case L2::ItemDataType::WEAPON:
|
||||
return CreateWeaponOrShield(itemInfo);
|
||||
}
|
||||
|
||||
return CreateEtc(itemInfo);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Update(std::shared_ptr<Entities::BaseItem>& item, const ItemData& itemInfo) const
|
||||
{
|
||||
//FIXME during first start data may be undefined
|
||||
const auto data = GetItemData(itemInfo.itemId);
|
||||
|
||||
if (data)
|
||||
{
|
||||
switch (data->dataType)
|
||||
{
|
||||
case L2::ItemDataType::ARMOR:
|
||||
UpdateArmor(item, itemInfo);
|
||||
return;
|
||||
case L2::ItemDataType::WEAPON:
|
||||
UpdateWeaponOrShield(item, itemInfo);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateEtc(item, itemInfo);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<Entities::BaseItem> CreateEtc(const ItemData& itemInfo) const
|
||||
{
|
||||
const auto& data = GetEtcData(itemInfo);
|
||||
|
||||
return std::make_shared<Entities::EtcItem>(
|
||||
data.objectId,
|
||||
data.itemId,
|
||||
data.mana,
|
||||
data.name,
|
||||
data.iconName,
|
||||
data.description,
|
||||
data.weight,
|
||||
data.amount,
|
||||
data.isQuest
|
||||
);
|
||||
}
|
||||
|
||||
void UpdateEtc(std::shared_ptr<Entities::BaseItem> &item, const ItemData& itemInfo) const
|
||||
{
|
||||
auto etcItem = std::dynamic_pointer_cast<Entities::EtcItem>(item);
|
||||
|
||||
const auto& data = GetEtcData(itemInfo);
|
||||
|
||||
etcItem->Update(
|
||||
data.itemId,
|
||||
data.mana,
|
||||
data.name,
|
||||
data.iconName,
|
||||
data.description,
|
||||
data.weight,
|
||||
data.amount,
|
||||
data.isQuest
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<Entities::BaseItem> CreateArmor(const ItemData& itemInfo) const
|
||||
{
|
||||
const auto& data = GetArmorData(itemInfo);
|
||||
|
||||
return std::make_shared<Entities::ArmorItem>(
|
||||
data.objectId,
|
||||
data.itemId,
|
||||
data.mana,
|
||||
data.name,
|
||||
data.iconName,
|
||||
data.description,
|
||||
data.weight,
|
||||
data.isEquipped,
|
||||
data.enchantLevel,
|
||||
data.armorType,
|
||||
data.crystalType,
|
||||
data.pDefense,
|
||||
data.mDefense,
|
||||
data.setEffect,
|
||||
data.addSetEffect,
|
||||
data.enchantEffect
|
||||
);
|
||||
}
|
||||
|
||||
void UpdateArmor(std::shared_ptr<Entities::BaseItem>& item, const ItemData& itemInfo) const
|
||||
{
|
||||
auto armorItem = std::dynamic_pointer_cast<Entities::ArmorItem>(item);
|
||||
|
||||
const auto& data = GetArmorData(itemInfo);
|
||||
|
||||
armorItem->Update(
|
||||
data.itemId,
|
||||
data.mana,
|
||||
data.name,
|
||||
data.iconName,
|
||||
data.description,
|
||||
data.weight,
|
||||
data.isEquipped,
|
||||
data.enchantLevel,
|
||||
data.armorType,
|
||||
data.crystalType,
|
||||
data.pDefense,
|
||||
data.mDefense,
|
||||
data.setEffect,
|
||||
data.addSetEffect,
|
||||
data.enchantEffect
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<Entities::BaseItem> CreateWeaponOrShield(const ItemData& itemInfo) const
|
||||
{
|
||||
const auto itemData = static_cast<const FL2WeaponItemData*>(GetItemData(itemInfo.itemId));
|
||||
|
||||
if (itemData->weaponType != L2::WeaponType::SHIELD)
|
||||
{
|
||||
const auto& data = GetWeaponData(itemInfo, itemData);
|
||||
|
||||
return std::make_shared<Entities::WeaponItem>(
|
||||
data.objectId,
|
||||
data.itemId,
|
||||
data.mana,
|
||||
data.name,
|
||||
data.iconName,
|
||||
data.description,
|
||||
data.weight,
|
||||
data.isEquipped,
|
||||
data.enchantLevel,
|
||||
data.weaponType,
|
||||
data.crystalType,
|
||||
data.rndDamage,
|
||||
data.pAttack,
|
||||
data.mAttack,
|
||||
data.critical,
|
||||
data.hitModify,
|
||||
data.atkSpd,
|
||||
data.mpConsume,
|
||||
data.soulshotCount,
|
||||
data.spiritshotCount
|
||||
);
|
||||
}
|
||||
|
||||
const auto& data = GetShieldData(itemInfo, itemData);
|
||||
|
||||
return std::make_shared<Entities::ShieldItem>(
|
||||
data.objectId,
|
||||
data.itemId,
|
||||
data.mana,
|
||||
data.name,
|
||||
data.iconName,
|
||||
data.description,
|
||||
data.weight,
|
||||
data.isEquipped,
|
||||
data.enchantLevel,
|
||||
data.crystalType,
|
||||
data.evasion,
|
||||
data.pDefense,
|
||||
data.defRate
|
||||
);
|
||||
}
|
||||
|
||||
void UpdateWeaponOrShield(std::shared_ptr<Entities::BaseItem>& item, const ItemData& itemInfo) const
|
||||
{
|
||||
const auto itemData = static_cast<const FL2WeaponItemData*>(GetItemData(itemInfo.itemId));
|
||||
|
||||
if (itemData->weaponType != L2::WeaponType::SHIELD)
|
||||
{
|
||||
auto weaponItem = std::dynamic_pointer_cast<Entities::WeaponItem>(item);
|
||||
const auto& data = GetWeaponData(itemInfo, itemData);
|
||||
|
||||
weaponItem->Update(
|
||||
data.itemId,
|
||||
data.mana,
|
||||
data.name,
|
||||
data.iconName,
|
||||
data.description,
|
||||
data.weight,
|
||||
data.isEquipped,
|
||||
data.enchantLevel,
|
||||
data.weaponType,
|
||||
data.crystalType,
|
||||
data.rndDamage,
|
||||
data.pAttack,
|
||||
data.mAttack,
|
||||
data.critical,
|
||||
data.hitModify,
|
||||
data.atkSpd,
|
||||
data.mpConsume,
|
||||
data.soulshotCount,
|
||||
data.spiritshotCount
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
auto shieldItem = std::dynamic_pointer_cast<Entities::ShieldItem>(item);
|
||||
const auto& data = GetShieldData(itemInfo, itemData);
|
||||
|
||||
shieldItem->Update(
|
||||
data.itemId,
|
||||
data.mana,
|
||||
data.name,
|
||||
data.iconName,
|
||||
data.description,
|
||||
data.weight,
|
||||
data.isEquipped,
|
||||
data.enchantLevel,
|
||||
data.crystalType,
|
||||
data.evasion,
|
||||
data.pDefense,
|
||||
data.defRate
|
||||
);
|
||||
}
|
||||
|
||||
const BaseData GetBaseData(const ItemData& itemInfo) const
|
||||
{
|
||||
const auto data = GetItemData(itemInfo.itemId);
|
||||
|
||||
const auto nameEntry = data ? m_FName.GetEntry(data->nameIndex) : nullptr;
|
||||
const auto name = nameEntry ? std::wstring(nameEntry->value) : L"";
|
||||
@ -41,99 +329,52 @@ namespace Interlude
|
||||
const auto icon = iconEntry ? std::wstring(iconEntry->value) : L"";
|
||||
const auto description = data && data->description ? std::wstring(data->description) : L"";
|
||||
|
||||
if (data)
|
||||
{
|
||||
switch (data->dataType)
|
||||
{
|
||||
case L2::ItemDataType::ARMOR:
|
||||
return CreateArmor(itemInfo, data, name, icon, description);
|
||||
case L2::ItemDataType::WEAPON:
|
||||
return CreateWeaponOrShield(itemInfo, data, name, icon, description);
|
||||
}
|
||||
}
|
||||
|
||||
return CreateEtc(itemInfo, data, name, icon, description);
|
||||
}
|
||||
|
||||
std::shared_ptr<Entities::BaseItem> Copy(std::shared_ptr<Entities::BaseItem> other) const
|
||||
{
|
||||
auto otherPtr = other.get();
|
||||
{
|
||||
const auto object = dynamic_cast<const Entities::EtcItem*>(otherPtr);
|
||||
if (object)
|
||||
{
|
||||
return std::make_shared<Entities::EtcItem>(object);
|
||||
}
|
||||
}
|
||||
{
|
||||
const auto object = dynamic_cast<const Entities::ArmorItem*>(otherPtr);
|
||||
if (object)
|
||||
{
|
||||
return std::make_shared<Entities::ArmorItem>(object);
|
||||
}
|
||||
}
|
||||
{
|
||||
const auto object = dynamic_cast<const Entities::WeaponItem*>(otherPtr);
|
||||
if (object)
|
||||
{
|
||||
return std::make_shared<Entities::WeaponItem>(object);
|
||||
}
|
||||
}
|
||||
{
|
||||
const auto object = dynamic_cast<const Entities::ShieldItem*>(otherPtr);
|
||||
if (object)
|
||||
{
|
||||
return std::make_shared<Entities::ShieldItem>(object);
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_shared<Entities::BaseItem>(otherPtr);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<Entities::BaseItem> CreateEtc(
|
||||
const ItemData& itemInfo,
|
||||
const FL2ItemDataBase* itemData,
|
||||
const std::wstring& name,
|
||||
const std::wstring& icon,
|
||||
const std::wstring& description
|
||||
) const
|
||||
{
|
||||
return std::make_shared<Entities::EtcItem>(
|
||||
return {
|
||||
itemInfo.objectId,
|
||||
itemInfo.itemId,
|
||||
itemInfo.mana,
|
||||
name,
|
||||
icon,
|
||||
description,
|
||||
itemData ? itemData->weight : 0,
|
||||
itemInfo.amount,
|
||||
itemInfo.isQuest
|
||||
);
|
||||
(uint16_t)(data ? data->weight : 0)
|
||||
};
|
||||
}
|
||||
|
||||
std::shared_ptr<Entities::BaseItem> CreateArmor(
|
||||
const ItemData& itemInfo,
|
||||
const FL2ItemDataBase* itemData,
|
||||
const std::wstring& name,
|
||||
const std::wstring& icon,
|
||||
const std::wstring& description
|
||||
) const
|
||||
const EtcData GetEtcData(const ItemData& itemInfo) const
|
||||
{
|
||||
const auto casted = static_cast<const FL2ArmorItemData*>(itemData);
|
||||
const auto& baseData = GetBaseData(itemInfo);
|
||||
|
||||
return {
|
||||
baseData.objectId,
|
||||
baseData.itemId,
|
||||
baseData.mana,
|
||||
baseData.name,
|
||||
baseData.iconName,
|
||||
baseData.description,
|
||||
baseData.weight,
|
||||
itemInfo.amount,
|
||||
itemInfo.isQuest
|
||||
};
|
||||
}
|
||||
|
||||
const ArmorData GetArmorData(const ItemData& itemInfo) const
|
||||
{
|
||||
const auto& baseData = GetBaseData(itemInfo);
|
||||
|
||||
const auto casted = static_cast<const FL2ArmorItemData*>(GetItemData(itemInfo.itemId));
|
||||
|
||||
const auto setEffect = casted && casted->setEffect ? std::wstring(casted->setEffect) : L"";
|
||||
const auto addSetEffect = casted && casted->setEffect ? std::wstring(casted->setEffect) : L"";
|
||||
const auto enchantEffect = casted && casted->enchantEffect ? std::wstring(casted->enchantEffect) : L"";
|
||||
|
||||
return std::make_shared<Entities::ArmorItem>(
|
||||
itemInfo.objectId,
|
||||
itemInfo.itemId,
|
||||
itemInfo.mana,
|
||||
name,
|
||||
icon,
|
||||
description,
|
||||
itemData ? itemData->weight : 0,
|
||||
return {
|
||||
baseData.objectId,
|
||||
baseData.itemId,
|
||||
baseData.mana,
|
||||
baseData.name,
|
||||
baseData.iconName,
|
||||
baseData.description,
|
||||
baseData.weight,
|
||||
itemInfo.isEquipped > 0,
|
||||
itemInfo.enchantLevel,
|
||||
casted ? static_cast<Enums::ArmorTypeEnum>(casted->armorType) : Enums::ArmorTypeEnum::none,
|
||||
@ -143,60 +384,61 @@ namespace Interlude
|
||||
setEffect,
|
||||
addSetEffect,
|
||||
enchantEffect
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
std::shared_ptr<Entities::BaseItem> CreateWeaponOrShield(
|
||||
const ItemData& itemInfo,
|
||||
const FL2ItemDataBase* itemData,
|
||||
const std::wstring& name,
|
||||
const std::wstring& icon,
|
||||
const std::wstring& description
|
||||
) const
|
||||
const ShieldData GetShieldData(const ItemData& itemInfo, const FL2WeaponItemData* itemData) const
|
||||
{
|
||||
const auto casted = static_cast<const FL2WeaponItemData*>(itemData);
|
||||
const auto& baseData = GetBaseData(itemInfo);
|
||||
|
||||
if (casted->weaponType != L2::WeaponType::SHIELD)
|
||||
{
|
||||
return std::make_shared<Entities::WeaponItem>(
|
||||
itemInfo.objectId,
|
||||
itemInfo.itemId,
|
||||
itemInfo.mana,
|
||||
name,
|
||||
icon,
|
||||
description,
|
||||
itemData ? itemData->weight : 0,
|
||||
itemInfo.isEquipped > 0,
|
||||
itemInfo.enchantLevel,
|
||||
casted ? static_cast<Enums::WeaponTypeEnum>(casted->weaponType) : Enums::WeaponTypeEnum::none,
|
||||
casted ? static_cast<Enums::CrystalTypeEnum>(casted->crystalType) : Enums::CrystalTypeEnum::none,
|
||||
casted ? casted->rndDamage : 0,
|
||||
m_EnchantHelper.GetPAttackEnchantValue(casted->weaponType, itemInfo.isTwoHanded, casted->crystalType, casted ? casted->pAttack : 0, itemInfo.enchantLevel),
|
||||
m_EnchantHelper.GetMAttackEnchantValue(casted->crystalType, casted ? casted->mAttack : 0, itemInfo.enchantLevel),
|
||||
casted ? casted->critical : 0,
|
||||
casted ? casted->hitModify : 0,
|
||||
casted ? casted->atkSpd : 0,
|
||||
casted ? casted->mpConsume : 0,
|
||||
casted ? casted->soulshotCount : 0,
|
||||
casted ? casted->spiritshotCount : 0
|
||||
);
|
||||
}
|
||||
|
||||
return std::make_shared<Entities::ShieldItem>(
|
||||
itemInfo.objectId,
|
||||
itemInfo.itemId,
|
||||
itemInfo.mana,
|
||||
name,
|
||||
icon,
|
||||
description,
|
||||
itemData ? itemData->weight : 0,
|
||||
return {
|
||||
baseData.objectId,
|
||||
baseData.itemId,
|
||||
baseData.mana,
|
||||
baseData.name,
|
||||
baseData.iconName,
|
||||
baseData.description,
|
||||
baseData.weight,
|
||||
itemInfo.isEquipped > 0,
|
||||
itemInfo.enchantLevel,
|
||||
casted ? static_cast<Enums::CrystalTypeEnum>(casted->crystalType) : Enums::CrystalTypeEnum::none,
|
||||
casted ? casted->shieldEvasion : 0,
|
||||
m_EnchantHelper.GetDefenseEnchantValue(casted ? casted->shieldPdef : 0, itemInfo.enchantLevel),
|
||||
casted ? casted->shieldDefRate : 0
|
||||
);
|
||||
itemData ? static_cast<Enums::CrystalTypeEnum>(itemData->crystalType) : Enums::CrystalTypeEnum::none,
|
||||
(int16_t)(itemData ? itemData->shieldEvasion : 0),
|
||||
m_EnchantHelper.GetDefenseEnchantValue(itemData ? itemData->shieldPdef : 0, itemInfo.enchantLevel),
|
||||
(uint16_t)(itemData ? itemData->shieldDefRate : 0)
|
||||
};
|
||||
}
|
||||
|
||||
const WeaponData GetWeaponData(const ItemData& itemInfo, const FL2WeaponItemData* itemData) const
|
||||
{
|
||||
const auto& baseData = GetBaseData(itemInfo);
|
||||
|
||||
return {
|
||||
baseData.objectId,
|
||||
baseData.itemId,
|
||||
baseData.mana,
|
||||
baseData.name,
|
||||
baseData.iconName,
|
||||
baseData.description,
|
||||
baseData.weight,
|
||||
itemInfo.isEquipped > 0,
|
||||
itemInfo.enchantLevel,
|
||||
itemData ? static_cast<Enums::WeaponTypeEnum>(itemData->weaponType) : Enums::WeaponTypeEnum::none,
|
||||
itemData ? static_cast<Enums::CrystalTypeEnum>(itemData->crystalType) : Enums::CrystalTypeEnum::none,
|
||||
(uint8_t)(itemData ? itemData->rndDamage : 0),
|
||||
m_EnchantHelper.GetPAttackEnchantValue(itemData->weaponType, itemInfo.isTwoHanded, itemData->crystalType, itemData ? itemData->pAttack : 0, itemInfo.enchantLevel),
|
||||
m_EnchantHelper.GetMAttackEnchantValue(itemData->crystalType, itemData ? itemData->mAttack : 0, itemInfo.enchantLevel),
|
||||
(uint16_t)(itemData ? itemData->critical : 0),
|
||||
(int8_t)(itemData ? itemData->hitModify : 0),
|
||||
(uint16_t)(itemData ? itemData->atkSpd : 0),
|
||||
(uint8_t)(itemData ? itemData->mpConsume : 0),
|
||||
(uint8_t)(itemData ? itemData->soulshotCount : 0),
|
||||
(uint8_t)(itemData ? itemData->spiritshotCount : 0)
|
||||
};
|
||||
}
|
||||
|
||||
const FL2ItemDataBase* GetItemData(const uint32_t itemId) const
|
||||
{
|
||||
return m_L2GameData.GetItemData(itemId);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -8,13 +8,52 @@ namespace Interlude
|
||||
{
|
||||
class NPCFactory
|
||||
{
|
||||
private:
|
||||
struct Data
|
||||
{
|
||||
uint32_t id;
|
||||
ValueObjects::Transform transform;
|
||||
bool isHostile;
|
||||
uint32_t npcId;
|
||||
ValueObjects::FullName fullName;
|
||||
ValueObjects::VitalStats vitalStats;
|
||||
};
|
||||
|
||||
public:
|
||||
NPCFactory() = default;
|
||||
virtual ~NPCFactory() = default;
|
||||
|
||||
std::shared_ptr<Entities::NPC> Create(const User* item, const Enums::SpoilStateEnum spoiledState) const
|
||||
std::shared_ptr<Entities::NPC> Create(const User* item) const
|
||||
{
|
||||
const auto& data = GetData(item);
|
||||
|
||||
return std::make_shared<Entities::NPC>(
|
||||
data.id,
|
||||
data.transform,
|
||||
data.isHostile,
|
||||
data.npcId,
|
||||
data.fullName,
|
||||
data.vitalStats
|
||||
);
|
||||
}
|
||||
|
||||
void Update(std::shared_ptr<Entities::NPC>& npc, const User* item) const
|
||||
{
|
||||
const auto& data = GetData(item);
|
||||
|
||||
npc->Update(
|
||||
data.transform,
|
||||
data.isHostile,
|
||||
data.npcId,
|
||||
data.fullName,
|
||||
data.vitalStats
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
const Data GetData(const User* item) const
|
||||
{
|
||||
return {
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
|
||||
@ -28,7 +67,6 @@ namespace Interlude
|
||||
),
|
||||
item->isMob != 0,
|
||||
item->npcId,
|
||||
spoiledState,
|
||||
ValueObjects::FullName(
|
||||
std::wstring(item->nickname),
|
||||
std::wstring(item->title)
|
||||
@ -38,7 +76,7 @@ namespace Interlude
|
||||
item->maxMp, item->mp,
|
||||
item->maxCp, item->cp
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
@ -8,13 +8,49 @@ namespace Interlude
|
||||
{
|
||||
class PlayerFactory
|
||||
{
|
||||
private:
|
||||
struct Data
|
||||
{
|
||||
uint32_t id;
|
||||
ValueObjects::Transform transform;
|
||||
ValueObjects::FullName fullName;
|
||||
ValueObjects::Phenotype phenotype;
|
||||
ValueObjects::VitalStats vitalStats;
|
||||
};
|
||||
|
||||
public:
|
||||
PlayerFactory() = default;
|
||||
virtual ~PlayerFactory() = default;
|
||||
|
||||
std::shared_ptr<Entities::Player> Create(const User* item) const
|
||||
{
|
||||
const auto& data = GetData(item);
|
||||
|
||||
return std::make_shared<Entities::Player>(
|
||||
data.id,
|
||||
data.transform,
|
||||
data.fullName,
|
||||
data.phenotype,
|
||||
data.vitalStats
|
||||
);
|
||||
}
|
||||
|
||||
void Update(std::shared_ptr<Entities::Player> &player, const User* item) const
|
||||
{
|
||||
const auto& data = GetData(item);
|
||||
|
||||
player->Update(
|
||||
data.transform,
|
||||
data.fullName,
|
||||
data.phenotype,
|
||||
data.vitalStats
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
const Data GetData(const User* item) const
|
||||
{
|
||||
return {
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
ValueObjects::Vector3(item->pawn->Location.x, item->pawn->Location.y, item->pawn->Location.z),
|
||||
@ -41,7 +77,7 @@ namespace Interlude
|
||||
item->maxMp, item->mp,
|
||||
item->maxCp, item->cp
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
@ -14,6 +14,19 @@ namespace Interlude
|
||||
{
|
||||
class SkillFactory
|
||||
{
|
||||
private:
|
||||
struct Data
|
||||
{
|
||||
uint32_t skillId;
|
||||
uint8_t level;
|
||||
bool isActive;
|
||||
uint8_t cost;
|
||||
int16_t range;
|
||||
std::wstring name;
|
||||
std::wstring description;
|
||||
std::wstring iconName;
|
||||
};
|
||||
|
||||
public:
|
||||
SkillFactory(const L2GameDataWrapper& l2GameData, const FName& fName) :
|
||||
m_L2GameData(l2GameData),
|
||||
@ -26,16 +39,37 @@ namespace Interlude
|
||||
|
||||
std::shared_ptr<Entities::Skill> Create(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
|
||||
{
|
||||
return std::make_shared<Entities::Skill>(BuildSkillData(skillId, level, isActive));
|
||||
const auto& data = GetData(skillId, level, isActive);
|
||||
|
||||
return std::make_shared<Entities::Skill>(
|
||||
data.skillId,
|
||||
data.level,
|
||||
data.isActive,
|
||||
data.cost,
|
||||
data.range,
|
||||
data.name,
|
||||
data.description,
|
||||
data.iconName
|
||||
);
|
||||
}
|
||||
|
||||
void Update(std::shared_ptr<Entities::Skill>& skill, const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
|
||||
{
|
||||
skill->Update(BuildSkillData(skillId, level, isActive));
|
||||
const auto& data = GetData(skillId, level, isActive);
|
||||
|
||||
skill->Update(
|
||||
data.level,
|
||||
data.isActive,
|
||||
data.cost,
|
||||
data.range,
|
||||
data.name,
|
||||
data.description,
|
||||
data.iconName
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
const Entities::Skill::Data BuildSkillData(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
|
||||
const Data GetData(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
|
||||
{
|
||||
const auto data = m_L2GameData.GetMSData(skillId, level);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <chrono>
|
||||
#include <shared_mutex>
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
@ -9,7 +9,6 @@
|
||||
#include "../../../Events/HeroDeletedEvent.h"
|
||||
#include "../../../Events/EventDispatcher.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -18,27 +17,15 @@ namespace Interlude
|
||||
class AbnormalEffectRepository : public Repositories::EntityRepositoryInterface
|
||||
{
|
||||
public:
|
||||
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override
|
||||
const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
|
||||
const auto objects = m_EntityFinder.FindEntities<std::shared_ptr<Entities::AbnormalEffect>>(m_Effects, [this](std::shared_ptr<Entities::AbnormalEffect> item) {
|
||||
return std::make_shared<Entities::AbnormalEffect>(item.get());
|
||||
});
|
||||
|
||||
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
|
||||
|
||||
for (const auto kvp : objects)
|
||||
{
|
||||
result.push_back(kvp.second);
|
||||
}
|
||||
|
||||
return result;
|
||||
return m_Effects;
|
||||
}
|
||||
|
||||
AbnormalEffectRepository(const AbnormalEffectFactory& factory, EntityFinder& finder) :
|
||||
m_Factory(factory),
|
||||
m_EntityFinder(finder)
|
||||
AbnormalEffectRepository(const AbnormalEffectFactory& factory) :
|
||||
m_Factory(factory)
|
||||
{
|
||||
EventDispatcher::GetInstance().Subscribe(AbnormalEffectChangedEvent::name, [this](const Event& evt) {
|
||||
OnEffectToggled(evt);
|
||||
@ -75,40 +62,48 @@ namespace Interlude
|
||||
if (evt.GetName() == AbnormalEffectChangedEvent::name)
|
||||
{
|
||||
const auto casted = static_cast<const AbnormalEffectChangedEvent&>(evt);
|
||||
const auto skillInfo = casted.GetSkillInfo();
|
||||
|
||||
const auto &actualIds = Create(casted.GetSkillInfo());
|
||||
Delete(actualIds);
|
||||
}
|
||||
}
|
||||
|
||||
std::map<uint32_t, int32_t> ids;
|
||||
for (size_t i = 0; i < skillInfo.size(); i += 3)
|
||||
private:
|
||||
const std::unordered_map<uint32_t, int32_t> Create(const std::vector<int32_t> &skillInfo)
|
||||
{
|
||||
std::unordered_map<uint32_t, int32_t> ids;
|
||||
|
||||
for (size_t i = 0; i < skillInfo.size(); i += 3)
|
||||
{
|
||||
const auto effectId = skillInfo[i];
|
||||
const auto level = skillInfo[i + 1];
|
||||
|
||||
m_Effects[effectId] = m_Factory.Create(effectId, level);
|
||||
|
||||
ids[effectId] = effectId;
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
void Delete(const std::unordered_map<uint32_t, int32_t> &actualIds)
|
||||
{
|
||||
for (auto it = m_Effects.begin(); it != m_Effects.end();)
|
||||
{
|
||||
if (actualIds.find(it->second->GetId()) == actualIds.end())
|
||||
{
|
||||
const auto effectId = skillInfo[i];
|
||||
const auto level = skillInfo[i + 1];
|
||||
|
||||
auto effect = m_Factory.Create(effectId, level);
|
||||
m_Effects.emplace(effect->GetId(), effect);
|
||||
|
||||
ids[effectId] = effectId;
|
||||
it = m_Effects.erase(it);
|
||||
}
|
||||
|
||||
for (auto it = m_Effects.begin(); it != m_Effects.end();)
|
||||
else
|
||||
{
|
||||
const auto& effect = it->second;
|
||||
|
||||
if (ids.find(effect->GetId()) == ids.end())
|
||||
{
|
||||
it = m_Effects.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const AbnormalEffectFactory& m_Factory;
|
||||
std::map<uint32_t, std::shared_ptr<Entities::AbnormalEffect>> m_Effects;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Entities::EntityInterface>> m_Effects;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
EntityFinder& m_EntityFinder;
|
||||
};
|
||||
}
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include <vector>
|
||||
#include <shared_mutex>
|
||||
#include "Domain/Repositories/ChatMessageRepositoryInterface.h"
|
||||
#include "../Factories/ChatMessageFactory.h"
|
||||
#include "../../../Events/ChatMessageCreatedEvent.h"
|
||||
#include "../../../Events/EventDispatcher.h"
|
||||
@ -11,17 +10,20 @@ using namespace L2Bot::Domain;
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
class ChatMessageRepository : public Repositories::ChatMessageRepositoryInterface
|
||||
class ChatMessageRepository : public Repositories::EntityRepositoryInterface
|
||||
{
|
||||
public:
|
||||
const std::vector<ValueObjects::ChatMessage> GetMessages() override
|
||||
const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
|
||||
const auto result = m_Messages;
|
||||
m_Messages.clear();
|
||||
return m_Messages;
|
||||
}
|
||||
|
||||
return result;
|
||||
void Reset()
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
m_Messages.clear();
|
||||
}
|
||||
|
||||
ChatMessageRepository(const ChatMessageFactory& factory) :
|
||||
@ -39,7 +41,8 @@ namespace Interlude
|
||||
{
|
||||
const auto casted = static_cast<const ChatMessageCreatedEvent&>(evt);
|
||||
|
||||
m_Messages.push_back(m_Factory.Create(casted.GetChatMessage()));
|
||||
const auto message = m_Factory.Create(casted.GetChatMessage());
|
||||
m_Messages[message->GetId()] = message;
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +51,7 @@ namespace Interlude
|
||||
|
||||
private:
|
||||
const ChatMessageFactory& m_Factory;
|
||||
std::vector<ValueObjects::ChatMessage> m_Messages;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Entities::EntityInterface>> m_Messages;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
};
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
#include <shared_mutex>
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
@ -8,7 +8,6 @@
|
||||
#include "../Factories/DropFactory.h"
|
||||
#include "../../GameStructs/FindObjectsTrait.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -17,22 +16,25 @@ namespace Interlude
|
||||
class DropRepository : public Repositories::EntityRepositoryInterface, public FindObjectsTrait
|
||||
{
|
||||
public:
|
||||
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override
|
||||
const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
|
||||
const std::map<uint32_t, Item*> items = FindAllObjects<Item*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
const auto allItems = FindAllObjects<Item*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
return m_NetworkHandler.GetNextItem(radius, prevId);
|
||||
});
|
||||
const auto objects = m_EntityFinder.FindEntities<Item*>(items, [this](Item* item) {
|
||||
return m_Factory.Create(item);
|
||||
});
|
||||
|
||||
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
|
||||
|
||||
for (const auto kvp : objects)
|
||||
{
|
||||
result.push_back(kvp.second);
|
||||
std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> result;
|
||||
for (const auto kvp : allItems) {
|
||||
const auto item = kvp.second;
|
||||
if (m_Drops.find(item->objectId) == m_Drops.end()) {
|
||||
m_Drops[item->objectId] = m_Factory.Create(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Factory.Update(m_Drops[item->objectId], item);
|
||||
}
|
||||
result[item->objectId] = m_Drops[item->objectId];
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -41,14 +43,13 @@ namespace Interlude
|
||||
void Reset() override
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
m_EntityFinder.Reset();
|
||||
m_Drops.clear();
|
||||
}
|
||||
|
||||
DropRepository(const NetworkHandlerWrapper& networkHandler, const DropFactory& factory, EntityFinder& finder, const uint16_t radius) :
|
||||
DropRepository(const NetworkHandlerWrapper& networkHandler, const DropFactory& factory, const uint16_t radius) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_Radius(radius),
|
||||
m_EntityFinder(finder)
|
||||
m_Radius(radius)
|
||||
{
|
||||
|
||||
}
|
||||
@ -60,7 +61,7 @@ namespace Interlude
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
const DropFactory& m_Factory;
|
||||
const uint16_t m_Radius;
|
||||
EntityFinder& m_EntityFinder;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Entities::Drop>> m_Drops;
|
||||
};
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include "../../../Events/HeroCreatedEvent.h"
|
||||
#include "../../../Events/HeroDeletedEvent.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -16,39 +15,28 @@ namespace Interlude
|
||||
class HeroRepository : public Repositories::EntityRepositoryInterface
|
||||
{
|
||||
public:
|
||||
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override
|
||||
const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
|
||||
auto hero = m_NetworkHandler.GetHero();
|
||||
const auto hero = m_NetworkHandler.GetHero();
|
||||
|
||||
if (hero != nullptr && m_PrevHero == nullptr)
|
||||
{
|
||||
EventDispatcher::GetInstance().Dispatch(HeroCreatedEvent{});
|
||||
std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> result;
|
||||
if (hero) {
|
||||
if (!m_Hero) {
|
||||
m_Hero = m_Factory.Create(hero);
|
||||
EventDispatcher::GetInstance().Dispatch(HeroCreatedEvent{});
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Factory.Update(m_Hero, hero);
|
||||
}
|
||||
result[hero->objectId] = m_Hero;
|
||||
}
|
||||
if (hero == nullptr && m_PrevHero != nullptr)
|
||||
{
|
||||
else {
|
||||
m_Hero = nullptr;
|
||||
EventDispatcher::GetInstance().Dispatch(HeroDeletedEvent{});
|
||||
}
|
||||
m_PrevHero = hero;
|
||||
|
||||
std::map<uint32_t, User*> items;
|
||||
|
||||
if (hero)
|
||||
{
|
||||
items.emplace(hero->objectId, hero);
|
||||
}
|
||||
|
||||
const auto objects = m_EntityFinder.FindEntities<User*>(items, [this](User* item) {
|
||||
return m_Factory.Create(item);
|
||||
});
|
||||
|
||||
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
|
||||
|
||||
for (const auto kvp : objects)
|
||||
{
|
||||
result.push_back(kvp.second);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -56,13 +44,12 @@ namespace Interlude
|
||||
void Reset() override
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
m_EntityFinder.Reset();
|
||||
m_Hero = nullptr;
|
||||
}
|
||||
|
||||
HeroRepository(const NetworkHandlerWrapper& networkHandler, const HeroFactory& factory, EntityFinder& finder) :
|
||||
HeroRepository(const NetworkHandlerWrapper& networkHandler, const HeroFactory& factory) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_EntityFinder(finder)
|
||||
m_Factory(factory)
|
||||
{
|
||||
|
||||
}
|
||||
@ -73,8 +60,6 @@ namespace Interlude
|
||||
private:
|
||||
const HeroFactory& m_Factory;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
User* m_PrevHero = nullptr;
|
||||
EntityFinder& m_EntityFinder;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
std::shared_ptr<Entities::Hero> m_Hero;
|
||||
};
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <chrono>
|
||||
#include <shared_mutex>
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
#include "../Factories/ItemFactory.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
#include "../../../Events/ItemCreatedEvent.h"
|
||||
#include "../../../Events/ItemUpdatedEvent.h"
|
||||
#include "../../../Events/ItemDeletedEvent.h"
|
||||
@ -22,21 +21,11 @@ namespace Interlude
|
||||
class ItemRepository : public Repositories::EntityRepositoryInterface
|
||||
{
|
||||
public:
|
||||
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override
|
||||
const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
|
||||
const auto objects = m_EntityFinder.FindEntities<std::shared_ptr<Entities::BaseItem>>(m_Items, [this](std::shared_ptr<Entities::BaseItem> item) {
|
||||
return m_Factory.Copy(item);
|
||||
});
|
||||
|
||||
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
|
||||
|
||||
for (const auto kvp : objects)
|
||||
{
|
||||
result.push_back(kvp.second);
|
||||
}
|
||||
|
||||
std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> result(m_Items.begin(), m_Items.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -51,10 +40,9 @@ namespace Interlude
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ItemRepository(const NetworkHandlerWrapper& networkHandler, const ItemFactory& factory, EntityFinder& finder) :
|
||||
ItemRepository(const NetworkHandlerWrapper& networkHandler, const ItemFactory& factory) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_EntityFinder(finder)
|
||||
m_Factory(factory)
|
||||
{
|
||||
EventDispatcher::GetInstance().Subscribe(ItemCreatedEvent::name, [this](const Event& evt) {
|
||||
OnItemCreated(evt);
|
||||
@ -121,10 +109,13 @@ namespace Interlude
|
||||
{
|
||||
if (kvp.second->GetItemId() == itemId)
|
||||
{
|
||||
auto ptr = dynamic_cast<Entities::EtcItem*>(kvp.second.get());
|
||||
if (ptr)
|
||||
auto casted = std::dynamic_pointer_cast<Entities::EtcItem>(kvp.second);
|
||||
if (isEnabled) {
|
||||
casted->StartAutouse();
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr->Autouse(isEnabled);
|
||||
casted->StopAutouse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -145,15 +136,18 @@ namespace Interlude
|
||||
const auto casted = static_cast<const ItemCreatedEvent&>(evt);
|
||||
const auto& data = casted.GetItemData();
|
||||
|
||||
auto item = m_Factory.Create(data);
|
||||
|
||||
if (m_Items.find(data.objectId) == m_Items.end())
|
||||
{
|
||||
m_Items.emplace(data.objectId, item);
|
||||
auto item = m_Factory.Create(data);
|
||||
if (item) {
|
||||
m_Items[data.objectId] = item;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// When equip/unequip accessories
|
||||
m_Items[data.objectId]->Update(item.get());
|
||||
m_Factory.Update(m_Items[data.objectId], data);
|
||||
}
|
||||
m_NewItems[data.objectId] = data.objectId;
|
||||
}
|
||||
@ -173,8 +167,7 @@ namespace Interlude
|
||||
return;
|
||||
}
|
||||
|
||||
auto item = m_Factory.Create(data);
|
||||
m_Items[data.objectId]->Update(item.get());
|
||||
m_Factory.Update(m_Items[data.objectId], data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,12 +200,11 @@ namespace Interlude
|
||||
|
||||
private:
|
||||
const ItemFactory& m_Factory;
|
||||
std::map<uint32_t, std::shared_ptr<Entities::BaseItem>> m_Items;
|
||||
std::map<uint32_t, uint32_t> m_NewItems;
|
||||
std::unordered_map<std::uint32_t, std::shared_ptr<Entities::BaseItem>> m_Items;
|
||||
std::unordered_map<std::uint32_t, std::uint32_t> m_NewItems;
|
||||
bool m_IsNewCycle = true;
|
||||
uint32_t m_UsedSkillId = 0;
|
||||
std::uint32_t m_UsedSkillId = 0;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
EntityFinder& m_EntityFinder;
|
||||
};
|
||||
}
|
@ -9,7 +9,6 @@
|
||||
#include "../../../Events/SpoiledEvent.h"
|
||||
#include "../../../Events/CreatureDiedEvent.h"
|
||||
#include "../../GameStructs/FindObjectsTrait.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -18,33 +17,33 @@ namespace Interlude
|
||||
class NPCRepository : public Repositories::EntityRepositoryInterface, public FindObjectsTrait
|
||||
{
|
||||
public:
|
||||
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override
|
||||
const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
|
||||
const auto creatures = FindAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
const auto allCreatures = FindAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
return m_NetworkHandler.GetNextCreature(radius, prevId);
|
||||
});
|
||||
|
||||
std::map<uint32_t, User*> items;
|
||||
for (const auto& kvp : creatures)
|
||||
{
|
||||
std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> result;
|
||||
for (const auto kvp : allCreatures) {
|
||||
const auto creature = kvp.second;
|
||||
if (creature->userType == L2::UserType::NPC) {
|
||||
items.emplace(creature->objectId, creature);
|
||||
if (creature->userType != L2::UserType::NPC) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
if (m_Npcs.find(creature->objectId) == m_Npcs.end()) {
|
||||
m_Npcs[creature->objectId] = m_Factory.Create(creature);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Factory.Update(m_Npcs[creature->objectId], creature);
|
||||
}
|
||||
|
||||
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
|
||||
const auto spoilState = m_Spoiled.find(creature->objectId) == m_Spoiled.end() ? Enums::SpoilStateEnum::none : m_Spoiled[creature->objectId];
|
||||
m_Npcs[creature->objectId]->UpdateSpoilState(spoilState);
|
||||
|
||||
for (const auto kvp : objects)
|
||||
{
|
||||
result.push_back(kvp.second);
|
||||
result[creature->objectId] = m_Npcs[creature->objectId];
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -53,14 +52,13 @@ namespace Interlude
|
||||
void Reset() override
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
m_EntityFinder.Reset();
|
||||
m_Npcs.clear();
|
||||
}
|
||||
|
||||
NPCRepository(const NetworkHandlerWrapper& networkHandler, const NPCFactory& factory, EntityFinder& finder, const uint16_t radius) :
|
||||
NPCRepository(const NetworkHandlerWrapper& networkHandler, const NPCFactory& factory, const uint16_t radius) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_Radius(radius),
|
||||
m_EntityFinder(finder)
|
||||
m_Radius(radius)
|
||||
{
|
||||
EventDispatcher::GetInstance().Subscribe(SpoiledEvent::name, [this](const Event& evt) {
|
||||
OnSpoiled(evt);
|
||||
@ -75,6 +73,7 @@ namespace Interlude
|
||||
|
||||
void OnSpoiled(const Event& evt)
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
if (evt.GetName() == SpoiledEvent::name)
|
||||
{
|
||||
const auto casted = static_cast<const SpoiledEvent&>(evt);
|
||||
@ -92,6 +91,7 @@ namespace Interlude
|
||||
|
||||
void OnCreatureDied(const Event& evt)
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
if (evt.GetName() == CreatureDiedEvent::name)
|
||||
{
|
||||
const auto casted = static_cast<const CreatureDiedEvent&>(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;
|
||||
EntityFinder& m_EntityFinder;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Entities::NPC>> m_Npcs;
|
||||
};
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
#include "../Factories/PlayerFactory.h"
|
||||
#include "../../GameStructs/FindObjectsTrait.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -14,32 +12,29 @@ namespace Interlude
|
||||
class PlayerRepository : public Repositories::EntityRepositoryInterface, public FindObjectsTrait
|
||||
{
|
||||
public:
|
||||
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override
|
||||
const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
|
||||
const auto creatures = FindAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
const auto allCreatures = FindAllObjects<User*>(m_Radius, [this](float_t radius, int32_t prevId) {
|
||||
return m_NetworkHandler.GetNextCreature(radius, prevId);
|
||||
});
|
||||
|
||||
std::map<uint32_t, User*> items;
|
||||
for (const auto& kvp : creatures)
|
||||
std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> result;
|
||||
for (const auto& kvp : allCreatures)
|
||||
{
|
||||
const auto creature = kvp.second;
|
||||
if (creature->userType == L2::UserType::USER && creature->lvl == 0) {
|
||||
items.emplace(creature->objectId, creature);
|
||||
const auto &creature = kvp.second;
|
||||
if (creature->userType != L2::UserType::USER || creature->lvl != 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const auto objects = m_EntityFinder.FindEntities<User*>(items, [this](User* item) {
|
||||
return m_Factory.Create(item);
|
||||
});
|
||||
if (m_Players.find(creature->objectId) == m_Players.end()) {
|
||||
m_Players[creature->objectId] = m_Factory.Create(creature);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Factory.Update(m_Players[creature->objectId], creature);
|
||||
}
|
||||
|
||||
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
|
||||
|
||||
for (const auto kvp : objects)
|
||||
{
|
||||
result.push_back(kvp.second);
|
||||
result[creature->objectId] = m_Players[creature->objectId];
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -48,14 +43,13 @@ namespace Interlude
|
||||
void Reset() override
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
m_EntityFinder.Reset();
|
||||
m_Players.clear();
|
||||
}
|
||||
|
||||
PlayerRepository(const NetworkHandlerWrapper& networkHandler, const PlayerFactory& factory, EntityFinder& finder, const uint16_t radius) :
|
||||
PlayerRepository(const NetworkHandlerWrapper& networkHandler, const PlayerFactory& factory, const uint16_t radius) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_Radius(radius),
|
||||
m_EntityFinder(finder)
|
||||
m_Radius(radius)
|
||||
{
|
||||
|
||||
}
|
||||
@ -67,7 +61,6 @@ namespace Interlude
|
||||
const PlayerFactory& m_Factory;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
const uint16_t m_Radius;
|
||||
EntityFinder& m_EntityFinder;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Entities::Player>> m_Players;
|
||||
};
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <chrono>
|
||||
#include <shared_mutex>
|
||||
#include "Domain/Repositories/EntityRepositoryInterface.h"
|
||||
@ -14,7 +14,6 @@
|
||||
#include "../../../Events/EventDispatcher.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "../../../Common/TimerMap.h"
|
||||
#include "../../../Services/EntityFinder.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -23,28 +22,17 @@ namespace Interlude
|
||||
class SkillRepository : public Repositories::EntityRepositoryInterface
|
||||
{
|
||||
public:
|
||||
const std::vector<std::shared_ptr<DTO::EntityState>> GetEntities() override
|
||||
const std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> GetEntities() override
|
||||
{
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
|
||||
const auto objects = m_EntityFinder.FindEntities<std::shared_ptr<Entities::Skill>>(m_Skills, [this](std::shared_ptr<Entities::Skill> item) {
|
||||
return std::make_shared<Entities::Skill>(item.get());
|
||||
});
|
||||
|
||||
auto result = std::vector<std::shared_ptr<DTO::EntityState>>();
|
||||
|
||||
for (const auto kvp : objects)
|
||||
{
|
||||
result.push_back(kvp.second);
|
||||
}
|
||||
|
||||
std::unordered_map<std::uint32_t, std::shared_ptr<Entities::EntityInterface>> result(m_Skills.begin(), m_Skills.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
SkillRepository(const NetworkHandlerWrapper& networkHandler, const SkillFactory& factory, EntityFinder& finder) :
|
||||
SkillRepository(const NetworkHandlerWrapper& networkHandler, const SkillFactory& factory) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory),
|
||||
m_EntityFinder(finder)
|
||||
m_Factory(factory)
|
||||
{
|
||||
EventDispatcher::GetInstance().Subscribe(SkillCreatedEvent::name, [this](const Event& evt) {
|
||||
OnSkillCreated(evt);
|
||||
@ -130,17 +118,17 @@ namespace Interlude
|
||||
|
||||
if (m_Skills.find(skillId) == m_Skills.end())
|
||||
{
|
||||
auto skill = m_Factory.Create(
|
||||
m_Skills[skillId] = m_Factory.Create(
|
||||
skillInfo[2],
|
||||
skillInfo[1],
|
||||
skillInfo[0]
|
||||
);
|
||||
m_Skills[skill->GetId()] = skill;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto skill = m_Skills[skillId];
|
||||
m_Factory.Update(
|
||||
m_Skills[skillId],
|
||||
skill,
|
||||
skillInfo[2],
|
||||
skillInfo[1],
|
||||
skillInfo[0]
|
||||
@ -198,10 +186,8 @@ namespace Interlude
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& skill = m_Skills[m_UsedSkillId];
|
||||
|
||||
skill->StopCasting();
|
||||
m_CastingTimers.StopTimer(skill->GetId());
|
||||
m_Skills[m_UsedSkillId]->StopCasting();
|
||||
m_CastingTimers.StopTimer(m_UsedSkillId);
|
||||
|
||||
m_UsedSkillId = 0;
|
||||
}
|
||||
@ -215,7 +201,7 @@ namespace Interlude
|
||||
const auto casted = static_cast<const AbnormalEffectChangedEvent&>(evt);
|
||||
const auto skillInfo = casted.GetSkillInfo();
|
||||
|
||||
std::map<uint32_t, int32_t> ids;
|
||||
std::unordered_map<uint32_t, int32_t> ids;
|
||||
|
||||
for (size_t i = 0; i < skillInfo.size(); i += 3)
|
||||
{
|
||||
@ -244,14 +230,13 @@ namespace Interlude
|
||||
|
||||
private:
|
||||
const SkillFactory& m_Factory;
|
||||
std::map<uint32_t, std::shared_ptr<Entities::Skill>> m_Skills;
|
||||
std::map<uint32_t, uint32_t> m_NewSkills;
|
||||
std::unordered_map<std::uint32_t, std::shared_ptr<Entities::Skill>> m_Skills;
|
||||
std::unordered_map<std::uint32_t, std::uint32_t> m_NewSkills;
|
||||
bool m_IsNewCycle = true;
|
||||
uint32_t m_UsedSkillId = 0;
|
||||
const NetworkHandlerWrapper& m_NetworkHandler;
|
||||
TimerMap m_ReloadingTimers;
|
||||
TimerMap m_CastingTimers;
|
||||
std::shared_timed_mutex m_Mutex;
|
||||
EntityFinder& m_EntityFinder;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user