Advertisement
sopse

Darkmoon Faire

Jan 11th, 2016
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.46 KB | None | 0 0
  1. #include "ScriptMgr.h"
  2. #include "Player.h"
  3. #include "GameObject.h"
  4. #include "GameObjectAI.h"
  5. //#include "EventMap.h"
  6.  
  7. enum events
  8. {
  9.     TONK_EVENT_CHECK = 1,
  10.     BLASTENHEIMER_EVENT_CHECK = 2,
  11. };
  12.  
  13. //Blastenheimer 5000 Ultra Cannon
  14. class Blastenheimer : public GameObjectScript
  15. {
  16. public:
  17.     Blastenheimer() : GameObjectScript("Blastenheimer") { }
  18.  
  19.     struct BlastenheimerAI : public GameObjectAI
  20.     {
  21.         BlastenheimerAI(GameObject* go) : GameObjectAI(go) { }
  22.  
  23.         bool GossipHello(Player* player) override
  24.         {
  25.             plr = player;
  26.             player->CastSpell(player, 24832);
  27.             player->SetMovement(MOVE_ROOT);
  28.             plr->NearTeleportTo(-10785.190430f, 785.208557f, 32.695553f, 1.458903f);
  29.             _events.ScheduleEvent(BLASTENHEIMER_EVENT_CHECK, 2200);
  30.             return true;
  31.         }
  32.  
  33.         void UpdateAI(uint32 diff) override
  34.         {
  35.             if (_events.Empty())
  36.                 return;
  37.  
  38.             _events.Update(diff);
  39.  
  40.             while (uint32 eventId = _events.ExecuteEvent())
  41.             {
  42.                 switch (eventId)
  43.                 {
  44.                 case BLASTENHEIMER_EVENT_CHECK:
  45.                     if (!plr)
  46.                         return;
  47.  
  48.                     if (!plr->IsAlive())
  49.                         return;                
  50.  
  51.                     plr->SetMovement(MOVE_UNROOT);
  52.                     plr->CastSpell(plr, 42867);
  53.                     plr->RemoveAura(24832);
  54.                     plr = NULL; //reset the pointer
  55.                     break;
  56.                 }
  57.             }
  58.         }
  59.  
  60.         Player* plr;
  61.         EventMap _events;
  62.     };
  63.  
  64.     GameObjectAI* GetAI(GameObject* go) const override
  65.     {
  66.         return new BlastenheimerAI(go);
  67.     }
  68. };
  69.  
  70. // Tonk Controller
  71. class TonkControlConsole : public GameObjectScript
  72. {
  73. public:
  74.     TonkControlConsole() : GameObjectScript("TonkControlConsole") { }
  75.  
  76.     struct TonkControlConsoleAI : public GameObjectAI
  77.     {
  78.         TonkControlConsoleAI(GameObject* go) : GameObjectAI(go) { }
  79.  
  80.         bool GossipHello(Player* player) override
  81.         {
  82.             tonkConsole = NULL;
  83.             tonk = NULL;
  84.  
  85.             plr = player;
  86.             tonkConsole = player->FindNearestGameObject(180524, 1000.0f);
  87.  
  88.             // Open and disable the Tonk Console
  89.             tonkConsole->SetUInt32Value(GAMEOBJECT_FLAGS, 1);
  90.             tonkConsole->SetGoState(GO_STATE_ACTIVE);
  91.  
  92.             // Spawn Steam Tonk
  93.             player->SummonCreature(19405, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation(), TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1000);
  94.  
  95.             // Store the tonk just spawned
  96.             tonk = NULL;
  97.             tonk = player->FindNearestCreature(19405, 100.0f);
  98.  
  99.             if (!tonk || !tonk->IsAlive())
  100.                 return false;
  101.  
  102.             player->CastSpell(tonk, 33849);
  103.  
  104.             _events.ScheduleEvent(TONK_EVENT_CHECK, 500);
  105.             return true;
  106.         }
  107.  
  108.         void UpdateAI(uint32 diff) override
  109.         {
  110.             if (_events.Empty())
  111.                 return;
  112.  
  113.             _events.Update(diff);
  114.  
  115.             while (uint32 eventId = _events.ExecuteEvent())
  116.             {
  117.                 switch (eventId)
  118.                 {
  119.                 case TONK_EVENT_CHECK:
  120.  
  121.                     if (!plr || !tonk)
  122.                         return;
  123.  
  124.                     if (!plr->HasAura(33849) || !tonk->IsAlive())
  125.                     {
  126.                         // Kill then Despawn Tonk
  127.                         plr->Kill(tonk, false);
  128.                         plr->CastSpell(plr, 2880);
  129.                         plr->RemoveAura(33849);
  130.                         tonk->DespawnOrUnsummon(1000);
  131.  
  132.                         // Close the console so others can access it
  133.                         tonkConsole->SetUInt32Value(GAMEOBJECT_FLAGS, 0);
  134.                         tonkConsole->SetGoState(GO_STATE_READY);
  135.                     }
  136.                     else
  137.                         _events.ScheduleEvent(TONK_EVENT_CHECK, 100);
  138.  
  139.                     break;
  140.                 }
  141.             }
  142.         }
  143.  
  144.         EventMap _events;
  145.         Creature* tonk = NULL;
  146.         Player* plr = NULL;
  147.         GameObject* tonkConsole = NULL;
  148.     };
  149.  
  150.     GameObjectAI* GetAI(GameObject* go) const override
  151.     {
  152.         return new TonkControlConsoleAI(go);
  153.     }
  154. };
  155.  
  156. void AddSC_darkmoonfaire()
  157. {
  158.     new TonkControlConsole();
  159.     new Blastenheimer();
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement