Files
TrinityCore/src/server/scripts/Spells/spell_warlock.cpp
Treeston 34c7810fe5 Core: Combat/threat system rewrite (PR #19930)
- PvE combat is now always mutual. UNIT_FLAG_IN_COMBAT is backed by actual references to the units we're in combat with.
- PvP combat is now also tracked, and almost always mutual; spells like Vanish and Feign Death can break this rule. That means we can easily determine a list of players we're fighting.
- By extension, IsInCombatWith now has sensible behavior when invoked on nonplayers.
- Threat and combat systems are no longer the same.
  - They still have an enforced relationship (threat implies combat - clearing combat clears threat)...
  - ...but we can have combat without threat. A creature (with threat list) isn't considered to be engaged until it has an entry on its threat list...
  - ...which means we can now faithfully replicate retail engage behavior. Combat on projectile launch - engagement start on projectile impact. Yay for progress!
- AI method refactor, as already ported in 6113b9d - `JustEngagedWith`, `JustEnteredCombat` and `JustExitedCombat`.
- Vehicle threat is now properly pooled on the main vehicle body (fixes #16542).
- Various edge case bug fixes for threat redirects (Misdirection "cancelling" Vigilance and similar).
- Target re-selection is now significantly faster.
- Fixed a ton of other smaller edge case bugs, probably.

Closes #7951 and #19998.

(cherry picked from commit 532ab1c7f8)
2021-05-16 21:56:01 +02:00

983 lines
36 KiB
C++

/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Scripts for spells with SPELLFAMILY_WARLOCK and SPELLFAMILY_GENERIC spells used by warlock players.
* Ordered alphabetically using scriptname.
* Scriptnames of files in this file should be prefixed with "spell_warl_".
*/
#include "ScriptMgr.h"
#include "AreaTrigger.h"
#include "Creature.h"
#include "GameObject.h"
#include "ObjectAccessor.h"
#include "Player.h"
#include "Random.h"
#include "SpellAuraEffects.h"
#include "SpellAuras.h"
#include "SpellMgr.h"
#include "SpellScript.h"
enum WarlockSpells
{
SPELL_WARLOCK_CREATE_HEALTHSTONE = 23517,
SPELL_WARLOCK_DEMONIC_CIRCLE_ALLOW_CAST = 62388,
SPELL_WARLOCK_DEMONIC_CIRCLE_SUMMON = 48018,
SPELL_WARLOCK_DEMONIC_CIRCLE_TELEPORT = 48020,
SPELL_WARLOCK_DEVOUR_MAGIC_HEAL = 19658,
SPELL_WARLOCK_GLYPH_OF_DEMON_TRAINING = 56249,
SPELL_WARLOCK_GLYPH_OF_SOUL_SWAP = 56226,
SPELL_WARLOCK_GLYPH_OF_SUCCUBUS = 56250,
SPELL_WARLOCK_IMPROVED_HEALTH_FUNNEL_BUFF_R1 = 60955,
SPELL_WARLOCK_IMPROVED_HEALTH_FUNNEL_BUFF_R2 = 60956,
SPELL_WARLOCK_IMPROVED_HEALTH_FUNNEL_R1 = 18703,
SPELL_WARLOCK_IMPROVED_HEALTH_FUNNEL_R2 = 18704,
SPELL_WARLOCK_RAIN_OF_FIRE = 5740,
SPELL_WARLOCK_RAIN_OF_FIRE_DAMAGE = 42223,
SPELL_WARLOCK_SEED_OF_CORRUPTION_DAMAGE = 27285,
SPELL_WARLOCK_SEED_OF_CORRUPTION_GENERIC = 32865,
SPELL_WARLOCK_SOULSHATTER_EFFECT = 32835,
SPELL_WARLOCK_SOUL_SWAP_CD_MARKER = 94229,
SPELL_WARLOCK_SOUL_SWAP_OVERRIDE = 86211,
SPELL_WARLOCK_SOUL_SWAP_MOD_COST = 92794,
SPELL_WARLOCK_SOUL_SWAP_DOT_MARKER = 92795,
SPELL_WARLOCK_UNSTABLE_AFFLICTION = 30108,
SPELL_WARLOCK_UNSTABLE_AFFLICTION_DISPEL = 31117,
SPELL_WARLOCK_SHADOWFLAME = 37378,
SPELL_WARLOCK_FLAMESHADOW = 37379,
};
enum MiscSpells
{
SPELL_GEN_REPLENISHMENT = 57669,
SPELL_PRIEST_SHADOW_WORD_DEATH = 32409
};
// 710 - Banish
class spell_warl_banish : public SpellScriptLoader
{
public:
spell_warl_banish() : SpellScriptLoader("spell_warl_banish") { }
class spell_warl_banish_SpellScript : public SpellScript
{
PrepareSpellScript(spell_warl_banish_SpellScript);
public:
spell_warl_banish_SpellScript() {}
private:
void HandleBanish(SpellMissInfo missInfo)
{
if (missInfo != SPELL_MISS_IMMUNE)
return;
if (Unit* target = GetHitUnit())
{
// Casting Banish on a banished target will remove applied aura
if (Aura * banishAura = target->GetAura(GetSpellInfo()->Id, GetCaster()->GetGUID()))
banishAura->Remove();
}
}
void Register() override
{
BeforeHit += BeforeSpellHitFn(spell_warl_banish_SpellScript::HandleBanish);
}
};
SpellScript* GetSpellScript() const override
{
return new spell_warl_banish_SpellScript();
}
};
// 77220 - Mastery: Chaotic Energies
class spell_warl_chaotic_energies : public AuraScript
{
PrepareAuraScript(spell_warl_chaotic_energies);
void HandleAbsorb(AuraEffect* /*aurEff*/, DamageInfo& dmgInfo, uint32& absorbAmount)
{
AuraEffect const* effect1 = GetEffect(EFFECT_1);
if (!effect1 || !GetTargetApplication()->HasEffect(EFFECT_1))
{
PreventDefaultAction();
return;
}
// You take ${$s2/3}% reduced damage
float damageReductionPct = float(effect1->GetAmount()) / 3;
// plus a random amount of up to ${$s2/3}% additional reduced damage
damageReductionPct += frand(0.0f, damageReductionPct);
absorbAmount = CalculatePct(dmgInfo.GetDamage(), damageReductionPct);
}
void Register() override
{
OnEffectAbsorb += AuraEffectAbsorbFn(spell_warl_chaotic_energies::HandleAbsorb, EFFECT_2);
}
};
// 6201 - Create Healthstone
class spell_warl_create_healthstone : public SpellScriptLoader
{
public:
spell_warl_create_healthstone() : SpellScriptLoader("spell_warl_create_healthstone") { }
class spell_warl_create_healthstone_SpellScript : public SpellScript
{
PrepareSpellScript(spell_warl_create_healthstone_SpellScript);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_WARLOCK_CREATE_HEALTHSTONE });
}
bool Load() override
{
return GetCaster()->GetTypeId() == TYPEID_PLAYER;
}
void HandleScriptEffect(SpellEffIndex /*effIndex*/)
{
GetCaster()->CastSpell(GetCaster(), SPELL_WARLOCK_CREATE_HEALTHSTONE, true);
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_warl_create_healthstone_SpellScript::HandleScriptEffect, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
}
};
SpellScript* GetSpellScript() const override
{
return new spell_warl_create_healthstone_SpellScript();
}
};
// 48018 - Demonic Circle: Summon
/// Updated 4.3.4
class spell_warl_demonic_circle_summon : public SpellScriptLoader
{
public:
spell_warl_demonic_circle_summon() : SpellScriptLoader("spell_warl_demonic_circle_summon") { }
class spell_warl_demonic_circle_summon_AuraScript : public AuraScript
{
PrepareAuraScript(spell_warl_demonic_circle_summon_AuraScript);
void HandleRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes mode)
{
// If effect is removed by expire remove the summoned demonic circle too.
if (!(mode & AURA_EFFECT_HANDLE_REAPPLY))
GetTarget()->RemoveGameObject(GetId(), true);
GetTarget()->RemoveAura(SPELL_WARLOCK_DEMONIC_CIRCLE_ALLOW_CAST);
}
void HandleDummyTick(AuraEffect const* /*aurEff*/)
{
if (GameObject* circle = GetTarget()->GetGameObject(GetId()))
{
// Here we check if player is in demonic circle teleport range, if so add
// WARLOCK_DEMONIC_CIRCLE_ALLOW_CAST; allowing him to cast the WARLOCK_DEMONIC_CIRCLE_TELEPORT.
// If not in range remove the WARLOCK_DEMONIC_CIRCLE_ALLOW_CAST.
SpellInfo const* spellInfo = sSpellMgr->AssertSpellInfo(SPELL_WARLOCK_DEMONIC_CIRCLE_TELEPORT, GetCastDifficulty());
if (GetTarget()->IsWithinDist(circle, spellInfo->GetMaxRange(true)))
{
if (!GetTarget()->HasAura(SPELL_WARLOCK_DEMONIC_CIRCLE_ALLOW_CAST))
GetTarget()->CastSpell(GetTarget(), SPELL_WARLOCK_DEMONIC_CIRCLE_ALLOW_CAST, true);
}
else
GetTarget()->RemoveAura(SPELL_WARLOCK_DEMONIC_CIRCLE_ALLOW_CAST);
}
}
void Register() override
{
OnEffectRemove += AuraEffectApplyFn(spell_warl_demonic_circle_summon_AuraScript::HandleRemove, EFFECT_0, SPELL_AURA_PERIODIC_DUMMY, AURA_EFFECT_HANDLE_REAL_OR_REAPPLY_MASK);
OnEffectPeriodic += AuraEffectPeriodicFn(spell_warl_demonic_circle_summon_AuraScript::HandleDummyTick, EFFECT_0, SPELL_AURA_PERIODIC_DUMMY);
}
};
AuraScript* GetAuraScript() const override
{
return new spell_warl_demonic_circle_summon_AuraScript();
}
};
// 48020 - Demonic Circle: Teleport
/// Updated 4.3.4
class spell_warl_demonic_circle_teleport : public SpellScriptLoader
{
public:
spell_warl_demonic_circle_teleport() : SpellScriptLoader("spell_warl_demonic_circle_teleport") { }
class spell_warl_demonic_circle_teleport_AuraScript : public AuraScript
{
PrepareAuraScript(spell_warl_demonic_circle_teleport_AuraScript);
void HandleTeleport(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
if (Player* player = GetTarget()->ToPlayer())
{
if (GameObject* circle = player->GetGameObject(SPELL_WARLOCK_DEMONIC_CIRCLE_SUMMON))
{
player->NearTeleportTo(circle->GetPositionX(), circle->GetPositionY(), circle->GetPositionZ(), circle->GetOrientation());
player->RemoveMovementImpairingAuras(false);
}
}
}
void Register() override
{
OnEffectApply += AuraEffectApplyFn(spell_warl_demonic_circle_teleport_AuraScript::HandleTeleport, EFFECT_0, SPELL_AURA_MECHANIC_IMMUNITY, AURA_EFFECT_HANDLE_REAL);
}
};
AuraScript* GetAuraScript() const override
{
return new spell_warl_demonic_circle_teleport_AuraScript();
}
};
// 67518, 19505 - Devour Magic
class spell_warl_devour_magic : public SpellScriptLoader
{
public:
spell_warl_devour_magic() : SpellScriptLoader("spell_warl_devour_magic") { }
class spell_warl_devour_magic_SpellScript : public SpellScript
{
PrepareSpellScript(spell_warl_devour_magic_SpellScript);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_WARLOCK_GLYPH_OF_DEMON_TRAINING, SPELL_WARLOCK_DEVOUR_MAGIC_HEAL });
}
void OnSuccessfulDispel(SpellEffIndex /*effIndex*/)
{
if (SpellEffectInfo const* effect = GetSpellInfo()->GetEffect(EFFECT_1))
{
Unit* caster = GetCaster();
CastSpellExtraArgs args;
args.TriggerFlags = TRIGGERED_FULL_MASK;
args.AddSpellBP0(effect->CalcValue(caster));
caster->CastSpell(caster, SPELL_WARLOCK_DEVOUR_MAGIC_HEAL, args);
// Glyph of Felhunter
if (Unit* owner = caster->GetOwner())
if (owner->GetAura(SPELL_WARLOCK_GLYPH_OF_DEMON_TRAINING))
owner->CastSpell(owner, SPELL_WARLOCK_DEVOUR_MAGIC_HEAL, args);
}
}
void Register() override
{
OnEffectSuccessfulDispel += SpellEffectFn(spell_warl_devour_magic_SpellScript::OnSuccessfulDispel, EFFECT_0, SPELL_EFFECT_DISPEL);
}
};
SpellScript* GetSpellScript() const override
{
return new spell_warl_devour_magic_SpellScript();
}
};
// 48181 - Haunt
/// Updated 4.3.4
class spell_warl_haunt : public SpellScriptLoader
{
public:
spell_warl_haunt() : SpellScriptLoader("spell_warl_haunt") { }
class spell_warl_haunt_SpellScript : public SpellScript
{
PrepareSpellScript(spell_warl_haunt_SpellScript);
void HandleAfterHit()
{
if (Aura* aura = GetHitAura())
if (AuraEffect* aurEff = aura->GetEffect(EFFECT_1))
aurEff->SetAmount(CalculatePct(aurEff->GetAmount(), GetHitDamage()));
}
void Register() override
{
AfterHit += SpellHitFn(spell_warl_haunt_SpellScript::HandleAfterHit);
}
};
SpellScript* GetSpellScript() const override
{
return new spell_warl_haunt_SpellScript();
}
};
// 755 - Health Funnel
/// Updated 4.3.4
class spell_warl_health_funnel : public SpellScriptLoader
{
public:
spell_warl_health_funnel() : SpellScriptLoader("spell_warl_health_funnel") { }
class spell_warl_health_funnel_AuraScript : public AuraScript
{
PrepareAuraScript(spell_warl_health_funnel_AuraScript);
void ApplyEffect(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
Unit* caster = GetCaster();
if (!caster)
return;
Unit* target = GetTarget();
if (caster->HasAura(SPELL_WARLOCK_IMPROVED_HEALTH_FUNNEL_R2))
target->CastSpell(target, SPELL_WARLOCK_IMPROVED_HEALTH_FUNNEL_BUFF_R2, true);
else if (caster->HasAura(SPELL_WARLOCK_IMPROVED_HEALTH_FUNNEL_R1))
target->CastSpell(target, SPELL_WARLOCK_IMPROVED_HEALTH_FUNNEL_BUFF_R1, true);
}
void RemoveEffect(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
Unit* target = GetTarget();
target->RemoveAurasDueToSpell(SPELL_WARLOCK_IMPROVED_HEALTH_FUNNEL_BUFF_R1);
target->RemoveAurasDueToSpell(SPELL_WARLOCK_IMPROVED_HEALTH_FUNNEL_BUFF_R2);
}
void OnPeriodic(AuraEffect const* aurEff)
{
Unit* caster = GetCaster();
if (!caster)
return;
//! HACK for self damage, is not blizz :/
uint32 damage = caster->CountPctFromMaxHealth(aurEff->GetBaseAmount());
if (Player* modOwner = caster->GetSpellModOwner())
modOwner->ApplySpellMod(GetSpellInfo(), SpellModOp::PowerCost0, damage);
SpellNonMeleeDamage damageInfo(caster, caster, GetSpellInfo(), GetAura()->GetSpellVisual(), GetSpellInfo()->SchoolMask, GetAura()->GetCastGUID());
damageInfo.periodicLog = true;
damageInfo.damage = damage;
caster->DealSpellDamage(&damageInfo, false);
caster->SendSpellNonMeleeDamageLog(&damageInfo);
}
void Register() override
{
OnEffectApply += AuraEffectApplyFn(spell_warl_health_funnel_AuraScript::ApplyEffect, EFFECT_0, SPELL_AURA_OBS_MOD_HEALTH, AURA_EFFECT_HANDLE_REAL);
OnEffectRemove += AuraEffectRemoveFn(spell_warl_health_funnel_AuraScript::RemoveEffect, EFFECT_0, SPELL_AURA_OBS_MOD_HEALTH, AURA_EFFECT_HANDLE_REAL);
OnEffectPeriodic += AuraEffectPeriodicFn(spell_warl_health_funnel_AuraScript::OnPeriodic, EFFECT_0, SPELL_AURA_OBS_MOD_HEALTH);
}
};
AuraScript* GetAuraScript() const override
{
return new spell_warl_health_funnel_AuraScript();
}
};
// 6262 - Healthstone
class spell_warl_healthstone_heal : public SpellScriptLoader
{
public:
spell_warl_healthstone_heal() : SpellScriptLoader("spell_warl_healthstone_heal") { }
class spell_warl_healthstone_heal_SpellScript : public SpellScript
{
PrepareSpellScript(spell_warl_healthstone_heal_SpellScript);
void HandleOnHit()
{
int32 heal = int32(CalculatePct(GetCaster()->GetCreateHealth(), GetHitHeal()));
SetHitHeal(heal);
}
void Register() override
{
OnHit += SpellHitFn(spell_warl_healthstone_heal_SpellScript::HandleOnHit);
}
};
SpellScript* GetSpellScript() const override
{
return new spell_warl_healthstone_heal_SpellScript();
}
};
// 6358 - Seduction (Special Ability)
class spell_warl_seduction : public SpellScriptLoader
{
public:
spell_warl_seduction() : SpellScriptLoader("spell_warl_seduction") { }
class spell_warl_seduction_SpellScript : public SpellScript
{
PrepareSpellScript(spell_warl_seduction_SpellScript);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_WARLOCK_GLYPH_OF_SUCCUBUS, SPELL_PRIEST_SHADOW_WORD_DEATH });
}
void HandleScriptEffect(SpellEffIndex /*effIndex*/)
{
Unit* caster = GetCaster();
if (Unit* target = GetHitUnit())
{
if (caster->GetOwner() && caster->GetOwner()->HasAura(SPELL_WARLOCK_GLYPH_OF_SUCCUBUS))
{
target->RemoveAurasByType(SPELL_AURA_PERIODIC_DAMAGE, ObjectGuid::Empty, target->GetAura(SPELL_PRIEST_SHADOW_WORD_DEATH)); // SW:D shall not be removed.
target->RemoveAurasByType(SPELL_AURA_PERIODIC_DAMAGE_PERCENT);
target->RemoveAurasByType(SPELL_AURA_PERIODIC_LEECH);
}
}
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_warl_seduction_SpellScript::HandleScriptEffect, EFFECT_0, SPELL_EFFECT_APPLY_AURA);
}
};
SpellScript* GetSpellScript() const override
{
return new spell_warl_seduction_SpellScript();
}
};
// 27285 - Seed of Corruption
/// Updated 4.3.4
class spell_warl_seed_of_corruption : public SpellScriptLoader
{
public:
spell_warl_seed_of_corruption() : SpellScriptLoader("spell_warl_seed_of_corruption") { }
class spell_warl_seed_of_corruption_SpellScript : public SpellScript
{
PrepareSpellScript(spell_warl_seed_of_corruption_SpellScript);
void FilterTargets(std::list<WorldObject*>& targets)
{
if (GetExplTargetUnit())
targets.remove(GetExplTargetUnit());
}
void Register() override
{
OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(spell_warl_seed_of_corruption_SpellScript::FilterTargets, EFFECT_0, TARGET_UNIT_DEST_AREA_ENEMY);
}
};
SpellScript* GetSpellScript() const override
{
return new spell_warl_seed_of_corruption_SpellScript();
}
};
// 27243 - Seed of Corruption
class spell_warl_seed_of_corruption_dummy : public SpellScriptLoader
{
public:
spell_warl_seed_of_corruption_dummy() : SpellScriptLoader("spell_warl_seed_of_corruption_dummy") { }
class spell_warl_seed_of_corruption_dummy_AuraScript : public AuraScript
{
PrepareAuraScript(spell_warl_seed_of_corruption_dummy_AuraScript);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_WARLOCK_SEED_OF_CORRUPTION_DAMAGE });
}
void HandleProc(AuraEffect* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
DamageInfo* damageInfo = eventInfo.GetDamageInfo();
if (!damageInfo || !damageInfo->GetDamage())
return;
int32 amount = aurEff->GetAmount() - damageInfo->GetDamage();
if (amount > 0)
{
const_cast<AuraEffect*>(aurEff)->SetAmount(amount);
if (!GetTarget()->HealthBelowPctDamaged(1, damageInfo->GetDamage()))
return;
}
Remove();
Unit* caster = GetCaster();
if (!caster)
return;
caster->CastSpell(eventInfo.GetActionTarget(), SPELL_WARLOCK_SEED_OF_CORRUPTION_DAMAGE, aurEff);
}
void Register() override
{
OnEffectProc += AuraEffectProcFn(spell_warl_seed_of_corruption_dummy_AuraScript::HandleProc, EFFECT_1, SPELL_AURA_DUMMY);
}
};
AuraScript* GetAuraScript() const override
{
return new spell_warl_seed_of_corruption_dummy_AuraScript();
}
};
// 32863 - Seed of Corruption
// 36123 - Seed of Corruption
// 38252 - Seed of Corruption
// 39367 - Seed of Corruption
// 44141 - Seed of Corruption
// 70388 - Seed of Corruption
// Monster spells, triggered only on amount drop (not on death)
class spell_warl_seed_of_corruption_generic : public SpellScriptLoader
{
public:
spell_warl_seed_of_corruption_generic() : SpellScriptLoader("spell_warl_seed_of_corruption_generic") { }
class spell_warl_seed_of_corruption_generic_AuraScript : public AuraScript
{
PrepareAuraScript(spell_warl_seed_of_corruption_generic_AuraScript);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_WARLOCK_SEED_OF_CORRUPTION_GENERIC });
}
void HandleProc(AuraEffect* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
DamageInfo* damageInfo = eventInfo.GetDamageInfo();
if (!damageInfo || !damageInfo->GetDamage())
return;
int32 amount = aurEff->GetAmount() - damageInfo->GetDamage();
if (amount > 0)
{
const_cast<AuraEffect*>(aurEff)->SetAmount(amount);
return;
}
Remove();
Unit* caster = GetCaster();
if (!caster)
return;
caster->CastSpell(eventInfo.GetActionTarget(), SPELL_WARLOCK_SEED_OF_CORRUPTION_GENERIC, aurEff);
}
void Register() override
{
OnEffectProc += AuraEffectProcFn(spell_warl_seed_of_corruption_generic_AuraScript::HandleProc, EFFECT_1, SPELL_AURA_DUMMY);
}
};
AuraScript* GetAuraScript() const override
{
return new spell_warl_seed_of_corruption_generic_AuraScript();
}
};
// 86121 - Soul Swap
class spell_warl_soul_swap : public SpellScriptLoader
{
public:
spell_warl_soul_swap() : SpellScriptLoader("spell_warl_soul_swap") { }
class spell_warl_soul_swap_SpellScript : public SpellScript
{
PrepareSpellScript(spell_warl_soul_swap_SpellScript);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo(
{
SPELL_WARLOCK_GLYPH_OF_SOUL_SWAP,
SPELL_WARLOCK_SOUL_SWAP_CD_MARKER,
SPELL_WARLOCK_SOUL_SWAP_OVERRIDE
});
}
void HandleHit(SpellEffIndex /*effIndex*/)
{
GetCaster()->CastSpell(GetCaster(), SPELL_WARLOCK_SOUL_SWAP_OVERRIDE, true);
GetHitUnit()->CastSpell(GetCaster(), SPELL_WARLOCK_SOUL_SWAP_DOT_MARKER, true);
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_warl_soul_swap_SpellScript::HandleHit, EFFECT_0, SPELL_EFFECT_SCHOOL_DAMAGE);
}
};
SpellScript* GetSpellScript() const override
{
return new spell_warl_soul_swap_SpellScript();
}
};
// 86211 - Soul Swap Override - Also acts as a dot container
class spell_warl_soul_swap_override : public SpellScriptLoader
{
public:
static char constexpr const ScriptName[] = "spell_warl_soul_swap_override";
spell_warl_soul_swap_override() : SpellScriptLoader(ScriptName) { }
class spell_warl_soul_swap_override_AuraScript : public AuraScript
{
PrepareAuraScript(spell_warl_soul_swap_override_AuraScript);
//! Forced to, pure virtual functions must have a body when linking
void Register() override { }
public:
void AddDot(uint32 id) { _dotList.push_back(id); }
std::list<uint32> const GetDotList() const { return _dotList; }
Unit* GetOriginalSwapSource() const { return _swapCaster; }
void SetOriginalSwapSource(Unit* victim) { _swapCaster = victim; }
private:
std::list<uint32> _dotList;
Unit* _swapCaster = nullptr;
};
AuraScript* GetAuraScript() const override
{
return new spell_warl_soul_swap_override_AuraScript();
}
};
char constexpr const spell_warl_soul_swap_override::ScriptName[];
typedef spell_warl_soul_swap_override::spell_warl_soul_swap_override_AuraScript SoulSwapOverrideAuraScript;
//! Soul Swap Copy Spells - 92795 - Simply copies spell IDs.
class spell_warl_soul_swap_dot_marker : public SpellScriptLoader
{
public:
spell_warl_soul_swap_dot_marker() : SpellScriptLoader("spell_warl_soul_swap_dot_marker") { }
class spell_warl_soul_swap_dot_marker_SpellScript : public SpellScript
{
PrepareSpellScript(spell_warl_soul_swap_dot_marker_SpellScript);
void HandleHit(SpellEffIndex /*effIndex*/)
{
Unit* swapVictim = GetCaster();
Unit* warlock = GetHitUnit();
if (!warlock || !swapVictim)
return;
Unit::AuraApplicationMap const& appliedAuras = swapVictim->GetAppliedAuras();
SoulSwapOverrideAuraScript* swapSpellScript = nullptr;
if (Aura* swapOverrideAura = warlock->GetAura(SPELL_WARLOCK_SOUL_SWAP_OVERRIDE))
swapSpellScript = swapOverrideAura->GetScript<SoulSwapOverrideAuraScript>(spell_warl_soul_swap_override::ScriptName);
if (!swapSpellScript)
return;
flag128 classMask = GetEffectInfo()->SpellClassMask;
for (Unit::AuraApplicationMap::const_iterator itr = appliedAuras.begin(); itr != appliedAuras.end(); ++itr)
{
SpellInfo const* spellProto = itr->second->GetBase()->GetSpellInfo();
if (itr->second->GetBase()->GetCaster() == warlock)
if (spellProto->SpellFamilyName == SPELLFAMILY_WARLOCK && (spellProto->SpellFamilyFlags & classMask))
swapSpellScript->AddDot(itr->first);
}
swapSpellScript->SetOriginalSwapSource(swapVictim);
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_warl_soul_swap_dot_marker_SpellScript::HandleHit, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
SpellScript* GetSpellScript() const override
{
return new spell_warl_soul_swap_dot_marker_SpellScript();
}
};
// 86213 - Soul Swap Exhale
class spell_warl_soul_swap_exhale : public SpellScriptLoader
{
public:
spell_warl_soul_swap_exhale() : SpellScriptLoader("spell_warl_soul_swap_exhale") { }
class spell_warl_soul_swap_exhale_SpellScript : public SpellScript
{
PrepareSpellScript(spell_warl_soul_swap_exhale_SpellScript);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_WARLOCK_SOUL_SWAP_MOD_COST, SPELL_WARLOCK_SOUL_SWAP_OVERRIDE });
}
SpellCastResult CheckCast()
{
Unit* currentTarget = GetExplTargetUnit();
Unit* swapTarget = nullptr;
if (Aura const* swapOverride = GetCaster()->GetAura(SPELL_WARLOCK_SOUL_SWAP_OVERRIDE))
if (SoulSwapOverrideAuraScript* swapScript = swapOverride->GetScript<SoulSwapOverrideAuraScript>(spell_warl_soul_swap_override::ScriptName))
swapTarget = swapScript->GetOriginalSwapSource();
// Soul Swap Exhale can't be cast on the same target than Soul Swap
if (swapTarget && currentTarget && swapTarget == currentTarget)
return SPELL_FAILED_BAD_TARGETS;
return SPELL_CAST_OK;
}
void OnEffectHit(SpellEffIndex /*effIndex*/)
{
GetCaster()->CastSpell(GetCaster(), SPELL_WARLOCK_SOUL_SWAP_MOD_COST, true);
bool hasGlyph = GetCaster()->HasAura(SPELL_WARLOCK_GLYPH_OF_SOUL_SWAP);
std::list<uint32> dotList;
Unit* swapSource = nullptr;
if (Aura const* swapOverride = GetCaster()->GetAura(SPELL_WARLOCK_SOUL_SWAP_OVERRIDE))
{
SoulSwapOverrideAuraScript* swapScript = swapOverride->GetScript<SoulSwapOverrideAuraScript>(spell_warl_soul_swap_override::ScriptName);
if (!swapScript)
return;
dotList = swapScript->GetDotList();
swapSource = swapScript->GetOriginalSwapSource();
}
if (dotList.empty())
return;
for (std::list<uint32>::const_iterator itr = dotList.begin(); itr != dotList.end(); ++itr)
{
GetCaster()->AddAura(*itr, GetHitUnit());
if (!hasGlyph && swapSource)
swapSource->RemoveAurasDueToSpell(*itr);
}
// Remove Soul Swap Exhale buff
GetCaster()->RemoveAurasDueToSpell(SPELL_WARLOCK_SOUL_SWAP_OVERRIDE);
if (hasGlyph) // Add a cooldown on Soul Swap if caster has the glyph
GetCaster()->CastSpell(GetCaster(), SPELL_WARLOCK_SOUL_SWAP_CD_MARKER, false);
}
void Register() override
{
OnCheckCast += SpellCheckCastFn(spell_warl_soul_swap_exhale_SpellScript::CheckCast);
OnEffectHitTarget += SpellEffectFn(spell_warl_soul_swap_exhale_SpellScript::OnEffectHit, EFFECT_0, SPELL_EFFECT_SCHOOL_DAMAGE);
}
};
SpellScript* GetSpellScript() const override
{
return new spell_warl_soul_swap_exhale_SpellScript();
}
};
// 29858 - Soulshatter
/// Updated 4.3.4
class spell_warl_soulshatter : public SpellScriptLoader
{
public:
spell_warl_soulshatter() : SpellScriptLoader("spell_warl_soulshatter") { }
class spell_warl_soulshatter_SpellScript : public SpellScript
{
PrepareSpellScript(spell_warl_soulshatter_SpellScript);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_WARLOCK_SOULSHATTER_EFFECT });
}
void HandleDummy(SpellEffIndex /*effIndex*/)
{
Unit* caster = GetCaster();
if (Unit* target = GetHitUnit())
if (target->GetThreatManager().IsThreatenedBy(caster, true))
caster->CastSpell(target, SPELL_WARLOCK_SOULSHATTER_EFFECT, true);
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_warl_soulshatter_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
SpellScript* GetSpellScript() const override
{
return new spell_warl_soulshatter_SpellScript();
}
};
// 37377 - Shadowflame
// 39437 - Shadowflame Hellfire and RoF
template <uint32 TriggerSpellId>
class spell_warl_t4_2p_bonus : public SpellScriptLoader
{
public:
spell_warl_t4_2p_bonus(char const* ScriptName) : SpellScriptLoader(ScriptName) { }
template <uint32 Trigger>
class spell_warl_t4_2p_bonus_AuraScript : public AuraScript
{
PrepareAuraScript(spell_warl_t4_2p_bonus_AuraScript);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ Trigger });
}
void HandleProc(AuraEffect* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
Unit* caster = eventInfo.GetActor();
caster->CastSpell(caster, Trigger, aurEff);
}
void Register() override
{
OnEffectProc += AuraEffectProcFn(spell_warl_t4_2p_bonus_AuraScript::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
}
};
AuraScript* GetAuraScript() const override
{
return new spell_warl_t4_2p_bonus_AuraScript<TriggerSpellId>();
}
};
// 30108, 34438, 34439, 35183 - Unstable Affliction
/// Updated 4.3.4
class spell_warl_unstable_affliction : public SpellScriptLoader
{
public:
spell_warl_unstable_affliction() : SpellScriptLoader("spell_warl_unstable_affliction") { }
class spell_warl_unstable_affliction_AuraScript : public AuraScript
{
PrepareAuraScript(spell_warl_unstable_affliction_AuraScript);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_WARLOCK_UNSTABLE_AFFLICTION_DISPEL });
}
void HandleDispel(DispelInfo* dispelInfo)
{
if (Unit* caster = GetCaster())
if (AuraEffect const* aurEff = GetEffect(EFFECT_1))
{
// backfire damage and silence
CastSpellExtraArgs args(aurEff);
args.AddSpellBP0(aurEff->GetAmount() * 9);
caster->CastSpell(dispelInfo->GetDispeller(), SPELL_WARLOCK_UNSTABLE_AFFLICTION_DISPEL, args);
}
}
void Register() override
{
AfterDispel += AuraDispelFn(spell_warl_unstable_affliction_AuraScript::HandleDispel);
}
};
AuraScript* GetAuraScript() const override
{
return new spell_warl_unstable_affliction_AuraScript();
}
};
// 5740 - Rain of Fire
/// Updated 7.1.5
class spell_warl_rain_of_fire : public SpellScriptLoader
{
public:
spell_warl_rain_of_fire() : SpellScriptLoader("spell_warl_rain_of_fire") { }
class spell_warl_rain_of_fire_AuraScript : public AuraScript
{
PrepareAuraScript(spell_warl_rain_of_fire_AuraScript);
void HandleDummyTick(AuraEffect const* /*aurEff*/)
{
std::vector<AreaTrigger*> rainOfFireAreaTriggers = GetTarget()->GetAreaTriggers(SPELL_WARLOCK_RAIN_OF_FIRE);
GuidUnorderedSet targetsInRainOfFire;
for (AreaTrigger* rainOfFireAreaTrigger : rainOfFireAreaTriggers)
{
GuidUnorderedSet const& insideTargets = rainOfFireAreaTrigger->GetInsideUnits();
targetsInRainOfFire.insert(insideTargets.begin(), insideTargets.end());
}
for (ObjectGuid insideTargetGuid : targetsInRainOfFire)
if (Unit* insideTarget = ObjectAccessor::GetUnit(*GetTarget(), insideTargetGuid))
if (!GetTarget()->IsFriendlyTo(insideTarget))
GetTarget()->CastSpell(insideTarget, SPELL_WARLOCK_RAIN_OF_FIRE_DAMAGE, true);
}
void Register() override
{
OnEffectPeriodic += AuraEffectPeriodicFn(spell_warl_rain_of_fire_AuraScript::HandleDummyTick, EFFECT_3, SPELL_AURA_PERIODIC_DUMMY);
}
};
AuraScript* GetAuraScript() const override
{
return new spell_warl_rain_of_fire_AuraScript();
}
};
void AddSC_warlock_spell_scripts()
{
new spell_warl_banish();
RegisterAuraScript(spell_warl_chaotic_energies);
new spell_warl_create_healthstone();
new spell_warl_demonic_circle_summon();
new spell_warl_demonic_circle_teleport();
new spell_warl_devour_magic();
new spell_warl_haunt();
new spell_warl_health_funnel();
new spell_warl_healthstone_heal();
new spell_warl_seduction();
new spell_warl_seed_of_corruption();
new spell_warl_seed_of_corruption_dummy();
new spell_warl_seed_of_corruption_generic();
new spell_warl_soul_swap();
new spell_warl_soul_swap_dot_marker();
new spell_warl_soul_swap_exhale();
new spell_warl_soul_swap_override();
new spell_warl_soulshatter();
new spell_warl_t4_2p_bonus<SPELL_WARLOCK_FLAMESHADOW>("spell_warl_t4_2p_bonus_shadow");
new spell_warl_t4_2p_bonus<SPELL_WARLOCK_SHADOWFLAME>("spell_warl_t4_2p_bonus_fire");
new spell_warl_unstable_affliction();
new spell_warl_rain_of_fire();
}