Core/Arenas: Refactor arena code and db layout
This commit is contained in:
@@ -16225,6 +16225,7 @@ void Player::_LoadArenaTeamInfo(PreparedQueryResult result)
|
||||
{
|
||||
// arenateamid, played_week, played_season, personal_rating
|
||||
memset((void*)&m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1], 0, sizeof(uint32) * MAX_ARENA_SLOT * ARENA_TEAM_END);
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
@@ -16232,63 +16233,46 @@ void Player::_LoadArenaTeamInfo(PreparedQueryResult result)
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 arenateamid = fields[0].GetUInt32();
|
||||
uint32 played_week = fields[1].GetUInt32();
|
||||
uint32 played_season = fields[2].GetUInt32();
|
||||
uint32 wons_season = fields[3].GetUInt32();
|
||||
uint32 arenaTeamId = fields[0].GetUInt32();
|
||||
|
||||
ArenaTeam* aTeam = sObjectMgr->GetArenaTeamById(arenateamid);
|
||||
if (!aTeam)
|
||||
ArenaTeam* arenaTeam = sObjectMgr->GetArenaTeamById(arenaTeamId);
|
||||
if (!arenaTeam)
|
||||
{
|
||||
sLog->outError("Player::_LoadArenaTeamInfo: couldn't load arenateam %u", arenateamid);
|
||||
sLog->outError("Player::_LoadArenaTeamInfo: couldn't load arenateam %u", arenaTeamId);
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8 arenaSlot = aTeam->GetSlot();
|
||||
uint8 arenaSlot = arenaTeam->GetSlot();
|
||||
|
||||
SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_ID, arenateamid);
|
||||
SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_TYPE, aTeam->GetType());
|
||||
SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_MEMBER, (aTeam->GetCaptain() == GetGUID()) ? 0 : 1);
|
||||
SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_GAMES_WEEK, played_week);
|
||||
SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_GAMES_SEASON, played_season);
|
||||
SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_WINS_SEASON, wons_season);
|
||||
SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_ID, arenaTeamId);
|
||||
SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_TYPE, arenaTeam->GetType());
|
||||
SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_MEMBER, (arenaTeam->GetCaptain() == GetGUID()) ? 0 : 1);
|
||||
SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_GAMES_WEEK, uint32(fields[1].GetUInt16()));
|
||||
SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_GAMES_SEASON, uint32(fields[2].GetUInt16()));
|
||||
SetArenaTeamInfoField(arenaSlot, ARENA_TEAM_WINS_SEASON, uint32(fields[3].GetUInt16()));
|
||||
}
|
||||
while (result->NextRow());
|
||||
}
|
||||
|
||||
void Player::_LoadArenaStatsInfo(PreparedQueryResult result)
|
||||
{
|
||||
uint8 slot = 0;
|
||||
if (!result)
|
||||
uint16 personalRatingCache[] = {0, 0, 0};
|
||||
|
||||
if (result)
|
||||
{
|
||||
for (; slot <= 2; ++slot)
|
||||
do
|
||||
{
|
||||
CharacterDatabase.PExecute("INSERT INTO character_arena_stats (guid, slot, personal_rating, matchmaker_rating) VALUES (%u, %u, 0, 1500)", GetGUIDLow(), slot);
|
||||
SetArenaTeamInfoField(slot, ARENA_TEAM_PERSONAL_RATING, 0);
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
personalRatingCache[fields[0].GetUInt8()] = fields[1].GetUInt16();
|
||||
}
|
||||
return;
|
||||
while (result->NextRow());
|
||||
}
|
||||
|
||||
do
|
||||
for (uint8 slot = 0; slot <= 2; ++slot)
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 personalrating = 0;
|
||||
uint32 matchmakerrating = 1500;
|
||||
if (fields[0].GetUInt8() > slot)
|
||||
{
|
||||
CharacterDatabase.PExecute("INSERT INTO character_arena_stats (guid, slot, personal_rating, matchmaker_rating) VALUES (%u, %u, %u, %u)", GetGUIDLow(), slot, personalrating, matchmakerrating);
|
||||
SetArenaTeamInfoField(slot, ARENA_TEAM_PERSONAL_RATING, personalrating);
|
||||
slot++;
|
||||
continue;
|
||||
}
|
||||
|
||||
personalrating = fields[1].GetUInt32();
|
||||
matchmakerrating = fields[2].GetUInt32();
|
||||
SetArenaTeamInfoField(slot, ARENA_TEAM_PERSONAL_RATING, personalrating);
|
||||
slot++;
|
||||
SetArenaTeamInfoField(slot, ARENA_TEAM_PERSONAL_RATING, uint32(personalRatingCache[slot]));
|
||||
}
|
||||
while (result->NextRow());
|
||||
}
|
||||
|
||||
void Player::_LoadEquipmentSets(PreparedQueryResult result)
|
||||
@@ -16549,7 +16533,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder)
|
||||
continue;
|
||||
|
||||
if (ArenaTeam * at = sObjectMgr->GetArenaTeamById(arena_team_id))
|
||||
if (at->HaveMember(GetGUID()))
|
||||
if (at->IsMember(GetGUID()))
|
||||
continue;
|
||||
|
||||
// arena team not exist or not member, cleanup fields
|
||||
@@ -19732,21 +19716,25 @@ void Player::RemovePetitionsAndSigns(uint64 guid, uint32 type)
|
||||
|
||||
void Player::LeaveAllArenaTeams(uint64 guid)
|
||||
{
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT arena_team_member.arenateamid FROM arena_team_member JOIN arena_team ON arena_team_member.arenateamid = arena_team.arenateamid WHERE guid='%u'", GUID_LOPART(guid));
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_LOAD_PLAYER_ARENA_TEAMS);
|
||||
stmt->setUInt32(0, GUID_LOPART(guid));
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
uint32 at_id = fields[0].GetUInt32();
|
||||
if (at_id != 0)
|
||||
Field* fields = result->Fetch();
|
||||
uint32 arenaTeamId = fields[0].GetUInt32();
|
||||
if (arenaTeamId != 0)
|
||||
{
|
||||
ArenaTeam * at = sObjectMgr->GetArenaTeamById(at_id);
|
||||
if (at)
|
||||
at->DelMember(guid);
|
||||
ArenaTeam* arenaTeam = sObjectMgr->GetArenaTeamById(arenaTeamId);
|
||||
if (arenaTeam)
|
||||
arenaTeam->DelMember(guid, true);
|
||||
}
|
||||
} while (result->NextRow());
|
||||
}
|
||||
while (result->NextRow());
|
||||
}
|
||||
|
||||
void Player::SetRestBonus (float rest_bonus_new)
|
||||
|
||||
Reference in New Issue
Block a user