mirror of
https://github.com/araxiaonline/TrinityCore.git
synced 2026-06-16 04:59:41 -04:00
Core/SmartAI: Implement SMART_EVENT_FRIENDLY_HEALTH_PCT.
On current clean TDB, there are a total of 106 creatures using SMART_EVENT_FRIENDLY_HEALTH (non-PCT) which has a flat first parameter, but only 8 of these use the event correctly (and therefore only 8 of them actually work). Closes #10520
This commit is contained in:
@@ -2623,7 +2623,7 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
|
||||
return;
|
||||
|
||||
Unit* target = DoSelectLowestHpFriendly((float)e.event.friendlyHealt.radius, e.event.friendlyHealt.hpDeficit);
|
||||
if (!target)
|
||||
if (!target || !target->IsInCombat())
|
||||
return;
|
||||
ProcessTimedAction(e, e.event.friendlyHealt.repeatMin, e.event.friendlyHealt.repeatMax, target);
|
||||
break;
|
||||
@@ -2940,6 +2940,55 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
|
||||
ProcessAction(e, unit, var0);
|
||||
break;
|
||||
}
|
||||
case SMART_EVENT_FRIENDLY_HEALTH_PCT:
|
||||
{
|
||||
if (!me || !me->IsInCombat())
|
||||
return;
|
||||
|
||||
ObjectList* _targets = NULL;
|
||||
|
||||
switch (e.GetTargetType())
|
||||
{
|
||||
case SMART_TARGET_CREATURE_RANGE:
|
||||
case SMART_TARGET_CREATURE_GUID:
|
||||
case SMART_TARGET_CREATURE_DISTANCE:
|
||||
case SMART_TARGET_CLOSEST_CREATURE:
|
||||
case SMART_TARGET_CLOSEST_PLAYER:
|
||||
case SMART_TARGET_PLAYER_RANGE:
|
||||
case SMART_TARGET_PLAYER_DISTANCE:
|
||||
_targets = GetTargets(e);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_targets)
|
||||
return;
|
||||
|
||||
Unit* target = NULL;
|
||||
|
||||
for (ObjectList::const_iterator itr = _targets->begin(); itr != _targets->end(); ++itr)
|
||||
{
|
||||
if (IsUnit(*itr) && me->IsFriendlyTo((*itr)->ToUnit()) && (*itr)->ToUnit()->IsAlive() && (*itr)->ToUnit()->IsInCombat())
|
||||
{
|
||||
uint32 healthPct = uint32((*itr)->ToUnit()->GetHealthPct());
|
||||
|
||||
if (healthPct > e.event.friendlyHealtPct.maxHpPct || healthPct < e.event.friendlyHealtPct.minHpPct)
|
||||
continue;
|
||||
|
||||
target = (*itr)->ToUnit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete _targets;
|
||||
|
||||
if (!target)
|
||||
return;
|
||||
|
||||
ProcessTimedAction(e, e.event.friendlyHealtPct.repeatMin, e.event.friendlyHealtPct.repeatMax, target);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
TC_LOG_ERROR(LOG_FILTER_SQL, "SmartScript::ProcessEvent: Unhandled Event type %u", e.GetEventType());
|
||||
break;
|
||||
@@ -3019,6 +3068,7 @@ void SmartScript::UpdateTimer(SmartScriptHolder& e, uint32 const diff)
|
||||
case SMART_EVENT_HAS_AURA:
|
||||
case SMART_EVENT_TARGET_BUFFED:
|
||||
case SMART_EVENT_IS_BEHIND_TARGET:
|
||||
case SMART_EVENT_FRIENDLY_HEALTH_PCT:
|
||||
{
|
||||
ProcessEvent(e);
|
||||
if (e.GetScriptType() == SMART_SCRIPT_TYPE_TIMED_ACTIONLIST)
|
||||
|
||||
Reference in New Issue
Block a user