[svn] Add Unit::IsWithinCombatDist function to check melee range and spell range (now range is related to the attacker's bounding_radius and target's combat_reach, not sure if both should be combat_reach).

--HG--
branch : trunk
This commit is contained in:
megamage
2008-10-19 14:42:12 -05:00
parent e7519059c9
commit 672d304a44
5 changed files with 21 additions and 6 deletions
+1 -1
View File
@@ -133,7 +133,7 @@ void ScriptedAI::DoMeleeAttackIfReady()
if( m_creature->isAttackReady() && !m_creature->IsNonMeleeSpellCasted(false))
{
//If we are within range melee the target
if( m_creature->IsWithinDistInMap(m_creature->getVictim(), ATTACK_DISTANCE))
if( m_creature->IsWithinCombatDist(m_creature->getVictim(), ATTACK_DISTANCE))
{
m_creature->AttackerStateUpdate(m_creature->getVictim());
m_creature->resetAttackTimer();
+2 -2
View File
@@ -1056,7 +1056,7 @@ void Player::Update( uint32 p_time )
if (isAttackReady(BASE_ATTACK))
{
if(!IsWithinDistInMap(pVictim, pldistance))
if(!IsWithinCombatDist(pVictim, pldistance))
{
setAttackTimer(BASE_ATTACK,100);
if(m_swingErrorMsg != 1) // send single time (client auto repeat)
@@ -1093,7 +1093,7 @@ void Player::Update( uint32 p_time )
if ( haveOffhandWeapon() && isAttackReady(OFF_ATTACK))
{
if(!IsWithinDistInMap(pVictim, pldistance))
if(!IsWithinCombatDist(pVictim, pldistance))
{
setAttackTimer(OFF_ATTACK,100);
}
+2 -3
View File
@@ -4337,10 +4337,9 @@ uint8 Spell::CheckRange(bool strict)
if(target && target != m_caster)
{
// distance from target center in checks
float dist = m_caster->GetDistance(target->GetPositionX(),target->GetPositionY(),target->GetPositionZ());
if(dist > max_range)
if(!m_caster->IsWithinCombatDist(target, max_range))
return SPELL_FAILED_OUT_OF_RANGE; //0x5A;
if(dist < min_range)
if(min_range && m_caster->IsWithinCombatDist(target, min_range)) // skip this check if min_range = 0
return SPELL_FAILED_TOO_CLOSE;
if( m_caster->GetTypeId() == TYPEID_PLAYER &&
(m_spellInfo->FacingCasterFlags & SPELL_FACING_FLAG_INFRONT) && !m_caster->HasInArc( M_PI, target ) )
+15
View File
@@ -408,6 +408,21 @@ bool Unit::canReachWithAttack(Unit *pVictim) const
return IsWithinDistInMap(pVictim, reach);
}
bool Unit::IsWithinCombatDist(Unit *obj, float dist2compare) const
{
if (!obj || !IsInMap(obj)) return false;
float dx = GetPositionX() - obj->GetPositionX();
float dy = GetPositionY() - obj->GetPositionY();
float dz = GetPositionZ() - obj->GetPositionZ();
float distsq = dx*dx + dy*dy + dz*dz;
//not sure here, or combatreach + combatreach?
float sizefactor = GetObjectSize() + obj->GetFloatValue(UNIT_FIELD_COMBATREACH);
float maxdist = dist2compare + sizefactor;
return distsq < maxdist * maxdist;
}
void Unit::RemoveSpellsCausingAura(AuraType auraType)
{
if (auraType >= TOTAL_AURAS) return;
+1
View File
@@ -718,6 +718,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
bool isAttackReady(WeaponAttackType type = BASE_ATTACK) const { return m_attackTimer[type] == 0; }
bool haveOffhandWeapon() const;
bool canReachWithAttack(Unit *pVictim) const;
bool IsWithinCombatDist(Unit *obj, float dist2compare) const;
uint32 m_extraAttacks;
void _addAttacker(Unit *pAttacker) // must be called only from Unit::Attack(Unit*)