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:
Giacomo Pozzoni
2020-08-25 14:14:06 +02:00
committed by Shauren
parent 71cbe9f318
commit 902ed74c2a
5 changed files with 59 additions and 15 deletions
+32 -15
View File
@@ -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)