aboutsummaryrefslogtreecommitdiff
path: root/src/game/Unit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/Unit.cpp')
-rw-r--r--src/game/Unit.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 0d45ed36457..a05cc8929ea 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -11344,7 +11344,7 @@ Unit* Creature::SelectVictim()
else
return NULL;
- if(target)
+ if(target && (!target->isAttackingPlayer() || IsFriendlyTo(target->getVictim()))) // if the victim of target is a player, only defend the victim if we are friendly
{
SetInFront(target);
return target;
@@ -11356,7 +11356,9 @@ Unit* Creature::SelectVictim()
// Note: creature not have targeted movement generator but have attacker in this case
for(AttackerSet::const_iterator itr = m_attackers.begin(); itr != m_attackers.end(); ++itr)
{
- if(canCreatureAttack(*itr) && ((*itr)->GetTypeId() != TYPEID_PLAYER && (!((Creature*)(*itr))->HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN))))
+ if(canCreatureAttack(*itr) && (*itr)->GetTypeId() != TYPEID_PLAYER
+ && !((Creature*)(*itr))->HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN)
+ && (!(*itr)->isAttackingPlayer() || IsFriendlyTo(target->getVictim()))) // if the victim of target is a player, only defend the victim if we are friendly
return NULL;
}
@@ -11367,7 +11369,8 @@ Unit* Creature::SelectVictim()
// search nearby enemy before enter evade mode
if(HasReactState(REACT_AGGRESSIVE))
if(target = SelectNearestTarget())
- return target;
+ if(!target->isAttackingPlayer() || IsFriendlyTo(target->getVictim())) // if the victim of target is a player, only defend the victim if we are friendly
+ return target;
if(m_invisibilityMask)
{