diff --git a/Source/Scripts/Spells/DemonHunter.cs b/Source/Scripts/Spells/DemonHunter.cs index a158f679b..23fb92803 100644 --- a/Source/Scripts/Spells/DemonHunter.cs +++ b/Source/Scripts/Spells/DemonHunter.cs @@ -20,12 +20,14 @@ using Game.Entities; using Game.Scripting; using Game.Spells; using Game.AI; +using System.Collections.Generic; namespace Scripts.Spells.DemonHunter { struct SpellIds { public const uint ChaosStrikeEnergize = 193840; + public const uint FirstBlood = 206416; public const uint SigilOfChainsGrip = 208674; public const uint SigilOfChainsSlow = 204843; public const uint SigilOfChainsTargetSelect = 204834; @@ -58,6 +60,93 @@ namespace Scripts.Spells.DemonHunter } } + [Script] // 206416 - First Blood + class spell_dh_first_blood : AuraScript + { + ObjectGuid _firstTargetGUID; + + public ObjectGuid GetFirstTarget() { return _firstTargetGUID; } + public void SetFirstTarget(ObjectGuid targetGuid) { _firstTargetGUID = targetGuid; } + + public override void Register() { } + } + + // 188499 - Blade Dance + [Script] // 210152 - Death Sweep + class spell_dh_blade_dance : SpellScript + { + public override bool Validate(SpellInfo spellInfo) + { + return ValidateSpellInfo(SpellIds.FirstBlood); + } + + void DecideFirstTarget(List targetList) + { + if (targetList.Empty()) + return; + + Aura aura = GetCaster().GetAura(SpellIds.FirstBlood); + if (aura == null) + return; + + ObjectGuid firstTargetGUID = ObjectGuid.Empty; + ObjectGuid selectedTarget = GetCaster().GetTarget(); + + // Prefer the selected target if he is one of the enemies + if (targetList.Count > 1 && !selectedTarget.IsEmpty()) + { + var foundObj = targetList.Find(obj => obj.GetGUID() == selectedTarget); + if (foundObj != null) + firstTargetGUID = foundObj.GetGUID(); + } + + if (firstTargetGUID.IsEmpty()) + firstTargetGUID = targetList[0].GetGUID(); + + spell_dh_first_blood script = aura.GetScript(nameof(spell_dh_first_blood)); + if (script != null) + script.SetFirstTarget(firstTargetGUID); + } + + public override void Register() + { + OnObjectAreaTargetSelect.Add(new ObjectAreaTargetSelectHandler(DecideFirstTarget, 0, Targets.UnitSrcAreaEnemy)); + } + } + + // 199552 - Blade Dance + // 200685 - Blade Dance + // 210153 - Death Sweep + [Script] // 210155 - Death Sweep + class spell_dh_blade_dance_damage : SpellScript + { + public override bool Validate(SpellInfo spellInfo) + { + return ValidateSpellInfo(SpellIds.FirstBlood); + } + + void HandleHitTarget() + { + int damage = GetHitDamage(); + + AuraEffect aurEff = GetCaster().GetAuraEffect(SpellIds.FirstBlood, 0); + if (aurEff != null) + { + spell_dh_first_blood script = aurEff.GetBase().GetScript(nameof(spell_dh_first_blood)); + if (script != null) + if (GetHitUnit().GetGUID() == script.GetFirstTarget()) + MathFunctions.AddPct(ref damage, aurEff.GetAmount()); + } + + SetHitDamage(damage); + } + + public override void Register() + { + OnHit.Add(new HitHandler(HandleHitTarget)); + } + } + // 204596 - Sigil of Flame // 207684 - Sigil of Misery // 202137 - Sigil of Silence diff --git a/sql/updates/world/master/2021_10_26_08_world.sql b/sql/updates/world/master/2021_10_26_08_world.sql new file mode 100644 index 000000000..1f620337b --- /dev/null +++ b/sql/updates/world/master/2021_10_26_08_world.sql @@ -0,0 +1,14 @@ +DELETE FROM `spell_script_names` WHERE `ScriptName` IN ( +'spell_dh_blade_dance', +'spell_dh_blade_dance_damage', +'spell_dh_first_blood' +); + +INSERT INTO `spell_script_names` (`spell_id`, `ScriptName`) VALUES +(188499, 'spell_dh_blade_dance'), +(210152, 'spell_dh_blade_dance'), +(199552, 'spell_dh_blade_dance_damage'), +(200685, 'spell_dh_blade_dance_damage'), +(210153, 'spell_dh_blade_dance_damage'), +(210155, 'spell_dh_blade_dance_damage'), +(206416, 'spell_dh_first_blood');