aboutsummaryrefslogtreecommitdiff
path: root/src/game/Creature.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/Creature.cpp')
-rw-r--r--src/game/Creature.cpp37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index 1dc436b104f..fa710a41be3 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -1689,8 +1689,7 @@ bool Creature::canStartAttack(Unit const* who, bool force) const
if(!force)
{
- // if victim(1) has a victim(2), and victim(2) is a non-friendly player, don't attack victim(1) unless forced
- if(who->getVictim() && who->getVictim()->GetCharmerOrOwnerPlayerOrPlayerItself() && !IsFriendlyTo(who->getVictim()))
+ if(!_IsTargetAcceptable(who))
return false;
if(who->isInCombat())
@@ -2149,14 +2148,6 @@ bool Creature::CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction /
if (GetCharmerOrOwnerGUID())
return false;
- // don't help players or units controlled or owned by players
- if (u->GetCharmerOrOwnerPlayerOrPlayerItself())
- return false;
-
- // don't help if the unit is fleeing from the enemy player
- if (!u->isAttackingPlayer() && enemy->GetTypeId() == TYPEID_PLAYER)
- return false;
-
// only from same creature faction
if (checkfaction)
{
@@ -2176,6 +2167,32 @@ bool Creature::CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction /
return true;
}
+// use this function to avoid having hostile creatures attack
+// friendlies and other mobs they shouldn't attack
+bool Creature::_IsTargetAcceptable(const Unit* target) const
+{
+ const Unit* targetVictim = target->getAttackerForHelper();
+
+ if(!targetVictim) // if target does not have a victim, the target is acceptable
+ return true;
+
+ const Player* targetVictimPlayer = targetVictim->GetCharmerOrOwnerPlayerOrPlayerItself();
+
+ if(!targetVictimPlayer) // if the victim is not a player, the target is acceptable
+ return true;
+
+ // if the victim is a non-friendly player, the target is not acceptable
+ if(!IsFriendlyTo(targetVictim))
+ return false;
+
+ // if the target is passive, the target is not acceptable
+ if(((Creature*)target)->GetReactState() == REACT_PASSIVE)
+ return false;
+
+ // otherwise, the target is acceptable
+ return true;
+}
+
void Creature::SaveRespawnTime()
{
if(isSummon() || !m_DBTableGuid || m_creatureData && !m_creatureData->dbData)