*Passive targets under attack by players are not ideal targets for hostile creatures, so avoid them.
--HG-- branch : trunk
This commit is contained in:
+27
-10
@@ -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)
|
||||
|
||||
@@ -641,6 +641,7 @@ class TRINITY_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 _IsTargetAcceptable(const Unit* target) const;
|
||||
|
||||
MovementGeneratorType GetDefaultMovementType() const { return m_defaultMovementType; }
|
||||
void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; }
|
||||
|
||||
+2
-3
@@ -11344,7 +11344,7 @@ Unit* Creature::SelectVictim()
|
||||
else
|
||||
return NULL;
|
||||
|
||||
if(target && (!target->getVictim() || IsFriendlyTo(target->getVictim()))) // if victim(1) has a victim(2), only attack victim(1) if we are friendly with victim(2)
|
||||
if(target && _IsTargetAcceptable(target))
|
||||
{
|
||||
SetInFront(target);
|
||||
return target;
|
||||
@@ -11358,7 +11358,6 @@ Unit* Creature::SelectVictim()
|
||||
{
|
||||
if((*itr) && canCreatureAttack(*itr) && (*itr)->GetTypeId() != TYPEID_PLAYER
|
||||
&& !((Creature*)(*itr))->HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN))
|
||||
// && (!(*itr)->getVictim() || IsFriendlyTo((*itr)->getVictim()))) // if victim(1) has a victim(2), only attack victim(1) if we are friendly with victim(2)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -11369,7 +11368,7 @@ Unit* Creature::SelectVictim()
|
||||
// search nearby enemy before enter evade mode
|
||||
if(HasReactState(REACT_AGGRESSIVE))
|
||||
if(target = SelectNearestTarget())
|
||||
if(!target->getVictim() || IsFriendlyTo(target->getVictim())) // if victim(1) has a victim(2), only attack victim(1) if we are friendly with victim(2)
|
||||
if(_IsTargetAcceptable(target))
|
||||
return target;
|
||||
|
||||
if(m_invisibilityMask)
|
||||
|
||||
Reference in New Issue
Block a user