feat: add exceptions
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
#include "../GameStructs/FName.h"
|
||||
#include "../../../Common/Common.h"
|
||||
#include "Domain/Entities/AbnormalEffect.h"
|
||||
#include "Domain/Exceptions.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -28,15 +29,17 @@ namespace Interlude
|
||||
{
|
||||
const auto data = m_L2GameData.GetMSData(skillId, level);
|
||||
|
||||
const auto name = data && data->name ? data->name : L"";
|
||||
const auto description = data && data->description ? data->description : L"";
|
||||
const auto iconEntry = data ? m_FName.GetEntry(data->iconNameIndex) : nullptr;
|
||||
if (!data) {
|
||||
throw RuntimeException(std::format(L"cannot load MSData for abnormal effect {}", skillId));
|
||||
}
|
||||
|
||||
const auto iconEntry = m_FName.GetEntry(data->iconNameIndex);
|
||||
|
||||
return std::make_shared<Entities::AbnormalEffect>(
|
||||
skillId,
|
||||
static_cast<uint8_t>(level),
|
||||
std::wstring(name),
|
||||
std::wstring(description),
|
||||
data->name ? std::wstring(data->name) : L"",
|
||||
data->description ? std::wstring(data->description) : L"",
|
||||
iconEntry ? std::wstring(iconEntry->value) : L""
|
||||
);
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <format>
|
||||
#include "../GameStructs/L2GameDataWrapper.h"
|
||||
#include "../GameStructs/FName.h"
|
||||
#include "../GameStructs/GameStructs.h"
|
||||
#include "../../../Common/Common.h"
|
||||
#include "Domain/Entities/Drop.h"
|
||||
#include "Domain/Exceptions.h"
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
@ -63,8 +65,15 @@ namespace Interlude
|
||||
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;
|
||||
if (!itemData) {
|
||||
throw RuntimeException(std::format(L"cannot load ItemData for drop {}", item->itemId));
|
||||
}
|
||||
const auto nameEntry = m_FName.GetEntry(itemData->nameIndex);
|
||||
const auto iconEntry = m_FName.GetEntry(itemData->iconNameIndex);
|
||||
|
||||
if (!item->pawn) {
|
||||
throw RuntimeException(std::format(L"pawn is empty for drop {}", std::wstring(nameEntry->value)));
|
||||
}
|
||||
|
||||
return {
|
||||
item->objectId,
|
||||
|
@ -1,9 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <format>
|
||||
#include "../GameStructs/GameStructs.h"
|
||||
#include "../../../Common/Common.h"
|
||||
#include "Domain/Entities/Hero.h"
|
||||
#include "Domain/Exceptions.h"
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
@ -72,73 +74,79 @@ namespace Interlude
|
||||
private:
|
||||
const Data GetData(const User* item) const
|
||||
{
|
||||
const auto playerController = item->pawn ? item->pawn->lineagePlayerController : nullptr;
|
||||
if (!item->pawn) {
|
||||
throw RuntimeException(std::format(L"pawn is empty for hero {}", item->nickname));
|
||||
}
|
||||
const auto playerController = item->pawn->lineagePlayerController;
|
||||
if (!playerController) {
|
||||
throw RuntimeException(std::format(L"player controller is empty for hero {}", item->nickname));
|
||||
}
|
||||
|
||||
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::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::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
|
||||
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->targetObjectId,
|
||||
playerController->isStanding == 1
|
||||
};
|
||||
}
|
||||
};
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "Domain/Entities/ShieldItem.h"
|
||||
#include "Domain/DTO/ItemData.h"
|
||||
#include "../Helpers/EnchantHelper.h"
|
||||
#include "Domain/Exceptions.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -92,39 +93,37 @@ namespace Interlude
|
||||
{
|
||||
//FIXME during first start data may be undefined
|
||||
const auto data = GetItemData(itemInfo.itemId);
|
||||
|
||||
if (data)
|
||||
if (!data) {
|
||||
throw RuntimeException(std::format(L"cannot load ItemData for item {}", itemInfo.itemId));
|
||||
}
|
||||
|
||||
switch (data->dataType)
|
||||
{
|
||||
switch (data->dataType)
|
||||
{
|
||||
case L2::ItemDataType::ARMOR:
|
||||
return CreateArmor(itemInfo);
|
||||
case L2::ItemDataType::WEAPON:
|
||||
return CreateWeaponOrShield(itemInfo);
|
||||
}
|
||||
|
||||
return CreateEtc(itemInfo);
|
||||
case L2::ItemDataType::ARMOR:
|
||||
return CreateArmor(itemInfo);
|
||||
case L2::ItemDataType::WEAPON:
|
||||
return CreateWeaponOrShield(itemInfo, static_cast<const FL2WeaponItemData*>(data));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return CreateEtc(itemInfo);
|
||||
}
|
||||
|
||||
void Update(std::shared_ptr<Entities::BaseItem>& item, const DTO::ItemData& itemInfo) const
|
||||
{
|
||||
//FIXME during first start data may be undefined
|
||||
const auto data = GetItemData(itemInfo.itemId);
|
||||
|
||||
if (data)
|
||||
if (!data) {
|
||||
throw RuntimeException(std::format(L"cannot load ItemData for item {}", itemInfo.itemId));
|
||||
}
|
||||
|
||||
switch (data->dataType)
|
||||
{
|
||||
switch (data->dataType)
|
||||
{
|
||||
case L2::ItemDataType::ARMOR:
|
||||
UpdateArmor(item, itemInfo);
|
||||
return;
|
||||
case L2::ItemDataType::WEAPON:
|
||||
UpdateWeaponOrShield(item, itemInfo);
|
||||
return;
|
||||
}
|
||||
case L2::ItemDataType::ARMOR:
|
||||
UpdateArmor(item, itemInfo);
|
||||
return;
|
||||
case L2::ItemDataType::WEAPON:
|
||||
UpdateWeaponOrShield(item, itemInfo, static_cast<const FL2WeaponItemData*>(data));
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateEtc(item, itemInfo);
|
||||
@ -215,10 +214,8 @@ namespace Interlude
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<Entities::BaseItem> CreateWeaponOrShield(const DTO::ItemData& itemInfo) const
|
||||
std::shared_ptr<Entities::BaseItem> CreateWeaponOrShield(const DTO::ItemData& itemInfo, const FL2WeaponItemData* itemData) const
|
||||
{
|
||||
const auto itemData = static_cast<const FL2WeaponItemData*>(GetItemData(itemInfo.itemId));
|
||||
|
||||
if (itemData->weaponType != L2::WeaponType::SHIELD)
|
||||
{
|
||||
const auto& data = GetWeaponData(itemInfo, itemData);
|
||||
@ -266,10 +263,8 @@ namespace Interlude
|
||||
);
|
||||
}
|
||||
|
||||
void UpdateWeaponOrShield(std::shared_ptr<Entities::BaseItem>& item, const DTO::ItemData& itemInfo) const
|
||||
void UpdateWeaponOrShield(std::shared_ptr<Entities::BaseItem>& item, const DTO::ItemData& itemInfo, const FL2WeaponItemData* itemData) 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);
|
||||
@ -322,21 +317,20 @@ namespace Interlude
|
||||
const BaseData GetBaseData(const DTO::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"";
|
||||
const auto iconEntry = data ? m_FName.GetEntry(data->iconNameIndex) : nullptr;
|
||||
const auto icon = iconEntry ? std::wstring(iconEntry->value) : L"";
|
||||
const auto description = data && data->description ? std::wstring(data->description) : L"";
|
||||
if (!data) {
|
||||
throw RuntimeException(std::format(L"cannot load ItemData for item {}", itemInfo.itemId));
|
||||
}
|
||||
const auto nameEntry = m_FName.GetEntry(data->nameIndex);
|
||||
const auto iconEntry = m_FName.GetEntry(data->iconNameIndex);
|
||||
|
||||
return {
|
||||
itemInfo.objectId,
|
||||
itemInfo.itemId,
|
||||
itemInfo.mana,
|
||||
name,
|
||||
icon,
|
||||
description,
|
||||
(uint16_t)(data ? data->weight : 0)
|
||||
nameEntry ? std::wstring(nameEntry->value) : L"",
|
||||
iconEntry ? std::wstring(iconEntry->value) : L"",
|
||||
data->description ? std::wstring(data->description) : L"",
|
||||
static_cast<uint16_t>(data->weight)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <format>
|
||||
#include "../../../Common/Common.h"
|
||||
#include "Domain/Entities/NPC.h"
|
||||
#include "Domain/Exceptions.h"
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
@ -53,6 +55,9 @@ namespace Interlude
|
||||
private:
|
||||
const Data GetData(const User* item) const
|
||||
{
|
||||
if (!item->pawn) {
|
||||
throw RuntimeException(std::format(L"pawn is empty for npc {}", item->nickname));
|
||||
}
|
||||
return {
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
|
@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <format>
|
||||
#include "../../../Common/Common.h"
|
||||
#include "Domain/Entities/Player.h"
|
||||
#include "Domain/Exceptions.h"
|
||||
|
||||
namespace Interlude
|
||||
{
|
||||
@ -50,6 +52,9 @@ namespace Interlude
|
||||
private:
|
||||
const Data GetData(const User* item) const
|
||||
{
|
||||
if (!item->pawn) {
|
||||
throw RuntimeException(std::format(L"pawn is empty for player {}", item->nickname));
|
||||
}
|
||||
return {
|
||||
item->objectId,
|
||||
ValueObjects::Transform(
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "../GameStructs/FName.h"
|
||||
#include "../../../Common/Common.h"
|
||||
#include "Domain/Entities/Skill.h"
|
||||
#include "Domain/Exceptions.h"
|
||||
|
||||
using namespace L2Bot::Domain;
|
||||
|
||||
@ -72,21 +73,20 @@ namespace Interlude
|
||||
const Data GetData(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
|
||||
{
|
||||
const auto data = m_L2GameData.GetMSData(skillId, level);
|
||||
if (!data) {
|
||||
throw RuntimeException(std::format(L"cannot load MSData for skill {}", skillId));
|
||||
}
|
||||
|
||||
const auto cost = data ? data->mpCost : 0;
|
||||
const auto range = data ? data->range : 0;
|
||||
const auto name = data && data->name ? data->name : L"";
|
||||
const auto description = data && data->description ? data->description : L"";
|
||||
const auto iconEntry = data ? m_FName.GetEntry(data->iconNameIndex) : nullptr;
|
||||
const auto iconEntry = m_FName.GetEntry(data->iconNameIndex);
|
||||
|
||||
return {
|
||||
skillId,
|
||||
static_cast<uint8_t>(level),
|
||||
isActive != 1,
|
||||
static_cast<uint8_t>(cost),
|
||||
static_cast<int16_t>(range),
|
||||
std::wstring(name),
|
||||
std::wstring(description),
|
||||
static_cast<uint8_t>(data->mpCost),
|
||||
static_cast<int16_t>(data->range),
|
||||
data->name ? std::wstring(data->name) : L"",
|
||||
data->description ? std::wstring(data->description) : L"",
|
||||
iconEntry ? std::wstring(iconEntry->value) : L"",
|
||||
};
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "../Factories/HeroFactory.h"
|
||||
#include "Domain/Events/HeroCreatedEvent.h"
|
||||
#include "Domain/Events/HeroDeletedEvent.h"
|
||||
#include "Domain/Events/CreatureDiedEvent.h"
|
||||
#include "../GameStructs/NetworkHandlerWrapper.h"
|
||||
#include "Domain/Services/ServiceLocator.h"
|
||||
|
||||
@ -49,6 +50,21 @@ namespace Interlude
|
||||
m_Hero = nullptr;
|
||||
}
|
||||
|
||||
void Init() override
|
||||
{
|
||||
Services::ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(Events::CreatureDiedEvent::name, [this](const Events::Event& evt) {
|
||||
std::unique_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
if (evt.GetName() == Events::CreatureDiedEvent::name)
|
||||
{
|
||||
const auto casted = static_cast<const Events::CreatureDiedEvent&>(evt);
|
||||
if (m_Hero && m_Hero->GetId() == casted.GetCreatureId())
|
||||
{
|
||||
Services::ServiceLocator::GetInstance().GetLogger()->App(L"{} died", m_Hero->GetFullName().GetNickname());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
HeroRepository(const NetworkHandlerWrapper& networkHandler, const HeroFactory& factory) :
|
||||
m_NetworkHandler(networkHandler),
|
||||
m_Factory(factory)
|
||||
|
Reference in New Issue
Block a user