Jump to content

[fix] pet attack range

Auntie Mangos

Recommended Posts

Very old problem. Tryed to fix this month' ago (http://getmangos.eu/community/viewtopic.php?id=654). Just noticed it again but because the system has changed here is a new (simple) fix.

Problem is that Unit::canReachWithAttack is used PetAI::Update to determine wheather a pet is close enough to attack or not. CanReachWithAttack uses UNIT_FIELD_COMBATREACH for calculation, witch can be 1 or lower for normal sized pets.

In TargetedMovementGenerator<T>::Update it is checked if the distance is greater RATE_TARGET_POS_RECALCULATION_RANGE (+objsize...). As this is 1.5 by default there is the case, that the pet's TMG targetlocation is not updatet, but the pet can't reach the target with the meleeattack.

CanReachWithAttack is only used for PetAI, so I think this is maybe outdatet and should not be used anymore!? In all other cases IsWithinDistInMap(victim, ATTACK_DISTANCE) is used, so that we have a fixed meleerange of 5.

Patch: http://github.com/pasdVn/mangos/commit/d5861030bfe33643b4bccc35a4efbcef2c566e54

Other sollution would be to limit the range to RATE_TARGET_POS_RECALCULATION_RANGE (as a minimum) in canReachWithAttack


Link to comment
Share on other sites

  • 39 years later...

A little change to let the patch apply on newer mangos:

diff --git a/src/game/PetAI.cpp b/src/game/PetAI.cpp
index 8de2644..23d431a 100644
--- a/src/game/PetAI.cpp
+++ b/src/game/PetAI.cpp
@@ -162,7 +162,7 @@ void PetAI::UpdateAI(const uint32 diff)
            // not required to be stopped case
-            else if (m_creature->isAttackReady() && m_creature->canReachWithAttack(m_creature->getVictim()))
+            else if (m_creature->isAttackReady() && m_creature->IsWithinDistInMap(m_creature->getVictim(), ATTACK_DISTANCE))

@@ -335,6 +335,6 @@ void PetAI::AttackedBy(Unit *attacker)
    //when attacked, fight back in case 1)no victim already AND 2)not set to passive AND 3)not set to stay, unless can it can reach attacker with melee attack anyway
    if(!m_creature->getVictim() && m_creature->GetCharmInfo() && !m_creature->GetCharmInfo()->HasReactState(REACT_PASSIVE) &&
-        (!m_creature->GetCharmInfo()->HasCommandState(COMMAND_STAY) || m_creature->canReachWithAttack(attacker)))
+        (!m_creature->GetCharmInfo()->HasCommandState(COMMAND_STAY) || m_creature->IsWithinDistInMap(m_creature->getVictim(), ATTACK_DISTANCE)))

Great job pasdVn, still the best ;)

Link to comment
Share on other sites

  • 4 weeks later...
This topic is now closed to further replies.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use