refactor(game): extract EntityController from GameHandler (step 1.3)

Moves entity lifecycle, name/creature/game-object caches, transport GUID
tracking, and the entire update-object pipeline out of GameHandler into a
new EntityController class (friend-class pattern, same as CombatHandler
et al.).

What moved:
- applyUpdateObjectBlock() — 1,520-line core of all entity creation,
  field updates, and movement application
- processOutOfRangeObjects() / finalizeUpdateObjectBatch()
- handleUpdateObject() / handleCompressedUpdateObject() / handleDestroyObject()
- handleNameQueryResponse() / handleCreatureQueryResponse()
- handleGameObjectQueryResponse() / handleGameObjectPageText()
- handlePageTextQueryResponse()
- enqueueUpdateObjectWork() / processPendingUpdateObjectWork()
- playerNameCache, playerClassRaceCache_, pendingNameQueries
- creatureInfoCache, pendingCreatureQueries
- gameObjectInfoCache_, pendingGameObjectQueries_
- transportGuids_, serverUpdatedTransportGuids_
- EntityManager (accessed by other handlers via getEntityManager())

8 opcodes re-registered by EntityController::registerOpcodes():
  SMSG_UPDATE_OBJECT, SMSG_COMPRESSED_UPDATE_OBJECT, SMSG_DESTROY_OBJECT,
  SMSG_NAME_QUERY_RESPONSE, SMSG_CREATURE_QUERY_RESPONSE,
  SMSG_GAMEOBJECT_QUERY_RESPONSE, SMSG_GAMEOBJECT_PAGETEXT,
  SMSG_PAGE_TEXT_QUERY_RESPONSE

Other handler files (combat, movement, social, spell, inventory, quest,
chat) updated to access EntityManager via getEntityManager() and the
name cache via getPlayerNameCache() — no logic changes.

Also included:
- .clang-tidy: add modernize-use-nodiscard,
  modernize-use-designated-initializers; set -std=c++20 in ExtraArgs
- test.sh: prepend clang's own resource include dir before GCC's to
  silence xmmintrin.h / ia32intrin.h conflicts during clang-tidy runs

Line counts:
  entity_controller.hpp  147 lines  (new)
  entity_controller.cpp  2172 lines (new)
  game_handler.cpp       8095 lines (was 10143, −2048)

Build: 0 errors, 0 warnings.
This commit is contained in:
Paul 2026-03-29 08:21:27 +03:00
parent 4f2a4e5520
commit f5757aca83
15 changed files with 2497 additions and 2260 deletions

View file

