Advertisement
faiver

Emudevs

Mar 28th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 25.42 KB | None | 0 0
  1. #include "ScriptPCH.h"
  2. #include "Chat.h"
  3. #include "ArenaTeamMgr.h"
  4. #include "BattlegroundMgr.h"
  5. #include "WorldPacket.h"
  6. #include "Battleground.h"
  7. #include "CreatureTextMgr.h"
  8. #include "Config.h"
  9. #include "ArenaTeam.h"
  10. #include "Player.h"
  11.  
  12. //int8 UsingGossip;
  13.  
  14. class arena_spectator_commands : public CommandScript
  15. {
  16.     public:
  17.         arena_spectator_commands() : CommandScript("arena_spectator_commands") { }
  18.  
  19.         static bool HandleSpectateCommand(ChatHandler* handler, const char *args)
  20.         {
  21.             Player* target;
  22.             uint64 target_guid;
  23.             std::string target_name;
  24.             if (!handler->extractPlayerTarget((char*)args, &target, &target_guid, &target_name))
  25.                 return false;
  26.  
  27.             Player* player = handler->GetSession()->GetPlayer();
  28.             if (target == player || target_guid == player->GetGUID())
  29.             {
  30.                 handler->SendSysMessage(LANG_CANT_TELEPORT_SELF);
  31.                 handler->SetSentErrorMessage(true);
  32.                 return false;
  33.             }
  34.  
  35.             if (player->isInCombat())
  36.             {
  37.                 handler->SendSysMessage(LANG_YOU_IN_COMBAT);
  38.                 handler->SetSentErrorMessage(true);
  39.                 return false;
  40.             }
  41.            
  42.             if (player->isSpectator())
  43.             {
  44.                 handler->SendSysMessage(LANG_SPEC_ALREADY_SPECTATOR);
  45.                 handler->SetSentErrorMessage(true);
  46.                 return false;
  47.             }
  48.            
  49.             if (player->GetMap()->IsBattlegroundOrArena())
  50.             {
  51.                 handler->SendSysMessage(LANG_SPEC_ON_ARENA_OR_BG);
  52.                 handler->SetSentErrorMessage(true);
  53.                 return false;
  54.             }
  55.  
  56.             if (!target)
  57.             {
  58.                 handler->SendSysMessage(LANG_PLAYER_NOT_EXIST_OR_OFFLINE);
  59.                 handler->SetSentErrorMessage(true);
  60.                 return false;
  61.             }
  62.  
  63.             if (player->GetPet())
  64.             {
  65.                 handler->PSendSysMessage("Debes guardar tu mascota.");
  66.                 handler->SetSentErrorMessage(true);
  67.                 return false;
  68.             }
  69.  
  70.             if (player->IsMounted())
  71.             {
  72.                 handler->PSendSysMessage("Debes bajarte de tu montura.");
  73.                 handler->SetSentErrorMessage(true);
  74.                 return false;
  75.             }
  76.            
  77.             if (player->InBattlegroundQueue() || !player->CanJoinToBattleground() || player->isUsingLfg())
  78.             {
  79.                 handler->PSendSysMessage("Debes abandonar la cola de Arenas o BG.");
  80.                 handler->SetSentErrorMessage(true);
  81.                 return false;
  82.             }
  83.            
  84.             if (player->GetMap()->IsBattlegroundOrArena() && !player->isSpectator())
  85.             {
  86.                 handler->PSendSysMessage("Ya estas en un campo de batalla.");
  87.                 handler->SetSentErrorMessage(true);
  88.                 return false;
  89.             }
  90.  
  91.             Map* cMap = target->GetMap();
  92.             if (!cMap->IsBattleArena())
  93.             {
  94.                 handler->PSendSysMessage("Jugador no encontrado en la arena");
  95.                 handler->SetSentErrorMessage(true);
  96.                 return false;
  97.             }
  98.  
  99.             if (player->GetMap()->IsBattleground())
  100.             {
  101.                 handler->PSendSysMessage("No puedes hacer eso mientras estas en un campo de batalla.");
  102.                 handler->SetSentErrorMessage(true);
  103.                 return false;
  104.             }
  105.  
  106.             // all's well, set bg id
  107.             // when porting out from the bg, it will be reset to 0
  108.             player->SetBattlegroundId(target->GetBattlegroundId(), target->GetBattlegroundTypeId());
  109.             // remember current position as entry point for return at bg end teleportation
  110.             if (!player->GetMap()->IsBattlegroundOrArena())
  111.                 player->SetBattlegroundEntryPoint();
  112.  
  113.             if (target->isSpectator())
  114.             {
  115.                 handler->PSendSysMessage("No puedes hacer eso, el jugador es un espectador.");
  116.                 handler->SetSentErrorMessage(true);
  117.                 return false;
  118.             }
  119.  
  120.             // stop flight if need
  121.             if (player->isInFlight())
  122.             {
  123.                 player->GetMotionMaster()->MovementExpired();
  124.                 player->CleanupAfterTaxiFlight();
  125.             }
  126.             // save only in non-flight case
  127.             else
  128.                 player->SaveRecallPosition();
  129.  
  130.             // search for two teams
  131.             Battleground *bGround = target->GetBattleground();
  132.  
  133.             if (bGround->isRated())
  134.             {              
  135.                 uint32 slot = bGround->GetArenaType() - 2;
  136.                 if (bGround->GetArenaType() > 3)
  137.                     slot = 2;
  138.                 uint32 firstTeamID = target->GetArenaTeamId(slot);
  139.                 uint32 secondTeamID = 0;
  140.                 Player *firstTeamMember  = target;
  141.                 Player *secondTeamMember = NULL;
  142.                 for (Battleground::BattlegroundPlayerMap::const_iterator itr = bGround->GetPlayers().begin(); itr != bGround->GetPlayers().end(); ++itr)
  143.                     if (Player* tmpPlayer = ObjectAccessor::FindPlayer(itr->first))
  144.                     {                          
  145.                         if (tmpPlayer->isSpectator())
  146.                             continue;
  147.  
  148.                         uint32 tmpID = tmpPlayer->GetArenaTeamId(slot);
  149.                         if (tmpID != firstTeamID && tmpID > 0)
  150.                         {
  151.                             secondTeamID = tmpID;
  152.                             secondTeamMember = tmpPlayer;
  153.                             break;
  154.                         }
  155.                     }
  156.  
  157.                 if (firstTeamID > 0 && secondTeamID > 0 && secondTeamMember)
  158.                 {
  159.                     ArenaTeam *firstTeam  = sArenaTeamMgr->GetArenaTeamById(firstTeamID);
  160.                     ArenaTeam *secondTeam = sArenaTeamMgr->GetArenaTeamById(secondTeamID);
  161.                     if (firstTeam && secondTeam)
  162.                     {
  163.                         handler->PSendSysMessage("Has entrado en una arena puntuada.");
  164.                         handler->PSendSysMessage("Equipos:");
  165.                         handler->PSendSysMessage("%s - %s", firstTeam->GetName().c_str(), secondTeam->GetName().c_str());
  166.                         handler->PSendSysMessage("%u(%u) - %u(%u)", firstTeam->GetRating(), firstTeam->GetAverageMMR(firstTeamMember->GetGroup()),
  167.                                                                     secondTeam->GetRating(), secondTeam->GetAverageMMR(secondTeamMember->GetGroup()));
  168.                     }
  169.                 }
  170.             }
  171.        
  172.             //Custom
  173.             handler->PSendSysMessage("|CFFFF0000Recuerda que dispones de los comandos:|R");
  174.             handler->PSendSysMessage("|CFF87CEFA.spectate player |CFF800080#nombre_jugador|R : Sirve para espectar a un jugador en concreto");
  175.             handler->PSendSysMessage("|CFF87CEFA.spectate view |CFF800080#nombre_jugador|R : Pasas a ver la misma vista que el jugador #nombre_jugador");
  176.             handler->PSendSysMessage("|CFF87CEFA.spectate reset|R : Reinicia la cámara por si has puesto el comando .spectate view");
  177.             handler->PSendSysMessage("|CFF87CEFA.spectate leave|R : Dejas de espectar la Arena y vuelves a tu posición original.");
  178.            
  179.             ItemPosCountVec off_dest;
  180.             ItemPosCountVec off_dest_2;
  181.             //Item* RangedItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_RANGED);
  182.             Item* FirstItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND);
  183.             Item* OffItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND);
  184.  
  185.             /*uint8 off_msg = player->CanStoreItem(NULL_BAG, NULL_SLOT, off_dest, RangedItem, false);
  186.             if(off_msg == EQUIP_ERR_OK)
  187.             {
  188.                 player->RemoveItem(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_RANGED, true);
  189.                 player->StoreItem(off_dest, RangedItem, true);
  190.             }*/
  191.            
  192.             InventoryResult off_msg_2 = player->CanStoreItem(NULL_BAG, NULL_SLOT, off_dest, FirstItem, false);
  193.             if(off_msg_2 == EQUIP_ERR_OK)
  194.             {
  195.                 player->RemoveItem(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND, true);
  196.                 player->StoreItem(off_dest, FirstItem, true);
  197.             }
  198.             else
  199.                 player->SendEquipError(off_msg_2, FirstItem, NULL);
  200.            
  201.             InventoryResult off_msg_3 = player->CanStoreItem(NULL_BAG, NULL_SLOT, off_dest_2, OffItem, false);
  202.             if(off_msg_3 == EQUIP_ERR_OK)
  203.             {
  204.                 player->RemoveItem(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND, true);
  205.                 player->StoreItem(off_dest_2, OffItem, true);
  206.             }
  207.             else
  208.                 player->SendEquipError(off_msg_3, OffItem, NULL);
  209.  
  210.             // to point to see at target with same orientation
  211.             float x, y, z;
  212.             target->GetContactPoint(player, x, y, z);
  213.  
  214.             player->TeleportTo(target->GetMapId(), x, y, z, player->GetAngle(target), TELE_TO_GM_MODE);
  215.             //std::string chrNameLink = handler->playerLink(target_name);
  216.             //handler->PSendSysMessage("Has aparecido ante %u", chrNameLink.c_str());
  217.             player->SetPhaseMask(target->GetPhaseMask(), true);
  218.             player->SetSpectate(true);
  219.             target->GetBattleground()->AddSpectator(player->GetGUID());
  220.  
  221.             return true;
  222.         }
  223.  
  224.         static bool HandleSpectateCancelCommand(ChatHandler* handler, const char* /*args*/)
  225.         {
  226.             Player* player =  handler->GetSession()->GetPlayer();
  227.  
  228.             if (!player->isSpectator())
  229.             {
  230.                 handler->PSendSysMessage("Tu no eres un espectador.");
  231.                 handler->SetSentErrorMessage(true);
  232.                 return false;
  233.             }
  234.  
  235.             player->GetBattleground()->RemoveSpectator(player->GetGUID());
  236.             player->CancelSpectate();
  237.             player->TeleportToBGEntryPoint();
  238.  
  239.             return true;
  240.         }
  241.  
  242.         static bool HandleSpectateFromCommand(ChatHandler* handler, const char *args)
  243.         {
  244.             Player* target;
  245.             uint64 target_guid;
  246.             std::string target_name;
  247.             if (!handler->extractPlayerTarget((char*)args, &target, &target_guid, &target_name))
  248.                 return false;
  249.  
  250.             Player* player = handler->GetSession()->GetPlayer();
  251.  
  252.             if (!target)
  253.             {
  254.                 handler->PSendSysMessage("No se puede encontrar al jugador.");
  255.                 handler->SetSentErrorMessage(true);
  256.                 return false;
  257.             }
  258.  
  259.             if (!player->isSpectator())
  260.             {
  261.                 handler->PSendSysMessage("Tu no eres un espectador, mira a alguien antes.");
  262.                 handler->SetSentErrorMessage(true);
  263.                 return false;
  264.             }
  265.  
  266.             if (target->isSpectator() && target != player)
  267.             {
  268.                 handler->PSendSysMessage("No puedes hacer eso. El jugador es un espectador.");
  269.                 handler->SetSentErrorMessage(true);
  270.                 return false;
  271.             }
  272.  
  273.             if (player->GetMap() != target->GetMap())
  274.             {
  275.                 handler->PSendSysMessage("No puedes hacer eso. Arenas diferentes?");
  276.                 handler->SetSentErrorMessage(true);
  277.                 return false;
  278.             }
  279.  
  280.             // check for arena preperation
  281.             // if exists than battle didn`t begin
  282.             /*if (target->HasAura(32728) || target->HasAura(32727) && UsingGossip == 0)
  283.             {
  284.                 handler->PSendSysMessage("No puedes hacer eso. La arena aun no ha empezado.");
  285.                 handler->SetSentErrorMessage(true);
  286.                 return false;
  287.             }*/
  288.  
  289.             (target == player && player->getSpectateFrom()) ? player->SetViewpoint(player->getSpectateFrom(), false) :
  290.                                                                 player->SetViewpoint(target, true);
  291.             return true;
  292.         }
  293.  
  294.         static bool HandleSpectateResetCommand(ChatHandler* handler, const char *args)
  295.         {
  296.             Player* player = handler->GetSession()->GetPlayer();
  297.  
  298.             if (!player)
  299.             {
  300.                 handler->PSendSysMessage("No se puede encontrar el jugador.");
  301.                 handler->SetSentErrorMessage(true);
  302.                 return false;
  303.             }
  304.  
  305.             if (!player->isSpectator())
  306.             {
  307.                 handler->PSendSysMessage("No eres un espectador!");
  308.                 handler->SetSentErrorMessage(true);
  309.                 return false;
  310.             }
  311.  
  312.             Battleground *bGround = player->GetBattleground();
  313.             if (!bGround)
  314.                 return false;
  315.  
  316.             if (bGround->GetStatus() != STATUS_IN_PROGRESS)
  317.                 return true;
  318.  
  319.             for (Battleground::BattlegroundPlayerMap::const_iterator itr = bGround->GetPlayers().begin(); itr != bGround->GetPlayers().end(); ++itr)
  320.                 if (Player* tmpPlayer = ObjectAccessor::FindPlayer(itr->first))
  321.                 {
  322.                     if (tmpPlayer->isSpectator())
  323.                         continue;
  324.  
  325.                     uint32 tmpID = bGround->GetPlayerTeam(tmpPlayer->GetGUID());
  326.  
  327.                     // generate addon massage
  328.                     std::string pName = tmpPlayer->GetName();
  329.                     std::string tName = "";
  330.  
  331.                     if (Player *target = tmpPlayer->GetSelectedPlayer())
  332.                         tName = target->GetName();
  333.  
  334.                     SpectatorAddonMsg msg;
  335.                     msg.SetPlayer(pName);
  336.                     if (tName != "")
  337.                         msg.SetTarget(tName);
  338.                     msg.SetStatus(tmpPlayer->isAlive());
  339.                     msg.SetClass(tmpPlayer->getClass());
  340.                     msg.SetCurrentHP(tmpPlayer->GetHealth());
  341.                     msg.SetMaxHP(tmpPlayer->GetMaxHealth());
  342.                     Powers powerType = tmpPlayer->getPowerType();
  343.                     msg.SetMaxPower(tmpPlayer->GetMaxPower(powerType));
  344.                     msg.SetCurrentPower(tmpPlayer->GetPower(powerType));
  345.                     msg.SetPowerType(powerType);
  346.                     msg.SetTeam(tmpID);
  347.                     msg.SendPacket(player->GetGUID());
  348.                 }
  349.  
  350.             return true;
  351.         }
  352.  
  353.         ChatCommand* GetCommands() const
  354.         {
  355.             static ChatCommand spectateCommandTable[] =
  356.             {
  357.                 { "player",         SEC_PLAYER,      true,  &HandleSpectateCommand,        "", NULL },
  358.                 { "view",           SEC_PLAYER,      true,  &HandleSpectateFromCommand,    "", NULL },
  359.                 { "reset",          SEC_PLAYER,      true,  &HandleSpectateResetCommand,   "", NULL },
  360.                 { "leave",          SEC_PLAYER,      true,  &HandleSpectateCancelCommand,  "", NULL },
  361.                 { NULL,             0,               false, NULL,                          "", NULL }
  362.             };
  363.  
  364.             static ChatCommand commandTable[] =
  365.             {
  366.                 { "spectate",       SEC_PLAYER, false,  NULL, "", spectateCommandTable },
  367.                 { NULL,             0,          false,  NULL, "", NULL }
  368.             };
  369.             return commandTable;
  370.         }
  371. };
  372.  
  373.  
  374. enum NpcSpectatorAtions {
  375.     // will be used for scrolling
  376.     NPC_SPECTATOR_ACTION_LIST_GAMES         = 1000,
  377.     NPC_SPECTATOR_ACTION_LIST_TOP_GAMES     = 2000,
  378.  
  379.     // NPC_SPECTATOR_ACTION_SELECTED_PLAYER + player.Guid()
  380.     NPC_SPECTATOR_ACTION_SELECTED_PLAYER    = 3000
  381. };
  382.  
  383. //const uint16 TopGamesRating = 1800;
  384. //const uint8  GamesOnPage    = 20;
  385. const uint8  GamesOnPage    = 15;
  386.  
  387. class npc_arena_spectator : public CreatureScript
  388. {
  389.     public:
  390.         npc_arena_spectator() : CreatureScript("npc_arena_spectator") { }
  391.  
  392.         bool OnGossipHello(Player* pPlayer, Creature* pCreature)
  393.         {
  394.             pPlayer->ADD_GOSSIP_ITEM(9, "Partidas: 2c2", GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_LIST_GAMES);
  395.             pPlayer->ADD_GOSSIP_ITEM(9, "Partidas: 3c3", GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_LIST_TOP_GAMES);
  396.             pPlayer->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, pCreature->GetGUID());
  397.             return true;
  398.         }
  399.  
  400.         bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 action)
  401.         {
  402.             player->PlayerTalkClass->ClearMenus();
  403.             if (action >= NPC_SPECTATOR_ACTION_LIST_GAMES && action < NPC_SPECTATOR_ACTION_LIST_TOP_GAMES)
  404.             {
  405.                 ShowPage(player, action - NPC_SPECTATOR_ACTION_LIST_GAMES, false);
  406.                 player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  407.             }
  408.             else if (action >= NPC_SPECTATOR_ACTION_LIST_TOP_GAMES && action < NPC_SPECTATOR_ACTION_SELECTED_PLAYER)
  409.             {
  410.                 ShowPage(player, action - NPC_SPECTATOR_ACTION_LIST_TOP_GAMES, true);
  411.                 player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  412.             }
  413.             else
  414.             {
  415.                 uint64 guid = action - NPC_SPECTATOR_ACTION_SELECTED_PLAYER;
  416.                 if (Player* target = ObjectAccessor::FindPlayer(guid))
  417.                 {
  418.                     ChatHandler handler(player);
  419.                     char const* pTarget = target->GetName();
  420.                     Battleground* bgroundd = target->GetBattleground();
  421.                     //UsingGossip = 1;
  422.                     arena_spectator_commands::HandleSpectateCommand(&handler, pTarget);
  423.                 }
  424.             }          
  425.             return true;
  426.         }
  427.  
  428.         std::string GetClassNameById(uint8 id)
  429.         {
  430.             std::string sClass = "";
  431.             switch (id)
  432.             {
  433.                 case CLASS_WARRIOR:         sClass = "Guerrero ";        break;
  434.                 case CLASS_PALADIN:         sClass = "Paladin ";           break;
  435.                 case CLASS_HUNTER:          sClass = "Cazador ";           break;
  436.                 case CLASS_ROGUE:           sClass = "Picaro ";          break;
  437.                 case CLASS_PRIEST:          sClass = "Sacerdote ";         break;
  438.                 case CLASS_DEATH_KNIGHT:    sClass = "DK ";             break;
  439.                 case CLASS_SHAMAN:          sClass = "Chaman ";          break;
  440.                 case CLASS_MAGE:            sClass = "Mago ";           break;
  441.                 case CLASS_WARLOCK:         sClass = "Brujo ";        break;
  442.                 case CLASS_DRUID:           sClass = "Druida ";          break;
  443.             }
  444.             return sClass;
  445.         }
  446.  
  447.         std::string GetGamesStringData(Battleground *arena, uint16 mmr)
  448.         {
  449.             std::string teamsMember[BG_TEAMS_COUNT];
  450.             uint32 firstTeamId = 0;
  451.             for (Battleground::BattlegroundPlayerMap::const_iterator itr = arena->GetPlayers().begin(); itr != arena->GetPlayers().end(); ++itr)
  452.                 if (Player* player = ObjectAccessor::FindPlayer(itr->first))
  453.                 {
  454.                     if (player->isSpectator())
  455.                         continue;
  456.  
  457.                     uint32 team = itr->second.Team;
  458.                     if (!firstTeamId)
  459.                         firstTeamId = team;
  460.  
  461.                     teamsMember[firstTeamId == team] += GetClassNameById(player->getClass());
  462.                 }
  463.  
  464.  
  465.             /*uint16 a;
  466.             a = arena->GetArenaMatchmakerRating(0);
  467.             std::stringstream ss;
  468.             ss << a;
  469.             std::string data = teamsMember[0] +" ("+ss.str();
  470.             uint16 b;
  471.             b = arena->GetArenaMatchmakerRating(1);
  472.             std::stringstream sss;
  473.             sss << b;
  474.             data += ") - " + teamsMember[1] +" ("+sss.str()+")";
  475.             return data;*/
  476.            
  477.             /*std::string data = teamsMember[0] + "(";
  478.             std::stringstream ss;
  479.             ss << mmr;
  480.             data += ss.str();
  481.             data += ") - " + teamsMember[1];       
  482.             return data;*/
  483.  
  484.             //Caida aqui:
  485.             /*Player* jugador;
  486.             Battleground *bGround = jugador->GetBattleground();
  487.             uint32 slot = bGround->GetArenaType() - 2;
  488.             if (bGround->GetArenaType() > 3)
  489.                 slot = 2;
  490.             uint32 firstTeamID = jugador->GetArenaTeamId(slot);
  491.             uint32 secondTeamID = 0;*/
  492.             //Fin caida
  493.             /*for (Battleground::BattlegroundPlayerMap::const_iterator itr = bGround->GetPlayers().begin(); itr != bGround->GetPlayers().end(); ++itr)
  494.                     if (Player* tmpPlayer = ObjectAccessor::FindPlayer(itr->first))
  495.                     {
  496.                         uint32 tmpID = tmpPlayer->GetArenaTeamId(slot);
  497.                         if (tmpID != firstTeamID && tmpID > 0)
  498.                         {
  499.                             secondTeamID = tmpID;
  500.                             break;
  501.                         }
  502.                     }
  503.             //uint32 a;
  504.             ArenaTeam *PrimerTeam = sArenaTeamMgr->GetArenaTeamById(firstTeamID);
  505.             uint32 PrimerTeamRating = PrimerTeam->GetRating();
  506.             std::stringstream ss;
  507.             ss << PrimerTeamRating;
  508.             //uint32 b;
  509.             ArenaTeam *SegundoTeam = sArenaTeamMgr->GetArenaTeamById(secondTeamID);
  510.             uint32 SegundoTeamRating = PrimerTeam->GetRating();
  511.             std::stringstream sss;
  512.             sss << SegundoTeamRating;
  513.             //Mensaje:
  514.             std::string data = teamsMember[0] +" ("+ss.str();
  515.             data += ") - " + teamsMember[1] +" ("+sss.str()+")";
  516.             return data;*/
  517.             std::string data = teamsMember[0] +" - ";
  518.             data += teamsMember[1];    
  519.             return data;
  520.             /*std::string data = teamsMember[0] + " - ";
  521.             std::stringstream ss;
  522.             ss << mmr;
  523.             data += ss.str();
  524.             data += " - " + teamsMember[1];
  525.             return data;*/
  526.         }
  527.  
  528.         uint64 GetFirstPlayerGuid(Battleground *arena)
  529.         {
  530.             for (Battleground::BattlegroundPlayerMap::const_iterator itr = arena->GetPlayers().begin(); itr != arena->GetPlayers().end(); ++itr)
  531.                 if (Player* player = ObjectAccessor::FindPlayer(itr->first))
  532.                     return itr->first;
  533.             return 0;
  534.         }
  535.  
  536.         void ShowPage(Player *player, uint16 page, bool isTop)
  537.         {
  538.             /*uint16 highGames  = 0;
  539.             uint16 lowGames   = 0;*/
  540.             uint16 TypeTwo = 0;
  541.             uint16 TypeThree = 0;
  542.             bool haveNextPage = false;
  543.             for (uint8 i = 0; i <= MAX_BATTLEGROUND_TYPE_ID; ++i)
  544.             {
  545.                 if (!sBattlegroundMgr->IsArenaType(BattlegroundTypeId(i)))
  546.                     continue;
  547.  
  548.                 BattlegroundSet bgs = sBattlegroundMgr->GetBattlegroundsByType(BattlegroundTypeId(i));
  549.                 //for (BattlegroundSet::iterator itr = bgs.begin(); itr != bgs.end(); ++itr)
  550.  
  551.                 for(BattlegroundSet::iterator itr = bgs.begin(); itr != bgs.end(); ++itr)
  552.                 {
  553.                     Battleground* arena = itr->second;
  554.  
  555.                     /*if (Player* target = ObjectAccessor::FindPlayer(GetFirstPlayerGuid(arena)))
  556.                         if (target && (target->HasAura(32728) || target->HasAura(32727)))
  557.                             continue;*/
  558.  
  559.                     if (!arena->GetPlayersSize())
  560.                         continue;
  561.  
  562.                     /*uint16 mmr = arena->GetArenaMatchmakerRating(0) + arena->GetArenaMatchmakerRating(1);
  563.                     mmr /= 2;*/
  564.                     uint16 mmrTwo = arena->GetArenaMatchmakerRating(0);
  565.                     uint16 mmrThree = arena->GetArenaMatchmakerRating(1);
  566.  
  567.                     if (isTop && /*mmr >= TopGamesRating*/arena->GetArenaType() == ARENA_TYPE_3v3)
  568.                     {
  569.                         /*highGames++;
  570.                         if(highGames > (page + 1) * GamesOnPage)*/
  571.                         TypeThree++;
  572.                         if(TypeThree > (page + 1) * GamesOnPage)
  573.                         {
  574.                             haveNextPage = true;
  575.                             break;
  576.                         }
  577.  
  578.                         /*if(highGames >= page * GamesOnPage)
  579.                             player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, GetGamesStringData(arena, mmr), GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_SELECTED_PLAYER + GetFirstPlayerGuid(arena));*/
  580.                         player->ADD_GOSSIP_ITEM(0, "Arenas 3c3 disput""\xC3\xA1""ndose actualmente:", GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_LIST_TOP_GAMES);
  581.                         if(TypeThree >= page * GamesOnPage)
  582.                            player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, GetGamesStringData(arena, mmrThree), GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_SELECTED_PLAYER + GetFirstPlayerGuid(arena));
  583.                     }
  584.                     else if (!isTop && /*mmr < TopGamesRating*/arena->GetArenaType() == ARENA_TYPE_2v2)
  585.                     {
  586.                         /*lowGames++;
  587.                         if(lowGames > (page + 1) * GamesOnPage)*/
  588.                         TypeTwo++;
  589.                         if(TypeTwo > (page + 1) * GamesOnPage)
  590.                         {
  591.                             haveNextPage = true;
  592.                             break;
  593.                         }
  594.  
  595.                         /*if(lowGames >= page * GamesOnPage)
  596.                             player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, GetGamesStringData(arena, mmr), GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_SELECTED_PLAYER + GetFirstPlayerGuid(arena));*/
  597.                         player->ADD_GOSSIP_ITEM(0, "Arenas 2c2 disput""\xC3\xA1""ndose actualmente:", GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_LIST_GAMES);
  598.                         if(TypeTwo >= page * GamesOnPage)
  599.                             player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, GetGamesStringData(arena, mmrTwo), GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_SELECTED_PLAYER + GetFirstPlayerGuid(arena));
  600.                     }
  601.                 }
  602.             }
  603.  
  604.             if (page > 0)
  605.                 player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, "|cff9b0000<- Anterior", GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_LIST_GAMES + page - 1);
  606.  
  607.             if (haveNextPage)
  608.                 player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, "|cff2e2efeSiguiente ->", GOSSIP_SENDER_MAIN, NPC_SPECTATOR_ACTION_LIST_GAMES + page + 1);
  609.         }
  610. };
  611.  
  612.  
  613. void AddSC_arena_spectator_script()
  614. {
  615.     new arena_spectator_commands();
  616.     new npc_arena_spectator();
  617. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement