aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities/Unit
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2017-05-29 16:39:20 +0200
committerGitHub <noreply@github.com>2017-05-29 16:39:20 +0200
commit69fd6245dc41dca658cadb4e99c1ee6593fe000b (patch)
treebc3babb9d1ef46ab26975d7347089a2821d7ce2f /src/server/game/Entities/Unit
parent60a69bcd3d6ae5fe55d6a18e67938a3a61bbbe6a (diff)
Partial revert of 15a207f, which was causing issues (ref #4943 and #19768). Instead, fix the underlying issue from 15a207f one level further down - Unit::getAttackerForHelper() shouldn't return units that we aren't in combat with (victim can be such a unit for players/player pets, which can startattack from a distance without entering combat). (#19814)
Fixes the following issues: - Player pets would aggro neutral mobs as soon as they start autocasting (Imp's Firebolt) if they're in react range (due to victim != null, autocast counts as autoattack and sets victim) - Neutral mobs would randomly evade when aggro switched between targets. Closes #19768, #19485 and #10921. (from PR #19814)
Diffstat (limited to 'src/server/game/Entities/Unit')
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index f16fb651727..a3eaa245435 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -5768,13 +5768,22 @@ void Unit::_removeAttacker(Unit* pAttacker)
Unit* Unit::getAttackerForHelper() const // If someone wants to help, who to give them
{
- if (GetVictim() != NULL)
- return GetVictim();
+ if (Unit* victim = GetVictim())
+ if (!IsControlledByPlayer() || IsInCombatWith(victim) || victim->IsInCombatWith(this))
+ return victim;
if (!m_attackers.empty())
return *(m_attackers.begin());
- return NULL;
+ if (Player* owner = GetCharmerOrOwnerPlayerOrPlayerItself())
+ {
+ HostileRefManager& refs = owner->getHostileRefManager();
+ for (Reference<Unit, ThreatManager> const& ref : refs)
+ if (Unit* hostile = ref.GetSource()->GetOwner())
+ return hostile;
+ }
+
+ return nullptr;
}
bool Unit::Attack(Unit* victim, bool meleeAttack)