aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraftedRO <24683355+CraftedRO@users.noreply.github.com>2024-06-03 20:16:19 +0300
committerGitHub <noreply@github.com>2024-06-03 19:16:19 +0200
commitb2a77f6d015380dd46aaba7764b91e5d39a44e45 (patch)
tree979810d4df73485e87e279811082fc4f793118b5
parent6a5fa255fe053796588684e3876f6047cf92a08f (diff)
Scripts/Spells: Prevent sacrificing immune minions with Death Pact (#29920)
Co-authored-by: Shauren <shauren.trinity@gmail.com>
-rw-r--r--src/server/scripts/Spells/spell_dk.cpp52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/server/scripts/Spells/spell_dk.cpp b/src/server/scripts/Spells/spell_dk.cpp
index 2e16e4f7ebd..71eb6b58fe1 100644
--- a/src/server/scripts/Spells/spell_dk.cpp
+++ b/src/server/scripts/Spells/spell_dk.cpp
@@ -758,42 +758,42 @@ class spell_dk_death_pact : public SpellScript
{
PrepareSpellScript(spell_dk_death_pact);
- SpellCastResult CheckCast()
+ void FilterTargets(std::list<WorldObject*>& targetList)
{
- // Check if we have valid targets, otherwise skip spell casting here
- if (Player* player = GetCaster()->ToPlayer())
- for (Unit::ControlList::const_iterator itr = player->m_Controlled.begin(); itr != player->m_Controlled.end(); ++itr)
- if (Creature* undeadPet = (*itr)->ToCreature())
- if (undeadPet->IsAlive() &&
- undeadPet->GetOwnerGUID() == player->GetGUID() &&
- undeadPet->GetCreatureType() == CREATURE_TYPE_UNDEAD &&
- undeadPet->IsWithinDist(player, 100.0f, false))
- return SPELL_CAST_OK;
+ targetList.remove_if([&](WorldObject* target)
+ {
+ Unit* unit = target->ToUnit();
+ if (!unit)
+ return true;
+ if (unit->GetOwnerGUID() != GetCaster()->GetGUID())
+ return true;
+ if (unit->GetCreatureType() != CREATURE_TYPE_UNDEAD)
+ return true;
+ return false;
+ });
- return SPELL_FAILED_NO_PET;
- }
+ if (targetList.empty())
+ {
+ FinishCast(SPELL_FAILED_NO_PET);
+ return;
+ }
- void FilterTargets(std::list<WorldObject*>& targetList)
- {
- Unit* target = nullptr;
- for (std::list<WorldObject*>::iterator itr = targetList.begin(); itr != targetList.end(); ++itr)
+ targetList.remove_if([&](WorldObject* target)
{
- if (Unit* unit = (*itr)->ToUnit())
- if (unit->GetOwnerGUID() == GetCaster()->GetGUID() && unit->GetCreatureType() == CREATURE_TYPE_UNDEAD)
- {
- target = unit;
- break;
- }
+ return target->ToUnit()->IsImmunedToSpell(GetSpellInfo(), GetCaster());
+ });
+
+ if (targetList.empty())
+ {
+ FinishCast(SPELL_FAILED_IMMUNE);
+ return;
}
- targetList.clear();
- if (target)
- targetList.push_back(target);
+ Trinity::Containers::RandomResize(targetList, 1);
}
void Register() override
{
- OnCheckCast += SpellCheckCastFn(spell_dk_death_pact::CheckCast);
OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(spell_dk_death_pact::FilterTargets, EFFECT_1, TARGET_UNIT_DEST_AREA_ALLY);
}
};