From 5bb553b0e37580e0c011b91e55a3841a5f1ac039 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 7 Jan 2022 13:46:21 -0500 Subject: [PATCH] Core/Auras: Implemented SPELL_AURA_TRIGGER_SPELL_ON_HEALTH_PCT Port From (https://github.com/TrinityCore/TrinityCore/commit/b221f4b37251db2206dd14d46c00f1b6f1f16480) --- .../Constants/Spells/SpellAuraConst.cs | 18 +++++++---- Source/Game/Entities/Unit/Unit.cs | 32 +++++++++++++++++-- Source/Game/Spells/Auras/AuraEffect.cs | 27 ++++++++++++++++ 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/Source/Framework/Constants/Spells/SpellAuraConst.cs b/Source/Framework/Constants/Spells/SpellAuraConst.cs index 1012c0084..d7cf86a74 100644 --- a/Source/Framework/Constants/Spells/SpellAuraConst.cs +++ b/Source/Framework/Constants/Spells/SpellAuraConst.cs @@ -545,6 +545,18 @@ namespace Framework.Constants RealOrReapplyMask = (Reapply | Real) } + public enum AuraTriggerOnPowerChangeDirection + { + Gain = 0, + Loss = 1 + } + + public enum AuraTriggerOnHealthChangeDirection + { + Above = 0, + Below = 1, + } + // Diminishing Returns Types public enum DiminishingReturnsType { @@ -578,10 +590,4 @@ namespace Framework.Constants Level4 = 3, TauntImmune = 4 } - - public enum AuraTriggerOnPowerChangeDirection - { - Gain = 0, - Loss = 1 - } } diff --git a/Source/Game/Entities/Unit/Unit.cs b/Source/Game/Entities/Unit/Unit.cs index 25a868265..dcd36e3bd 100644 --- a/Source/Game/Entities/Unit/Unit.cs +++ b/Source/Game/Entities/Unit/Unit.cs @@ -242,13 +242,13 @@ namespace Game.Entities _spellHistory.Update(); } - public void HandleEmoteCommand(Emote animId, Player target = null, uint[] spellVisualKitIds = null) + public void HandleEmoteCommand(Emote emoteId, Player target = null, uint[] spellVisualKitIds = null) { EmoteMessage packet = new(); packet.Guid = GetGUID(); - packet.EmoteID = (uint)animId; + packet.EmoteID = (uint)emoteId; - var emotesEntry = CliDB.EmotesStorage.LookupByKey(animId); + var emotesEntry = CliDB.EmotesStorage.LookupByKey(emoteId); if (emotesEntry != null && spellVisualKitIds != null) if (emotesEntry.AnimId == (uint)Anim.MountSpecial || emotesEntry.AnimId == (uint)Anim.MountSelfSpecial) packet.SpellVisualKitIDs.AddRange(spellVisualKitIds); @@ -2880,6 +2880,32 @@ namespace Game.Entities return gain; } + void TriggerOnHealthChangeAuras(ulong oldVal, ulong newVal) + { + foreach (AuraEffect effect in GetAuraEffectsByType(AuraType.TriggerSpellOnHealthPct)) + { + int triggerHealthPct = effect.GetAmount(); + uint triggerSpell = effect.GetSpellEffectInfo().TriggerSpell; + ulong threshold = CountPctFromMaxHealth(triggerHealthPct); + + switch ((AuraTriggerOnHealthChangeDirection)effect.GetMiscValue()) + { + case AuraTriggerOnHealthChangeDirection.Above: + if (newVal < threshold || oldVal > threshold) + continue; + break; + case AuraTriggerOnHealthChangeDirection.Below: + if (newVal > threshold || oldVal < threshold) + continue; + break; + default: + break; + } + + CastSpell(this, triggerSpell, new CastSpellExtraArgs(effect)); + } + } + public bool IsImmuneToAll() { return IsImmuneToPC() && IsImmuneToNPC(); } public void SetImmuneToAll(bool apply, bool keepCombat) diff --git a/Source/Game/Spells/Auras/AuraEffect.cs b/Source/Game/Spells/Auras/AuraEffect.cs index 9b186525a..a88338070 100644 --- a/Source/Game/Spells/Auras/AuraEffect.cs +++ b/Source/Game/Spells/Auras/AuraEffect.cs @@ -3538,6 +3538,33 @@ namespace Game.Spells target.ModifyPower(powerType, change); } + [AuraEffectHandler(AuraType.TriggerSpellOnHealthPct)] + void HandleTriggerSpellOnHealthPercent(AuraApplication aurApp, AuraEffectHandleModes mode, bool apply) + { + if (!mode.HasFlag(AuraEffectHandleModes.Real) || !apply) + return; + + Unit target = aurApp.GetTarget(); + int thresholdPct = GetAmount(); + uint triggerSpell = GetSpellEffectInfo().TriggerSpell; + + switch ((AuraTriggerOnHealthChangeDirection)GetMiscValue()) + { + case AuraTriggerOnHealthChangeDirection.Above: + if (!target.HealthAbovePct(thresholdPct)) + return; + break; + case AuraTriggerOnHealthChangeDirection.Below: + if (!target.HealthBelowPct(thresholdPct)) + return; + break; + default: + break; + } + + target.CastSpell(target, triggerSpell, new CastSpellExtraArgs(this)); + } + /********************************/ /*** FIGHT ***/ /********************************/