Advertisement
bucur35

DK

Nov 2nd, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 32.01 KB | None | 0 0
  1. #include "ScriptMgr.h"
  2. #include "SpellScript.h"
  3. #include "SpellAuraEffects.h"
  4.  
  5. enum DeathKnightSpells
  6. {
  7.     DK_SPELL_RUNIC_POWER_ENERGIZE               = 49088,
  8.     DK_SPELL_ANTI_MAGIC_SHELL_TALENT            = 51052,
  9.     DK_SPELL_CORPSE_EXPLOSION_TRIGGERED         = 43999,
  10.     DK_SPELL_CORPSE_EXPLOSION_VISUAL            = 51270,
  11.     DK_SPELL_GHOUL_EXPLODE                      = 47496,
  12.     DK_SPELL_SCOURGE_STRIKE_TRIGGERED           = 70890,
  13.     DK_SPELL_BLOOD_BOIL_TRIGGERED               = 65658,
  14.     DK_SPELL_WILL_OF_THE_NECROPOLIS_TALENT_R1   = 49189,
  15.     DK_SPELL_WILL_OF_THE_NECROPOLIS_AURA_R1     = 52284,
  16.     DK_SPELL_BLOOD_PRESENCE                     = 48266,
  17.     DK_SPELL_IMPROVED_BLOOD_PRESENCE_TRIGGERED  = 63611,
  18.     DK_SPELL_UNHOLY_PRESENCE                    = 48265,
  19.     DK_SPELL_IMPROVED_UNHOLY_PRESENCE_TRIGGERED = 63622,
  20.     SPELL_DK_ITEM_T8_MELEE_4P_BONUS             = 64736,
  21.     DK_SPELL_BLACK_ICE_R1                       = 49140,
  22. };
  23.  
  24. // 50462 - Anti-Magic Shell (on raid member)
  25. class spell_dk_anti_magic_shell_raid : public SpellScriptLoader
  26. {
  27.     public:
  28.         spell_dk_anti_magic_shell_raid() : SpellScriptLoader("spell_dk_anti_magic_shell_raid") { }
  29.  
  30.         class spell_dk_anti_magic_shell_raid_AuraScript : public AuraScript
  31.         {
  32.             PrepareAuraScript(spell_dk_anti_magic_shell_raid_AuraScript);
  33.  
  34.             uint32 absorbPct;
  35.  
  36.             bool Load()
  37.             {
  38.                 absorbPct = GetSpellInfo()->Effects[EFFECT_0].CalcValue(GetCaster());
  39.                 return true;
  40.             }
  41.  
  42.             void CalculateAmount(AuraEffect const* /*aurEff*/, int32 & amount, bool & /*canBeRecalculated*/)
  43.             {
  44.                 // TODO: this should absorb limited amount of damage, but no info on calculation formula
  45.                 amount = -1;
  46.             }
  47.  
  48.             void Absorb(AuraEffect* /*aurEff*/, DamageInfo & dmgInfo, uint32 & absorbAmount)
  49.             {
  50.                  absorbAmount = CalculatePct(dmgInfo.GetDamage(), absorbPct);
  51.             }
  52.  
  53.             void Register()
  54.             {
  55.                  DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_dk_anti_magic_shell_raid_AuraScript::CalculateAmount, EFFECT_0, SPELL_AURA_SCHOOL_ABSORB);
  56.                  OnEffectAbsorb += AuraEffectAbsorbFn(spell_dk_anti_magic_shell_raid_AuraScript::Absorb, EFFECT_0);
  57.             }
  58.         };
  59.  
  60.         AuraScript* GetAuraScript() const
  61.         {
  62.             return new spell_dk_anti_magic_shell_raid_AuraScript();
  63.         }
  64. };
  65.  
  66. // 48707 - Anti-Magic Shell (on self)
  67. class spell_dk_anti_magic_shell_self : public SpellScriptLoader
  68. {
  69.     public:
  70.         spell_dk_anti_magic_shell_self() : SpellScriptLoader("spell_dk_anti_magic_shell_self") { }
  71.  
  72.         class spell_dk_anti_magic_shell_self_AuraScript : public AuraScript
  73.         {
  74.             PrepareAuraScript(spell_dk_anti_magic_shell_self_AuraScript);
  75.  
  76.             uint32 absorbPct, hpPct;
  77.             bool Load()
  78.             {
  79.                 absorbPct = GetSpellInfo()->Effects[EFFECT_0].CalcValue(GetCaster());
  80.                 hpPct = GetSpellInfo()->Effects[EFFECT_1].CalcValue(GetCaster());
  81.                 return true;
  82.             }
  83.  
  84.             bool Validate(SpellInfo const* /*spellEntry*/)
  85.             {
  86.                 if (!sSpellMgr->GetSpellInfo(DK_SPELL_RUNIC_POWER_ENERGIZE))
  87.                     return false;
  88.                 return true;
  89.             }
  90.  
  91.             void CalculateAmount(AuraEffect const* /*aurEff*/, int32 & amount, bool & /*canBeRecalculated*/)
  92.             {
  93.                 amount = GetCaster()->CountPctFromMaxHealth(hpPct);
  94.             }
  95.  
  96.             void Absorb(AuraEffect* /*aurEff*/, DamageInfo & dmgInfo, uint32 & absorbAmount)
  97.             {
  98.                 absorbAmount = std::min(CalculatePct(dmgInfo.GetDamage(), absorbPct), GetTarget()->CountPctFromMaxHealth(hpPct));
  99.             }
  100.  
  101.             void Trigger(AuraEffect* aurEff, DamageInfo & /*dmgInfo*/, uint32 & absorbAmount)
  102.             {
  103.                 Unit* target = GetTarget();
  104.                 // damage absorbed by Anti-Magic Shell energizes the DK with additional runic power.
  105.                 // This, if I'm not mistaken, shows that we get back ~20% of the absorbed damage as runic power.
  106.                 int32 bp = absorbAmount * 2 / 10;
  107.                 target->CastCustomSpell(target, DK_SPELL_RUNIC_POWER_ENERGIZE, &bp, NULL, NULL, true, NULL, aurEff);
  108.             }
  109.  
  110.             void Register()
  111.             {
  112.                  DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_dk_anti_magic_shell_self_AuraScript::CalculateAmount, EFFECT_0, SPELL_AURA_SCHOOL_ABSORB);
  113.                  OnEffectAbsorb += AuraEffectAbsorbFn(spell_dk_anti_magic_shell_self_AuraScript::Absorb, EFFECT_0);
  114.                  AfterEffectAbsorb += AuraEffectAbsorbFn(spell_dk_anti_magic_shell_self_AuraScript::Trigger, EFFECT_0);
  115.             }
  116.         };
  117.  
  118.         AuraScript* GetAuraScript() const
  119.         {
  120.             return new spell_dk_anti_magic_shell_self_AuraScript();
  121.         }
  122. };
  123.  
  124. // 50461 - Anti-Magic Zone
  125. class spell_dk_anti_magic_zone : public SpellScriptLoader
  126. {
  127.     public:
  128.         spell_dk_anti_magic_zone() : SpellScriptLoader("spell_dk_anti_magic_zone") { }
  129.  
  130.         class spell_dk_anti_magic_zone_AuraScript : public AuraScript
  131.         {
  132.             PrepareAuraScript(spell_dk_anti_magic_zone_AuraScript);
  133.  
  134.             uint32 absorbPct;
  135.  
  136.             bool Load()
  137.             {
  138.                 absorbPct = GetSpellInfo()->Effects[EFFECT_0].CalcValue(GetCaster());
  139.                 return true;
  140.             }
  141.  
  142.             bool Validate(SpellInfo const* /*spellEntry*/)
  143.             {
  144.                 if (!sSpellMgr->GetSpellInfo(DK_SPELL_ANTI_MAGIC_SHELL_TALENT))
  145.                     return false;
  146.                 return true;
  147.             }
  148.  
  149.             void CalculateAmount(AuraEffect const* /*aurEff*/, int32 & amount, bool & /*canBeRecalculated*/)
  150.             {
  151.                 SpellInfo const* talentSpell = sSpellMgr->GetSpellInfo(DK_SPELL_ANTI_MAGIC_SHELL_TALENT);
  152.                 amount = talentSpell->Effects[EFFECT_0].CalcValue(GetCaster());
  153.                 if (Player* player = GetCaster()->ToPlayer())
  154.                      amount += int32(2 * player->GetTotalAttackPowerValue(BASE_ATTACK));
  155.             }
  156.  
  157.             void Absorb(AuraEffect* /*aurEff*/, DamageInfo & dmgInfo, uint32 & absorbAmount)
  158.             {
  159.                  absorbAmount = CalculatePct(dmgInfo.GetDamage(), absorbPct);
  160.             }
  161.  
  162.             void Register()
  163.             {
  164.                  DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_dk_anti_magic_zone_AuraScript::CalculateAmount, EFFECT_0, SPELL_AURA_SCHOOL_ABSORB);
  165.                  OnEffectAbsorb += AuraEffectAbsorbFn(spell_dk_anti_magic_zone_AuraScript::Absorb, EFFECT_0);
  166.             }
  167.         };
  168.  
  169.         AuraScript* GetAuraScript() const
  170.         {
  171.             return new spell_dk_anti_magic_zone_AuraScript();
  172.         }
  173. };
  174.  
  175. // 49158 Corpse Explosion (51325, 51326, 51327, 51328)
  176. class spell_dk_corpse_explosion : public SpellScriptLoader
  177. {
  178.     public:
  179.         spell_dk_corpse_explosion() : SpellScriptLoader("spell_dk_corpse_explosion") { }
  180.  
  181.         class spell_dk_corpse_explosion_SpellScript : public SpellScript
  182.         {
  183.             PrepareSpellScript(spell_dk_corpse_explosion_SpellScript);
  184.  
  185.             bool Validate(SpellInfo const* /*spellEntry*/)
  186.             {
  187.                 if (!sSpellMgr->GetSpellInfo(DK_SPELL_CORPSE_EXPLOSION_TRIGGERED) || !sSpellMgr->GetSpellInfo(DK_SPELL_GHOUL_EXPLODE))
  188.                     return false;
  189.                 if (!sSpellMgr->GetSpellInfo(DK_SPELL_CORPSE_EXPLOSION_VISUAL))
  190.                     return false;
  191.                 return true;
  192.             }
  193.  
  194.             void HandleDummy(SpellEffIndex /*effIndex*/)
  195.             {
  196.                 if (Unit* unitTarget = GetHitUnit())
  197.                 {
  198.                     int32 bp = 0;
  199.                     if (unitTarget->isAlive())  // Living ghoul as a target
  200.                     {
  201.                         bp = int32(unitTarget->CountPctFromMaxHealth(25));
  202.                         unitTarget->CastCustomSpell(unitTarget, DK_SPELL_GHOUL_EXPLODE, &bp, NULL, NULL, false);
  203.                     }
  204.                     else                        // Some corpse
  205.                     {
  206.                         bp = GetEffectValue();
  207.                         GetCaster()->CastCustomSpell(unitTarget, GetSpellInfo()->Effects[EFFECT_1].CalcValue(), &bp, NULL, NULL, true);
  208.                         // Corpse Explosion (Suicide)
  209.                         unitTarget->CastSpell(unitTarget, DK_SPELL_CORPSE_EXPLOSION_TRIGGERED, true);
  210.                     }
  211.                     // Set corpse look
  212.                     GetCaster()->CastSpell(unitTarget, DK_SPELL_CORPSE_EXPLOSION_VISUAL, true);
  213.                 }
  214.             }
  215.  
  216.             void Register()
  217.             {
  218.                 OnEffectHitTarget += SpellEffectFn(spell_dk_corpse_explosion_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
  219.             }
  220.         };
  221.  
  222.         SpellScript* GetSpellScript() const
  223.         {
  224.             return new spell_dk_corpse_explosion_SpellScript();
  225.         }
  226. };
  227.  
  228. // 47496 - Explode, Ghoul spell for Corpse Explosion
  229. class spell_dk_ghoul_explode : public SpellScriptLoader
  230. {
  231.     public:
  232.         spell_dk_ghoul_explode() : SpellScriptLoader("spell_dk_ghoul_explode") { }
  233.  
  234.         class spell_dk_ghoul_explode_SpellScript : public SpellScript
  235.         {
  236.             PrepareSpellScript(spell_dk_ghoul_explode_SpellScript);
  237.  
  238.             bool Validate(SpellInfo const* /*spellEntry*/)
  239.             {
  240.                 if (!sSpellMgr->GetSpellInfo(DK_SPELL_CORPSE_EXPLOSION_TRIGGERED))
  241.                     return false;
  242.                 return true;
  243.             }
  244.  
  245.             void Suicide(SpellEffIndex /*effIndex*/)
  246.             {
  247.                 if (Unit* unitTarget = GetHitUnit())
  248.                 {
  249.                     // Corpse Explosion (Suicide)
  250.                     unitTarget->CastSpell(unitTarget, DK_SPELL_CORPSE_EXPLOSION_TRIGGERED, true);
  251.                 }
  252.             }
  253.  
  254.             void Register()
  255.             {
  256.                 OnEffectHitTarget += SpellEffectFn(spell_dk_ghoul_explode_SpellScript::Suicide, EFFECT_1, SPELL_EFFECT_SCHOOL_DAMAGE);
  257.             }
  258.         };
  259.  
  260.         SpellScript* GetSpellScript() const
  261.         {
  262.             return new spell_dk_ghoul_explode_SpellScript();
  263.         }
  264. };
  265.  
  266. class spell_dk_death_gate : public SpellScriptLoader
  267. {
  268.     public:
  269.         spell_dk_death_gate() : SpellScriptLoader("spell_dk_death_gate") {}
  270.  
  271.         class spell_dk_death_gate_SpellScript : public SpellScript
  272.         {
  273.             PrepareSpellScript(spell_dk_death_gate_SpellScript);
  274.  
  275.             SpellCastResult CheckClass()
  276.             {
  277.                 if (GetCaster()->getClass() != CLASS_DEATH_KNIGHT)
  278.                 {
  279.                     SetCustomCastResultMessage(SPELL_CUSTOM_ERROR_MUST_BE_DEATH_KNIGHT);
  280.                     return SPELL_FAILED_CUSTOM_ERROR;
  281.                 }
  282.  
  283.                 return SPELL_CAST_OK;
  284.             }
  285.  
  286.             void HandleScript(SpellEffIndex effIndex)
  287.             {
  288.                 PreventHitDefaultEffect(effIndex);
  289.                 if (Unit* target = GetHitUnit())
  290.                     target->CastSpell(target, GetEffectValue(), false);
  291.             }
  292.  
  293.             void Register()
  294.             {
  295.                 OnCheckCast += SpellCheckCastFn(spell_dk_death_gate_SpellScript::CheckClass);
  296.                 OnEffectHitTarget += SpellEffectFn(spell_dk_death_gate_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
  297.             }
  298.         };
  299.  
  300.         SpellScript* GetSpellScript() const
  301.         {
  302.             return new spell_dk_death_gate_SpellScript();
  303.         }
  304. };
  305.  
  306. class spell_dk_death_pact : public SpellScriptLoader
  307. {
  308.     public:
  309.         spell_dk_death_pact() : SpellScriptLoader("spell_dk_death_pact") { }
  310.  
  311.         class spell_dk_death_pact_SpellScript : public SpellScript
  312.         {
  313.             PrepareSpellScript(spell_dk_death_pact_SpellScript);
  314.  
  315.             SpellCastResult CheckCast()
  316.             {
  317.                 // Check if we have valid targets, otherwise skip spell casting here
  318.                 if (Player* player = GetCaster()->ToPlayer())
  319.                     for (Unit::ControlList::const_iterator itr = player->m_Controlled.begin(); itr != player->m_Controlled.end(); ++itr)
  320.                         if (Creature* undeadPet = (*itr)->ToCreature())
  321.                             if (undeadPet->isAlive() &&
  322.                                 undeadPet->GetOwnerGUID() == player->GetGUID() &&
  323.                                 undeadPet->GetCreatureType() == CREATURE_TYPE_UNDEAD &&
  324.                                 undeadPet->IsWithinDist(player, 100.0f, false))
  325.                                 return SPELL_CAST_OK;
  326.  
  327.                 return SPELL_FAILED_NO_PET;
  328.             }
  329.  
  330.             void FilterTargets(std::list<WorldObject*>& unitList)
  331.             {
  332.                 Unit* unit_to_add = NULL;
  333.                 for (std::list<WorldObject*>::iterator itr = unitList.begin(); itr != unitList.end(); ++itr)
  334.                 {
  335.                     if (Unit* unit = (*itr)->ToUnit())
  336.                     if (unit->GetOwnerGUID() == GetCaster()->GetGUID() && unit->GetCreatureType() == CREATURE_TYPE_UNDEAD)
  337.                     {
  338.                         unit_to_add = unit;
  339.                         break;
  340.                     }
  341.                 }
  342.  
  343.                 unitList.clear();
  344.                 if (unit_to_add)
  345.                     unitList.push_back(unit_to_add);
  346.             }
  347.  
  348.             void Register()
  349.             {
  350.                 OnCheckCast += SpellCheckCastFn(spell_dk_death_pact_SpellScript::CheckCast);
  351.                 OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(spell_dk_death_pact_SpellScript::FilterTargets, EFFECT_1, TARGET_UNIT_DEST_AREA_ALLY);
  352.             }
  353.         };
  354.  
  355.         SpellScript* GetSpellScript() const
  356.         {
  357.             return new spell_dk_death_pact_SpellScript();
  358.         }
  359. };
  360.  
  361. // 55090 Scourge Strike (55265, 55270, 55271)
  362. class spell_dk_scourge_strike : public SpellScriptLoader
  363. {
  364.     public:
  365.         spell_dk_scourge_strike() : SpellScriptLoader("spell_dk_scourge_strike") { }
  366.  
  367.         class spell_dk_scourge_strike_SpellScript : public SpellScript
  368.         {
  369.             PrepareSpellScript(spell_dk_scourge_strike_SpellScript);
  370.             float multiplier;
  371.  
  372.             bool Load()
  373.             {
  374.                 multiplier = 1.0f;
  375.                 return true;
  376.             }
  377.  
  378.             bool Validate(SpellInfo const* /*spellEntry*/)
  379.             {
  380.                 if (!sSpellMgr->GetSpellInfo(DK_SPELL_SCOURGE_STRIKE_TRIGGERED))
  381.                     return false;
  382.                 return true;
  383.             }
  384.  
  385.             void HandleDummy(SpellEffIndex /*effIndex*/)
  386.             {
  387.                 Unit* caster = GetCaster();
  388.                 if (Unit* unitTarget = GetHitUnit())
  389.                 {
  390.                     multiplier = (GetEffectValue() * unitTarget->GetDiseasesByCaster(caster->GetGUID()) / 100.f);
  391.                     // Death Knight T8 Melee 4P Bonus
  392.                     if (AuraEffect const* aurEff = caster->GetAuraEffect(SPELL_DK_ITEM_T8_MELEE_4P_BONUS, EFFECT_0))
  393.                         AddPct(multiplier, aurEff->GetAmount());
  394.                 }
  395.             }
  396.  
  397.             void HandleAfterHit()
  398.             {
  399.                 Unit* caster = GetCaster();
  400.                 if (Unit* unitTarget = GetHitUnit())
  401.                 {
  402.                     int32 bp = GetHitDamage() * multiplier;
  403.  
  404.                     if (AuraEffect* aurEff = caster->GetAuraEffectOfRankedSpell(DK_SPELL_BLACK_ICE_R1, EFFECT_0))
  405.                         AddPct(bp, aurEff->GetAmount());
  406.  
  407.                     caster->CastCustomSpell(unitTarget, DK_SPELL_SCOURGE_STRIKE_TRIGGERED, &bp, NULL, NULL, true);
  408.                 }
  409.             }
  410.  
  411.             void Register()
  412.             {
  413.                 OnEffectHitTarget += SpellEffectFn(spell_dk_scourge_strike_SpellScript::HandleDummy, EFFECT_2, SPELL_EFFECT_DUMMY);
  414.                 AfterHit += SpellHitFn(spell_dk_scourge_strike_SpellScript::HandleAfterHit);
  415.             }
  416.         };
  417.  
  418.         SpellScript* GetSpellScript() const
  419.         {
  420.             return new spell_dk_scourge_strike_SpellScript();
  421.         }
  422. };
  423.  
  424. // 49145 - Spell Deflection
  425. class spell_dk_spell_deflection : public SpellScriptLoader
  426. {
  427.     public:
  428.         spell_dk_spell_deflection() : SpellScriptLoader("spell_dk_spell_deflection") { }
  429.  
  430.         class spell_dk_spell_deflection_AuraScript : public AuraScript
  431.         {
  432.             PrepareAuraScript(spell_dk_spell_deflection_AuraScript);
  433.  
  434.             uint32 absorbPct;
  435.  
  436.             bool Load()
  437.             {
  438.                 absorbPct = GetSpellInfo()->Effects[EFFECT_0].CalcValue(GetCaster());
  439.                 return true;
  440.             }
  441.  
  442.             void CalculateAmount(AuraEffect const* /*aurEff*/, int32 & amount, bool & /*canBeRecalculated*/)
  443.             {
  444.                 // Set absorbtion amount to unlimited
  445.                 amount = -1;
  446.             }
  447.  
  448.             void Absorb(AuraEffect* /*aurEff*/, DamageInfo & dmgInfo, uint32 & absorbAmount)
  449.             {
  450.                 // You have a chance equal to your Parry chance
  451.                 if ((dmgInfo.GetDamageType() == SPELL_DIRECT_DAMAGE) && roll_chance_f(GetTarget()->GetUnitParryChance()))
  452.                     absorbAmount = CalculatePct(dmgInfo.GetDamage(), absorbPct);
  453.             }
  454.  
  455.             void Register()
  456.             {
  457.                  DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_dk_spell_deflection_AuraScript::CalculateAmount, EFFECT_0, SPELL_AURA_SCHOOL_ABSORB);
  458.                  OnEffectAbsorb += AuraEffectAbsorbFn(spell_dk_spell_deflection_AuraScript::Absorb, EFFECT_0);
  459.             }
  460.         };
  461.  
  462.         AuraScript* GetAuraScript() const
  463.         {
  464.             return new spell_dk_spell_deflection_AuraScript();
  465.         }
  466. };
  467.  
  468. // 48721 Blood Boil
  469. class spell_dk_blood_boil : public SpellScriptLoader
  470. {
  471.     public:
  472.         spell_dk_blood_boil() : SpellScriptLoader("spell_dk_blood_boil") { }
  473.  
  474.         class spell_dk_blood_boil_SpellScript : public SpellScript
  475.         {
  476.             PrepareSpellScript(spell_dk_blood_boil_SpellScript);
  477.  
  478.             bool Validate(SpellInfo const* /*spellEntry*/)
  479.             {
  480.                 if (!sSpellMgr->GetSpellInfo(DK_SPELL_BLOOD_BOIL_TRIGGERED))
  481.                     return false;
  482.                 return true;
  483.             }
  484.  
  485.             bool Load()
  486.             {
  487.                 _executed = false;
  488.                 return GetCaster()->GetTypeId() == TYPEID_PLAYER && GetCaster()->getClass() == CLASS_DEATH_KNIGHT;
  489.             }
  490.  
  491.             void HandleAfterHit()
  492.             {
  493.                 if (_executed || !GetHitUnit())
  494.                     return;
  495.  
  496.                 _executed = true;
  497.                 GetCaster()->CastSpell(GetCaster(), DK_SPELL_BLOOD_BOIL_TRIGGERED, true);
  498.             }
  499.  
  500.             void Register()
  501.             {
  502.                 AfterHit += SpellHitFn(spell_dk_blood_boil_SpellScript::HandleAfterHit);
  503.             }
  504.  
  505.             bool _executed;
  506.         };
  507.  
  508.         SpellScript* GetSpellScript() const
  509.         {
  510.             return new spell_dk_blood_boil_SpellScript();
  511.         }
  512. };
  513.  
  514. // 52284 - Will of the Necropolis
  515. class spell_dk_will_of_the_necropolis : public SpellScriptLoader
  516. {
  517.     public:
  518.         spell_dk_will_of_the_necropolis() : SpellScriptLoader("spell_dk_will_of_the_necropolis") { }
  519.  
  520.         class spell_dk_will_of_the_necropolis_AuraScript : public AuraScript
  521.         {
  522.             PrepareAuraScript(spell_dk_will_of_the_necropolis_AuraScript);
  523.  
  524.             bool Validate(SpellInfo const* spellEntry)
  525.             {
  526.                 // can't use other spell than will of the necropolis due to spell_ranks dependency
  527.                 if (sSpellMgr->GetFirstSpellInChain(DK_SPELL_WILL_OF_THE_NECROPOLIS_AURA_R1) != sSpellMgr->GetFirstSpellInChain(spellEntry->Id))
  528.                     return false;
  529.  
  530.                 uint8 rank = sSpellMgr->GetSpellRank(spellEntry->Id);
  531.                 if (!sSpellMgr->GetSpellWithRank(DK_SPELL_WILL_OF_THE_NECROPOLIS_TALENT_R1, rank, true))
  532.                     return false;
  533.  
  534.                 return true;
  535.             }
  536.  
  537.             uint32 absorbPct;
  538.  
  539.             bool Load()
  540.             {
  541.                 absorbPct = GetSpellInfo()->Effects[EFFECT_0].CalcValue(GetCaster());
  542.                 return true;
  543.             }
  544.  
  545.             void CalculateAmount(AuraEffect const* /*aurEff*/, int32 & amount, bool & /*canBeRecalculated*/)
  546.             {
  547.                 // Set absorbtion amount to unlimited
  548.                 amount = -1;
  549.             }
  550.  
  551.             void Absorb(AuraEffect* /*aurEff*/, DamageInfo & dmgInfo, uint32 & absorbAmount)
  552.             {
  553.                 // min pct of hp is stored in effect 0 of talent spell
  554.                 uint32 rank = sSpellMgr->GetSpellRank(GetSpellInfo()->Id);
  555.                 SpellInfo const* talentProto = sSpellMgr->GetSpellInfo(sSpellMgr->GetSpellWithRank(DK_SPELL_WILL_OF_THE_NECROPOLIS_TALENT_R1, rank));
  556.  
  557.                 int32 remainingHp = int32(GetTarget()->GetHealth() - dmgInfo.GetDamage());
  558.                 int32 minHp = int32(GetTarget()->CountPctFromMaxHealth(talentProto->Effects[EFFECT_0].CalcValue(GetCaster())));
  559.  
  560.                 // Damage that would take you below [effect0] health or taken while you are at [effect0]
  561.                 if (remainingHp < minHp)
  562.                     absorbAmount = CalculatePct(dmgInfo.GetDamage(), absorbPct);
  563.             }
  564.  
  565.             void Register()
  566.             {
  567.                  DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_dk_will_of_the_necropolis_AuraScript::CalculateAmount, EFFECT_0, SPELL_AURA_SCHOOL_ABSORB);
  568.                  OnEffectAbsorb += AuraEffectAbsorbFn(spell_dk_will_of_the_necropolis_AuraScript::Absorb, EFFECT_0);
  569.             }
  570.         };
  571.  
  572.         AuraScript* GetAuraScript() const
  573.         {
  574.             return new spell_dk_will_of_the_necropolis_AuraScript();
  575.         }
  576. };
  577.  
  578. // 50365, 50371 Improved Blood Presence
  579. class spell_dk_improved_blood_presence : public SpellScriptLoader
  580. {
  581. public:
  582.     spell_dk_improved_blood_presence() : SpellScriptLoader("spell_dk_improved_blood_presence") { }
  583.  
  584.     class spell_dk_improved_blood_presence_AuraScript : public AuraScript
  585.     {
  586.         PrepareAuraScript(spell_dk_improved_blood_presence_AuraScript);
  587.  
  588.         bool Validate(SpellInfo const* /*entry*/)
  589.         {
  590.             if (!sSpellMgr->GetSpellInfo(DK_SPELL_BLOOD_PRESENCE) || !sSpellMgr->GetSpellInfo(DK_SPELL_IMPROVED_BLOOD_PRESENCE_TRIGGERED))
  591.                 return false;
  592.             return true;
  593.         }
  594.  
  595.         void HandleEffectApply(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
  596.         {
  597.             Unit* target = GetTarget();
  598.             if (!target->HasAura(DK_SPELL_BLOOD_PRESENCE) && !target->HasAura(DK_SPELL_IMPROVED_BLOOD_PRESENCE_TRIGGERED))
  599.             {
  600.                 int32 basePoints1 = aurEff->GetAmount();
  601.                 target->CastCustomSpell(target, DK_SPELL_IMPROVED_BLOOD_PRESENCE_TRIGGERED, NULL, &basePoints1, NULL, true, 0, aurEff);
  602.             }
  603.         }
  604.  
  605.         void HandleEffectRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
  606.         {
  607.             Unit* target = GetTarget();
  608.             if (!target->HasAura(DK_SPELL_BLOOD_PRESENCE))
  609.                 target->RemoveAura(DK_SPELL_IMPROVED_BLOOD_PRESENCE_TRIGGERED);
  610.         }
  611.  
  612.         void Register()
  613.         {
  614.             AfterEffectApply += AuraEffectApplyFn(spell_dk_improved_blood_presence_AuraScript::HandleEffectApply, EFFECT_0, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL);
  615.             AfterEffectRemove += AuraEffectRemoveFn(spell_dk_improved_blood_presence_AuraScript::HandleEffectRemove, EFFECT_0, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL);
  616.         }
  617.     };
  618.  
  619.     AuraScript* GetAuraScript() const
  620.     {
  621.         return new spell_dk_improved_blood_presence_AuraScript();
  622.     }
  623. };
  624.  
  625. // 50391, 50392 Improved Unholy Presence
  626. class spell_dk_improved_unholy_presence : public SpellScriptLoader
  627. {
  628. public:
  629.     spell_dk_improved_unholy_presence() : SpellScriptLoader("spell_dk_improved_unholy_presence") { }
  630.  
  631.     class spell_dk_improved_unholy_presence_AuraScript : public AuraScript
  632.     {
  633.         PrepareAuraScript(spell_dk_improved_unholy_presence_AuraScript);
  634.  
  635.         bool Validate(SpellInfo const* /*entry*/)
  636.         {
  637.             if (!sSpellMgr->GetSpellInfo(DK_SPELL_UNHOLY_PRESENCE) || !sSpellMgr->GetSpellInfo(DK_SPELL_IMPROVED_UNHOLY_PRESENCE_TRIGGERED))
  638.                 return false;
  639.             return true;
  640.         }
  641.  
  642.         void HandleEffectApply(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
  643.         {
  644.             Unit* target = GetTarget();
  645.             if (target->HasAura(DK_SPELL_UNHOLY_PRESENCE) && !target->HasAura(DK_SPELL_IMPROVED_UNHOLY_PRESENCE_TRIGGERED))
  646.             {
  647.                 // Not listed as any effect, only base points set in dbc
  648.                 int32 basePoints0 = aurEff->GetSpellInfo()->Effects[EFFECT_1].CalcValue();
  649.                 target->CastCustomSpell(target, DK_SPELL_IMPROVED_UNHOLY_PRESENCE_TRIGGERED, &basePoints0, &basePoints0, &basePoints0, true, 0, aurEff);
  650.             }
  651.         }
  652.  
  653.         void HandleEffectRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
  654.         {
  655.             GetTarget()->RemoveAura(DK_SPELL_IMPROVED_UNHOLY_PRESENCE_TRIGGERED);
  656.         }
  657.  
  658.         void Register()
  659.         {
  660.             AfterEffectApply += AuraEffectApplyFn(spell_dk_improved_unholy_presence_AuraScript::HandleEffectApply, EFFECT_0, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL);
  661.             AfterEffectRemove += AuraEffectRemoveFn(spell_dk_improved_unholy_presence_AuraScript::HandleEffectRemove, EFFECT_0, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL);
  662.         }
  663.     };
  664.  
  665.     AuraScript* GetAuraScript() const
  666.     {
  667.         return new spell_dk_improved_unholy_presence_AuraScript();
  668.     }
  669. };
  670.  
  671. enum DeathStrike
  672. {
  673.     ICON_ID_IMPROVED_DEATH_STRIKE   = 2751,
  674.     SPELL_DEATH_STRIKE_HEAL         = 45470,
  675. };
  676.  
  677. class spell_dk_death_strike : public SpellScriptLoader
  678. {
  679.     public:
  680.         spell_dk_death_strike() : SpellScriptLoader("spell_dk_death_strike") { }
  681.  
  682.         class spell_dk_death_strike_SpellScript : public SpellScript
  683.         {
  684.             PrepareSpellScript(spell_dk_death_strike_SpellScript);
  685.  
  686.             bool Validate(SpellInfo const* /*SpellEntry*/)
  687.             {
  688.                 if (!sSpellMgr->GetSpellInfo(SPELL_DEATH_STRIKE_HEAL))
  689.                     return false;
  690.                 return true;
  691.             }
  692.  
  693.             void HandleDummy(SpellEffIndex /* effIndex */)
  694.             {
  695.                 Unit* caster = GetCaster();
  696.                 if (Unit* target = GetHitUnit())
  697.                 {
  698.                     uint32 count = target->GetDiseasesByCaster(caster->GetGUID());
  699.                     int32 bp = int32(count * caster->CountPctFromMaxHealth(int32(GetSpellInfo()->Effects[EFFECT_0].DamageMultiplier)));
  700.                     // Improved Death Strike
  701.                     if (AuraEffect const* aurEff = caster->GetAuraEffect(SPELL_AURA_ADD_PCT_MODIFIER, SPELLFAMILY_DEATHKNIGHT, ICON_ID_IMPROVED_DEATH_STRIKE, 0))
  702.                         AddPct(bp, caster->CalculateSpellDamage(caster, aurEff->GetSpellInfo(), 2));
  703.                     caster->CastCustomSpell(caster, SPELL_DEATH_STRIKE_HEAL, &bp, NULL, NULL, false);
  704.                 }
  705.             }
  706.  
  707.             void Register()
  708.             {
  709.                 OnEffectHitTarget += SpellEffectFn(spell_dk_death_strike_SpellScript::HandleDummy, EFFECT_2, SPELL_EFFECT_DUMMY);
  710.             }
  711.  
  712.         };
  713.  
  714.         SpellScript* GetSpellScript() const
  715.         {
  716.             return new spell_dk_death_strike_SpellScript();
  717.         }
  718. };
  719.  
  720. enum DeathCoil
  721. {
  722.     SPELL_DEATH_COIL_DAMAGE     = 47632,
  723.     SPELL_DEATH_COIL_HEAL       = 47633,
  724.     SPELL_SIGIL_VENGEFUL_HEART  = 64962,
  725. };
  726.  
  727. class spell_dk_death_coil : public SpellScriptLoader
  728. {
  729.     public:
  730.         spell_dk_death_coil() : SpellScriptLoader("spell_dk_death_coil") { }
  731.  
  732.         class spell_dk_death_coil_SpellScript : public SpellScript
  733.         {
  734.             PrepareSpellScript(spell_dk_death_coil_SpellScript);
  735.  
  736.             bool Validate(SpellInfo const* /*spell*/)
  737.             {
  738.                 if (!sSpellMgr->GetSpellInfo(SPELL_DEATH_COIL_DAMAGE) || !sSpellMgr->GetSpellInfo(SPELL_DEATH_COIL_HEAL))
  739.                     return false;
  740.                 return true;
  741.             }
  742.  
  743.             void HandleDummy(SpellEffIndex /*effIndex*/)
  744.             {
  745.                 int32 damage = GetEffectValue();
  746.                 Unit* caster = GetCaster();
  747.                 if (Unit* target = GetHitUnit())
  748.                 {
  749.                     if (caster->IsFriendlyTo(target))
  750.                     {
  751.                         int32 bp = int32(damage * 1.5f);
  752.                         caster->CastCustomSpell(target, SPELL_DEATH_COIL_HEAL, &bp, NULL, NULL, true);
  753.                     }
  754.                     else
  755.                     {
  756.                         if (AuraEffect const* auraEffect = caster->GetAuraEffect(SPELL_SIGIL_VENGEFUL_HEART, EFFECT_1))
  757.                             damage += auraEffect->GetBaseAmount();
  758.                         caster->CastCustomSpell(target, SPELL_DEATH_COIL_DAMAGE, &damage, NULL, NULL, true);
  759.                     }
  760.                 }
  761.             }
  762.  
  763.             SpellCastResult CheckCast()
  764.             {
  765.                 Unit* caster = GetCaster();
  766.                 if (Unit* target = GetExplTargetUnit())
  767.                 {
  768.                     if (!caster->IsFriendlyTo(target) && !caster->isInFront(target))
  769.                         return SPELL_FAILED_UNIT_NOT_INFRONT;
  770.  
  771.                     if (target->IsFriendlyTo(caster) && target->GetCreatureType() != CREATURE_TYPE_UNDEAD)
  772.                         return SPELL_FAILED_BAD_TARGETS;
  773.                 }
  774.                 else
  775.                     return SPELL_FAILED_BAD_TARGETS;
  776.  
  777.                 return SPELL_CAST_OK;
  778.             }
  779.  
  780.             void Register()
  781.             {
  782.                 OnCheckCast += SpellCheckCastFn(spell_dk_death_coil_SpellScript::CheckCast);
  783.                 OnEffectHitTarget += SpellEffectFn(spell_dk_death_coil_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
  784.             }
  785.  
  786.         };
  787.  
  788.         SpellScript* GetSpellScript() const
  789.         {
  790.             return new spell_dk_death_coil_SpellScript();
  791.         }
  792. };
  793.  
  794. class spell_dk_death_grip : public SpellScriptLoader
  795. {
  796.     public:
  797.         spell_dk_death_grip() : SpellScriptLoader("spell_dk_death_grip") { }
  798.  
  799.         class spell_dk_death_grip_SpellScript : public SpellScript
  800.         {
  801.             PrepareSpellScript(spell_dk_death_grip_SpellScript);
  802.  
  803.             void HandleDummy(SpellEffIndex /*effIndex*/)
  804.             {
  805.                 int32 damage = GetEffectValue();
  806.                 Position const* pos = GetExplTargetDest();
  807.                 if (Unit* target = GetHitUnit())
  808.                 {
  809.                     if (!target->HasAuraType(SPELL_AURA_DEFLECT_SPELLS)) // Deterrence
  810.                         target->CastSpell(pos->GetPositionX(), pos->GetPositionY(), pos->GetPositionZ(), damage, true);
  811.                 }
  812.             }
  813.  
  814.             void Register()
  815.             {
  816.                 OnEffectHitTarget += SpellEffectFn(spell_dk_death_grip_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
  817.             }
  818.  
  819.         };
  820.  
  821.         SpellScript* GetSpellScript() const
  822.         {
  823.             return new spell_dk_death_grip_SpellScript();
  824.         }
  825. };
  826.  
  827. void AddSC_deathknight_spell_scripts()
  828. {
  829.     new spell_dk_anti_magic_shell_raid();
  830.     new spell_dk_anti_magic_shell_self();
  831.     new spell_dk_anti_magic_zone();
  832.     new spell_dk_corpse_explosion();
  833.     new spell_dk_ghoul_explode();
  834.     new spell_dk_death_gate();
  835.     new spell_dk_death_pact();
  836.     new spell_dk_scourge_strike();
  837.     new spell_dk_spell_deflection();
  838.     new spell_dk_blood_boil();
  839.     new spell_dk_will_of_the_necropolis();
  840.     new spell_dk_improved_blood_presence();
  841.     new spell_dk_improved_unholy_presence();
  842.     new spell_dk_death_strike();
  843.     new spell_dk_death_coil();
  844.     new spell_dk_death_grip();
  845. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement