Skip to content

Commit 26376d8

Browse files
committed
Scripts/Spells: Use Spell::GetPowerTypeCostAmount where possible instead of iterating Spell::GetPowerCost
1 parent 0e36fd9 commit 26376d8

File tree

7 files changed

+14
-29
lines changed

7 files changed

+14
-29
lines changed

src/server/game/Spells/Auras/SpellAuraEffects.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,8 +1389,7 @@ bool AuraEffect::CheckEffectProc(AuraApplication* aurApp, ProcEventInfo& eventIn
13891389

13901390
// Costs Check
13911391
std::vector<SpellPowerCost> const& costs = eventInfo.GetProcSpell()->GetPowerCost();
1392-
auto m = std::find_if(costs.begin(), costs.end(), [](SpellPowerCost const& cost) { return cost.Amount > 0; });
1393-
if (m == costs.end())
1392+
if (std::ranges::none_of(costs, [](SpellPowerCost const& cost) { return cost.Amount > 0; }))
13941393
return false;
13951394
break;
13961395
}

src/server/game/Spells/Spell.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4771,7 +4771,7 @@ void Spell::SendSpellStart()
47714771

47724772
if ((m_caster->GetTypeId() == TYPEID_PLAYER ||
47734773
(m_caster->GetTypeId() == TYPEID_UNIT && m_caster->ToCreature()->IsPet()))
4774-
&& std::find_if(m_powerCost.begin(), m_powerCost.end(), [](SpellPowerCost const& cost) { return cost.Power != POWER_HEALTH; }) != m_powerCost.end())
4774+
&& std::ranges::any_of(m_powerCost, [](SpellPowerCost const& cost) { return cost.Power != POWER_HEALTH; }))
47754775
castFlags |= CAST_FLAG_POWER_LEFT_SELF;
47764776

47774777
if (HasPowerTypeCost(POWER_RUNES))
@@ -4870,7 +4870,7 @@ void Spell::SendSpellGo()
48704870

48714871
if ((m_caster->GetTypeId() == TYPEID_PLAYER ||
48724872
(m_caster->GetTypeId() == TYPEID_UNIT && m_caster->ToCreature()->IsPet()))
4873-
&& std::find_if(m_powerCost.begin(), m_powerCost.end(), [](SpellPowerCost const& cost) { return cost.Power != POWER_HEALTH; }) != m_powerCost.end())
4873+
&& std::ranges::any_of(m_powerCost, [](SpellPowerCost const& cost) { return cost.Power != POWER_HEALTH; }))
48744874
castFlags |= CAST_FLAG_POWER_LEFT_SELF;
48754875

48764876
if ((m_caster->GetTypeId() == TYPEID_PLAYER)
@@ -8150,11 +8150,7 @@ bool Spell::HasPowerTypeCost(Powers power) const
81508150

81518151
Optional<int32> Spell::GetPowerTypeCostAmount(Powers power) const
81528152
{
8153-
auto itr = std::find_if(m_powerCost.cbegin(), m_powerCost.cend(), [power](SpellPowerCost const& cost)
8154-
{
8155-
return cost.Power == power;
8156-
});
8157-
8153+
auto itr = std::ranges::find(m_powerCost, power, &SpellPowerCost::Power);
81588154
if (itr == m_powerCost.cend())
81598155
return { };
81608156

@@ -9590,7 +9586,7 @@ void SelectRandomInjuredTargets(std::list<WorldObject*>& targets, size_t maxTarg
95909586
tempTargets.resize(targets.size());
95919587

95929588
// categorize each target
9593-
std::transform(targets.begin(), targets.end(), tempTargets.begin(), [&](WorldObject* target)
9589+
std::ranges::transform(targets, tempTargets.begin(), [&](WorldObject* target)
95949590
{
95959591
int32 negativePoints = 0;
95969592
if (prioritizeGroupMembersOf && (!target->IsUnit() || target->ToUnit()->IsInRaidWith(prioritizeGroupMembersOf)))

src/server/game/Spells/SpellMgr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,7 @@ bool SpellMgr::CanSpellTriggerProcOnEvent(SpellProcEntry const& procEntry, ProcE
534534
return false;
535535

536536
std::vector<SpellPowerCost> const& costs = eventInfo.GetProcSpell()->GetPowerCost();
537-
auto m = std::find_if(costs.begin(), costs.end(), [](SpellPowerCost const& cost) { return cost.Amount > 0; });
538-
if (m == costs.end())
537+
if (std::ranges::none_of(costs, [](SpellPowerCost const& cost) { return cost.Amount > 0; }))
539538
return false;
540539
}
541540

src/server/scripts/Spells/spell_druid.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,12 +1846,11 @@ class spell_dru_t3_8p_bonus : public AuraScript
18461846
return;
18471847

18481848
Unit* caster = eventInfo.GetActor();
1849-
std::vector<SpellPowerCost> const& costs = spell->GetPowerCost();
1850-
auto m = std::find_if(costs.begin(), costs.end(), [](SpellPowerCost const& cost) { return cost.Power == POWER_MANA; });
1851-
if (m == costs.end())
1849+
Optional<int32> manaCost = spell->GetPowerTypeCostAmount(POWER_MANA);
1850+
if (!manaCost)
18521851
return;
18531852

1854-
int32 amount = CalculatePct(m->Amount, aurEff->GetAmount());
1853+
int32 amount = CalculatePct(*manaCost, aurEff->GetAmount());
18551854
CastSpellExtraArgs args(aurEff);
18561855
args.AddSpellBP0(amount);
18571856
caster->CastSpell(nullptr, SPELL_DRUID_EXHILARATE, args);

src/server/scripts/Spells/spell_item.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,12 +1658,8 @@ class spell_item_pendant_of_the_violet_eye : public AuraScript
16581658
bool CheckProc(ProcEventInfo& eventInfo)
16591659
{
16601660
if (Spell const* spell = eventInfo.GetProcSpell())
1661-
{
1662-
std::vector<SpellPowerCost> const& costs = spell->GetPowerCost();
1663-
auto m = std::find_if(costs.begin(), costs.end(), [](SpellPowerCost const& cost) { return cost.Power == POWER_MANA && cost.Amount > 0; });
1664-
if (m != costs.end())
1661+
if (spell->GetPowerTypeCostAmount(POWER_MANA) > 0)
16651662
return true;
1666-
}
16671663

16681664
return false;
16691665
}

src/server/scripts/Spells/spell_rogue.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,10 +1031,8 @@ class spell_rog_sinister_strike : public SpellScript
10311031
damagePerCombo += t5->GetAmount();
10321032

10331033
int32 finalDamage = damagePerCombo;
1034-
std::vector<SpellPowerCost> const& costs = GetSpell()->GetPowerCost();
1035-
auto c = std::find_if(costs.begin(), costs.end(), [](SpellPowerCost const& cost) { return cost.Power == POWER_COMBO_POINTS; });
1036-
if (c != costs.end())
1037-
finalDamage *= c->Amount;
1034+
if (Optional<int32> comboPointCost = GetSpell()->GetPowerTypeCostAmount(POWER_COMBO_POINTS))
1035+
finalDamage *= *comboPointCost;
10381036

10391037
SetHitDamage(finalDamage);
10401038
}

src/server/scripts/Spells/spell_shaman.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,11 +1012,9 @@ class spell_sha_item_mana_surge : public AuraScript
10121012
{
10131013
PreventDefaultAction();
10141014

1015-
std::vector<SpellPowerCost> const& costs = eventInfo.GetProcSpell()->GetPowerCost();
1016-
auto m = std::find_if(costs.begin(), costs.end(), [](SpellPowerCost const& cost) { return cost.Power == POWER_MANA; });
1017-
if (m != costs.end())
1015+
if (Optional<int32> manaCost = eventInfo.GetProcSpell()->GetPowerTypeCostAmount(POWER_MANA))
10181016
{
1019-
int32 mana = CalculatePct(m->Amount, 35);
1017+
int32 mana = CalculatePct(*manaCost, 35);
10201018
if (mana > 0)
10211019
{
10221020
CastSpellExtraArgs args(aurEff);

0 commit comments

Comments
 (0)