Merge pull request #6976 from Elron103/pull-requests

Scripts/Spells: Fix Deathknight ability Death Pact 48743 Closes #5950
This commit is contained in:
kandera
2012-06-29 10:18:58 -07:00

View File

@@ -334,6 +334,21 @@ class spell_dk_death_pact : public SpellScriptLoader
{
PrepareSpellScript(spell_dk_death_pact_SpellScript);
SpellCastResult CheckCast()
{
// 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->GetCreatureInfo()->type == CREATURE_TYPE_UNDEAD &&
undeadPet->IsWithinDist(player, 100.0f, false))
return SPELL_CAST_OK;
return SPELL_FAILED_NO_PET;
}
void FilterTargets(std::list<Unit*>& unitList)
{
Unit* unit_to_add = NULL;
@@ -351,17 +366,11 @@ class spell_dk_death_pact : public SpellScriptLoader
unitList.clear();
if (unit_to_add)
unitList.push_back(unit_to_add);
else
{
// Pet not found - remove cooldown
if (Player* modOwner = GetCaster()->GetSpellModOwner())
modOwner->RemoveSpellCooldown(GetSpellInfo()->Id, true);
FinishCast(SPELL_FAILED_NO_PET);
}
}
void Register()
{
OnCheckCast += SpellCheckCastFn(spell_dk_death_pact_SpellScript::CheckCast);
OnUnitTargetSelect += SpellUnitTargetFn(spell_dk_death_pact_SpellScript::FilterTargets, EFFECT_1, TARGET_UNIT_DEST_AREA_ALLY);
}
};