PageRenderTime 273ms CodeModel.GetById 5ms app.highlight 244ms RepoModel.GetById 1ms app.codeStats 1ms

/src/server/scripts/Spells/spell_generic.cpp

https://gitlab.com/tkrokli/TrinityCore_434
C++ | 4156 lines | 3424 code | 585 blank | 147 comment | 325 complexity | 85ae9a833aac52d19732228c4733c1ef MD5 | raw file
   1/*
   2 * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
   3 *
   4 * This program is free software; you can redistribute it and/or modify it
   5 * under the terms of the GNU General Public License as published by the
   6 * Free Software Foundation; either version 2 of the License, or (at your
   7 * option) any later version.
   8 *
   9 * This program is distributed in the hope that it will be useful, but WITHOUT
  10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12 * more details.
  13 *
  14 * You should have received a copy of the GNU General Public License along
  15 * with this program. If not, see <http://www.gnu.org/licenses/>.
  16 */
  17
  18/*
  19 * Scripts for spells with SPELLFAMILY_GENERIC which cannot be included in AI script file
  20 * of creature using it or can't be bound to any player class.
  21 * Ordered alphabetically using scriptname.
  22 * Scriptnames of files in this file should be prefixed with "spell_gen_"
  23 */
  24
  25#include "ScriptMgr.h"
  26#include "Battleground.h"
  27#include "Cell.h"
  28#include "CellImpl.h"
  29#include "GridNotifiers.h"
  30#include "GridNotifiersImpl.h"
  31#include "Group.h"
  32#include "InstanceScript.h"
  33#include "LFGMgr.h"
  34#include "Pet.h"
  35#include "ReputationMgr.h"
  36#include "SkillDiscovery.h"
  37#include "SpellHistory.h"
  38#include "SpellScript.h"
  39#include "SpellAuraEffects.h"
  40#include "Vehicle.h"
  41
  42class spell_gen_absorb0_hitlimit1 : public SpellScriptLoader
  43{
  44    public:
  45        spell_gen_absorb0_hitlimit1() : SpellScriptLoader("spell_gen_absorb0_hitlimit1") { }
  46
  47        class spell_gen_absorb0_hitlimit1_AuraScript : public AuraScript
  48        {
  49            PrepareAuraScript(spell_gen_absorb0_hitlimit1_AuraScript);
  50
  51        public:
  52            spell_gen_absorb0_hitlimit1_AuraScript()
  53            {
  54                limit = 0;
  55            }
  56
  57        private:
  58            uint32 limit;
  59
  60            bool Load() override
  61            {
  62                // Max absorb stored in 1 dummy effect
  63                limit = GetSpellInfo()->Effects[EFFECT_1].CalcValue();
  64                return true;
  65            }
  66
  67            void Absorb(AuraEffect* /*aurEff*/, DamageInfo& /*dmgInfo*/, uint32& absorbAmount)
  68            {
  69                absorbAmount = std::min(limit, absorbAmount);
  70            }
  71
  72            void Register() override
  73            {
  74                OnEffectAbsorb += AuraEffectAbsorbFn(spell_gen_absorb0_hitlimit1_AuraScript::Absorb, EFFECT_0);
  75            }
  76        };
  77
  78        AuraScript* GetAuraScript() const override
  79        {
  80            return new spell_gen_absorb0_hitlimit1_AuraScript();
  81        }
  82};
  83
  84// 28764 - Adaptive Warding (Frostfire Regalia Set)
  85enum AdaptiveWarding
  86{
  87    SPELL_GEN_ADAPTIVE_WARDING_FIRE     = 28765,
  88    SPELL_GEN_ADAPTIVE_WARDING_NATURE   = 28768,
  89    SPELL_GEN_ADAPTIVE_WARDING_FROST    = 28766,
  90    SPELL_GEN_ADAPTIVE_WARDING_SHADOW   = 28769,
  91    SPELL_GEN_ADAPTIVE_WARDING_ARCANE   = 28770
  92};
  93
  94class spell_gen_adaptive_warding : public SpellScriptLoader
  95{
  96    public:
  97        spell_gen_adaptive_warding() : SpellScriptLoader("spell_gen_adaptive_warding") { }
  98
  99        class spell_gen_adaptive_warding_AuraScript : public AuraScript
 100        {
 101            PrepareAuraScript(spell_gen_adaptive_warding_AuraScript);
 102
 103            bool Validate(SpellInfo const* /*spellInfo*/) override
 104            {
 105                if (!sSpellMgr->GetSpellInfo(SPELL_GEN_ADAPTIVE_WARDING_FIRE) ||
 106                    !sSpellMgr->GetSpellInfo(SPELL_GEN_ADAPTIVE_WARDING_NATURE) ||
 107                    !sSpellMgr->GetSpellInfo(SPELL_GEN_ADAPTIVE_WARDING_FROST) ||
 108                    !sSpellMgr->GetSpellInfo(SPELL_GEN_ADAPTIVE_WARDING_SHADOW) ||
 109                    !sSpellMgr->GetSpellInfo(SPELL_GEN_ADAPTIVE_WARDING_ARCANE))
 110                    return false;
 111                return true;
 112            }
 113
 114            bool CheckProc(ProcEventInfo& eventInfo)
 115            {
 116                if (eventInfo.GetDamageInfo()->GetSpellInfo()) // eventInfo.GetSpellInfo()
 117                    return false;
 118
 119                // find Mage Armor
 120                if (!GetTarget()->GetAuraEffect(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT, SPELLFAMILY_MAGE, 0x10000000, 0x0, 0x0))
 121                    return false;
 122
 123                switch (GetFirstSchoolInMask(eventInfo.GetSchoolMask()))
 124                {
 125                    case SPELL_SCHOOL_NORMAL:
 126                    case SPELL_SCHOOL_HOLY:
 127                        return false;
 128                    default:
 129                        break;
 130                }
 131                return true;
 132            }
 133
 134            void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
 135            {
 136                PreventDefaultAction();
 137
 138                uint32 spellId = 0;
 139                switch (GetFirstSchoolInMask(eventInfo.GetSchoolMask()))
 140                {
 141                    case SPELL_SCHOOL_FIRE:
 142                        spellId = SPELL_GEN_ADAPTIVE_WARDING_FIRE;
 143                        break;
 144                    case SPELL_SCHOOL_NATURE:
 145                        spellId = SPELL_GEN_ADAPTIVE_WARDING_NATURE;
 146                        break;
 147                    case SPELL_SCHOOL_FROST:
 148                        spellId = SPELL_GEN_ADAPTIVE_WARDING_FROST;
 149                        break;
 150                    case SPELL_SCHOOL_SHADOW:
 151                        spellId = SPELL_GEN_ADAPTIVE_WARDING_SHADOW;
 152                        break;
 153                    case SPELL_SCHOOL_ARCANE:
 154                        spellId = SPELL_GEN_ADAPTIVE_WARDING_ARCANE;
 155                        break;
 156                    default:
 157                        return;
 158                }
 159                GetTarget()->CastSpell(GetTarget(), spellId, true, NULL, aurEff);
 160            }
 161
 162            void Register() override
 163            {
 164                DoCheckProc += AuraCheckProcFn(spell_gen_adaptive_warding_AuraScript::CheckProc);
 165                OnEffectProc += AuraEffectProcFn(spell_gen_adaptive_warding_AuraScript::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
 166            }
 167        };
 168
 169        AuraScript* GetAuraScript() const override
 170        {
 171            return new spell_gen_adaptive_warding_AuraScript();
 172        }
 173};
 174
 175enum AlchemistStone
 176{
 177    ALECHEMIST_STONE_HEAL      = 21399,
 178    ALECHEMIST_STONE_MANA      = 21400,
 179};
 180
 181// 17619 - Alchemist Stone
 182class spell_gen_alchemist_stone : public SpellScriptLoader
 183{
 184    public:
 185        spell_gen_alchemist_stone() : SpellScriptLoader("spell_gen_alchemist_stone") { }
 186
 187        class spell_gen_alchemist_stone_AuraScript : public AuraScript
 188        {
 189            PrepareAuraScript(spell_gen_alchemist_stone_AuraScript);
 190
 191            bool Validate(SpellInfo const* /*spellInfo*/) override
 192            {
 193                if (!sSpellMgr->GetSpellInfo(ALECHEMIST_STONE_HEAL) ||
 194                    !sSpellMgr->GetSpellInfo(ALECHEMIST_STONE_MANA))
 195                    return false;
 196                return true;
 197            }
 198
 199            bool CheckProc(ProcEventInfo& eventInfo)
 200            {
 201                return eventInfo.GetDamageInfo()->GetSpellInfo()->SpellFamilyName == SPELLFAMILY_POTION;
 202            }
 203
 204            void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
 205            {
 206                PreventDefaultAction();
 207
 208                uint32 spellId = 0;
 209                int32 bp = int32(eventInfo.GetDamageInfo()->GetDamage() * 0.4f);
 210
 211                if (eventInfo.GetDamageInfo()->GetSpellInfo()->HasEffect(SPELL_EFFECT_HEAL))
 212                    spellId = ALECHEMIST_STONE_HEAL;
 213                else if (eventInfo.GetDamageInfo()->GetSpellInfo()->HasEffect(SPELL_EFFECT_ENERGIZE))
 214                    spellId = ALECHEMIST_STONE_MANA;
 215
 216                if (!spellId)
 217                    return;
 218
 219                GetTarget()->CastCustomSpell(spellId, SPELLVALUE_BASE_POINT0, bp, GetTarget(), true, NULL, aurEff);
 220            }
 221
 222
 223            void Register() override
 224            {
 225                DoCheckProc += AuraCheckProcFn(spell_gen_alchemist_stone_AuraScript::CheckProc);
 226                OnEffectProc += AuraEffectProcFn(spell_gen_alchemist_stone_AuraScript::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
 227            }
 228        };
 229
 230        AuraScript* GetAuraScript() const override
 231        {
 232            return new spell_gen_alchemist_stone_AuraScript();
 233        }
 234};
 235
 236class spell_gen_allow_cast_from_item_only : public SpellScriptLoader
 237{
 238    public:
 239        spell_gen_allow_cast_from_item_only() : SpellScriptLoader("spell_gen_allow_cast_from_item_only") { }
 240
 241        class spell_gen_allow_cast_from_item_only_SpellScript : public SpellScript
 242        {
 243            PrepareSpellScript(spell_gen_allow_cast_from_item_only_SpellScript);
 244
 245            SpellCastResult CheckRequirement()
 246            {
 247                if (!GetCastItem())
 248                    return SPELL_FAILED_CANT_DO_THAT_RIGHT_NOW;
 249                return SPELL_CAST_OK;
 250            }
 251
 252            void Register() override
 253            {
 254                OnCheckCast += SpellCheckCastFn(spell_gen_allow_cast_from_item_only_SpellScript::CheckRequirement);
 255            }
 256        };
 257
 258        SpellScript* GetSpellScript() const override
 259        {
 260            return new spell_gen_allow_cast_from_item_only_SpellScript();
 261        }
 262};
 263
 264enum AnimalBloodPoolSpell
 265{
 266    SPELL_ANIMAL_BLOOD      = 46221,
 267    SPELL_SPAWN_BLOOD_POOL  = 63471
 268};
 269
 270class spell_gen_animal_blood : public SpellScriptLoader
 271{
 272    public:
 273        spell_gen_animal_blood() : SpellScriptLoader("spell_gen_animal_blood") { }
 274
 275        class spell_gen_animal_blood_AuraScript : public AuraScript
 276        {
 277            PrepareAuraScript(spell_gen_animal_blood_AuraScript);
 278
 279            bool Validate(SpellInfo const* /*spellInfo*/) override
 280            {
 281                if (!sSpellMgr->GetSpellInfo(SPELL_SPAWN_BLOOD_POOL))
 282                    return false;
 283                return true;
 284            }
 285
 286            void OnApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
 287            {
 288                // Remove all auras with spell id 46221, except the one currently being applied
 289                while (Aura* aur = GetUnitOwner()->GetOwnedAura(SPELL_ANIMAL_BLOOD, ObjectGuid::Empty, ObjectGuid::Empty, 0, GetAura()))
 290                    GetUnitOwner()->RemoveOwnedAura(aur);
 291            }
 292
 293            void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
 294            {
 295                if (Unit* owner = GetUnitOwner())
 296                    if (owner->IsInWater())
 297                        owner->CastSpell(owner, SPELL_SPAWN_BLOOD_POOL, true);
 298            }
 299
 300            void Register() override
 301            {
 302                AfterEffectApply += AuraEffectRemoveFn(spell_gen_animal_blood_AuraScript::OnApply, EFFECT_0, SPELL_AURA_PERIODIC_TRIGGER_SPELL, AURA_EFFECT_HANDLE_REAL);
 303                AfterEffectRemove += AuraEffectRemoveFn(spell_gen_animal_blood_AuraScript::OnRemove, EFFECT_0, SPELL_AURA_PERIODIC_TRIGGER_SPELL, AURA_EFFECT_HANDLE_REAL);
 304            }
 305        };
 306
 307        AuraScript* GetAuraScript() const override
 308        {
 309            return new spell_gen_animal_blood_AuraScript();
 310        }
 311};
 312
 313// 41337 Aura of Anger
 314class spell_gen_aura_of_anger : public SpellScriptLoader
 315{
 316    public:
 317        spell_gen_aura_of_anger() : SpellScriptLoader("spell_gen_aura_of_anger") { }
 318
 319        class spell_gen_aura_of_anger_AuraScript : public AuraScript
 320        {
 321            PrepareAuraScript(spell_gen_aura_of_anger_AuraScript);
 322
 323            void HandleEffectPeriodicUpdate(AuraEffect* aurEff)
 324            {
 325                if (AuraEffect* aurEff1 = aurEff->GetBase()->GetEffect(EFFECT_1))
 326                    aurEff1->ChangeAmount(aurEff1->GetAmount() + 5);
 327                aurEff->SetAmount(100 * aurEff->GetTickNumber());
 328            }
 329
 330            void Register() override
 331            {
 332                OnEffectUpdatePeriodic += AuraEffectUpdatePeriodicFn(spell_gen_aura_of_anger_AuraScript::HandleEffectPeriodicUpdate, EFFECT_0, SPELL_AURA_PERIODIC_DAMAGE);
 333            }
 334        };
 335
 336        AuraScript* GetAuraScript() const override
 337        {
 338            return new spell_gen_aura_of_anger_AuraScript();
 339        }
 340};
 341
 342enum ServiceUniform
 343{
 344    // Spells
 345    SPELL_SERVICE_UNIFORM       = 71450,
 346
 347    // Models
 348    MODEL_GOBLIN_MALE           = 31002,
 349    MODEL_GOBLIN_FEMALE         = 31003
 350};
 351
 352class spell_gen_aura_service_uniform : public SpellScriptLoader
 353{
 354    public:
 355        spell_gen_aura_service_uniform() : SpellScriptLoader("spell_gen_aura_service_uniform") { }
 356
 357        class spell_gen_aura_service_uniform_AuraScript : public AuraScript
 358        {
 359            PrepareAuraScript(spell_gen_aura_service_uniform_AuraScript);
 360
 361            bool Validate(SpellInfo const* /*spellInfo*/) override
 362            {
 363                if (!sSpellMgr->GetSpellInfo(SPELL_SERVICE_UNIFORM))
 364                    return false;
 365                return true;
 366            }
 367
 368            void OnApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
 369            {
 370                // Apply model goblin
 371                Unit* target = GetTarget();
 372                if (target->GetTypeId() == TYPEID_PLAYER)
 373                {
 374                    if (target->getGender() == GENDER_MALE)
 375                        target->SetDisplayId(MODEL_GOBLIN_MALE);
 376                    else
 377                        target->SetDisplayId(MODEL_GOBLIN_FEMALE);
 378                }
 379            }
 380
 381            void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
 382            {
 383                Unit* target = GetTarget();
 384                if (target->GetTypeId() == TYPEID_PLAYER)
 385                    target->RestoreDisplayId();
 386            }
 387
 388            void Register() override
 389            {
 390                AfterEffectApply += AuraEffectRemoveFn(spell_gen_aura_service_uniform_AuraScript::OnApply, EFFECT_0, SPELL_AURA_TRANSFORM, AURA_EFFECT_HANDLE_REAL);
 391                AfterEffectRemove += AuraEffectRemoveFn(spell_gen_aura_service_uniform_AuraScript::OnRemove, EFFECT_0, SPELL_AURA_TRANSFORM, AURA_EFFECT_HANDLE_REAL);
 392            }
 393        };
 394
 395        AuraScript* GetAuraScript() const override
 396        {
 397            return new spell_gen_aura_service_uniform_AuraScript();
 398        }
 399};
 400
 401class spell_gen_av_drekthar_presence : public SpellScriptLoader
 402{
 403    public:
 404        spell_gen_av_drekthar_presence() : SpellScriptLoader("spell_gen_av_drekthar_presence") { }
 405
 406        class spell_gen_av_drekthar_presence_AuraScript : public AuraScript
 407        {
 408            PrepareAuraScript(spell_gen_av_drekthar_presence_AuraScript);
 409
 410            bool CheckAreaTarget(Unit* target)
 411            {
 412                switch (target->GetEntry())
 413                {
 414                    // alliance
 415                    case 14762: // Dun Baldar North Marshal
 416                    case 14763: // Dun Baldar South Marshal
 417                    case 14764: // Icewing Marshal
 418                    case 14765: // Stonehearth Marshal
 419                    case 11948: // Vandar Stormspike
 420                    // horde
 421                    case 14772: // East Frostwolf Warmaster
 422                    case 14776: // Tower Point Warmaster
 423                    case 14773: // Iceblood Warmaster
 424                    case 14777: // West Frostwolf Warmaster
 425                    case 11946: // Drek'thar
 426                        return true;
 427                    default:
 428                        return false;
 429                }
 430            }
 431
 432            void Register() override
 433            {
 434                DoCheckAreaTarget += AuraCheckAreaTargetFn(spell_gen_av_drekthar_presence_AuraScript::CheckAreaTarget);
 435            }
 436        };
 437
 438        AuraScript* GetAuraScript() const override
 439        {
 440            return new spell_gen_av_drekthar_presence_AuraScript();
 441        }
 442};
 443
 444enum GenericBandage
 445{
 446    SPELL_RECENTLY_BANDAGED     = 11196
 447};
 448
 449class spell_gen_bandage : public SpellScriptLoader
 450{
 451    public:
 452        spell_gen_bandage() : SpellScriptLoader("spell_gen_bandage") { }
 453
 454        class spell_gen_bandage_SpellScript : public SpellScript
 455        {
 456            PrepareSpellScript(spell_gen_bandage_SpellScript);
 457
 458            bool Validate(SpellInfo const* /*spellInfo*/) override
 459            {
 460                if (!sSpellMgr->GetSpellInfo(SPELL_RECENTLY_BANDAGED))
 461                    return false;
 462                return true;
 463            }
 464
 465            SpellCastResult CheckCast()
 466            {
 467                if (Unit* target = GetExplTargetUnit())
 468                {
 469                    if (target->HasAura(SPELL_RECENTLY_BANDAGED))
 470                        return SPELL_FAILED_TARGET_AURASTATE;
 471                }
 472                return SPELL_CAST_OK;
 473            }
 474
 475            void HandleScript()
 476            {
 477                if (Unit* target = GetHitUnit())
 478                    GetCaster()->CastSpell(target, SPELL_RECENTLY_BANDAGED, true);
 479            }
 480
 481            void Register() override
 482            {
 483                OnCheckCast += SpellCheckCastFn(spell_gen_bandage_SpellScript::CheckCast);
 484                AfterHit += SpellHitFn(spell_gen_bandage_SpellScript::HandleScript);
 485            }
 486        };
 487
 488        SpellScript* GetSpellScript() const override
 489        {
 490            return new spell_gen_bandage_SpellScript();
 491        }
 492};
 493
 494enum Bonked
 495{
 496    SPELL_BONKED            = 62991,
 497    SPELL_FOAM_SWORD_DEFEAT = 62994,
 498    SPELL_ON_GUARD          = 62972
 499};
 500
 501class spell_gen_bonked : public SpellScriptLoader
 502{
 503    public:
 504        spell_gen_bonked() : SpellScriptLoader("spell_gen_bonked") { }
 505
 506        class spell_gen_bonked_SpellScript : public SpellScript
 507        {
 508            PrepareSpellScript(spell_gen_bonked_SpellScript);
 509
 510            void HandleScript(SpellEffIndex /*effIndex*/)
 511            {
 512                if (Player* target = GetHitPlayer())
 513                {
 514                    Aura const* aura = GetHitAura();
 515                    if (!(aura && aura->GetStackAmount() == 3))
 516                        return;
 517
 518                    target->CastSpell(target, SPELL_FOAM_SWORD_DEFEAT, true);
 519                    target->RemoveAurasDueToSpell(SPELL_BONKED);
 520
 521                    if (Aura const* auraOnGuard = target->GetAura(SPELL_ON_GUARD))
 522                    {
 523                        if (Item* item = target->GetItemByGuid(auraOnGuard->GetCastItemGUID()))
 524                            target->DestroyItemCount(item->GetEntry(), 1, true);
 525                    }
 526                }
 527            }
 528
 529            void Register() override
 530            {
 531                OnEffectHitTarget += SpellEffectFn(spell_gen_bonked_SpellScript::HandleScript, EFFECT_1, SPELL_EFFECT_SCRIPT_EFFECT);
 532            }
 533        };
 534
 535        SpellScript* GetSpellScript() const override
 536        {
 537            return new spell_gen_bonked_SpellScript();
 538        }
 539};
 540
 541/* DOCUMENTATION: Break-Shield spells
 542    Break-Shield spells can be classified in three groups:
 543
 544        - Spells on vehicle bar used by players:
 545            + EFFECT_0: SCRIPT_EFFECT
 546            + EFFECT_1: NONE
 547            + EFFECT_2: NONE
 548        - Spells cast by players triggered by script:
 549            + EFFECT_0: SCHOOL_DAMAGE
 550            + EFFECT_1: SCRIPT_EFFECT
 551            + EFFECT_2: FORCE_CAST
 552        - Spells cast by NPCs on players:
 553            + EFFECT_0: SCHOOL_DAMAGE
 554            + EFFECT_1: SCRIPT_EFFECT
 555            + EFFECT_2: NONE
 556
 557    In the following script we handle the SCRIPT_EFFECT for effIndex EFFECT_0 and EFFECT_1.
 558        - When handling EFFECT_0 we're in the "Spells on vehicle bar used by players" case
 559          and we'll trigger "Spells cast by players triggered by script"
 560        - When handling EFFECT_1 we're in the "Spells cast by players triggered by script"
 561          or "Spells cast by NPCs on players" so we'll search for the first defend layer and drop it.
 562*/
 563
 564enum BreakShieldSpells
 565{
 566    SPELL_BREAK_SHIELD_DAMAGE_2K                 = 62626,
 567    SPELL_BREAK_SHIELD_DAMAGE_10K                = 64590,
 568
 569    SPELL_BREAK_SHIELD_TRIGGER_FACTION_MOUNTS    = 62575, // Also on ToC5 mounts
 570    SPELL_BREAK_SHIELD_TRIGGER_CAMPAING_WARHORSE = 64595,
 571    SPELL_BREAK_SHIELD_TRIGGER_UNK               = 66480
 572};
 573
 574class spell_gen_break_shield: public SpellScriptLoader
 575{
 576    public:
 577        spell_gen_break_shield(const char* name) : SpellScriptLoader(name) { }
 578
 579        class spell_gen_break_shield_SpellScript : public SpellScript
 580        {
 581            PrepareSpellScript(spell_gen_break_shield_SpellScript);
 582
 583            void HandleScriptEffect(SpellEffIndex effIndex)
 584            {
 585                Unit* target = GetHitUnit();
 586
 587                switch (effIndex)
 588                {
 589                    case EFFECT_0: // On spells wich trigger the damaging spell (and also the visual)
 590                    {
 591                        uint32 spellId;
 592
 593                        switch (GetSpellInfo()->Id)
 594                        {
 595                            case SPELL_BREAK_SHIELD_TRIGGER_UNK:
 596                            case SPELL_BREAK_SHIELD_TRIGGER_CAMPAING_WARHORSE:
 597                                spellId = SPELL_BREAK_SHIELD_DAMAGE_10K;
 598                                break;
 599                            case SPELL_BREAK_SHIELD_TRIGGER_FACTION_MOUNTS:
 600                                spellId = SPELL_BREAK_SHIELD_DAMAGE_2K;
 601                                break;
 602                            default:
 603                                return;
 604                        }
 605
 606                        if (Unit* rider = GetCaster()->GetCharmer())
 607                            rider->CastSpell(target, spellId, false);
 608                        else
 609                            GetCaster()->CastSpell(target, spellId, false);
 610                        break;
 611                    }
 612                    case EFFECT_1: // On damaging spells, for removing a defend layer
 613                    {
 614                        Unit::AuraApplicationMap const& auras = target->GetAppliedAuras();
 615                        for (Unit::AuraApplicationMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
 616                        {
 617                            if (Aura* aura = itr->second->GetBase())
 618                            {
 619                                SpellInfo const* auraInfo = aura->GetSpellInfo();
 620                                if (auraInfo && auraInfo->SpellIconID == 2007 && aura->HasEffectType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN))
 621                                {
 622                                    aura->ModStackAmount(-1, AURA_REMOVE_BY_ENEMY_SPELL);
 623                                    // Remove dummys from rider (Necessary for updating visual shields)
 624                                    if (Unit* rider = target->GetCharmer())
 625                                        if (Aura* defend = rider->GetAura(aura->GetId()))
 626                                            defend->ModStackAmount(-1, AURA_REMOVE_BY_ENEMY_SPELL);
 627                                    break;
 628                                }
 629                            }
 630                        }
 631                        break;
 632                    }
 633                    default:
 634                        break;
 635                }
 636            }
 637
 638            void Register() override
 639            {
 640                OnEffectHitTarget += SpellEffectFn(spell_gen_break_shield_SpellScript::HandleScriptEffect, EFFECT_FIRST_FOUND, SPELL_EFFECT_SCRIPT_EFFECT);
 641            }
 642        };
 643
 644        SpellScript* GetSpellScript() const override
 645        {
 646            return new spell_gen_break_shield_SpellScript();
 647        }
 648};
 649
 650// 46394 Brutallus Burn
 651class spell_gen_burn_brutallus : public SpellScriptLoader
 652{
 653    public:
 654        spell_gen_burn_brutallus() : SpellScriptLoader("spell_gen_burn_brutallus") { }
 655
 656        class spell_gen_burn_brutallus_AuraScript : public AuraScript
 657        {
 658            PrepareAuraScript(spell_gen_burn_brutallus_AuraScript);
 659
 660            void HandleEffectPeriodicUpdate(AuraEffect* aurEff)
 661            {
 662                if (aurEff->GetTickNumber() % 11 == 0)
 663                    aurEff->SetAmount(aurEff->GetAmount() * 2);
 664            }
 665
 666            void Register() override
 667            {
 668                OnEffectUpdatePeriodic += AuraEffectUpdatePeriodicFn(spell_gen_burn_brutallus_AuraScript::HandleEffectPeriodicUpdate, EFFECT_0, SPELL_AURA_PERIODIC_DAMAGE);
 669            }
 670        };
 671
 672        AuraScript* GetAuraScript() const override
 673        {
 674            return new spell_gen_burn_brutallus_AuraScript();
 675        }
 676};
 677
 678enum CannibalizeSpells
 679{
 680    SPELL_CANNIBALIZE_TRIGGERED = 20578
 681};
 682
 683class spell_gen_cannibalize : public SpellScriptLoader
 684{
 685    public:
 686        spell_gen_cannibalize() : SpellScriptLoader("spell_gen_cannibalize") { }
 687
 688        class spell_gen_cannibalize_SpellScript : public SpellScript
 689        {
 690            PrepareSpellScript(spell_gen_cannibalize_SpellScript);
 691
 692            bool Validate(SpellInfo const* /*spellInfo*/) override
 693            {
 694                if (!sSpellMgr->GetSpellInfo(SPELL_CANNIBALIZE_TRIGGERED))
 695                    return false;
 696                return true;
 697            }
 698
 699            SpellCastResult CheckIfCorpseNear()
 700            {
 701                Unit* caster = GetCaster();
 702                float max_range = GetSpellInfo()->GetMaxRange(false);
 703                WorldObject* result = NULL;
 704                // search for nearby enemy corpse in range
 705                Trinity::AnyDeadUnitSpellTargetInRangeCheck check(caster, max_range, GetSpellInfo(), TARGET_CHECK_ENEMY);
 706                Trinity::WorldObjectSearcher<Trinity::AnyDeadUnitSpellTargetInRangeCheck> searcher(caster, result, check);
 707                caster->GetMap()->VisitFirstFound(caster->m_positionX, caster->m_positionY, max_range, searcher);
 708                if (!result)
 709                    return SPELL_FAILED_NO_EDIBLE_CORPSES;
 710                return SPELL_CAST_OK;
 711            }
 712
 713            void HandleDummy(SpellEffIndex /*effIndex*/)
 714            {
 715                GetCaster()->CastSpell(GetCaster(), SPELL_CANNIBALIZE_TRIGGERED, false);
 716            }
 717
 718            void Register() override
 719            {
 720                OnEffectHit += SpellEffectFn(spell_gen_cannibalize_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
 721                OnCheckCast += SpellCheckCastFn(spell_gen_cannibalize_SpellScript::CheckIfCorpseNear);
 722            }
 723        };
 724
 725        SpellScript* GetSpellScript() const override
 726        {
 727            return new spell_gen_cannibalize_SpellScript();
 728        }
 729};
 730
 731enum ChaosBlast
 732{
 733    SPELL_CHAOS_BLAST   = 37675
 734};
 735
 736class spell_gen_chaos_blast : public SpellScriptLoader
 737{
 738    public:
 739        spell_gen_chaos_blast() : SpellScriptLoader("spell_gen_chaos_blast") { }
 740
 741        class spell_gen_chaos_blast_SpellScript : public SpellScript
 742        {
 743            PrepareSpellScript(spell_gen_chaos_blast_SpellScript);
 744
 745            bool Validate(SpellInfo const* /*spellInfo*/) override
 746            {
 747                if (!sSpellMgr->GetSpellInfo(SPELL_CHAOS_BLAST))
 748                    return false;
 749                return true;
 750            }
 751            void HandleDummy(SpellEffIndex /* effIndex */)
 752            {
 753                int32 basepoints0 = 100;
 754                Unit* caster = GetCaster();
 755                if (Unit* target = GetHitUnit())
 756                    caster->CastCustomSpell(target, SPELL_CHAOS_BLAST, &basepoints0, NULL, NULL, true);
 757            }
 758
 759            void Register() override
 760            {
 761                OnEffectHitTarget += SpellEffectFn(spell_gen_chaos_blast_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
 762            }
 763        };
 764
 765        SpellScript* GetSpellScript() const override
 766        {
 767            return new spell_gen_chaos_blast_SpellScript();
 768        }
 769};
 770
 771enum Clone
 772{
 773    SPELL_NIGHTMARE_FIGMENT_MIRROR_IMAGE        = 57528
 774};
 775
 776class spell_gen_clone : public SpellScriptLoader
 777{
 778    public:
 779        spell_gen_clone() : SpellScriptLoader("spell_gen_clone") { }
 780
 781        class spell_gen_clone_SpellScript : public SpellScript
 782        {
 783            PrepareSpellScript(spell_gen_clone_SpellScript);
 784
 785            void HandleScriptEffect(SpellEffIndex effIndex)
 786            {
 787                PreventHitDefaultEffect(effIndex);
 788                GetHitUnit()->CastSpell(GetCaster(), uint32(GetEffectValue()), true);
 789            }
 790
 791            void Register() override
 792            {
 793                if (m_scriptSpellId == SPELL_NIGHTMARE_FIGMENT_MIRROR_IMAGE)
 794                {
 795                    OnEffectHitTarget += SpellEffectFn(spell_gen_clone_SpellScript::HandleScriptEffect, EFFECT_1, SPELL_EFFECT_DUMMY);
 796                    OnEffectHitTarget += SpellEffectFn(spell_gen_clone_SpellScript::HandleScriptEffect, EFFECT_2, SPELL_EFFECT_DUMMY);
 797                }
 798                else
 799                {
 800                    OnEffectHitTarget += SpellEffectFn(spell_gen_clone_SpellScript::HandleScriptEffect, EFFECT_1, SPELL_EFFECT_SCRIPT_EFFECT);
 801                    OnEffectHitTarget += SpellEffectFn(spell_gen_clone_SpellScript::HandleScriptEffect, EFFECT_2, SPELL_EFFECT_SCRIPT_EFFECT);
 802                }
 803            }
 804        };
 805
 806        SpellScript* GetSpellScript() const override
 807        {
 808            return new spell_gen_clone_SpellScript();
 809        }
 810};
 811
 812enum CloneWeaponSpells
 813{
 814    SPELL_COPY_WEAPON_AURA       = 41054,
 815    SPELL_COPY_WEAPON_2_AURA     = 63418,
 816    SPELL_COPY_WEAPON_3_AURA     = 69893,
 817
 818    SPELL_COPY_OFFHAND_AURA      = 45205,
 819    SPELL_COPY_OFFHAND_2_AURA    = 69896,
 820
 821    SPELL_COPY_RANGED_AURA       = 57594
 822};
 823
 824class spell_gen_clone_weapon : public SpellScriptLoader
 825{
 826    public:
 827        spell_gen_clone_weapon() : SpellScriptLoader("spell_gen_clone_weapon") { }
 828
 829        class spell_gen_clone_weapon_SpellScript : public SpellScript
 830        {
 831            PrepareSpellScript(spell_gen_clone_weapon_SpellScript);
 832
 833            void HandleScriptEffect(SpellEffIndex effIndex)
 834            {
 835                PreventHitDefaultEffect(effIndex);
 836                GetHitUnit()->CastSpell(GetCaster(), uint32(GetEffectValue()), true);
 837            }
 838
 839            void Register() override
 840            {
 841                OnEffectHitTarget += SpellEffectFn(spell_gen_clone_weapon_SpellScript::HandleScriptEffect, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
 842            }
 843        };
 844
 845        SpellScript* GetSpellScript() const override
 846        {
 847            return new spell_gen_clone_weapon_SpellScript();
 848        }
 849};
 850
 851class spell_gen_clone_weapon_aura : public SpellScriptLoader
 852{
 853    public:
 854        spell_gen_clone_weapon_aura() : SpellScriptLoader("spell_gen_clone_weapon_aura") { }
 855
 856        class spell_gen_clone_weapon_auraScript : public AuraScript
 857        {
 858            PrepareAuraScript(spell_gen_clone_weapon_auraScript);
 859
 860        public:
 861            spell_gen_clone_weapon_auraScript()
 862            {
 863                prevItem = 0;
 864            }
 865
 866        private:
 867            bool Validate(SpellInfo const* /*spellInfo*/) override
 868            {
 869                if (!sSpellMgr->GetSpellInfo(SPELL_COPY_WEAPON_AURA) ||
 870                    !sSpellMgr->GetSpellInfo(SPELL_COPY_WEAPON_2_AURA) ||
 871                    !sSpellMgr->GetSpellInfo(SPELL_COPY_WEAPON_3_AURA) ||
 872                    !sSpellMgr->GetSpellInfo(SPELL_COPY_OFFHAND_AURA) ||
 873                    !sSpellMgr->GetSpellInfo(SPELL_COPY_OFFHAND_2_AURA) ||
 874                    !sSpellMgr->GetSpellInfo(SPELL_COPY_RANGED_AURA))
 875                    return false;
 876                return true;
 877            }
 878
 879            void OnApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
 880            {
 881                Unit* caster = GetCaster();
 882                Unit* target = GetTarget();
 883                if (!caster)
 884                    return;
 885
 886                switch (GetSpellInfo()->Id)
 887                {
 888                    case SPELL_COPY_WEAPON_AURA:
 889                    case SPELL_COPY_WEAPON_2_AURA:
 890                    case SPELL_COPY_WEAPON_3_AURA:
 891                    {
 892                        prevItem = target->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID);
 893
 894                        if (Player* player = caster->ToPlayer())
 895                        {
 896                            if (Item* mainItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND))
 897                                target->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID, mainItem->GetEntry());
 898                        }
 899                        else
 900                            target->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID, caster->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID));
 901                        break;
 902                    }
 903                    case SPELL_COPY_OFFHAND_AURA:
 904                    case SPELL_COPY_OFFHAND_2_AURA:
 905                    {
 906                        prevItem = target->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID) + 1;
 907
 908                        if (Player* player = caster->ToPlayer())
 909                        {
 910                            if (Item* offItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND))
 911                                target->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 1, offItem->GetEntry());
 912                        }
 913                        else
 914                            target->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 1, caster->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 1));
 915                        break;
 916                    }
 917                    case SPELL_COPY_RANGED_AURA:
 918                    {
 919                        prevItem = target->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID) + 2;
 920
 921                        if (Player* player = caster->ToPlayer())
 922                        {
 923                            if (Item* rangedItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_RANGED))
 924                                target->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 2, rangedItem->GetEntry());
 925                        }
 926                        else
 927                            target->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 2, caster->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 2));
 928                        break;
 929                    }
 930                    default:
 931                        break;
 932                }
 933            }
 934
 935            void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
 936            {
 937                Unit* target = GetTarget();
 938
 939                switch (GetSpellInfo()->Id)
 940                {
 941                    case SPELL_COPY_WEAPON_AURA:
 942                    case SPELL_COPY_WEAPON_2_AURA:
 943                    case SPELL_COPY_WEAPON_3_AURA:
 944                        target->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID, prevItem);
 945                        break;
 946                    case SPELL_COPY_OFFHAND_AURA:
 947                    case SPELL_COPY_OFFHAND_2_AURA:
 948                        target->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 1, prevItem);
 949                        break;
 950                    case SPELL_COPY_RANGED_AURA:
 951                        target->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 2, prevItem);
 952                        break;
 953                    default:
 954                        break;
 955                }
 956            }
 957
 958            void Register() override
 959            {
 960                OnEffectApply += AuraEffectApplyFn(spell_gen_clone_weapon_auraScript::OnApply, EFFECT_0, SPELL_AURA_PERIODIC_DUMMY, AURA_EFFECT_HANDLE_REAL_OR_REAPPLY_MASK);
 961                OnEffectRemove += AuraEffectRemoveFn(spell_gen_clone_weapon_auraScript::OnRemove, EFFECT_0, SPELL_AURA_PERIODIC_DUMMY, AURA_EFFECT_HANDLE_REAL_OR_REAPPLY_MASK);
 962            }
 963
 964        private:
 965            uint32 prevItem;
 966        };
 967
 968        AuraScript* GetAuraScript() const override
 969        {
 970            return new spell_gen_clone_weapon_auraScript();
 971        }
 972};
 973
 974class spell_gen_count_pct_from_max_hp : public SpellScriptLoader
 975{
 976    public:
 977        spell_gen_count_pct_from_max_hp(char const* name, int32 damagePct = 0) : SpellScriptLoader(name), _damagePct(damagePct) { }
 978
 979        class spell_gen_count_pct_from_max_hp_SpellScript : public SpellScript
 980        {
 981            PrepareSpellScript(spell_gen_count_pct_from_max_hp_SpellScript);
 982
 983        public:
 984            spell_gen_count_pct_from_max_hp_SpellScript(int32 damagePct) : SpellScript(), _damagePct(damagePct) { }
 985
 986            void RecalculateDamage()
 987            {
 988                if (!_damagePct)
 989                    _damagePct = GetHitDamage();
 990
 991                SetHitDamage(GetHitUnit()->CountPctFromMaxHealth(_damagePct));
 992            }
 993
 994            void Register() override
 995            {
 996                OnHit += SpellHitFn(spell_gen_count_pct_from_max_hp_SpellScript::RecalculateDamage);
 997            }
 998
 999        private:
1000            int32 _damagePct;
1001        };
1002
1003        SpellScript* GetSpellScript() const override
1004        {
1005            return new spell_gen_count_pct_from_max_hp_SpellScript(_damagePct);
1006        }
1007
1008    private:
1009        int32 _damagePct;
1010};
1011
1012// 63845 - Create Lance
1013enum CreateLanceSpells
1014{
1015    SPELL_CREATE_LANCE_ALLIANCE = 63914,
1016    SPELL_CREATE_LANCE_HORDE    = 63919
1017};
1018
1019class spell_gen_create_lance : public SpellScriptLoader
1020{
1021    public:
1022        spell_gen_create_lance() : SpellScriptLoader("spell_gen_create_lance") { }
1023
1024        class spell_gen_create_lance_SpellScript : public SpellScript
1025        {
1026            PrepareSpellScript(spell_gen_create_lance_SpellScript);
1027
1028            bool Validate(SpellInfo const* /*spellInfo*/) override
1029            {
1030                if (!sSpellMgr->GetSpellInfo(SPELL_CREATE_LANCE_ALLIANCE) ||
1031                    !sSpellMgr->GetSpellInfo(SPELL_CREATE_LANCE_HORDE))
1032                    return false;
1033                return true;
1034            }
1035
1036            void HandleScript(SpellEffIndex effIndex)
1037            {
1038                PreventHitDefaultEffect(effIndex);
1039
1040                if (Player* target = GetHitPlayer())
1041                {
1042                    if (target->GetTeam() == ALLIANCE)
1043                        GetCaster()->CastSpell(target, SPELL_CREATE_LANCE_ALLIANCE, true);
1044                    else
1045                        GetCaster()->CastSpell(target, SPELL_CREATE_LANCE_HORDE, true);
1046                }
1047            }
1048
1049            void Register() override
1050            {
1051                OnEffectHitTarget += SpellEffectFn(spell_gen_create_lance_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
1052            }
1053        };
1054
1055        SpellScript* GetSpellScript() const override
1056        {
1057            return new spell_gen_create_lance_SpellScript();
1058        }
1059};
1060
1061class spell_gen_creature_permanent_feign_death : public SpellScriptLoader
1062{
1063    public:
1064        spell_gen_creature_permanent_feign_death() : SpellScriptLoader("spell_gen_creature_permanent_feign_death") { }
1065
1066        class spell_gen_creature_permanent_feign_death_AuraScript : public AuraScript
1067        {
1068            PrepareAuraScript(spell_gen_creature_permanent_feign_death_AuraScript);
1069
1070            void HandleEffectApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
1071            {
1072                Unit* target = GetTarget();
1073                target->SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_DEAD);
1074                target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH);
1075
1076                if (target->GetTypeId() == TYPEID_UNIT)
1077                    target->ToCreature()->SetReactState(REACT_PASSIVE);
1078            }
1079
1080            void Register() override
1081            {
1082                OnEffectApply += AuraEffectApplyFn(spell_gen_creature_permanent_feign_death_AuraScript::HandleEffectApply, EFFECT_0, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL);
1083            }
1084        };
1085
1086        AuraScript* GetAuraScript() const override
1087        {
1088            return new spell_gen_creature_permanent_feign_death_AuraScript();
1089        }
1090};
1091
1092enum DalaranDisguiseSpells
1093{
1094    SPELL_SUNREAVER_DISGUISE_TRIGGER       = 69672,
1095    SPELL_SUNREAVER_DISGUISE_FEMALE        = 70973,
1096    SPELL_SUNREAVER_DISGUISE_MALE          = 70974,
1097
1098    SPELL_SILVER_COVENANT_DISGUISE_TRIGGER = 69673,
1099    SPELL_SILVER_COVENANT_DISGUISE_FEMALE  = 70971,
1100    SPELL_SILVER_COVENANT_DISGUISE_MALE    = 70972
1101};
1102
1103class spell_gen_dalaran_disguise : public SpellScriptLoader
1104{
1105    public:
1106        spell_gen_dalaran_disguise(const char* name) : SpellScriptLoader(name) { }
1107
1108        class spell_gen_dalaran_disguise_SpellScript : public SpellScript
1109        {
1110            PrepareSpellScript(spell_gen_dalaran_disguise_SpellScript);
1111
1112            bool Validate(SpellInfo const* spellInfo) override
1113            {
1114                switch (spellInfo->Id)
1115                {
1116                    case SPELL_SUNREAVER_DISGUISE_TRIGGER:
1117                        if (!sSpellMgr->GetSpellInfo(SPELL_SUNREAVER_DISGUISE_FEMALE) ||
1118                            !sSpellMgr->GetSpellInfo(SPELL_SUNREAVER_DISGUISE_MALE))
1119                            return false;
1120                        break;
1121                    case SPELL_SILVER_COVENANT_DISGUISE_TRIGGER:
1122                        if (!sSpellMgr->GetSpellInfo(SPELL_SILVER_COVENANT_DISGUISE_FEMALE) ||
1123                            !sSpellMgr->GetSpellInfo(SPELL_SILVER_COVENANT_DISGUISE_MALE))
1124                            return false;
1125                        break;
1126                }
1127                return true;
1128            }
1129
1130            void HandleScript(SpellEffIndex /*effIndex*/)
1131            {
1132                if (Player* player = GetHitPlayer())
1133                {
1134                    uint8 gender = player->getGender();
1135
1136                    uint32 spellId = GetSpellInfo()->Id;
1137
1138                    switch (spellId)
1139                    {
1140                        case SPELL_SUNREAVER_DISGUISE_TRIGGER:
1141                            spellId = gender ? SPELL_SUNREAVER_DISGUISE_FEMALE : SPELL_SUNREAVER_DISGUISE_MALE;
1142                            break;
1143                        case SPELL_SILVER_COVENANT_DISGUISE_TRIGGER:
1144                            spellId = gender ? SPELL_SILVER_COVENANT_DISGUISE_FEMALE : SPELL_SILVER_COVENANT_DISGUISE_MALE;
1145                            break;
1146                        default:
1147                            break;
1148                    }
1149
1150                    GetCaster()->CastSpell(player, spellId, true);
1151                }
1152            }
1153
1154            void Register() override
1155            {
1156                OnEffectHitTarget += SpellEffectFn(spell_gen_dalaran_disguise_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
1157            }
1158        };
1159
1160        SpellScript* GetSpellScript() const override
1161        {
1162            return new spell_gen_dalaran_disguise_SpellScript();
1163        }
1164};
1165
1166enum DefendVisuals
1167{
1168    SPELL_VISUAL_SHIELD_1 = 63130,
1169    SPELL_VISUAL_SHIELD_2 = 63131,
1170    SPELL_VISUAL_SHIELD_3 = 63132
1171};
1172
1173class spell_gen_defend : public SpellScriptLoader
1174{
1175    public:
1176        spell_gen_defend() : SpellScriptLoader("spell_gen_defend") { }
1177
1178        class spell_gen_defend_AuraScript : public AuraScript
1179        {
1180            PrepareAuraScript(spell_gen_defend_AuraScript);
1181
1182            bool Validate(SpellInfo const* /*spellInfo*/) override
1183            {
1184                if (!sSpellMgr->GetSpellInfo(SPELL_VISUAL_SHIELD_1))
1185                    return false;
1186                if (!sSpellMgr->GetSpellInfo(SPELL_VISUAL_SHIELD_2))
1187                    return false;
1188                if (!sSpellMgr->GetSpellInfo(SPELL_VISUAL_SHIELD_3))
1189                    return false;
1190                return true;
1191            }
1192
1193            void RefreshVisualShields(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
1194            {
1195                if (GetCaster())
1196                {
1197                    Unit* target = GetTarget();
1198
1199                    for (uint8 i = 0; i < GetSpellInfo()->StackAmount; ++i)
1200                        target->RemoveAurasDueToSpell(SPELL_VISUAL_SHIELD_1 + i);
1201
1202                    target->CastSpell(target, SPELL_VISUAL_SHIELD_1 + GetAura()->GetStackAmount() - 1, true, NULL, aurEff);
1203                }
1204                else
1205                    GetTarget()->RemoveAurasDueToSpell(GetId());
1206            }
1207
1208            void RemoveVisualShields(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
1209            {
1210                for (uint8 i = 0; i < GetSpellInfo()->StackAmount; ++i)
1211                    GetTarget()->RemoveAurasDueToSpell(SPELL_VISUAL_SHIELD_1 + i);
1212            }
1213
1214            void RemoveDummyFromDriver(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
1215            {
1216                if (Unit* caster = GetCaster())
1217                    if (TempSummon* vehicle = caster->ToTempSummon())
1218                        if (Unit* rider = vehicle->GetSummoner())
1219                            rider->RemoveAurasDueToSpell(GetId());
1220            }
1221
1222            void Register() override
1223            {
1224                SpellInfo const* spell = sSpellMgr->EnsureSpellInfo(m_scriptSpellId);
1225
1226                // Defend spells cast by NPCs (add visuals)
1227                if (spell->Effects[EFFECT_0].ApplyAuraName == SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN)
1228                {
1229                    AfterEffectApply += AuraEffectApplyFn(spell_gen_defend_AuraScript::RefreshVisualShields, EFFECT_0, SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN, AURA_EFFECT_HANDLE_REAL_OR_REAPPLY_MASK);
1230                    OnEffectRemove += AuraEffectRemoveFn(spell_gen_defend_AuraScript::RemoveVisualShields, EFFECT_0, SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN, AURA_EFFECT_HANDLE_CHANGE_AMOUNT_MASK);
1231                }
1232
1233                // Remove Defend spell from player when he dismounts
1234                if (spell->Effects[EFFECT_2].ApplyAuraName == SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN)
1235                    OnEffectRemove += AuraEffectRemoveFn(spell_gen_defend_AuraScript::RemoveDummyFromDriver, EFFECT_2, SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN, AURA_EFFECT_HANDLE_REAL);
1236
1237                // Defend spells cast by players (add/remove visuals)
1238                if (spell->Effects[EFFECT_1].ApplyAuraName == SPELL_AURA_DUMMY)
1239                {
1240                    AfterEffectApply += AuraEffectApplyFn(spell_gen_defend_AuraScript::RefreshVisualShields, EFFECT_1, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL_OR_REAPPLY_MASK);
1241                    OnEffectRemove += AuraEffectRemoveFn(spell_gen_defend_AuraScript::RemoveVisualShields, EFFECT_1, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_CHANGE_AMOUNT_MASK);
1242                }
1243            }
1244        };
1245
1246        AuraScript* GetAuraScript() const override
1247        {
1248            return new spell_gen_defend_AuraScript();
1249        }
1250};
1251
1252class spell_gen_despawn_self : public SpellScriptLoader
1253{
1254    public:
1255        spell_gen_despawn_self() : SpellScriptLoader("spell_gen_despawn_self") { }
1256
1257        class spell_gen_despawn_self_SpellScript : public SpellScript
1258        {
1259            PrepareSpellScript(spell_gen_despawn_self_SpellScript);
1260
1261            bool Load() override
1262            {
1263                return GetCaster()->GetTypeId() == TYPEID_UNIT;
1264            }
1265
1266            void HandleDummy(SpellEffIndex effIndex)
1267            {
1268                if (GetSpellInfo()->Effects[effIndex].Effect == SPELL_EFFECT_DUMMY || GetSpellInfo()->Effects[effIndex].Effect == SPELL_EFFECT_SCRIPT_EFFECT)
1269                    GetCaster()->ToCreature()->DespawnOrUnsummon();
1270            }
1271
1272            void Register() override
1273            {
1274                OnEffectHitTarget += SpellEffectFn(spell_gen_despawn_self_SpellScript::HandleDummy, EFFECT_ALL, SPELL_EFFECT_ANY);
1275            }
1276        };
1277
1278        SpellScript* GetSpellScript() const override
1279        {
1280            return new spell_gen_despawn_self_SpellScript();
1281        }
1282};
1283
1284enum DivineStormSpell
1285{
1286    SPELL_DIVINE_STORM      = 53385,
1287};
1288
1289// 70769 Divine Storm!
1290class spell_gen_divine_storm_cd_reset : public SpellScriptLoader
1291{
1292    public:
1293        spell_gen_divine_storm_cd_reset() : SpellScriptLoader("spell_gen_divine_storm_cd_reset") { }
1294
1295        class spell_gen_divine_storm_cd_reset_SpellScript : public SpellScript
1296        {
1297            PrepareSpellScript(spell_gen_divine_storm_cd_reset_SpellScript);
1298
1299            bool Load() override
1300            {
1301                return GetCaster()->GetTypeId() == TYPEID_PLAYER;
1302            }
1303
1304            bool Validate(SpellInfo const* /*spellInfo*/) override
1305            {
1306                if (!sSpellMgr->GetSpellInfo(SPELL_DIVINE_STORM))
1307                    return false;
1308                return true;
1309            }
1310
1311            void HandleScript(SpellEffIndex /*effIndex*/)
1312            {
1313                Player* caster = GetCaster()->ToPlayer();
1314                if (caster->GetSpellHistory()->HasCooldown(SPELL_DIVINE_STORM))
1315                    caster->GetSpellHistory()->ResetCooldown(SPELL_DIVINE_STORM, true);
1316            }
1317
1318            void Register() override
1319            {
1320                OnEffectHitTarget += SpellEffectFn(spell_gen_divine_storm_cd_reset_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_DUMMY);
1321            }
1322        };
1323
1324        SpellScript* GetSpellScript() const override
1325        {
1326            return new spell_gen_divine_storm_cd_reset_SpellScript();
1327        }
1328};
1329
1330class spell_gen_ds_flush_knockback : public SpellScriptLoader
1331{
1332    public:
1333        spell_gen_ds_flush_knockback() : SpellScriptLoader("spell_gen_ds_flush_knockback") { }
1334
1335        class spell_gen_ds_flush_knockback_SpellScript : public SpellScript
1336        {
1337            PrepareSpellScript(spell_gen_ds_flush_knockback_SpellScript);
1338
1339            void HandleScript(SpellEffIndex /*effIndex*/)
1340            {
1341                // Here the target is the water spout and determines the position where the player is knocked from
1342                if (Unit* target = GetHitUnit())
1343                {
1344                    if (Player* player = GetCaster()->ToPlayer())
1345                    {
1346                        float horizontalSpeed = 20.0f + (40.0f - GetCaster()->GetDistance(target));
1347                        float verticalSpeed = 8.0f;
1348                        // This method relies on the Dalaran Sewer map disposition and Water Spout position
1349                        // What we do is knock the player from a position exactly behind him and at the end of the pipe
1350                        player->KnockbackFrom(target->GetPositionX(), player->GetPositionY(), horizontalSpeed, verticalSpeed);
1351                    }
1352                }
1353            }
1354
1355            void Register() override
1356            {
1357                OnEffectHitTarget += SpellEffectFn(spell_gen_ds_flush_knockback_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_DUMMY);
1358            }
1359        };
1360
1361        SpellScript* GetSpellScript() const override
1362        {
1363            return new spell_gen_ds_flush_knockback_SpellScript();
1364        }
1365};
1366
1367enum DummyTrigger
1368{
1369    SPELL_PERSISTANT_SHIELD_TRIGGERED       = 26470,
1370    SPELL_PERSISTANT_SHIELD                 = 26467
1371};
1372
1373class spell_gen_dummy_trigger : public SpellScriptLoader
1374{
1375    public:
1376        spell_gen_dummy_trigger() : SpellScriptLoader("spell_gen_dummy_trigger") { }
1377
1378        class spell_gen_dummy_trigger_SpellScript : public SpellScript
1379        {
1380            PrepareSpellScript(spell_gen_dummy_trigger_SpellScript);
1381
1382            bool Validate(SpellInfo const* /*spellInfo*/) override
1383            {
1384                if (!sSpellMgr->GetSpellInfo(SPELL_PERSISTANT_SHIELD_TRIGGERED) ||
1385                    !sSpellMgr->GetSpellInfo(SPELL_PERSISTANT_SHIELD))
1386                    return false;
1387                return true;
1388            }
1389
1390            void HandleDummy(SpellEffIndex /* effIndex */)
1391            {
1392                int32 damage = GetEffectValue();
1393                Unit* caster = GetCaster();
1394                if (Unit* target = GetHitUnit())
1395                    if (SpellInfo const* triggeredByAuraSpell = GetTriggeringSpell())
1396                        if (triggeredByAuraSpell->Id == SPELL_PERSISTANT_SHIELD_TRIGGERED)
1397                            caster->CastCustomSpell(target, SPELL_PERSISTANT_SHIELD_TRIGGERED, &damage, NULL, NULL, true);
1398            }
1399
1400            void Register() override
1401            {
1402                OnEffectHitTarget += SpellEffectFn(spell_gen_dummy_trigger_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
1403            }
1404        };
1405
1406        SpellScript* GetSpellScript() const override
1407        {
1408            return new spell_gen_dummy_trigger_SpellScript();
1409        }
1410};
1411
1412class spell_gen_dungeon_credit : public SpellScriptLoader
1413{
1414    public:
1415        spell_gen_dungeon_credit() : SpellScriptLoader("spell_gen_dungeon_credit") { }
1416
1417        class spell_gen_dungeon_credit_SpellScript : public SpellScript
1418        {
1419            PrepareSpellScript(spell_gen_dungeon_credit_SpellScript);
1420
1421        public:
1422            spell_gen_dungeon_credit_SpellScript()
1423            {
1424                _handled = false;
1425            }
1426
1427        private:
1428            bool Load() override
1429            {
1430                return GetCaster()->GetTypeId() == TYPEID_UNIT;
1431            }
1432
1433            void CreditEncounter()
1434            {
1435                // This hook is executed for every target, make sure we only credit instance once
1436                if (_handled)
1437                    return;
1438
1439                _handled = true;
1440                Unit* caster = GetCaster();
1441                if (InstanceScript* instance = caster->GetInstanceScript())
1442                    instance->UpdateEncounterState(ENCOUNTER_CREDIT_CAST_SPELL, GetSpellInfo()->Id, caster);
1443            }
1444
1445            void Register() override
1446            {
1447                AfterHit += SpellHitFn(spell_gen_dungeon_credit_SpellScript::CreditEncounter);
1448            }
1449
1450        private:
1451            bool _handled;
1452        };
1453
1454        SpellScript* GetSpellScript() const override
1455        {
1456            return new spell_gen_dungeon_credit_SpellScript();
1457        }
1458};
1459
1460enum EluneCandle
1461{
1462    // Creatures
1463    NPC_OMEN                       = 15467,
1464
1465    // Spells
1466    SPELL_ELUNE_CANDLE_OMEN_HEAD   = 26622,
1467    SPELL_ELUNE_CANDLE_OMEN_CHEST  = 26624,
1468    SPELL_ELUNE_CANDLE_OMEN_HAND_R = 26625,
1469    SPELL_ELUNE_CANDLE_OMEN_HAND_L = 26649,
1470    SPELL_ELUNE_CANDLE_NORMAL      = 26636
1471};
1472
1473class spell_gen_elune_candle : public SpellScriptLoader
1474{
1475    public:
1476        spell_gen_elune_candle() : SpellScriptLoader("spell_gen_elune_candle") { }
1477
1478        class spell_gen_elune_candle_SpellScript : public SpellScript
1479        {
1480            PrepareSpellScript(spell_gen_elune_candle_SpellScript);
1481
1482            bool Validate(SpellInfo const* /*spellInfo*/) override
1483            {
1484                if (!sSpellMgr->GetSpellInfo(SPELL_ELUNE_CANDLE_OMEN_HEAD) ||
1485                    !sSpellMgr->GetSpellInfo(SPELL_ELUNE_CANDLE_OMEN_CHEST) ||
1486                    !sSpellMgr->GetSpellInfo(SPELL_ELUNE_CANDLE_OMEN_HAND_R) ||
1487                    !sSpellMgr->GetSpellInfo(SPELL_ELUNE_CANDLE_OMEN_HAND_L) ||
1488                    !sSpellMgr->GetSpellInfo(SPELL_ELUNE_CANDLE_NORMAL))
1489                    return false;
1490                return true;
1491            }
1492
1493            void HandleScript(SpellEffIndex /*effIndex*/)
1494            {
1495                uint32 spellId = 0;
1496
1497                if (GetHitUnit()->GetEntry() == NPC_OMEN)
1498                {
1499                    switch (urand(0, 3))
1500                    {
1501                        case 0:
1502                            spellId = SPELL_ELUNE_CANDLE_OMEN_HEAD;
1503                            break;
1504                        case 1:
1505                            spellId = SPELL_ELUNE_CANDLE_OMEN_CHEST;
1506                            break;
1507                        case 2:
1508                            spellId = SPELL_ELUNE_CANDLE_OMEN_HAND_R;
1509                            break;
1510                        case 3:
1511                            spellId = SPELL_ELUNE_CANDLE_OMEN_HAND_L;
1512                            break;
1513                    }
1514                }
1515                else
1516                    spellId = SPELL_ELUNE_CANDLE_NORMAL;
1517
1518                GetCaster()->CastSpell(GetHitUnit(), spellId, true, NULL);
1519            }
1520
1521            void Register() override
1522            {
1523                OnEffectHitTarget += SpellEffectFn(spell_gen_elune_candle_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_DUMMY);
1524            }
1525        };
1526
1527        SpellScript* GetSpellScript() const override
1528        {
1529            return new spell_gen_elune_candle_SpellScript();
1530        }
1531};
1532
1533enum TransporterBackfires
1534{
1535    SPELL_TRANSPORTER_MALFUNCTION_POLYMORPH     = 23444,
1536    SPELL_TRANSPORTER_EVIL_TWIN                 = 23445,
1537    SPELL_TRANSPORTER_MALFUNCTION_MISS          = 36902
1538};
1539
1540class spell_gen_gadgetzan_transporter_backfire : public SpellScriptLoader
1541{
1542    public:
1543        spell_gen_gadgetzan_transporter_backfire() : SpellScriptLoader("spell_gen_gadgetzan_transporter_backfire") { }
1544
1545        class spell_gen_gadgetzan_transporter_backfire_SpellScript : public SpellScript
1546        {
1547            PrepareSpellScript(spell_gen_gadgetzan_transporter_backfire_SpellScript);
1548
1549            bool Validate(SpellInfo const* /*spellInfo*/) override
1550            {
1551                if (!sSpellMgr->GetSpellInfo(SPELL_TRANSPORTER_MALFUNCTION_POLYMORPH) ||
1552                    !sSpellMgr->GetSpellInfo(SPELL_TRANSPORTER_EVIL_TWIN) ||
1553                    !sSpellMgr->GetSpellInfo(SPELL_TRANSPORTER_MALFUNCTION_MISS))
1554                    return false;
1555                return true;
1556            }
1557
1558            void HandleDummy(SpellEffIndex /* effIndex */)
1559            {
1560                Unit* caster = GetCaster();
1561                int32 r = irand(0, 119);
1562                if (r < 20)                           // Transporter Malfunction - 1/6 polymorph
1563                    caster->CastSpell(caster, SPELL_TRANSPORTER_MALFUNCTION_POLYMORPH, true);
1564                else if (r < 100)                     // Evil Twin               - 4/6 evil twin
1565                    caster->CastSpell(caster, SPELL_TRANSPORTER_EVIL_TWIN, true);
1566                else                                    // Transporter Malfunction - 1/6 miss the target
1567                    caster->CastSpell(caster, SPELL_TRANSPORTER_MALFUNCTION_MISS, true);
1568            }
1569
1570            void Register() override
1571            {
1572                OnEffectHitTarget += SpellEffectFn(spell_gen_gadgetzan_transporter_backfire_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
1573            }
1574        };
1575
1576        SpellScript* GetSpellScript() const override
1577        {
1578            return new spell_gen_gadgetzan_transporter_backfire_SpellScript();
1579        }
1580};
1581
1582
1583class spell_gen_gift_of_naaru : public SpellScriptLoader
1584{
1585    public:
1586        spell_gen_gift_of_naaru() : SpellScriptLoader("spell_gen_gift_of_naaru") { }
1587
1588        class spell_gen_gift_of_naaru_AuraScript : public AuraScript
1589        {
1590            PrepareAuraScript(spell_gen_gift_of_naaru_AuraScript);
1591
1592            void CalculateAmount(AuraEffect const* aurEff, int32& amount, bool& /*canBeRecalculated*/)
1593            {
1594                if (!GetCaster())
1595                    return;
1596
1597                float heal = 0.0f;
1598                switch (GetSpellInfo()->SpellFamilyName)
1599                {
1600                    case SPELLFAMILY_MAGE:
1601                    case SPELLFAMILY_WARLOCK:
1602                    case SPELLFAMILY_PRIEST:
1603                        heal = 1.885f * float(GetCaster()->SpellBaseDamageBonusDone(GetSpellInfo()->GetSchoolMask()));
1604                        break;
1605                    case SPELLFAMILY_PALADIN:
1606                    case SPELLFAMILY_SHAMAN:
1607                        heal = std::max(1.885f * float(GetCaster()->SpellBaseDamageBonusDone(GetSpellInfo()->GetSchoolMask())), 1.1f * float(GetCaster()->GetTotalAttackPowerValue(BASE_ATTACK)));
1608                        break;
1609                    case SPELLFAMILY_WARRIOR:
1610                    case SPELLFAMILY_HUNTER:
1611                    case SPELLFAMILY_DEATHKNIGHT:
1612                        heal = 1.1f * float(std::max(GetCaster()->GetTotalAttackPowerValue(BASE_ATTACK), GetCaster()->GetTotalAttackPowerValue(RANGED_ATTACK)));
1613                        break;
1614                    case SPELLFAMILY_GENERIC:
1615                    default:
1616                        break;
1617                }
1618
1619                int32 healTick = std::floor(heal / aurEff->GetTotalTicks());
1620                amount += int32(std::max(healTick, 0));
1621            }
1622
1623            void Register() override
1624            {
1625                DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_gift_of_naaru_AuraScript::CalculateAmount, EFFECT_0, SPELL_AURA_PERIODIC_HEAL);
1626            }
1627        };
1628
1629        AuraScript* GetAuraScript() const override
1630        {
1631            return new spell_gen_gift_of_naaru_AuraScript();
1632        }
1633};
1634
1635enum GnomishTransporter
1636{
1637    SPELL_TRANSPORTER_SUCCESS                   = 23441,
1638    SPELL_TRANSPORTER_FAILURE                   = 23446
1639};
1640
1641class spell_gen_gnomish_transporter : public SpellScriptLoader
1642{
1643    public:
1644        spell_gen_gnomish_transporter() : SpellScriptLoader("spell_gen_gnomish_transporter") { }
1645
1646        class spell_gen_gnomish_transporter_SpellScript : public SpellScript
1647        {
1648            PrepareSpellScript(spell_gen_gnomish_transporter_SpellScript);
1649
1650            bool Validate(SpellInfo const* /*spellInfo*/) override
1651            {
1652                if (!sSpellMgr->GetSpellInfo(SPELL_TRANSPORTER_SUCCESS) ||
1653                    !sSpellMgr->GetSpellInfo(SPELL_TRANSPORTER_FAILURE))
1654                    return false;
1655                return true;
1656            }
1657
1658            void HandleDummy(SpellEffIndex /* effIndex */)
1659            {
1660                GetCaster()->CastSpell(GetCaster(), roll_chance_i(50) ? SPELL_TRANSPORTER_SUCCESS : SPELL_TRANSPORTER_FAILURE, true);
1661            }
1662
1663            void Register() override
1664            {
1665                OnEffectHitTarget += SpellEffectFn(spell_gen_gnomish_transporter_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
1666            }
1667        };
1668
1669        SpellScript* GetSpellScript() const override
1670        {
1671            return new spell_gen_gnomish_transporter_SpellScript();
1672        }
1673};
1674
1675
1676enum Interrupt
1677{
1678    SPELL_GEN_THROW_INTERRUPT           = 32747
1679};
1680
1681// 32748 - Deadly Throw Interrupt
1682// 44835 - Maim Interrupt
1683class spell_gen_interrupt : public SpellScriptLoader
1684{
1685    public:
1686        spell_gen_interrupt() : SpellScriptLoader("spell_gen_interrupt") { }
1687
1688        class spell_gen_interrupt_AuraScript : public AuraScript
1689        {
1690            PrepareAuraScript(spell_gen_interrupt_AuraScript);
1691
1692            bool Validate(SpellInfo const* /*spellInfo*/) override
1693            {
1694                if (!sSpellMgr->GetSpellInfo(SPELL_GEN_THROW_INTERRUPT))
1695                    return false;
1696                return true;
1697            }
1698
1699            void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
1700            {
1701                PreventDefaultAction();
1702                GetTarget()->CastSpell(eventInfo.GetProcTarget(), SPELL_GEN_THROW_INTERRUPT, true, NULL, aurEff);
1703            }
1704
1705            void Register() override
1706            {
1707                OnEffectProc += AuraEffectProcFn(spell_gen_interrupt_AuraScript::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
1708            }
1709        };
1710
1711        AuraScript* GetAuraScript() const override
1712        {
1713            return new spell_gen_interrupt_AuraScript();
1714        }
1715};
1716
1717class spell_gen_increase_stats_buff : public SpellScriptLoader
1718{
1719    public:
1720        spell_gen_increase_stats_buff(char const* scriptName) : SpellScriptLoader(scriptName) { }
1721
1722        class spell_gen_increase_stats_buff_SpellScript : public SpellScript
1723        {
1724            PrepareSpellScript(spell_gen_increase_stats_buff_SpellScript);
1725
1726            void HandleDummy(SpellEffIndex /*effIndex*/)
1727            {
1728                if (GetHitUnit()->IsInRaidWith(GetCaster()))
1729                    GetCaster()->CastSpell(GetCaster(), GetEffectValue() + 1, true); // raid buff
1730                else
1731                    GetCaster()->CastSpell(GetHitUnit(), GetEffectValue(), true); // single-target buff
1732            }
1733
1734            void Register() override
1735            {
1736                OnEffectHitTarget += SpellEffectFn(spell_gen_increase_stats_buff_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
1737            }
1738        };
1739
1740        SpellScript* GetSpellScript() const override
1741        {
1742            return new spell_gen_increase_stats_buff_SpellScript();
1743        }
1744};
1745
1746enum GenericLifebloom
1747{
1748    SPELL_HEXLORD_MALACRASS_LIFEBLOOM_FINAL_HEAL        = 43422,
1749    SPELL_TUR_RAGEPAW_LIFEBLOOM_FINAL_HEAL              = 52552,
1750    SPELL_CENARION_SCOUT_LIFEBLOOM_FINAL_HEAL           = 53692,
1751    SPELL_TWISTED_VISAGE_LIFEBLOOM_FINAL_HEAL           = 57763,
1752    SPELL_FACTION_CHAMPIONS_DRU_LIFEBLOOM_FINAL_HEAL    = 66094
1753};
1754
1755class spell_gen_lifebloom : public SpellScriptLoader
1756{
1757    public:
1758        spell_gen_lifebloom(const char* name, uint32 spellId) : SpellScriptLoader(name), _spellId(spellId) { }
1759
1760        class spell_gen_lifebloom_AuraScript : public AuraScript
1761        {
1762            PrepareAuraScript(spell_gen_lifebloom_AuraScript);
1763
1764        public:
1765            spell_gen_lifebloom_AuraScript(uint32 spellId) : AuraScript(), _spellId(spellId) { }
1766
1767            bool Validate(SpellInfo const* /*spellInfo*/) override
1768            {
1769                if (!sSpellMgr->GetSpellInfo(_spellId))
1770                    return false;
1771                return true;
1772            }
1773
1774            void AfterRemove(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
1775            {
1776                // Final heal only on duration end
1777                if (GetTargetApplication()->GetRemoveMode() != AURA_REMOVE_BY_EXPIRE && GetTargetApplication()->GetRemoveMode() != AURA_REMOVE_BY_ENEMY_SPELL)
1778                    return;
1779
1780                // final heal
1781                GetTarget()->CastSpell(GetTarget(), _spellId, true, NULL, aurEff, GetCasterGUID());
1782            }
1783
1784            void Register() override
1785            {
1786                AfterEffectRemove += AuraEffectRemoveFn(spell_gen_lifebloom_AuraScript::AfterRemove, EFFECT_0, SPELL_AURA_PERIODIC_HEAL, AURA_EFFECT_HANDLE_REAL);
1787            }
1788
1789        private:
1790            uint32 _spellId;
1791        };
1792
1793        AuraScript* GetAuraScript() const override
1794        {
1795            return new spell_gen_lifebloom_AuraScript(_spellId);
1796        }
1797
1798    private:
1799        uint32 _spellId;
1800};
1801
1802/* DOCUMENTATION: Charge spells
1803    Charge spells can be classified in four groups:
1804
1805        - Spells on vehicle bar used by players:
1806            + EFFECT_0: SCRIPT_EFFECT
1807            + EFFECT_1: TRIGGER_SPELL
1808            + EFFECT_2: NONE
1809        - Spells cast by player's mounts triggered by script:
1810            + EFFECT_0: CHARGE
1811            + EFFECT_1: TRIGGER_SPELL
1812            + EFFECT_2: APPLY_AURA
1813        - Spells cast by players on the target triggered by script:
1814            + EFFECT_0: SCHOOL_DAMAGE
1815            + EFFECT_1: SCRIPT_EFFECT
1816            + EFFECT_2: NONE
1817        - Spells cast by NPCs on players:
1818            + EFFECT_0: SCHOOL_DAMAGE
1819            + EFFECT_1: CHARGE
1820            + EFFECT_2: SCRIPT_EFFECT
1821
1822    In the following script we handle the SCRIPT_EFFECT and CHARGE
1823        - When handling SCRIPT_EFFECT:
1824            + EFFECT_0: Corresponds to "Spells on vehicle bar used by players" and we make player's mount cast
1825              the charge effect on the current target ("Spells cast by player's mounts triggered by script").
1826            + EFFECT_1 and EFFECT_2: Triggered when "Spells cast by player's mounts triggered by script" hits target,
1827              corresponding to "Spells cast by players on the target triggered by script" and "Spells cast by
1828              NPCs on players" and we check Defend layers and drop a charge of the first found.
1829        - When handling CHARGE:
1830            + Only launched for "Spells cast by player's mounts triggered by script", makes the player cast the
1831              damaging spell on target with a small chance of failing it.
1832*/
1833
1834enum ChargeSpells
1835{
1836    SPELL_CHARGE_DAMAGE_8K5             = 62874,
1837    SPELL_CHARGE_DAMAGE_20K             = 68498,
1838    SPELL_CHARGE_DAMAGE_45K             = 64591,
1839
1840    SPELL_CHARGE_CHARGING_EFFECT_8K5    = 63661,
1841    SPELL_CHARGE_CHARGING_EFFECT_20K_1  = 68284,
1842    SPELL_CHARGE_CHARGING_EFFECT_20K_2  = 68501,
1843    SPELL_CHARGE_CHARGING_EFFECT_45K_1  = 62563,
1844    SPELL_CHARGE_CHARGING_EFFECT_45K_2  = 66481,
1845
1846    SPELL_CHARGE_TRIGGER_FACTION_MOUNTS = 62960,
1847    SPELL_CHARGE_TRIGGER_TRIAL_CHAMPION = 68282,
1848
1849    SPELL_CHARGE_MISS_EFFECT            = 62977,
1850};
1851
1852class spell_gen_mounted_charge: public SpellScriptLoader
1853{
1854    public:
1855        spell_gen_mounted_charge() : SpellScriptLoader("spell_gen_mounted_charge") { }
1856
1857        class spell_gen_mounted_charge_SpellScript : public SpellScript
1858        {
1859            PrepareSpellScript(spell_gen_mounted_charge_SpellScript);
1860
1861            void HandleScriptEffect(SpellEffIndex effIndex)
1862            {
1863                Unit* target = GetHitUnit();
1864
1865                switch (effIndex)
1866                {
1867                    case EFFECT_0: // On spells wich trigger the damaging spell (and also the visual)
1868                    {
1869                        uint32 spellId;
1870
1871                        switch (GetSpellInfo()->Id)
1872                        {
1873                            case SPELL_CHARGE_TRIGGER_TRIAL_CHAMPION:
1874                                spellId = SPELL_CHARGE_CHARGING_EFFECT_20K_1;
1875                                break;
1876                            case SPELL_CHARGE_TRIGGER_FACTION_MOUNTS:
1877                                spellId = SPELL_CHARGE_CHARGING_EFFECT_8K5;
1878                                break;
1879                            default:
1880                                return;
1881                        }
1882
1883                        // If target isn't a training dummy there's a chance of failing the charge
1884                        if (!target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE) && roll_chance_f(12.5f))
1885                            spellId = SPELL_CHARGE_MISS_EFFECT;
1886
1887                        if (Unit* vehicle = GetCaster()->GetVehicleBase())
1888                            vehicle->CastSpell(target, spellId, false);
1889                        else
1890                            GetCaster()->CastSpell(target, spellId, false);
1891                        break;
1892                    }
1893                    case EFFECT_1: // On damaging spells, for removing a defend layer
1894                    case EFFECT_2:
1895                    {
1896                        Unit::AuraApplicationMap const& auras = target->GetAppliedAuras();
1897                        for (Unit::AuraApplicationMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
1898                        {
1899                            if (Aura* aura = itr->second->GetBase())
1900                            {
1901                                SpellInfo const* auraInfo = aura->GetSpellInfo();
1902                                if (auraInfo && auraInfo->SpellIconID == 2007 && aura->HasEffectType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN))
1903                                {
1904                                    aura->ModStackAmount(-1, AURA_REMOVE_BY_ENEMY_SPELL);
1905                                    // Remove dummys from rider (Necessary for updating visual shields)
1906                                    if (Unit* rider = target->GetCharmer())
1907                                        if (Aura* defend = rider->GetAura(aura->GetId()))
1908                                            defend->ModStackAmount(-1, AURA_REMOVE_BY_ENEMY_SPELL);
1909                                    break;
1910                                }
1911                            }
1912                        }
1913                        break;
1914                    }
1915                }
1916            }
1917
1918            void HandleChargeEffect(SpellEffIndex /*effIndex*/)
1919            {
1920                uint32 spellId;
1921
1922                switch (GetSpellInfo()->Id)
1923                {
1924                    case SPELL_CHARGE_CHARGING_EFFECT_8K5:
1925                        spellId = SPELL_CHARGE_DAMAGE_8K5;
1926                        break;
1927                    case SPELL_CHARGE_CHARGING_EFFECT_20K_1:
1928                    case SPELL_CHARGE_CHARGING_EFFECT_20K_2:
1929                        spellId = SPELL_CHARGE_DAMAGE_20K;
1930                        break;
1931                    case SPELL_CHARGE_CHARGING_EFFECT_45K_1:
1932                    case SPELL_CHARGE_CHARGING_EFFECT_45K_2:
1933                        spellId = SPELL_CHARGE_DAMAGE_45K;
1934                        break;
1935                    default:
1936                        return;
1937                }
1938
1939                if (Unit* rider = GetCaster()->GetCharmer())
1940                    rider->CastSpell(GetHitUnit(), spellId, false);
1941                else
1942                    GetCaster()->CastSpell(GetHitUnit(), spellId, false);
1943            }
1944
1945            void Register() override
1946            {
1947                SpellInfo const* spell = sSpellMgr->EnsureSpellInfo(m_scriptSpellId);
1948
1949                if (spell->HasEffect(SPELL_EFFECT_SCRIPT_EFFECT))
1950                    OnEffectHitTarget += SpellEffectFn(spell_gen_mounted_charge_SpellScript::HandleScriptEffect, EFFECT_FIRST_FOUND, SPELL_EFFECT_SCRIPT_EFFECT);
1951
1952                if (spell->Effects[EFFECT_0].Effect == SPELL_EFFECT_CHARGE)
1953                    OnEffectHitTarget += SpellEffectFn(spell_gen_mounted_charge_SpellScript::HandleChargeEffect, EFFECT_0, SPELL_EFFECT_CHARGE);
1954            }
1955        };
1956
1957        SpellScript* GetSpellScript() const override
1958        {
1959            return new spell_gen_mounted_charge_SpellScript();
1960        }
1961};
1962
1963enum Netherbloom
1964{
1965    SPELL_NETHERBLOOM_POLLEN_1      = 28703
1966};
1967
1968// 28702 - Netherbloom
1969class spell_gen_netherbloom : public SpellScriptLoader
1970{
1971    public:
1972        spell_gen_netherbloom() : SpellScriptLoader("spell_gen_netherbloom") { }
1973
1974        class spell_gen_netherbloom_SpellScript : public SpellScript
1975        {
1976            PrepareSpellScript(spell_gen_netherbloom_SpellScript);
1977
1978            bool Validate(SpellInfo const* /*spellInfo*/) override
1979            {
1980                for (uint8 i = 0; i < 5; ++i)
1981                    if (!sSpellMgr->GetSpellInfo(SPELL_NETHERBLOOM_POLLEN_1 + i))
1982                        return false;
1983                return true;
1984            }
1985
1986            void HandleScript(SpellEffIndex effIndex)
1987            {
1988                PreventHitDefaultEffect(effIndex);
1989
1990                if (Unit* target = GetHitUnit())
1991                {
1992                    // 25% chance of casting a random buff
1993                    if (roll_chance_i(75))
1994                        return;
1995
1996                    // triggered spells are 28703 to 28707
1997                    // Note: some sources say, that there was the possibility of
1998                    //       receiving a debuff. However, this seems to be removed by a patch.
1999
2000                    // don't overwrite an existing aura
2001                    for (uint8 i = 0; i < 5; ++i)
2002                        if (target->HasAura(SPELL_NETHERBLOOM_POLLEN_1 + i))
2003                            return;
2004
2005                    target->CastSpell(target, SPELL_NETHERBLOOM_POLLEN_1 + urand(0, 4), true);
2006                }
2007            }
2008
2009            void Register() override
2010            {
2011                OnEffectHitTarget += SpellEffectFn(spell_gen_netherbloom_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
2012            }
2013        };
2014
2015        SpellScript* GetSpellScript() const override
2016        {
2017            return new spell_gen_netherbloom_SpellScript();
2018        }
2019};
2020
2021enum NightmareVine
2022{
2023    SPELL_NIGHTMARE_POLLEN      = 28721
2024};
2025
2026// 28720 - Nightmare Vine
2027class spell_gen_nightmare_vine : public SpellScriptLoader
2028{
2029    public:
2030        spell_gen_nightmare_vine() : SpellScriptLoader("spell_gen_nightmare_vine") { }
2031
2032        class spell_gen_nightmare_vine_SpellScript : public SpellScript
2033        {
2034            PrepareSpellScript(spell_gen_nightmare_vine_SpellScript);
2035
2036            bool Validate(SpellInfo const* /*spellInfo*/) override
2037            {
2038                if (!sSpellMgr->GetSpellInfo(SPELL_NIGHTMARE_POLLEN))
2039                    return false;
2040                return true;
2041            }
2042
2043            void HandleScript(SpellEffIndex effIndex)
2044            {
2045                PreventHitDefaultEffect(effIndex);
2046
2047                if (Unit* target = GetHitUnit())
2048                {
2049                    // 25% chance of casting Nightmare Pollen
2050                    if (roll_chance_i(25))
2051                        target->CastSpell(target, SPELL_NIGHTMARE_POLLEN, true);
2052                }
2053            }
2054
2055            void Register() override
2056            {
2057                OnEffectHitTarget += SpellEffectFn(spell_gen_nightmare_vine_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
2058            }
2059        };
2060
2061        SpellScript* GetSpellScript() const override
2062        {
2063            return new spell_gen_nightmare_vine_SpellScript();
2064        }
2065};
2066
2067enum ObsidianArmor
2068{
2069    SPELL_GEN_OBSIDIAN_ARMOR_HOLY       = 27536,
2070    SPELL_GEN_OBSIDIAN_ARMOR_FIRE       = 27533,
2071    SPELL_GEN_OBSIDIAN_ARMOR_NATURE     = 27538,
2072    SPELL_GEN_OBSIDIAN_ARMOR_FROST      = 27534,
2073    SPELL_GEN_OBSIDIAN_ARMOR_SHADOW     = 27535,
2074    SPELL_GEN_OBSIDIAN_ARMOR_ARCANE     = 27540
2075};
2076
2077// 27539 - Obsidian Armor
2078class spell_gen_obsidian_armor : public SpellScriptLoader
2079{
2080    public:
2081        spell_gen_obsidian_armor() : SpellScriptLoader("spell_gen_obsidian_armor") { }
2082
2083        class spell_gen_obsidian_armor_AuraScript : public AuraScript
2084        {
2085            PrepareAuraScript(spell_gen_obsidian_armor_AuraScript);
2086
2087            bool Validate(SpellInfo const* /*spellInfo*/) override
2088            {
2089                if (!sSpellMgr->GetSpellInfo(SPELL_GEN_OBSIDIAN_ARMOR_HOLY) ||
2090                    !sSpellMgr->GetSpellInfo(SPELL_GEN_OBSIDIAN_ARMOR_FIRE) ||
2091                    !sSpellMgr->GetSpellInfo(SPELL_GEN_OBSIDIAN_ARMOR_NATURE) ||
2092                    !sSpellMgr->GetSpellInfo(SPELL_GEN_OBSIDIAN_ARMOR_FROST) ||
2093                    !sSpellMgr->GetSpellInfo(SPELL_GEN_OBSIDIAN_ARMOR_SHADOW) ||
2094                    !sSpellMgr->GetSpellInfo(SPELL_GEN_OBSIDIAN_ARMOR_ARCANE))
2095                    return false;
2096                return true;
2097            }
2098
2099            bool CheckProc(ProcEventInfo& eventInfo)
2100            {
2101                if (eventInfo.GetDamageInfo()->GetSpellInfo()) // eventInfo.GetSpellInfo()
2102                    return false;
2103
2104                if (GetFirstSchoolInMask(eventInfo.GetSchoolMask()) == SPELL_SCHOOL_NORMAL)
2105                    return false;
2106
2107                return true;
2108            }
2109
2110            void OnProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo)
2111            {
2112                PreventDefaultAction();
2113
2114                uint32 spellId = 0;
2115                switch (GetFirstSchoolInMask(eventInfo.GetSchoolMask()))
2116                {
2117                    case SPELL_SCHOOL_HOLY:
2118                        spellId = SPELL_GEN_OBSIDIAN_ARMOR_HOLY;
2119                        break;
2120                    case SPELL_SCHOOL_FIRE:
2121                        spellId = SPELL_GEN_OBSIDIAN_ARMOR_FIRE;
2122                        break;
2123                    case SPELL_SCHOOL_NATURE:
2124                        spellId = SPELL_GEN_OBSIDIAN_ARMOR_NATURE;
2125                        break;
2126                    case SPELL_SCHOOL_FROST:
2127                        spellId = SPELL_GEN_OBSIDIAN_ARMOR_FROST;
2128                        break;
2129                    case SPELL_SCHOOL_SHADOW:
2130                        spellId = SPELL_GEN_OBSIDIAN_ARMOR_SHADOW;
2131                        break;
2132                    case SPELL_SCHOOL_ARCANE:
2133                        spellId = SPELL_GEN_OBSIDIAN_ARMOR_ARCANE;
2134                        break;
2135                    default:
2136                        return;
2137                }
2138                GetTarget()->CastSpell(GetTarget(), spellId, true, NULL, aurEff);
2139            }
2140
2141            void Register() override
2142            {
2143                DoCheckProc += AuraCheckProcFn(spell_gen_obsidian_armor_AuraScript::CheckProc);
2144                OnEffectProc += AuraEffectProcFn(spell_gen_obsidian_armor_AuraScript::OnProc, EFFECT_0, SPELL_AURA_DUMMY);
2145            }
2146        };
2147
2148        AuraScript* GetAuraScript() const override
2149        {
2150            return new spell_gen_obsidian_armor_AuraScript();
2151        }
2152};
2153
2154enum TournamentPennantSpells
2155{
2156    SPELL_PENNANT_STORMWIND_ASPIRANT        = 62595,
2157    SPELL_PENNANT_STORMWIND_VALIANT         = 62596,
2158    SPELL_PENNANT_STORMWIND_CHAMPION        = 62594,
2159    SPELL_PENNANT_GNOMEREGAN_ASPIRANT       = 63394,
2160    SPELL_PENNANT_GNOMEREGAN_VALIANT        = 63395,
2161    SPELL_PENNANT_GNOMEREGAN_CHAMPION       = 63396,
2162    SPELL_PENNANT_SEN_JIN_ASPIRANT          = 63397,
2163    SPELL_PENNANT_SEN_JIN_VALIANT           = 63398,
2164    SPELL_PENNANT_SEN_JIN_CHAMPION          = 63399,
2165    SPELL_PENNANT_SILVERMOON_ASPIRANT       = 63401,
2166    SPELL_PENNANT_SILVERMOON_VALIANT        = 63402,
2167    SPELL_PENNANT_SILVERMOON_CHAMPION       = 63403,
2168    SPELL_PENNANT_DARNASSUS_ASPIRANT        = 63404,
2169    SPELL_PENNANT_DARNASSUS_VALIANT         = 63405,
2170    SPELL_PENNANT_DARNASSUS_CHAMPION        = 63406,
2171    SPELL_PENNANT_EXODAR_ASPIRANT           = 63421,
2172    SPELL_PENNANT_EXODAR_VALIANT            = 63422,
2173    SPELL_PENNANT_EXODAR_CHAMPION           = 63423,
2174    SPELL_PENNANT_IRONFORGE_ASPIRANT        = 63425,
2175    SPELL_PENNANT_IRONFORGE_VALIANT         = 63426,
2176    SPELL_PENNANT_IRONFORGE_CHAMPION        = 63427,
2177    SPELL_PENNANT_UNDERCITY_ASPIRANT        = 63428,
2178    SPELL_PENNANT_UNDERCITY_VALIANT         = 63429,
2179    SPELL_PENNANT_UNDERCITY_CHAMPION        = 63430,
2180    SPELL_PENNANT_ORGRIMMAR_ASPIRANT        = 63431,
2181    SPELL_PENNANT_ORGRIMMAR_VALIANT         = 63432,
2182    SPELL_PENNANT_ORGRIMMAR_CHAMPION        = 63433,
2183    SPELL_PENNANT_THUNDER_BLUFF_ASPIRANT    = 63434,
2184    SPELL_PENNANT_THUNDER_BLUFF_VALIANT     = 63435,
2185    SPELL_PENNANT_THUNDER_BLUFF_CHAMPION    = 63436,
2186    SPELL_PENNANT_ARGENT_CRUSADE_ASPIRANT   = 63606,
2187    SPELL_PENNANT_ARGENT_CRUSADE_VALIANT    = 63500,
2188    SPELL_PENNANT_ARGENT_CRUSADE_CHAMPION   = 63501,
2189    SPELL_PENNANT_EBON_BLADE_ASPIRANT       = 63607,
2190    SPELL_PENNANT_EBON_BLADE_VALIANT        = 63608,
2191    SPELL_PENNANT_EBON_BLADE_CHAMPION       = 63609
2192};
2193
2194enum TournamentMounts
2195{
2196    NPC_STORMWIND_STEED                     = 33217,
2197    NPC_IRONFORGE_RAM                       = 33316,
2198    NPC_GNOMEREGAN_MECHANOSTRIDER           = 33317,
2199    NPC_EXODAR_ELEKK                        = 33318,
2200    NPC_DARNASSIAN_NIGHTSABER               = 33319,
2201    NPC_ORGRIMMAR_WOLF                      = 33320,
2202    NPC_DARK_SPEAR_RAPTOR                   = 33321,
2203    NPC_THUNDER_BLUFF_KODO                  = 33322,
2204    NPC_SILVERMOON_HAWKSTRIDER              = 33323,
2205    NPC_FORSAKEN_WARHORSE                   = 33324,
2206    NPC_ARGENT_WARHORSE                     = 33782,
2207    NPC_ARGENT_STEED_ASPIRANT               = 33845,
2208    NPC_ARGENT_HAWKSTRIDER_ASPIRANT         = 33844
2209};
2210
2211enum TournamentQuestsAchievements
2212{
2213    ACHIEVEMENT_CHAMPION_STORMWIND          = 2781,
2214    ACHIEVEMENT_CHAMPION_DARNASSUS          = 2777,
2215    ACHIEVEMENT_CHAMPION_IRONFORGE          = 2780,
2216    ACHIEVEMENT_CHAMPION_GNOMEREGAN         = 2779,
2217    ACHIEVEMENT_CHAMPION_THE_EXODAR         = 2778,
2218    ACHIEVEMENT_CHAMPION_ORGRIMMAR          = 2783,
2219    ACHIEVEMENT_CHAMPION_SEN_JIN            = 2784,
2220    ACHIEVEMENT_CHAMPION_THUNDER_BLUFF      = 2786,
2221    ACHIEVEMENT_CHAMPION_UNDERCITY          = 2787,
2222    ACHIEVEMENT_CHAMPION_SILVERMOON         = 2785,
2223    ACHIEVEMENT_ARGENT_VALOR                = 2758,
2224    ACHIEVEMENT_CHAMPION_ALLIANCE           = 2782,
2225    ACHIEVEMENT_CHAMPION_HORDE              = 2788,
2226
2227    QUEST_VALIANT_OF_STORMWIND              = 13593,
2228    QUEST_A_VALIANT_OF_STORMWIND            = 13684,
2229    QUEST_VALIANT_OF_DARNASSUS              = 13706,
2230    QUEST_A_VALIANT_OF_DARNASSUS            = 13689,
2231    QUEST_VALIANT_OF_IRONFORGE              = 13703,
2232    QUEST_A_VALIANT_OF_IRONFORGE            = 13685,
2233    QUEST_VALIANT_OF_GNOMEREGAN             = 13704,
2234    QUEST_A_VALIANT_OF_GNOMEREGAN           = 13688,
2235    QUEST_VALIANT_OF_THE_EXODAR             = 13705,
2236    QUEST_A_VALIANT_OF_THE_EXODAR           = 13690,
2237    QUEST_VALIANT_OF_ORGRIMMAR              = 13707,
2238    QUEST_A_VALIANT_OF_ORGRIMMAR            = 13691,
2239    QUEST_VALIANT_OF_SEN_JIN                = 13708,
2240    QUEST_A_VALIANT_OF_SEN_JIN              = 13693,
2241    QUEST_VALIANT_OF_THUNDER_BLUFF          = 13709,
2242    QUEST_A_VALIANT_OF_THUNDER_BLUFF        = 13694,
2243    QUEST_VALIANT_OF_UNDERCITY              = 13710,
2244    QUEST_A_VALIANT_OF_UNDERCITY            = 13695,
2245    QUEST_VALIANT_OF_SILVERMOON             = 13711,
2246    QUEST_A_VALIANT_OF_SILVERMOON           = 13696
2247};
2248
2249class spell_gen_on_tournament_mount : public SpellScriptLoader
2250{
2251    public:
2252        spell_gen_on_tournament_mount() : SpellScriptLoader("spell_gen_on_tournament_mount") { }
2253
2254        class spell_gen_on_tournament_mount_AuraScript : public AuraScript
2255        {
2256            PrepareAuraScript(spell_gen_on_tournament_mount_AuraScript);
2257
2258        public:
2259            spell_gen_on_tournament_mount_AuraScript()
2260            {
2261                _pennantSpellId = 0;
2262            }
2263
2264        private:
2265            uint32 _pennantSpellId;
2266
2267            bool Load() override
2268            {
2269                return GetCaster() && GetCaster()->GetTypeId() == TYPEID_PLAYER;
2270            }
2271
2272            void HandleApplyEffect(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
2273            {
2274                if (Unit* caster = GetCaster())
2275                {
2276                    if (Unit* vehicle = caster->GetVehicleBase())
2277                    {
2278                        _pennantSpellId = GetPennatSpellId(caster->ToPlayer(), vehicle);
2279                        caster->CastSpell(caster, _pennantSpellId, true);
2280                    }
2281                }
2282            }
2283
2284            void HandleRemoveEffect(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
2285            {
2286                if (Unit* caster = GetCaster())
2287                    caster->RemoveAurasDueToSpell(_pennantSpellId);
2288            }
2289
2290            uint32 GetPennatSpellId(Player* player, Unit* mount)
2291            {
2292                switch (mount->GetEntry())
2293                {
2294                    case NPC_ARGENT_STEED_ASPIRANT:
2295                    case NPC_STORMWIND_STEED:
2296                    {
2297                        if (player->HasAchieved(ACHIEVEMENT_CHAMPION_STORMWIND))
2298                            return SPELL_PENNANT_STORMWIND_CHAMPION;
2299                        else if (player->GetQuestRewardStatus(QUEST_VALIANT_OF_STORMWIND) || player->GetQuestRewardStatus(QUEST_A_VALIANT_OF_STORMWIND))
2300                            return SPELL_PENNANT_STORMWIND_VALIANT;
2301                        else
2302                            return SPELL_PENNANT_STORMWIND_ASPIRANT;
2303                    }
2304                    case NPC_GNOMEREGAN_MECHANOSTRIDER:
2305                    {
2306                        if (player->HasAchieved(ACHIEVEMENT_CHAMPION_GNOMEREGAN))
2307                            return SPELL_PENNANT_GNOMEREGAN_CHAMPION;
2308                        else if (player->GetQuestRewardStatus(QUEST_VALIANT_OF_GNOMEREGAN) || player->GetQuestRewardStatus(QUEST_A_VALIANT_OF_GNOMEREGAN))
2309                            return SPELL_PENNANT_GNOMEREGAN_VALIANT;
2310                        else
2311                            return SPELL_PENNANT_GNOMEREGAN_ASPIRANT;
2312                    }
2313                    case NPC_DARK_SPEAR_RAPTOR:
2314                    {
2315                        if (player->HasAchieved(ACHIEVEMENT_CHAMPION_SEN_JIN))
2316                            return SPELL_PENNANT_SEN_JIN_CHAMPION;
2317                        else if (player->GetQuestRewardStatus(QUEST_VALIANT_OF_SEN_JIN) || player->GetQuestRewardStatus(QUEST_A_VALIANT_OF_SEN_JIN))
2318                            return SPELL_PENNANT_SEN_JIN_VALIANT;
2319                        else
2320                            return SPELL_PENNANT_SEN_JIN_ASPIRANT;
2321                    }
2322                    case NPC_ARGENT_HAWKSTRIDER_ASPIRANT:
2323                    case NPC_SILVERMOON_HAWKSTRIDER:
2324                    {
2325                        if (player->HasAchieved(ACHIEVEMENT_CHAMPION_SILVERMOON))
2326                            return SPELL_PENNANT_SILVERMOON_CHAMPION;
2327                        else if (player->GetQuestRewardStatus(QUEST_VALIANT_OF_SILVERMOON) || player->GetQuestRewardStatus(QUEST_A_VALIANT_OF_SILVERMOON))
2328                            return SPELL_PENNANT_SILVERMOON_VALIANT;
2329                        else
2330                            return SPELL_PENNANT_SILVERMOON_ASPIRANT;
2331                    }
2332                    case NPC_DARNASSIAN_NIGHTSABER:
2333                    {
2334                        if (player->HasAchieved(ACHIEVEMENT_CHAMPION_DARNASSUS))
2335                            return SPELL_PENNANT_DARNASSUS_CHAMPION;
2336                        else if (player->GetQuestRewardStatus(QUEST_VALIANT_OF_DARNASSUS) || player->GetQuestRewardStatus(QUEST_A_VALIANT_OF_DARNASSUS))
2337                            return SPELL_PENNANT_DARNASSUS_VALIANT;
2338                        else
2339                            return SPELL_PENNANT_DARNASSUS_ASPIRANT;
2340                    }
2341                    case NPC_EXODAR_ELEKK:
2342                    {
2343                        if (player->HasAchieved(ACHIEVEMENT_CHAMPION_THE_EXODAR))
2344                            return SPELL_PENNANT_EXODAR_CHAMPION;
2345                        else if (player->GetQuestRewardStatus(QUEST_VALIANT_OF_THE_EXODAR) || player->GetQuestRewardStatus(QUEST_A_VALIANT_OF_THE_EXODAR))
2346                            return SPELL_PENNANT_EXODAR_VALIANT;
2347                        else
2348                            return SPELL_PENNANT_EXODAR_ASPIRANT;
2349                    }
2350                    case NPC_IRONFORGE_RAM:
2351                    {
2352                        if (player->HasAchieved(ACHIEVEMENT_CHAMPION_IRONFORGE))
2353                            return SPELL_PENNANT_IRONFORGE_CHAMPION;
2354                        else if (player->GetQuestRewardStatus(QUEST_VALIANT_OF_IRONFORGE) || player->GetQuestRewardStatus(QUEST_A_VALIANT_OF_IRONFORGE))
2355                            return SPELL_PENNANT_IRONFORGE_VALIANT;
2356                        else
2357                            return SPELL_PENNANT_IRONFORGE_ASPIRANT;
2358                    }
2359                    case NPC_FORSAKEN_WARHORSE:
2360                    {
2361                        if (player->HasAchieved(ACHIEVEMENT_CHAMPION_UNDERCITY))
2362                            return SPELL_PENNANT_UNDERCITY_CHAMPION;
2363                        else if (player->GetQuestRewardStatus(QUEST_VALIANT_OF_UNDERCITY) || player->GetQuestRewardStatus(QUEST_A_VALIANT_OF_UNDERCITY))
2364                            return SPELL_PENNANT_UNDERCITY_VALIANT;
2365                        else
2366                            return SPELL_PENNANT_UNDERCITY_ASPIRANT;
2367                    }
2368                    case NPC_ORGRIMMAR_WOLF:
2369                    {
2370                        if (player->HasAchieved(ACHIEVEMENT_CHAMPION_ORGRIMMAR))
2371                            return SPELL_PENNANT_ORGRIMMAR_CHAMPION;
2372                        else if (player->GetQuestRewardStatus(QUEST_VALIANT_OF_ORGRIMMAR) || player->GetQuestRewardStatus(QUEST_A_VALIANT_OF_ORGRIMMAR))
2373                            return SPELL_PENNANT_ORGRIMMAR_VALIANT;
2374                        else
2375                            return SPELL_PENNANT_ORGRIMMAR_ASPIRANT;
2376                    }
2377                    case NPC_THUNDER_BLUFF_KODO:
2378                    {
2379                        if (player->HasAchieved(ACHIEVEMENT_CHAMPION_THUNDER_BLUFF))
2380                            return SPELL_PENNANT_THUNDER_BLUFF_CHAMPION;
2381                        else if (player->GetQuestRewardStatus(QUEST_VALIANT_OF_THUNDER_BLUFF) || player->GetQuestRewardStatus(QUEST_A_VALIANT_OF_THUNDER_BLUFF))
2382                            return SPELL_PENNANT_THUNDER_BLUFF_VALIANT;
2383                        else
2384                            return SPELL_PENNANT_THUNDER_BLUFF_ASPIRANT;
2385                    }
2386                    case NPC_ARGENT_WARHORSE:
2387                    {
2388                        if (player->HasAchieved(ACHIEVEMENT_CHAMPION_ALLIANCE) || player->HasAchieved(ACHIEVEMENT_CHAMPION_HORDE))
2389                            return player->getClass() == CLASS_DEATH_KNIGHT ? SPELL_PENNANT_EBON_BLADE_CHAMPION : SPELL_PENNANT_ARGENT_CRUSADE_CHAMPION;
2390                        else if (player->HasAchieved(ACHIEVEMENT_ARGENT_VALOR))
2391                            return player->getClass() == CLASS_DEATH_KNIGHT ? SPELL_PENNANT_EBON_BLADE_VALIANT : SPELL_PENNANT_ARGENT_CRUSADE_VALIANT;
2392                        else
2393                            return player->getClass() == CLASS_DEATH_KNIGHT ? SPELL_PENNANT_EBON_BLADE_ASPIRANT : SPELL_PENNANT_ARGENT_CRUSADE_ASPIRANT;
2394                    }
2395                    default:
2396                        return 0;
2397                }
2398            }
2399
2400            void Register() override
2401            {
2402                AfterEffectApply += AuraEffectApplyFn(spell_gen_on_tournament_mount_AuraScript::HandleApplyEffect, EFFECT_0, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL_OR_REAPPLY_MASK);
2403                OnEffectRemove += AuraEffectRemoveFn(spell_gen_on_tournament_mount_AuraScript::HandleRemoveEffect, EFFECT_0, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL_OR_REAPPLY_MASK);
2404            }
2405        };
2406
2407        AuraScript* GetAuraScript() const override
2408        {
2409            return new spell_gen_on_tournament_mount_AuraScript();
2410        }
2411};
2412
2413class spell_gen_oracle_wolvar_reputation : public SpellScriptLoader
2414{
2415    public:
2416        spell_gen_oracle_wolvar_reputation() : SpellScriptLoader("spell_gen_oracle_wolvar_reputation") { }
2417
2418        class spell_gen_oracle_wolvar_reputation_SpellScript : public SpellScript
2419        {
2420            PrepareSpellScript(spell_gen_oracle_wolvar_reputation_SpellScript);
2421
2422            bool Load() override
2423            {
2424                return GetCaster()->GetTypeId() == TYPEID_PLAYER;
2425            }
2426
2427            void HandleDummy(SpellEffIndex effIndex)
2428            {
2429                Player* player = GetCaster()->ToPlayer();
2430                uint32 factionId = GetSpellInfo()->Effects[effIndex].CalcValue();
2431                int32  repChange = GetSpellInfo()->Effects[EFFECT_1].CalcValue();
2432
2433                FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId);
2434                if (!factionEntry)
2435                    return;
2436
2437                // Set rep to baserep + basepoints (expecting spillover for oposite faction -> become hated)
2438                // Not when player already has equal or higher rep with this faction
2439                if (player->GetReputationMgr().GetReputation(factionEntry) < repChange)
2440                    player->GetReputationMgr().SetReputation(factionEntry, repChange);
2441
2442                // EFFECT_INDEX_2 most likely update at war state, we already handle this in SetReputation
2443            }
2444
2445            void Register() override
2446            {
2447                OnEffectHit += SpellEffectFn(spell_gen_oracle_wolvar_reputation_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
2448            }
2449        };
2450
2451        SpellScript* GetSpellScript() const override
2452        {
2453            return new spell_gen_oracle_wolvar_reputation_SpellScript();
2454        }
2455};
2456
2457enum OrcDisguiseSpells
2458{
2459    SPELL_ORC_DISGUISE_TRIGGER       = 45759,
2460    SPELL_ORC_DISGUISE_MALE          = 45760,
2461    SPELL_ORC_DISGUISE_FEMALE        = 45762
2462};
2463
2464class spell_gen_orc_disguise : public SpellScriptLoader
2465{
2466    public:
2467        spell_gen_orc_disguise() : SpellScriptLoader("spell_gen_orc_disguise") { }
2468
2469        class spell_gen_orc_disguise_SpellScript : public SpellScript
2470        {
2471            PrepareSpellScript(spell_gen_orc_disguise_SpellScript);
2472
2473            bool Validate(SpellInfo const* /*spellInfo*/) override
2474            {
2475                if (!sSpellMgr->GetSpellInfo(SPELL_ORC_DISGUISE_TRIGGER) ||
2476                    !sSpellMgr->GetSpellInfo(SPELL_ORC_DISGUISE_MALE) ||
2477                    !sSpellMgr->GetSpellInfo(SPELL_ORC_DISGUISE_FEMALE))
2478                    return false;
2479                return true;
2480            }
2481
2482            void HandleScript(SpellEffIndex /*effIndex*/)
2483            {
2484                Unit* caster = GetCaster();
2485                if (Player* target = GetHitPlayer())
2486                {
2487                    uint8 gender = target->getGender();
2488                    if (!gender)
2489                        caster->CastSpell(target, SPELL_ORC_DISGUISE_MALE, true);
2490                    else
2491                        caster->CastSpell(target, SPELL_ORC_DISGUISE_FEMALE, true);
2492                }
2493            }
2494
2495            void Register() override
2496            {
2497                OnEffectHitTarget += SpellEffectFn(spell_gen_orc_disguise_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
2498            }
2499        };
2500
2501        SpellScript* GetSpellScript() const override
2502        {
2503            return new spell_gen_orc_disguise_SpellScript();
2504        }
2505};
2506
2507enum ParachuteSpells
2508{
2509    SPELL_PARACHUTE         = 45472,
2510    SPELL_PARACHUTE_BUFF    = 44795,
2511};
2512
2513// 45472 Parachute
2514class spell_gen_parachute : public SpellScriptLoader
2515{
2516    public:
2517        spell_gen_parachute() : SpellScriptLoader("spell_gen_parachute") { }
2518
2519        class spell_gen_parachute_AuraScript : public AuraScript
2520        {
2521            PrepareAuraScript(spell_gen_parachute_AuraScript);
2522
2523            bool Validate(SpellInfo const* /*spellInfo*/) override
2524            {
2525                if (!sSpellMgr->GetSpellInfo(SPELL_PARACHUTE) ||
2526                    !sSpellMgr->GetSpellInfo(SPELL_PARACHUTE_BUFF))
2527                    return false;
2528                return true;
2529            }
2530
2531            void HandleEffectPeriodic(AuraEffect const* /*aurEff*/)
2532            {
2533                if (Player* target = GetTarget()->ToPlayer())
2534                    if (target->IsFalling())
2535                    {
2536                        target->RemoveAurasDueToSpell(SPELL_PARACHUTE);
2537                        target->CastSpell(target, SPELL_PARACHUTE_BUFF, true);
2538                    }
2539            }
2540
2541            void Register() override
2542            {
2543                OnEffectPeriodic += AuraEffectPeriodicFn(spell_gen_parachute_AuraScript::HandleEffectPeriodic, EFFECT_0, SPELL_AURA_PERIODIC_DUMMY);
2544            }
2545        };
2546
2547        AuraScript* GetAuraScript() const override
2548        {
2549            return new spell_gen_parachute_AuraScript();
2550        }
2551};
2552
2553enum PetSummoned
2554{
2555    NPC_DOOMGUARD       = 11859,
2556    NPC_INFERNAL        = 89,
2557    NPC_IMP             = 416
2558};
2559
2560class spell_gen_pet_summoned : public SpellScriptLoader
2561{
2562    public:
2563        spell_gen_pet_summoned() : SpellScriptLoader("spell_gen_pet_summoned") { }
2564
2565        class spell_gen_pet_summoned_SpellScript : public SpellScript
2566        {
2567            PrepareSpellScript(spell_gen_pet_summoned_SpellScript);
2568
2569            bool Load() override
2570            {
2571                return GetCaster()->GetTypeId() == TYPEID_PLAYER;
2572            }
2573
2574            void HandleScript(SpellEffIndex /*effIndex*/)
2575            {
2576                Player* player = GetCaster()->ToPlayer();
2577                if (player->GetLastPetNumber())
2578                {
2579                    PetType newPetType = (player->getClass() == CLASS_HUNTER) ? HUNTER_PET : SUMMON_PET;
2580                    Pet* newPet = new Pet(player, newPetType);
2581                    if (newPet->LoadPetFromDB(player, 0, player->GetLastPetNumber(), true))
2582                    {
2583                        // revive the pet if it is dead
2584                        if (newPet->getDeathState() == DEAD)
2585                            newPet->setDeathState(ALIVE);
2586
2587                        newPet->SetFullHealth();
2588                        newPet->SetPower(newPet->getPowerType(), newPet->GetMaxPower(newPet->getPowerType()));
2589
2590                        switch (newPet->GetEntry())
2591                        {
2592                            case NPC_DOOMGUARD:
2593                            case NPC_INFERNAL:
2594                                newPet->SetEntry(NPC_IMP);
2595                                break;
2596                            default:
2597                                break;
2598                        }
2599                    }
2600                    else
2601                        delete newPet;
2602                }
2603            }
2604
2605            void Register() override
2606            {
2607                OnEffectHitTarget += SpellEffectFn(spell_gen_pet_summoned_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
2608            }
2609        };
2610
2611        SpellScript* GetSpellScript() const override
2612        {
2613            return new spell_gen_pet_summoned_SpellScript();
2614        }
2615};
2616
2617class spell_gen_profession_research : public SpellScriptLoader
2618{
2619    public:
2620        spell_gen_profession_research() : SpellScriptLoader("spell_gen_profession_research") { }
2621
2622        class spell_gen_profession_research_SpellScript : public SpellScript
2623        {
2624            PrepareSpellScript(spell_gen_profession_research_SpellScript);
2625
2626            bool Load() override
2627            {
2628                return GetCaster()->GetTypeId() == TYPEID_PLAYER;
2629            }
2630
2631            SpellCastResult CheckRequirement()
2632            {
2633                if (HasDiscoveredAllSpells(GetSpellInfo()->Id, GetCaster()->ToPlayer()))
2634                {
2635                    SetCustomCastResultMessage(SPELL_CUSTOM_ERROR_NOTHING_TO_DISCOVER);
2636                    return SPELL_FAILED_CUSTOM_ERROR;
2637                }
2638
2639                return SPELL_CAST_OK;
2640            }
2641
2642            void HandleScript(SpellEffIndex /*effIndex*/)
2643            {
2644                Player* caster = GetCaster()->ToPlayer();
2645                uint32 spellId = GetSpellInfo()->Id;
2646
2647                // learn random explicit discovery recipe (if any)
2648                if (uint32 discoveredSpellId = GetExplicitDiscoverySpell(spellId, caster))
2649                    caster->LearnSpell(discoveredSpellId, false);
2650
2651                caster->UpdateCraftSkill(spellId);
2652            }
2653
2654            void Register() override
2655            {
2656                OnCheckCast += SpellCheckCastFn(spell_gen_profession_research_SpellScript::CheckRequirement);
2657                OnEffectHitTarget += SpellEffectFn(spell_gen_profession_research_SpellScript::HandleScript, EFFECT_1, SPELL_EFFECT_SCRIPT_EFFECT);
2658            }
2659        };
2660
2661        SpellScript* GetSpellScript() const override
2662        {
2663            return new spell_gen_profession_research_SpellScript();
2664        }
2665};
2666
2667class spell_gen_remove_flight_auras : public SpellScriptLoader
2668{
2669    public:
2670        spell_gen_remove_flight_auras() : SpellScriptLoader("spell_gen_remove_flight_auras") { }
2671
2672        class spell_gen_remove_flight_auras_SpellScript : public SpellScript
2673        {
2674            PrepareSpellScript(spell_gen_remove_flight_auras_SpellScript);
2675
2676            void HandleScript(SpellEffIndex /*effIndex*/)
2677            {
2678                if (Unit* target = GetHitUnit())
2679                {
2680                    target->RemoveAurasByType(SPELL_AURA_FLY);
2681                    target->RemoveAurasByType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED);
2682                }
2683            }
2684
2685            void Register() override
2686            {
2687                OnEffectHitTarget += SpellEffectFn(spell_gen_remove_flight_auras_SpellScript::HandleScript, EFFECT_1, SPELL_EFFECT_SCRIPT_EFFECT);
2688            }
2689        };
2690
2691        SpellScript* GetSpellScript() const override
2692        {
2693            return new spell_gen_remove_flight_auras_SpellScript();
2694        }
2695};
2696
2697enum Replenishment
2698{
2699    SPELL_REPLENISHMENT             = 57669,
2700    SPELL_INFINITE_REPLENISHMENT    = 61782
2701};
2702
2703class ReplenishmentCheck
2704{
2705public:
2706    bool operator()(WorldObject* obj) const
2707    {
2708        if (Unit* target = obj->ToUnit())
2709            return target->getPowerType() != POWER_MANA;
2710
2711        return true;
2712    }
2713};
2714
2715class spell_gen_replenishment : public SpellScriptLoader
2716{
2717    public:
2718        spell_gen_replenishment() : SpellScriptLoader("spell_gen_replenishment") { }
2719
2720        class spell_gen_replenishment_SpellScript : public SpellScript
2721        {
2722            PrepareSpellScript(spell_gen_replenishment_SpellScript);
2723
2724            void RemoveInvalidTargets(std::list<WorldObject*>& targets)
2725            {
2726                // In arenas Replenishment may only affect the caster
2727                if (Player* caster = GetCaster()->ToPlayer())
2728                {
2729                    if (caster->InArena())
2730                    {
2731                        targets.clear();
2732                        targets.push_back(caster);
2733                        return;
2734                    }
2735                }
2736
2737                targets.remove_if(ReplenishmentCheck());
2738
2739                uint8 const maxTargets = 10;
2740
2741                if (targets.size() > maxTargets)
2742                {
2743                    targets.sort(Trinity::PowerPctOrderPred(POWER_MANA));
2744                    targets.resize(maxTargets);
2745                }
2746            }
2747
2748            void Register() override
2749            {
2750                OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(spell_gen_replenishment_SpellScript::RemoveInvalidTargets, EFFECT_ALL, TARGET_UNIT_CASTER_AREA_RAID);
2751            }
2752        };
2753
2754        SpellScript* GetSpellScript() const override
2755        {
2756            return new spell_gen_replenishment_SpellScript();
2757        }
2758
2759        class spell_gen_replenishment_AuraScript : public AuraScript
2760        {
2761            PrepareAuraScript(spell_gen_replenishment_AuraScript);
2762
2763            bool Load() override
2764            {
2765                return GetUnitOwner()->getPowerType() == POWER_MANA;
2766            }
2767
2768            void CalculateAmount(AuraEffect const* /*aurEff*/, int32& amount, bool& /*canBeRecalculated*/)
2769            {
2770                switch (GetSpellInfo()->Id)
2771                {
2772                    case SPELL_REPLENISHMENT:
2773                        amount = GetUnitOwner()->GetMaxPower(POWER_MANA) * 0.002f;
2774                        break;
2775                    case SPELL_INFINITE_REPLENISHMENT:
2776                        amount = GetUnitOwner()->GetMaxPower(POWER_MANA) * 0.0025f;
2777                        break;
2778                    default:
2779                        break;
2780                }
2781            }
2782
2783            void Register() override
2784            {
2785                DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_replenishment_AuraScript::CalculateAmount, EFFECT_0, SPELL_AURA_PERIODIC_ENERGIZE);
2786            }
2787        };
2788
2789        AuraScript* GetAuraScript() const override
2790        {
2791            return new spell_gen_replenishment_AuraScript();
2792        }
2793};
2794
2795
2796enum RunningWildMountIds
2797{
2798    RUNNING_WILD_MODEL_MALE     = 29422,
2799    RUNNING_WILD_MODEL_FEMALE   = 29423,
2800    SPELL_ALTERED_FORM          = 97709
2801};
2802
2803class spell_gen_running_wild : public SpellScriptLoader
2804{
2805    public:
2806        spell_gen_running_wild() : SpellScriptLoader("spell_gen_running_wild") { }
2807
2808        class spell_gen_running_wild_AuraScript : public AuraScript
2809        {
2810            PrepareAuraScript(spell_gen_running_wild_AuraScript);
2811
2812            bool Validate(SpellInfo const* /*spell*/) override
2813            {
2814                if (!sCreatureDisplayInfoStore.LookupEntry(RUNNING_WILD_MODEL_MALE))
2815                    return false;
2816                if (!sCreatureDisplayInfoStore.LookupEntry(RUNNING_WILD_MODEL_FEMALE))
2817                    return false;
2818                return true;
2819            }
2820
2821            void HandleMount(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
2822            {
2823                Unit* target = GetTarget();
2824                PreventDefaultAction();
2825
2826                target->Mount(target->getGender() == GENDER_FEMALE ? RUNNING_WILD_MODEL_FEMALE : RUNNING_WILD_MODEL_MALE, 0, 0);
2827
2828                // cast speed aura
2829                if (MountCapabilityEntry const* mountCapability = sMountCapabilityStore.LookupEntry(aurEff->GetAmount()))
2830                    target->CastSpell(target, mountCapability->SpeedModSpell, TRIGGERED_FULL_MASK);
2831            }
2832
2833            void Register() override
2834            {
2835                OnEffectApply += AuraEffectApplyFn(spell_gen_running_wild_AuraScript::HandleMount, EFFECT_1, SPELL_AURA_MOUNTED, AURA_EFFECT_HANDLE_REAL);
2836            }
2837        };
2838
2839        class spell_gen_running_wild_SpellScript : public SpellScript
2840        {
2841            PrepareSpellScript(spell_gen_running_wild_SpellScript);
2842
2843            bool Validate(SpellInfo const* /*spell*/) override
2844            {
2845                if (!sSpellMgr->GetSpellInfo(SPELL_ALTERED_FORM))
2846                    return false;
2847                return true;
2848            }
2849
2850            bool Load() override
2851            {
2852                // Definitely not a good thing, but currently the only way to do something at cast start
2853                // Should be replaced as soon as possible with a new hook: BeforeCastStart
2854                GetCaster()->CastSpell(GetCaster(), SPELL_ALTERED_FORM, TRIGGERED_FULL_MASK);
2855                return false;
2856            }
2857
2858            void Register() override
2859            {
2860            }
2861        };
2862
2863        AuraScript* GetAuraScript() const override
2864        {
2865            return new spell_gen_running_wild_AuraScript();
2866        }
2867
2868        SpellScript* GetSpellScript() const override
2869        {
2870            return new spell_gen_running_wild_SpellScript();
2871        }
2872};
2873
2874class spell_gen_two_forms : public SpellScriptLoader
2875{
2876    public:
2877        spell_gen_two_forms() : SpellScriptLoader("spell_gen_two_forms") { }
2878
2879        class spell_gen_two_forms_SpellScript : public SpellScript
2880        {
2881            PrepareSpellScript(spell_gen_two_forms_SpellScript);
2882
2883            SpellCastResult CheckCast()
2884            {
2885                if (GetCaster()->IsInCombat())
2886                {
2887                    SetCustomCastResultMessage(SPELL_CUSTOM_ERROR_CANT_TRANSFORM);
2888                    return SPELL_FAILED_CUSTOM_ERROR;
2889                }
2890
2891                // Player cannot transform to human form if he is forced to be worgen for some reason (Darkflight)
2892                if (GetCaster()->GetAuraEffectsByType(SPELL_AURA_WORGEN_ALTERED_FORM).size() > 1)
2893                {
2894                    SetCustomCastResultMessage(SPELL_CUSTOM_ERROR_CANT_TRANSFORM);
2895                    return SPELL_FAILED_CUSTOM_ERROR;
2896                }
2897
2898                return SPELL_CAST_OK;
2899            }
2900
2901            void HandleTransform(SpellEffIndex effIndex)
2902            {
2903                Unit* target = GetHitUnit();
2904                PreventHitDefaultEffect(effIndex);
2905                if (target->HasAuraType(SPELL_AURA_WORGEN_ALTERED_FORM))
2906                    target->RemoveAurasByType(SPELL_AURA_WORGEN_ALTERED_FORM);
2907                else    // Basepoints 1 for this aura control whether to trigger transform transition animation or not.
2908                    target->CastCustomSpell(SPELL_ALTERED_FORM, SPELLVALUE_BASE_POINT0, 1, target, TRIGGERED_FULL_MASK);
2909            }
2910
2911            void Register() override
2912            {
2913                OnCheckCast += SpellCheckCastFn(spell_gen_two_forms_SpellScript::CheckCast);
2914                OnEffectHitTarget += SpellEffectFn(spell_gen_two_forms_SpellScript::HandleTransform, EFFECT_0, SPELL_EFFECT_DUMMY);
2915            }
2916        };
2917
2918        SpellScript* GetSpellScript() const override
2919        {
2920            return new spell_gen_two_forms_SpellScript();
2921        }
2922};
2923
2924class spell_gen_darkflight : public SpellScriptLoader
2925{
2926    public:
2927        spell_gen_darkflight() : SpellScriptLoader("spell_gen_darkflight") { }
2928
2929        class spell_gen_darkflight_SpellScript : public SpellScript
2930        {
2931            PrepareSpellScript(spell_gen_darkflight_SpellScript);
2932
2933            void TriggerTransform()
2934            {
2935                GetCaster()->CastSpell(GetCaster(), SPELL_ALTERED_FORM, TRIGGERED_FULL_MASK);
2936            }
2937
2938            void Register() override
2939            {
2940                AfterCast += SpellCastFn(spell_gen_darkflight_SpellScript::TriggerTransform);
2941            }
2942        };
2943
2944        SpellScript* GetSpellScript() const override
2945        {
2946            return new spell_gen_darkflight_SpellScript();
2947        }
2948};
2949enum SeaforiumSpells
2950{
2951    SPELL_PLANT_CHARGES_CREDIT_ACHIEVEMENT  = 60937
2952};
2953
2954class spell_gen_seaforium_blast : public SpellScriptLoader
2955{
2956    public:
2957        spell_gen_seaforium_blast() : SpellScriptLoader("spell_gen_seaforium_blast") { }
2958
2959        class spell_gen_seaforium_blast_SpellScript : public SpellScript
2960        {
2961            PrepareSpellScript(spell_gen_seaforium_blast_SpellScript);
2962
2963            bool Validate(SpellInfo const* /*spellInfo*/) override
2964            {
2965                if (!sSpellMgr->GetSpellInfo(SPELL_PLANT_CHARGES_CREDIT_ACHIEVEMENT))
2966                    return false;
2967                return true;
2968            }
2969
2970            bool Load() override
2971            {
2972                // OriginalCaster is always available in Spell::prepare
2973                return GetOriginalCaster()->GetTypeId() == TYPEID_PLAYER;
2974            }
2975
2976            void AchievementCredit(SpellEffIndex /*effIndex*/)
2977            {
2978                // but in effect handling OriginalCaster can become NULL
2979                if (Unit* originalCaster = GetOriginalCaster())
2980                    if (GameObject* go = GetHitGObj())
2981                        if (go->GetGOInfo()->type == GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING)
2982                            originalCaster->CastSpell(originalCaster, SPELL_PLANT_CHARGES_CREDIT_ACHIEVEMENT, true);
2983            }
2984
2985            void Register() override
2986            {
2987                OnEffectHitTarget += SpellEffectFn(spell_gen_seaforium_blast_SpellScript::AchievementCredit, EFFECT_1, SPELL_EFFECT_GAMEOBJECT_DAMAGE);
2988            }
2989        };
2990
2991        SpellScript* GetSpellScript() const override
2992        {
2993            return new spell_gen_seaforium_blast_SpellScript();
2994        }
2995};
2996
2997enum SpectatorCheerTrigger
2998{
2999    EMOTE_ONE_SHOT_CHEER        = 4,
3000    EMOTE_ONE_SHOT_EXCLAMATION  = 5,
3001    EMOTE_ONE_SHOT_APPLAUD      = 21
3002};
3003
3004uint8 const EmoteArray[3] = { EMOTE_ONE_SHOT_CHEER, EMOTE_ONE_SHOT_EXCLAMATION, EMOTE_ONE_SHOT_APPLAUD };
3005
3006class spell_gen_spectator_cheer_trigger : public SpellScriptLoader
3007{
3008    public:
3009        spell_gen_spectator_cheer_trigger() : SpellScriptLoader("spell_gen_spectator_cheer_trigger") { }
3010
3011        class spell_gen_spectator_cheer_trigger_SpellScript : public SpellScript
3012        {
3013            PrepareSpellScript(spell_gen_spectator_cheer_trigger_SpellScript);
3014
3015            void HandleDummy(SpellEffIndex /*effIndex*/)
3016            {
3017                GetCaster()->HandleEmoteCommand(EmoteArray[urand(0, 2)]);
3018            }
3019
3020            void Register() override
3021            {
3022                OnEffectHitTarget += SpellEffectFn(spell_gen_spectator_cheer_trigger_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
3023            }
3024        };
3025
3026        SpellScript* GetSpellScript() const override
3027        {
3028            return new spell_gen_spectator_cheer_trigger_SpellScript();
3029        }
3030};
3031
3032class spell_gen_spirit_healer_res : public SpellScriptLoader
3033{
3034    public:
3035        spell_gen_spirit_healer_res(): SpellScriptLoader("spell_gen_spirit_healer_res") { }
3036
3037        class spell_gen_spirit_healer_res_SpellScript : public SpellScript
3038        {
3039            PrepareSpellScript(spell_gen_spirit_healer_res_SpellScript);
3040
3041            bool Load() override
3042            {
3043                return GetOriginalCaster() && GetOriginalCaster()->GetTypeId() == TYPEID_PLAYER;
3044            }
3045
3046            void HandleDummy(SpellEffIndex /* effIndex */)
3047            {
3048                Player* originalCaster = GetOriginalCaster()->ToPlayer();
3049                if (Unit* target = GetHitUnit())
3050                {
3051                    WorldPacket data(SMSG_SPIRIT_HEALER_CONFIRM, 8);
3052                    data << uint64(target->GetGUID());
3053                    originalCaster->GetSession()->SendPacket(&data);
3054                }
3055            }
3056
3057            void Register() override
3058            {
3059                OnEffectHitTarget += SpellEffectFn(spell_gen_spirit_healer_res_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
3060            }
3061        };
3062
3063        SpellScript* GetSpellScript() const override
3064        {
3065            return new spell_gen_spirit_healer_res_SpellScript();
3066        }
3067};
3068
3069enum SummonElemental
3070{
3071    SPELL_SUMMON_FIRE_ELEMENTAL  = 8985,
3072    SPELL_SUMMON_EARTH_ELEMENTAL = 19704
3073};
3074
3075class spell_gen_summon_elemental : public SpellScriptLoader
3076{
3077    public:
3078        spell_gen_summon_elemental(const char* name, uint32 spellId) : SpellScriptLoader(name), _spellId(spellId) { }
3079
3080        class spell_gen_summon_elemental_AuraScript : public AuraScript
3081        {
3082            PrepareAuraScript(spell_gen_summon_elemental_AuraScript);
3083
3084        public:
3085            spell_gen_summon_elemental_AuraScript(uint32 spellId) : AuraScript(), _spellId(spellId) { }
3086
3087            bool Validate(SpellInfo const* /*spellInfo*/) override
3088            {
3089                if (!sSpellMgr->GetSpellInfo(_spellId))
3090                    return false;
3091                return true;
3092            }
3093
3094            void AfterApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
3095            {
3096                if (GetCaster())
3097                    if (Unit* owner = GetCaster()->GetOwner())
3098                        owner->CastSpell(owner, _spellId, true);
3099            }
3100
3101            void AfterRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
3102            {
3103                if (GetCaster())
3104                    if (Unit* owner = GetCaster()->GetOwner())
3105                        if (owner->GetTypeId() == TYPEID_PLAYER) /// @todo this check is maybe wrong
3106                            owner->ToPlayer()->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
3107            }
3108
3109            void Register() override
3110            {
3111                 AfterEffectApply += AuraEffectApplyFn(spell_gen_summon_elemental_AuraScript::AfterApply, EFFECT_1, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL);
3112                 AfterEffectRemove += AuraEffectRemoveFn(spell_gen_summon_elemental_AuraScript::AfterRemove, EFFECT_1, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL);
3113            }
3114
3115        private:
3116            uint32 _spellId;
3117        };
3118
3119        AuraScript* GetAuraScript() const override
3120        {
3121            return new spell_gen_summon_elemental_AuraScript(_spellId);
3122        }
3123
3124    private:
3125        uint32 _spellId;
3126};
3127
3128enum TournamentMountsSpells
3129{
3130    SPELL_LANCE_EQUIPPED     = 62853
3131};
3132
3133class spell_gen_summon_tournament_mount : public SpellScriptLoader
3134{
3135    public:
3136        spell_gen_summon_tournament_mount() : SpellScriptLoader("spell_gen_summon_tournament_mount") { }
3137
3138        class spell_gen_summon_tournament_mount_SpellScript : public SpellScript
3139        {
3140            PrepareSpellScript(spell_gen_summon_tournament_mount_SpellScript);
3141
3142            bool Validate(SpellInfo const* /*spellInfo*/) override
3143            {
3144                if (!sSpellMgr->GetSpellInfo(SPELL_LANCE_EQUIPPED))
3145                    return false;
3146                return true;
3147            }
3148
3149            SpellCastResult CheckIfLanceEquiped()
3150            {
3151                if (GetCaster()->IsInDisallowedMountForm())
3152                    GetCaster()->RemoveAurasByType(SPELL_AURA_MOD_SHAPESHIFT);
3153
3154                if (!GetCaster()->HasAura(SPELL_LANCE_EQUIPPED))
3155                {
3156                    SetCustomCastResultMessage(SPELL_CUSTOM_ERROR_MUST_HAVE_LANCE_EQUIPPED);
3157                    return SPELL_FAILED_CUSTOM_ERROR;
3158                }
3159
3160                return SPELL_CAST_OK;
3161            }
3162
3163            void Register() override
3164            {
3165                OnCheckCast += SpellCheckCastFn(spell_gen_summon_tournament_mount_SpellScript::CheckIfLanceEquiped);
3166            }
3167        };
3168
3169        SpellScript* GetSpellScript() const override
3170        {
3171            return new spell_gen_summon_tournament_mount_SpellScript();
3172        }
3173};
3174
3175// 41213, 43416, 69222, 73076 - Throw Shield
3176class spell_gen_throw_shield : public SpellScriptLoader
3177{
3178    public:
3179        spell_gen_throw_shield() : SpellScriptLoader("spell_gen_throw_shield") { }
3180
3181        class spell_gen_throw_shield_SpellScript : public SpellScript
3182        {
3183            PrepareSpellScript(spell_gen_throw_shield_SpellScript);
3184
3185            void HandleScriptEffect(SpellEffIndex effIndex)
3186            {
3187                PreventHitDefaultEffect(effIndex);
3188                GetCaster()->CastSpell(GetHitUnit(), uint32(GetEffectValue()), true);
3189            }
3190
3191            void Register() override
3192            {
3193                OnEffectHitTarget += SpellEffectFn(spell_gen_throw_shield_SpellScript::HandleScriptEffect, EFFECT_1, SPELL_EFFECT_SCRIPT_EFFECT);
3194            }
3195        };
3196
3197        SpellScript* GetSpellScript() const override
3198        {
3199            return new spell_gen_throw_shield_SpellScript();
3200        }
3201};
3202
3203enum MountedDuelSpells
3204{
3205    SPELL_ON_TOURNAMENT_MOUNT = 63034,
3206    SPELL_MOUNTED_DUEL        = 62875
3207};
3208
3209class spell_gen_tournament_duel : public SpellScriptLoader
3210{
3211    public:
3212        spell_gen_tournament_duel() : SpellScriptLoader("spell_gen_tournament_duel") { }
3213
3214        class spell_gen_tournament_duel_SpellScript : public SpellScript
3215        {
3216            PrepareSpellScript(spell_gen_tournament_duel_SpellScript);
3217
3218            bool Validate(SpellInfo const* /*spellInfo*/) override
3219            {
3220                if (!sSpellMgr->GetSpellInfo(SPELL_ON_TOURNAMENT_MOUNT) ||
3221                    !sSpellMgr->GetSpellInfo(SPELL_MOUNTED_DUEL))
3222                    return false;
3223                return true;
3224            }
3225
3226            void HandleScriptEffect(SpellEffIndex /*effIndex*/)
3227            {
3228                if (Unit* rider = GetCaster()->GetCharmer())
3229                {
3230                    if (Player* playerTarget = GetHitPlayer())
3231                    {
3232                        if (playerTarget->HasAura(SPELL_ON_TOURNAMENT_MOUNT) && playerTarget->GetVehicleBase())
3233                            rider->CastSpell(playerTarget, SPELL_MOUNTED_DUEL, true);
3234                    }
3235                    else if (Unit* unitTarget = GetHitUnit())
3236                    {
3237                        if (unitTarget->GetCharmer() && unitTarget->GetCharmer()->GetTypeId() == TYPEID_PLAYER && unitTarget->GetCharmer()->HasAura(SPELL_ON_TOURNAMENT_MOUNT))
3238                            rider->CastSpell(unitTarget->GetCharmer(), SPELL_MOUNTED_DUEL, true);
3239                    }
3240                }
3241            }
3242
3243            void Register() override
3244            {
3245                OnEffectHitTarget += SpellEffectFn(spell_gen_tournament_duel_SpellScript::HandleScriptEffect, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
3246            }
3247        };
3248
3249        SpellScript* GetSpellScript() const override
3250        {
3251            return new spell_gen_tournament_duel_SpellScript();
3252        }
3253};
3254
3255class spell_gen_tournament_pennant : public SpellScriptLoader
3256{
3257    public:
3258        spell_gen_tournament_pennant() : SpellScriptLoader("spell_gen_tournament_pennant") { }
3259
3260        class spell_gen_tournament_pennant_AuraScript : public AuraScript
3261        {
3262            PrepareAuraScript(spell_gen_tournament_pennant_AuraScript);
3263
3264            bool Load() override
3265            {
3266                return GetCaster() && GetCaster()->GetTypeId() == TYPEID_PLAYER;
3267            }
3268
3269            void HandleApplyEffect(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
3270            {
3271                if (Unit* caster = GetCaster())
3272                    if (!caster->GetVehicleBase())
3273                        caster->RemoveAurasDueToSpell(GetId());
3274            }
3275
3276            void Register() override
3277            {
3278                OnEffectApply += AuraEffectApplyFn(spell_gen_tournament_pennant_AuraScript::HandleApplyEffect, EFFECT_0, SPELL_AURA_DUMMY, AURA_EFFECT_HANDLE_REAL_OR_REAPPLY_MASK);
3279            }
3280        };
3281
3282        AuraScript* GetAuraScript() const override
3283        {
3284            return new spell_gen_tournament_pennant_AuraScript();
3285        }
3286};
3287
3288
3289
3290enum PvPTrinketTriggeredSpells
3291{
3292    SPELL_WILL_OF_THE_FORSAKEN_COOLDOWN_TRIGGER         = 72752,
3293    SPELL_WILL_OF_THE_FORSAKEN_COOLDOWN_TRIGGER_WOTF    = 72757
3294};
3295
3296class spell_pvp_trinket_wotf_shared_cd : public SpellScriptLoader
3297{
3298    public:
3299        spell_pvp_trinket_wotf_shared_cd() : SpellScriptLoader("spell_pvp_trinket_wotf_shared_cd") { }
3300
3301        class spell_pvp_trinket_wotf_shared_cd_SpellScript : public SpellScript
3302        {
3303            PrepareSpellScript(spell_pvp_trinket_wotf_shared_cd_SpellScript);
3304
3305            bool Load() override
3306            {
3307                return GetCaster()->GetTypeId() == TYPEID_PLAYER;
3308            }
3309
3310            bool Validate(SpellInfo const* /*spellInfo*/) override
3311            {
3312                if (!sSpellMgr->GetSpellInfo(SPELL_WILL_OF_THE_FORSAKEN_COOLDOWN_TRIGGER) ||
3313                    !sSpellMgr->GetSpellInfo(SPELL_WILL_OF_THE_FORSAKEN_COOLDOWN_TRIGGER_WOTF))
3314                    return false;
3315                return true;
3316            }
3317
3318            void HandleScript()
3319            {
3320                // This is only needed because spells cast from spell_linked_spell are triggered by default
3321                // Spell::SendSpellCooldown() skips all spells with TRIGGERED_IGNORE_SPELL_AND_CATEGORY_CD
3322                GetCaster()->GetSpellHistory()->StartCooldown(GetSpellInfo(), 0, GetSpell());
3323            }
3324
3325            void Register() override
3326            {
3327                AfterCast += SpellCastFn(spell_pvp_trinket_wotf_shared_cd_SpellScript::HandleScript);
3328            }
3329        };
3330
3331        SpellScript* GetSpellScript() const override
3332        {
3333            return new spell_pvp_trinket_wotf_shared_cd_SpellScript();
3334        }
3335};
3336
3337enum FriendOrFowl
3338{
3339    SPELL_TURKEY_VENGEANCE      = 25285
3340};
3341
3342class spell_gen_turkey_marker : public SpellScriptLoader
3343{
3344    public:
3345        spell_gen_turkey_marker() : SpellScriptLoader("spell_gen_turkey_marker") { }
3346
3347        class spell_gen_turkey_marker_AuraScript : public AuraScript
3348        {
3349            PrepareAuraScript(spell_gen_turkey_marker_AuraScript);
3350
3351            void OnApply(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
3352            {
3353                // store stack apply times, so we can pop them while they expire
3354                _applyTimes.push_back(getMSTime());
3355                Unit* target = GetTarget();
3356
3357                // on stack 15 cast the achievement crediting spell
3358                if (GetStackAmount() >= 15)
3359                    target->CastSpell(target, SPELL_TURKEY_VENGEANCE, true, NULL, aurEff, GetCasterGUID());
3360            }
3361
3362            void OnPeriodic(AuraEffect const* /*aurEff*/)
3363            {
3364                if (_applyTimes.empty())
3365                    return;
3366
3367                // pop stack if it expired for us
3368                if (_applyTimes.front() + GetMaxDuration() < getMSTime())
3369                    ModStackAmount(-1, AURA_REMOVE_BY_EXPIRE);
3370            }
3371
3372            void Register() override
3373            {
3374                AfterEffectApply += AuraEffectApplyFn(spell_gen_turkey_marker_AuraScript::OnApply, EFFECT_0, SPELL_AURA_PERIODIC_DUMMY, AURA_EFFECT_HANDLE_REAL);
3375                OnEffectPeriodic += AuraEffectPeriodicFn(spell_gen_turkey_marker_AuraScript::OnPeriodic, EFFECT_0, SPELL_AURA_PERIODIC_DUMMY);
3376            }
3377
3378            std::list<uint32> _applyTimes;
3379        };
3380
3381        AuraScript* GetAuraScript() const override
3382        {
3383            return new spell_gen_turkey_marker_AuraScript();
3384        }
3385};
3386
3387enum FoamSword
3388{
3389    ITEM_FOAM_SWORD_GREEN   = 45061,
3390    ITEM_FOAM_SWORD_PINK    = 45176,
3391    ITEM_FOAM_SWORD_BLUE    = 45177,
3392    ITEM_FOAM_SWORD_RED     = 45178,
3393    ITEM_FOAM_SWORD_YELLOW  = 45179
3394};
3395
3396class spell_gen_upper_deck_create_foam_sword : public SpellScriptLoader
3397{
3398    public:
3399        spell_gen_upper_deck_create_foam_sword() : SpellScriptLoader("spell_gen_upper_deck_create_foam_sword") { }
3400
3401        class spell_gen_upper_deck_create_foam_sword_SpellScript : public SpellScript
3402        {
3403            PrepareSpellScript(spell_gen_upper_deck_create_foam_sword_SpellScript);
3404
3405            void HandleScript(SpellEffIndex effIndex)
3406            {
3407                if (Player* player = GetHitPlayer())
3408                {
3409                    static uint32 const itemId[5] = { ITEM_FOAM_SWORD_GREEN, ITEM_FOAM_SWORD_PINK, ITEM_FOAM_SWORD_BLUE, ITEM_FOAM_SWORD_RED, ITEM_FOAM_SWORD_YELLOW };
3410                    // player can only have one of these items
3411                    for (uint8 i = 0; i < 5; ++i)
3412                    {
3413                        if (player->HasItemCount(itemId[i], 1, true))
3414                            return;
3415                    }
3416
3417                    CreateItem(effIndex, itemId[urand(0, 4)]);
3418                }
3419            }
3420
3421            void Register() override
3422            {
3423                OnEffectHitTarget += SpellEffectFn(spell_gen_upper_deck_create_foam_sword_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
3424            }
3425        };
3426
3427        SpellScript* GetSpellScript() const override
3428        {
3429            return new spell_gen_upper_deck_create_foam_sword_SpellScript();
3430        }
3431};
3432
3433enum VehicleScaling
3434{
3435    SPELL_GEAR_SCALING      = 66668
3436};
3437
3438class spell_gen_vehicle_scaling : public SpellScriptLoader
3439{
3440    public:
3441        spell_gen_vehicle_scaling() : SpellScriptLoader("spell_gen_vehicle_scaling") { }
3442
3443        class spell_gen_vehicle_scaling_AuraScript : public AuraScript
3444        {
3445            PrepareAuraScript(spell_gen_vehicle_scaling_AuraScript);
3446
3447            bool Load() override
3448            {
3449                return GetCaster() && GetCaster()->GetTypeId() == TYPEID_PLAYER;
3450            }
3451
3452            void CalculateAmount(AuraEffect const* /*aurEff*/, int32& amount, bool& /*canBeRecalculated*/)
3453            {
3454                Unit* caster = GetCaster();
3455                float factor;
3456                uint16 baseItemLevel;
3457
3458                /// @todo Reserach coeffs for different vehicles
3459                switch (GetId())
3460                {
3461                    case SPELL_GEAR_SCALING:
3462                        factor = 1.0f;
3463                        baseItemLevel = 205;
3464                        break;
3465                    default:
3466                        factor = 1.0f;
3467                        baseItemLevel = 170;
3468                        break;
3469                }
3470
3471                float avgILvl = caster->ToPlayer()->GetAverageItemLevel();
3472                if (avgILvl < baseItemLevel)
3473                    return;                     /// @todo Research possibility of scaling down
3474
3475                amount = uint16((avgILvl - baseItemLevel) * factor);
3476            }
3477
3478            void Register() override
3479            {
3480                DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_vehicle_scaling_AuraScript::CalculateAmount, EFFECT_0, SPELL_AURA_MOD_HEALING_PCT);
3481                DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_vehicle_scaling_AuraScript::CalculateAmount, EFFECT_1, SPELL_AURA_MOD_DAMAGE_PERCENT_DONE);
3482                DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_vehicle_scaling_AuraScript::CalculateAmount, EFFECT_2, SPELL_AURA_MOD_INCREASE_HEALTH_PERCENT);
3483            }
3484        };
3485
3486        AuraScript* GetAuraScript() const override
3487        {
3488            return new spell_gen_vehicle_scaling_AuraScript();
3489        }
3490};
3491
3492enum VendorBarkTrigger
3493{
3494    NPC_AMPHITHEATER_VENDOR     = 30098,
3495    SAY_AMPHITHEATER_VENDOR     = 0
3496};
3497
3498class spell_gen_vendor_bark_trigger : public SpellScriptLoader
3499{
3500    public:
3501        spell_gen_vendor_bark_trigger() : SpellScriptLoader("spell_gen_vendor_bark_trigger") { }
3502
3503        class spell_gen_vendor_bark_trigger_SpellScript : public SpellScript
3504        {
3505            PrepareSpellScript(spell_gen_vendor_bark_trigger_SpellScript);
3506
3507            void HandleDummy(SpellEffIndex /* effIndex */)
3508            {
3509                if (Creature* vendor = GetCaster()->ToCreature())
3510                    if (vendor->GetEntry() == NPC_AMPHITHEATER_VENDOR)
3511                        vendor->AI()->Talk(SAY_AMPHITHEATER_VENDOR);
3512            }
3513
3514            void Register() override
3515            {
3516                OnEffectHitTarget += SpellEffectFn(spell_gen_vendor_bark_trigger_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
3517            }
3518        };
3519
3520        SpellScript* GetSpellScript() const override
3521        {
3522            return new spell_gen_vendor_bark_trigger_SpellScript();
3523        }
3524
3525};
3526
3527class spell_gen_wg_water : public SpellScriptLoader
3528{
3529    public:
3530        spell_gen_wg_water() : SpellScriptLoader("spell_gen_wg_water") { }
3531
3532        class spell_gen_wg_water_SpellScript : public SpellScript
3533        {
3534            PrepareSpellScript(spell_gen_wg_water_SpellScript);
3535
3536            SpellCastResult CheckCast()
3537            {
3538                if (!GetSpellInfo()->CheckTargetCreatureType(GetCaster()))
3539                    return SPELL_FAILED_DONT_REPORT;
3540                return SPELL_CAST_OK;
3541            }
3542
3543            void Register() override
3544            {
3545                OnCheckCast += SpellCheckCastFn(spell_gen_wg_water_SpellScript::CheckCast);
3546            }
3547        };
3548
3549        SpellScript* GetSpellScript() const override
3550        {
3551            return new spell_gen_wg_water_SpellScript();
3552        }
3553};
3554
3555enum WhisperGulchYoggSaronWhisper
3556{
3557    SPELL_YOGG_SARON_WHISPER_DUMMY  = 29072
3558};
3559
3560class spell_gen_whisper_gulch_yogg_saron_whisper : public SpellScriptLoader
3561{
3562    public:
3563        spell_gen_whisper_gulch_yogg_saron_whisper() : SpellScriptLoader("spell_gen_whisper_gulch_yogg_saron_whisper") { }
3564
3565        class spell_gen_whisper_gulch_yogg_saron_whisper_AuraScript : public AuraScript
3566        {
3567            PrepareAuraScript(spell_gen_whisper_gulch_yogg_saron_whisper_AuraScript);
3568
3569            bool Validate(SpellInfo const* /*spellInfo*/) override
3570            {
3571                if (!sSpellMgr->GetSpellInfo(SPELL_YOGG_SARON_WHISPER_DUMMY))
3572                    return false;
3573                return true;
3574            }
3575
3576            void HandleEffectPeriodic(AuraEffect const* /*aurEff*/)
3577            {
3578                PreventDefaultAction();
3579                GetTarget()->CastSpell((Unit*)NULL, SPELL_YOGG_SARON_WHISPER_DUMMY, true);
3580            }
3581
3582            void Register() override
3583            {
3584                OnEffectPeriodic += AuraEffectPeriodicFn(spell_gen_whisper_gulch_yogg_saron_whisper_AuraScript::HandleEffectPeriodic, EFFECT_0, SPELL_AURA_PERIODIC_DUMMY);
3585            }
3586        };
3587
3588        AuraScript* GetAuraScript() const override
3589        {
3590            return new spell_gen_whisper_gulch_yogg_saron_whisper_AuraScript();
3591        }
3592};
3593
3594class spell_gen_eject_all_passengers : public SpellScriptLoader
3595{
3596    public:
3597        spell_gen_eject_all_passengers() : SpellScriptLoader("spell_gen_eject_all_passengers") { }
3598
3599        class spell_gen_eject_all_passengers_SpellScript : public SpellScript
3600        {
3601            PrepareSpellScript(spell_gen_eject_all_passengers_SpellScript);
3602
3603            void RemoveVehicleAuras()
3604            {
3605                if (Vehicle* vehicle = GetHitUnit()->GetVehicleKit())
3606                    vehicle->RemoveAllPassengers();
3607            }
3608
3609            void Register() override
3610            {
3611                AfterHit += SpellHitFn(spell_gen_eject_all_passengers_SpellScript::RemoveVehicleAuras);
3612            }
3613        };
3614
3615        SpellScript* GetSpellScript() const override
3616        {
3617            return new spell_gen_eject_all_passengers_SpellScript();
3618        }
3619};
3620
3621class spell_gen_eject_passenger : public SpellScriptLoader
3622{
3623    public:
3624        spell_gen_eject_passenger() : SpellScriptLoader("spell_gen_eject_passenger") { }
3625
3626        class spell_gen_eject_passenger_SpellScript : public SpellScript
3627        {
3628            PrepareSpellScript(spell_gen_eject_passenger_SpellScript);
3629
3630            bool Validate(SpellInfo const* spellInfo) override
3631            {
3632                if (spellInfo->Effects[EFFECT_0].CalcValue() < 1)
3633                    return false;
3634                return true;
3635            }
3636
3637            void EjectPassenger(SpellEffIndex /*effIndex*/)
3638            {
3639                if (Vehicle* vehicle = GetHitUnit()->GetVehicleKit())
3640                {
3641                    if (Unit* passenger = vehicle->GetPassenger(GetEffectValue() - 1))
3642                        passenger->ExitVehicle();
3643                }
3644            }
3645
3646            void Register() override
3647            {
3648                OnEffectHitTarget += SpellEffectFn(spell_gen_eject_passenger_SpellScript::EjectPassenger, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
3649            }
3650        };
3651
3652        SpellScript* GetSpellScript() const override
3653        {
3654            return new spell_gen_eject_passenger_SpellScript();
3655        }
3656};
3657
3658enum GMFreeze
3659{
3660    SPELL_GM_FREEZE = 9454
3661};
3662
3663class spell_gen_gm_freeze : public SpellScriptLoader
3664{
3665    public:
3666        spell_gen_gm_freeze() : SpellScriptLoader("spell_gen_gm_freeze") { }
3667
3668        class spell_gen_gm_freeze_AuraScript : public AuraScript
3669        {
3670            PrepareAuraScript(spell_gen_gm_freeze_AuraScript);
3671
3672            bool Validate(SpellInfo const* /*spellInfo*/) override
3673            {
3674                if (!sSpellMgr->GetSpellInfo(SPELL_GM_FREEZE))
3675                    return false;
3676                return true;
3677            }
3678
3679            void OnApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
3680            {
3681                // Do what was done before to the target in HandleFreezeCommand
3682                if (Player* player = GetTarget()->ToPlayer())
3683                {
3684                    // stop combat + make player unattackable + duel stop + stop some spells
3685                    player->setFaction(35);
3686                    player->CombatStop();
3687                    if (player->IsNonMeleeSpellCast(true))
3688                        player->InterruptNonMeleeSpells(true);
3689                    player->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
3690
3691                    // if player class = hunter || warlock remove pet if alive
3692                    if ((player->getClass() == CLASS_HUNTER) || (player->getClass() == CLASS_WARLOCK))
3693                    {
3694                        if (Pet* pet = player->GetPet())
3695                        {
3696                            pet->SavePetToDB(PET_SAVE_AS_CURRENT);
3697                            // not let dismiss dead pet
3698                            if (pet->IsAlive())
3699                                player->RemovePet(pet, PET_SAVE_NOT_IN_SLOT);
3700                        }
3701                    }
3702                }
3703            }
3704
3705            void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
3706            {
3707                // Do what was done before to the target in HandleUnfreezeCommand
3708                if (Player* player = GetTarget()->ToPlayer())
3709                {
3710                    // Reset player faction + allow combat + allow duels
3711                    player->setFactionForRace(player->getRace());
3712                    player->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
3713                    // save player
3714                    player->SaveToDB();
3715                }
3716            }
3717
3718            void Register() override
3719            {
3720                OnEffectApply += AuraEffectApplyFn(spell_gen_gm_freeze_AuraScript::OnApply, EFFECT_0, SPELL_AURA_MOD_STUN, AURA_EFFECT_HANDLE_REAL);
3721                OnEffectRemove += AuraEffectRemoveFn(spell_gen_gm_freeze_AuraScript::OnRemove, EFFECT_0, SPELL_AURA_MOD_STUN, AURA_EFFECT_HANDLE_REAL);
3722            }
3723        };
3724
3725        AuraScript* GetAuraScript() const override
3726        {
3727            return new spell_gen_gm_freeze_AuraScript();
3728        }
3729};
3730
3731class spell_gen_stand : public SpellScriptLoader
3732{
3733public:
3734    spell_gen_stand() : SpellScriptLoader("spell_gen_stand") { }
3735
3736    class spell_gen_stand_SpellScript : public SpellScript
3737    {
3738        PrepareSpellScript(spell_gen_stand_SpellScript);
3739
3740        void HandleScript(SpellEffIndex /*eff*/)
3741        {
3742            Creature* target = GetHitCreature();
3743            if (!target)
3744                return;
3745
3746            target->SetByteValue(UNIT_FIELD_BYTES_1, 0, UNIT_STAND_STATE_STAND);
3747            target->HandleEmoteCommand(EMOTE_STATE_NONE);
3748        }
3749
3750        void Register() override
3751        {
3752            OnEffectHitTarget += SpellEffectFn(spell_gen_stand_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
3753        }
3754    };
3755
3756    SpellScript* GetSpellScript() const override
3757    {
3758        return new spell_gen_stand_SpellScript();
3759    }
3760};
3761
3762enum RequiredMixologySpells
3763{
3764    SPELL_MIXOLOGY                      = 53042,
3765    // Flasks
3766    SPELL_FLASK_OF_THE_FROST_WYRM       = 53755,
3767    SPELL_FLASK_OF_STONEBLOOD           = 53758,
3768    SPELL_FLASK_OF_ENDLESS_RAGE         = 53760,
3769    SPELL_FLASK_OF_PURE_MOJO            = 54212,
3770    SPELL_LESSER_FLASK_OF_RESISTANCE    = 62380,
3771    SPELL_LESSER_FLASK_OF_TOUGHNESS     = 53752,
3772    SPELL_FLASK_OF_BLINDING_LIGHT       = 28521,
3773    SPELL_FLASK_OF_CHROMATIC_WONDER     = 42735,
3774    SPELL_FLASK_OF_FORTIFICATION        = 28518,
3775    SPELL_FLASK_OF_MIGHTY_RESTORATION   = 28519,
3776    SPELL_FLASK_OF_PURE_DEATH           = 28540,
3777    SPELL_FLASK_OF_RELENTLESS_ASSAULT   = 28520,
3778    SPELL_FLASK_OF_CHROMATIC_RESISTANCE = 17629,
3779    SPELL_FLASK_OF_DISTILLED_WISDOM     = 17627,
3780    SPELL_FLASK_OF_SUPREME_POWER        = 17628,
3781    SPELL_FLASK_OF_THE_TITANS           = 17626,
3782    // Elixirs
3783    SPELL_ELIXIR_OF_MIGHTY_AGILITY      = 28497,
3784    SPELL_ELIXIR_OF_ACCURACY            = 60340,
3785    SPELL_ELIXIR_OF_DEADLY_STRIKES      = 60341,
3786    SPELL_ELIXIR_OF_MIGHTY_DEFENSE      = 60343,
3787    SPELL_ELIXIR_OF_EXPERTISE           = 60344,
3788    SPELL_ELIXIR_OF_ARMOR_PIERCING      = 60345,
3789    SPELL_ELIXIR_OF_LIGHTNING_SPEED     = 60346,
3790    SPELL_ELIXIR_OF_MIGHTY_FORTITUDE    = 53751,
3791    SPELL_ELIXIR_OF_MIGHTY_MAGEBLOOD    = 53764,
3792    SPELL_ELIXIR_OF_MIGHTY_STRENGTH     = 53748,
3793    SPELL_ELIXIR_OF_MIGHTY_TOUGHTS      = 60347,
3794    SPELL_ELIXIR_OF_PROTECTION          = 53763,
3795    SPELL_ELIXIR_OF_SPIRIT              = 53747,
3796    SPELL_GURUS_ELIXIR                  = 53749,
3797    SPELL_SHADOWPOWER_ELIXIR            = 33721,
3798    SPELL_WRATH_ELIXIR                  = 53746,
3799    SPELL_ELIXIR_OF_EMPOWERMENT         = 28514,
3800    SPELL_ELIXIR_OF_MAJOR_MAGEBLOOD     = 28509,
3801    SPELL_ELIXIR_OF_MAJOR_SHADOW_POWER  = 28503,
3802    SPELL_ELIXIR_OF_MAJOR_DEFENSE       = 28502,
3803    SPELL_FEL_STRENGTH_ELIXIR           = 38954,
3804    SPELL_ELIXIR_OF_IRONSKIN            = 39628,
3805    SPELL_ELIXIR_OF_MAJOR_AGILITY       = 54494,
3806    SPELL_ELIXIR_OF_DRAENIC_WISDOM      = 39627,
3807    SPELL_ELIXIR_OF_MAJOR_FIREPOWER     = 28501,
3808    SPELL_ELIXIR_OF_MAJOR_FROST_POWER   = 28493,
3809    SPELL_EARTHEN_ELIXIR                = 39626,
3810    SPELL_ELIXIR_OF_MASTERY             = 33726,
3811    SPELL_ELIXIR_OF_HEALING_POWER       = 28491,
3812    SPELL_ELIXIR_OF_MAJOR_FORTITUDE     = 39625,
3813    SPELL_ELIXIR_OF_MAJOR_STRENGTH      = 28490,
3814    SPELL_ADEPTS_ELIXIR                 = 54452,
3815    SPELL_ONSLAUGHT_ELIXIR              = 33720,
3816    SPELL_MIGHTY_TROLLS_BLOOD_ELIXIR    = 24361,
3817    SPELL_GREATER_ARCANE_ELIXIR         = 17539,
3818    SPELL_ELIXIR_OF_THE_MONGOOSE        = 17538,
3819    SPELL_ELIXIR_OF_BRUTE_FORCE         = 17537,
3820    SPELL_ELIXIR_OF_SAGES               = 17535,
3821    SPELL_ELIXIR_OF_SUPERIOR_DEFENSE    = 11348,
3822    SPELL_ELIXIR_OF_DEMONSLAYING        = 11406,
3823    SPELL_ELIXIR_OF_GREATER_FIREPOWER   = 26276,
3824    SPELL_ELIXIR_OF_SHADOW_POWER        = 11474,
3825    SPELL_MAGEBLOOD_ELIXIR              = 24363,
3826    SPELL_ELIXIR_OF_GIANTS              = 11405,
3827    SPELL_ELIXIR_OF_GREATER_AGILITY     = 11334,
3828    SPELL_ARCANE_ELIXIR                 = 11390,
3829    SPELL_ELIXIR_OF_GREATER_INTELLECT   = 11396,
3830    SPELL_ELIXIR_OF_GREATER_DEFENSE     = 11349,
3831    SPELL_ELIXIR_OF_FROST_POWER         = 21920,
3832    SPELL_ELIXIR_OF_AGILITY             = 11328,
3833    SPELL_MAJOR_TROLLS_BLLOOD_ELIXIR    =  3223,
3834    SPELL_ELIXIR_OF_FORTITUDE           =  3593,
3835    SPELL_ELIXIR_OF_OGRES_STRENGTH      =  3164,
3836    SPELL_ELIXIR_OF_FIREPOWER           =  7844,
3837    SPELL_ELIXIR_OF_LESSER_AGILITY      =  3160,
3838    SPELL_ELIXIR_OF_DEFENSE             =  3220,
3839    SPELL_STRONG_TROLLS_BLOOD_ELIXIR    =  3222,
3840    SPELL_ELIXIR_OF_MINOR_ACCURACY      = 63729,
3841    SPELL_ELIXIR_OF_WISDOM              =  3166,
3842    SPELL_ELIXIR_OF_GIANTH_GROWTH       =  8212,
3843    SPELL_ELIXIR_OF_MINOR_AGILITY       =  2374,
3844    SPELL_ELIXIR_OF_MINOR_FORTITUDE     =  2378,
3845    SPELL_WEAK_TROLLS_BLOOD_ELIXIR      =  3219,
3846    SPELL_ELIXIR_OF_LIONS_STRENGTH      =  2367,
3847    SPELL_ELIXIR_OF_MINOR_DEFENSE       =   673
3848};
3849
3850class spell_gen_mixology_bonus : public SpellScriptLoader
3851{
3852public:
3853    spell_gen_mixology_bonus() : SpellScriptLoader("spell_gen_mixology_bonus") { }
3854
3855    class spell_gen_mixology_bonus_AuraScript : public AuraScript
3856    {
3857        PrepareAuraScript(spell_gen_mixology_bonus_AuraScript);
3858
3859    public:
3860        spell_gen_mixology_bonus_AuraScript()
3861        {
3862            bonus = 0;
3863        }
3864
3865    private:
3866        bool Validate(SpellInfo const* /*spellInfo*/) override
3867        {
3868            if (!sSpellMgr->GetSpellInfo(SPELL_MIXOLOGY))
3869                return false;
3870            return true;
3871        }
3872
3873        bool Load() override
3874        {
3875            return GetCaster() && GetCaster()->GetTypeId() == TYPEID_PLAYER;
3876        }
3877
3878        void SetBonusValueForEffect(SpellEffIndex effIndex, int32 value, AuraEffect const* aurEff)
3879        {
3880            if (aurEff->GetEffIndex() == uint32(effIndex))
3881                bonus = value;
3882        }
3883
3884        void CalculateAmount(AuraEffect const* aurEff, int32& amount, bool& /*canBeRecalculated*/)
3885        {
3886            if (GetCaster()->HasAura(SPELL_MIXOLOGY) && GetCaster()->HasSpell(GetSpellInfo()->Effects[EFFECT_0].TriggerSpell))
3887            {
3888                switch (GetId())
3889                {
3890                    case SPELL_WEAK_TROLLS_BLOOD_ELIXIR:
3891                    case SPELL_MAGEBLOOD_ELIXIR:
3892                        bonus = amount;
3893                        break;
3894                    case SPELL_ELIXIR_OF_FROST_POWER:
3895                    case SPELL_LESSER_FLASK_OF_TOUGHNESS:
3896                    case SPELL_LESSER_FLASK_OF_RESISTANCE:
3897                        bonus = CalculatePct(amount, 80);
3898                        break;
3899                    case SPELL_ELIXIR_OF_MINOR_DEFENSE:
3900                    case SPELL_ELIXIR_OF_LIONS_STRENGTH:
3901                    case SPELL_ELIXIR_OF_MINOR_AGILITY:
3902                    case SPELL_MAJOR_TROLLS_BLLOOD_ELIXIR:
3903                    case SPELL_ELIXIR_OF_SHADOW_POWER:
3904                    case SPELL_ELIXIR_OF_BRUTE_FORCE:
3905                    case SPELL_MIGHTY_TROLLS_BLOOD_ELIXIR:
3906                    case SPELL_ELIXIR_OF_GREATER_FIREPOWER:
3907                    case SPELL_ONSLAUGHT_ELIXIR:
3908                    case SPELL_EARTHEN_ELIXIR:
3909                    case SPELL_ELIXIR_OF_MAJOR_AGILITY:
3910                    case SPELL_FLASK_OF_THE_TITANS:
3911                    case SPELL_FLASK_OF_RELENTLESS_ASSAULT:
3912                    case SPELL_FLASK_OF_STONEBLOOD:
3913                    case SPELL_ELIXIR_OF_MINOR_ACCURACY:
3914                        bonus = CalculatePct(amount, 50);
3915                        break;
3916                    case SPELL_ELIXIR_OF_PROTECTION:
3917                        bonus = 280;
3918                        break;
3919                    case SPELL_ELIXIR_OF_MAJOR_DEFENSE:
3920                        bonus = 200;
3921                        break;
3922                    case SPELL_ELIXIR_OF_GREATER_DEFENSE:
3923                    case SPELL_ELIXIR_OF_SUPERIOR_DEFENSE:
3924                        bonus = 140;
3925                        break;
3926                    case SPELL_ELIXIR_OF_FORTITUDE:
3927                        bonus = 100;
3928                        break;
3929                    case SPELL_FLASK_OF_ENDLESS_RAGE:
3930                        bonus = 82;
3931                        break;
3932                    case SPELL_ELIXIR_OF_DEFENSE:
3933                        bonus = 70;
3934                        break;
3935                    case SPELL_ELIXIR_OF_DEMONSLAYING:
3936                        bonus = 50;
3937                        break;
3938                    case SPELL_FLASK_OF_THE_FROST_WYRM:
3939                        bonus = 47;
3940                        break;
3941                    case SPELL_WRATH_ELIXIR:
3942                        bonus = 32;
3943                        break;
3944                    case SPELL_ELIXIR_OF_MAJOR_FROST_POWER:
3945                    case SPELL_ELIXIR_OF_MAJOR_FIREPOWER:
3946                    case SPELL_ELIXIR_OF_MAJOR_SHADOW_POWER:
3947                        bonus = 29;
3948                        break;
3949                    case SPELL_ELIXIR_OF_MIGHTY_TOUGHTS:
3950                        bonus = 27;
3951                        break;
3952                    case SPELL_FLASK_OF_SUPREME_POWER:
3953                    case SPELL_FLASK_OF_BLINDING_LIGHT:
3954                    case SPELL_FLASK_OF_PURE_DEATH:
3955                    case SPELL_SHADOWPOWER_ELIXIR:
3956                        bonus = 23;
3957                        break;
3958                    case SPELL_ELIXIR_OF_MIGHTY_AGILITY:
3959                    case SPELL_FLASK_OF_DISTILLED_WISDOM:
3960                    case SPELL_ELIXIR_OF_SPIRIT:
3961                    case SPELL_ELIXIR_OF_MIGHTY_STRENGTH:
3962                    case SPELL_FLASK_OF_PURE_MOJO:
3963                    case SPELL_ELIXIR_OF_ACCURACY:
3964                    case SPELL_ELIXIR_OF_DEADLY_STRIKES:
3965                    case SPELL_ELIXIR_OF_MIGHTY_DEFENSE:
3966                    case SPELL_ELIXIR_OF_EXPERTISE:
3967                    case SPELL_ELIXIR_OF_ARMOR_PIERCING:
3968                    case SPELL_ELIXIR_OF_LIGHTNING_SPEED:
3969                        bonus = 20;
3970                        break;
3971                    case SPELL_FLASK_OF_CHROMATIC_RESISTANCE:
3972                        bonus = 17;
3973                        break;
3974                    case SPELL_ELIXIR_OF_MINOR_FORTITUDE:
3975                    case SPELL_ELIXIR_OF_MAJOR_STRENGTH:
3976                        bonus = 15;
3977                        break;
3978                    case SPELL_FLASK_OF_MIGHTY_RESTORATION:
3979                        bonus = 13;
3980                        break;
3981                    case SPELL_ARCANE_ELIXIR:
3982                        bonus = 12;
3983                        break;
3984                    case SPELL_ELIXIR_OF_GREATER_AGILITY:
3985                    case SPELL_ELIXIR_OF_GIANTS:
3986                        bonus = 11;
3987                        break;
3988                    case SPELL_ELIXIR_OF_AGILITY:
3989                    case SPELL_ELIXIR_OF_GREATER_INTELLECT:
3990                    case SPELL_ELIXIR_OF_SAGES:
3991                    case SPELL_ELIXIR_OF_IRONSKIN:
3992                    case SPELL_ELIXIR_OF_MIGHTY_MAGEBLOOD:
3993                        bonus = 10;
3994                        break;
3995                    case SPELL_ELIXIR_OF_HEALING_POWER:
3996                        bonus = 9;
3997                        break;
3998                    case SPELL_ELIXIR_OF_DRAENIC_WISDOM:
3999                    case SPELL_GURUS_ELIXIR:
4000                        bonus = 8;
4001                        break;
4002                    case SPELL_ELIXIR_OF_FIREPOWER:
4003                    case SPELL_ELIXIR_OF_MAJOR_MAGEBLOOD:
4004                    case SPELL_ELIXIR_OF_MASTERY:
4005                        bonus = 6;
4006                        break;
4007                    case SPELL_ELIXIR_OF_LESSER_AGILITY:
4008                    case SPELL_ELIXIR_OF_OGRES_STRENGTH:
4009                    case SPELL_ELIXIR_OF_WISDOM:
4010                    case SPELL_ELIXIR_OF_THE_MONGOOSE:
4011                        bonus = 5;
4012                        break;
4013                    case SPELL_STRONG_TROLLS_BLOOD_ELIXIR:
4014                    case SPELL_FLASK_OF_CHROMATIC_WONDER:
4015                        bonus = 4;
4016                        break;
4017                    case SPELL_ELIXIR_OF_EMPOWERMENT:
4018                        bonus = -10;
4019                        break;
4020                    case SPELL_ADEPTS_ELIXIR:
4021                        SetBonusValueForEffect(EFFECT_0, 13, aurEff);
4022                        SetBonusValueForEffect(EFFECT_1, 13, aurEff);
4023                        SetBonusValueForEffect(EFFECT_2, 8, aurEff);
4024                        break;
4025                    case SPELL_ELIXIR_OF_MIGHTY_FORTITUDE:
4026                        SetBonusValueForEffect(EFFECT_0, 160, aurEff);
4027                        break;
4028                    case SPELL_ELIXIR_OF_MAJOR_FORTITUDE:
4029                        SetBonusValueForEffect(EFFECT_0, 116, aurEff);
4030                        SetBonusValueForEffect(EFFECT_1, 6, aurEff);
4031                        break;
4032                    case SPELL_FEL_STRENGTH_ELIXIR:
4033                        SetBonusValueForEffect(EFFECT_0, 40, aurEff);
4034                        SetBonusValueForEffect(EFFECT_1, 40, aurEff);
4035                        break;
4036                    case SPELL_FLASK_OF_FORTIFICATION:
4037                        SetBonusValueForEffect(EFFECT_0, 210, aurEff);
4038                        SetBonusValueForEffect(EFFECT_1, 5, aurEff);
4039                        break;
4040                    case SPELL_GREATER_ARCANE_ELIXIR:
4041                        SetBonusValueForEffect(EFFECT_0, 19, aurEff);
4042                        SetBonusValueForEffect(EFFECT_1, 19, aurEff);
4043                        SetBonusValueForEffect(EFFECT_2, 5, aurEff);
4044                        break;
4045                    case SPELL_ELIXIR_OF_GIANTH_GROWTH:
4046                        SetBonusValueForEffect(EFFECT_0, 5, aurEff);
4047                        break;
4048                    default:
4049                        TC_LOG_ERROR("spells", "SpellId %u couldn't be processed in spell_gen_mixology_bonus", GetId());
4050                        break;
4051                }
4052                amount += bonus;
4053            }
4054        }
4055
4056        int32 bonus;
4057
4058        void Register() override
4059        {
4060            DoEffectCalcAmount += AuraEffectCalcAmountFn(spell_gen_mixology_bonus_AuraScript::CalculateAmount, EFFECT_ALL, SPELL_AURA_ANY);
4061        }
4062    };
4063
4064    AuraScript* GetAuraScript() const override
4065    {
4066        return new spell_gen_mixology_bonus_AuraScript();
4067    }
4068};
4069
4070void AddSC_generic_spell_scripts()
4071{
4072    new spell_gen_absorb0_hitlimit1();
4073    new spell_gen_adaptive_warding();
4074    new spell_gen_alchemist_stone();
4075    new spell_gen_allow_cast_from_item_only();
4076    new spell_gen_animal_blood();
4077    new spell_gen_aura_of_anger();
4078    new spell_gen_aura_service_uniform();
4079    new spell_gen_av_drekthar_presence();
4080    new spell_gen_bandage();
4081    new spell_gen_bonked();
4082    new spell_gen_break_shield("spell_gen_break_shield");
4083    new spell_gen_break_shield("spell_gen_tournament_counterattack");
4084    new spell_gen_burn_brutallus();
4085    new spell_gen_cannibalize();
4086    new spell_gen_chaos_blast();
4087    new spell_gen_clone();
4088    new spell_gen_clone_weapon();
4089    new spell_gen_clone_weapon_aura();
4090    new spell_gen_count_pct_from_max_hp("spell_gen_default_count_pct_from_max_hp");
4091    new spell_gen_count_pct_from_max_hp("spell_gen_50pct_count_pct_from_max_hp", 50);
4092    new spell_gen_create_lance();
4093    new spell_gen_creature_permanent_feign_death();
4094    new spell_gen_dalaran_disguise("spell_gen_sunreaver_disguise");
4095    new spell_gen_dalaran_disguise("spell_gen_silver_covenant_disguise");
4096    new spell_gen_defend();
4097    new spell_gen_despawn_self();
4098    new spell_gen_divine_storm_cd_reset();
4099    new spell_gen_ds_flush_knockback();
4100    new spell_gen_dummy_trigger();
4101    new spell_gen_dungeon_credit();
4102    new spell_gen_elune_candle();
4103    new spell_gen_gadgetzan_transporter_backfire();
4104    new spell_gen_gift_of_naaru();
4105    new spell_gen_gnomish_transporter();
4106    new spell_gen_increase_stats_buff("spell_pal_blessing_of_kings");
4107    new spell_gen_increase_stats_buff("spell_pal_blessing_of_might");
4108    new spell_gen_increase_stats_buff("spell_dru_mark_of_the_wild");
4109    new spell_gen_increase_stats_buff("spell_pri_power_word_fortitude");
4110    new spell_gen_increase_stats_buff("spell_pri_shadow_protection");
4111    new spell_gen_increase_stats_buff("spell_mage_arcane_brilliance");
4112    new spell_gen_increase_stats_buff("spell_mage_dalaran_brilliance");
4113    new spell_gen_interrupt();
4114    new spell_gen_lifebloom("spell_hexlord_lifebloom", SPELL_HEXLORD_MALACRASS_LIFEBLOOM_FINAL_HEAL);
4115    new spell_gen_lifebloom("spell_tur_ragepaw_lifebloom", SPELL_TUR_RAGEPAW_LIFEBLOOM_FINAL_HEAL);
4116    new spell_gen_lifebloom("spell_cenarion_scout_lifebloom", SPELL_CENARION_SCOUT_LIFEBLOOM_FINAL_HEAL);
4117    new spell_gen_lifebloom("spell_twisted_visage_lifebloom", SPELL_TWISTED_VISAGE_LIFEBLOOM_FINAL_HEAL);
4118    new spell_gen_lifebloom("spell_faction_champion_dru_lifebloom", SPELL_FACTION_CHAMPIONS_DRU_LIFEBLOOM_FINAL_HEAL);
4119    new spell_gen_mounted_charge();
4120    new spell_gen_netherbloom();
4121    new spell_gen_obsidian_armor();
4122    new spell_gen_on_tournament_mount();
4123    new spell_gen_oracle_wolvar_reputation();
4124    new spell_gen_orc_disguise();
4125    new spell_gen_parachute();
4126    new spell_gen_pet_summoned();
4127    new spell_gen_profession_research();
4128    new spell_gen_remove_flight_auras();
4129    new spell_gen_replenishment();
4130    // Running Wild
4131    new spell_gen_running_wild();
4132    new spell_gen_two_forms();
4133    new spell_gen_darkflight();
4134    /*                          */
4135    new spell_gen_seaforium_blast();
4136    new spell_gen_spectator_cheer_trigger();
4137    new spell_gen_spirit_healer_res();
4138    new spell_gen_summon_elemental("spell_gen_summon_fire_elemental", SPELL_SUMMON_FIRE_ELEMENTAL);
4139    new spell_gen_summon_elemental("spell_gen_summon_earth_elemental", SPELL_SUMMON_EARTH_ELEMENTAL);
4140    new spell_gen_summon_tournament_mount();
4141    new spell_gen_throw_shield();
4142    new spell_gen_tournament_duel();
4143    new spell_gen_tournament_pennant();
4144    new spell_pvp_trinket_wotf_shared_cd();
4145    new spell_gen_turkey_marker();
4146    new spell_gen_upper_deck_create_foam_sword();
4147    new spell_gen_vehicle_scaling();
4148    new spell_gen_vendor_bark_trigger();
4149    new spell_gen_wg_water();
4150    new spell_gen_whisper_gulch_yogg_saron_whisper();
4151    new spell_gen_eject_all_passengers();
4152    new spell_gen_eject_passenger();
4153    new spell_gen_gm_freeze();
4154    new spell_gen_stand();
4155    new spell_gen_mixology_bonus();
4156}