60 | | } |
61 | | } |
62 | | |
63 | | void BattleGroundQueue::AddPlayer(Player *plr, uint32 bgTypeId) |
| 63 | for(QueuedGroupsList::iterator itr = m_QueuedGroups[i].begin(); itr!= m_QueuedGroups[i].end(); ++itr) |
| 64 | { |
| 65 | delete (*itr); |
| 66 | } |
| 67 | m_QueuedGroups[i].clear(); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // initialize eligible groups from the given source matching the given specifications |
| 72 | void BattleGroundQueue::EligibleGroups::Init(BattleGroundQueue::QueuedGroupsList *source, uint32 BgTypeId, uint32 side, uint32 MaxPlayers, uint8 ArenaType, bool IsRated, uint32 MinRating, uint32 MaxRating, uint32 DisregardTime, uint32 excludeTeam) |
| 73 | { |
| 74 | // clear from prev initialization |
| 75 | clear(); |
| 76 | BattleGroundQueue::QueuedGroupsList::iterator itr, next; |
| 77 | // iterate through the source |
| 78 | for(itr = source->begin(); itr!= source->end(); itr = next) |
| 79 | { |
| 80 | next = itr; |
| 81 | ++next; |
| 82 | if( (*itr)->BgTypeId == BgTypeId && // bg type must match |
| 83 | (*itr)->ArenaType == ArenaType && // arena type must match |
| 84 | (*itr)->IsRated == IsRated && // israted must match |
| 85 | (*itr)->IsInvitedToBGInstanceGUID == 0 && // leave out already invited groups |
| 86 | (*itr)->Team == side && // match side |
| 87 | (*itr)->Players.size() <= MaxPlayers && // the group must fit in the bg |
| 88 | ( !excludeTeam || (*itr)->ArenaTeamId != excludeTeam ) && // if excludeTeam is specified, leave out those arena team ids |
| 89 | ( !IsRated || (*itr)->Players.size() == MaxPlayers ) && // if rated, then pass only if the player count is exact NEEDS TESTING! (but now this should never happen) |
| 90 | ( (*itr)->JoinTime <= DisregardTime // pass if disregard time is greater than join time |
| 91 | || (*itr)->ArenaTeamRating == 0 // pass if no rating info |
| 92 | || ( (*itr)->ArenaTeamRating >= MinRating // pass if matches the rating range |
| 93 | && (*itr)->ArenaTeamRating <= MaxRating ) ) ) |
| 94 | { |
| 95 | // the group matches the conditions |
| 96 | // insert it in order of groupsize, and join time |
| 97 | uint32 size = (*itr)->Players.size(); |
| 98 | uint32 jointime = (*itr)->JoinTime; |
| 99 | bool inserted = false; |
| 100 | |
| 101 | for(std::list<GroupQueueInfo *>::iterator elig_itr = begin(); elig_itr != end(); ++elig_itr) |
| 102 | { |
| 103 | // if the next one's size is smaller, then insert |
| 104 | // also insert if the next one's size is equal, but it joined the queue later |
| 105 | if( ((*elig_itr)->Players.size()<size) || |
| 106 | ((*elig_itr)->Players.size() == size && (*elig_itr)->JoinTime > jointime) ) |
| 107 | { |
| 108 | insert(elig_itr,(*itr)); |
| 109 | inserted = true; |
| 110 | break; |
| 111 | } |
| 112 | } |
| 113 | // if not inserted -> this is the smallest group -> push_back |
| 114 | if(!inserted) |
| 115 | { |
| 116 | push_back((*itr)); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // remove group from eligible groups |
| 123 | // used when building selection pools |
| 124 | void BattleGroundQueue::EligibleGroups::RemoveGroup(GroupQueueInfo * ginfo) |
| 125 | { |
| 126 | for(std::list<GroupQueueInfo *>::iterator itr = begin(); itr != end(); ++itr) |
| 127 | { |
| 128 | if((*itr)==ginfo) |
| 129 | { |
| 130 | erase(itr); |
| 131 | return; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | // selection pool initialization, used to clean up from prev selection |
| 137 | void BattleGroundQueue::SelectionPool::Init() |
| 138 | { |
| 139 | SelectedGroups.clear(); |
| 140 | MaxGroup = 0; |
| 141 | PlayerCount = 0; |
| 142 | } |
| 143 | |
| 144 | // get the maximal group from the selection pool |
| 145 | // used when building the pool, and have to remove the largest |
| 146 | GroupQueueInfo * BattleGroundQueue::SelectionPool::GetMaximalGroup() |
| 147 | { |
| 148 | if(SelectedGroups.empty()) |
| 149 | { |
| 150 | sLog.outError("Getting max group when selection pool is empty, this should never happen."); |
| 151 | MaxGroup = NULL; |
| 152 | return 0; |
| 153 | } |
| 154 | // actually select the max group if it's not set |
| 155 | if(MaxGroup==0 && !SelectedGroups.empty()) |
| 156 | { |
| 157 | uint32 max_size = 0; |
| 158 | for(std::list<GroupQueueInfo *>::iterator itr = SelectedGroups.begin(); itr != SelectedGroups.end(); ++itr) |
| 159 | { |
| 160 | if(max_size<(*itr)->Players.size()) |
| 161 | { |
| 162 | MaxGroup =(*itr); |
| 163 | max_size = MaxGroup->Players.size(); |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | return MaxGroup; |
| 168 | } |
| 169 | |
| 170 | // remove group info from selection pool |
| 171 | // used when building selection pools and have to remove maximal group |
| 172 | void BattleGroundQueue::SelectionPool::RemoveGroup(GroupQueueInfo *ginfo) |
| 173 | { |
| 174 | // uninitiate max group info if needed |
| 175 | if(MaxGroup == ginfo) |
| 176 | MaxGroup = 0; |
| 177 | // find what to remove |
| 178 | for(std::list<GroupQueueInfo *>::iterator itr = SelectedGroups.begin(); itr != SelectedGroups.end(); ++itr) |
| 179 | { |
| 180 | if((*itr)==ginfo) |
| 181 | { |
| 182 | SelectedGroups.erase(itr); |
| 183 | // decrease selected players count |
| 184 | PlayerCount -= ginfo->Players.size(); |
| 185 | return; |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | // add group to selection |
| 191 | // used when building selection pools |
| 192 | void BattleGroundQueue::SelectionPool::AddGroup(GroupQueueInfo * ginfo) |
| 193 | { |
| 194 | SelectedGroups.push_back(ginfo); |
| 195 | // increase selected players count |
| 196 | PlayerCount+=ginfo->Players.size(); |
| 197 | if(!MaxGroup || ginfo->Players.size() > MaxGroup->Players.size()) |
| 198 | { |
| 199 | // update max group info if needed |
| 200 | MaxGroup = ginfo; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // add group to bg queue with the given leader and bg specifications |
| 205 | GroupQueueInfo * BattleGroundQueue::AddGroup(Player *leader, uint32 BgTypeId, uint8 ArenaType, bool isRated, uint32 arenaRating, uint32 arenateamid) |
| 206 | { |
| 207 | uint32 queue_id = leader->GetBattleGroundQueueIdFromLevel(); |
| 208 | |
| 209 | // create new ginfo |
| 210 | // cannot use the method like in addplayer, because that could modify an in-queue group's stats |
| 211 | // (e.g. leader leaving queue then joining as individual again) |
| 212 | GroupQueueInfo* ginfo = new GroupQueueInfo; |
| 213 | ginfo->BgTypeId = BgTypeId; |
| 214 | ginfo->ArenaType = ArenaType; |
| 215 | ginfo->ArenaTeamId = arenateamid; |
| 216 | ginfo->IsRated = isRated; |
| 217 | ginfo->IsInvitedToBGInstanceGUID = 0; // maybe this should be modifiable by function arguments to enable selection of running instances? |
| 218 | ginfo->JoinTime = getMSTime(); |
| 219 | ginfo->Team = leader->GetTeam(); |
| 220 | |
| 221 | if(sBattleGroundMgr.GetMaxRatingDifference()) // if max difference is set, then store rating info for queue |
| 222 | ginfo->ArenaTeamRating = arenaRating; |
| 223 | else |
| 224 | ginfo->ArenaTeamRating = 0; // don't if it doesn't matter |
| 225 | |
| 226 | ginfo->Players.clear(); |
| 227 | |
| 228 | m_QueuedGroups[queue_id].push_back(ginfo); |
| 229 | |
| 230 | // return ginfo, because it is needed to add players to this group info |
| 231 | return ginfo; |
| 232 | } |
| 233 | |
| 234 | void BattleGroundQueue::AddPlayer(Player *plr, GroupQueueInfo *ginfo) |
73 | | info.Team = plr->GetTeam(); |
74 | | |
75 | | //add player to waiting order queue |
76 | | m_PlayersSortedByWaitTime[queue_id].push_back(plr->GetGUID()); |
77 | | |
78 | | if(plr->GetTeam() == ALLIANCE) |
79 | | ++m_QueuedPlayers[queue_id].Alliance; |
80 | | else |
81 | | ++m_QueuedPlayers[queue_id].Horde; |
82 | | |
83 | | this->Update(bgTypeId, queue_id); |
84 | | |
85 | | if( sWorld.getConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE) ) |
86 | | { |
87 | | BattleGround* bg = sBattleGroundMgr.GetBattleGround(bgTypeId); |
88 | | char const* bgName = bg->GetName(); |
89 | | |
90 | | uint32 q_min_level = Player::GetMinLevelForBattleGroundQueueId(queue_id); |
91 | | uint32 q_max_level = Player::GetMaxLevelForBattleGroundQueueId(queue_id); |
92 | | |
93 | | // replace hardcoded max level by player max level for nice output |
94 | | if(q_max_level > sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL)) |
95 | | q_max_level = sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL); |
96 | | |
97 | | int8 MinPlayers = bg->GetMinPlayersPerTeam(); |
98 | | |
99 | | uint8 qHorde = m_QueuedPlayers[queue_id].Horde; |
100 | | uint8 qAlliance = m_QueuedPlayers[queue_id].Alliance; |
101 | | |
102 | | // Show queue status to player only (when joining queue) |
103 | | if(sWorld.getConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_PLAYERONLY)) |
104 | | { |
105 | | ChatHandler(plr).PSendSysMessage(LANG_BG_QUEUE_ANNOUNCE_SELF, |
106 | | bgName, q_min_level, q_max_level, qAlliance, MinPlayers - qAlliance, qHorde, MinPlayers - qHorde); |
107 | | } |
108 | | // System message |
109 | | else |
110 | | { |
111 | | sWorld.SendWorldText(LANG_BG_QUEUE_ANNOUNCE_WORLD, |
112 | | bgName, q_min_level, q_max_level, qAlliance, MinPlayers - qAlliance, qHorde, MinPlayers - qHorde); |
113 | | } |
114 | | } |
| 243 | info.GroupInfo = ginfo; |
| 244 | |
| 245 | // add the pinfo to ginfo's list |
| 246 | ginfo->Players[plr->GetGUID()] = &info; |
139 | | else |
140 | | { //player is online, we have his level, so we can find exact queue from his level |
141 | | queue_id = plr->GetBattleGroundQueueIdFromLevel(); |
142 | | itr = m_QueuedPlayers[queue_id].find(guid); |
143 | | IsSet = true; |
144 | | } |
145 | | |
146 | | //all variables are set, so remove player |
147 | | //remove player from time queue |
148 | | m_PlayersSortedByWaitTime[queue_id].remove(guid); |
149 | | |
150 | | if (IsSet && itr != m_QueuedPlayers[queue_id].end()) |
151 | | { |
152 | | if (!itr->second.IsInvitedToBGInstanceGUID) |
153 | | { |
154 | | if(itr->second.Team == ALLIANCE) |
155 | | --m_QueuedPlayers[queue_id].Alliance; |
156 | | else |
157 | | --m_QueuedPlayers[queue_id].Horde; |
158 | | } |
159 | | else |
160 | | { |
161 | | if (decreaseInvitedCount) |
162 | | { |
163 | | BattleGround* bg = sBattleGroundMgr.GetBattleGround(itr->second.IsInvitedToBGInstanceGUID); |
| 282 | |
| 283 | // couldn't find the player in bg queue, return |
| 284 | if(!IsSet) |
| 285 | { |
| 286 | sLog.outError("Battleground: couldn't find player to remove."); |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | group = itr->second.GroupInfo; |
| 291 | |
| 292 | for(group_itr=m_QueuedGroups[queue_id].begin(); group_itr != m_QueuedGroups[queue_id].end(); ++group_itr) |
| 293 | { |
| 294 | if(group == (GroupQueueInfo*)(*group_itr)) |
| 295 | break; |
| 296 | } |
| 297 | |
| 298 | // variables are set (what about leveling up when in queue????) |
| 299 | // remove player from group |
| 300 | // if only player there, remove group |
| 301 | |
| 302 | // remove player queue info from group queue info |
| 303 | std::map<uint64, PlayerQueueInfo*>::iterator pitr = group->Players.find(guid); |
| 304 | |
| 305 | if(pitr != group->Players.end()) |
| 306 | group->Players.erase(pitr); |
| 307 | |
| 308 | // check for iterator correctness |
| 309 | if (group_itr != m_QueuedGroups[queue_id].end() && itr != m_QueuedPlayers[queue_id].end()) |
| 310 | { |
| 311 | // used when player left the queue, NOT used when porting to bg |
| 312 | if (decreaseInvitedCount) |
| 313 | { |
| 314 | // if invited to bg, and should decrease invited count, then do it |
| 315 | if(group->IsInvitedToBGInstanceGUID) |
| 316 | { |
| 317 | BattleGround* bg = sBattleGroundMgr.GetBattleGround(group->IsInvitedToBGInstanceGUID); |
| 331 | // remove group queue info if needed |
| 332 | if(group->Players.empty()) |
| 333 | { |
| 334 | m_QueuedGroups[queue_id].erase(group_itr); |
| 335 | delete group; |
| 336 | } |
| 337 | // NEEDS TESTING! |
| 338 | // group wasn't empty, so it wasn't deleted, and player have left a rated queue -> everyone from the group should leave too |
| 339 | // don't remove recursively if already invited to bg! |
| 340 | else if(!group->IsInvitedToBGInstanceGUID && decreaseInvitedCount && group->IsRated) |
| 341 | { |
| 342 | // remove next player, this is recursive |
| 343 | // first send removal information |
| 344 | if(Player *plr2 = objmgr.GetPlayer(group->Players.begin()->first)) |
| 345 | { |
| 346 | BattleGround * bg = sBattleGroundMgr.GetBattleGroundTemplate(group->BgTypeId); |
| 347 | uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(group->BgTypeId,group->ArenaType); |
| 348 | uint32 queueSlot = plr2->GetBattleGroundQueueIndex(bgQueueTypeId); |
| 349 | plr2->RemoveBattleGroundQueueId(bgQueueTypeId); // must be called this way, because if you move this call to queue->removeplayer, it causes bugs |
| 350 | WorldPacket data; |
| 351 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, plr2->GetTeam(), queueSlot, STATUS_NONE, 0, 0); |
| 352 | plr2->GetSession()->SendPacket(&data); |
| 353 | } |
| 354 | // then actually delete, this may delete the group as well! |
| 355 | RemovePlayer(group->Players.begin()->first,decreaseInvitedCount); |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | bool BattleGroundQueue::InviteGroupToBG(GroupQueueInfo * ginfo, BattleGround * bg, uint32 side) |
| 361 | { |
| 362 | // set side if needed |
| 363 | if(side) |
| 364 | ginfo->Team = side; |
| 365 | |
| 366 | if(!ginfo->IsInvitedToBGInstanceGUID) |
| 367 | { |
| 368 | // not yet invited |
| 369 | // set invitation |
| 370 | ginfo->IsInvitedToBGInstanceGUID = bg->GetInstanceID(); |
| 371 | uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bg->GetTypeID(), bg->GetArenaType()); |
| 372 | // loop through the players |
| 373 | for(std::map<uint64,PlayerQueueInfo*>::iterator itr = ginfo->Players.begin(); itr != ginfo->Players.end(); ++itr) |
| 374 | { |
| 375 | // set status |
| 376 | itr->second->InviteTime = getMSTime(); |
| 377 | itr->second->LastInviteTime = getMSTime(); |
| 378 | |
| 379 | // get the player |
| 380 | Player* plr = objmgr.GetPlayer(itr->first); |
| 381 | // if offline, skip him |
| 382 | if(!plr) |
| 383 | continue; |
| 384 | |
| 385 | // invite the player |
| 386 | sBattleGroundMgr.InvitePlayer(plr, bg->GetInstanceID(),ginfo->Team); |
| 387 | |
| 388 | WorldPacket data; |
| 389 | |
| 390 | uint32 queueSlot = plr->GetBattleGroundQueueIndex(bgQueueTypeId); |
| 391 | |
| 392 | sLog.outDebug("Battleground: invited plr %s (%u) to BG instance %u queueindex %u bgtype %u, I can't help it if they don't press the enter battle button.",plr->GetName(),plr->GetGUIDLow(),bg->GetInstanceID(),queueSlot,bg->GetTypeID()); |
| 393 | |
| 394 | // send status packet |
| 395 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, side?side:plr->GetTeam(), queueSlot, STATUS_WAIT_JOIN, INVITE_ACCEPT_WAIT_TIME, 0); |
| 396 | plr->GetSession()->SendPacket(&data); |
| 397 | } |
| 398 | return true; |
| 399 | } |
| 400 | |
| 401 | return false; |
| 402 | } |
| 403 | |
| 404 | // this function is responsible for the selection of queued groups when trying to create new battlegrounds |
| 405 | bool BattleGroundQueue::BuildSelectionPool(uint32 bgTypeId, uint32 queue_id, uint32 MinPlayers, uint32 MaxPlayers, SelectionPoolBuildMode mode, uint8 ArenaType, bool isRated, uint32 MinRating, uint32 MaxRating, uint32 DisregardTime, uint32 excludeTeam) |
| 406 | { |
| 407 | uint32 side; |
| 408 | switch(mode) |
| 409 | { |
| 410 | case NORMAL_ALLIANCE: |
| 411 | case ONESIDE_ALLIANCE_TEAM1: |
| 412 | case ONESIDE_ALLIANCE_TEAM2: |
| 413 | side = ALLIANCE; |
| 414 | break; |
| 415 | case NORMAL_HORDE: |
| 416 | case ONESIDE_HORDE_TEAM1: |
| 417 | case ONESIDE_HORDE_TEAM2: |
| 418 | side = HORDE; |
| 419 | break; |
| 420 | default: |
| 421 | //unknown mode, return false |
| 422 | sLog.outDebug("Battleground: unknown selection pool build mode, returning..."); |
| 423 | return false; |
| 424 | break; |
| 425 | } |
| 426 | |
| 427 | // inititate the groups eligible to create the bg |
| 428 | m_EligibleGroups.Init(&(m_QueuedGroups[queue_id]), bgTypeId, side, MaxPlayers, ArenaType, isRated, MinRating, MaxRating, DisregardTime, excludeTeam); |
| 429 | // init the selected groups (clear) |
| 430 | m_SelectionPools[mode].Init(); |
| 431 | while(!(m_EligibleGroups.empty())) |
| 432 | { |
| 433 | sLog.outDebug("m_EligibleGroups is not empty, continue building selection pool"); |
| 434 | // in decreasing group size, add groups to join if they fit in the MaxPlayersPerTeam players |
| 435 | for(EligibleGroups::iterator itr= m_EligibleGroups.begin(); itr!=m_EligibleGroups.end(); ++itr) |
| 436 | { |
| 437 | // get the maximal not yet checked group |
| 438 | GroupQueueInfo * MaxGroup = (*itr); |
| 439 | // if it fits in the maxplayer size, add it |
| 440 | if( (m_SelectionPools[mode].GetPlayerCount() + MaxGroup->Players.size()) <= MaxPlayers ) |
| 441 | { |
| 442 | m_SelectionPools[mode].AddGroup(MaxGroup); |
| 443 | } |
| 444 | } |
| 445 | if(m_SelectionPools[mode].GetPlayerCount()>=MinPlayers) |
| 446 | { |
| 447 | // the selection pool is set, return |
| 448 | sLog.outDebug("pool build succeeded, return true"); |
| 449 | return true; |
| 450 | } |
| 451 | // if the selection pool's not set, then remove the group with the highest player count, and try again with the rest. |
| 452 | GroupQueueInfo * MaxGroup = m_SelectionPools[mode].GetMaximalGroup(); |
| 453 | m_EligibleGroups.RemoveGroup(MaxGroup); |
| 454 | m_SelectionPools[mode].RemoveGroup(MaxGroup); |
| 455 | } |
| 456 | // failed to build a selection pool matching the given values |
| 457 | return false; |
| 458 | } |
| 459 | |
| 460 | // used to remove the Enter Battle window if the battle has already, but someone still has it |
| 461 | // (this can happen in arenas mainly, since the preparation is shorter than the timer for the bgqueueremove event |
| 462 | void BattleGroundQueue::BGEndedRemoveInvites(BattleGround *bg) |
| 463 | { |
| 464 | uint32 queue_id = bg->GetQueueType(); |
| 465 | uint32 bgInstanceId = bg->GetInstanceID(); |
| 466 | uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bg->GetTypeID(), bg->GetArenaType()); |
| 467 | QueuedGroupsList::iterator itr, next; |
| 468 | for(itr = m_QueuedGroups[queue_id].begin(); itr != m_QueuedGroups[queue_id].end(); itr = next) |
| 469 | { |
| 470 | // must do this way, because the groupinfo will be deleted when all playerinfos are removed |
| 471 | GroupQueueInfo * ginfo = (*itr); |
| 472 | next = itr; |
| 473 | ++next; |
| 474 | // if group was invited to this bg instance, then remove all references |
| 475 | if(ginfo->IsInvitedToBGInstanceGUID == bgInstanceId) |
| 476 | { |
| 477 | // after removing this much playerinfos, the ginfo will be deleted, so we'll use a for loop |
| 478 | uint32 to_remove = ginfo->Players.size(); |
| 479 | uint32 team = ginfo->Team; |
| 480 | for(int i = 0; i < to_remove; ++i) |
| 481 | { |
| 482 | // always remove the first one in the group |
| 483 | std::map<uint64, PlayerQueueInfo * >::iterator itr2 = ginfo->Players.begin(); |
| 484 | if(itr2 == ginfo->Players.end()) |
| 485 | { |
| 486 | sLog.outError("Empty Players in ginfo, this should never happen!"); |
| 487 | return; |
| 488 | } |
| 489 | |
| 490 | // get the player |
| 491 | Player * plr = objmgr.GetPlayer(itr2->first); |
| 492 | if(!plr) |
| 493 | { |
| 494 | sLog.outError("Player offline when trying to remove from GroupQueueInfo, this should never happen."); |
| 495 | continue; |
| 496 | } |
| 497 | |
| 498 | // get the queueslot |
| 499 | uint32 queueSlot = plr->GetBattleGroundQueueIndex(bgQueueTypeId); |
| 500 | if (queueSlot < PLAYER_MAX_BATTLEGROUND_QUEUES) // player is in queue |
| 501 | { |
| 502 | plr->RemoveBattleGroundQueueId(bgQueueTypeId); |
| 503 | // remove player from queue, this might delete the ginfo as well! don't use that pointer after this! |
| 504 | RemovePlayer(itr2->first, true); |
| 505 | // this is probably unneeded, since this player was already invited -> does not fit when initing eligible groups |
| 506 | // but updateing the queue can't hurt |
| 507 | Update(bgQueueTypeId, bg->GetQueueType()); |
| 508 | // send info to client |
| 509 | WorldPacket data; |
| 510 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, team, queueSlot, STATUS_NONE, 0, 0); |
| 511 | plr->GetSession()->SendPacket(&data); |
| 512 | } |
| 513 | } |
| 514 | } |
205 | | Player* plr = objmgr.GetPlayer(*itr2); |
206 | | if (!plr) |
207 | | { |
208 | | //something is wrong!, kick player from queue |
209 | | sLog.outError("BATTLEGROUND: problem with inviting offline player to Battleground queue .... pls report bug"); |
210 | | uint64 oldval = *itr2; |
211 | | itr2 = m_PlayersSortedByWaitTime[queue_id].erase(itr2); |
212 | | RemovePlayer(oldval, true); |
213 | | continue; |
214 | | } |
215 | | |
216 | | // player will be invited, if in bg there is a free slot for him |
217 | | if (bg->HasFreeSlotsForTeam(plr->GetTeam())) |
218 | | { |
219 | | // iterator to player's queue status |
220 | | QueuedPlayersMap::iterator itrPlayerStatus = m_QueuedPlayers[queue_id].find(*itr2); |
221 | | |
222 | | // remove him from time queue |
223 | | itr2 = m_PlayersSortedByWaitTime[queue_id].erase(itr2); |
224 | | |
225 | | // only check to be sure ... but this condition shouldn't be true (if it is true, then there is a bug somewhere and pls report it) |
226 | | if (itrPlayerStatus == m_QueuedPlayers[queue_id].end()) |
227 | | continue; |
228 | | |
229 | | // check if player is not already invited |
230 | | if (!itrPlayerStatus->second.IsInvitedToBGInstanceGUID) |
231 | | { |
232 | | itrPlayerStatus->second.IsInvitedToBGInstanceGUID = bg->GetInstanceID(); |
233 | | itrPlayerStatus->second.InviteTime = getMSTime(); |
234 | | itrPlayerStatus->second.LastInviteTime = getMSTime(); |
235 | | if(itrPlayerStatus->second.Team == ALLIANCE) |
236 | | --m_QueuedPlayers[queue_id].Alliance; |
237 | | else |
238 | | --m_QueuedPlayers[queue_id].Horde; |
239 | | sBattleGroundMgr.InvitePlayer(plr, bg->GetInstanceID()); |
240 | | |
241 | | WorldPacket data; |
242 | | uint32 queueSlot = plr->GetBattleGroundQueueIndex(bgTypeId); |
243 | | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, plr->GetTeam(), queueSlot, STATUS_WAIT_JOIN, INVITE_ACCEPT_WAIT_TIME, 0); |
244 | | plr->GetSession()->SendPacket(&data); |
245 | | } |
246 | | } |
247 | | else |
248 | | ++itr2; |
249 | | |
250 | | //if battleground is FULL, then it is removed from free slot queue - not yet implemented! |
251 | | if (!bg->HasFreeSlots()) |
252 | | { |
253 | | //if bg is full, there is no need to invite other players, so break |
254 | | break; |
255 | | //remove BG from BGFreeSlotQueue - not used now, in this system we don't remove BGs from free queue |
256 | | //bg->RemoveFromBGFreeSlotQueue() --- do not uncomment this - not yet implemented |
257 | | } |
| 560 | // if group fits in, invite it |
| 561 | InviteGroupToBG((*itr),bg,(*itr)->Team); |
276 | | if (m_QueuedPlayers[queue_id].Alliance >= bg2->GetMinPlayersPerTeam() && m_QueuedPlayers[queue_id].Horde >= bg2->GetMinPlayersPerTeam()) |
277 | | { |
| 580 | } |
| 581 | |
| 582 | // get the min. players per team, properly for larger arenas as well. (must have full teams for arena matches!) |
| 583 | uint32 MinPlayersPerTeam = bg_template->GetMinPlayersPerTeam(); |
| 584 | uint32 MaxPlayersPerTeam = bg_template->GetMaxPlayersPerTeam(); |
| 585 | if(bg_template->isArena()) |
| 586 | { |
| 587 | if(sBattleGroundMgr.isArenaTesting()) |
| 588 | { |
| 589 | MaxPlayersPerTeam = 1; |
| 590 | MinPlayersPerTeam = 1; |
| 591 | } |
| 592 | else |
| 593 | { |
| 594 | switch(arenatype) |
| 595 | { |
| 596 | case ARENA_TYPE_2v2: |
| 597 | MaxPlayersPerTeam = 2; |
| 598 | MinPlayersPerTeam = 2; |
| 599 | break; |
| 600 | case ARENA_TYPE_3v3: |
| 601 | MaxPlayersPerTeam = 3; |
| 602 | MinPlayersPerTeam = 3; |
| 603 | break; |
| 604 | case ARENA_TYPE_5v5: |
| 605 | MaxPlayersPerTeam = 5; |
| 606 | MinPlayersPerTeam = 5; |
| 607 | break; |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | // found out the minimum and maximum ratings the newly added team should battle against |
| 613 | // arenaRating is the rating of the latest joined team |
| 614 | uint32 arenaMinRating = (arenaRating <= sBattleGroundMgr.GetMaxRatingDifference()) ? 0 : arenaRating - sBattleGroundMgr.GetMaxRatingDifference(); |
| 615 | // if no rating is specified, set maxrating to 0 |
| 616 | uint32 arenaMaxRating = (arenaRating == 0)? 0 : arenaRating + sBattleGroundMgr.GetMaxRatingDifference(); |
| 617 | uint32 discardTime = 0; |
| 618 | // if max rating difference is set and the time past since server startup is greater than the rating discard time |
| 619 | // (after what time the ratings aren't taken into account when making teams) then |
| 620 | // the discard time is current_time - time_to_discard, teams that joined after that, will have their ratings taken into account |
| 621 | // else leave the discard time on 0, this way all ratings will be discarded |
| 622 | if(sBattleGroundMgr.GetMaxRatingDifference() && getMSTime() >= sBattleGroundMgr.GetRatingDiscardTimer()) |
| 623 | discardTime = getMSTime() - sBattleGroundMgr.GetRatingDiscardTimer(); |
| 624 | |
| 625 | // try to build the selection pools |
| 626 | bool bAllyOK = BuildSelectionPool(bgTypeId, queue_id, MinPlayersPerTeam, MaxPlayersPerTeam, NORMAL_ALLIANCE, arenatype, isRated, arenaMinRating, arenaMaxRating, discardTime); |
| 627 | if(bAllyOK) |
| 628 | sLog.outDebug("Battleground: ally pool succesfully build"); |
| 629 | else |
| 630 | sLog.outDebug("Battleground: ally pool wasn't created"); |
| 631 | bool bHordeOK = BuildSelectionPool(bgTypeId, queue_id, MinPlayersPerTeam, MaxPlayersPerTeam, NORMAL_HORDE, arenatype, isRated, arenaMinRating, arenaMaxRating, discardTime); |
| 632 | if(bHordeOK) |
| 633 | sLog.outDebug("Battleground: horde pool succesfully built"); |
| 634 | else |
| 635 | sLog.outDebug("Battleground: horde pool wasn't created"); |
| 636 | |
| 637 | // if selection pools are ready, create the new bg |
| 638 | if (bAllyOK && bHordeOK) |
| 639 | { |
| 640 | BattleGround * bg2 = 0; |
| 641 | // special handling for arenas |
| 642 | if(bg_template->isArena()) |
| 643 | { |
| 644 | // Find a random arena, that can be created |
| 645 | uint8 arenas[] = {BATTLEGROUND_NA, BATTLEGROUND_BE, BATTLEGROUND_RL}; |
| 646 | uint32 arena_num = urand(0,2); |
| 647 | if( !(bg2 = sBattleGroundMgr.CreateNewBattleGround(arenas[arena_num%3])) && |
| 648 | !(bg2 = sBattleGroundMgr.CreateNewBattleGround(arenas[(arena_num+1)%3])) && |
| 649 | !(bg2 = sBattleGroundMgr.CreateNewBattleGround(arenas[(arena_num+2)%3])) ) |
| 650 | { |
| 651 | sLog.outError("Battleground: couldn't create arena"); |
| 652 | return; |
| 653 | } |
| 654 | |
| 655 | // set the MaxPlayersPerTeam values based on arenatype |
| 656 | // setting the min player values isn't needed, since we won't be using that value later on. |
| 657 | if(sBattleGroundMgr.isArenaTesting()) |
| 658 | { |
| 659 | bg2->SetMaxPlayersPerTeam(1); |
| 660 | bg2->SetMaxPlayers(2); |
| 661 | } |
| 662 | else |
| 663 | { |
| 664 | switch(arenatype) |
| 665 | { |
| 666 | case ARENA_TYPE_2v2: |
| 667 | bg2->SetMaxPlayersPerTeam(2); |
| 668 | bg2->SetMaxPlayers(4); |
| 669 | break; |
| 670 | case ARENA_TYPE_3v3: |
| 671 | bg2->SetMaxPlayersPerTeam(3); |
| 672 | bg2->SetMaxPlayers(6); |
| 673 | break; |
| 674 | case ARENA_TYPE_5v5: |
| 675 | bg2->SetMaxPlayersPerTeam(5); |
| 676 | bg2->SetMaxPlayers(10); |
| 677 | break; |
| 678 | default: |
| 679 | break; |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | else |
| 684 | { |
| 685 | // create new battleground |
| 686 | bg2 = sBattleGroundMgr.CreateNewBattleGround(bgTypeId); |
| 687 | } |
| 688 | |
| 689 | if(!bg2) |
| 690 | { |
| 691 | sLog.outError("Battleground: couldn't create bg %u",bgTypeId); |
| 692 | return; |
| 693 | } |
| 694 | |
| 695 | // start the joining of the bg |
280 | | |
281 | | for (PlayerGuidsSortedByTimeQueue::iterator itr2 = m_PlayersSortedByWaitTime[queue_id].begin(); itr2 != m_PlayersSortedByWaitTime[queue_id].end();) |
282 | | { |
283 | | Player* plr = objmgr.GetPlayer(*itr2); |
284 | | if (!plr) |
285 | | { |
286 | | //something is wrong!, kick player from queue |
287 | | sLog.outError("BATTLEGROUND: problem with inviting offline player to Battleground queue .... pls report bug"); |
288 | | uint64 oldval = *itr2; |
289 | | itr2 = m_PlayersSortedByWaitTime[queue_id].erase(itr2); |
290 | | RemovePlayer(oldval, true); |
291 | | continue; |
292 | | } |
293 | | |
294 | | /* TODO: (i'm not sure this code will be useful: |
295 | | here should be some condition like if (bg2->isArena() && bg2->isRated()) |
296 | | { |
297 | | invite players from 1 certain group on each faction to play arena match |
298 | | } else if ....and existing code |
299 | | */ |
300 | | // player will be invited, if in bg there is a free slot for him |
301 | | if (bg2->HasFreeSlotsForTeam(plr->GetTeam())) |
302 | | { |
303 | | // iterator to player's queue status |
304 | | QueuedPlayersMap::iterator itrPlayerStatus = m_QueuedPlayers[queue_id].find(*itr2); |
305 | | |
306 | | // remove him from time queue |
307 | | itr2 = m_PlayersSortedByWaitTime[queue_id].erase(itr2); |
308 | | |
309 | | // only check to be sure ... but this condition shouldn't be true (if it is true, then there is a bug somewhere and report it) |
310 | | if (itrPlayerStatus == m_QueuedPlayers[queue_id].end()) |
311 | | continue; |
312 | | |
313 | | //check if player is not already invited |
314 | | if (!itrPlayerStatus->second.IsInvitedToBGInstanceGUID) |
| 698 | // initialize arena / rating info |
| 699 | bg2->SetArenaType(arenatype); |
| 700 | // set rating |
| 701 | bg2->SetRated(isRated); |
| 702 | |
| 703 | std::list<GroupQueueInfo* >::iterator itr; |
| 704 | |
| 705 | // invite groups from horde selection pool |
| 706 | for(itr = m_SelectionPools[NORMAL_HORDE].SelectedGroups.begin(); itr != m_SelectionPools[NORMAL_HORDE].SelectedGroups.end(); ++itr) |
| 707 | { |
| 708 | InviteGroupToBG((*itr),bg2,HORDE); |
| 709 | } |
| 710 | |
| 711 | // invite groups from ally selection pools |
| 712 | for(itr = m_SelectionPools[NORMAL_ALLIANCE].SelectedGroups.begin(); itr != m_SelectionPools[NORMAL_ALLIANCE].SelectedGroups.end(); ++itr) |
| 713 | { |
| 714 | InviteGroupToBG((*itr),bg2,ALLIANCE); |
| 715 | } |
| 716 | |
| 717 | // start the battleground |
| 718 | bg2->StartBattleGround(); |
| 719 | } |
| 720 | |
| 721 | // there weren't enough players for a "normal" match |
| 722 | // if arena, enable horde versus horde or alliance versus alliance teams here |
| 723 | |
| 724 | else if(bg_template->isArena()) |
| 725 | { |
| 726 | bool bOneSideHordeTeam1 = false, bOneSideHordeTeam2 = false; |
| 727 | bool bOneSideAllyTeam1 = false, bOneSideAllyTeam2 = false; |
| 728 | bOneSideHordeTeam1 = BuildSelectionPool(bgTypeId, queue_id,MaxPlayersPerTeam,MaxPlayersPerTeam,ONESIDE_HORDE_TEAM1,arenatype, isRated, arenaMinRating, arenaMaxRating, discardTime); |
| 729 | if(bOneSideHordeTeam1) |
| 730 | { |
| 731 | // one team has been selected, find out if other can be selected too |
| 732 | std::list<GroupQueueInfo* >::iterator itr; |
| 733 | // temporarily change the team side to enable building the next pool excluding the already selected groups |
| 734 | for(itr = m_SelectionPools[ONESIDE_HORDE_TEAM1].SelectedGroups.begin(); itr != m_SelectionPools[ONESIDE_HORDE_TEAM1].SelectedGroups.end(); ++itr) |
| 735 | (*itr)->Team=ALLIANCE; |
| 736 | |
| 737 | bOneSideHordeTeam2 = BuildSelectionPool(bgTypeId, queue_id,MaxPlayersPerTeam,MaxPlayersPerTeam,ONESIDE_HORDE_TEAM2,arenatype, isRated, arenaMinRating, arenaMaxRating, discardTime, (*(m_SelectionPools[ONESIDE_HORDE_TEAM1].SelectedGroups.begin()))->ArenaTeamId); |
| 738 | |
| 739 | // change back the team to horde |
| 740 | for(itr = m_SelectionPools[ONESIDE_HORDE_TEAM1].SelectedGroups.begin(); itr != m_SelectionPools[ONESIDE_HORDE_TEAM1].SelectedGroups.end(); ++itr) |
| 741 | (*itr)->Team=HORDE; |
| 742 | |
| 743 | if(!bOneSideHordeTeam2) |
| 744 | bOneSideHordeTeam1 = false; |
| 745 | } |
| 746 | if(!bOneSideHordeTeam1) |
| 747 | { |
| 748 | // check for one sided ally |
| 749 | bOneSideAllyTeam1 = BuildSelectionPool(bgTypeId, queue_id,MaxPlayersPerTeam,MaxPlayersPerTeam,ONESIDE_ALLIANCE_TEAM1,arenatype, isRated, arenaMinRating, arenaMaxRating, discardTime); |
| 750 | if(bOneSideAllyTeam1) |
| 751 | { |
| 752 | // one team has been selected, find out if other can be selected too |
| 753 | std::list<GroupQueueInfo* >::iterator itr; |
| 754 | // temporarily change the team side to enable building the next pool excluding the already selected groups |
| 755 | for(itr = m_SelectionPools[ONESIDE_ALLIANCE_TEAM1].SelectedGroups.begin(); itr != m_SelectionPools[ONESIDE_ALLIANCE_TEAM1].SelectedGroups.end(); ++itr) |
| 756 | (*itr)->Team=HORDE; |
| 757 | |
| 758 | bOneSideAllyTeam2 = BuildSelectionPool(bgTypeId, queue_id,MaxPlayersPerTeam,MaxPlayersPerTeam,ONESIDE_ALLIANCE_TEAM2,arenatype, isRated, arenaMinRating, arenaMaxRating, discardTime,(*(m_SelectionPools[ONESIDE_ALLIANCE_TEAM1].SelectedGroups.begin()))->ArenaTeamId); |
| 759 | |
| 760 | // change back the team to ally |
| 761 | for(itr = m_SelectionPools[ONESIDE_ALLIANCE_TEAM1].SelectedGroups.begin(); itr != m_SelectionPools[ONESIDE_ALLIANCE_TEAM1].SelectedGroups.end(); ++itr) |
| 762 | (*itr)->Team=ALLIANCE; |
| 763 | } |
| 764 | |
| 765 | if(!bOneSideAllyTeam2) |
| 766 | bOneSideAllyTeam1 = false; |
| 767 | } |
| 768 | // 1-sided BuildSelectionPool() will work, because the MinPlayersPerTeam == MaxPlayersPerTeam in every arena!!!! |
| 769 | if( (bOneSideHordeTeam1 && bOneSideHordeTeam2) || |
| 770 | (bOneSideAllyTeam1 && bOneSideAllyTeam2) ) |
| 771 | { |
| 772 | // which side has enough players? |
| 773 | uint32 side = 0; |
| 774 | SelectionPoolBuildMode mode1, mode2; |
| 775 | // find out what pools are we using |
| 776 | if(bOneSideAllyTeam1 && bOneSideAllyTeam2) |
| 777 | { |
| 778 | side = ALLIANCE; |
| 779 | mode1 = ONESIDE_ALLIANCE_TEAM1; |
| 780 | mode2 = ONESIDE_ALLIANCE_TEAM2; |
| 781 | } |
| 782 | else |
| 783 | { |
| 784 | side = HORDE; |
| 785 | mode1 = ONESIDE_HORDE_TEAM1; |
| 786 | mode2 = ONESIDE_HORDE_TEAM2; |
| 787 | } |
| 788 | |
| 789 | // create random arena |
| 790 | uint8 arenas[] = {BATTLEGROUND_NA, BATTLEGROUND_BE, BATTLEGROUND_RL}; |
| 791 | uint32 arena_num = urand(0,2); |
| 792 | BattleGround* bg2 = NULL; |
| 793 | if( !(bg2 = sBattleGroundMgr.CreateNewBattleGround(arenas[arena_num%3])) && |
| 794 | !(bg2 = sBattleGroundMgr.CreateNewBattleGround(arenas[(arena_num+1)%3])) && |
| 795 | !(bg2 = sBattleGroundMgr.CreateNewBattleGround(arenas[(arena_num+2)%3])) ) |
| 796 | { |
| 797 | sLog.outError("Could not create arena."); |
| 798 | return; |
| 799 | } |
| 800 | |
| 801 | sLog.outDebug("Battleground: One-faction arena created."); |
| 802 | // init stats |
| 803 | if(sBattleGroundMgr.isArenaTesting()) |
| 804 | { |
| 805 | bg2->SetMaxPlayersPerTeam(1); |
| 806 | bg2->SetMaxPlayers(2); |
| 807 | } |
| 808 | else |
| 809 | { |
| 810 | switch(arenatype) |
447 | | } |
448 | | |
449 | | void BattleGroundMgr::BuildBattleGroundStatusPacket(WorldPacket *data, BattleGround *bg, uint32 team, uint8 QueueSlot, uint8 StatusID, uint32 Time1, uint32 Time2) |
| 997 | // use the SetDeleteThis variable |
| 998 | // direct deletion caused crashes |
| 999 | if(itr->second->m_SetDeleteThis) |
| 1000 | { |
| 1001 | BattleGround * bg = itr->second; |
| 1002 | m_BattleGrounds.erase(itr); |
| 1003 | delete bg; |
| 1004 | } |
| 1005 | } |
| 1006 | // if rating difference counts, maybe force-update queues |
| 1007 | if(m_MaxRatingDifference) |
| 1008 | { |
| 1009 | // it's time to force update |
| 1010 | if(m_NextRatingDiscardUpdate < diff) |
| 1011 | { |
| 1012 | // forced update for level 70 rated arenas |
| 1013 | m_BattleGroundQueues[BATTLEGROUND_QUEUE_2v2].Update(BATTLEGROUND_AA,6,ARENA_TYPE_2v2,true,0); |
| 1014 | m_BattleGroundQueues[BATTLEGROUND_QUEUE_3v3].Update(BATTLEGROUND_AA,6,ARENA_TYPE_3v3,true,0); |
| 1015 | m_BattleGroundQueues[BATTLEGROUND_QUEUE_5v5].Update(BATTLEGROUND_AA,6,ARENA_TYPE_5v5,true,0); |
| 1016 | m_NextRatingDiscardUpdate = m_RatingDiscardTimer; |
| 1017 | } |
| 1018 | else |
| 1019 | m_NextRatingDiscardUpdate -= diff; |
| 1020 | } |
| 1021 | if(m_AutoDistributePoints) |
| 1022 | { |
| 1023 | if(m_AutoDistributionTimeChecker < diff) |
| 1024 | { |
| 1025 | if(time(NULL) > m_NextAutoDistributionTime) |
| 1026 | { |
| 1027 | DistributeArenaPoints(); |
| 1028 | m_NextAutoDistributionTime = time(NULL) + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY * sWorld.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS); |
| 1029 | CharacterDatabase.PExecute("UPDATE saved_variables SET NextArenaPointDistributionTime = FROM_UNIXTIME('"I64FMTD"')",(uint64)m_NextAutoDistributionTime); |
| 1030 | } |
| 1031 | m_AutoDistributionTimeChecker = 600000; // check 10 minutes |
| 1032 | } |
| 1033 | else |
| 1034 | m_AutoDistributionTimeChecker -= diff; |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | void BattleGroundMgr::BuildBattleGroundStatusPacket(WorldPacket *data, BattleGround *bg, uint32 team, uint8 QueueSlot, uint8 StatusID, uint32 Time1, uint32 Time2, uint32 arenatype, uint8 israted) |
| 1310 | BattleGround * BattleGroundMgr::GetBattleGroundTemplate(uint32 bgTypeId) |
| 1311 | { |
| 1312 | return BGFreeSlotQueue[bgTypeId].empty() ? NULL : BGFreeSlotQueue[bgTypeId].back(); |
| 1313 | } |
| 1314 | |
| 1315 | // create a new battleground that will really be used to play |
| 1316 | BattleGround * BattleGroundMgr::CreateNewBattleGround(uint32 bgTypeId) |
| 1317 | { |
| 1318 | BattleGround *bg = NULL; |
| 1319 | |
| 1320 | // get the template BG |
| 1321 | BattleGround *bg_template = GetBattleGroundTemplate(bgTypeId); |
| 1322 | |
| 1323 | if(!bg_template) |
| 1324 | { |
| 1325 | sLog.outError("BattleGround: CreateNewBattleGround - bg template not found for %u", bgTypeId); |
| 1326 | return 0; |
| 1327 | } |
| 1328 | |
| 1329 | // create a copy of the BG template |
| 1330 | switch(bgTypeId) |
| 1331 | { |
| 1332 | case BATTLEGROUND_AV: |
| 1333 | bg = new BattleGroundAV(*(BattleGroundAV*)bg_template); |
| 1334 | break; |
| 1335 | case BATTLEGROUND_WS: |
| 1336 | bg = new BattleGroundWS(*(BattleGroundWS*)bg_template); |
| 1337 | break; |
| 1338 | case BATTLEGROUND_AB: |
| 1339 | bg = new BattleGroundAB(*(BattleGroundAB*)bg_template); |
| 1340 | break; |
| 1341 | case BATTLEGROUND_NA: |
| 1342 | bg = new BattleGroundNA(*(BattleGroundNA*)bg_template); |
| 1343 | break; |
| 1344 | case BATTLEGROUND_BE: |
| 1345 | bg = new BattleGroundBE(*(BattleGroundBE*)bg_template); |
| 1346 | break; |
| 1347 | case BATTLEGROUND_AA: |
| 1348 | bg = new BattleGroundAA(*(BattleGroundAA*)bg_template); |
| 1349 | break; |
| 1350 | case BATTLEGROUND_EY: |
| 1351 | bg = new BattleGroundEY(*(BattleGroundEY*)bg_template); |
| 1352 | break; |
| 1353 | case BATTLEGROUND_RL: |
| 1354 | bg = new BattleGroundRL(*(BattleGroundRL*)bg_template); |
| 1355 | break; |
| 1356 | default: |
| 1357 | //bg = new BattleGround; |
| 1358 | return 0; |
| 1359 | break; // placeholder for non implemented BG |
| 1360 | } |
| 1361 | |
| 1362 | // generate a new instance id |
| 1363 | bg->SetInstanceID(MapManager::Instance().GenerateInstanceId()); // set instance id |
| 1364 | |
| 1365 | // reset the new bg (set status to status_wait_queue from status_none) |
| 1366 | bg->Reset(); |
| 1367 | |
| 1368 | /* will be setup in BG::Update() when the first player is ported in |
| 1369 | if(!(bg->SetupBattleGround())) |
| 1370 | { |
| 1371 | sLog.outError("BattleGround: CreateNewBattleGround: SetupBattleGround failed for bg %u", bgTypeId); |
| 1372 | delete bg; |
| 1373 | return 0; |
| 1374 | } |
| 1375 | */ |
| 1376 | |
| 1377 | // add BG to free slot queue |
| 1378 | bg->AddToBGFreeSlotQueue(); |
| 1379 | |
| 1380 | // add bg to update list |
| 1381 | AddBattleGround(bg->GetInstanceID(), bg); |
| 1382 | |
| 1383 | return bg; |
| 1384 | } |
| 1385 | |
| 1386 | // used to create the BG templates |
| 1553 | void BattleGroundMgr::InitAutomaticArenaPointDistribution() |
| 1554 | { |
| 1555 | if(m_AutoDistributePoints) |
| 1556 | { |
| 1557 | sLog.outDebug("Initializing Automatic Arena Point Distribution"); |
| 1558 | QueryResult * result = CharacterDatabase.Query("SELECT UNIX_TIMESTAMP(NextArenaPointDistributionTime) FROM saved_variables"); |
| 1559 | if(!result) |
| 1560 | { |
| 1561 | sLog.outDebug("Battleground: Next arena point distribution time not found in SavedVariables, reseting it now."); |
| 1562 | m_NextAutoDistributionTime = time(NULL) + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY * sWorld.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS); |
| 1563 | CharacterDatabase.PExecute("INSERT INTO saved_variables (NextArenaPointDistributionTime) VALUES ( FROM_UNIXTIME('"I64FMTD"') )",(uint64)m_NextAutoDistributionTime); |
| 1564 | } |
| 1565 | else |
| 1566 | { |
| 1567 | m_NextAutoDistributionTime = (*result)[0].GetUInt64(); |
| 1568 | delete result; |
| 1569 | } |
| 1570 | sLog.outDebug("Automatic Arena Point Distribution initialized."); |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | void BattleGroundMgr::DistributeArenaPoints() |
| 1575 | { |
| 1576 | // used to distribute arena points based on last week's stats |
| 1577 | |
| 1578 | CharacterDatabase.BeginTransaction(); |
| 1579 | // direct execute, because of the later GetUInt32ValueFromDB() calls |
| 1580 | // 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 |
| 1581 | CharacterDatabase.DirectPExecute("UPDATE characters b, arena_team_member a SET b.data = CONCAT( SUBSTRING_INDEX(b.data, ' ', '%u'),' ', CAST( IF ( ((CAST( SUBSTRING( b.data FROM (CHAR_LENGTH(SUBSTRING_INDEX(b.data,' ','%u')) + 2) FOR (CHAR_LENGTH(SUBSTRING_INDEX(b.data,' ','%u')) - CHAR_LENGTH(SUBSTRING_INDEX(b.data,' ','%u')) - 1) ) AS UNSIGNED) + (SELECT MAX(c.points_to_add) FROM arena_team_member c WHERE c.guid = b.guid GROUP BY c.guid) ) < '%u'), CAST(SUBSTRING(b.data FROM (CHAR_LENGTH(SUBSTRING_INDEX(b.data,' ','%u')) + 2) FOR (CHAR_LENGTH(SUBSTRING_INDEX(b.data,' ','%u')) - CHAR_LENGTH(SUBSTRING_INDEX(b.data,' ','%u')) - 1) ) AS UNSIGNED) + (SELECT MAX(d.points_to_add) FROM arena_team_member d WHERE d.guid = b.guid GROUP BY d.guid), '%u') AS CHAR),' ',SUBSTRING(b.data FROM (CHAR_LENGTH(SUBSTRING_INDEX(b.data,' ','%u')) + 2))) WHERE b.guid = a.guid",PLAYER_FIELD_ARENA_CURRENCY, PLAYER_FIELD_ARENA_CURRENCY, PLAYER_FIELD_ARENA_CURRENCY+1, PLAYER_FIELD_ARENA_CURRENCY, sWorld.getConfig(CONFIG_MAX_ARENA_POINTS),PLAYER_FIELD_ARENA_CURRENCY, PLAYER_FIELD_ARENA_CURRENCY+1, PLAYER_FIELD_ARENA_CURRENCY, sWorld.getConfig(CONFIG_MAX_ARENA_POINTS), PLAYER_FIELD_ARENA_CURRENCY+1); |
| 1582 | for(int i=0; i<3; ++i) |
| 1583 | { |
| 1584 | // reset weekly played matches |
| 1585 | uint32 position = PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 6 * i + 2; |
| 1586 | CharacterDatabase.DirectPExecute("UPDATE characters SET data = CONCAT( SUBSTRING_INDEX(data,' ','%u'),' ','0',' ',SUBSTRING(data FROM (CHAR_LENGTH(SUBSTRING_INDEX(data,' ','%u')) + 2)))",position, position + 1); |
| 1587 | } |
| 1588 | CharacterDatabase.DirectExecute("UPDATE arena_team_member SET points_to_add = '0', played_week = '0', wons_week = '0'"); |
| 1589 | CharacterDatabase.DirectExecute("UPDATE arena_team_stats SET games = '0', wins = '0'"); |
| 1590 | CharacterDatabase.CommitTransaction(); |
| 1591 | |
| 1592 | QueryResult *result = CharacterDatabase.PQuery("SELECT guid, data FROM characters WHERE online = '1'"); |
| 1593 | if( result ) |
| 1594 | { |
| 1595 | do |
| 1596 | { |
| 1597 | Field *fields = result->Fetch(); |
| 1598 | |
| 1599 | uint32 guid = fields[0].GetUInt32(); |
| 1600 | if(Player * pl = objmgr.GetPlayer(MAKE_NEW_GUID(guid, 0, HIGHGUID_PLAYER))) |
| 1601 | { |
| 1602 | Tokens data = StrSplit(fields[1].GetCppString(), " "); |
| 1603 | // update arena currency |
| 1604 | pl->SetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY, Player::GetUInt32ValueFromArray(data, PLAYER_FIELD_ARENA_CURRENCY)); |
| 1605 | // reset played this week count for all teams |
| 1606 | for(int i= 0; i < 3; ++i) |
| 1607 | pl->SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + 6 * i + 2, 0); |
| 1608 | } |
| 1609 | |
| 1610 | } while (result->NextRow()); |
| 1611 | |
| 1612 | delete result; |
| 1613 | } |
| 1614 | |
| 1615 | for(ObjectMgr::ArenaTeamSet::iterator titr = objmgr.GetArenaTeamSetBegin(); titr != objmgr.GetArenaTeamSetEnd(); ++titr) |
| 1616 | { |
| 1617 | if(ArenaTeam * at = (*titr)) |
| 1618 | { |
| 1619 | at->FinishWeek(); // set played this week etc values to 0 in memory, too |
| 1620 | // at->SaveToDB(); // no need, the modified values are already saved above |
| 1621 | at->NotifyStatsChanged(); // notify the players of the changes |
| 1622 | } |
| 1623 | } |
| 1624 | } |
| 1625 | |
| 1691 | |
| 1692 | void BattleGroundMgr::RemoveBattleGround(uint32 instanceID) |
| 1693 | { |
| 1694 | BattleGroundSet::iterator itr = m_BattleGrounds.find(instanceID); |
| 1695 | if(itr!=m_BattleGrounds.end()) |
| 1696 | m_BattleGrounds.erase(itr); |
| 1697 | } |
| 1698 | |
| 1699 | bool BattleGroundMgr::IsArenaType(uint32 bgTypeId) const |
| 1700 | { |
| 1701 | return ( bgTypeId == BATTLEGROUND_AA || |
| 1702 | bgTypeId == BATTLEGROUND_BE || |
| 1703 | bgTypeId == BATTLEGROUND_NA || |
| 1704 | bgTypeId == BATTLEGROUND_RL ); |
| 1705 | } |
| 1706 | |
| 1707 | bool BattleGroundMgr::IsBattleGroundType(uint32 bgTypeId) const |
| 1708 | { |
| 1709 | return !IsArenaType(bgTypeId); |
| 1710 | } |
| 1711 | |
| 1712 | uint32 BattleGroundMgr::BGQueueTypeId(uint32 bgTypeId, uint8 arenaType) const |
| 1713 | { |
| 1714 | switch(bgTypeId) |
| 1715 | { |
| 1716 | case BATTLEGROUND_WS: |
| 1717 | return BATTLEGROUND_QUEUE_WS; |
| 1718 | case BATTLEGROUND_AB: |
| 1719 | return BATTLEGROUND_QUEUE_AB; |
| 1720 | case BATTLEGROUND_AV: |
| 1721 | return BATTLEGROUND_QUEUE_AV; |
| 1722 | case BATTLEGROUND_EY: |
| 1723 | return BATTLEGROUND_QUEUE_EY; |
| 1724 | case BATTLEGROUND_AA: |
| 1725 | case BATTLEGROUND_NA: |
| 1726 | case BATTLEGROUND_RL: |
| 1727 | case BATTLEGROUND_BE: |
| 1728 | switch(arenaType) |
| 1729 | { |
| 1730 | case ARENA_TYPE_2v2: |
| 1731 | return BATTLEGROUND_QUEUE_2v2; |
| 1732 | case ARENA_TYPE_3v3: |
| 1733 | return BATTLEGROUND_QUEUE_3v3; |
| 1734 | case ARENA_TYPE_5v5: |
| 1735 | return BATTLEGROUND_QUEUE_5v5; |
| 1736 | default: |
| 1737 | return 0; |
| 1738 | } |
| 1739 | default: |
| 1740 | return 0; |
| 1741 | } |
| 1742 | } |
| 1743 | |
| 1744 | uint32 BattleGroundMgr::BGTemplateId(uint32 bgQueueTypeId) const |
| 1745 | { |
| 1746 | switch(bgQueueTypeId) |
| 1747 | { |
| 1748 | case BATTLEGROUND_QUEUE_WS: |
| 1749 | return BATTLEGROUND_WS; |
| 1750 | case BATTLEGROUND_QUEUE_AB: |
| 1751 | return BATTLEGROUND_AB; |
| 1752 | case BATTLEGROUND_QUEUE_AV: |
| 1753 | return BATTLEGROUND_AV; |
| 1754 | case BATTLEGROUND_QUEUE_EY: |
| 1755 | return BATTLEGROUND_EY; |
| 1756 | case BATTLEGROUND_QUEUE_2v2: |
| 1757 | case BATTLEGROUND_QUEUE_3v3: |
| 1758 | case BATTLEGROUND_QUEUE_5v5: |
| 1759 | return BATTLEGROUND_AA; |
| 1760 | default: |
| 1761 | return 0; |
| 1762 | } |
| 1763 | } |
| 1764 | |
| 1765 | uint8 BattleGroundMgr::BGArenaType(uint32 bgQueueTypeId) const |
| 1766 | { |
| 1767 | switch(bgQueueTypeId) |
| 1768 | { |
| 1769 | case BATTLEGROUND_QUEUE_2v2: |
| 1770 | return ARENA_TYPE_2v2; |
| 1771 | case BATTLEGROUND_QUEUE_3v3: |
| 1772 | return ARENA_TYPE_3v3; |
| 1773 | case BATTLEGROUND_QUEUE_5v5: |
| 1774 | return ARENA_TYPE_5v5; |
| 1775 | default: |
| 1776 | return 0; |
| 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | void BattleGroundMgr::ToggleArenaTesting() |
| 1781 | { |
| 1782 | m_ArenaTesting = !m_ArenaTesting; |
| 1783 | sWorld.SendWorldText(LANG_ARENA_TESTING, m_ArenaTesting ? "on" : "off"); |
| 1784 | } |