bool Unit::SelectHostilTarget() { //function provides main threat functionality //next-victim-selection algorithm and evade mode are called //threat list sorting etc. assert(GetTypeId()== TYPEID_UNIT); Unit* target = NULL; //This function only useful once AI has been initilazied if (!((Creature*)this)->AI()) return false; if(!m_ThreatManager.isThreatListEmpty()) { if(!HasAuraType(SPELL_AURA_MOD_TAUNT)) { target = m_ThreatManager.getHostilTarget(); } } if(target) { if(!hasUnitState(UNIT_STAT_STUNDED)) SetInFront(target); ((Creature*)this)->AI()->AttackStart(target); return true; } // no target but something prevent go to evade mode // Check for Hunter Freezing Traps & Rouge Blind Spell // These auras need removing if creature has no valid target. if( ((Creature*)this)->hasUnitState(UNIT_STAT_STUNDED) || ((Creature*)this)->hasUnitState(UNIT_STAT_CONFUSED)) { if( ((Creature*)this)->HasAura(3355, 0 ) || ((Creature*)this)->HasAura(14308, 0 ) || ((Creature*)this)->HasAura(14309, 0 ) || ((Creature*)this)->HasAura(2094, 0 ) ) { ((Creature*)this)->RemoveAurasDueToSpell(2094);// Blind ((Creature*)this)->RemoveAurasDueToSpell(3355);// Freezing Trap Effect 1 ((Creature*)this)->RemoveAurasDueToSpell(14308);// Freezing Trap Effect 2 ((Creature*)this)->RemoveAurasDueToSpell(14309);// Freezing Trap Effect 3 } } if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT) || !CanFreeMove() ) return false; // last case when creature don't must go to evade mode: // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list // for example at owner command to pet attack some far away creature // Note: creature not have targeted movement generator but have attacker in this case if( GetMotionMaster()->empty() || GetMotionMaster()->top()->GetMovementGeneratorType() != TARGETED_MOTION_TYPE ) { for(AttackerSet::const_iterator itr = m_attackers.begin(); itr != m_attackers.end(); ++itr) { if( (*itr)->IsInMap(this) && (*itr)->isTargetableForAttack() && (*itr)->isInAccessablePlaceFor((Creature*)this) ) return false; } } // enter in evade mode in other case ((Creature*)this)->AI()->EnterEvadeMode(); return false; }