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) if (!me->canFly() && me->GetDistanceZ(unit) > CREATURE_Z_ATTACK_RANGE)
return; 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->IsHostileToPlayers() || me->IsHostileTo(unit) /*|| u->getVictim() && me->IsFriendlyTo(u->getVictim())*/) &&
unit->isInAccessiblePlaceFor(me)) unit->isInAccessiblePlaceFor(me))
{ {
+1 -1
View File
@@ -39,7 +39,7 @@ void PossessedAI::UpdateAI(const uint32 /*diff*/)
{ {
if (me->getVictim()) if (me->getVictim())
{ {
if (!me->canAttack(me->getVictim())) if (!me->IsValidAttackTarget(me->getVictim()))
me->AttackStop(); me->AttackStop();
else else
DoMeleeAttackIfReady(); DoMeleeAttackIfReady();
+1 -1
View File
@@ -58,7 +58,7 @@ bool PetAI::_needToStop()
if (_CheckTargetCC(me->getVictim()) && !targetHasCC) if (_CheckTargetCC(me->getVictim()) && !targetHasCC)
return true; return true;
return !me->canAttack(me->getVictim()); return !me->IsValidAttackTarget(me->getVictim());
} }
void PetAI::_stopAttack() 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()); me->GetMotionMaster()->MoveFollow(charmer, PET_FOLLOW_DIST, me->GetFollowAngle());
Unit* target = me->getVictim(); Unit* target = me->getVictim();
if (!target || !charmer->canAttack(target)) if (!target || !charmer->IsValidAttackTarget(target))
AttackStart(charmer->SelectNearestTargetInAttackDistance()); AttackStart(charmer->SelectNearestTargetInAttackDistance());
} }
+1 -1
View File
@@ -528,7 +528,7 @@ AISpellInfoType* GetAISpellInfo(uint32 i);
inline void CreatureAI::SetGazeOn(Unit* target) inline void CreatureAI::SetGazeOn(Unit* target)
{ {
if (me->canAttack(target)) if (me->IsValidAttackTarget(target))
{ {
AttackStart(target); AttackStart(target);
me->SetReactState(REACT_PASSIVE); me->SetReactState(REACT_PASSIVE);
@@ -1989,7 +1989,7 @@ bool Creature::canCreatureAttack(Unit const* pVictim, bool force) const
if (!pVictim->IsInMap(this)) if (!pVictim->IsInMap(this))
return false; return false;
if (!canAttack(pVictim, force)) if (!IsValidAttackTarget(pVictim))
return false; return false;
if (!pVictim->isInAccessiblePlaceFor(this)) if (!pVictim->isInAccessiblePlaceFor(this))
@@ -199,7 +199,7 @@ void CreatureGroup::MemberAttackStart(Creature* member, Unit* target)
if (itr->first->getVictim()) if (itr->first->getVictim())
continue; continue;
if (itr->first->canAttack(target) && itr->first->AI()) if (itr->first->IsValidAttackTarget(target) && itr->first->AI())
itr->first->AI()->AttackStart(target); 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); GetMotionMaster()->MoveFollow(charmer, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
Unit* target = getVictim(); Unit* target = getVictim();
if (!target || !charmer->canAttack(target)) if (!target || !charmer->IsValidAttackTarget(target))
{ {
target = charmer->SelectNearestTarget(); target = charmer->SelectNearestTarget();
if (!target) 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 bool Unit::_IsValidAttackTarget(Unit const* target, SpellInfo const* bySpell) const
{ {
ASSERT(target);
// can't attack self // can't attack self
if (this == target) if (this == target)
return false; return false;
@@ -12506,6 +12508,8 @@ bool Unit::IsValidAssistTarget(Unit const* target) const
bool Unit::_IsValidAssistTarget(Unit const* target, SpellInfo const* bySpell) const bool Unit::_IsValidAssistTarget(Unit const* target, SpellInfo const* bySpell) const
{ {
ASSERT(target);
// can assist to self // can assist to self
if (this == target) if (this == target)
return true; return true;
@@ -13171,7 +13175,7 @@ Unit* Creature::SelectVictim()
{ {
--aura; --aura;
caster = (*aura)->GetCaster(); 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; target = caster;
break; break;
@@ -807,7 +807,7 @@ namespace Trinity
return u->isAlive() return u->isAlive()
&& i_funit->IsWithinDistInMap(u, i_range) && i_funit->IsWithinDistInMap(u, i_range)
&& !i_funit->IsFriendlyTo(u) && !i_funit->IsFriendlyTo(u)
&& i_funit->canAttack(u) && i_funit->IsValidAttackTarget(u)
&& u->GetCreatureType() != CREATURE_TYPE_CRITTER && u->GetCreatureType() != CREATURE_TYPE_CRITTER
&& i_funit->canSeeOrDetect(u); && i_funit->canSeeOrDetect(u);
} }
@@ -977,7 +977,7 @@ namespace Trinity
if (!me->IsWithinDistInMap(u, m_range)) if (!me->IsWithinDistInMap(u, m_range))
return false; return false;
if (!me->canAttack(u)) if (!me->IsValidAttackTarget(u))
return false; return false;
m_range = me->GetDistance(u); // use found unit range as new range limit for next check 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 (m_force)
{ {
if (!me->canAttack(u)) if (!me->IsValidAttackTarget(u))
return false; return false;
} }
else else
@@ -45,7 +45,7 @@ void WorldSession::HandleAttackSwingOpcode(WorldPacket & recv_data)
return; return;
} }
if (!_player->canAttack(pEnemy)) if (!_player->IsValidAttackTarget(pEnemy))
{ {
// stop attack state at client // stop attack state at client
SendAttackStop(pEnemy); SendAttackStop(pEnemy);
@@ -191,7 +191,7 @@ void WorldSession::HandlePetActionHelper(Unit* pet, uint64 guid1, uint16 spellid
return; return;
if (Unit* owner = pet->GetOwner()) if (Unit* owner = pet->GetOwner())
if (!owner->canAttack(TargetUnit)) if (!owner->IsValidAttackTarget(TargetUnit))
return; return;
// Not let attack through obstructions // Not let attack through obstructions
+1 -1
View File
@@ -1364,7 +1364,7 @@ void Spell::EffectDummy(SpellEffIndex effIndex)
// remove invalid attackers // remove invalid attackers
for (Unit::AttackerSet::iterator aItr = attackers.begin(); aItr != attackers.end();) for (Unit::AttackerSet::iterator aItr = attackers.begin(); aItr != attackers.end();)
if (!(*aItr)->canAttack(m_caster)) if (!(*aItr)->IsValidAttackTarget(m_caster))
attackers.erase(aItr++); attackers.erase(aItr++);
else else
++aItr; ++aItr;
@@ -226,7 +226,7 @@ public:
Unit* eventStarter = Unit::GetUnit(*me, uiEventStarterGUID); Unit* eventStarter = Unit::GetUnit(*me, uiEventStarterGUID);
if (eventStarter && me->canAttack(eventStarter)) if (eventStarter && me->IsValidAttackTarget(eventStarter))
AttackStart(eventStarter); AttackStart(eventStarter);
else if (!UpdateVictim()) else if (!UpdateVictim())
{ {
@@ -250,7 +250,7 @@ public:
// switch to "who" if nearer than current target. // switch to "who" if nearer than current target.
void SelectNearestTarget(Unit* who) void SelectNearestTarget(Unit* who)
{ {
if (me->getVictim() && me->GetDistanceOrder(who, me->getVictim()) && me->canAttack(who)) if (me->getVictim() && me->GetDistanceOrder(who, me->getVictim()) && me->IsValidAttackTarget(who))
{ {
me->getThreatManager().modifyThreatPercent(me->getVictim(), -100); me->getThreatManager().modifyThreatPercent(me->getVictim(), -100);
me->AddThreat(who, 1000000.0f); me->AddThreat(who, 1000000.0f);
@@ -862,7 +862,7 @@ public:
void EnterCombat(Unit* who) void EnterCombat(Unit* who)
{ {
if (me->canAttack(who)) if (me->IsValidAttackTarget(who))
AttackStart(who); AttackStart(who);
} }
@@ -1618,7 +1618,7 @@ public:
void EnterCombat(Unit* who) void EnterCombat(Unit* who)
{ {
if (me->canAttack(who)) if (me->IsValidAttackTarget(who))
AttackStart(who); AttackStart(who);
} }