bool OnGossipSelect(Player* player, Creature* creature, uint32 /*uiSender*/, uint32 uiAction) 
	{
		player->PlayerTalkClass->ClearMenus();
		switch(uiAction) 
		{
			case ARENA_GOODBYE:
			{
				player->CLOSE_GOSSIP_MENU();
				break;
			}

			case ARENA_HELP:
			{
				ChatHandler(player->GetSession()).PSendSysMessage("|cffff6060[Information]:|r This npc shows the server gladiators (Top 10). You shall simply click on team name and see team details");
				break;
			}

			case ARENA_2V2_LADDER:
			case ARENA_5V5_LADDER:
			case ARENA_3V3_LADDER:
			{
				uint32 teamType = optionToTeamType(uiAction);
				QueryResult result = CharacterDatabase.PQuery("SELECT arenaTeamId, name, rating FROM arena_team WHERE type = '%u' ORDER BY rating DESC LIMIT %u;", teamType, ARENA_MAX_RESULTS);
                    
				if(!result) 
				{
					player->ADD_GOSSIP_ITEM(7, "Nevermind", GOSSIP_SENDER_MAIN, ARENA_GOODBYE);
					player->SEND_GOSSIP_MENU(1, creature->GetGUID());
				} 
				else
				{
					std::string name;
					uint32 teamId, rating, rank = 1;
					player->ADD_GOSSIP_ITEM(0,"Top Arena List - Gladiators:", GOSSIP_SENDER_MAIN, ARENA_GOODBYE);
					do 
					{
						Field *fields = result->Fetch();
						teamId = fields[0].GetUInt32();
						name = fields[1].GetString();
						rating = fields[2].GetUInt32();
                            
						std::stringstream buffer;
						buffer << rank << ". " << name;
						buffer << ": " << "|cFF1E90FF" << rating << "|r" << " rating!";
						player->ADD_GOSSIP_ITEM(4, buffer.str(), GOSSIP_SENDER_MAIN, ARENA_START_TEAM_LOOKUP + teamId);
							
						rank++;
					} 
					while(result->NextRow());
					player->ADD_GOSSIP_ITEM(7, "Nevermind", GOSSIP_SENDER_MAIN, ARENA_GOODBYE);
					player->SEND_GOSSIP_MENU(90086, creature->GetGUID());
				}
				break;
			}
			
			default:
			{
				if (uiAction > ARENA_START_TEAM_LOOKUP) 
				{
					uint32 teamId = uiAction - ARENA_START_TEAM_LOOKUP;
					QueryResult result = CharacterDatabase.PQuery("SELECT name, rating, seasonWins, seasonGames - seasonWins, weekWins, weekGames - weekWins, rank, captainGuid , type FROM arena_team WHERE arenaTeamId = '%u'", teamId);
                        
					if(!result) 
					{
						player->GetSession()->SendNotification("Arena team not found...");
						player->CLOSE_GOSSIP_MENU();
						return true;
					}
                        
					Field *fields = result->Fetch();
					std::string name = fields[0].GetString();
					uint32 rating = fields[1].GetUInt32();
					uint32 seasonWins = fields[2].GetUInt32();
					uint32 seasonLosses = fields[3].GetUInt32();
					uint32 weekWins = fields[4].GetUInt32();
					uint32 weekLosses = fields[5].GetUInt32();
					uint32 rank = fields[6].GetUInt32();
					uint32 captainGuid = fields[7].GetUInt32();
					uint32 type = fields[8].GetUInt32();
					uint32 parentOption = teamTypeToOption(type);
                        
					std::string seasonWinPercentage = getWinPercent(seasonWins, seasonLosses);
					std::string weekWinPercentage = getWinPercent(weekWins, weekLosses);
                        
					std::stringstream buf;
					buf << "Team Name: " << "|cFF1E90FF" << name << "|r";
					player->ADD_GOSSIP_ITEM(7, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
					buf.str("");
					
					buf << "Rating: " << "|cFF1E90FF" << rating << "|r" << " (Rank: " << "|cFF1E90FF" << rank << "|r" << ", Type: " << "|cFF1E90FF" << type << "v" << type << "|r"")";
					player->ADD_GOSSIP_ITEM(4, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
					buf.str("");
					
					buf << "Total Week: " << "|cFF1E90FF" << weekWins << "-" << weekLosses << "|r"" (" << "|cFF1E90FF" << weekWinPercentage << "|r" << "win)"; 
					player->ADD_GOSSIP_ITEM(4, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
					buf.str("");
					
					buf << "Total Season: " << "|cFF1E90FF" << seasonWins << "-" << seasonLosses << "|r" << " (" << "|cFF1E90FF" << seasonWinPercentage << "|r" << " win)"; 
					player->ADD_GOSSIP_ITEM(4, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
                        
					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);
					if(!members) 
					{
						player->ADD_GOSSIP_ITEM(7, "No team members found...?", GOSSIP_SENDER_MAIN, parentOption);
					} 
					else 
					{
						uint32 memberPos = 1;
						uint32 memberCount = members->GetRowCount();
						uint32 guid, personalRating, level;
						std::string name, race, Class;
                            
						buf.str("");
						buf << "      --- " << memberCount << " team" << ((memberCount == 1) ? " member" : " members") << " found" << " ---";
						player->ADD_GOSSIP_ITEM(0, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
						do 
						{
							fields = members->Fetch();
							guid = fields[0].GetUInt32();
							personalRating = fields[1].GetUInt32();
							weekWins= fields[2].GetUInt32();
							weekLosses = fields[3].GetUInt32();
							seasonWins = fields[4].GetUInt32();
							seasonLosses = fields[5].GetUInt32();
							name = fields[6].GetString();
							race = raceToString(fields[7].GetUInt8());
							Class = classToString(fields[8].GetUInt8());
							level = fields[9].GetUInt32();
                                
							seasonWinPercentage = getWinPercent(seasonWins, seasonLosses);
							weekWinPercentage = getWinPercent(weekWins, weekLosses);
                                
							buf.str(""); 
							buf << memberPos << ". "; 
							if (guid == captainGuid) 
								buf <<  "Team Captain ";
								
							buf << name << ", " << getPlayerStatus(guid);
							player->ADD_GOSSIP_ITEM(7, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
							buf.str("");
							
							buf << race << " " << Class << ", " << "|cFF1E90FF" << personalRating << "|r" << " personal rating!";
							player->ADD_GOSSIP_ITEM(4, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
							buf.str("");
							
							buf << "Week: " << "|cFF1E90FF" << weekWins << "-" << weekLosses << "|r" << " (" << "|cFF1E90FF" << weekWinPercentage << "|r" << " win), " << "|cFF1E90FF" << (weekWins + weekLosses) << "|r" << " played!"; 
							player->ADD_GOSSIP_ITEM(4, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
							buf.str("");
							
							buf << "Season: " << "|cFF1E90FF" << seasonWins << "-" << seasonLosses << "|r" << " (" << "|cFF1E90FF" << seasonWinPercentage << "|r" << " win), " << "|cFF1E90FF" << (seasonWins + seasonLosses) << "|r" << " played!"; 
							player->ADD_GOSSIP_ITEM(4, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
							memberPos++;
						} 
						while(members->NextRow());
					}
					player->SEND_GOSSIP_MENU(90087, creature->GetGUID());
				}
			}
		}
		return true;
	}
Beispiel #2
0
        bool OnGossipSelect(Player* player, Creature* creature, uint32 /*uiSender*/, uint32 uiAction) {
            player->PlayerTalkClass->ClearMenus();
            
            switch(uiAction) {
			case 0:
				// Here should the magic happend
                case ARENA_GOODBYE:
                {
                    player->PlayerTalkClass->SendCloseGossip();
                    break;
                }
                case ARENA_2V2_LADDER:
                case ARENA_5V5_LADDER: // 1v1
                case ARENA_3V3_LADDER:
                {
                    uint32 teamType = optionToTeamType(uiAction);
                    QueryResult result = CharacterDatabase.PQuery(
                            "SELECT arenaTeamid, name, rating, seasonWins, seasonGames - seasonWins "
                            "FROM `arena_team` WHERE `type` = '%u' ORDER BY rating DESC LIMIT %u;", teamType, ARENA_MAX_RESULTS
                            );
                    
                    if(!result) {
                        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Goodbye", GOSSIP_SENDER_MAIN, ARENA_GOODBYE);
                        player->SEND_GOSSIP_MENU(ARENA_GOSSIP_NOTEAMS, creature->GetGUID());
                    } else {
                        //uint64 rowCount = result->GetRowCount();
                        std::string name;
                        uint32 teamId, rating, seasonWins, seasonLosses, rank = 1;
                        do {
                            Field *fields = result->Fetch();
                            teamId = fields[0].GetUInt32();
                            name = fields[1].GetString();
                            rating = fields[2].GetUInt32();
                            seasonWins = fields[3].GetUInt32();
                            seasonLosses = fields[4].GetUInt32();
                            
                            std::stringstream buffer;
                            buffer << rank << ". [" << rating << "] " << name;
                            buffer << " (" << seasonWins << "-" << seasonLosses << ")";
                            player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, buffer.str(), GOSSIP_SENDER_MAIN, ARENA_START_TEAM_LOOKUP + teamId);
                            
                            rank++;
                        } while(result->NextRow());
                        
                        player->SEND_GOSSIP_MENU(ARENA_GOSSIP_TEAMS, creature->GetGUID());
                    }
                    break;
                }
                default:
                {
                    if (uiAction > ARENA_START_TEAM_LOOKUP) 
                    {
                        uint32 teamId = uiAction - ARENA_START_TEAM_LOOKUP;
                        
                        // lookup team
                        QueryResult result = CharacterDatabase.PQuery(
                            //       0       1         2           3
                            "SELECT name, rating, seasonWins, seasonGames - seasonWins, "
                            //  4                 5            6        7         8
                            "weekWins, weekGames - weekWins, rank, captainGuid , type "
                            "FROM `arena_team` WHERE `arenaTeamId` = '%u'", teamId);
                        
                        // no team found
                        if(!result) {
                            player->GetSession()->SendNotification("Arena team not found...");
                            player->PlayerTalkClass->SendCloseGossip();
                            return true;
                        }
                        
                        // populate the results
                        Field *fields = result->Fetch();
                        std::string name = fields[0].GetString();
                        uint32 rating = fields[1].GetUInt32();
                        uint32 seasonWins = fields[2].GetUInt32();
                        uint32 seasonLosses = fields[3].GetUInt32();
                        uint32 weekWins = fields[4].GetUInt32();
                        uint32 weekLosses = fields[5].GetUInt32();
                        uint32 rank = fields[6].GetUInt32();
                        uint32 captainGuid = fields[7].GetUInt32();
                        uint32 type = fields[8].GetUInt32();
                        uint32 parentOption = teamTypeToOption(type);
                        
                        std::string seasonWinPercentage = getWinPercent(seasonWins, seasonLosses);
                        std::string weekWinPercentage = getWinPercent(weekWins, weekLosses);
                        
                        std::stringstream buf;
                        buf << "Team Name: " << name;
                        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
                        buf.str("");
                        buf << "Rating: " << rating << " (rank " << rank << ", bracket " << type << "v" << type << ")";
                        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
                        buf.str("");
                        buf << "Total Week: " << weekWins << "-" << weekLosses << " (" << weekWinPercentage << " win), " << (weekWins + weekLosses) << " played"; 
                        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
                        buf.str("");
                        buf << "Total Season: " << seasonWins << "-" << seasonLosses << " (" << seasonWinPercentage << " win), " << (seasonWins + seasonLosses) << " played"; 
                        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
                        
                        QueryResult members = CharacterDatabase.PQuery(
                                "SELECT "
                                // 0     1                 2           3
                                "a.guid, a.personalRating, a.weekWins, a.weekGames - a.weekWins, "
                                // 4           5
                                "a.seasonWins, a.seasonGames - seasonWins, "
                                // 6     7       8        9
                                "c.name, c.race, c.class, c.level "
                                "FROM arena_team_member a LEFT JOIN characters c ON a.guid = c.guid "
                                "WHERE arenaTeamId = '%u' "
                                "ORDER BY a.guid = '%u' DESC, a.seasonGames DESC, c.name ASC",
                                teamId, captainGuid);
                        
                        if(!members) {
                            player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "No team members found...?", GOSSIP_SENDER_MAIN, parentOption);
                            
                        } else {
                            uint32 memberPos = 1;
                            uint32 memberCount = members->GetRowCount();
                            uint32 guid, personalRating, level;
                            std::string name, race, Class;
                            
                            buf.str("");
                            buf << memberCount << " team " << ((memberCount == 1) ? "member" : " members") << " found:";
                            player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
                            
                            do {
                                // populate fields
                                fields = members->Fetch();
                                guid = fields[0].GetUInt32();
                                personalRating = fields[1].GetUInt32();
                                weekWins= fields[2].GetUInt32();
                                weekLosses = fields[3].GetUInt32();
                                seasonWins = fields[4].GetUInt32();
                                seasonLosses = fields[5].GetUInt32();
                                name = fields[6].GetString();
                                race = raceToString(fields[7].GetUInt8());
                                Class = classToString(fields[8].GetUInt8());
                                level = fields[9].GetUInt32();
                                
                                seasonWinPercentage = getWinPercent(seasonWins, seasonLosses);
                                weekWinPercentage = getWinPercent(weekWins, weekLosses);
                                
                                // TODO: add output
                                buf.str(""); // clear it
                                buf << memberPos << ". "; 
                                if (guid == captainGuid) 
                                    buf <<  "Team Captain ";
                                buf << name << ", " << getPlayerStatus(guid);
                                
                                player->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_1, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
                                buf.str("");
                                buf << "Level " << level << " " << race << " " << Class << ", " << personalRating << " personal rating.";
                                player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
                                buf.str("");
                                buf << "Week: " << weekWins << "-" << weekLosses << " (" << weekWinPercentage << " win), " << (weekWins + weekLosses) << " played"; 
                                player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
                                buf.str("");
                                buf << "Season: " << seasonWins << "-" << seasonLosses << " (" << seasonWinPercentage << " win), " << (seasonWins + seasonLosses) << " played"; 
                                player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
                                memberPos++;
                            } while(members->NextRow());
                            
                        }
                        
                        buf.str("");
                        buf << "Return to " << type << "v" << type << " rankings!";
                        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, buf.str(), GOSSIP_SENDER_MAIN, parentOption);
                        player->SEND_GOSSIP_MENU(ARENA_GOSSIP_TEAM_LOOKUP, creature->GetGUID());
                    }
                }
            }
            
            return true;
        }