/*
* This file is part of the AzerothCore 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 .
*/
#include "Pet.h"
#include "Player.h"
#include "SpellAuraEffects.h"
#include "SpellMgr.h"
#include "SpellScript.h"
#include "SpellScriptLoader.h"
#include "TemporarySummon.h"
/*
* Scripts for spells with SPELLFAMILY_MAGE and SPELLFAMILY_GENERIC spells used by mage players.
* Ordered alphabetically using scriptname.
* Scriptnames of files in this file should be prefixed with "spell_mage_".
*/
enum MageSpells
{
SPELL_MAGE_ARCANE_MISSILES_R1 = 5143,
SPELL_MAGE_BLAZING_SPEED = 31643,
SPELL_MAGE_MAGIC_ABSORPTION_MANA = 29442,
SPELL_MAGE_BURNOUT_TRIGGER = 44450,
SPELL_MAGE_IMPROVED_BLIZZARD_CHILLED = 12486,
SPELL_MAGE_COMBUSTION = 11129,
SPELL_MAGE_COMBUSTION_PROC = 28682,
SPELL_MAGE_COLD_SNAP = 11958,
SPELL_MAGE_FOCUS_MAGIC_PROC = 54648,
SPELL_MAGE_FROST_WARDING_R1 = 11189,
SPELL_MAGE_FROST_WARDING_TRIGGERED = 57776,
SPELL_MAGE_INCANTERS_ABSORBTION_R1 = 44394,
SPELL_MAGE_INCANTERS_ABSORBTION_TRIGGERED = 44413,
SPELL_MAGE_IGNITE = 12654,
SPELL_MAGE_MASTER_OF_ELEMENTS_ENERGIZE = 29077,
SPELL_MAGE_PERMAFROST_AURA = 68391,
SPELL_MAGE_SQUIRREL_FORM = 32813,
SPELL_MAGE_GIRAFFE_FORM = 32816,
SPELL_MAGE_SERPENT_FORM = 32817,
SPELL_MAGE_DRAGONHAWK_FORM = 32818,
SPELL_MAGE_WORGEN_FORM = 32819,
SPELL_MAGE_SHEEP_FORM = 32820,
SPELL_MAGE_GLYPH_OF_ETERNAL_WATER = 70937,
SPELL_MAGE_SUMMON_WATER_ELEMENTAL_PERMANENT = 70908,
SPELL_MAGE_SUMMON_WATER_ELEMENTAL_TEMPORARY = 70907,
SPELL_MAGE_GLYPH_OF_BLAST_WAVE = 62126,
SPELL_MAGE_FINGERS_OF_FROST = 44543,
SPELL_MAGE_FINGERS_OF_FROST_AURASTATE_AURA = 44544,
SPELL_MAGE_ARCANE_POTENCY_RANK_1 = 57529,
SPELL_MAGE_ARCANE_POTENCY_RANK_2 = 57531,
SPELL_MAGE_EMPOWERED_FIRE_PROC = 67545,
SPELL_MAGE_T10_2P_BONUS = 70752,
SPELL_MAGE_T10_2P_BONUS_EFFECT = 70753,
SPELL_MAGE_T8_4P_BONUS = 64869,
SPELL_MAGE_HOT_STREAK_PROC = 48108,
SPELL_MAGE_CHILLED_R1 = 12484,
SPELL_MAGE_CHILLED_R2 = 12485,
SPELL_MAGE_CHILLED_R3 = 12486,
SPELL_MAGE_MANA_SURGE = 37445,
SPELL_MAGE_FROST_NOVA = 122,
SPELL_MAGE_LIVING_BOMB_R1 = 44457,
SPELL_MAGE_MISSILE_BARRAGE_PROC = 44401
};
enum MageSpellIcons
{
MAGE_ICON_MAGIC_ABSORPTION = 459,
MAGE_ICON_CLEARCASTING = 212,
MAGE_ICON_PRESENCE_OF_MIND = 139,
MAGE_ICON_LIVING_BOMB = 3000
};
class spell_mage_arcane_blast : public SpellScript
{
PrepareSpellScript(spell_mage_arcane_blast);
bool Load() override { _triggerSpellId = 0; return true; }
void HandleTriggerSpell(SpellEffIndex effIndex)
{
_triggerSpellId = GetSpellInfo()->Effects[effIndex].TriggerSpell;
PreventHitDefaultEffect(effIndex);
}
void HandleAfterCast()
{
GetCaster()->CastSpell(GetCaster(), _triggerSpellId, TRIGGERED_FULL_MASK);
}
void Register() override
{
OnEffectLaunch += SpellEffectFn(spell_mage_arcane_blast::HandleTriggerSpell, EFFECT_1, SPELL_EFFECT_TRIGGER_SPELL);
OnEffectLaunchTarget += SpellEffectFn(spell_mage_arcane_blast::HandleTriggerSpell, EFFECT_1, SPELL_EFFECT_TRIGGER_SPELL);
AfterCast += SpellCastFn(spell_mage_arcane_blast::HandleAfterCast);
}
private:
uint32 _triggerSpellId;
};
class spell_mage_burning_determination : public AuraScript
{
PrepareAuraScript(spell_mage_burning_determination);
bool CheckProc(ProcEventInfo& eventInfo)
{
if (!eventInfo.GetSpellInfo() || !eventInfo.GetActionTarget())
return false;
// Need Interrupt or Silenced mechanic
if (!(eventInfo.GetSpellInfo()->GetAllEffectsMechanicMask() & ((1ULL << MECHANIC_INTERRUPT) | (1ULL << MECHANIC_SILENCE))))
return false;
// Xinef: immuned effect should just eat charge
if (eventInfo.GetHitMask() & PROC_EX_IMMUNE)
{
eventInfo.GetActionTarget()->RemoveAurasDueToSpell(54748);
return false;
}
if (Aura* aura = eventInfo.GetActionTarget()->GetAura(54748))
{
if (aura->GetDuration() < aura->GetMaxDuration())
eventInfo.GetActionTarget()->RemoveAurasDueToSpell(54748);
return false;
}
return true;
}
void HandleProc(ProcEventInfo& /*eventInfo*/)
{
PreventDefaultAction();
GetUnitOwner()->CastSpell(GetUnitOwner(), 54748, true);
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_burning_determination::CheckProc);
OnProc += AuraProcFn(spell_mage_burning_determination::HandleProc);
}
};
class spell_mage_molten_armor : public AuraScript
{
PrepareAuraScript(spell_mage_molten_armor);
bool CheckProc(ProcEventInfo& eventInfo)
{
SpellInfo const* spellInfo = eventInfo.GetSpellInfo();
if (!spellInfo || (eventInfo.GetTypeMask() & PROC_FLAG_TAKEN_MELEE_AUTO_ATTACK))
return true;
if (!eventInfo.GetActionTarget())
{
return false;
}
// Xinef: Molten Shields talent
if (AuraEffect* aurEff = eventInfo.GetActionTarget()->GetAuraEffect(SPELL_AURA_ADD_FLAT_MODIFIER, SPELLFAMILY_MAGE, 16, EFFECT_0))
return roll_chance_i(aurEff->GetSpellInfo()->GetRank() * 50);
return false;
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_molten_armor::CheckProc);
}
};
class spell_mage_mirror_image : public AuraScript
{
PrepareAuraScript(spell_mage_mirror_image)
void HandleEffectApply(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
{
GetTarget()->CastSpell((Unit*)nullptr, GetSpellInfo()->Effects[aurEff->GetEffIndex()].TriggerSpell, true);
}
void CalcPeriodic(AuraEffect const* /*effect*/, bool& isPeriodic, int32& /*amplitude*/)
{
isPeriodic = false;
}
void Register() override
{
OnEffectApply += AuraEffectApplyFn(spell_mage_mirror_image::HandleEffectApply, EFFECT_2, SPELL_AURA_PERIODIC_DUMMY, AURA_EFFECT_HANDLE_REAL);
DoEffectCalcPeriodic += AuraEffectCalcPeriodicFn(spell_mage_mirror_image::CalcPeriodic, EFFECT_2, SPELL_AURA_PERIODIC_DUMMY);
}
};
class spell_mage_burnout : public AuraScript
{
PrepareAuraScript(spell_mage_burnout);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_BURNOUT_TRIGGER });
}
bool CheckProc(ProcEventInfo& eventInfo)
{
return eventInfo.GetSpellInfo() != nullptr;
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
int32 mana = int32(eventInfo.GetSpellInfo()->CalcPowerCost(GetTarget(), eventInfo.GetSchoolMask()));
mana = CalculatePct(mana, aurEff->GetAmount());
GetTarget()->CastCustomSpell(SPELL_MAGE_BURNOUT_TRIGGER, SPELLVALUE_BASE_POINT0, mana, GetTarget(), true, nullptr, aurEff);
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_burnout::CheckProc);
OnEffectProc += AuraEffectProcFn(spell_mage_burnout::HandleProc, EFFECT_1, SPELL_AURA_DUMMY);
}
};
class spell_mage_burnout_trigger : public SpellScript
{
PrepareSpellScript(spell_mage_burnout_trigger);
void HandleDummy(SpellEffIndex effIndex)
{
PreventHitDefaultEffect(effIndex);
if (Unit* target = GetHitUnit())
{
int32 newDamage = -(target->ModifyPower(POWER_MANA, -GetEffectValue()));
GetSpell()->ExecuteLogEffectTakeTargetPower(effIndex, target, POWER_MANA, newDamage, 0.0f);
}
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_mage_burnout_trigger::HandleDummy, EFFECT_0, SPELL_EFFECT_POWER_BURN);
}
};
class spell_mage_pet_scaling : public AuraScript
{
PrepareAuraScript(spell_mage_pet_scaling);
void CalculateResistanceAmount(AuraEffect const* aurEff, int32& amount, bool& /*canBeRecalculated*/)
{
// xinef: mage pet inherits 40% of resistance from owner and 35% of armor (guessed)
if (Unit* owner = GetUnitOwner()->GetOwner())
{
SpellSchoolMask schoolMask = SpellSchoolMask(aurEff->GetSpellInfo()->Effects[aurEff->GetEffIndex()].MiscValue);
int32 modifier = schoolMask == SPELL_SCHOOL_MASK_NORMAL ? 35 : 40;
amount = CalculatePct(std::max(0, owner->GetResistance(schoolMask)), modifier);
}
}
void CalculateStatAmount(AuraEffect const* aurEff, int32& amount, bool& /*canBeRecalculated*/)
{
// xinef: mage pet inherits 30% of intellect / stamina
if (Unit* owner = GetUnitOwner()->GetOwner())
{
Stats stat = Stats(aurEff->GetSpellInfo()->Effects[aurEff->GetEffIndex()].MiscValue);
amount = CalculatePct(std::max(0, owner->GetStat(stat)), 30);
}
}
void CalculateAPAmount(AuraEffect const* /*aurEff*/, int32& /*amount*/, bool& /*canBeRecalculated*/)
{
// xinef: mage pet inherits 0% AP
}
void CalculateSPAmount(AuraEffect const* /*aurEff*/, int32& amount, bool& /*canBeRecalculated*/)
{
// xinef: mage pet inherits 33% of SP
if (Unit* owner = GetUnitOwner()->GetOwner())
{
int32 frost = owner->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_FROST);
amount = CalculatePct(std::max(0, frost), 33);
// xinef: Update appropriate player field
if (owner->IsPlayer())
owner->SetUInt32Value(PLAYER_PET_SPELL_POWER, (uint32)amount);
}
}
void HandleEffectApply(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
{
if (GetUnitOwner()->IsPet())
return;
GetUnitOwner()->ApplySpellImmune(0, IMMUNITY_STATE, aurEff->GetAuraType(), true, SPELL_BLOCK_TYPE_POSITIVE);
if (aurEff->GetAuraType() == SPELL_AURA_MOD_ATTACK_POWER)
GetUnitOwner()->ApplySpellImmune(0, IMMUNITY_STATE, SPELL_AURA_MOD_ATTACK_POWER_PCT, true, SPELL_BLOCK_TYPE_POSITIVE);
else if (aurEff->GetAuraType() == SPELL_AURA_MOD_STAT)
GetUnitOwner()->ApplySpellImmune(0, IMMUNITY_STATE, SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE, true, SPELL_BLOCK_TYPE_POSITIVE);
}
void CalcPeriodic(AuraEffect const* /*aurEff*/, bool& isPeriodic, int32& amplitude)
{
if (!GetUnitOwner()->IsPet())
return;
isPeriodic = true;
amplitude = 2 * IN_MILLISECONDS;
}
void HandlePeriodic(AuraEffect const* aurEff)
{
PreventDefaultAction();
if (aurEff->GetAuraType() == SPELL_AURA_MOD_STAT && (aurEff->GetMiscValue() == STAT_STAMINA || aurEff->GetMiscValue() == STAT_INTELLECT))
{
int32 currentAmount = aurEff->GetAmount();
int32 newAmount = GetEffect(aurEff->GetEffIndex())->CalculateAmount(GetCaster());
if (newAmount != currentAmount)
{
if (aurEff->GetMiscValue() == STAT_STAMINA)
{
uint32 actStat = GetUnitOwner()->GetHealth();
GetEffect(aurEff->GetEffIndex())->ChangeAmount(newAmount, false);
GetUnitOwner()->SetHealth(std::min(GetUnitOwner()->GetMaxHealth(), actStat));
}
else
{
uint32 actStat = GetUnitOwner()->GetPower(POWER_MANA);
GetEffect(aurEff->GetEffIndex())->ChangeAmount(newAmount, false);
GetUnitOwner()->SetPower(POWER_MANA, std::min(GetUnitOwner()->GetMaxPower(POWER_MANA), actStat));
}
}
}
else
GetEffect(aurEff->GetEffIndex())->RecalculateAmount();
}
void Register() override
{
if (m_scriptSpellId != 35657)
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_pet_scaling::CalculateResistanceAmount, EFFECT_ALL, SPELL_AURA_MOD_RESISTANCE);
if (m_scriptSpellId == 35657 || m_scriptSpellId == 35658)
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_pet_scaling::CalculateStatAmount, EFFECT_ALL, SPELL_AURA_MOD_STAT);
if (m_scriptSpellId == 35657)
{
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_pet_scaling::CalculateAPAmount, EFFECT_ALL, SPELL_AURA_MOD_ATTACK_POWER);
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_pet_scaling::CalculateSPAmount, EFFECT_ALL, SPELL_AURA_MOD_DAMAGE_DONE);
}
OnEffectApply += AuraEffectApplyFn(spell_mage_pet_scaling::HandleEffectApply, EFFECT_ALL, SPELL_AURA_ANY, AURA_EFFECT_HANDLE_REAL);
DoEffectCalcPeriodic += AuraEffectCalcPeriodicFn(spell_mage_pet_scaling::CalcPeriodic, EFFECT_ALL, SPELL_AURA_ANY);
OnEffectPeriodic += AuraEffectPeriodicFn(spell_mage_pet_scaling::HandlePeriodic, EFFECT_ALL, SPELL_AURA_ANY);
}
};
class spell_mage_brain_freeze : public AuraScript
{
PrepareAuraScript(spell_mage_brain_freeze);
bool CheckProc(ProcEventInfo& eventInfo)
{
SpellInfo const* spellInfo = eventInfo.GetSpellInfo();
if (!spellInfo)
return false;
// xinef: Improved Blizzard, generic chilled check
if (spellInfo->SpellFamilyFlags[0] & 0x100000)
return spellInfo->Id == SPELL_MAGE_IMPROVED_BLIZZARD_CHILLED;
return true;
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_brain_freeze::CheckProc);
}
};
class spell_mage_glyph_of_eternal_water : public AuraScript
{
PrepareAuraScript(spell_mage_glyph_of_eternal_water);
void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
if (Unit* target = GetTarget())
if (Player* player = target->ToPlayer())
if (Pet* pet = player->GetPet())
if (pet->GetEntry() == NPC_WATER_ELEMENTAL_PERM)
pet->Remove(PET_SAVE_NOT_IN_SLOT);
}
void Register() override
{
OnEffectRemove += AuraEffectRemoveFn(spell_mage_glyph_of_eternal_water::OnRemove, EFFECT_0, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL);
}
};
class spell_mage_combustion_proc : public AuraScript
{
PrepareAuraScript(spell_mage_combustion_proc);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_COMBUSTION });
}
void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
GetTarget()->RemoveAurasDueToSpell(SPELL_MAGE_COMBUSTION);
}
void Register() override
{
AfterEffectRemove += AuraEffectRemoveFn(spell_mage_combustion_proc::OnRemove, EFFECT_0, SPELL_AURA_ADD_FLAT_MODIFIER, AURA_EFFECT_HANDLE_REAL);
}
};
// Incanter's Absorbtion
class spell_mage_incanters_absorbtion_base_AuraScript : public AuraScript
{
public:
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_INCANTERS_ABSORBTION_TRIGGERED, SPELL_MAGE_INCANTERS_ABSORBTION_R1 });
}
void Trigger(AuraEffect* aurEff, DamageInfo& /*dmgInfo*/, uint32& absorbAmount)
{
Unit* target = GetTarget();
if (AuraEffect* talentAurEff = target->GetAuraEffectOfRankedSpell(SPELL_MAGE_INCANTERS_ABSORBTION_R1, EFFECT_0))
{
int32 bp = CalculatePct(absorbAmount, talentAurEff->GetAmount());
if (AuraEffect* currentAura = target->GetAuraEffect(SPELL_AURA_MOD_DAMAGE_DONE, SPELLFAMILY_MAGE, 2941, EFFECT_0))
{
bp += int32(currentAura->GetAmount() * (currentAura->GetBase()->GetDuration() / (float)currentAura->GetBase()->GetMaxDuration()));
currentAura->ChangeAmount(bp);
currentAura->GetBase()->RefreshDuration();
}
else
target->CastCustomSpell(target, SPELL_MAGE_INCANTERS_ABSORBTION_TRIGGERED, &bp, nullptr, nullptr, true, nullptr, aurEff);
}
}
};
// -11113 - Blast Wave
class spell_mage_blast_wave : public SpellScript
{
PrepareSpellScript(spell_mage_blast_wave);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_GLYPH_OF_BLAST_WAVE });
}
void HandleKnockBack(SpellEffIndex effIndex)
{
if (GetCaster()->HasAura(SPELL_MAGE_GLYPH_OF_BLAST_WAVE))
PreventHitDefaultEffect(effIndex);
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_mage_blast_wave::HandleKnockBack, EFFECT_2, SPELL_EFFECT_KNOCK_BACK);
}
};
// 11958 - Cold Snap
class spell_mage_cold_snap : public SpellScript
{
PrepareSpellScript(spell_mage_cold_snap);
bool Load() override
{
return GetCaster()->IsPlayer();
}
void HandleDummy(SpellEffIndex /*effIndex*/)
{
Player* caster = GetCaster()->ToPlayer();
// immediately finishes the cooldown on Frost spells
PlayerSpellMap const& spellMap = caster->GetSpellMap();
for (PlayerSpellMap::const_iterator itr = spellMap.begin(); itr != spellMap.end(); ++itr)
{
SpellInfo const* spellInfo = sSpellMgr->AssertSpellInfo(itr->first);
if (spellInfo->SpellFamilyName == SPELLFAMILY_MAGE && (spellInfo->GetSchoolMask() & SPELL_SCHOOL_MASK_FROST) && spellInfo->Id != SPELL_MAGE_COLD_SNAP && spellInfo->GetRecoveryTime() > 0)
{
SpellCooldowns::iterator citr = caster->GetSpellCooldownMap().find(spellInfo->Id);
if (citr != caster->GetSpellCooldownMap().end() && citr->second.needSendToClient)
caster->RemoveSpellCooldown(spellInfo->Id, true);
else
caster->RemoveSpellCooldown(spellInfo->Id, false);
}
}
}
void Register() override
{
OnEffectHit += SpellEffectFn(spell_mage_cold_snap::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
// -543 - Fire Ward
// -6143 - Frost Ward
class spell_mage_fire_frost_ward : public spell_mage_incanters_absorbtion_base_AuraScript
{
PrepareAuraScript(spell_mage_fire_frost_ward);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_FROST_WARDING_TRIGGERED, SPELL_MAGE_FROST_WARDING_R1 });
}
void CalculateAmount(AuraEffect const* /*aurEff*/, int32& amount, bool& canBeRecalculated)
{
canBeRecalculated = false;
if (Unit* caster = GetCaster())
{
// +80.68% from sp bonus
float bonus = 0.8068f;
bonus *= caster->SpellBaseDamageBonusDone(GetSpellInfo()->GetSchoolMask());
bonus *= caster->CalculateLevelPenalty(GetSpellInfo());
amount += int32(bonus);
}
}
void Absorb(AuraEffect* aurEff, DamageInfo& dmgInfo, uint32& absorbAmount)
{
Unit* target = GetTarget();
if (AuraEffect* talentAurEff = target->GetAuraEffectOfRankedSpell(SPELL_MAGE_FROST_WARDING_R1, EFFECT_0))
{
int32 chance = talentAurEff->GetSpellInfo()->Effects[EFFECT_1].CalcValue(); // SPELL_EFFECT_DUMMY with NO_TARGET
if (roll_chance_i(chance))
{
int32 bp = dmgInfo.GetDamage();
target->CastCustomSpell(target, SPELL_MAGE_FROST_WARDING_TRIGGERED, &bp, nullptr, nullptr, true, nullptr, aurEff);
absorbAmount = 0;
// Xinef: trigger Incanters Absorbtion
uint32 damage = dmgInfo.GetDamage();
Trigger(aurEff, dmgInfo, damage);
// Xinef: hack for chaos bolt
if (!dmgInfo.GetSpellInfo() || dmgInfo.GetSpellInfo()->SpellIconID != 3178)
dmgInfo.AbsorbDamage(bp);
PreventDefaultAction();
}
}
}
void Register() override
{
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_fire_frost_ward::CalculateAmount, EFFECT_0, SPELL_AURA_SCHOOL_ABSORB);
OnEffectAbsorb += AuraEffectAbsorbFn(spell_mage_fire_frost_ward::Absorb, EFFECT_0);
AfterEffectAbsorb += AuraEffectAbsorbFn(spell_mage_fire_frost_ward::Trigger, EFFECT_0);
}
};
// 54646 - Focus Magic
class spell_mage_focus_magic : public AuraScript
{
PrepareAuraScript(spell_mage_focus_magic);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_FOCUS_MAGIC_PROC });
}
bool Load() override
{
_procTarget = nullptr;
return true;
}
bool CheckProc(ProcEventInfo& /*eventInfo*/)
{
_procTarget = GetCaster();
return _procTarget && _procTarget->IsAlive();
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& /*eventInfo*/)
{
PreventDefaultAction();
GetTarget()->CastSpell(_procTarget, SPELL_MAGE_FOCUS_MAGIC_PROC, true, nullptr, aurEff);
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_focus_magic::CheckProc);
OnEffectProc += AuraEffectProcFn(spell_mage_focus_magic::HandleProc, EFFECT_0, SPELL_AURA_MOD_SPELL_CRIT_CHANCE);
}
private:
Unit* _procTarget;
};
// -11426 - Ice Barrier
class spell_mage_ice_barrier_aura : public spell_mage_incanters_absorbtion_base_AuraScript
{
PrepareAuraScript(spell_mage_ice_barrier_aura);
/// @todo: Rework
static int32 CalculateSpellAmount(Unit* caster, int32 amount, SpellInfo const* spellInfo, const AuraEffect* aurEff)
{
// +80.68% from sp bonus
float bonus = 0.8068f;
bonus *= caster->SpellBaseDamageBonusDone(spellInfo->GetSchoolMask());
// Glyph of Ice Barrier: its weird having a SPELLMOD_ALL_EFFECTS here but its blizzards doing :)
// Glyph of Ice Barrier is only applied at the spell damage bonus because it was already applied to the base value in CalculateSpellDamage
bonus = caster->ApplyEffectModifiers(spellInfo, aurEff->GetEffIndex(), bonus);
bonus *= caster->CalculateLevelPenalty(spellInfo);
amount += int32(bonus);
return amount;
}
void CalculateAmount(AuraEffect const* aurEff, int32& amount, bool& canBeRecalculated)
{
canBeRecalculated = false;
if (Unit* caster = GetCaster())
amount = CalculateSpellAmount(caster, amount, GetSpellInfo(), aurEff);
}
void Register() override
{
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_ice_barrier_aura::CalculateAmount, EFFECT_0, SPELL_AURA_SCHOOL_ABSORB);
AfterEffectAbsorb += AuraEffectAbsorbFn(spell_mage_ice_barrier_aura::Trigger, EFFECT_0);
}
};
class spell_mage_ice_barrier : public SpellScript
{
PrepareSpellScript(spell_mage_ice_barrier);
/// @todo: Rework
static int32 CalculateSpellAmount(Unit* caster, int32 amount, SpellInfo const* spellInfo, const AuraEffect* aurEff)
{
// +80.68% from sp bonus
float bonus = 0.8068f;
bonus *= caster->SpellBaseDamageBonusDone(spellInfo->GetSchoolMask());
// Glyph of Ice Barrier: its weird having a SPELLMOD_ALL_EFFECTS here but its blizzards doing :)
// Glyph of Ice Barrier is only applied at the spell damage bonus because it was already applied to the base value in CalculateSpellDamage
bonus = caster->ApplyEffectModifiers(spellInfo, aurEff->GetEffIndex(), bonus);
bonus *= caster->CalculateLevelPenalty(spellInfo);
amount += int32(bonus);
return amount;
}
SpellCastResult CheckCast()
{
Unit* caster = GetCaster();
if (AuraEffect* aurEff = caster->GetAuraEffect(SPELL_AURA_SCHOOL_ABSORB, (SpellFamilyNames)GetSpellInfo()->SpellFamilyName, GetSpellInfo()->SpellIconID, EFFECT_0))
{
int32 newAmount = GetSpellInfo()->Effects[EFFECT_0].CalcValue(caster, nullptr, nullptr);
newAmount = CalculateSpellAmount(caster, newAmount, GetSpellInfo(), aurEff);
if (aurEff->GetAmount() > newAmount)
return SPELL_FAILED_AURA_BOUNCED;
}
return SPELL_CAST_OK;
}
void Register() override
{
OnCheckCast += SpellCheckCastFn(spell_mage_ice_barrier::CheckCast);
}
};
// -11119 - Ignite
class spell_mage_ignite : public AuraScript
{
PrepareAuraScript(spell_mage_ignite);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_IGNITE });
}
bool CheckProc(ProcEventInfo& eventInfo)
{
if (!eventInfo.GetActor() || !eventInfo.GetProcTarget())
return false;
DamageInfo* damageInfo = eventInfo.GetDamageInfo();
if (!damageInfo || !damageInfo->GetSpellInfo())
{
return false;
}
// Molten Armor
if (SpellInfo const* spellInfo = eventInfo.GetSpellInfo())
{
if (spellInfo->SpellFamilyFlags[1] & 0x8)
{
return false;
}
}
return true;
}
void HandleProc(AuraEffect const* /*aurEff*/, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
SpellInfo const* igniteDot = sSpellMgr->AssertSpellInfo(SPELL_MAGE_IGNITE);
int32 pct = 8 * GetSpellInfo()->GetRank();
int32 amount = int32(CalculatePct(eventInfo.GetDamageInfo()->GetDamage(), pct) / igniteDot->GetMaxTicks());
// Xinef: implement ignite bug
eventInfo.GetProcTarget()->CastDelayedSpellWithPeriodicAmount(eventInfo.GetActor(), SPELL_MAGE_IGNITE, SPELL_AURA_PERIODIC_DAMAGE, amount);
//GetTarget()->CastCustomSpell(SPELL_MAGE_IGNITE, SPELLVALUE_BASE_POINT0, amount, eventInfo.GetProcTarget(), true, nullptr, aurEff);
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_ignite::CheckProc);
OnEffectProc += AuraEffectProcFn(spell_mage_ignite::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
}
};
// -44457 - Living Bomb
class spell_mage_living_bomb : public AuraScript
{
PrepareAuraScript(spell_mage_living_bomb);
bool Validate(SpellInfo const* spell) override
{
if (!sSpellMgr->GetSpellInfo(uint32(spell->Effects[EFFECT_1].CalcValue())))
return false;
return true;
}
void AfterRemove(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
{
AuraRemoveMode removeMode = GetTargetApplication()->GetRemoveMode();
if (removeMode != AURA_REMOVE_BY_ENEMY_SPELL && removeMode != AURA_REMOVE_BY_EXPIRE)
return;
if (Unit* caster = GetCaster())
caster->CastSpell(GetTarget(), uint32(aurEff->GetAmount()), true, nullptr, aurEff);
}
void Register() override
{
AfterEffectRemove += AuraEffectRemoveFn(spell_mage_living_bomb::AfterRemove, EFFECT_1, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL);
}
};
// -1463 - Mana Shield
class spell_mage_mana_shield : public spell_mage_incanters_absorbtion_base_AuraScript
{
PrepareAuraScript(spell_mage_mana_shield);
void CalculateAmount(AuraEffect const* /*aurEff*/, int32& amount, bool& canBeRecalculated)
{
canBeRecalculated = false;
if (Unit* caster = GetCaster())
{
// +80.53% from sp bonus
float bonus = 0.8053f;
bonus *= caster->SpellBaseDamageBonusDone(GetSpellInfo()->GetSchoolMask());
bonus *= caster->CalculateLevelPenalty(GetSpellInfo());
amount += int32(bonus);
}
}
void Register() override
{
DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_mage_mana_shield::CalculateAmount, EFFECT_0, SPELL_AURA_MANA_SHIELD);
AfterEffectManaShield += AuraEffectManaShieldFn(spell_mage_mana_shield::Trigger, EFFECT_0);
}
};
// -29074 - Master of Elements
class spell_mage_master_of_elements : public AuraScript
{
PrepareAuraScript(spell_mage_master_of_elements);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_MASTER_OF_ELEMENTS_ENERGIZE, SPELL_MAGE_LIVING_BOMB_R1 });
}
bool CheckProc(ProcEventInfo& eventInfo)
{
DamageInfo* damageInfo = eventInfo.GetDamageInfo();
if (!damageInfo || !damageInfo->GetSpellInfo())
return false;
return true;
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
SpellInfo const* spellInfo = eventInfo.GetDamageInfo()->GetSpellInfo();
// Living Bomb explosion has no mana cost, use the aura spell's cost instead
if (spellInfo->SpellFamilyName == SPELLFAMILY_MAGE
&& spellInfo->SpellIconID == MAGE_ICON_LIVING_BOMB
&& !spellInfo->ManaCost && !spellInfo->ManaCostPercentage)
{
uint8 rank = sSpellMgr->GetSpellRank(spellInfo->Id);
spellInfo = sSpellMgr->GetSpellInfo(
sSpellMgr->GetSpellWithRank(SPELL_MAGE_LIVING_BOMB_R1, rank));
if (!spellInfo)
return;
}
// Use base mana cost (ManaCost + ManaCostPercentage) without spell mods,
// as the talent refunds based on "base mana cost"
int32 mana = spellInfo->ManaCost + int32(CalculatePct(GetTarget()->GetCreateMana(), spellInfo->ManaCostPercentage));
mana = CalculatePct(mana, aurEff->GetAmount());
if (mana > 0)
{
GetTarget()->CastCustomSpell(SPELL_MAGE_MASTER_OF_ELEMENTS_ENERGIZE, SPELLVALUE_BASE_POINT0, mana, GetTarget(), true, nullptr, aurEff);
}
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_master_of_elements::CheckProc);
OnEffectProc += AuraEffectProcFn(spell_mage_master_of_elements::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
}
};
enum SilvermoonPolymorph
{
NPC_AUROSALIA = 18744,
};
/// @todo move out of here and rename - not a mage spell
// 32826 - Polymorph (Visual)
class spell_mage_polymorph_cast_visual : public SpellScript
{
PrepareSpellScript(spell_mage_polymorph_cast_visual);
static const uint32 PolymorhForms[6];
bool Validate(SpellInfo const* /*spellInfo*/) override
{
// check if spell ids exist in dbc
for (uint32 i = 0; i < 6; ++i)
if (!sSpellMgr->GetSpellInfo(PolymorhForms[i]))
return false;
return true;
}
void HandleDummy(SpellEffIndex /*effIndex*/)
{
if (Unit* target = GetCaster()->FindNearestCreature(NPC_AUROSALIA, 30.0f))
if (target->IsCreature())
target->CastSpell(target, PolymorhForms[urand(0, 5)], true);
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_mage_polymorph_cast_visual::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
const uint32 spell_mage_polymorph_cast_visual::spell_mage_polymorph_cast_visual::PolymorhForms[6] =
{
SPELL_MAGE_SQUIRREL_FORM,
SPELL_MAGE_GIRAFFE_FORM,
SPELL_MAGE_SERPENT_FORM,
SPELL_MAGE_DRAGONHAWK_FORM,
SPELL_MAGE_WORGEN_FORM,
SPELL_MAGE_SHEEP_FORM
};
// 31687 - Summon Water Elemental
class spell_mage_summon_water_elemental : public SpellScript
{
PrepareSpellScript(spell_mage_summon_water_elemental)
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo(
{
SPELL_MAGE_GLYPH_OF_ETERNAL_WATER,
SPELL_MAGE_SUMMON_WATER_ELEMENTAL_TEMPORARY,
SPELL_MAGE_SUMMON_WATER_ELEMENTAL_PERMANENT
});
}
void HandleDummy(SpellEffIndex /*effIndex*/)
{
Unit* caster = GetCaster();
if (Creature* pet = ObjectAccessor::GetCreature(*caster, caster->GetPetGUID()))
if (!pet->IsAlive())
pet->ToTempSummon()->UnSummon();
// Glyph of Eternal Water
if (caster->HasAura(SPELL_MAGE_GLYPH_OF_ETERNAL_WATER))
caster->CastSpell(caster, SPELL_MAGE_SUMMON_WATER_ELEMENTAL_PERMANENT, true);
else
caster->CastSpell(caster, SPELL_MAGE_SUMMON_WATER_ELEMENTAL_TEMPORARY, true);
if (Creature* pet = ObjectAccessor::GetCreature(*caster, caster->GetPetGUID()))
if (pet->GetCharmInfo() && caster->ToPlayer())
{
pet->m_CreatureSpellCooldowns.clear();
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(31707);
pet->GetCharmInfo()->ToggleCreatureAutocast(spellInfo, true);
pet->GetCharmInfo()->SetSpellAutocast(spellInfo, true);
caster->ToPlayer()->CharmSpellInitialize();
}
}
void Register() override
{
OnEffectHit += SpellEffectFn(spell_mage_summon_water_elemental::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
// 74396 - Fingers of Frost
class spell_mage_fingers_of_frost : public AuraScript
{
PrepareAuraScript(spell_mage_fingers_of_frost);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_FINGERS_OF_FROST_AURASTATE_AURA });
}
void PrepareProc(ProcEventInfo& eventInfo)
{
if (Spell const* spell = eventInfo.GetProcSpell())
{
bool isTriggered = spell->IsTriggered();
bool isCastPhase = (eventInfo.GetSpellPhaseMask() & PROC_SPELL_PHASE_CAST) != 0;
bool isChanneled = spell->GetSpellInfo()->IsChanneled();
bool prevent = false;
if (isTriggered)
prevent = false;
else if (isChanneled)
prevent = true;
else if (!isCastPhase)
prevent = true;
if (prevent)
PreventDefaultAction();
}
}
void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
GetTarget()->RemoveAurasDueToSpell(SPELL_MAGE_FINGERS_OF_FROST_AURASTATE_AURA);
}
void Register() override
{
DoPrepareProc += AuraProcFn(spell_mage_fingers_of_frost::PrepareProc);
AfterEffectRemove += AuraEffectRemoveFn(spell_mage_fingers_of_frost::OnRemove, EFFECT_0, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL);
}
};
// -31571 - Arcane Potency
class spell_mage_arcane_potency : public AuraScript
{
PrepareAuraScript(spell_mage_arcane_potency);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo(
{
SPELL_MAGE_ARCANE_POTENCY_RANK_1,
SPELL_MAGE_ARCANE_POTENCY_RANK_2
});
}
bool CheckProc(ProcEventInfo& eventInfo)
{
SpellInfo const* spellInfo = eventInfo.GetSpellInfo();
if (!spellInfo)
return false;
// Only proc on Clearcasting or Presence of Mind
if (spellInfo->SpellIconID != MAGE_ICON_CLEARCASTING && spellInfo->SpellIconID != MAGE_ICON_PRESENCE_OF_MIND)
return false;
return true;
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& /*eventInfo*/)
{
PreventDefaultAction();
uint32 spellId = GetSpellInfo()->GetRank() == 1 ? SPELL_MAGE_ARCANE_POTENCY_RANK_1 : SPELL_MAGE_ARCANE_POTENCY_RANK_2;
GetTarget()->CastSpell(GetTarget(), spellId, true, nullptr, aurEff);
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_arcane_potency::CheckProc);
OnEffectProc += AuraEffectProcFn(spell_mage_arcane_potency::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
}
};
// 11129 - Combustion
class spell_mage_combustion : public AuraScript
{
PrepareAuraScript(spell_mage_combustion);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_COMBUSTION_PROC });
}
bool CheckProc(ProcEventInfo& eventInfo)
{
// Do not take charges, add a stack of crit buff
if (!(eventInfo.GetHitMask() & PROC_HIT_CRITICAL))
{
eventInfo.GetActor()->CastSpell(static_cast(nullptr), SPELL_MAGE_COMBUSTION_PROC, true);
return false;
}
return true;
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_combustion::CheckProc);
}
};
// -31656 - Empowered Fire
class spell_mage_empowered_fire : public AuraScript
{
PrepareAuraScript(spell_mage_empowered_fire);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_EMPOWERED_FIRE_PROC });
}
bool CheckProc(ProcEventInfo& eventInfo)
{
SpellInfo const* spellInfo = eventInfo.GetSpellInfo();
if (!spellInfo)
return false;
// Only proc on Ignite
return spellInfo->Id == SPELL_MAGE_IGNITE;
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& /*eventInfo*/)
{
PreventDefaultAction();
Unit* target = GetTarget();
// Calculate mana restored: 2% of base mana (percent value comes from spell 67545 effect 0)
uint32 percent = sSpellMgr->GetSpellInfo(SPELL_MAGE_EMPOWERED_FIRE_PROC)->Effects[EFFECT_0].CalcValue();
int32 mana = int32(CalculatePct(target->GetCreateMana(), percent));
target->CastCustomSpell(SPELL_MAGE_EMPOWERED_FIRE_PROC, SPELLVALUE_BASE_POINT0, mana, target, true, nullptr, aurEff);
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_empowered_fire::CheckProc);
OnEffectProc += AuraEffectProcFn(spell_mage_empowered_fire::HandleProc, EFFECT_0, SPELL_AURA_ADD_FLAT_MODIFIER);
}
};
// 48108 - Hot Streak, 57761 - Fireball!
class spell_mage_gen_extra_effects : public AuraScript
{
PrepareAuraScript(spell_mage_gen_extra_effects);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo(
{
SPELL_MAGE_T8_4P_BONUS,
SPELL_MAGE_T10_2P_BONUS,
SPELL_MAGE_T10_2P_BONUS_EFFECT
});
}
bool CheckProc(ProcEventInfo& eventInfo)
{
Unit* caster = eventInfo.GetActor();
// T8 4P bonus: prevent double proc on Arcane Missiles
if (GetSpellInfo()->Id == SPELL_MAGE_HOT_STREAK_PROC && caster->HasAura(SPELL_MAGE_T8_4P_BONUS))
{
SpellInfo const* spellInfo = eventInfo.GetSpellInfo();
if (spellInfo && spellInfo->SpellFamilyName == SPELLFAMILY_MAGE &&
(spellInfo->SpellFamilyFlags[0] & 0x00000800)) // Arcane Missiles
return false;
}
return true;
}
void HandleProc(ProcEventInfo& eventInfo)
{
Unit* caster = eventInfo.GetActor();
// T10 2P bonus: apply pushing the limit on proc consumption
if (caster->HasAura(SPELL_MAGE_T10_2P_BONUS))
caster->CastSpell(caster, SPELL_MAGE_T10_2P_BONUS_EFFECT, true);
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_gen_extra_effects::CheckProc);
OnProc += AuraProcFn(spell_mage_gen_extra_effects::HandleProc);
}
};
// 56372 - Glyph of Ice Block
class spell_mage_glyph_of_ice_block : public AuraScript
{
PrepareAuraScript(spell_mage_glyph_of_ice_block);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_FROST_NOVA });
}
void HandleProc(AuraEffect const* /*aurEff*/, ProcEventInfo& /*eventInfo*/)
{
PreventDefaultAction();
Player* player = GetTarget()->ToPlayer();
if (!player)
return;
// Reset cooldowns on Frost Nova and all its ranks
SpellInfo const* frostNovaInfo = sSpellMgr->GetSpellInfo(SPELL_MAGE_FROST_NOVA);
if (!frostNovaInfo)
return;
PlayerSpellMap const& spellMap = player->GetSpellMap();
for (auto const& itr : spellMap)
{
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(itr.first);
if (!spellInfo)
continue;
// Frost Nova spell family flags: 0x00000040
if (spellInfo->SpellFamilyName == SPELLFAMILY_MAGE &&
(spellInfo->SpellFamilyFlags[0] & 0x00000040))
{
player->RemoveSpellCooldown(spellInfo->Id, true);
}
}
}
void Register() override
{
OnEffectProc += AuraEffectProcFn(spell_mage_glyph_of_ice_block::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
}
};
// 56374 - Glyph of Icy Veins
class spell_mage_glyph_of_icy_veins : public AuraScript
{
PrepareAuraScript(spell_mage_glyph_of_icy_veins);
void HandleProc(AuraEffect const* /*aurEff*/, ProcEventInfo& /*eventInfo*/)
{
PreventDefaultAction();
Unit* target = GetTarget();
// Remove attack speed slows and haste reducting auras
target->RemoveAurasByType(SPELL_AURA_HASTE_SPELLS);
target->RemoveAurasByType(SPELL_AURA_MOD_DECREASE_SPEED);
}
void Register() override
{
OnEffectProc += AuraEffectProcFn(spell_mage_glyph_of_icy_veins::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
}
};
// 56375 - Glyph of Polymorph
class spell_mage_glyph_of_polymorph : public AuraScript
{
PrepareAuraScript(spell_mage_glyph_of_polymorph);
void HandleProc(AuraEffect const* /*aurEff*/, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
Unit* target = eventInfo.GetProcTarget();
if (!target)
return;
// Remove DoTs from target
target->RemoveAurasByType(SPELL_AURA_PERIODIC_DAMAGE, ObjectGuid::Empty, target->GetAura(32409), true); // SW:D shall not be removed.
target->RemoveAurasByType(SPELL_AURA_PERIODIC_DAMAGE_PERCENT, ObjectGuid::Empty, nullptr, true);
target->RemoveAurasByType(SPELL_AURA_PERIODIC_LEECH, ObjectGuid::Empty, nullptr, true);
}
void Register() override
{
OnEffectProc += AuraEffectProcFn(spell_mage_glyph_of_polymorph::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
}
};
// -44445 - Hot Streak
class spell_mage_hot_streak : public AuraScript
{
PrepareAuraScript(spell_mage_hot_streak);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_HOT_STREAK_PROC });
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
// Non-crit - reset counter
if (!(eventInfo.GetHitMask() & PROC_EX_CRITICAL_HIT))
{
_critStreak = 0;
return;
}
// Crit - increment counter
++_critStreak;
// Two crits in a row - proc Hot Streak if chance succeeds
if (_critStreak >= 2)
{
_critStreak = 0;
if (roll_chance_i(aurEff->GetAmount()))
GetTarget()->CastSpell(GetTarget(), SPELL_MAGE_HOT_STREAK_PROC, true, nullptr, aurEff);
}
}
void Register() override
{
OnEffectProc += AuraEffectProcFn(spell_mage_hot_streak::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
}
private:
uint8 _critStreak = 0;
};
// -11185 - Improved Blizzard
class spell_mage_imp_blizzard : public AuraScript
{
PrepareAuraScript(spell_mage_imp_blizzard);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo(
{
SPELL_MAGE_CHILLED_R1,
SPELL_MAGE_CHILLED_R2,
SPELL_MAGE_CHILLED_R3,
SPELL_MAGE_FINGERS_OF_FROST_AURASTATE_AURA
});
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
uint32 spellId;
switch (GetSpellInfo()->GetRank())
{
case 1: spellId = SPELL_MAGE_CHILLED_R1; break;
case 2: spellId = SPELL_MAGE_CHILLED_R2; break;
case 3: spellId = SPELL_MAGE_CHILLED_R3; break;
default: return;
}
Unit* caster = GetTarget();
if (Unit* target = eventInfo.GetProcTarget())
caster->CastSpell(target, spellId, true, nullptr, aurEff);
// Fingers of Frost: Blizzard chill effects can trigger FoF
if (AuraEffect const* fofTalent = caster->GetAuraEffectOfRankedSpell(SPELL_MAGE_FINGERS_OF_FROST, EFFECT_0))
if (roll_chance_i(fofTalent->GetAmount()))
caster->CastSpell(caster, SPELL_MAGE_FINGERS_OF_FROST_AURASTATE_AURA, true);
}
void Register() override
{
OnEffectProc += AuraEffectProcFn(spell_mage_imp_blizzard::HandleProc, EFFECT_0, SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
}
};
// 61062, 37447 - Improved Mana Gems
class spell_mage_imp_mana_gems : public AuraScript
{
PrepareAuraScript(spell_mage_imp_mana_gems);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_MANA_SURGE });
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& /*eventInfo*/)
{
PreventDefaultAction();
GetTarget()->CastSpell(GetTarget(), SPELL_MAGE_MANA_SURGE, true, nullptr, aurEff);
}
void Register() override
{
OnEffectProc += AuraEffectProcFn(spell_mage_imp_mana_gems::HandleProc, EFFECT_1, SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
}
};
// -44404 - Missile Barrage
class spell_mage_missile_barrage : public AuraScript
{
PrepareAuraScript(spell_mage_missile_barrage);
bool CheckProc(ProcEventInfo& eventInfo)
{
SpellInfo const* spellInfo = eventInfo.GetSpellInfo();
if (!spellInfo)
return false;
// Arcane Blast - full proc chance (100%)
// Arcane Blast spell family flags: 0x20000000
if (spellInfo->SpellFamilyFlags[0] & 0x20000000)
return true;
// Other spells - 50% proc chance
return roll_chance_i(50);
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_missile_barrage::CheckProc);
}
};
// -29441 - Magic Absorption
class spell_mage_magic_absorption : public AuraScript
{
PrepareAuraScript(spell_mage_magic_absorption);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_MAGIC_ABSORPTION_MANA });
}
bool CheckProc(ProcEventInfo& /*eventInfo*/)
{
return GetTarget()->HasActivePowerType(POWER_MANA);
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& /*eventInfo*/)
{
PreventDefaultAction();
Unit* target = GetTarget();
int32 bp = CalculatePct(int32(target->GetMaxPower(POWER_MANA)), aurEff->GetAmount());
target->CastCustomSpell(SPELL_MAGE_MAGIC_ABSORPTION_MANA, SPELLVALUE_BASE_POINT0, bp, target, true, nullptr, aurEff);
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_magic_absorption::CheckProc);
OnEffectProc += AuraEffectProcFn(spell_mage_magic_absorption::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
}
};
// -31641 - Blazing Speed
class spell_mage_blazing_speed : public AuraScript
{
PrepareAuraScript(spell_mage_blazing_speed);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_BLAZING_SPEED });
}
void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
if (Unit* target = eventInfo.GetActionTarget())
target->CastSpell(target, SPELL_MAGE_BLAZING_SPEED, true, nullptr, aurEff);
}
void Register() override
{
OnEffectProc += AuraEffectProcFn(spell_mage_blazing_speed::HandleProc, EFFECT_0, SPELL_AURA_PROC_TRIGGER_SPELL);
}
};
// -5143 - Arcane Missiles
class spell_mage_arcane_missiles : public AuraScript
{
PrepareAuraScript(spell_mage_arcane_missiles);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_T10_2P_BONUS, SPELL_MAGE_T10_2P_BONUS_EFFECT });
}
void OnRemove(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
{
Unit* target = GetTarget();
if (target->HasAura(SPELL_MAGE_T10_2P_BONUS) && _canProcT10)
target->CastSpell(target, SPELL_MAGE_T10_2P_BONUS_EFFECT, true, nullptr, aurEff);
}
void Register() override
{
AfterEffectRemove += AuraEffectRemoveFn(spell_mage_arcane_missiles::OnRemove, EFFECT_1, SPELL_AURA_PERIODIC_TRIGGER_SPELL, AURA_EFFECT_HANDLE_REAL);
}
public:
void AllowT10Proc() { _canProcT10 = true; }
private:
bool _canProcT10 = false;
};
// -31661 - Dragon's Breath
class spell_mage_dragon_breath : public AuraScript
{
PrepareAuraScript(spell_mage_dragon_breath);
bool CheckProc(ProcEventInfo& eventInfo)
{
// Don't proc with Living Bomb explosion
SpellInfo const* spellInfo = eventInfo.GetSpellInfo();
if (spellInfo && spellInfo->SpellIconID == MAGE_ICON_LIVING_BOMB && spellInfo->SpellFamilyName == SPELLFAMILY_MAGE)
return false;
return true;
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_dragon_breath::CheckProc);
}
};
// -44614 - Frostfire Bolt
class spell_mage_frostfire_bolt : public AuraScript
{
PrepareAuraScript(spell_mage_frostfire_bolt);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_PERMAFROST_AURA });
}
void ApplyPermafrost(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
{
if (Unit* caster = GetCaster())
caster->CastSpell(GetTarget(), SPELL_MAGE_PERMAFROST_AURA, true, nullptr, aurEff);
}
void RemovePermafrost(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
GetTarget()->RemoveAurasDueToSpell(SPELL_MAGE_PERMAFROST_AURA);
}
void Register() override
{
AfterEffectApply += AuraEffectApplyFn(spell_mage_frostfire_bolt::ApplyPermafrost, EFFECT_0, SPELL_AURA_MOD_DECREASE_SPEED, AURA_EFFECT_HANDLE_REAL_OR_REAPPLY_MASK);
AfterEffectRemove += AuraEffectRemoveFn(spell_mage_frostfire_bolt::RemovePermafrost, EFFECT_0, SPELL_AURA_MOD_DECREASE_SPEED, AURA_EFFECT_HANDLE_REAL);
}
};
// 45438 - Ice Block
class spell_mage_ice_block : public SpellScript
{
PrepareSpellScript(spell_mage_ice_block);
bool Validate(SpellInfo const* spellInfo) override
{
return spellInfo->ExcludeCasterAuraSpell && ValidateSpellInfo({ static_cast(spellInfo->ExcludeCasterAuraSpell) });
}
void TriggerHypothermia()
{
GetCaster()->CastSpell(GetCaster(), GetSpellInfo()->ExcludeCasterAuraSpell, true);
}
void Register() override
{
AfterHit += SpellHitFn(spell_mage_ice_block::TriggerHypothermia);
}
};
// 12536 - Clearcasting
class spell_mage_clearcasting : public AuraScript
{
PrepareAuraScript(spell_mage_clearcasting);
bool CheckProc(ProcEventInfo& eventInfo)
{
SpellInfo const* spellInfo = eventInfo.GetSpellInfo();
if (!spellInfo)
return true;
// Missile Barrage has priority over Clearcasting for Arcane Missiles
if (spellInfo->SpellFamilyName == SPELLFAMILY_MAGE && (spellInfo->SpellFamilyFlags[0] & 0x800))
if (GetTarget()->HasAura(SPELL_MAGE_MISSILE_BARRAGE_PROC))
return false;
return true;
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_clearcasting::CheckProc);
}
};
// 44401 - Missile Barrage (proc buff)
class spell_mage_missile_barrage_proc : public AuraScript
{
PrepareAuraScript(spell_mage_missile_barrage_proc);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo({ SPELL_MAGE_T10_2P_BONUS, SPELL_MAGE_T8_4P_BONUS, SPELL_MAGE_ARCANE_MISSILES_R1 });
}
bool CheckProc(ProcEventInfo& eventInfo)
{
Unit* caster = eventInfo.GetActor();
// Prevent double proc for Arcane Missiles
if (caster == eventInfo.GetActionTarget())
return false;
// T8 4P bonus: chance to not consume the proc
if (AuraEffect const* aurEff = caster->GetAuraEffect(SPELL_MAGE_T8_4P_BONUS, EFFECT_0))
if (roll_chance_i(aurEff->GetAmount()))
return false;
return true;
}
void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
Unit* caster = GetTarget();
// T10 2P bonus: signal Arcane Missiles to proc the bonus when it ends
if (caster->HasAura(SPELL_MAGE_T10_2P_BONUS))
{
if (Aura* aura = caster->GetAuraOfRankedSpell(SPELL_MAGE_ARCANE_MISSILES_R1))
{
if (spell_mage_arcane_missiles* script = dynamic_cast(aura->GetScriptByName("spell_mage_arcane_missiles")))
script->AllowT10Proc();
}
}
}
void Register() override
{
DoCheckProc += AuraCheckProcFn(spell_mage_missile_barrage_proc::CheckProc);
AfterEffectRemove += AuraEffectRemoveFn(spell_mage_missile_barrage_proc::OnRemove, EFFECT_0, SPELL_AURA_ADD_FLAT_MODIFIER, AURA_EFFECT_HANDLE_REAL);
}
};
void AddSC_mage_spell_scripts()
{
RegisterSpellScript(spell_mage_arcane_blast);
RegisterSpellScript(spell_mage_arcane_missiles);
RegisterSpellScript(spell_mage_arcane_potency);
RegisterSpellScript(spell_mage_blazing_speed);
RegisterSpellScript(spell_mage_burning_determination);
RegisterSpellScript(spell_mage_molten_armor);
RegisterSpellScript(spell_mage_mirror_image);
RegisterSpellScript(spell_mage_burnout);
RegisterSpellScript(spell_mage_burnout_trigger);
RegisterSpellScript(spell_mage_pet_scaling);
RegisterSpellScript(spell_mage_brain_freeze);
RegisterSpellScript(spell_mage_combustion);
RegisterSpellScript(spell_mage_glyph_of_eternal_water);
RegisterSpellScript(spell_mage_combustion_proc);
RegisterSpellScript(spell_mage_dragon_breath);
RegisterSpellScript(spell_mage_empowered_fire);
RegisterSpellScript(spell_mage_gen_extra_effects);
RegisterSpellScript(spell_mage_frostfire_bolt);
RegisterSpellScript(spell_mage_glyph_of_ice_block);
RegisterSpellScript(spell_mage_glyph_of_icy_veins);
RegisterSpellScript(spell_mage_glyph_of_polymorph);
RegisterSpellScript(spell_mage_hot_streak);
RegisterSpellScript(spell_mage_ice_barrier);
RegisterSpellScript(spell_mage_ice_barrier_aura);
RegisterSpellScript(spell_mage_ice_block);
RegisterSpellScript(spell_mage_imp_blizzard);
RegisterSpellScript(spell_mage_imp_mana_gems);
RegisterSpellScript(spell_mage_clearcasting);
RegisterSpellScript(spell_mage_missile_barrage);
RegisterSpellScript(spell_mage_missile_barrage_proc);
RegisterSpellScript(spell_mage_blast_wave);
RegisterSpellScript(spell_mage_cold_snap);
RegisterSpellScript(spell_mage_fire_frost_ward);
RegisterSpellScript(spell_mage_focus_magic);
RegisterSpellScript(spell_mage_ignite);
RegisterSpellScript(spell_mage_living_bomb);
RegisterSpellScript(spell_mage_mana_shield);
RegisterSpellScript(spell_mage_master_of_elements);
RegisterSpellScript(spell_mage_polymorph_cast_visual);
RegisterSpellScript(spell_mage_summon_water_elemental);
RegisterSpellScript(spell_mage_fingers_of_frost);
RegisterSpellScript(spell_mage_magic_absorption);
}