mirror of
https://github.com/mangosfour/server.git
synced 2025-12-12 19:37:03 +00:00
[c12616] Simplify use of CombatReach
This commit is contained in:
parent
e478b27dcc
commit
dc3de04d62
6 changed files with 36 additions and 22 deletions
|
|
@ -1683,7 +1683,7 @@ SpellEntry const* Creature::ReachWithSpellAttack(Unit* pVictim)
|
||||||
float range = GetSpellMaxRange(srange);
|
float range = GetSpellMaxRange(srange);
|
||||||
float minrange = GetSpellMinRange(srange);
|
float minrange = GetSpellMinRange(srange);
|
||||||
|
|
||||||
float dist = GetCombatDistance(pVictim);
|
float dist = GetCombatDistance(pVictim, spellInfo->rangeIndex == SPELL_RANGE_IDX_COMBAT);
|
||||||
|
|
||||||
// if(!isInFront( pVictim, range ) && spellInfo->AttributesEx )
|
// if(!isInFront( pVictim, range ) && spellInfo->AttributesEx )
|
||||||
// continue;
|
// continue;
|
||||||
|
|
@ -1739,7 +1739,7 @@ SpellEntry const* Creature::ReachWithSpellCure(Unit* pVictim)
|
||||||
float range = GetSpellMaxRange(srange);
|
float range = GetSpellMaxRange(srange);
|
||||||
float minrange = GetSpellMinRange(srange);
|
float minrange = GetSpellMinRange(srange);
|
||||||
|
|
||||||
float dist = GetCombatDistance(pVictim);
|
float dist = GetCombatDistance(pVictim, spellInfo->rangeIndex == SPELL_RANGE_IDX_COMBAT);
|
||||||
|
|
||||||
// if(!isInFront( pVictim, range ) && spellInfo->AttributesEx )
|
// if(!isInFront( pVictim, range ) && spellInfo->AttributesEx )
|
||||||
// continue;
|
// continue;
|
||||||
|
|
@ -2096,7 +2096,7 @@ bool Creature::MeetsSelectAttackingRequirement(Unit* pTarget, SpellEntry const*
|
||||||
SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(pSpellInfo->rangeIndex);
|
SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(pSpellInfo->rangeIndex);
|
||||||
float max_range = GetSpellMaxRange(srange);
|
float max_range = GetSpellMaxRange(srange);
|
||||||
float min_range = GetSpellMinRange(srange);
|
float min_range = GetSpellMinRange(srange);
|
||||||
float dist = GetCombatDistance(pTarget);
|
float dist = GetCombatDistance(pTarget, false);
|
||||||
|
|
||||||
return dist < max_range && dist >= min_range;
|
return dist < max_range && dist >= min_range;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ CanCastResult CreatureAI::CanCastSpell(Unit* pTarget, const SpellEntry* pSpell,
|
||||||
if (pTarget != m_creature)
|
if (pTarget != m_creature)
|
||||||
{
|
{
|
||||||
// pTarget is out of range of this spell (also done by Spell::CheckCast())
|
// pTarget is out of range of this spell (also done by Spell::CheckCast())
|
||||||
float fDistance = m_creature->GetCombatDistance(pTarget);
|
float fDistance = m_creature->GetCombatDistance(pTarget, pSpell->rangeIndex == SPELL_RANGE_IDX_COMBAT);
|
||||||
|
|
||||||
if (fDistance > (m_creature->IsHostileTo(pTarget) ? pSpellRange->maxRange : pSpellRange->maxRangeFriendly))
|
if (fDistance > (m_creature->IsHostileTo(pTarget) ? pSpellRange->maxRange : pSpellRange->maxRangeFriendly))
|
||||||
return CAST_FAIL_TOO_FAR;
|
return CAST_FAIL_TOO_FAR;
|
||||||
|
|
|
||||||
|
|
@ -6554,7 +6554,7 @@ SpellCastResult Spell::CheckRange(bool strict)
|
||||||
if (target && target != m_caster)
|
if (target && target != m_caster)
|
||||||
{
|
{
|
||||||
// distance from target in checks
|
// distance from target in checks
|
||||||
float dist = m_caster->GetCombatDistance(target);
|
float dist = m_caster->GetCombatDistance(target, m_spellInfo->rangeIndex == SPELL_RANGE_IDX_COMBAT);
|
||||||
|
|
||||||
if (dist > max_range)
|
if (dist > max_range)
|
||||||
return SPELL_FAILED_OUT_OF_RANGE;
|
return SPELL_FAILED_OUT_OF_RANGE;
|
||||||
|
|
|
||||||
|
|
@ -738,17 +738,36 @@ void Unit::resetAttackTimer(WeaponAttackType type)
|
||||||
m_attackTimer[type] = uint32(GetAttackTime(type) * m_modAttackSpeedPct[type]);
|
m_attackTimer[type] = uint32(GetAttackTime(type) * m_modAttackSpeedPct[type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Unit::CanReachWithMeleeAttack(Unit* pVictim, float flat_mod /*= 0.0f*/) const
|
float Unit::GetCombatReach(Unit const* pVictim, bool forMeleeRange /*=true*/, float flat_mod /*=0.0f*/) const
|
||||||
{
|
{
|
||||||
MANGOS_ASSERT(pVictim);
|
|
||||||
|
|
||||||
// The measured values show BASE_MELEE_OFFSET in (1.3224, 1.342)
|
// The measured values show BASE_MELEE_OFFSET in (1.3224, 1.342)
|
||||||
float reach = GetFloatValue(UNIT_FIELD_COMBATREACH) + pVictim->GetFloatValue(UNIT_FIELD_COMBATREACH) +
|
float reach = GetFloatValue(UNIT_FIELD_COMBATREACH) + pVictim->GetFloatValue(UNIT_FIELD_COMBATREACH) +
|
||||||
BASE_MELEERANGE_OFFSET + flat_mod;
|
BASE_MELEERANGE_OFFSET + flat_mod;
|
||||||
|
|
||||||
if (reach < ATTACK_DISTANCE)
|
if (forMeleeRange && reach < ATTACK_DISTANCE)
|
||||||
reach = ATTACK_DISTANCE;
|
reach = ATTACK_DISTANCE;
|
||||||
|
|
||||||
|
return reach;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Unit::GetCombatDistance(Unit const* target, bool forMeleeRange) const
|
||||||
|
{
|
||||||
|
float radius = GetCombatReach(target, forMeleeRange);
|
||||||
|
|
||||||
|
float dx = GetPositionX() - target->GetPositionX();
|
||||||
|
float dy = GetPositionY() - target->GetPositionY();
|
||||||
|
float dz = GetPositionZ() - target->GetPositionZ();
|
||||||
|
float dist = sqrt((dx * dx) + (dy * dy) + (dz * dz)) - radius;
|
||||||
|
|
||||||
|
return (dist > 0.0f ? dist : 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Unit::CanReachWithMeleeAttack(Unit const* pVictim, float flat_mod /*= 0.0f*/) const
|
||||||
|
{
|
||||||
|
MANGOS_ASSERT(pVictim);
|
||||||
|
|
||||||
|
float reach = GetCombatReach(pVictim, true, flat_mod);
|
||||||
|
|
||||||
// This check is not related to bounding radius
|
// This check is not related to bounding radius
|
||||||
float dx = GetPositionX() - pVictim->GetPositionX();
|
float dx = GetPositionX() - pVictim->GetPositionX();
|
||||||
float dy = GetPositionY() - pVictim->GetPositionY();
|
float dy = GetPositionY() - pVictim->GetPositionY();
|
||||||
|
|
@ -6330,16 +6349,6 @@ void Unit::Uncharm()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float Unit::GetCombatDistance(const Unit* target) const
|
|
||||||
{
|
|
||||||
float radius = target->GetFloatValue(UNIT_FIELD_COMBATREACH) + GetFloatValue(UNIT_FIELD_COMBATREACH);
|
|
||||||
float dx = GetPositionX() - target->GetPositionX();
|
|
||||||
float dy = GetPositionY() - target->GetPositionY();
|
|
||||||
float dz = GetPositionZ() - target->GetPositionZ();
|
|
||||||
float dist = sqrt((dx * dx) + (dy * dy) + (dz * dz)) - radius;
|
|
||||||
return (dist > 0 ? dist : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Unit::SetPet(Pet* pet)
|
void Unit::SetPet(Pet* pet)
|
||||||
{
|
{
|
||||||
SetPetGuid(pet ? pet->GetObjectGuid() : ObjectGuid());
|
SetPetGuid(pet ? pet->GetObjectGuid() : ObjectGuid());
|
||||||
|
|
|
||||||
|
|
@ -1187,7 +1187,13 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
|
||||||
return !HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_DISARM_RANGED);
|
return !HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_DISARM_RANGED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool CanReachWithMeleeAttack(Unit* pVictim, float flat_mod = 0.0f) const;
|
|
||||||
|
/// Returns the combined combat reach of two mobs
|
||||||
|
float GetCombatReach(Unit const* pVictim, bool forMeleeRange = true, float flat_mod = 0.0f) const;
|
||||||
|
/// Returns the remaining combat distance between two mobs (CombatReach substracted)
|
||||||
|
float GetCombatDistance(Unit const* target, bool forMeleeRange) const;
|
||||||
|
/// Returns if the Unit can reach a victim with Melee Attack
|
||||||
|
bool CanReachWithMeleeAttack(Unit const* pVictim, float flat_mod = 0.0f) const;
|
||||||
uint32 m_extraAttacks;
|
uint32 m_extraAttacks;
|
||||||
|
|
||||||
void _addAttacker(Unit* pAttacker) // must be called only from Unit::Attack(Unit*)
|
void _addAttacker(Unit* pAttacker) // must be called only from Unit::Attack(Unit*)
|
||||||
|
|
@ -1540,7 +1546,6 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
|
||||||
bool IsCharmerOrOwnerPlayerOrPlayerItself() const;
|
bool IsCharmerOrOwnerPlayerOrPlayerItself() const;
|
||||||
Player* GetCharmerOrOwnerPlayerOrPlayerItself();
|
Player* GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||||
Player const* GetCharmerOrOwnerPlayerOrPlayerItself() const;
|
Player const* GetCharmerOrOwnerPlayerOrPlayerItself() const;
|
||||||
float GetCombatDistance(const Unit* target) const;
|
|
||||||
|
|
||||||
void SetPet(Pet* pet);
|
void SetPet(Pet* pet);
|
||||||
void SetCharm(Unit* pet);
|
void SetCharm(Unit* pet);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "12615"
|
#define REVISION_NR "12616"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue