From 6297e81009753446549276e7938a97dd176e664a Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 25 May 2022 13:30:00 -0400 Subject: [PATCH] Core/SAI: Add new action SMART_ACTION_SET_HEALTH_PCT Port From (https://github.com/TrinityCore/TrinityCore/commit/4c30b2a1827b81774136d37cb521dbd5823c3423) --- Source/Framework/Constants/SmartAIConst.cs | 1 + Source/Game/AI/SmartScripts/SmartAIManager.cs | 16 +++++++ Source/Game/AI/SmartScripts/SmartScript.cs | 48 ++++++++++++------- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/Source/Framework/Constants/SmartAIConst.cs b/Source/Framework/Constants/SmartAIConst.cs index 9a29dc796..4bba1c1d6 100644 --- a/Source/Framework/Constants/SmartAIConst.cs +++ b/Source/Framework/Constants/SmartAIConst.cs @@ -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 diff --git a/Source/Game/AI/SmartScripts/SmartAIManager.cs b/Source/Game/AI/SmartScripts/SmartAIManager.cs index f69546491..de15aee8c 100644 --- a/Source/Game/AI/SmartScripts/SmartAIManager.cs +++ b/Source/Game/AI/SmartScripts/SmartAIManager.cs @@ -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; diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index e427c4c41..d70153e3a 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -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())