diff options
author | megamage <none@none> | 2008-10-19 14:42:12 -0500 |
---|---|---|
committer | megamage <none@none> | 2008-10-19 14:42:12 -0500 |
commit | 672d304a4478afa58d6e094b1bf53ae25b176356 (patch) | |
tree | 6c8524a714d9885415249a20274e773be71a10d6 /src | |
parent | e7519059c93476d2ea78225d3785ddbf6d607900 (diff) |
[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
Diffstat (limited to 'src')
-rw-r--r-- | src/bindings/scripts/include/sc_creature.cpp | 2 | ||||
-rw-r--r-- | src/game/Player.cpp | 4 | ||||
-rw-r--r-- | src/game/Spell.cpp | 5 | ||||
-rw-r--r-- | src/game/Unit.cpp | 15 | ||||
-rw-r--r-- | src/game/Unit.h | 1 |
5 files changed, 21 insertions, 6 deletions
diff --git a/src/bindings/scripts/include/sc_creature.cpp b/src/bindings/scripts/include/sc_creature.cpp index b18d018c5a9..a5401b8100d 100644 --- a/src/bindings/scripts/include/sc_creature.cpp +++ b/src/bindings/scripts/include/sc_creature.cpp @@ -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(); diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 694c9eafc7b..32413aba503 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -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); } diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index f82f2bd29bf..3c44df10cb9 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -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 ) ) diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index ddce852a728..f7a3d96c00d 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -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; diff --git a/src/game/Unit.h b/src/game/Unit.h index 4410dd45b72..9c33b5a6c3f 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -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*) |