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

This commit is contained in:
Shauren
2025-01-20 22:49:52 +01:00
parent 0e36fd9360
commit 26376d89e1
7 changed files with 14 additions and 29 deletions

View File

@@ -1846,12 +1846,11 @@ class spell_dru_t3_8p_bonus : public AuraScript
return;
Unit* caster = eventInfo.GetActor();
std::vector<SpellPowerCost> const& costs = spell->GetPowerCost();
auto m = std::find_if(costs.begin(), costs.end(), [](SpellPowerCost const& cost) { return cost.Power == POWER_MANA; });
if (m == costs.end())
Optional<int32> manaCost = spell->GetPowerTypeCostAmount(POWER_MANA);
if (!manaCost)
return;
int32 amount = CalculatePct(m->Amount, aurEff->GetAmount());
int32 amount = CalculatePct(*manaCost, aurEff->GetAmount());
CastSpellExtraArgs args(aurEff);
args.AddSpellBP0(amount);
caster->CastSpell(nullptr, SPELL_DRUID_EXHILARATE, args);

View File

@@ -1658,12 +1658,8 @@ class spell_item_pendant_of_the_violet_eye : public AuraScript
bool CheckProc(ProcEventInfo& eventInfo)
{
if (Spell const* spell = eventInfo.GetProcSpell())
{
std::vector<SpellPowerCost> const& costs = spell->GetPowerCost();
auto m = std::find_if(costs.begin(), costs.end(), [](SpellPowerCost const& cost) { return cost.Power == POWER_MANA && cost.Amount > 0; });
if (m != costs.end())
if (spell->GetPowerTypeCostAmount(POWER_MANA) > 0)
return true;
}
return false;
}

View File

@@ -1031,10 +1031,8 @@ class spell_rog_sinister_strike : public SpellScript
damagePerCombo += t5->GetAmount();
int32 finalDamage = damagePerCombo;
std::vector<SpellPowerCost> const& costs = GetSpell()->GetPowerCost();
auto c = std::find_if(costs.begin(), costs.end(), [](SpellPowerCost const& cost) { return cost.Power == POWER_COMBO_POINTS; });
if (c != costs.end())
finalDamage *= c->Amount;
if (Optional<int32> comboPointCost = GetSpell()->GetPowerTypeCostAmount(POWER_COMBO_POINTS))
finalDamage *= *comboPointCost;
SetHitDamage(finalDamage);
}

View File

@@ -1012,11 +1012,9 @@ class spell_sha_item_mana_surge : public AuraScript
{
PreventDefaultAction();
std::vector<SpellPowerCost> const& costs = eventInfo.GetProcSpell()->GetPowerCost();
auto m = std::find_if(costs.begin(), costs.end(), [](SpellPowerCost const& cost) { return cost.Power == POWER_MANA; });
if (m != costs.end())
if (Optional<int32> manaCost = eventInfo.GetProcSpell()->GetPowerTypeCostAmount(POWER_MANA))
{
int32 mana = CalculatePct(m->Amount, 35);
int32 mana = CalculatePct(*manaCost, 35);
if (mana > 0)
{
CastSpellExtraArgs args(aurEff);