From 64041435fe9a09ed61b856d9ac13ffe1894a95ef Mon Sep 17 00:00:00 2001 From: Hondacrx Date: Sun, 8 Jun 2025 14:18:24 -0400 Subject: [PATCH] Scripts/Spells: Use Spell::GetPowerTypeCostAmount where possible instead of iterating Spell::GetPowerCost Port From (https://github.com/TrinityCore/TrinityCore/commit/26376d89e165aece42e58213632ef43ecb0d81b3) --- Source/Scripts/Spells/Druid.cs | 7 +++---- Source/Scripts/Spells/Item.cs | 9 ++------- Source/Scripts/Spells/Rogue.cs | 7 +++---- Source/Scripts/Spells/Shaman.cs | 7 +++---- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/Source/Scripts/Spells/Druid.cs b/Source/Scripts/Spells/Druid.cs index 82ad1bdc8..b216281fe 100644 --- a/Source/Scripts/Spells/Druid.cs +++ b/Source/Scripts/Spells/Druid.cs @@ -1761,12 +1761,11 @@ namespace Scripts.Spells.Druid return; Unit caster = eventInfo.GetActor(); - List costs = spell.GetPowerCost(); - var m = costs.Find(cost => cost.Power == PowerType.Mana); - if (m == null) + int? manaCost = spell.GetPowerTypeCostAmount(PowerType.Mana); + if (!manaCost.HasValue) return; - int amount = MathFunctions.CalculatePct(m.Amount, aurEff.GetAmount()); + int amount = MathFunctions.CalculatePct(manaCost.Value, aurEff.GetAmount()); CastSpellExtraArgs args = new(aurEff); args.AddSpellMod(SpellValueMod.BasePoint0, amount); caster.CastSpell(null, SpellIds.Exhilarate, args); diff --git a/Source/Scripts/Spells/Item.cs b/Source/Scripts/Spells/Item.cs index a303f6b2a..4e0ab15c9 100644 --- a/Source/Scripts/Spells/Item.cs +++ b/Source/Scripts/Spells/Item.cs @@ -1472,13 +1472,8 @@ namespace Scripts.Spells.Azerite bool CheckProc(ProcEventInfo eventInfo) { Spell spell = eventInfo.GetProcSpell(); - if (spell != null) - { - var cost = spell.GetPowerCost(); - var m = cost.Find(cost => cost.Power == PowerType.Mana && cost.Amount > 0); - if (m != null) - return true; - } + if (spell != null && spell.GetPowerTypeCostAmount(PowerType.Mana) > 0) + return true; return false; } diff --git a/Source/Scripts/Spells/Rogue.cs b/Source/Scripts/Spells/Rogue.cs index f8238c2e2..83d75d015 100644 --- a/Source/Scripts/Spells/Rogue.cs +++ b/Source/Scripts/Spells/Rogue.cs @@ -782,10 +782,9 @@ namespace Scripts.Spells.Rogue damagePerCombo += t5.GetAmount(); int finalDamage = damagePerCombo; - List cost = GetSpell().GetPowerCost(); - var c = cost.Find(cost => cost.Power == PowerType.ComboPoints); - if (c != null) - finalDamage *= c.Amount; + int? comboPointCost = GetSpell().GetPowerTypeCostAmount(PowerType.ComboPoints); + if (comboPointCost.HasValue) + finalDamage *= comboPointCost.Value; SetHitDamage(finalDamage); } diff --git a/Source/Scripts/Spells/Shaman.cs b/Source/Scripts/Spells/Shaman.cs index abd5d88d3..cbc6ea2e8 100644 --- a/Source/Scripts/Spells/Shaman.cs +++ b/Source/Scripts/Spells/Shaman.cs @@ -977,11 +977,10 @@ namespace Scripts.Spells.Shaman { PreventDefaultAction(); - List costs = eventInfo.GetProcSpell().GetPowerCost(); - var m = costs.Find(cost => cost.Power == PowerType.Mana); - if (m != null) + int? manaCost = eventInfo.GetProcSpell().GetPowerTypeCostAmount(PowerType.Mana); + if (manaCost.HasValue) { - int mana = MathFunctions.CalculatePct(m.Amount, 35); + int mana = MathFunctions.CalculatePct(manaCost.Value, 35); if (mana > 0) { CastSpellExtraArgs args = new(aurEff);