From 4997e316d9e4bf529e131d45528fff404d99b836 Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 13 May 2021 00:38:09 +0200 Subject: Core/Spells: Expose number of targets selected for each spell effect to scripts to allow implementing spells that do something depending on number of targets hit (cherry picked from commit 1a7779a6e6464d9bc5b367e02820213edd60f704) --- src/server/game/Spells/Spell.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/server/game/Spells/Spell.cpp') diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 5f024a813ea..e523ce7c111 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -2362,6 +2362,30 @@ void Spell::AddDestTarget(SpellDestination const& dest, uint32 effIndex) m_destTargets[effIndex] = dest; } +int64 Spell::GetUnitTargetCountForEffect(SpellEffIndex effect) const +{ + return std::count_if(m_UniqueTargetInfo.begin(), m_UniqueTargetInfo.end(), [effect](TargetInfo const& targetInfo) + { + return targetInfo.EffectMask & (1 << effect); + }); +} + +int64 Spell::GetGameObjectTargetCountForEffect(SpellEffIndex effect) const +{ + return std::count_if(m_UniqueGOTargetInfo.begin(), m_UniqueGOTargetInfo.end(), [effect](GOTargetInfo const& targetInfo) + { + return targetInfo.EffectMask & (1 << effect); + }); +} + +int64 Spell::GetItemTargetCountForEffect(SpellEffIndex effect) const +{ + return std::count_if(m_UniqueItemInfo.begin(), m_UniqueItemInfo.end(), [effect](ItemTargetInfo const& targetInfo) + { + return targetInfo.EffectMask & (1 << effect); + }); +} + void Spell::TargetInfo::PreprocessTarget(Spell* spell) { Unit* unit = spell->m_caster->GetGUID() == TargetGUID ? spell->m_caster->ToUnit() : ObjectAccessor::GetUnit(*spell->m_caster, TargetGUID); @@ -7784,7 +7808,7 @@ void Spell::DoEffectOnLaunchTarget(TargetInfo& targetInfo, float multiplier, Spe if (m_originalCaster->GetTypeId() == TYPEID_PLAYER) { // cap damage of player AOE - uint32 targetAmount = m_UniqueTargetInfo.size(); + int64 targetAmount = GetUnitTargetCountForEffect(spellEffectInfo.EffectIndex); if (targetAmount > 10) m_damage = m_damage * 10 / targetAmount; } -- cgit v1.2.3