diff --git a/zone/entity.cpp b/zone/entity.cpp index fa9a198f1..e20090491 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -5032,6 +5032,9 @@ void EntityList::ReloadMerchants() { } /** + * If we have a distance requested that is greater than our scanning distance + * then we return the full list + * * @param mob * @param distance * @return diff --git a/zone/entity.h b/zone/entity.h index 125bd1c7a..8e37d5342 100644 --- a/zone/entity.h +++ b/zone/entity.h @@ -512,7 +512,7 @@ public: inline const std::unordered_map &GetObjectList() { return object_list; } inline const std::unordered_map &GetDoorsList() { return door_list; } - std::unordered_map &GetCloseMobList(Mob *mob, float distance); + std::unordered_map &GetCloseMobList(Mob *mob, float distance = 0); void DepopAll(int NPCTypeID, bool StartSpawnTimer = true); diff --git a/zone/mob.h b/zone/mob.h index c0449af4b..cdd6f7041 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -171,7 +171,6 @@ public: void DisplayInfo(Mob *mob); std::unordered_map close_mobs; - std::unordered_map& GetSmartMobList(float distance = 0); Timer mob_scan_close; Timer mob_check_moving_timer; diff --git a/zone/npc.cpp b/zone/npc.cpp index 5325ea836..8b4996177 100644 --- a/zone/npc.cpp +++ b/zone/npc.cpp @@ -3019,14 +3019,14 @@ void NPC::SetSimpleRoamBox(float box_size, float move_distance, int move_delay) /** * @param caster * @param chance - * @param in_cast_range + * @param cast_range * @param spell_types * @return */ bool NPC::AICheckCloseBeneficialSpells( NPC *caster, uint8 chance, - float in_cast_range, + float cast_range, uint32 spell_types ) { @@ -3061,24 +3061,18 @@ bool NPC::AICheckCloseBeneficialSpells( return false; } - /** - * Cast range - */ - in_cast_range = (in_cast_range * in_cast_range); - /** * Check through close range mobs */ - for (auto & close_mob : close_mobs) { + for (auto & close_mob : entity_list.GetCloseMobList(caster, cast_range)) { Mob *mob = close_mob.second; if (mob->IsClient()) { continue; } - float distance = DistanceSquared(mob->GetPosition(), GetPosition()); - - if (distance > in_cast_range) { + float distance = Distance(mob->GetPosition(), caster->GetPosition()); + if (distance > cast_range) { continue; } @@ -3086,7 +3080,7 @@ bool NPC::AICheckCloseBeneficialSpells( "NPC [{}] Distance [{}] Cast Range [{}] Caster [{}]", mob->GetCleanName(), distance, - in_cast_range, + cast_range, caster->GetCleanName() ); @@ -3134,7 +3128,7 @@ void NPC::AIYellForHelp(Mob *sender, Mob *attacker) GetID() ); - for (auto &close_mob : close_mobs) { + for (auto &close_mob : entity_list.GetCloseMobList(sender)) { Mob *mob = close_mob.second; float distance = DistanceSquared(m_Position, mob->GetPosition()); @@ -3143,18 +3137,18 @@ void NPC::AIYellForHelp(Mob *sender, Mob *attacker) } float assist_range = (mob->GetAssistRange() * mob->GetAssistRange()); - if (distance > assist_range) { continue; } LogAIYellForHelpDetail( - "NPC [{}] ID [{}] is scanning - checking against NPC [{}] range [{}] dist [{}]", + "NPC [{}] ID [{}] is scanning - checking against NPC [{}] range [{}] dist [{}] in_range [{}]", GetCleanName(), GetID(), mob->GetCleanName(), assist_range, - distance + distance, + (distance < assist_range) ); if (mob->CheckAggro(attacker)) { diff --git a/zone/npc.h b/zone/npc.h index 6d53d2106..84ab8b4ef 100644 --- a/zone/npc.h +++ b/zone/npc.h @@ -143,7 +143,7 @@ public: virtual bool AI_IdleCastCheck(); virtual void AI_Event_SpellCastFinished(bool iCastSucceeded, uint16 slot); - bool AICheckCloseBeneficialSpells(NPC* caster, uint8 chance, float in_cast_range, uint32 spell_types); + bool AICheckCloseBeneficialSpells(NPC* caster, uint8 chance, float cast_range, uint32 spell_types); void AIYellForHelp(Mob* sender, Mob* attacker); void LevelScale();