Scripts/Spells: Use Spell::GetPowerTypeCostAmount where possible instead of iterating Spell::GetPowerCost

Port From (https://github.com/TrinityCore/TrinityCore/commit/26376d89e165aece42e58213632ef43ecb0d81b3)
This commit is contained in:
Hondacrx
2025-06-08 14:18:24 -04:00
parent df8481c614
commit 64041435fe
4 changed files with 11 additions and 19 deletions
+3 -4
View File
@@ -1761,12 +1761,11 @@ namespace Scripts.Spells.Druid
return; return;
Unit caster = eventInfo.GetActor(); Unit caster = eventInfo.GetActor();
List<SpellPowerCost> costs = spell.GetPowerCost(); int? manaCost = spell.GetPowerTypeCostAmount(PowerType.Mana);
var m = costs.Find(cost => cost.Power == PowerType.Mana); if (!manaCost.HasValue)
if (m == null)
return; return;
int amount = MathFunctions.CalculatePct(m.Amount, aurEff.GetAmount()); int amount = MathFunctions.CalculatePct(manaCost.Value, aurEff.GetAmount());
CastSpellExtraArgs args = new(aurEff); CastSpellExtraArgs args = new(aurEff);
args.AddSpellMod(SpellValueMod.BasePoint0, amount); args.AddSpellMod(SpellValueMod.BasePoint0, amount);
caster.CastSpell(null, SpellIds.Exhilarate, args); caster.CastSpell(null, SpellIds.Exhilarate, args);
+2 -7
View File
@@ -1472,13 +1472,8 @@ namespace Scripts.Spells.Azerite
bool CheckProc(ProcEventInfo eventInfo) bool CheckProc(ProcEventInfo eventInfo)
{ {
Spell spell = eventInfo.GetProcSpell(); Spell spell = eventInfo.GetProcSpell();
if (spell != null) if (spell != null && spell.GetPowerTypeCostAmount(PowerType.Mana) > 0)
{ return true;
var cost = spell.GetPowerCost();
var m = cost.Find(cost => cost.Power == PowerType.Mana && cost.Amount > 0);
if (m != null)
return true;
}
return false; return false;
} }
+3 -4
View File
@@ -782,10 +782,9 @@ namespace Scripts.Spells.Rogue
damagePerCombo += t5.GetAmount(); damagePerCombo += t5.GetAmount();
int finalDamage = damagePerCombo; int finalDamage = damagePerCombo;
List<SpellPowerCost> cost = GetSpell().GetPowerCost(); int? comboPointCost = GetSpell().GetPowerTypeCostAmount(PowerType.ComboPoints);
var c = cost.Find(cost => cost.Power == PowerType.ComboPoints); if (comboPointCost.HasValue)
if (c != null) finalDamage *= comboPointCost.Value;
finalDamage *= c.Amount;
SetHitDamage(finalDamage); SetHitDamage(finalDamage);
} }
+3 -4
View File
@@ -977,11 +977,10 @@ namespace Scripts.Spells.Shaman
{ {
PreventDefaultAction(); PreventDefaultAction();
List<SpellPowerCost> costs = eventInfo.GetProcSpell().GetPowerCost(); int? manaCost = eventInfo.GetProcSpell().GetPowerTypeCostAmount(PowerType.Mana);
var m = costs.Find(cost => cost.Power == PowerType.Mana); if (manaCost.HasValue)
if (m != null)
{ {
int mana = MathFunctions.CalculatePct(m.Amount, 35); int mana = MathFunctions.CalculatePct(manaCost.Value, 35);
if (mana > 0) if (mana > 0)
{ {
CastSpellExtraArgs args = new(aurEff); CastSpellExtraArgs args = new(aurEff);