Advertisement
Deathsoul

Arena top

Mar 6th, 2013
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.66 KB | None | 0 0
  1. *****************************************
  2. *Made By -??                 *
  3. *                                       *
  4. *****************************************
  5.  
  6.  
  7.  
  8. #include "ScriptPCH.h"
  9. #include <cstring>
  10. #include <string.h>
  11. #include "ObjectMgr.h"
  12. #include "ScriptMgr.h"
  13. #include "ArenaTeam.h"
  14. #include "World.h"
  15.  
  16. enum enus
  17. {
  18.     ARENA_MAX_RESULTS = 10,
  19.     ARENA_2V2_LADDER = GOSSIP_ACTION_INFO_DEF + 1,
  20.     ARENA_3V3_LADDER = GOSSIP_ACTION_INFO_DEF + 2,
  21.     ARENA_5V5_LADDER = GOSSIP_ACTION_INFO_DEF + 3,
  22.     ARENA_GOODBYE = GOSSIP_ACTION_INFO_DEF + 4,
  23.     ARENA_START_TEAM_LOOKUP = GOSSIP_ACTION_INFO_DEF + 5,
  24.     ARENA_HELP = GOSSIP_ACTION_INFO_DEF + 9999,
  25. };
  26.  
  27. class arena_top_teams : public CreatureScript
  28. {
  29.     private:
  30.     uint32 optionToTeamType(uint32 option)
  31.     {
  32.         uint32 teamType;
  33.         switch(option)
  34.         {
  35.             case ARENA_2V2_LADDER:
  36.                 teamType = 2;
  37.             break;
  38.                    
  39.             case ARENA_3V3_LADDER:
  40.                 teamType = 3;
  41.             break;
  42.                
  43.             case ARENA_5V5_LADDER:
  44.                 teamType = 5;
  45.             break;
  46.         }
  47.         return teamType;
  48.     }
  49.        
  50.     uint32 teamTypeToOption(uint32 teamType)
  51.     {
  52.         uint32 option;
  53.         switch(teamType)
  54.         {
  55.             case 2:
  56.                 option = ARENA_2V2_LADDER;
  57.             break;
  58.                    
  59.             case 3:
  60.                 option = ARENA_3V3_LADDER;
  61.             break;
  62.                    
  63.             case 5:
  64.                 option = ARENA_5V5_LADDER;
  65.             break;
  66.         }
  67.         return option;
  68.     }
  69.        
  70.     std::string raceToString(uint8 race)
  71.     {
  72.         std::string race_s = "Unknown";
  73.         switch (race)
  74.         {
  75.             case RACE_HUMAN:            
  76.                 race_s = "Human";      
  77.             break;
  78.                
  79.             case RACE_ORC:              
  80.                 race_s = "Orc";        
  81.             break;
  82.                
  83.             case RACE_DWARF:          
  84.                 race_s = "Dwarf";      
  85.             break;
  86.                
  87.             case RACE_NIGHTELF:        
  88.                 race_s = "Night Elf";  
  89.             break;
  90.                
  91.             case RACE_UNDEAD_PLAYER:  
  92.                 race_s = "Undead";      
  93.             break;
  94.                
  95.             case RACE_TAUREN:          
  96.                 race_s = "Tauren";      
  97.             break;
  98.                
  99.             case RACE_GNOME:            
  100.                 race_s = "Gnome";      
  101.             break;
  102.                
  103.             case RACE_TROLL:            
  104.                 race_s = "Troll";      
  105.             break;
  106.                
  107.             case RACE_BLOODELF:        
  108.                 race_s = "Blood Elf";  
  109.             break;
  110.                
  111.             case RACE_DRAENEI:          
  112.                 race_s = "Draenei";    
  113.             break;
  114.         }
  115.         return race_s;
  116.     }
  117.        
  118.     std::string classToString(uint8 Class)
  119.     {
  120.         std::string Class_s = "Unknown";
  121.         switch (Class)
  122.         {
  123.             case CLASS_WARRIOR:        
  124.                 Class_s = "Warrior";        
  125.             break;
  126.                
  127.             case CLASS_PALADIN:        
  128.                 Class_s = "Paladin";      
  129.             break;
  130.                
  131.             case CLASS_HUNTER:        
  132.                 Class_s = "Hunter";        
  133.             break;
  134.                
  135.             case CLASS_ROGUE:          
  136.                 Class_s = "Rogue";          
  137.             break;
  138.                
  139.             case CLASS_PRIEST:
  140.                 Class_s = "Priest";
  141.             break;
  142.                
  143.             case CLASS_DEATH_KNIGHT:
  144.                 Class_s = "Death Knight";
  145.             break;
  146.                
  147.             case CLASS_SHAMAN:
  148.                 Class_s = "Shaman";      
  149.             break;
  150.                
  151.             case CLASS_MAGE:
  152.                 Class_s = "Mage";          
  153.             break;
  154.                
  155.             case CLASS_WARLOCK:
  156.                 Class_s = "Warlock";      
  157.             break;
  158.                
  159.             case CLASS_DRUID:          
  160.                 Class_s = "Druid";          
  161.             break;
  162.         }
  163.         return Class_s;
  164.     }
  165.        
  166.     std::string getPlayerStatus(uint32 guid)
  167.     {
  168.         Player *player = sObjectAccessor->FindPlayer(guid);
  169.         if(!player)
  170.             return "Offline";
  171.         if(player->isAFK())
  172.             return "Online, <AFK> " + player->afkMsg;
  173.         if(player->isDND())
  174.             return "Online, <Busy> " + player->dndMsg;
  175.         return "Online";
  176.     }
  177.        
  178.     std::string getWinPercent(uint32 wins, uint32 losses)
  179.     {
  180.         uint32 totalGames = wins + losses;
  181.         if (totalGames == 0)
  182.             return "0%";
  183.            
  184.         std::stringstream buf;
  185.         uint32 percentage = (wins * 100) / totalGames;
  186.         buf << percentage << "%";
  187.         return buf.str();
  188.     }
  189.  
  190.     public:
  191.         arena_top_teams() : CreatureScript("arena_top_teams"){}
  192.        
  193.     bool OnGossipHello(Player *player, Creature *creature)
  194.     {
  195.         player->ADD_GOSSIP_ITEM(4,"|cff00ff00|TInterface\\icons\\spell_chargepositive:26|t|r How this npc work?", GOSSIP_SENDER_MAIN, ARENA_HELP);
  196.         player->ADD_GOSSIP_ITEM(4,"|cff00ff00|TInterface\\icons\\Achievement_Arena_2v2_7:26|t|r Top 10: 2v2 Arena", GOSSIP_SENDER_MAIN, ARENA_2V2_LADDER);
  197.         player->ADD_GOSSIP_ITEM(4,"|cff00ff00|TInterface\\icons\\Achievement_Arena_3v3_7:26|t|r Top 10: 3v3 Arena", GOSSIP_SENDER_MAIN, ARENA_3V3_LADDER);
  198.         player->ADD_GOSSIP_ITEM(4,"|cff00ff00|TInterface\\icons\\Achievement_Arena_5v5_7:26|t|r Top 10: 5v5 Arena", GOSSIP_SENDER_MAIN, ARENA_5V5_LADDER);
  199.         player->ADD_GOSSIP_ITEM(4,"|cff00ff00|TInterface\\icons\\spell_chargenegative:26|t|r Nevermind", GOSSIP_SENDER_MAIN, ARENA_GOODBYE);
  200.         player->SEND_GOSSIP_MENU(90085, creature->GetGUID());
  201.         return true;
  202.     }
  203.        
  204.     bool OnGossipSelect(Player* player, Creature* creature, uint32 /*uiSender*/, uint32 uiAction)
  205.     {
  206.         player->PlayerTalkClass->ClearMenus();
  207.         switch(uiAction)
  208.         {
  209.             case ARENA_GOODBYE:
  210.             {
  211.                 player->CLOSE_GOSSIP_MENU();
  212.                 break;
  213.             }
  214.  
  215.             case ARENA_HELP:
  216.             {
  217.                 ChatHandler(player->GetSession()).PSendSysMessage("|cffff6060[Information]:|r This npc show server gladiators (Top 10).Simple click on team name and see team details");
  218.                 break;
  219.             }
  220.  
  221.             case ARENA_2V2_LADDER:
  222.             case ARENA_5V5_LADDER:
  223.             case ARENA_3V3_LADDER:
  224.             {
  225.                 uint32 teamType = optionToTeamType(uiAction);
  226.                 QueryResult result = CharacterDatabase.PQuery("SELECT arenaTeamId, name, rating FROM arena_team WHERE type = '%u' ORDER BY rating DESC LIMIT %u;", teamType, ARENA_MAX_RESULTS);
  227.                    
  228.                 if(!result)
  229.                 {
  230.                     player->ADD_GOSSIP_ITEM(7, "Nevermind", GOSSIP_SENDER_MAIN, ARENA_GOODBYE);
  231.                     player->SEND_GOSSIP_MENU(1, creature->GetGUID());
  232.                 }
  233.                 else
  234.                 {
  235.                     std::string name;
  236.                     uint32 teamId, rating, rank = 1;
  237.                     player->ADD_GOSSIP_ITEM(0,"Top Arena List - Gladiators:", GOSSIP_SENDER_MAIN, ARENA_GOODBYE);
  238.                     do
  239.                     {
  240.                         Field *fields = result->Fetch();
  241.                         teamId = fields[0].GetUInt32();
  242.                         name = fields[1].GetString();
  243.                         rating = fields[2].GetUInt32();
  244.                            
  245.                         std::stringstream buffer;
  246.                         buffer << rank << ". " << name;
  247.                         buffer << ": " << "|cFF1E90FF" << rating << "|r" << " rating!";
  248.                         player->ADD_GOSSIP_ITEM(4, buffer.str(), GOSSIP_SENDER_MAIN, ARENA_START_TEAM_LOOKUP + teamId);
  249.                            
  250.                         rank++;
  251.                     }
  252.                     while(result->NextRow());
  253.                     player->ADD_GOSSIP_ITEM(7, "Nevermind", GOSSIP_SENDER_MAIN, ARENA_GOODBYE);
  254.                     player->SEND_GOSSIP_MENU(90086, creature->GetGUID());
  255.                 }
  256.                 break;
  257.             }
  258.            
  259.             default:
  260.             {
  261.                 if (uiAction > ARENA_START_TEAM_LOOKUP)
  262.                 {
  263.                     uint32 teamId = uiAction - ARENA_START_TEAM_LOOKUP;
  264.                     QueryResult result = CharacterDatabase.PQuery("SELECT name, rating, seasonWins, seasonGames - seasonWins, weekWins, weekGames - weekWins, rank, captainGuid , type FROM arena_team WHERE arenaTeamId = '%u'", teamId);
  265.                        
  266.                     if(!result)
  267.                     {
  268.                         player->GetSession()->SendNotification("Arena team not found...");
  269.                         player->CLOSE_GOSSIP_MENU();
  270.                         return true;
  271.                     }
  272.                        
  273.                     Field *fields = result->Fetch();
  274.                     std::string name = fields[0].GetString();
  275.                     uint32 rating = fields[1].GetUInt32();
  276.                     uint32 seasonWins = fields[2].GetUInt32();
  277.                     uint32 seasonLosses = fields[3].GetUInt32();
  278.                     uint32 weekWins = fields[4].GetUInt32();
  279.                     uint32 weekLosses = fields[5].GetUInt32();
  280.                     uint32 rank = fields[6].GetUInt32();
  281.                     uint32 captainGuid = fields[7].GetUInt32();
  282.                     uint32 type = fields[8].GetUInt32();
  283.                     uint32 parentOption = teamTypeToOption(type);
  284.                        
  285.                     std::string seasonWinPercentage = getWinPercent(seasonWins, seasonLosses);
  286.                     std::string weekWinPercentage = getWinPercent(weekWins, weekLosses);
  287.                        
  288.                     std::stringstream buf;
  289.                     buf << "Team Name: " << "|cFF1E90FF" << name << "|r";
  290.                     player->ADD_GOSSIP_ITEM(7, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
  291.                     buf.str("");
  292.                    
  293.                     buf << "Rating: " << "|cFF1E90FF" << rating << "|r" << " (Rank: " << "|cFF1E90FF" << rank << "|r" << ", Type: " << "|cFF1E90FF" << type << "v" << type << "|r"")";
  294.                     player->ADD_GOSSIP_ITEM(4, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
  295.                     buf.str("");
  296.                    
  297.                     buf << "Total Week: " << "|cFF1E90FF" << weekWins << "-" << weekLosses << "|r"" (" << "|cFF1E90FF" << weekWinPercentage << "|r" << "win)";
  298.                     player->ADD_GOSSIP_ITEM(4, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
  299.                     buf.str("");
  300.                    
  301.                     buf << "Total Season: " << "|cFF1E90FF" << seasonWins << "-" << seasonLosses << "|r" << " (" << "|cFF1E90FF" << seasonWinPercentage << "|r" << " win)";
  302.                     player->ADD_GOSSIP_ITEM(4, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
  303.                        
  304.                     QueryResult members = CharacterDatabase.PQuery("SELECT  a.guid, a.personalRating, a.weekWins, a.weekGames - a.weekWins, a.seasonWins, a.seasonGames - a.seasonWins, c.name, c.race, c.class, c.level FROM arena_team_member a LEFT JOIN characters c ON c.guid = a.guid WHERE arenaTeamId = '%u' ORDER BY a.guid = '%u' DESC, a.seasonGames DESC, c.name ASC", teamId, captainGuid);
  305.                     if(!members)
  306.                     {
  307.                         player->ADD_GOSSIP_ITEM(7, "No team members found...?", GOSSIP_SENDER_MAIN, parentOption);
  308.                     }
  309.                     else
  310.                     {
  311.                         uint32 memberPos = 1;
  312.                         uint32 memberCount = members->GetRowCount();
  313.                         uint32 guid, personalRating, level;
  314.                         std::string name, race, Class;
  315.                            
  316.                         buf.str("");
  317.                         buf << "      --- " << memberCount << " team" << ((memberCount == 1) ? " member" : " members") << " found" << " ---";
  318.                         player->ADD_GOSSIP_ITEM(0, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
  319.                         do
  320.                         {
  321.                             fields = members->Fetch();
  322.                             guid = fields[0].GetUInt32();
  323.                             personalRating = fields[1].GetUInt32();
  324.                             weekWins= fields[2].GetUInt32();
  325.                             weekLosses = fields[3].GetUInt32();
  326.                             seasonWins = fields[4].GetUInt32();
  327.                             seasonLosses = fields[5].GetUInt32();
  328.                             name = fields[6].GetString();
  329.                             race = raceToString(fields[7].GetUInt8());
  330.                             Class = classToString(fields[8].GetUInt8());
  331.                             level = fields[9].GetUInt32();
  332.                                
  333.                             seasonWinPercentage = getWinPercent(seasonWins, seasonLosses);
  334.                             weekWinPercentage = getWinPercent(weekWins, weekLosses);
  335.                                
  336.                             buf.str("");
  337.                             buf << memberPos << ". ";
  338.                             if (guid == captainGuid)
  339.                                 buf <<  "Team Captain ";
  340.                                
  341.                             buf << name << ", " << getPlayerStatus(guid);
  342.                             player->ADD_GOSSIP_ITEM(7, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
  343.                             buf.str("");
  344.                            
  345.                             buf << race << " " << Class << ", " << "|cFF1E90FF" << personalRating << "|r" << " personal rating!";
  346.                             player->ADD_GOSSIP_ITEM(4, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
  347.                             buf.str("");
  348.                            
  349.                             buf << "Week: " << "|cFF1E90FF" << weekWins << "-" << weekLosses << "|r" << " (" << "|cFF1E90FF" << weekWinPercentage << "|r" << " win), " << "|cFF1E90FF" << (weekWins + weekLosses) << "|r" << " played!";
  350.                             player->ADD_GOSSIP_ITEM(4, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
  351.                             buf.str("");
  352.                            
  353.                             buf << "Season: " << "|cFF1E90FF" << seasonWins << "-" << seasonLosses << "|r" << " (" << "|cFF1E90FF" << seasonWinPercentage << "|r" << " win), " << "|cFF1E90FF" << (seasonWins + seasonLosses) << "|r" << " played!";
  354.                             player->ADD_GOSSIP_ITEM(4, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
  355.                             memberPos++;
  356.                         }
  357.                         while(members->NextRow());
  358.                     }
  359.                     player->SEND_GOSSIP_MENU(90087, creature->GetGUID());
  360.                 }
  361.             }
  362.         }
  363.         return true;
  364.     }
  365. };
  366.  
  367. void AddSC_arena_top_teams()
  368. {
  369.     new arena_top_teams();
  370. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement