Advertisement
EmuDevs

EmuDevs: TrinityCore Simple Simon Says Game

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