@ -138,8 +138,8 @@ void ChatHandler::sendChatMessage(ChatType type, const std::string& message, con
echo.language = language;
echo.message = message;
auto nameIt = owner_.playerNameCache.find(owner_.playerGuid);
if (nameIt != owner_.playerNameCache.end()) {
auto nameIt = owner_.getPlayerNameCache().find(owner_.playerGuid);
if (nameIt != owner_.getPlayerNameCache().end()) {
echo.senderName = nameIt->second;
}
@ -179,11 +179,11 @@ void ChatHandler::handleMessageChat(network::Packet& packet) {
// Resolve sender name from entity/cache if not already set by parser
if (data.senderName.empty() && data.senderGuid != 0) {
auto nameIt = owner_.playerNameCache.find(data.senderGuid);
if (nameIt != owner_.playerNameCache.end()) {
auto nameIt = owner_.getPlayerNameCache().find(data.senderGuid);
if (nameIt != owner_.getPlayerNameCache().end()) {
data.senderName = nameIt->second;
} else {
auto entity = owner_.entityManager.getEntity(data.senderGuid);
auto entity = owner_.getEntityManager().getEntity(data.senderGuid);
if (entity) {
if (entity->getType() == ObjectType::PLAYER) {
auto player = std::dynamic_pointer_cast<Player>(entity);
@ -356,11 +356,11 @@ void ChatHandler::handleTextEmote(network::Packet& packet) {
}
std::string senderName;
auto nameIt = owner_.playerNameCache.find(data.senderGuid);
if (nameIt != owner_.playerNameCache.end()) {
auto nameIt = owner_.getPlayerNameCache().find(data.senderGuid);
if (nameIt != owner_.getPlayerNameCache().end()) {
senderName = nameIt->second;
} else {
auto entity = owner_.entityManager.getEntity(data.senderGuid);
auto entity = owner_.getEntityManager().getEntity(data.senderGuid);
if (entity) {
auto unit = std::dynamic_pointer_cast<Unit>(entity);
if (unit) senderName = unit->getName();
@ -685,7 +685,7 @@ void ChatHandler::handleChannelList(network::Packet& packet) {
uint64_t memberGuid = packet.readUInt64();
uint8_t memberFlags = packet.readUInt8();
std::string name;
auto entity = owner_.entityManager.getEntity(memberGuid);
auto entity = owner_.getEntityManager().getEntity(memberGuid);
if (entity) {
auto player = std::dynamic_pointer_cast<Player>(entity);
if (player && !player->getName().empty()) name = player->getName();

View file

@ -64,7 +64,7 @@ void CombatHandler::registerOpcodes(DispatchTable& table) {
};
table[Opcode::SMSG_ATTACKSWING_BADFACING] = [this](network::Packet& /*packet*/) {
if (autoAttackRequested_ && autoAttackTarget_ != 0) {
auto targetEntity = owner_.entityManager.getEntity(autoAttackTarget_);
auto targetEntity = owner_.getEntityManager().getEntity(autoAttackTarget_);
if (targetEntity) {
float toTargetX = targetEntity->getX() - owner_.movementInfo.x;
float toTargetY = targetEntity->getY() - owner_.movementInfo.y;
@ -96,7 +96,7 @@ void CombatHandler::registerOpcodes(DispatchTable& table) {
uint64_t guid = packet.readUInt64();
uint32_t reaction = packet.readUInt32();
if (reaction == 2 && owner_.npcAggroCallback_) {
auto entity = owner_.entityManager.getEntity(guid);
auto entity = owner_.getEntityManager().getEntity(guid);
if (entity)
owner_.npcAggroCallback_(guid, glm::vec3(entity->getX(), entity->getY(), entity->getZ()));
}
@ -204,7 +204,7 @@ void CombatHandler::startAutoAttack(uint64_t targetGuid) {
// Client-side melee range gate to avoid starting "swing forever" loops when
// target is already clearly out of range.
if (auto target = owner_.entityManager.getEntity(targetGuid)) {
if (auto target = owner_.getEntityManager().getEntity(targetGuid)) {
float dx = owner_.movementInfo.x - target->getLatestX();
float dy = owner_.movementInfo.y - target->getLatestY();
float dz = owner_.movementInfo.z - target->getLatestZ();
@ -368,7 +368,7 @@ void CombatHandler::updateCombatText(float deltaTime) {
void CombatHandler::autoTargetAttacker(uint64_t attackerGuid) {
if (attackerGuid == 0 || attackerGuid == owner_.playerGuid) return;
if (owner_.targetGuid != 0) return;
if (!owner_.entityManager.hasEntity(attackerGuid)) return;
if (!owner_.getEntityManager().hasEntity(attackerGuid)) return;
owner_.setTarget(attackerGuid);
}
@ -389,7 +389,7 @@ void CombatHandler::handleAttackStart(network::Packet& packet) {
// Play aggro sound when NPC attacks player
if (owner_.npcAggroCallback_) {
auto entity = owner_.entityManager.getEntity(data.attackerGuid);
auto entity = owner_.getEntityManager().getEntity(data.attackerGuid);
if (entity && entity->getType() == ObjectType::UNIT) {
glm::vec3 pos(entity->getX(), entity->getY(), entity->getZ());
owner_.npcAggroCallback_(data.attackerGuid, pos);
@ -400,8 +400,8 @@ void CombatHandler::handleAttackStart(network::Packet& packet) {
// Force both participants to face each other at combat start.
// Uses atan2(-dy, dx): canonical orientation convention where the West/Y
// component is negated (renderYaw = orientation + 90°, model-forward = render+X).
auto attackerEnt = owner_.entityManager.getEntity(data.attackerGuid);
auto victimEnt = owner_.entityManager.getEntity(data.victimGuid);
auto attackerEnt = owner_.getEntityManager().getEntity(data.attackerGuid);
auto victimEnt = owner_.getEntityManager().getEntity(data.victimGuid);
if (attackerEnt && victimEnt) {
float dx = victimEnt->getX() - attackerEnt->getX();
float dy = victimEnt->getY() - attackerEnt->getY();
@ -589,7 +589,7 @@ void CombatHandler::updateAutoAttack(float deltaTime) {
// Leave combat if auto-attack target is too far away (leash range)
// and keep melee intent tightly synced while stationary.
if (autoAttackRequested_ && autoAttackTarget_ != 0) {
auto targetEntity = owner_.entityManager.getEntity(autoAttackTarget_);
auto targetEntity = owner_.getEntityManager().getEntity(autoAttackTarget_);
if (targetEntity) {
const float targetX = targetEntity->getLatestX();
const float targetY = targetEntity->getLatestY();
@ -669,7 +669,7 @@ void CombatHandler::updateAutoAttack(float deltaTime) {
// Keep active melee attackers visually facing the player as positions change.
if (!hostileAttackers_.empty()) {
for (uint64_t attackerGuid : hostileAttackers_) {
auto attacker = owner_.entityManager.getEntity(attackerGuid);
auto attacker = owner_.getEntityManager().getEntity(attackerGuid);
if (!attacker) continue;
float dx = owner_.movementInfo.x - attacker->getX();
float dy = owner_.movementInfo.y - attacker->getY();
@ -1098,14 +1098,14 @@ void CombatHandler::clearTarget() {
std::shared_ptr<Entity> CombatHandler::getTarget() const {
if (owner_.targetGuid == 0) return nullptr;
return owner_.entityManager.getEntity(owner_.targetGuid);
return owner_.getEntityManager().getEntity(owner_.targetGuid);
}
void CombatHandler::setFocus(uint64_t guid) {
owner_.focusGuid = guid;
owner_.fireAddonEvent("PLAYER_FOCUS_CHANGED", {});
if (guid != 0) {
auto entity = owner_.entityManager.getEntity(guid);
auto entity = owner_.getEntityManager().getEntity(guid);
if (entity) {
std::string name;
auto unit = std::dynamic_pointer_cast<Unit>(entity);
@ -1131,7 +1131,7 @@ void CombatHandler::clearFocus() {
std::shared_ptr<Entity> CombatHandler::getFocus() const {
if (owner_.focusGuid == 0) return nullptr;
return owner_.entityManager.getEntity(owner_.focusGuid);
return owner_.getEntityManager().getEntity(owner_.focusGuid);
}
void CombatHandler::setMouseoverGuid(uint64_t guid) {
@ -1156,7 +1156,7 @@ void CombatHandler::targetLastTarget() {
void CombatHandler::targetEnemy(bool reverse) {
// Get list of hostile entities
std::vector<uint64_t> hostiles;
auto& entities = owner_.entityManager.getEntities();
auto& entities = owner_.getEntityManager().getEntities();
for (const auto& [guid, entity] : entities) {
if (entity->getType() == ObjectType::UNIT) {
@ -1200,7 +1200,7 @@ void CombatHandler::targetEnemy(bool reverse) {
void CombatHandler::targetFriend(bool reverse) {
// Get list of friendly entities (players)
std::vector<uint64_t> friendlies;
auto& entities = owner_.entityManager.getEntities();
auto& entities = owner_.getEntityManager().getEntities();
for (const auto& [guid, entity] : entities) {
if (entity->getType() == ObjectType::PLAYER && guid != owner_.playerGuid) {
@ -1266,7 +1266,7 @@ void CombatHandler::tabTarget(float playerX, float playerY, float playerZ) {
struct EntityDist { uint64_t guid; float distance; };
std::vector<EntityDist> sortable;
for (const auto& [guid, entity] : owner_.entityManager.getEntities()) {
for (const auto& [guid, entity] : owner_.getEntityManager().getEntities()) {
auto t = entity->getType();
if (t != ObjectType::UNIT && t != ObjectType::PLAYER) continue;
if (guid == owner_.playerGuid) continue;
@ -1297,7 +1297,7 @@ void CombatHandler::tabTarget(float playerX, float playerY, float playerZ) {
while (tries-- > 0) {
owner_.tabCycleIndex = (owner_.tabCycleIndex + 1) % static_cast<int>(owner_.tabCycleList.size());
uint64_t guid = owner_.tabCycleList[owner_.tabCycleIndex];
auto entity = owner_.entityManager.getEntity(guid);
auto entity = owner_.getEntityManager().getEntity(guid);
if (isValidTabTarget(entity)) {
setTarget(guid);
return;
@ -1373,7 +1373,7 @@ void CombatHandler::togglePvp() {
auto packet = TogglePvpPacket::build();
owner_.socket->send(packet);
auto entity = owner_.entityManager.getEntity(owner_.playerGuid);
auto entity = owner_.getEntityManager().getEntity(owner_.playerGuid);
bool currentlyPvp = false;
if (entity) {
currentlyPvp = (entity->getField(59) & 0x00001000) != 0;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -810,8 +810,8 @@ void InventoryHandler::handleLootRoll(network::Packet& packet) {
// Resolve player name
std::string playerName;
auto nit = owner_.playerNameCache.find(playerGuid);
if (nit != owner_.playerNameCache.end()) playerName = nit->second;
auto nit = owner_.getPlayerNameCache().find(playerGuid);
if (nit != owner_.getPlayerNameCache().end()) playerName = nit->second;
if (playerName.empty()) playerName = "Player";
if (pendingLootRollActive_ &&
@ -848,8 +848,8 @@ void InventoryHandler::handleLootRollWon(network::Packet& packet) {
uint8_t rollType = packet.readUInt8();
std::string winnerName;
auto nit = owner_.playerNameCache.find(winnerGuid);
if (nit != owner_.playerNameCache.end()) winnerName = nit->second;
auto nit = owner_.getPlayerNameCache().find(winnerGuid);
if (nit != owner_.getPlayerNameCache().end()) winnerName = nit->second;
if (winnerName.empty()) winnerName = "Player";
owner_.ensureItemInfo(itemId);
@ -1374,7 +1374,7 @@ void InventoryHandler::handleListInventory(network::Packet& packet) {
// Play vendor sound
if (owner_.npcVendorCallback_ && currentVendorItems_.vendorGuid != 0) {
auto entity = owner_.entityManager.getEntity(currentVendorItems_.vendorGuid);
auto entity = owner_.getEntityManager().getEntity(currentVendorItems_.vendorGuid);
if (entity && entity->getType() == ObjectType::UNIT) {
glm::vec3 pos(entity->getX(), entity->getY(), entity->getZ());
owner_.npcVendorCallback_(currentVendorItems_.vendorGuid, pos);
@ -2076,8 +2076,8 @@ void InventoryHandler::handleTradeStatus(network::Packet& packet) {
tradePeerGuid_ = packet.readUInt64();
tradeStatus_ = TradeStatus::PendingIncoming;
// Resolve name
auto nit = owner_.playerNameCache.find(tradePeerGuid_);
if (nit != owner_.playerNameCache.end()) tradePeerName_ = nit->second;
auto nit = owner_.getPlayerNameCache().find(tradePeerGuid_);
if (nit != owner_.getPlayerNameCache().end()) tradePeerName_ = nit->second;
else tradePeerName_ = "Unknown";
owner_.addSystemChatMessage(tradePeerName_ + " wants to trade with you.");
if (owner_.addonEventCallback_) owner_.addonEventCallback_("TRADE_REQUEST", {tradePeerName_});
@ -3098,7 +3098,7 @@ void InventoryHandler::maybeDetectVisibleItemLayout() {
" mismatches=", bestMismatches, " score=", bestScore, ")");
// Backfill existing player entities already in view.
for (const auto& [guid, ent] : owner_.entityManager.getEntities()) {
for (const auto& [guid, ent] : owner_.getEntityManager().getEntities()) {
if (!ent || ent->getType() != ObjectType::PLAYER) continue;
if (guid == owner_.playerGuid) continue;
updateOtherPlayerVisibleItems(guid, ent->getFields());

View file

@ -1180,7 +1180,7 @@ void MovementHandler::handleOtherPlayerMovement(network::Packet& packet) {
}
}
auto entity = owner_.entityManager.getEntity(moverGuid);
auto entity = owner_.getEntityManager().getEntity(moverGuid);
if (!entity) {
return;
}
@ -1539,7 +1539,7 @@ void MovementHandler::handleMonsterMove(network::Packet& packet) {
}
}
auto entity = owner_.entityManager.getEntity(data.guid);
auto entity = owner_.getEntityManager().getEntity(data.guid);
if (!entity) {
return;
}
@ -1552,7 +1552,7 @@ void MovementHandler::handleMonsterMove(network::Packet& packet) {
if (data.moveType == 4) {
orientation = core::coords::serverToCanonicalYaw(data.facingAngle);
} else if (data.moveType == 3) {
auto target = owner_.entityManager.getEntity(data.facingTarget);
auto target = owner_.getEntityManager().getEntity(data.facingTarget);
if (target) {
float dx = target->getX() - entity->getX();
float dy = target->getY() - entity->getY();
@ -1613,7 +1613,7 @@ void MovementHandler::handleMonsterMove(network::Packet& packet) {
posCanonical.x, posCanonical.y, posCanonical.z, 0);
}
} else if (data.moveType == 3 && data.facingTarget != 0) {
auto target = owner_.entityManager.getEntity(data.facingTarget);
auto target = owner_.getEntityManager().getEntity(data.facingTarget);
if (target) {
float dx = target->getX() - entity->getX();
float dy = target->getY() - entity->getY();
@ -1635,7 +1635,7 @@ void MovementHandler::handleMonsterMoveTransport(network::Packet& packet) {
float localY = packet.readFloat();
float localZ = packet.readFloat();
auto entity = owner_.entityManager.getEntity(moverGuid);
auto entity = owner_.getEntityManager().getEntity(moverGuid);
if (!entity) return;
if (packet.getReadPos() + 5 > packet.getSize()) {
@ -1674,7 +1674,7 @@ void MovementHandler::handleMonsterMoveTransport(network::Packet& packet) {
} else if (moveType == 3) {
if (packet.getReadPos() + 8 > packet.getSize()) return;
uint64_t tgtGuid = packet.readUInt64();
if (auto tgt = owner_.entityManager.getEntity(tgtGuid)) {
if (auto tgt = owner_.getEntityManager().getEntity(tgtGuid)) {
float dx = tgt->getX() - entity->getX();
float dy = tgt->getY() - entity->getY();
if (std::abs(dx) > 0.01f || std::abs(dy) > 0.01f)
@ -1922,7 +1922,7 @@ void MovementHandler::handleNewWorld(network::Packet& packet) {
owner_.mountCallback_(0);
}
for (const auto& [guid, entity] : owner_.entityManager.getEntities()) {
for (const auto& [guid, entity] : owner_.getEntityManager().getEntities()) {
if (guid == owner_.playerGuid) continue;
if (entity->getType() == ObjectType::UNIT && owner_.creatureDespawnCallback_) {
owner_.creatureDespawnCallback_(guid);
@ -1938,7 +1938,7 @@ void MovementHandler::handleNewWorld(network::Packet& packet) {
owner_.unitCastStates_.clear();
owner_.unitAurasCache_.clear();
owner_.clearCombatText();
owner_.entityManager.clear();
owner_.getEntityManager().clear();
owner_.clearHostileAttackers();
owner_.worldStates_.clear();
owner_.gossipPois_.clear();
@ -2278,7 +2278,7 @@ void MovementHandler::startClientTaxiPath(const std::vector<uint32_t>& pathNodes
movementInfo.orientation = initialOrientation;
sanitizeMovementForTaxi();
auto playerEntity = owner_.entityManager.getEntity(owner_.playerGuid);
auto playerEntity = owner_.getEntityManager().getEntity(owner_.playerGuid);
if (playerEntity) {
playerEntity->setPosition(start.x, start.y, start.z, initialOrientation);
}
@ -2293,7 +2293,7 @@ void MovementHandler::startClientTaxiPath(const std::vector<uint32_t>& pathNodes
void MovementHandler::updateClientTaxi(float deltaTime) {
if (!taxiClientActive_ || taxiClientPath_.size() < 2) return;
auto playerEntity = owner_.entityManager.getEntity(owner_.playerGuid);
auto playerEntity = owner_.getEntityManager().getEntity(owner_.playerGuid);
auto finishTaxiFlight = [&]() {
if (!taxiClientPath_.empty()) {
@ -2820,7 +2820,7 @@ void MovementHandler::updateAttachedTransportChildren(float /*deltaTime*/) {
stale.reserve(8);
for (const auto& [childGuid, attachment] : owner_.transportAttachments_) {
auto entity = owner_.entityManager.getEntity(childGuid);
auto entity = owner_.getEntityManager().getEntity(childGuid);
if (!entity) {
stale.push_back(childGuid);
continue;

View file

@ -504,7 +504,7 @@ void QuestHandler::registerOpcodes(DispatchTable& table) {
}
// Re-query all nearby quest giver NPCs so markers refresh
if (owner_.socket) {
for (const auto& [guid, entity] : owner_.entityManager.getEntities()) {
for (const auto& [guid, entity] : owner_.getEntityManager().getEntities()) {
if (entity->getType() != ObjectType::UNIT) continue;
auto unit = std::static_pointer_cast<Unit>(entity);
if (unit->getNpcFlags() & 0x02) {
@ -1557,7 +1557,7 @@ void QuestHandler::handleGossipMessage(network::Packet& packet) {
// Play NPC greeting voice
if (owner_.npcGreetingCallback_ && currentGossip_.npcGuid != 0) {
auto entity = owner_.entityManager.getEntity(currentGossip_.npcGuid);
auto entity = owner_.getEntityManager().getEntity(currentGossip_.npcGuid);
if (entity) {
glm::vec3 npcPos(entity->getX(), entity->getY(), entity->getZ());
owner_.npcGreetingCallback_(currentGossip_.npcGuid, npcPos);
@ -1654,7 +1654,7 @@ void QuestHandler::handleGossipComplete(network::Packet& packet) {
// Play farewell sound before closing
if (owner_.npcFarewellCallback_ && currentGossip_.npcGuid != 0) {
auto entity = owner_.entityManager.getEntity(currentGossip_.npcGuid);
auto entity = owner_.getEntityManager().getEntity(currentGossip_.npcGuid);
if (entity && entity->getType() == ObjectType::UNIT) {
glm::vec3 pos(entity->getX(), entity->getY(), entity->getZ());
owner_.npcFarewellCallback_(currentGossip_.npcGuid, pos);
@ -1865,13 +1865,13 @@ void QuestHandler::handleQuestConfirmAccept(network::Packet& packet) {
}
sharedQuestSharerName_.clear();
auto entity = owner_.entityManager.getEntity(sharedQuestSharerGuid_);
auto entity = owner_.getEntityManager().getEntity(sharedQuestSharerGuid_);
if (auto* unit = dynamic_cast<Unit*>(entity.get())) {
sharedQuestSharerName_ = unit->getName();
}
if (sharedQuestSharerName_.empty()) {
auto nit = owner_.playerNameCache.find(sharedQuestSharerGuid_);
if (nit != owner_.playerNameCache.end())
auto nit = owner_.getPlayerNameCache().find(sharedQuestSharerGuid_);
if (nit != owner_.getPlayerNameCache().end())
sharedQuestSharerName_ = nit->second;
}
if (sharedQuestSharerName_.empty()) {

View file

@ -154,7 +154,7 @@ void SocialHandler::registerOpcodes(DispatchTable& table) {
readyCheckResults_.clear();
if (packet.getSize() - packet.getReadPos() >= 8) {
uint64_t initiatorGuid = packet.readUInt64();
auto entity = owner_.entityManager.getEntity(initiatorGuid);
auto entity = owner_.getEntityManager().getEntity(initiatorGuid);
if (auto* unit = dynamic_cast<Unit*>(entity.get()))
readyCheckInitiator_ = unit->getName();
}
@ -174,11 +174,11 @@ void SocialHandler::registerOpcodes(DispatchTable& table) {
uint64_t respGuid = packet.readUInt64();
uint8_t isReady = packet.readUInt8();
if (isReady) ++readyCheckReadyCount_; else ++readyCheckNotReadyCount_;
auto nit = owner_.playerNameCache.find(respGuid);
auto nit = owner_.getPlayerNameCache().find(respGuid);
std::string rname;
if (nit != owner_.playerNameCache.end()) rname = nit->second;
if (nit != owner_.getPlayerNameCache().end()) rname = nit->second;
else {
auto ent = owner_.entityManager.getEntity(respGuid);
auto ent = owner_.getEntityManager().getEntity(respGuid);
if (ent) rname = std::static_pointer_cast<game::Unit>(ent)->getName();
}
if (!rname.empty()) {
@ -231,9 +231,9 @@ void SocialHandler::registerOpcodes(DispatchTable& table) {
uint64_t killerGuid = packet.readUInt64();
uint64_t victimGuid = packet.readUInt64();
auto nameFor = [this](uint64_t g) -> std::string {
auto nit = owner_.playerNameCache.find(g);
if (nit != owner_.playerNameCache.end()) return nit->second;
auto ent = owner_.entityManager.getEntity(g);
auto nit = owner_.getPlayerNameCache().find(g);
if (nit != owner_.getPlayerNameCache().end()) return nit->second;
auto ent = owner_.getEntityManager().getEntity(g);
if (ent && (ent->getType() == game::ObjectType::UNIT ||
ent->getType() == game::ObjectType::PLAYER))
return std::static_pointer_cast<game::Unit>(ent)->getName();
@ -303,16 +303,16 @@ void SocialHandler::registerOpcodes(DispatchTable& table) {
table[Opcode::SMSG_BATTLEGROUND_PLAYER_JOINED] = [this](network::Packet& packet) {
if (packet.getSize() - packet.getReadPos() >= 8) {
uint64_t guid = packet.readUInt64();
auto it = owner_.playerNameCache.find(guid);
if (it != owner_.playerNameCache.end() && !it->second.empty())
auto it = owner_.getPlayerNameCache().find(guid);
if (it != owner_.getPlayerNameCache().end() && !it->second.empty())
owner_.addSystemChatMessage(it->second + " has entered the battleground.");
}
};
table[Opcode::SMSG_BATTLEGROUND_PLAYER_LEFT] = [this](network::Packet& packet) {
if (packet.getSize() - packet.getReadPos() >= 8) {
uint64_t guid = packet.readUInt64();
auto it = owner_.playerNameCache.find(guid);
if (it != owner_.playerNameCache.end() && !it->second.empty())
auto it = owner_.getPlayerNameCache().find(guid);
if (it != owner_.getPlayerNameCache().end() && !it->second.empty())
owner_.addSystemChatMessage(it->second + " has left the battleground.");
}
};
@ -455,7 +455,7 @@ void SocialHandler::registerOpcodes(DispatchTable& table) {
if (roles & 0x08) roleName += "DPS ";
if (roleName.empty()) roleName = "None";
std::string pName = "A player";
if (auto e = owner_.entityManager.getEntity(roleGuid))
if (auto e = owner_.getEntityManager().getEntity(roleGuid))
if (auto u = std::dynamic_pointer_cast<Unit>(e))
pName = u->getName();
if (ready) owner_.addSystemChatMessage(pName + " has chosen: " + roleName);
@ -507,7 +507,7 @@ bool SocialHandler::isInGuild() const {
}
uint32_t SocialHandler::getEntityGuildId(uint64_t guid) const {
auto entity = owner_.entityManager.getEntity(guid);
auto entity = owner_.getEntityManager().getEntity(guid);
if (!entity || entity->getType() != ObjectType::PLAYER) return 0;
const uint16_t ufUnitEnd = fieldIndex(UF::UNIT_END);
if (ufUnitEnd == 0xFFFF) return 0;
@ -613,7 +613,7 @@ void SocialHandler::handleInspectResults(network::Packet& packet) {
size_t bytesLeft = packet.getSize() - packet.getReadPos();
if (bytesLeft < 6) {
LOG_WARNING("SMSG_TALENTS_INFO: too short after guid, ", bytesLeft, " bytes");
auto entity = owner_.entityManager.getEntity(guid);
auto entity = owner_.getEntityManager().getEntity(guid);
std::string name = "Target";
if (entity) {
auto player = std::dynamic_pointer_cast<Player>(entity);
@ -627,7 +627,7 @@ void SocialHandler::handleInspectResults(network::Packet& packet) {
uint8_t talentGroupCount = packet.readUInt8();
uint8_t activeTalentGroup = packet.readUInt8();
auto entity = owner_.entityManager.getEntity(guid);
auto entity = owner_.getEntityManager().getEntity(guid);
std::string playerName = "Target";
if (entity) {
auto player = std::dynamic_pointer_cast<Player>(entity);
@ -1028,12 +1028,12 @@ void SocialHandler::handleDuelRequested(network::Packet& packet) {
duelChallengerGuid_ = packet.readUInt64();
duelFlagGuid_ = packet.readUInt64();
duelChallengerName_.clear();
auto entity = owner_.entityManager.getEntity(duelChallengerGuid_);
auto entity = owner_.getEntityManager().getEntity(duelChallengerGuid_);
if (auto* unit = dynamic_cast<Unit*>(entity.get()))
duelChallengerName_ = unit->getName();
if (duelChallengerName_.empty()) {
auto nit = owner_.playerNameCache.find(duelChallengerGuid_);
if (nit != owner_.playerNameCache.end()) duelChallengerName_ = nit->second;
auto nit = owner_.getPlayerNameCache().find(duelChallengerGuid_);
if (nit != owner_.getPlayerNameCache().end()) duelChallengerName_ = nit->second;
}
if (duelChallengerName_.empty()) {
char tmp[32];
@ -1745,9 +1745,9 @@ void SocialHandler::handleFriendList(network::Packet& packet) {
classId = packet.readUInt32();
}
owner_.friendGuids_.insert(guid);
auto nit = owner_.playerNameCache.find(guid);
auto nit = owner_.getPlayerNameCache().find(guid);
std::string name;
if (nit != owner_.playerNameCache.end()) {
if (nit != owner_.getPlayerNameCache().end()) {
name = nit->second;
owner_.friendsCache[name] = guid;
} else {
@ -1780,15 +1780,15 @@ void SocialHandler::handleContactList(network::Packet& packet) {
areaId = packet.readUInt32(); level = packet.readUInt32(); classId = packet.readUInt32();
}
owner_.friendGuids_.insert(guid);
auto nit = owner_.playerNameCache.find(guid);
if (nit != owner_.playerNameCache.end()) owner_.friendsCache[nit->second] = guid;
auto nit = owner_.getPlayerNameCache().find(guid);
if (nit != owner_.getPlayerNameCache().end()) owner_.friendsCache[nit->second] = guid;
else owner_.queryPlayerName(guid);
}
ContactEntry entry;
entry.guid = guid; entry.flags = flags; entry.note = std::move(note);
entry.status = status; entry.areaId = areaId; entry.level = level; entry.classId = classId;
auto nit = owner_.playerNameCache.find(guid);
if (nit != owner_.playerNameCache.end()) entry.name = nit->second;
auto nit = owner_.getPlayerNameCache().find(guid);
if (nit != owner_.getPlayerNameCache().end()) entry.name = nit->second;
owner_.contacts_.push_back(std::move(entry));
}
if (owner_.addonEventCallback_) {
@ -1810,8 +1810,8 @@ void SocialHandler::handleFriendStatus(network::Packet& packet) {
if (cit != owner_.contacts_.end() && !cit->name.empty()) {
playerName = cit->name;
} else {
auto it = owner_.playerNameCache.find(data.guid);
if (it != owner_.playerNameCache.end()) playerName = it->second;
auto it = owner_.getPlayerNameCache().find(data.guid);
if (it != owner_.getPlayerNameCache().end()) playerName = it->second;
}
if (data.status == 1 || data.status == 2) owner_.friendsCache[playerName] = data.guid;
@ -1850,8 +1850,8 @@ void SocialHandler::handleRandomRoll(network::Packet& packet) {
if (!RandomRollParser::parse(packet, data)) return;
std::string rollerName = (data.rollerGuid == owner_.playerGuid) ? "You" : "Someone";
if (data.rollerGuid != owner_.playerGuid) {
auto it = owner_.playerNameCache.find(data.rollerGuid);
if (it != owner_.playerNameCache.end()) rollerName = it->second;
auto it = owner_.getPlayerNameCache().find(data.rollerGuid);
if (it != owner_.getPlayerNameCache().end()) rollerName = it->second;
}
std::string msg = rollerName + ((data.rollerGuid == owner_.playerGuid) ? " roll " : " rolls ");
msg += std::to_string(data.result) + " (" + std::to_string(data.minRoll) + "-" + std::to_string(data.maxRoll) + ")";
@ -2394,7 +2394,7 @@ void SocialHandler::handlePvpLogData(network::Packet& packet) {
ps.guid = packet.readUInt64(); ps.team = packet.readUInt8();
ps.killingBlows = packet.readUInt32(); ps.honorableKills = packet.readUInt32();
ps.deaths = packet.readUInt32(); ps.bonusHonor = packet.readUInt32();
{ auto ent = owner_.entityManager.getEntity(ps.guid);
{ auto ent = owner_.getEntityManager().getEntity(ps.guid);
if (ent && (ent->getType() == game::ObjectType::PLAYER || ent->getType() == game::ObjectType::UNIT))
{ auto u = std::static_pointer_cast<game::Unit>(ent); if (!u->getName().empty()) ps.name = u->getName(); } }
if (remaining() < 4) { bgScoreboard_.players.push_back(std::move(ps)); break; }

View file

@ -248,7 +248,7 @@ void SpellHandler::castSpell(uint32_t spellId, uint64_t targetGuid) {
owner_.addSystemChatMessage("You have no target.");
return;
}
auto entity = owner_.entityManager.getEntity(target);
auto entity = owner_.getEntityManager().getEntity(target);
if (!entity) {
owner_.addSystemChatMessage("You have no target.");
return;
@ -284,7 +284,7 @@ void SpellHandler::castSpell(uint32_t spellId, uint64_t targetGuid) {
isMeleeAbility = true;
}
if (isMeleeAbility && target != 0) {
auto entity = owner_.entityManager.getEntity(target);
auto entity = owner_.getEntityManager().getEntity(target);
if (entity) {
float dx = entity->getX() - owner_.movementInfo.x;
float dy = entity->getY() - owner_.movementInfo.y;
@ -305,7 +305,7 @@ void SpellHandler::castSpell(uint32_t spellId, uint64_t targetGuid) {
// Send both SET_FACING and a HEARTBEAT so the server has the updated orientation
// before it processes the cast packet.
if (target != 0) {
auto entity = owner_.entityManager.getEntity(target);
auto entity = owner_.getEntityManager().getEntity(target);
if (entity) {
float dx = entity->getX() - owner_.movementInfo.x;
float dy = entity->getY() - owner_.movementInfo.y;
@ -819,7 +819,7 @@ void SpellHandler::handleCastFailed(network::Packet& packet) {
// Show failure reason
int powerType = -1;
auto playerEntity = owner_.entityManager.getEntity(owner_.playerGuid);
auto playerEntity = owner_.getEntityManager().getEntity(owner_.playerGuid);
if (auto playerUnit = std::dynamic_pointer_cast<Unit>(playerEntity)) {
powerType = playerUnit->getPowerType();
}
@ -1418,13 +1418,13 @@ void SpellHandler::handleAchievementEarned(network::Packet& packet) {
}
} else {
std::string senderName;
auto entity = owner_.entityManager.getEntity(guid);
auto entity = owner_.getEntityManager().getEntity(guid);
if (auto* unit = dynamic_cast<Unit*>(entity.get())) {
senderName = unit->getName();
}
if (senderName.empty()) {
auto nit = owner_.playerNameCache.find(guid);
if (nit != owner_.playerNameCache.end())
auto nit = owner_.getPlayerNameCache().find(guid);
if (nit != owner_.getPlayerNameCache().end())
senderName = nit->second;
}
if (senderName.empty()) {
@ -2073,7 +2073,7 @@ void SpellHandler::handleCastResult(network::Packet& packet) {
owner_.craftQueueSpellId_ = 0; owner_.craftQueueRemaining_ = 0;
owner_.queuedSpellId_ = 0; owner_.queuedSpellTarget_ = 0;
int playerPowerType = -1;
if (auto pe = owner_.entityManager.getEntity(owner_.playerGuid)) {
if (auto pe = owner_.getEntityManager().getEntity(owner_.playerGuid)) {
if (auto pu = std::dynamic_pointer_cast<Unit>(pe))
playerPowerType = static_cast<int>(pu->getPowerType());
}
@ -2151,7 +2151,7 @@ void SpellHandler::handlePlaySpellVisual(network::Packet& packet) {
if (casterGuid == owner_.playerGuid) {
spawnPos = renderer->getCharacterPosition();
} else {
auto entity = owner_.entityManager.getEntity(casterGuid);
auto entity = owner_.getEntityManager().getEntity(casterGuid);
if (!entity) return;
glm::vec3 canonical(entity->getLatestX(), entity->getLatestY(), entity->getLatestZ());
spawnPos = core::coords::canonicalToRender(canonical);
@ -2308,7 +2308,7 @@ void SpellHandler::handleSpellFailure(network::Packet& packet) {
if (failGuid == owner_.playerGuid && failReason != 0) {
// Show interruption/failure reason in chat and error overlay for player
int pt = -1;
if (auto pe = owner_.entityManager.getEntity(owner_.playerGuid))
if (auto pe = owner_.getEntityManager().getEntity(owner_.playerGuid))
if (auto pu = std::dynamic_pointer_cast<Unit>(pe))
pt = static_cast<int>(pu->getPowerType());
const char* reason = getSpellCastResultString(failReason, pt);