Core/Entities: Replace Unit::canAttack usage with more accurate Unit::IsValidAttackTarget

This commit is contained in:
QAston
2011-09-16 23:49:31 +02:00
parent 3a3f2d927f
commit c0b1823524
15 changed files with 23 additions and 19 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ void GuardAI::MoveInLineOfSight(Unit* unit)
if (!me->canFly() && me->GetDistanceZ(unit) > CREATURE_Z_ATTACK_RANGE)
return;
if (!me->getVictim() && me->canAttack(unit) &&
if (!me->getVictim() && me->IsValidAttackTarget(unit) &&
(unit->IsHostileToPlayers() || me->IsHostileTo(unit) /*|| u->getVictim() && me->IsFriendlyTo(u->getVictim())*/) &&
unit->isInAccessiblePlaceFor(me))
{
+1 -1
View File
@@ -39,7 +39,7 @@ void PossessedAI::UpdateAI(const uint32 /*diff*/)
{
if (me->getVictim())
{
if (!me->canAttack(me->getVictim()))
if (!me->IsValidAttackTarget(me->getVictim()))
me->AttackStop();
else
DoMeleeAttackIfReady();
+1 -1
View File
@@ -58,7 +58,7 @@ bool PetAI::_needToStop()
if (_CheckTargetCC(me->getVictim()) && !targetHasCC)
return true;
return !me->canAttack(me->getVictim());
return !me->IsValidAttackTarget(me->getVictim());
}
void PetAI::_stopAttack()
+1 -1
View File
@@ -242,6 +242,6 @@ void SimpleCharmedAI::UpdateAI(const uint32 /*diff*/)
me->GetMotionMaster()->MoveFollow(charmer, PET_FOLLOW_DIST, me->GetFollowAngle());
Unit* target = me->getVictim();
if (!target || !charmer->canAttack(target))
if (!target || !charmer->IsValidAttackTarget(target))
AttackStart(charmer->SelectNearestTargetInAttackDistance());
}
+1 -1
View File
@@ -528,7 +528,7 @@ AISpellInfoType* GetAISpellInfo(uint32 i);
inline void CreatureAI::SetGazeOn(Unit* target)
{
if (me->canAttack(target))
if (me->IsValidAttackTarget(target))
{
AttackStart(target);
me->SetReactState(REACT_PASSIVE);
@@ -1989,7 +1989,7 @@ bool Creature::canCreatureAttack(Unit const* pVictim, bool force) const
if (!pVictim->IsInMap(this))
return false;
if (!canAttack(pVictim, force))
if (!IsValidAttackTarget(pVictim))
return false;
if (!pVictim->isInAccessiblePlaceFor(this))
@@ -199,7 +199,7 @@ void CreatureGroup::MemberAttackStart(Creature* member, Unit* target)
if (itr->first->getVictim())
continue;
if (itr->first->canAttack(target) && itr->first->AI())
if (itr->first->IsValidAttackTarget(target) && itr->first->AI())
itr->first->AI()->AttackStart(target);
}
}
+1 -1
View File
@@ -23029,7 +23029,7 @@ void Player::UpdateCharmedAI()
GetMotionMaster()->MoveFollow(charmer, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
Unit* target = getVictim();
if (!target || !charmer->canAttack(target))
if (!target || !charmer->IsValidAttackTarget(target))
{
target = charmer->SelectNearestTarget();
if (!target)
+5 -1
View File
@@ -12370,6 +12370,8 @@ bool Unit::IsValidAttackTarget(Unit const* target) const
bool Unit::_IsValidAttackTarget(Unit const* target, SpellInfo const* bySpell) const
{
ASSERT(target);
// can't attack self
if (this == target)
return false;
@@ -12506,6 +12508,8 @@ bool Unit::IsValidAssistTarget(Unit const* target) const
bool Unit::_IsValidAssistTarget(Unit const* target, SpellInfo const* bySpell) const
{
ASSERT(target);
// can assist to self
if (this == target)
return true;
@@ -13171,7 +13175,7 @@ Unit* Creature::SelectVictim()
{
--aura;
caster = (*aura)->GetCaster();
if (caster && canSeeOrDetect(caster, true) && canAttack(caster) && caster->isInAccessiblePlaceFor(ToCreature()))
if (caster && canSeeOrDetect(caster, true) && IsValidAttackTarget(caster) && caster->isInAccessiblePlaceFor(ToCreature()))
{
target = caster;
break;
@@ -807,7 +807,7 @@ namespace Trinity
return u->isAlive()
&& i_funit->IsWithinDistInMap(u, i_range)
&& !i_funit->IsFriendlyTo(u)
&& i_funit->canAttack(u)
&& i_funit->IsValidAttackTarget(u)
&& u->GetCreatureType() != CREATURE_TYPE_CRITTER
&& i_funit->canSeeOrDetect(u);
}
@@ -977,7 +977,7 @@ namespace Trinity
if (!me->IsWithinDistInMap(u, m_range))
return false;
if (!me->canAttack(u))
if (!me->IsValidAttackTarget(u))
return false;
m_range = me->GetDistance(u); // use found unit range as new range limit for next check
@@ -1008,7 +1008,7 @@ namespace Trinity
if (m_force)
{
if (!me->canAttack(u))
if (!me->IsValidAttackTarget(u))
return false;
}
else
@@ -45,7 +45,7 @@ void WorldSession::HandleAttackSwingOpcode(WorldPacket & recv_data)
return;
}
if (!_player->canAttack(pEnemy))
if (!_player->IsValidAttackTarget(pEnemy))
{
// stop attack state at client
SendAttackStop(pEnemy);
@@ -191,7 +191,7 @@ void WorldSession::HandlePetActionHelper(Unit* pet, uint64 guid1, uint16 spellid
return;
if (Unit* owner = pet->GetOwner())
if (!owner->canAttack(TargetUnit))
if (!owner->IsValidAttackTarget(TargetUnit))
return;
// Not let attack through obstructions
+1 -1
View File
@@ -1364,7 +1364,7 @@ void Spell::EffectDummy(SpellEffIndex effIndex)
// remove invalid attackers
for (Unit::AttackerSet::iterator aItr = attackers.begin(); aItr != attackers.end();)
if (!(*aItr)->canAttack(m_caster))
if (!(*aItr)->IsValidAttackTarget(m_caster))
attackers.erase(aItr++);
else
++aItr;