Advertisement
adriancs35

Immerseus <Tears of the Vale>

Apr 13th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.67 KB | None | 0 0
  1. #include "ScriptedCreature.h"
  2. #include "siege_of_orgrimmar.h"
  3.  
  4. enum eSpells
  5. {
  6.     /* Immerseus */
  7.     SPELL_SWIRL             = 143309,
  8.     SPELL_CORROSIVE_BLAST   = 143436,
  9.     SPELL_SEEPING_SHA       = 143281, // Areatrigger 1016 (143286)
  10.     SPELL_SPLIT             = 143020,
  11.     SPELL_REFORM            = 143469,
  12.     SPELL_BERSERK           = 64238,
  13.     SPELL_ZERO_POWER        = 72242,
  14.  
  15.     /* Puddles */
  16.     SPELL_ERUPTING_SHA      = 143498,
  17.     SPELL_ERUPTING_WATER    = 145377,
  18.     SPELL_SHA_RESIDUE       = 143459,
  19.     SPELL_PURIFIED          = 143523,
  20.     SPELL_PURIFIED_RESIDUE  = 143524,
  21.     SPELL_CONGEALING_VISUAL = 143538,
  22.     SPELL_CONGEALING        = 143540,
  23. };
  24.  
  25. enum eEvents
  26. {
  27.     /* Immerseus */
  28.     EVENT_BERSERK           = 1,
  29.     EVENT_SPLIT             = 2,
  30.     EVENT_CORROSIVE_BLAST   = 3,
  31.     EVENT_PHASE_SWIRL       = 4,
  32.     EVENT_SWIRL             = 5,
  33.     EVENT_SWIRL_ORIENTATION = 6,
  34. };
  35.  
  36. enum ePhases
  37. {
  38.     PHASE_NULL,
  39.     PHASE_COMBAT,
  40.     PHASE_SPLIT,
  41.     PHASE_SWIRL,
  42. };
  43.  
  44. #define ERUPTING_SHA_DIST   20.0f
  45.  
  46. static Creature *GetImmerseus(WorldObject *pSource)
  47. {
  48.     return ObjectAccessor::GetCreature(*pSource, pSource->GetInstanceScript()->GetData64(BOSS_IMMERSEUS));
  49. }
  50.  
  51. class boss_immerseus : public CreatureScript
  52. {
  53. public:
  54.     boss_immerseus() : CreatureScript("boss_immerseus") { }
  55.  
  56.     CreatureAI* GetAI(Creature* creature) const
  57.     {
  58.         if (!creature->GetVehicleKit())
  59.         {
  60.             TC_LOG_ERROR(LOG_FILTER_TSCR, "boss_immerseus_AI: creature should be a vehicle.");
  61.             return NULL;
  62.         }
  63.  
  64.         return GetSiegeOfOrgrimmarAI<boss_immerseus_AI>(creature);
  65.     }
  66.  
  67.     struct boss_immerseus_AI : public BossAI
  68.     {
  69.         boss_immerseus_AI(Creature* creature) :
  70.             BossAI(creature, DATA_IMMERSEUS) { }
  71.  
  72.         void Reset() override
  73.         {
  74.             _Reset();
  75.             events.Reset();
  76.             summons.DespawnAll();
  77.  
  78.             me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE);
  79.  
  80.             me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
  81.             me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
  82.  
  83.             me->setPowerType(POWER_ENERGY);
  84.             me->SetMaxPower(POWER_ENERGY, me->GetCreatePowers(POWER_ENERGY));
  85.  
  86.             DoCast(me, SPELL_ZERO_POWER);
  87.             me->SetPower(POWER_ENERGY, 100);
  88.  
  89.             me->RemoveAurasDueToSpell(SPELL_BERSERK);
  90.  
  91.             events.SetPhase(PHASE_NULL);
  92.  
  93.             DoCast(SPELL_SEEPING_SHA);
  94.  
  95.             instance->SetData(DATA_IMMERSEUS, NOT_STARTED);
  96.         }
  97.  
  98.         void JustDied(Unit* /*killer*/) override
  99.         {
  100.             instance->SetData(DATA_IMMERSEUS, DONE);
  101.  
  102.             summons.DespawnAll();
  103.         }
  104.  
  105.         void DamageTaken(Unit* /*killer*/, uint32 &damage) override
  106.         {
  107.             if (damage >= me->GetHealth())
  108.             {
  109.                 damage = 0;
  110.  
  111.                 events.SetPhase(PHASE_SPLIT);
  112.                 events.ScheduleEvent(EVENT_SPLIT, 0, 0, PHASE_SPLIT);
  113.             }
  114.         }
  115.  
  116.         void JustSummoned(Creature* summon) override
  117.         {
  118.             summons.Summon(summon);
  119.         }
  120.  
  121.         void SummonedCreatureDespawn(Creature* summon) override
  122.         {
  123.             summons.Despawn(summon);
  124.         }
  125.  
  126.         void EnterCombat(Unit* /*who*/) override
  127.         {
  128.             _EnterCombat();
  129.  
  130.             events.SetPhase(PHASE_COMBAT);
  131.             events.ScheduleEvent(EVENT_BERSERK, 10 * MINUTE * IN_MILLISECONDS, 0, PHASE_COMBAT);
  132.             events.ScheduleEvent(EVENT_CORROSIVE_BLAST, 10 * IN_MILLISECONDS, 0, PHASE_COMBAT);
  133.             events.ScheduleEvent(EVENT_SWIRL, 19 * IN_MILLISECONDS, 0, PHASE_COMBAT);
  134.  
  135.             instance->SetData(DATA_IMMERSEUS, IN_PROGRESS);
  136.         }
  137.  
  138.         void UpdateAI(uint32 diff) override
  139.         {
  140.             if (!UpdateVictim())
  141.                 return;
  142.  
  143.             if (me->HasUnitState(UNIT_STATE_CASTING) && !events.IsInPhase(PHASE_SWIRL))
  144.                 return;
  145.  
  146.             events.Update(diff);
  147.  
  148.             if (events.IsInPhase(PHASE_COMBAT) && me->GetPower(POWER_ENERGY) <= 0)
  149.                 me->Kill(me);
  150.  
  151.             switch (events.ExecuteEvent())
  152.             {
  153.                 case EVENT_BERSERK:
  154.                     DoCast(SPELL_BERSERK);
  155.  
  156.                     events.CancelEvent(EVENT_BERSERK);
  157.                     break;
  158.  
  159.                 case EVENT_SPLIT:
  160.                     DoCast(SPELL_SPLIT);
  161.  
  162.                     me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
  163.                     me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
  164.  
  165.                     events.CancelEvent(EVENT_SPLIT);
  166.                     break;
  167.  
  168.                 case EVENT_CORROSIVE_BLAST:
  169.                     DoCastVictim(SPELL_CORROSIVE_BLAST);
  170.  
  171.                     events.ScheduleEvent(EVENT_CORROSIVE_BLAST, 23 * IN_MILLISECONDS, 0, PHASE_COMBAT);
  172.                     break;
  173.  
  174.                 case EVENT_PHASE_SWIRL:
  175.                     events.SetPhase(PHASE_SWIRL);
  176.                     events.ScheduleEvent(EVENT_SWIRL, 0, 0, PHASE_SWIRL);
  177.  
  178.                     events.CancelEvent(EVENT_PHASE_SWIRL);
  179.                     break;
  180.  
  181.                 case EVENT_SWIRL:
  182.                     DoCast(SPELL_SWIRL);
  183.                     events.ScheduleEvent(EVENT_SWIRL_ORIENTATION, 0, 0, PHASE_SWIRL);
  184.                     events.ScheduleEvent(EVENT_SWIRL, 20 * IN_MILLISECONDS, 0, PHASE_COMBAT);
  185.                     break;
  186.  
  187.                 case EVENT_SWIRL_ORIENTATION:
  188.                 {
  189.                     uint32 duration = 0;
  190.                     float pitch = float(M_PI * 2 * (1 / 3) / 10 * IN_MILLISECONDS);
  191.  
  192.                     while (duration < 10 * IN_MILLISECONDS)
  193.                     {
  194.                         float newOrientation = pitch + me->GetOrientation();
  195.  
  196.                         if (newOrientation > M_PI * 2)
  197.                             newOrientation -= M_PI * 2;
  198.  
  199.                         me->SetOrientation(newOrientation);
  200.                         me->SendMovementUpdate();
  201.                         duration++;
  202.                     }
  203.                    
  204.                     events.SetPhase(PHASE_COMBAT);
  205.                     events.CancelEvent(EVENT_SWIRL_ORIENTATION);
  206.                     break;
  207.                 }
  208.  
  209.                 default:
  210.                     break;
  211.             }
  212.  
  213.             DoMeleeAttackIfReady();
  214.         }
  215.     };
  216. };
  217.  
  218. // #71603# Sha Puddle
  219. class npc_sha_puddle : public CreatureScript
  220. {
  221. public:
  222.     npc_sha_puddle() : CreatureScript("npc_sha_puddle") { }
  223.  
  224.     struct npc_sha_puddleAI : public ScriptedAI
  225.     {
  226.         npc_sha_puddleAI(Creature* creature) : ScriptedAI(creature)
  227.         {
  228.             instance = creature->GetInstanceScript();
  229.         }
  230.  
  231.         InstanceScript* instance;
  232.  
  233.         void Reset() override
  234.         {
  235.             me->SetReactState(REACT_PASSIVE);
  236.            
  237.             if (instance)
  238.                 if (Creature* immerseus = GetImmerseus(me))
  239.                     me->GetMotionMaster()->MovePoint(0, immerseus->GetPositionX(), immerseus->GetPositionY(), immerseus->GetPositionZ());
  240.         }
  241.  
  242.         void JustDied(Unit* /*killer*/) override
  243.         {
  244.             if (instance)
  245.                 if (Creature* immerseus = GetImmerseus(me))
  246.                     immerseus->ModifyPower(POWER_ENERGY, -1);
  247.  
  248.             DoCast(SPELL_SHA_RESIDUE);
  249.  
  250.             me->DespawnOrUnsummon(4 * IN_MILLISECONDS);
  251.         }
  252.  
  253.         void EnterCombat(Unit* who) override { }
  254.  
  255.         void UpdateAI(uint32 diff) override
  256.         {
  257.             if (instance)
  258.                 if (Creature* immerseus = GetImmerseus(me))
  259.                     if (me->GetExactDist2d(immerseus) <= 25.0f)
  260.                     {
  261.                         DoCast(SPELL_ERUPTING_SHA);
  262.                         me->DespawnOrUnsummon();
  263.                     }
  264.         }
  265.     };
  266.  
  267.     CreatureAI* GetAI(Creature* creature) const override
  268.     {
  269.         return new npc_sha_puddleAI(creature);
  270.     }
  271. };
  272.  
  273. // #71604# Contaminated Puddle
  274. class npc_contaminated_puddle : public CreatureScript
  275. {
  276. public:
  277.     npc_contaminated_puddle() : CreatureScript("npc_contaminated_puddle") { }
  278.  
  279.     struct npc_contaminated_puddleAI : public ScriptedAI
  280.     {
  281.         npc_contaminated_puddleAI(Creature* creature) : ScriptedAI(creature)
  282.         {
  283.             instance = creature->GetInstanceScript();
  284.         }
  285.  
  286.         InstanceScript* instance;
  287.         bool fullHealth;
  288.  
  289.         void Reset() override
  290.         {
  291.             fullHealth = false;
  292.  
  293.             me->SetReactState(REACT_PASSIVE);
  294.  
  295.             me->SetHealth(int32(me->GetMaxHealth() * .1f));
  296.  
  297.             if (instance)
  298.                 if (Creature* immerseus = GetImmerseus(me))
  299.                     me->GetMotionMaster()->MovePoint(0, immerseus->GetPositionX(), immerseus->GetPositionY(), immerseus->GetPositionZ());
  300.         }
  301.  
  302.         void HealReceived(Unit* /*healer*/, uint32& heal) override
  303.         {
  304.             if (!me->HasAura(SPELL_CONGEALING_VISUAL))
  305.             {
  306.                 DoCast(SPELL_CONGEALING_VISUAL);
  307.                 DoCast(SPELL_CONGEALING);
  308.             }
  309.  
  310.             if (!fullHealth && heal >= me->GetMaxHealth() - me->GetHealth())
  311.             {
  312.                 me->RemoveAurasDueToSpell(SPELL_CONGEALING);
  313.  
  314.                 DoCast(SPELL_PURIFIED);
  315.                 DoCast(SPELL_PURIFIED_RESIDUE);
  316.  
  317.                 if (instance)
  318.                     if (Creature* immerseus = GetImmerseus(me))
  319.                         immerseus->ModifyPower(POWER_ENERGY, -1);
  320.  
  321.                 fullHealth = true;
  322.             }
  323.         }
  324.  
  325.         void JustDied(Unit* /*killer*/) override { }
  326.  
  327.         void EnterCombat(Unit* who) override { }
  328.  
  329.         void UpdateAI(uint32 diff) override
  330.         {
  331.             if (int32 healthPerStack = me->GetHealth() / me->GetMaxHealth() * 10)
  332.                 if (Aura* congealing = me->GetAura(SPELL_CONGEALING))
  333.                     if (healthPerStack > 1)
  334.                         congealing->SetStackAmount(healthPerStack);
  335.  
  336.             if (instance)
  337.                 if (Creature* immerseus = GetImmerseus(me))
  338.                     if (me->GetExactDist2d(immerseus) <= 25.0f)
  339.                     {
  340.                         if (!me->HasAura(SPELL_PURIFIED))
  341.                             DoCast(SPELL_ERUPTING_WATER);
  342.  
  343.                         me->DespawnOrUnsummon();
  344.                     }
  345.         }
  346.     };
  347.  
  348.     CreatureAI* GetAI(Creature* creature) const override
  349.     {
  350.         return new npc_contaminated_puddleAI(creature);
  351.     }
  352. };
  353.  
  354. void AddSC_immerseus()
  355. {
  356.     sScriptMgr->AddScript(new boss_immerseus());
  357.     sScriptMgr->AddScript(new npc_sha_puddle());
  358.     sScriptMgr->AddScript(new npc_contaminated_puddle());
  359. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement