feat(Core/SmartAI): introduce new SMART_EVENT_IS_IN_MELEE_RANGE (#20575)

This commit is contained in:
Jelle Meeus
2024-11-20 10:36:17 +01:00
committed by GitHub
parent ff55c0e1de
commit 640f84e280
4 changed files with 37 additions and 1 deletions

View File

@@ -4231,6 +4231,18 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
ProcessTimedAction(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax, victim);
}
break;
}
case SMART_EVENT_IS_IN_MELEE_RANGE:
{
if (!me)
return;
if (Unit* victim = me->GetVictim())
if ((!e.event.meleeRange.invert && me->IsWithinMeleeRange(victim, static_cast<float>(e.event.meleeRange.dist))) ||
(e.event.meleeRange.invert && !me->IsWithinMeleeRange(victim, static_cast<float>(e.event.meleeRange.dist))))
ProcessTimedAction(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax, victim);
break;
}
case SMART_EVENT_RECEIVE_EMOTE:
@@ -4793,6 +4805,7 @@ void SmartScript::InitTimer(SmartScriptHolder& e)
case SMART_EVENT_AREA_CASTING:
case SMART_EVENT_IS_BEHIND_TARGET:
case SMART_EVENT_FRIENDLY_HEALTH_PCT:
case SMART_EVENT_IS_IN_MELEE_RANGE:
RecalcTimer(e, e.event.minMaxRepeat.min, e.event.minMaxRepeat.max);
break;
case SMART_EVENT_DISTANCE_CREATURE:
@@ -4878,6 +4891,7 @@ void SmartScript::UpdateTimer(SmartScriptHolder& e, uint32 const diff)
case SMART_EVENT_FRIENDLY_HEALTH_PCT:
case SMART_EVENT_DISTANCE_CREATURE:
case SMART_EVENT_DISTANCE_GAMEOBJECT:
case SMART_EVENT_IS_IN_MELEE_RANGE:
{
ASSERT(executionStack.empty());
executionStack.emplace_back(SmartScriptFrame{ e, nullptr, 0, 0, false, nullptr, nullptr });