refactor: change skill updating
This commit is contained in:
parent
ac7bde68e9
commit
a7a9b626f4
@ -8,6 +8,19 @@ namespace L2Bot::Domain::Entities
|
||||
{
|
||||
class Skill : public EntityInterface
|
||||
{
|
||||
public:
|
||||
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:
|
||||
const uint32_t GetId() const override
|
||||
{
|
||||
@ -22,19 +35,43 @@ namespace L2Bot::Domain::Entities
|
||||
return m_IsToggled;
|
||||
}
|
||||
|
||||
void UpdateReloadingState(const bool isReloading)
|
||||
void StartReloading()
|
||||
{
|
||||
m_IsReloading = isReloading;
|
||||
m_IsReloading = true;
|
||||
}
|
||||
void UpdateCastingState(const bool isCasting)
|
||||
void StopReloading()
|
||||
{
|
||||
m_IsCasting = isCasting;
|
||||
m_IsReloading = false;
|
||||
}
|
||||
void UpdateToggle(const bool isToggled)
|
||||
void StartCasting()
|
||||
{
|
||||
m_IsToggled = isToggled;
|
||||
m_IsCasting = true;
|
||||
}
|
||||
void StopCasting()
|
||||
{
|
||||
m_IsCasting = false;
|
||||
}
|
||||
void ToggleOn()
|
||||
{
|
||||
m_IsToggled = true;
|
||||
}
|
||||
void ToggleOff()
|
||||
{
|
||||
m_IsToggled = false;
|
||||
}
|
||||
void Update(const Data &data) {
|
||||
m_Level = data.level;
|
||||
m_IsActive = data.isActive;
|
||||
m_Cost = data.cost;
|
||||
m_Range = data.range;
|
||||
m_Name = data.name;
|
||||
m_Description = data.description;
|
||||
m_IconName = data.iconName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
**/
|
||||
void Update(const EntityInterface* other) override
|
||||
{
|
||||
const Skill* casted = static_cast<const Skill*>(other);
|
||||
@ -52,6 +89,9 @@ namespace L2Bot::Domain::Entities
|
||||
m_IsCasting = casted->m_IsCasting;
|
||||
m_IsReloading = casted->m_IsReloading;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
**/
|
||||
void SaveState() override
|
||||
{
|
||||
m_PrevState =
|
||||
@ -68,6 +108,9 @@ namespace L2Bot::Domain::Entities
|
||||
false
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
**/
|
||||
const bool IsEqual(const EntityInterface* other) const override
|
||||
{
|
||||
const Skill* casted = static_cast<const Skill*>(other);
|
||||
@ -83,7 +126,9 @@ namespace L2Bot::Domain::Entities
|
||||
m_IsCasting == casted->m_IsCasting &&
|
||||
m_IsReloading == casted->m_IsReloading;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
**/
|
||||
const std::vector<Serializers::Node> BuildSerializationNodes() const override
|
||||
{
|
||||
std::vector<Serializers::Node> result;
|
||||
@ -136,34 +181,22 @@ namespace L2Bot::Domain::Entities
|
||||
return result;
|
||||
}
|
||||
|
||||
Skill(
|
||||
const uint32_t skillId,
|
||||
const uint8_t level,
|
||||
const bool isActive,
|
||||
const uint8_t cost,
|
||||
const int16_t range,
|
||||
const std::wstring& name,
|
||||
const std::wstring& description,
|
||||
const std::wstring& iconName,
|
||||
const bool isToggled,
|
||||
const bool isCasting,
|
||||
const bool isReloading
|
||||
) :
|
||||
m_SkillId(skillId),
|
||||
m_Level(level),
|
||||
m_IsActive(isActive),
|
||||
m_Cost(cost),
|
||||
m_Range(range),
|
||||
m_Name(name),
|
||||
m_Description(description),
|
||||
m_IconName(iconName),
|
||||
m_IsToggled(isToggled),
|
||||
m_IsCasting(isCasting),
|
||||
m_IsReloading(isReloading)
|
||||
Skill(const Data &data) :
|
||||
m_SkillId(data.skillId),
|
||||
m_Level(data.level),
|
||||
m_IsActive(data.isActive),
|
||||
m_Cost(data.cost),
|
||||
m_Range(data.range),
|
||||
m_Name(data.name),
|
||||
m_Description(data.description),
|
||||
m_IconName(data.iconName)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
**/
|
||||
Skill(const Skill* other) :
|
||||
m_SkillId(other->m_SkillId),
|
||||
m_Level(other->m_Level),
|
||||
@ -179,10 +212,12 @@ namespace L2Bot::Domain::Entities
|
||||
{
|
||||
}
|
||||
|
||||
Skill() = default;
|
||||
virtual ~Skill() = default;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @deprecated
|
||||
**/
|
||||
struct GetState
|
||||
{
|
||||
std::wstring name = L"";
|
||||
|
@ -25,6 +25,17 @@ namespace Interlude
|
||||
virtual ~SkillFactory() = default;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
private:
|
||||
const Entities::Skill::Data BuildSkillData(const uint32_t skillId, const uint32_t level, const uint32_t isActive) const
|
||||
{
|
||||
const auto data = m_L2GameData.GetMSData(skillId, level);
|
||||
|
||||
@ -34,7 +45,7 @@ namespace Interlude
|
||||
const auto description = data && data->description ? data->description : L"";
|
||||
const auto iconEntry = data ? m_FName.GetEntry(data->iconNameIndex) : nullptr;
|
||||
|
||||
return std::make_shared<Entities::Skill>(
|
||||
return {
|
||||
skillId,
|
||||
static_cast<uint8_t>(level),
|
||||
isActive != 1,
|
||||
@ -43,10 +54,7 @@ namespace Interlude
|
||||
std::wstring(name),
|
||||
std::wstring(description),
|
||||
iconEntry ? std::wstring(iconEntry->value) : L"",
|
||||
false,
|
||||
false,
|
||||
false
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -128,18 +128,23 @@ namespace Interlude
|
||||
const auto skillInfo = casted.GetSkillInfo();
|
||||
const auto skillId = skillInfo[2];
|
||||
|
||||
if (m_Skills.find(skillId) == m_Skills.end())
|
||||
{
|
||||
auto skill = m_Factory.Create(
|
||||
skillInfo[2],
|
||||
skillInfo[1],
|
||||
skillInfo[0]
|
||||
);
|
||||
if (m_Skills.find(skillId) == m_Skills.end())
|
||||
{
|
||||
m_Skills.emplace(skill->GetId(), skill);
|
||||
m_Skills[skill->GetId()] = skill;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Skills[skillId]->Update(skill.get());
|
||||
m_Factory.Update(
|
||||
m_Skills[skillId],
|
||||
skillInfo[2],
|
||||
skillInfo[1],
|
||||
skillInfo[0]
|
||||
);
|
||||
}
|
||||
m_NewSkills[skillId] = skillId;
|
||||
}
|
||||
@ -161,18 +166,18 @@ namespace Interlude
|
||||
|
||||
const auto& skill = m_Skills[skillId];
|
||||
|
||||
skill->UpdateReloadingState(true);
|
||||
skill->UpdateCastingState(true);
|
||||
skill->StartReloading();
|
||||
skill->StartCasting();
|
||||
|
||||
m_UsedSkillId = skill->GetId();
|
||||
|
||||
m_ReloadingTimers.StartTimer(skill->GetId(), skillInfo[3], [this] (uint32_t skillId) {
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
m_Skills[skillId]->UpdateReloadingState(false);
|
||||
m_Skills[skillId]->StopReloading();
|
||||
});
|
||||
m_CastingTimers.StartTimer(skill->GetId(), skillInfo[2], [this] (uint32_t skillId) {
|
||||
std::shared_lock<std::shared_timed_mutex>(m_Mutex);
|
||||
m_Skills[skillId]->UpdateCastingState(false);
|
||||
m_Skills[skillId]->StopCasting();
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -195,7 +200,7 @@ namespace Interlude
|
||||
|
||||
const auto& skill = m_Skills[m_UsedSkillId];
|
||||
|
||||
skill->UpdateCastingState(false);
|
||||
skill->StopCasting();
|
||||
m_CastingTimers.StopTimer(skill->GetId());
|
||||
|
||||
m_UsedSkillId = 0;
|
||||
@ -227,11 +232,11 @@ namespace Interlude
|
||||
|
||||
if (skill->IsToggled() && !needToToggle)
|
||||
{
|
||||
skill->UpdateToggle(false);
|
||||
skill->ToggleOff();
|
||||
}
|
||||
else if (!skill->IsToggled() && needToToggle && isAura)
|
||||
{
|
||||
skill->UpdateToggle(true);
|
||||
skill->ToggleOn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user