feat: add attackers handling

This commit is contained in:
k0t9i
2023-11-11 15:44:03 +04:00
parent 129381e13c
commit e42ff2b5e7
10 changed files with 177 additions and 11 deletions

View File

@@ -43,6 +43,14 @@ namespace L2Bot::Domain::Entities
}
const size_t GetHash() const override
{
size_t attackersHash = 0;
for (const auto& kvp : m_AttackerIds)
{
attackersHash = Helpers::CombineHashes({
std::hash<uint32_t>{}(kvp.first),
});
}
return Helpers::CombineHashes({
WorldObject::GetHash(),
m_FullName.GetHash(),
@@ -54,7 +62,8 @@ namespace L2Bot::Domain::Entities
m_Reputation.GetHash(),
m_InventoryInfo.GetHash(),
std::hash<uint32_t>{}(m_TargetId),
std::hash<uint32_t>{}(m_IsStanding)
std::hash<uint32_t>{}(m_IsStanding),
attackersHash
});
}
const std::string GetEntityName() const override
@@ -65,6 +74,21 @@ namespace L2Bot::Domain::Entities
{
return m_FullName;
}
void AddAttacker(const uint32_t attackerId)
{
m_AttackerIds[attackerId] = attackerId;
}
void RemoveAttacker(const uint32_t attackerId)
{
if (m_AttackerIds.find(attackerId) != m_AttackerIds.end())
{
m_AttackerIds.erase(attackerId);
}
}
const std::map<uint32_t, uint32_t>& GetAttackerIds() const
{
return m_AttackerIds;
}
const std::vector<Serializers::Node> BuildSerializationNodes() const override
{
@@ -80,6 +104,12 @@ namespace L2Bot::Domain::Entities
result.push_back({ L"inventoryInfo", m_InventoryInfo.BuildSerializationNodes() });
result.push_back({ L"targetId", std::to_wstring(m_TargetId) });
result.push_back({ L"isStanding", std::to_wstring(m_IsStanding) });
std::vector<Serializers::Node> attackers;
for (const auto& kvp : m_AttackerIds)
{
attackers.push_back({ std::to_wstring(kvp.first), std::to_wstring(kvp.first) });
}
result.push_back({ L"attackerIds", attackers, true });
return result;
}
@@ -127,5 +157,6 @@ namespace L2Bot::Domain::Entities
ValueObjects::InventoryInfo m_InventoryInfo = ValueObjects::InventoryInfo();
uint32_t m_TargetId = 0;
bool m_IsStanding = true;
std::map<uint32_t, uint32_t> m_AttackerIds;
};
}

View File

@@ -0,0 +1,43 @@
#pragma once
#include <cstdint>
#include <vector>
#include "Event.h"
namespace L2Bot::Domain::Events
{
class AttackedEvent : public Event
{
public:
static constexpr const char* name = "attacked";
const std::string GetName() const
{
return std::string(name);
}
const uint32_t GetAttackerId() const
{
return m_AttackerId;
}
const uint32_t GetTargetId() const
{
return m_TargetId;
}
AttackedEvent(const uint32_t attackerId, const uint32_t targetId) :
m_AttackerId(attackerId),
m_TargetId(targetId)
{
}
AttackedEvent() = delete;
virtual ~AttackedEvent() = default;
private:
const uint32_t m_AttackerId;
const uint32_t m_TargetId;
};
}