mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 16:37:01 +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
|
|
@ -738,17 +738,36 @@ void Unit::resetAttackTimer(WeaponAttackType 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)
|
||||
float reach = GetFloatValue(UNIT_FIELD_COMBATREACH) + pVictim->GetFloatValue(UNIT_FIELD_COMBATREACH) +
|
||||
BASE_MELEERANGE_OFFSET + flat_mod;
|
||||
|
||||
if (reach < ATTACK_DISTANCE)
|
||||
if (forMeleeRange && 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
|
||||
float dx = GetPositionX() - pVictim->GetPositionX();
|
||||
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)
|
||||
{
|
||||
SetPetGuid(pet ? pet->GetObjectGuid() : ObjectGuid());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue