diff options
author | Treeston <treeston.mmoc@gmail.com> | 2017-05-29 16:39:20 +0200 |
---|---|---|
committer | funjoker <funjoker109@gmail.com> | 2020-06-14 23:49:04 +0200 |
commit | aa811d57b6dfd21689b6aaac3502c03528533222 (patch) | |
tree | 74411c052f59ccd3c6f58babc282f37c02bf0683 | |
parent | e782799c30367cfb0be4433395cf96b052268551 (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)
(cherry picked from commit 69fd6245dc41dca658cadb4e99c1ee6593fe000b)
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 7 | ||||
-rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 15 |
2 files changed, 13 insertions, 9 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 663976fca6a..fbdfedc6625 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -2425,14 +2425,9 @@ bool Creature::_IsTargetAcceptable(Unit const* target) const Unit const* targetVictim = target->getAttackerForHelper(); // if I'm already fighting target, or I'm hostile towards the target, the target is acceptable - if (GetVictim() == target || IsHostileTo(target)) + if (IsInCombatWith(target) || IsHostileTo(target)) return true; - // a player is targeting me, but I'm not hostile towards it, and not currently attacking it, the target is not acceptable - // (players may set their victim from a distance, and doesn't mean we should attack) - if (target->GetTypeId() == TYPEID_PLAYER && targetVictim == this) - return false; - // if the target's victim is friendly, and the target is neutral, the target is acceptable if (targetVictim && IsFriendlyTo(targetVictim)) return true; diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 6e485f64fc2..6d5b164f594 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -5635,13 +5635,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) |