Core/SAI: Add new action SMART_ACTION_SET_HEALTH_PCT (#25932)

* Core/SAI: Add new action SMART_ACTION_SET_HEALTH_PCT

Add new action SMART_ACTION_SET_HEALTH_PCT (142) with one single parameter "percent" to set the Unit health.
Close #25317

* Do not allow 0%

(cherry picked from commit 7d6f7e4d19)
This commit is contained in:
Giacomo Pozzoni
2021-01-25 21:27:57 +01:00
committed by Shauren
parent 23d77ecb81
commit 4c30b2a182
3 changed files with 57 additions and 25 deletions
+41 -25
View File
@@ -1650,15 +1650,19 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
break;
}
case SMART_ACTION_TRIGGER_TIMED_EVENT:
{
ProcessEventsFor((SMART_EVENT)SMART_EVENT_TIMED_EVENT_TRIGGERED, nullptr, e.action.timeEvent.id);
// remove this event if not repeatable
if (e.event.event_flags & SMART_EVENT_FLAG_NOT_REPEATABLE)
mRemIDs.push_back(e.action.timeEvent.id);
break;
}
case SMART_ACTION_REMOVE_TIMED_EVENT:
{
mRemIDs.push_back(e.action.timeEvent.id);
break;
}
case SMART_ACTION_OVERRIDE_SCRIPT_BASE_OBJECT:
{
for (WorldObject* target : targets)
@@ -1687,12 +1691,16 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
break;
}
case SMART_ACTION_RESET_SCRIPT_BASE_OBJECT:
{
ResetBaseObject();
break;
}
case SMART_ACTION_CALL_SCRIPT_RESET:
{
SetPhase(0);
OnReset();
break;
}
case SMART_ACTION_SET_RANGED_MOVEMENT:
{
if (!IsSmart())
@@ -2374,7 +2382,6 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
ProcessEventsFor((SMART_EVENT)SMART_EVENT_TIMED_EVENT_TRIGGERED, nullptr, eventId);
break;
}
case SMART_ACTION_REMOVE_ALL_GAMEOBJECTS:
{
for (WorldObject* const target : targets)
@@ -2446,6 +2453,17 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
break;
}
case SMART_ACTION_PLAY_CINEMATIC:
{
for (WorldObject* target : targets)
{
if (!IsPlayer(target))
continue;
target->ToPlayer()->SendCinematicStart(e.action.cinematic.entry);
}
break;
}
case SMART_ACTION_SET_MOVEMENT_SPEED:
{
uint32 speedInteger = e.action.movementSpeed.speedInteger;
@@ -2458,6 +2476,22 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
break;
}
case SMART_ACTION_PLAY_SPELL_VISUAL_KIT:
{
for (WorldObject* const target : targets)
{
if (IsUnit(target))
{
target->ToUnit()->SendPlaySpellVisualKit(e.action.spellVisualKit.spellVisualKitId, e.action.spellVisualKit.kitType,
e.action.spellVisualKit.duration);
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_PLAY_SPELL_VISUAL_KIT: target: %s (%s), SpellVisualKit: %u",
target->GetName().c_str(), target->GetGUID().ToString().c_str(), e.action.spellVisualKit.spellVisualKitId);
}
}
break;
}
case SMART_ACTION_OVERRIDE_LIGHT:
{
if (WorldObject* obj = GetBaseObject())
@@ -2479,24 +2513,17 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
break;
}
case SMART_ACTION_SET_HOVER:
{
for (WorldObject* target : targets)
if (IsUnit(target))
target->ToUnit()->SetHover(e.action.setHover.enable != 0);
break;
case SMART_ACTION_PLAY_SPELL_VISUAL_KIT:
}
case SMART_ACTION_SET_HEALTH_PCT:
{
for (WorldObject* const target : targets)
{
if (IsUnit(target))
{
target->ToUnit()->SendPlaySpellVisualKit(e.action.spellVisualKit.spellVisualKitId, e.action.spellVisualKit.kitType,
e.action.spellVisualKit.duration);
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_PLAY_SPELL_VISUAL_KIT: target: %s (%s), SpellVisualKit: %u",
target->GetName().c_str(), target->GetGUID().ToString().c_str(), e.action.spellVisualKit.spellVisualKitId);
}
}
for (WorldObject* target : targets)
if (Unit* targetUnit = target->ToUnit())
targetUnit->SetHealth(targetUnit->CountPctFromMaxHealth(e.action.setHealthPct.percent));
break;
}
case SMART_ACTION_CREATE_CONVERSATION:
@@ -2517,17 +2544,6 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
break;
}
case SMART_ACTION_PLAY_CINEMATIC:
{
for (WorldObject* target : targets)
{
if (!IsPlayer(target))
continue;
target->ToPlayer()->SendCinematicStart(e.action.cinematic.entry);
}
break;
}
case SMART_ACTION_ADD_TO_STORED_TARGET_LIST:
{
if (!targets.empty())