Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2.     Tommy @ EmuDevs
  3. */
  4. #include "WeatherMgr.h"
  5.  
  6. class on_gossip_change_weather : public CreatureScript
  7. {
  8. public:
  9.     on_gossip_change_weather() : CreatureScript("on_gossip_change_weather") { }
  10.  
  11.     bool OnGossipHello(Player* player, Creature* creature)
  12.     {
  13.         SendHello(player, creature);
  14.         return true;
  15.     }
  16.  
  17.     bool OnGossipSelect(Player* player, Creature* creature, uint32 /* sender */, uint32 actions)
  18.     {
  19.         player->PlayerTalkClass->ClearMenus();
  20.         Weather* weather = WeatherMgr::FindWeather(player->GetZoneId()); // See if weather is already going on
  21.         if (!weather) // No weather was found in the player's zone
  22.             weather = WeatherMgr::AddWeather(player->GetZoneId()); // Creating the weather
  23.         switch (actions)
  24.         {
  25.             case 1: // Change Weather (Show Options)
  26.                 SendWeatherOptions(player, creature);
  27.                 break;
  28.             case 2: // Nevermind
  29.                 player->CLOSE_GOSSIP_MENU();
  30.                 break;
  31.             case 3: // Normal Weather
  32.                 weather->SetWeather(WEATHER_TYPE_FINE, 0);
  33.                 break;
  34.             case 4: // Rain Weather
  35.                 weather->SetWeather(WEATHER_TYPE_RAIN, GetRandomGrade(WEATHER_TYPE_RAIN));
  36.                 break;
  37.             case 5: // Snow Weather
  38.                 weather->SetWeather(WEATHER_TYPE_SNOW, GetRandomGrade(WEATHER_TYPE_SNOW));
  39.                 break;
  40.             case 6: // Storm Weather
  41.                 weather->SetWeather(WEATHER_TYPE_STORM, GetRandomGrade(WEATHER_TYPE_STORM));
  42.                 break;
  43.             case 7: // Thunder Weather
  44.                 weather->SetWeather(WEATHER_TYPE_THUNDERS, 0);
  45.                 break;
  46.         }
  47.        
  48.         if (actions > 2) // Removing token
  49.             player->DestroyItemCount(60001, 1, true); // Change 30000 to the itemId
  50.     }
  51.  
  52.     void SendHello(Player* player, Creature* creature)
  53.     {
  54.         if (player->GetItemCount(60001) == 0) // Change 30000 to the correct itemId
  55.         {
  56.             ChatHandler(player->GetSession()).SendSysMessage("You need a shard of Azeroth to change the weather!");
  57.             return;
  58.         }
  59.  
  60.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "I want to use my shard to change the weather", 0, 1);
  61.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, "Nevermind..", 0, 2);
  62.         player->SEND_GOSSIP_MENU(1, creature->GetGUID());
  63.     }
  64.  
  65.     void SendWeatherOptions(Player* player, Creature* creature)
  66.     {
  67.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Normal Weather", 0, 3);
  68.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Rain Weather", 0, 4);
  69.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Snowy Weather", 0, 5);
  70.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Sandstorm Weather", 0, 6);
  71.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Thunder Weather", 0, 7);
  72.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, "Nevermind..", 0, 2);
  73.         player->SEND_GOSSIP_MENU(1, creature->GetGUID());
  74.     }
  75.  
  76.     WeatherState GetRandomGrade(WeatherType weatherType)
  77.     {
  78.         WeatherState tempState = WEATHER_STATE_FINE;
  79.         int randomNum = urand(0, 2);
  80.         switch (weatherType)
  81.         {
  82.             case WEATHER_TYPE_RAIN:
  83.                 if (randomNum == 0)
  84.                     tempState = WEATHER_STATE_LIGHT_RAIN;
  85.                 else if (randomNum == 1)
  86.                     tempState = WEATHER_STATE_MEDIUM_RAIN;
  87.                 else if (randomNum == 2)
  88.                     tempState == WEATHER_STATE_HEAVY_RAIN;
  89.                 break;
  90.             case WEATHER_TYPE_SNOW:
  91.                 if (randomNum == 0)
  92.                     tempState = WEATHER_STATE_LIGHT_SNOW;
  93.                 else if (randomNum == 1)
  94.                     tempState = WEATHER_STATE_MEDIUM_SNOW;
  95.                 else if (randomNum == 2)
  96.                     tempState == WEATHER_STATE_HEAVY_SNOW;
  97.                 break;
  98.             case WEATHER_TYPE_STORM:
  99.                 if (randomNum == 0)
  100.                     tempState = WEATHER_STATE_LIGHT_SANDSTORM;
  101.                 else if (randomNum == 1)
  102.                     tempState = WEATHER_STATE_MEDIUM_SANDSTORM;
  103.                 else if (randomNum == 2)
  104.                     tempState == WEATHER_STATE_HEAVY_SANDSTORM;
  105.                 break;
  106.         }
  107.  
  108.         return tempState;
  109.     }
  110. };
  111.  
  112. void WeatherChange()
  113. {
  114.     new on_gossip_change_weather;
  115. }