Professional Documents
Culture Documents
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright
information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ArenaTeamMgr.h"
#include "DatabaseEnv.h"
#include "Define.h"
#include "Language.h"
#include "Log.h"
#include "ObjectAccessor.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "World.h"
ArenaTeamMgr::ArenaTeamMgr()
{
NextArenaTeamId = 1;
LastArenaLogId = 0;
NextTempArenaTeamId = 0xFFF00000;
}
ArenaTeamMgr::~ArenaTeamMgr()
{
for (ArenaTeamContainer::iterator itr = ArenaTeamStore.begin(); itr !=
ArenaTeamStore.end(); ++itr)
delete itr->second;
}
ArenaTeamMgr* ArenaTeamMgr::instance()
{
static ArenaTeamMgr instance;
return &instance;
}
return nullptr;
}
uint32 ArenaTeamMgr::GenerateArenaTeamId()
{
if (NextArenaTeamId >= MAX_ARENA_TEAM_ID)
{
LOG_ERROR("bg.arena", "Arena team ids overflow!! Can't continue, shutting
down server. ");
World::StopNow(ERROR_EXIT_CODE);
}
return NextArenaTeamId++;
}
uint32 ArenaTeamMgr::GenerateTempArenaTeamId()
{
if (NextTempArenaTeamId >= MAX_TEMP_ARENA_TEAM_ID)
NextTempArenaTeamId = MAX_ARENA_TEAM_ID;
return NextTempArenaTeamId++;
}
void ArenaTeamMgr::LoadArenaTeams()
{
uint32 oldMSTime = getMSTime();
// 0 1 2
3 4 5 6 7 8
QueryResult result = CharacterDatabase.Query("SELECT arenaTeamId, name,
captainGuid, type, backgroundColor, emblemStyle, emblemColor, borderStyle,
borderColor, "
// 9 10 11 12 13
14
"rating, weekGames, weekWins, seasonGames, seasonWins,
`rank` FROM arena_team ORDER BY arenaTeamId ASC");
if (!result)
{
LOG_WARN("server.loading", ">> Loaded 0 arena teams. DB table `arena_team`
is empty!");
LOG_INFO("server.loading", " ");
return;
}
uint32 count = 0;
do
{
ArenaTeam* newArenaTeam = new ArenaTeam;
if (!newArenaTeam->LoadArenaTeamFromDB(result) || !newArenaTeam-
>LoadMembersFromDB(result2))
{
newArenaTeam->Disband(nullptr);
delete newArenaTeam;
continue;
}
AddArenaTeam(newArenaTeam);
++count;
} while (result->NextRow());
void ArenaTeamMgr::DistributeArenaPoints()
{
// Used to distribute arena points based on last week's stats
sWorld->SendWorldText(LANG_DIST_ARENA_POINTS_START);
sWorld->SendWorldText(LANG_DIST_ARENA_POINTS_ONLINE_START);
// Temporary structure for storing maximum points to add values for all players
std::map<ObjectGuid, uint32> PlayerPoints;
CharacterDatabasePreparedStatement* stmt;
CharacterDatabase.CommitTransaction(trans);
PlayerPoints.clear();
sWorld->SendWorldText(LANG_DIST_ARENA_POINTS_ONLINE_END);
sWorld->SendWorldText(LANG_DIST_ARENA_POINTS_TEAM_START);
for (ArenaTeamContainer::iterator titr = GetArenaTeamMapBegin(); titr !=
GetArenaTeamMapEnd(); ++titr)
{
if (ArenaTeam* at = titr->second)
{
at->FinishWeek();
at->SaveToDB();
at->NotifyStatsChanged();
}
}
sWorld->SendWorldText(LANG_DIST_ARENA_POINTS_TEAM_END);
sWorld->SendWorldText(LANG_DIST_ARENA_POINTS_END);
}