mirror of
https://github.com/araxiaonline/TrinityCore.git
synced 2026-06-18 14:10:18 -04:00
Core/SAI: Implement SMART_TARGET_ACTION_INVOKER in SMART_EVENT_FRIENDLY_HEALTH_PCT (#25318)
* Core/SAI: Implement SMART_TARGET_ACTION_INVOKER in SMART_EVENT_FRIENDLY_HEALTH_PCT
* Require radius (5th parameter) to be set
(cherry picked from commit cbed1039c4)
This commit is contained in:
@@ -3598,7 +3598,7 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
|
||||
if (!me || !me->IsEngaged())
|
||||
return;
|
||||
|
||||
ObjectVector targets;
|
||||
Unit* unitTarget = nullptr;
|
||||
switch (e.GetTargetType())
|
||||
{
|
||||
case SMART_TARGET_CREATURE_RANGE:
|
||||
@@ -3608,26 +3608,31 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
|
||||
case SMART_TARGET_CLOSEST_PLAYER:
|
||||
case SMART_TARGET_PLAYER_RANGE:
|
||||
case SMART_TARGET_PLAYER_DISTANCE:
|
||||
{
|
||||
ObjectVector targets;
|
||||
GetTargets(targets, e);
|
||||
|
||||
for (WorldObject* target : targets)
|
||||
{
|
||||
if (IsUnit(target) && me->IsFriendlyTo(target->ToUnit()) && target->ToUnit()->IsAlive() && target->ToUnit()->IsInCombat())
|
||||
{
|
||||
uint32 healthPct = uint32(target->ToUnit()->GetHealthPct());
|
||||
if (healthPct > e.event.friendlyHealthPct.maxHpPct || healthPct < e.event.friendlyHealthPct.minHpPct)
|
||||
continue;
|
||||
|
||||
unitTarget = target->ToUnit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SMART_TARGET_ACTION_INVOKER:
|
||||
unitTarget = DoSelectLowestHpPercentFriendly((float)e.event.friendlyHealthPct.radius, e.event.friendlyHealthPct.minHpPct, e.event.friendlyHealthPct.maxHpPct);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
Unit* unitTarget = nullptr;
|
||||
for (WorldObject* target : targets)
|
||||
{
|
||||
if (IsUnit(target) && me->IsFriendlyTo(target->ToUnit()) && target->ToUnit()->IsAlive() && target->ToUnit()->IsInCombat())
|
||||
{
|
||||
uint32 healthPct = uint32(target->ToUnit()->GetHealthPct());
|
||||
if (healthPct > e.event.friendlyHealthPct.maxHpPct || healthPct < e.event.friendlyHealthPct.minHpPct)
|
||||
continue;
|
||||
|
||||
unitTarget = target->ToUnit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!unitTarget)
|
||||
return;
|
||||
|
||||
@@ -4231,6 +4236,18 @@ Unit* SmartScript::DoSelectLowestHpFriendly(float range, uint32 MinHPDiff) const
|
||||
return unit;
|
||||
}
|
||||
|
||||
Unit* SmartScript::DoSelectLowestHpPercentFriendly(float range, uint32 minHpPct, uint32 maxHpPct) const
|
||||
{
|
||||
if (!me)
|
||||
return nullptr;
|
||||
|
||||
Unit* unit = nullptr;
|
||||
Trinity::MostHPPercentMissingInRange u_check(me, range, minHpPct, maxHpPct);
|
||||
Trinity::UnitLastSearcher<Trinity::MostHPPercentMissingInRange> searcher(me, unit, u_check);
|
||||
Cell::VisitGridObjects(me, searcher, range);
|
||||
return unit;
|
||||
}
|
||||
|
||||
void SmartScript::DoFindFriendlyCC(std::vector<Creature*>& creatures, float range) const
|
||||
{
|
||||
if (!me)
|
||||
|
||||
Reference in New Issue
Block a user