Core/SAI: Add new action SMART_ACTION_SET_HEALTH_PCT

Port From (https://github.com/TrinityCore/TrinityCore/commit/4c30b2a1827b81774136d37cb521dbd5823c3423)
This commit is contained in:
hondacrx
2022-05-25 13:30:00 -04:00
parent b83c96a59e
commit 6297e81009
3 changed files with 48 additions and 17 deletions
@@ -396,6 +396,7 @@ namespace Framework.Constants
OverrideWeather = 139, // zoneId, weatherId, intensity
SetAIAnimKit = 140, // DEPRECATED, DO REUSE (it was never used in any branch, treat as free action id)
SetHover = 141, // 0/1
SetHealthPct = 142, // percent
CreateConversation = 143, // conversation_template.id
SetImmunePC = 144, // 0/1
SetImmuneNPC = 145, // 0/1
@@ -1515,6 +1515,15 @@ namespace Game.AI
Log.outError(LogFilter.Sql, $"SmartAIMgr: Deprecated Event:({e}) skipped.");
break;
}
case SmartActions.SetHealthPct:
{
if (e.Action.setHealthPct.percent > 100 || e.Action.setHealthPct.percent == 0)
{
Log.outError(LogFilter.Sql, $"SmartAIMgr: {e} is trying to set invalid HP percent {e.Action.setHealthPct.percent}, skipped.");
return false;
}
break;
}
case SmartActions.CreateConversation:
{
if (Global.ConversationDataStorage.GetConversationTemplate(e.Action.conversation.id) == null)
@@ -2666,6 +2675,9 @@ namespace Game.AI
[FieldOffset(4)]
public Evade evade;
[FieldOffset(4)]
public SetHealthPct setHealthPct;
[FieldOffset(4)]
public Conversation conversation;
@@ -3218,6 +3230,10 @@ namespace Game.AI
{
public uint toRespawnPosition;
}
public struct SetHealthPct
{
public uint percent;
}
public struct Conversation
{
public uint id;
+31 -17
View File
@@ -2403,6 +2403,17 @@ namespace Game.AI
break;
}
case SmartActions.PlayCinematic:
{
foreach (var target in targets)
{
if (!IsPlayer(target))
continue;
target.ToPlayer().SendCinematicStart(e.Action.cinematic.entry);
}
break;
}
case SmartActions.SetMovementSpeed:
{
uint speedInteger = e.Action.movementSpeed.speedInteger;
@@ -2415,6 +2426,21 @@ namespace Game.AI
break;
}
case SmartActions.PlaySpellVisualKit:
{
foreach (var target in targets)
{
if (IsUnit(target))
{
target.ToUnit().SendPlaySpellVisualKit(e.Action.spellVisualKit.spellVisualKitId, e.Action.spellVisualKit.kitType,
e.Action.spellVisualKit.duration);
Log.outDebug(LogFilter.ScriptsAi, $"SmartScript::ProcessAction:: SMART_ACTION_PLAY_SPELL_VISUAL_KIT: target: {target.GetName()} ({target.GetGUID()}), SpellVisualKit: {e.Action.spellVisualKit.spellVisualKitId}");
}
}
break;
}
case SmartActions.OverrideLight:
{
WorldObject obj = GetBaseObject();
@@ -2444,16 +2470,15 @@ namespace Game.AI
target.ToUnit().SetHover(e.Action.setHover.enable != 0);
break;
}
case SmartActions.PlaySpellVisualKit:
case SmartActions.SetHealthPct:
{
foreach (var target in targets)
{
if (IsUnit(target))
{
target.ToUnit().SendPlaySpellVisualKit(e.Action.spellVisualKit.spellVisualKitId, e.Action.spellVisualKit.kitType, e.Action.spellVisualKit.duration);
Log.outDebug(LogFilter.ScriptsAi, $"SmartScript.ProcessAction:: SMART_ACTION_PLAY_SPELL_VISUAL_KIT: target: {target.GetName()} ({target.GetGUID()}), SpellVisualKit: {e.Action.spellVisualKit.spellVisualKitId}");
}
Unit targetUnit = target.ToUnit();
if (targetUnit != null)
targetUnit.SetHealth(targetUnit.CountPctFromMaxHealth((int)e.Action.setHealthPct.percent));
}
break;
}
case SmartActions.CreateConversation:
@@ -2474,17 +2499,6 @@ namespace Game.AI
break;
}
case SmartActions.PlayCinematic:
{
foreach (WorldObject target in targets)
{
if (!IsPlayer(target))
continue;
target.ToPlayer().SendCinematicStart(e.Action.cinematic.entry);
}
break;
}
case SmartActions.AddToStoredTargetList:
{
if (!targets.Empty())