mirror of
https://github.com/liyunfan1223/azerothcore-wotlk.git
synced 2026-08-07 23:38:00 +00:00
fix(Core/SmartAI): Don't add UNIT_STATE_MELEE_ATTACKING if unit is in ranged mode and not chasing (#26796)
This commit is contained in:
@@ -596,7 +596,25 @@ void SmartAI::UpdateAI(uint32 diff)
|
||||
return;
|
||||
|
||||
if (mCanAutoAttack)
|
||||
{
|
||||
UpdateMeleeStance();
|
||||
DoMeleeAttackIfReady();
|
||||
}
|
||||
}
|
||||
|
||||
void SmartAI::UpdateMeleeStance()
|
||||
{
|
||||
// Ranged creatures should not switch to melee stance at distance
|
||||
if (!_currentRangeMode || me->IsCrowdControlled())
|
||||
return;
|
||||
|
||||
Unit* victim = me->GetVictim();
|
||||
if (!victim)
|
||||
return;
|
||||
|
||||
bool const canMelee = me->IsWithinMeleeRange(victim);
|
||||
if (canMelee != me->HasUnitState(UNIT_STATE_MELEE_ATTACKING))
|
||||
me->Attack(victim, canMelee);
|
||||
}
|
||||
|
||||
bool SmartAI::IsEscortInvokerInRange()
|
||||
@@ -927,7 +945,7 @@ void SmartAI::AttackStart(Unit* who)
|
||||
return;
|
||||
}
|
||||
|
||||
if (who && me->Attack(who, mCanAutoAttack))
|
||||
if (who && me->Attack(who, mCanAutoAttack && !_currentRangeMode))
|
||||
{
|
||||
if (!me->HasUnitState(UNIT_STATE_NO_COMBAT_MOVEMENT))
|
||||
{
|
||||
@@ -1202,7 +1220,12 @@ void SmartAI::SetCurrentRangeMode(bool on, float range)
|
||||
_attackDistance = range;
|
||||
|
||||
if (Unit* victim = me->GetVictim())
|
||||
{
|
||||
me->GetMotionMaster()->MoveChase(victim, _attackDistance);
|
||||
|
||||
if (!on && mCanAutoAttack && !me->HasUnitState(UNIT_STATE_MELEE_ATTACKING))
|
||||
me->Attack(victim, true);
|
||||
}
|
||||
}
|
||||
|
||||
void SmartAI::SetMainSpell(uint32 spellId)
|
||||
|
||||
@@ -265,6 +265,7 @@ private:
|
||||
uint32 mDespawnState;
|
||||
void UpdateDespawn(const uint32 diff);
|
||||
void UpdateFollow(const uint32 diff);
|
||||
void UpdateMeleeStance();
|
||||
uint32 mEscortInvokerCheckTimer;
|
||||
bool mJustReset;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user