diff --git a/src/game/AggressorAI.cpp b/src/game/AggressorAI.cpp index 4ab9a7ab2..b6a5e356d 100644 --- a/src/game/AggressorAI.cpp +++ b/src/game/AggressorAI.cpp @@ -47,9 +47,8 @@ AggressorAI::MoveInLineOfSight(Unit *u) if( !m_creature->canFly() && m_creature->GetDistanceZ(u) > CREATURE_Z_ATTACK_RANGE ) return; - if (!m_creature->hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_DIED) && u->isTargetableForAttack() && - ( m_creature->IsHostileTo( u ) /*|| u->getVictim() && m_creature->IsFriendlyTo( u->getVictim() )*/ ) && - u->isInAccessablePlaceFor(m_creature)) + if (m_creature->CanInitiateAttack() && u->isTargetableForAttack() && + m_creature->IsHostileTo(u) && u->isInAccessablePlaceFor(m_creature)) { float attackRadius = m_creature->GetAttackDistance(u); if(m_creature->IsWithinDistInMap(u, attackRadius) && m_creature->IsWithinLOSInMap(u) ) diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 07b4a4c3c..cd4123c73 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -1634,6 +1634,20 @@ bool Creature::CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction / return true; } +bool Creature::CanInitiateAttack() +{ + if (hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_DIED)) + return false; + + if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE)) + return false; + + if (isPassiveToHostile()) + return false; + + return true; +} + void Creature::SaveRespawnTime() { if(isPet() || !m_DBTableGuid) diff --git a/src/game/Creature.h b/src/game/Creature.h index a713309a6..0ffd48d4d 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -556,6 +556,7 @@ class MANGOS_DLL_SPEC Creature : public Unit void SetNoSearchAssistance(bool val) { m_AlreadySearchedAssistance = val; } bool HasSearchedAssistance() { return m_AlreadySearchedAssistance; } bool CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction = true) const; + bool CanInitiateAttack(); MovementGeneratorType GetDefaultMovementType() const { return m_defaultMovementType; } void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; } diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index d036e9909..a564f8984 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -1022,7 +1022,7 @@ void CreatureEventAI::MoveInLineOfSight(Unit *who) if (m_creature->isCivilian() || m_creature->IsNeutralToAll()) return; - if (!m_creature->hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_DIED) && who->isTargetableForAttack() && + if (m_creature->CanInitiateAttack() && who->isTargetableForAttack() && m_creature->IsHostileTo(who) && who->isInAccessablePlaceFor(m_creature)) { if (!m_creature->canFly() && m_creature->GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE) diff --git a/src/game/Unit.h b/src/game/Unit.h index 1ca3879a9..8266046cc 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1342,6 +1342,8 @@ class MANGOS_DLL_SPEC Unit : public WorldObject void RemoveSpellbyDamageTaken(AuraType auraType, uint32 damage); bool isTargetableForAttack(bool inversAlive = false) const; + bool isPassiveToHostile() { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE); } + virtual bool IsInWater() const; virtual bool IsUnderWater() const; bool isInAccessablePlaceFor(Creature const* c) const; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index a3d5580ce..61da8a18c 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "9602" + #define REVISION_NR "9603" #endif // __REVISION_NR_H__