Advertisement
EmuDevs

Simon Says

Jun 6th, 2016
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.82 KB | None | 0 0
  1. /*
  2.    Simon Says
  3.    By Tommy
  4.    EmuDevs <http://emudevs.com>
  5. */
  6. enum NpcIds
  7. {
  8.     NPC_SPOTLIGHT_ONE               = 79900,
  9.     NPC_SPOTLIGHT_TWO               = 79901,
  10.     NPC_SPOTLIGHT_THREE             = 79902,
  11.     NPC_TURTLE_ONE                  = 79903,
  12.     NPC_FIRE_HAWK                   = 53245,
  13. };
  14.  
  15. enum SpellIds
  16. {
  17.     /* Spells */
  18.     SPELL_SPOTLIGHT                 = 50236,
  19. };
  20.  
  21. enum EventIds
  22. {
  23.     EVENT_NONE,
  24.     EVENT_EXPLAIN_1,
  25.     EVENT_EXPLAIN_2,
  26.     EVENT_EXPLAIN_SPOTLIGHT,
  27.     EVENT_SPOTLIGHT_1,
  28.     EVENT_SPOTLIGHT_2,
  29.     EVENT_CHECK_SPOTLIGHT,
  30.     EVENT_CHECK_SPOTLIGHT_2,
  31.     EVENT_EXPLAIN_KILL_CREATURE,
  32.     EVENT_EXPLAIN_KILL_CREATURE_START,
  33.     EVENT_CHECK_KILL_CREATURE
  34. };
  35.  
  36. static bool isEventActive = false;
  37.  
  38. class simon_himself : public CreatureScript
  39. {
  40. public:
  41.     simon_himself() : CreatureScript("simon_himself") { }
  42.  
  43.     bool OnGossipHello(Player* player, Creature* creature) override
  44.     {
  45.         if (isEventActive)
  46.         {
  47.             player->GetSession()->SendNotification("Event is already active!");
  48.             return false;
  49.         }
  50.  
  51.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Play Simon Says", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF);
  52.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Nevermind..", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
  53.         player->SEND_GOSSIP_MENU(1, creature->GetGUID());
  54.  
  55.         return true;
  56.     }
  57.  
  58.     bool OnGossipSelect(Player* player, Creature* creature, uint32 /* sender */, uint32 actions) override
  59.     {
  60.         player->PlayerTalkClass->ClearMenus();
  61.         simon_himselfAI* simonAI = CAST_AI(simon_himselfAI, creature->GetAI());
  62.  
  63.         if (actions == GOSSIP_ACTION_INFO_DEF)
  64.         {
  65.             simonAI->Start(player->GetGUID());
  66.             player->CLOSE_GOSSIP_MENU();
  67.         }
  68.         else
  69.             player->CLOSE_GOSSIP_MENU();
  70.  
  71.         return true;
  72.     }
  73.  
  74.     struct simon_himselfAI : public ScriptedAI
  75.     {
  76.         simon_himselfAI(Creature* creature) : ScriptedAI(creature) { }
  77.  
  78.         EventMap events;
  79.         uint64 playerGUID;
  80.         int killTimer;
  81.         int eventCheck;
  82.         float x, y, z;
  83.  
  84.         void Reset() override
  85.         {
  86.             events.Reset();
  87.             eventCheck = 0;
  88.             playerGUID = 0;
  89.             killTimer = 0;
  90.         }
  91.  
  92.         void UpdateAI(uint32 diff) override
  93.         {
  94.             events.Update(diff);
  95.             while (uint32 eventId = events.ExecuteEvent())
  96.             {
  97.                 switch (eventId)
  98.                 {
  99.                     case EVENT_EXPLAIN_1:
  100.                         Explain("Waz up!? Today, we're going to play Simon Says! What's Simon says? Well, you do as I say and you will win! Else, you will BE A LOSER!");
  101.                         events.ScheduleEvent(EVENT_EXPLAIN_2, 7000);
  102.                         break;
  103.                     case EVENT_EXPLAIN_2:
  104.                         Explain("Let's play.");
  105.                         events.ScheduleEvent(EVENT_SPOTLIGHT_1, 3000);
  106.                         break;
  107.                     case EVENT_SPOTLIGHT_1:
  108.                         me->GetPosition(x, y, z);
  109.                         spotLight = me->SummonCreature(NPC_SPOTLIGHT_ONE, x, y - 7, z, 0, TEMPSUMMON_MANUAL_DESPAWN, 0);
  110.                         AddLight(spotLight);
  111.                         Explain("We're going to play a game called spotlight! Alright, Simon Says jump into the spotlight!");
  112.                         events.ScheduleEvent(EVENT_CHECK_SPOTLIGHT, 1000);
  113.                         break;
  114.                     case EVENT_CHECK_SPOTLIGHT:
  115.                         if (spotLight)
  116.                         {
  117.                             if (CheckPlayerDistance(spotLight) <= 2.0f && eventCheck == 0)
  118.                             {
  119.                                 events.CancelEvent(EVENT_CHECK_SPOTLIGHT);
  120.                                 spotLight->DespawnOrUnsummon(100);
  121.                                 Explain("Ha! Okay, that much was obvious!");
  122.                                 events.ScheduleEvent(EVENT_EXPLAIN_SPOTLIGHT, 2000);
  123.                                 eventCheck++;
  124.                             }
  125.                         }
  126.                         if (eventCheck == 0)
  127.                             events.ScheduleEvent(EVENT_CHECK_SPOTLIGHT, 1000);
  128.                         break;
  129.                     case EVENT_EXPLAIN_SPOTLIGHT:
  130.                         Explain("Now I want you to beg for mercy! Wait.. that was harsh.. Simon says GET INTO THE SPOTLIGHT YOU WERE PREVIOUSLY IN!");
  131.                         events.ScheduleEvent(EVENT_SPOTLIGHT_2, 8000);
  132.                         break;
  133.                     case EVENT_SPOTLIGHT_2:
  134.                         spotLight = me->SummonCreature(NPC_SPOTLIGHT_ONE, x - 10, y - 7, z, 0, TEMPSUMMON_MANUAL_DESPAWN, 0);
  135.                         spotLightTwo = me->SummonCreature(NPC_SPOTLIGHT_TWO, x + 10, y - 7, z, 0, TEMPSUMMON_MANUAL_DESPAWN, 0);
  136.                         spotLightThree = me->SummonCreature(NPC_SPOTLIGHT_THREE, x + 25, y, z, 0, TEMPSUMMON_MANUAL_DESPAWN, 0);
  137.                         AddLight(spotLight);
  138.                         AddLight(spotLightTwo);
  139.                         AddLight(spotLightThree);
  140.                         events.ScheduleEvent(EVENT_CHECK_SPOTLIGHT_2, 1000);
  141.                         break;
  142.                     case EVENT_CHECK_SPOTLIGHT_2:
  143.                         if (spotLight && spotLightTwo && spotLightThree)
  144.                         {
  145.                             if (CheckPlayerDistance(spotLightTwo) <= 2.0f || CheckPlayerDistance(spotLightThree) <= 2.0f)
  146.                             {
  147.                                 spotLight->DespawnOrUnsummon(100);
  148.                                 spotLightTwo->DespawnOrUnsummon(100);
  149.                                 spotLightThree->DespawnOrUnsummon(100);
  150.                                 _Reset();
  151.                                 Explain("HAHA, you lost! No rewards for you!");
  152.                                 return;
  153.                             }
  154.  
  155.                             if (CheckPlayerDistance(spotLight) <= 2.0f && eventCheck == 1)
  156.                             {
  157.                                 events.CancelEvent(EVENT_CHECK_SPOTLIGHT_2);
  158.                                 spotLight->DespawnOrUnsummon(100);
  159.                                 spotLightTwo->DespawnOrUnsummon(100);
  160.                                 spotLightThree->DespawnOrUnsummon(100);
  161.                                 Explain("Darn! You actually did it... Simon is getting MAD!");
  162.                                 eventCheck++;
  163.                                 events.ScheduleEvent(EVENT_EXPLAIN_KILL_CREATURE, 5000);
  164.                             }
  165.                         }
  166.                         if (eventCheck == 1)
  167.                             events.ScheduleEvent(EVENT_CHECK_SPOTLIGHT_2, 1000);
  168.                         break;
  169.                     case EVENT_EXPLAIN_KILL_CREATURE:
  170.                         Explain("Simon says kill this Fire Hawk in 6 seconds!");
  171.                         events.ScheduleEvent(EVENT_EXPLAIN_KILL_CREATURE_START, 5000);
  172.                         break;
  173.                     case EVENT_EXPLAIN_KILL_CREATURE_START:
  174.                         Explain("GO!");
  175.                         fireHawk = me->SummonCreature(NPC_FIRE_HAWK, x, y - 5, z, 1.0, TEMPSUMMON_MANUAL_DESPAWN, 0);
  176.                         events.ScheduleEvent(EVENT_CHECK_KILL_CREATURE, 1000);
  177.                         break;
  178.                     case EVENT_CHECK_KILL_CREATURE:
  179.                         if (fireHawk)
  180.                         {
  181.                             if (killTimer >= 6 && eventCheck == 2)
  182.                             {
  183.                                 if (!fireHawk->IsAlive())
  184.                                 {
  185.                                      events.CancelEvent(EVENT_CHECK_KILL_CREATURE);
  186.                                      fireHawk->DespawnOrUnsummon(100);
  187.                                      Explain("Wow, you win! Congratulations!");
  188.                                      WinOrLose(true);
  189.                                      eventCheck++;
  190.                                      _Reset();
  191.                                 }
  192.                                 else
  193.                                 {
  194.                                     fireHawk->DespawnOrUnsummon(100);
  195.                                     _Reset();
  196.                                     Explain("HA, you lose!");
  197.                                 }
  198.                             }
  199.                             killTimer++;
  200.                         }
  201.                         if (eventCheck == 2)
  202.                             events.ScheduleEvent(EVENT_CHECK_KILL_CREATURE, 1000);
  203.                         break;
  204.                 }
  205.             }
  206.         }
  207.  
  208.         float CheckPlayerDistance(Creature* target)
  209.         {
  210.             if (!target)
  211.                 return 0;
  212.  
  213.             if (Player* player = ObjectAccessor::GetPlayer(*target, playerGUID);)
  214.                 return target->GetDistance2d(player);
  215.             return NULL;
  216.         }
  217.  
  218.         void Explain(const char* msg)
  219.         {
  220.             me->Say(msg, LANG_UNIVERSAL, 0);
  221.             me->HandleEmoteCommand(EMOTE_ONESHOT_TALK);
  222.         }
  223.  
  224.         void WinOrLose(bool won) // Call this if the player wins or loses
  225.         {
  226.             Player* player = ObjectAccessor::GetPlayer(*me, playerGUID);
  227.             if (player)
  228.             {
  229.                 if (player->GetGUID() == playerGUID)
  230.                 {
  231.                     if (won) // If the player won
  232.                     {
  233.                     }
  234.                     else // If the player lost
  235.                     {
  236.                     }
  237.                 }
  238.             }
  239.         }
  240.  
  241.         void Start(uint64 guid) // Starts the event
  242.         {
  243.             playerGUID = guid;
  244.             me->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
  245.             events.ScheduleEvent(EVENT_EXPLAIN_1, 1000);
  246.         }
  247.  
  248.         void AddLight(Creature* creature) // Adds spotlight to the specified creature
  249.         {
  250.             if (!creature)
  251.                 return;
  252.  
  253.             creature->AddAura(SPELL_SPOTLIGHT, creature);
  254.         }
  255.  
  256.         void _Reset()
  257.         {
  258.             spotLight = NULL;
  259.             spotLightTwo = NULL;
  260.             spotLightThree = NULL;
  261.             fireHawk = NULL;
  262.             eventCheck = 0;
  263.             playerGUID = 0;
  264.             killTimer = 0;
  265.             isEventActive = false;
  266.             me->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
  267.             events.Reset();
  268.         }
  269.  
  270.         private:
  271.             Creature* spotLight;
  272.             Creature* spotLightTwo;
  273.             Creature* spotLightThree;
  274.             Creature* fireHawk;
  275.     };
  276.  
  277.     CreatureAI* GetAI(Creature* creature) const override
  278.     {
  279.         return new simon_himselfAI(creature);
  280.     }
  281. };
  282.  
  283. void AddSC_simon_says()
  284. {
  285.     new simon_himself();
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement