mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Scripts/Spells: Use Spell::GetPowerTypeCostAmount where possible instead of iterating Spell::GetPowerCost
This commit is contained in:
@@ -1389,8 +1389,7 @@ bool AuraEffect::CheckEffectProc(AuraApplication* aurApp, ProcEventInfo& eventIn
|
||||
|
||||
// Costs Check
|
||||
std::vector<SpellPowerCost> const& costs = eventInfo.GetProcSpell()->GetPowerCost();
|
||||
auto m = std::find_if(costs.begin(), costs.end(), [](SpellPowerCost const& cost) { return cost.Amount > 0; });
|
||||
if (m == costs.end())
|
||||
if (std::ranges::none_of(costs, [](SpellPowerCost const& cost) { return cost.Amount > 0; }))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4771,7 +4771,7 @@ void Spell::SendSpellStart()
|
||||
|
||||
if ((m_caster->GetTypeId() == TYPEID_PLAYER ||
|
||||
(m_caster->GetTypeId() == TYPEID_UNIT && m_caster->ToCreature()->IsPet()))
|
||||
&& std::find_if(m_powerCost.begin(), m_powerCost.end(), [](SpellPowerCost const& cost) { return cost.Power != POWER_HEALTH; }) != m_powerCost.end())
|
||||
&& std::ranges::any_of(m_powerCost, [](SpellPowerCost const& cost) { return cost.Power != POWER_HEALTH; }))
|
||||
castFlags |= CAST_FLAG_POWER_LEFT_SELF;
|
||||
|
||||
if (HasPowerTypeCost(POWER_RUNES))
|
||||
@@ -4870,7 +4870,7 @@ void Spell::SendSpellGo()
|
||||
|
||||
if ((m_caster->GetTypeId() == TYPEID_PLAYER ||
|
||||
(m_caster->GetTypeId() == TYPEID_UNIT && m_caster->ToCreature()->IsPet()))
|
||||
&& std::find_if(m_powerCost.begin(), m_powerCost.end(), [](SpellPowerCost const& cost) { return cost.Power != POWER_HEALTH; }) != m_powerCost.end())
|
||||
&& std::ranges::any_of(m_powerCost, [](SpellPowerCost const& cost) { return cost.Power != POWER_HEALTH; }))
|
||||
castFlags |= CAST_FLAG_POWER_LEFT_SELF;
|
||||
|
||||
if ((m_caster->GetTypeId() == TYPEID_PLAYER)
|
||||
@@ -8150,11 +8150,7 @@ bool Spell::HasPowerTypeCost(Powers power) const
|
||||
|
||||
Optional<int32> Spell::GetPowerTypeCostAmount(Powers power) const
|
||||
{
|
||||
auto itr = std::find_if(m_powerCost.cbegin(), m_powerCost.cend(), [power](SpellPowerCost const& cost)
|
||||
{
|
||||
return cost.Power == power;
|
||||
});
|
||||
|
||||
auto itr = std::ranges::find(m_powerCost, power, &SpellPowerCost::Power);
|
||||
if (itr == m_powerCost.cend())
|
||||
return { };
|
||||
|
||||
@@ -9590,7 +9586,7 @@ void SelectRandomInjuredTargets(std::list<WorldObject*>& targets, size_t maxTarg
|
||||
tempTargets.resize(targets.size());
|
||||
|
||||
// categorize each target
|
||||
std::transform(targets.begin(), targets.end(), tempTargets.begin(), [&](WorldObject* target)
|
||||
std::ranges::transform(targets, tempTargets.begin(), [&](WorldObject* target)
|
||||
{
|
||||
int32 negativePoints = 0;
|
||||
if (prioritizeGroupMembersOf && (!target->IsUnit() || target->ToUnit()->IsInRaidWith(prioritizeGroupMembersOf)))
|
||||
|
||||
@@ -534,8 +534,7 @@ bool SpellMgr::CanSpellTriggerProcOnEvent(SpellProcEntry const& procEntry, ProcE
|
||||
return false;
|
||||
|
||||
std::vector<SpellPowerCost> const& costs = eventInfo.GetProcSpell()->GetPowerCost();
|
||||
auto m = std::find_if(costs.begin(), costs.end(), [](SpellPowerCost const& cost) { return cost.Amount > 0; });
|
||||
if (m == costs.end())
|
||||
if (std::ranges::none_of(costs, [](SpellPowerCost const& cost) { return cost.Amount > 0; }))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user