From 59a2f0cdde4986aac63ab0a0cff06fac24dcb9e3 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Tue, 11 Jul 2017 01:58:47 -0500 Subject: [PATCH] Refactor close_npcs to close_mobs for future implementations --- zone/client.cpp | 2 +- zone/client.h | 2 +- zone/client_process.cpp | 17 ++++++++++------- zone/entity.cpp | 7 +++---- zone/entity.h | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/zone/client.cpp b/zone/client.cpp index 03e113ed0..986c2b582 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -358,7 +358,7 @@ Client::~Client() { m_tradeskill_object = nullptr; } - close_npcs.clear(); + close_mobs.clear(); if(IsDueling() && GetDuelTarget() != 0) { Entity* entity = entity_list.GetID(GetDuelTarget()); diff --git a/zone/client.h b/zone/client.h index 879e6622a..7bd02c46c 100644 --- a/zone/client.h +++ b/zone/client.h @@ -222,7 +222,7 @@ public: Client(EQStreamInterface * ieqs); ~Client(); - std::unordered_map close_npcs; + std::unordered_map close_mobs; bool is_client_moving; //abstract virtual function implementations required by base abstract class diff --git a/zone/client_process.cpp b/zone/client_process.cpp index a5ced5d1a..08cb9a325 100644 --- a/zone/client_process.cpp +++ b/zone/client_process.cpp @@ -254,7 +254,7 @@ bool Client::Process() { /* Build a close range list of NPC's */ if (npc_close_scan_timer.Check()) { - close_npcs.clear(); + close_mobs.clear(); auto &mob_list = entity_list.GetMobList(); float scan_range = (RuleI(Range, ClientNPCScan) * RuleI(Range, ClientNPCScan)); @@ -265,10 +265,10 @@ bool Client::Process() { float distance = DistanceSquared(m_Position, mob->GetPosition()); if (mob->IsNPC()) { if (distance <= scan_range) { - close_npcs.insert(std::pair(mob->CastToNPC(), distance)); + close_mobs.insert(std::pair(mob, distance)); } else if (mob->GetAggroRange() > scan_range) { - close_npcs.insert(std::pair(mob->CastToNPC(), distance)); + close_mobs.insert(std::pair(mob, distance)); } } @@ -631,11 +631,14 @@ bool Client::Process() { // only if client is not feigned if (zone->CanDoCombat() && ret && !GetFeigned() && client_scan_npc_aggro_timer.Check()) { int npc_scan_count = 0; - for (auto it = close_npcs.begin(); it != close_npcs.end(); ++it) { - NPC *npc = it->first; + for (auto it = close_mobs.begin(); it != close_mobs.end(); ++it) { + Mob *mob = it->first; - if (npc->CheckWillAggro(this) && !npc->CheckAggro(this)) { - npc->AddToHateList(this, 25); + if (mob->IsClient()) + continue; + + if (mob->CheckWillAggro(this) && !mob->CheckAggro(this)) { + mob->AddToHateList(this, 25); } npc_scan_count++; } diff --git a/zone/entity.cpp b/zone/entity.cpp index eee89ce0f..2a3429f02 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -2323,10 +2323,9 @@ bool EntityList::RemoveNPC(uint16 delete_id) // make sure its proximity is removed RemoveProximity(delete_id); // remove from client close lists - RemoveNPCFromClientCloseLists(npc); + RemoveMobFromClientCloseLists(npc->CastToMob()); // remove from the list npc_list.erase(it); - // remove from limit list if needed if (npc_limit_list.count(delete_id)) @@ -2336,11 +2335,11 @@ bool EntityList::RemoveNPC(uint16 delete_id) return false; } -bool EntityList::RemoveNPCFromClientCloseLists(NPC *npc) +bool EntityList::RemoveMobFromClientCloseLists(Mob *mob) { auto it = client_list.begin(); while (it != client_list.end()) { - it->second->close_npcs.erase(npc); + it->second->close_mobs.erase(mob); ++it; } return false; diff --git a/zone/entity.h b/zone/entity.h index 16249547b..036e0c419 100644 --- a/zone/entity.h +++ b/zone/entity.h @@ -279,7 +279,7 @@ public: bool RemoveTrap(uint16 delete_id); bool RemoveObject(uint16 delete_id); bool RemoveProximity(uint16 delete_npc_id); - bool RemoveNPCFromClientCloseLists(NPC *npc); + bool RemoveMobFromClientCloseLists(Mob *mob); void RemoveAllMobs(); void RemoveAllClients(); void RemoveAllNPCs();