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:
Gultask
2026-07-27 21:31:47 -03:00
committed by GitHub
parent b7387f653d
commit f29869536b
2 changed files with 25 additions and 1 deletions

View File

@@ -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)

View File

@@ -265,6 +265,7 @@ private:
uint32 mDespawnState;
void UpdateDespawn(const uint32 diff);
void UpdateFollow(const uint32 diff);
void UpdateMeleeStance();
uint32 mEscortInvokerCheckTimer;
bool mJustReset;