1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #include "Common.h" |
---|
22 | #include "WorldPacket.h" |
---|
23 | #include "Opcodes.h" |
---|
24 | #include "Log.h" |
---|
25 | #include "Player.h" |
---|
26 | #include "ObjectMgr.h" |
---|
27 | #include "WorldSession.h" |
---|
28 | #include "MapManager.h" |
---|
29 | #include "ObjectAccessor.h" |
---|
30 | #include "Object.h" |
---|
31 | #include "Chat.h" |
---|
32 | #include "Language.h" |
---|
33 | #include "BattleGroundMgr.h" |
---|
34 | #include "BattleGroundWS.h" |
---|
35 | #include "BattleGround.h" |
---|
36 | #include "ArenaTeam.h" |
---|
37 | |
---|
38 | void WorldSession::HandleBattleGroundHelloOpcode( WorldPacket & recv_data ) |
---|
39 | { |
---|
40 | CHECK_PACKET_SIZE(recv_data, 8); |
---|
41 | |
---|
42 | uint64 guid; |
---|
43 | recv_data >> guid; |
---|
44 | sLog.outDebug( "WORLD: Recvd CMSG_BATTLEMASTER_HELLO Message from: " I64FMT, guid); |
---|
45 | |
---|
46 | Creature *unit = ObjectAccessor::GetCreature(*_player, guid); |
---|
47 | if(!unit) |
---|
48 | return; |
---|
49 | |
---|
50 | if(!unit->isBattleMaster()) // it's not battlemaster |
---|
51 | return; |
---|
52 | |
---|
53 | // Stop the npc if moving |
---|
54 | unit->StopMoving(); |
---|
55 | |
---|
56 | uint32 bgTypeId = objmgr.GetBattleMasterBG(unit->GetEntry()); |
---|
57 | |
---|
58 | if(!_player->GetBGAccessByLevel(bgTypeId)) |
---|
59 | { |
---|
60 | // temp, must be gossip message... |
---|
61 | SendNotification(LANG_YOUR_BG_LEVEL_REQ_ERROR); |
---|
62 | return; |
---|
63 | } |
---|
64 | |
---|
65 | SendBattlegGroundList(guid, bgTypeId); |
---|
66 | } |
---|
67 | |
---|
68 | void WorldSession::SendBattlegGroundList( uint64 guid, uint32 bgTypeId ) |
---|
69 | { |
---|
70 | WorldPacket data; |
---|
71 | sBattleGroundMgr.BuildBattleGroundListPacket(&data, guid, _player, bgTypeId); |
---|
72 | SendPacket( &data ); |
---|
73 | } |
---|
74 | |
---|
75 | void WorldSession::HandleBattleGroundJoinOpcode( WorldPacket & recv_data ) |
---|
76 | { |
---|
77 | CHECK_PACKET_SIZE(recv_data, 8+4+4+1); |
---|
78 | |
---|
79 | uint64 guid; |
---|
80 | uint32 bgTypeId; |
---|
81 | uint32 instanceId; |
---|
82 | uint8 joinAsGroup; |
---|
83 | Group * grp; |
---|
84 | |
---|
85 | recv_data >> guid; // battlemaster guid |
---|
86 | recv_data >> bgTypeId; // battleground type id (DBC id) |
---|
87 | recv_data >> instanceId; // instance id, 0 if First Available selected |
---|
88 | recv_data >> joinAsGroup; // join as group |
---|
89 | |
---|
90 | if(bgTypeId >= MAX_BATTLEGROUND_TYPES) |
---|
91 | { |
---|
92 | sLog.outError("Battleground: invalid bgtype received. possible cheater? player guid %u",_player->GetGUIDLow()); |
---|
93 | return; |
---|
94 | } |
---|
95 | |
---|
96 | sLog.outDebug( "WORLD: Recvd CMSG_BATTLEMASTER_JOIN Message from: " I64FMT, guid); |
---|
97 | |
---|
98 | // can do this, since it's battleground, not arena |
---|
99 | uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bgTypeId, 0); |
---|
100 | |
---|
101 | // ignore if we already in BG or BG queue |
---|
102 | if(_player->InBattleGround()) |
---|
103 | return; |
---|
104 | |
---|
105 | Creature *unit = ObjectAccessor::GetCreature(*_player, guid); |
---|
106 | if(!unit) |
---|
107 | return; |
---|
108 | |
---|
109 | if(!unit->isBattleMaster()) // it's not battlemaster |
---|
110 | return; |
---|
111 | |
---|
112 | // get bg instance or bg template if instance not found |
---|
113 | BattleGround * bg = 0; |
---|
114 | if(instanceId) |
---|
115 | BattleGround *bg = sBattleGroundMgr.GetBattleGround(instanceId); |
---|
116 | |
---|
117 | if(!bg && !(bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId))) |
---|
118 | { |
---|
119 | sLog.outError("Battleground: no available bg / template found"); |
---|
120 | return; |
---|
121 | } |
---|
122 | |
---|
123 | // check queueing conditions |
---|
124 | if(!joinAsGroup) |
---|
125 | { |
---|
126 | // check Deserter debuff |
---|
127 | if( !_player->CanJoinToBattleground() ) |
---|
128 | { |
---|
129 | WorldPacket data(SMSG_GROUP_JOINED_BATTLEGROUND, 4); |
---|
130 | data << (uint32) 0xFFFFFFFE; |
---|
131 | _player->GetSession()->SendPacket(&data); |
---|
132 | return; |
---|
133 | } |
---|
134 | // check if already in queue |
---|
135 | if (_player->GetBattleGroundQueueIndex(bgQueueTypeId) < PLAYER_MAX_BATTLEGROUND_QUEUES) |
---|
136 | //player is already in this queue |
---|
137 | return; |
---|
138 | // check if has free queue slots |
---|
139 | if(!_player->HasFreeBattleGroundQueueId()) |
---|
140 | return; |
---|
141 | } |
---|
142 | else |
---|
143 | { |
---|
144 | grp = _player->GetGroup(); |
---|
145 | // no group found, error |
---|
146 | if(!grp) |
---|
147 | return; |
---|
148 | uint32 err = grp->CanJoinBattleGroundQueue(bgTypeId, bgQueueTypeId, 0, bg->GetMaxPlayersPerTeam(), false, 0); |
---|
149 | switch(err) |
---|
150 | { |
---|
151 | // TODO: add error-based feedback to players in all cases |
---|
152 | case BG_JOIN_ERR_GROUP_TOO_MANY: |
---|
153 | { |
---|
154 | WorldPacket data; |
---|
155 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_BG_GROUP_TOO_LARGE), NULL); |
---|
156 | SendPacket(&data); |
---|
157 | } |
---|
158 | return; |
---|
159 | break; |
---|
160 | case BG_JOIN_ERR_OFFLINE_MEMBER: |
---|
161 | { |
---|
162 | WorldPacket data; |
---|
163 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_BG_GROUP_OFFLINE_MEMBER), NULL); |
---|
164 | SendPacket(&data); |
---|
165 | } |
---|
166 | return; |
---|
167 | break; |
---|
168 | case BG_JOIN_ERR_MIXED_FACTION: |
---|
169 | { |
---|
170 | WorldPacket data; |
---|
171 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_BG_GROUP_MIXED_FACTION), NULL); |
---|
172 | SendPacket(&data); |
---|
173 | } |
---|
174 | return; |
---|
175 | break; |
---|
176 | case BG_JOIN_ERR_MIXED_LEVELS: |
---|
177 | { |
---|
178 | WorldPacket data; |
---|
179 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_BG_GROUP_MIXED_LEVELS), NULL); |
---|
180 | SendPacket(&data); |
---|
181 | } |
---|
182 | return; |
---|
183 | break; |
---|
184 | case BG_JOIN_ERR_GROUP_MEMBER_ALREADY_IN_QUEUE: |
---|
185 | { |
---|
186 | WorldPacket data; |
---|
187 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_BG_GROUP_MEMBER_ALREADY_IN_QUEUE), NULL); |
---|
188 | SendPacket(&data); |
---|
189 | } |
---|
190 | return; |
---|
191 | break; |
---|
192 | case BG_JOIN_ERR_GROUP_DESERTER: |
---|
193 | { |
---|
194 | WorldPacket data; |
---|
195 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_BG_GROUP_MEMBER_DESERTER), NULL); |
---|
196 | SendPacket(&data); |
---|
197 | } |
---|
198 | return; |
---|
199 | break; |
---|
200 | case BG_JOIN_ERR_ALL_QUEUES_USED: |
---|
201 | { |
---|
202 | WorldPacket data; |
---|
203 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_BG_GROUP_MEMBER_NO_FREE_QUEUE_SLOTS), NULL); |
---|
204 | SendPacket(&data); |
---|
205 | } |
---|
206 | return; |
---|
207 | break; |
---|
208 | // all ok, can join |
---|
209 | case BG_JOIN_ERR_OK: |
---|
210 | break; |
---|
211 | // these aren't possible outcomes in bgs |
---|
212 | case BG_JOIN_ERR_GROUP_NOT_ENOUGH: |
---|
213 | case BG_JOIN_ERR_MIXED_ARENATEAM: |
---|
214 | return; |
---|
215 | break; |
---|
216 | // not the above? shouldn't happen, don't let join |
---|
217 | default: |
---|
218 | return; |
---|
219 | break; |
---|
220 | }; |
---|
221 | } |
---|
222 | |
---|
223 | // if we're here, then the conditions to join a bg are met. We can proceed in joining. |
---|
224 | |
---|
225 | // _player->GetGroup() was already checked, grp is already initialized |
---|
226 | if(joinAsGroup /* && _player->GetGroup()*/) |
---|
227 | { |
---|
228 | sLog.outDebug("Battleground: the following players are joining as group:"); |
---|
229 | GroupQueueInfo * ginfo = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddGroup(_player, bgTypeId, 0, false, 0); |
---|
230 | for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next()) |
---|
231 | { |
---|
232 | Player *member = itr->getSource(); |
---|
233 | if(!member) continue; // this should never happen |
---|
234 | |
---|
235 | uint32 queueSlot = member->AddBattleGroundQueueId(bgQueueTypeId); // add to queue |
---|
236 | |
---|
237 | // store entry point coords (same as leader entry point) |
---|
238 | member->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation()); |
---|
239 | |
---|
240 | WorldPacket data; |
---|
241 | // send status packet (in queue) |
---|
242 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, member->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0); |
---|
243 | member->GetSession()->SendPacket(&data); |
---|
244 | sBattleGroundMgr.BuildGroupJoinedBattlegroundPacket(&data, bgTypeId); |
---|
245 | member->GetSession()->SendPacket(&data); |
---|
246 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddPlayer(member, ginfo); |
---|
247 | sLog.outDebug("Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,member->GetGUIDLow(), member->GetName()); |
---|
248 | } |
---|
249 | sLog.outDebug("Battleground: group end"); |
---|
250 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, _player->GetBattleGroundQueueIdFromLevel()); |
---|
251 | } |
---|
252 | else |
---|
253 | { |
---|
254 | // already checked if queueSlot is valid, now just get it |
---|
255 | uint32 queueSlot = _player->AddBattleGroundQueueId(bgQueueTypeId); |
---|
256 | // store entry point coords |
---|
257 | _player->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation()); |
---|
258 | |
---|
259 | WorldPacket data; |
---|
260 | // send status packet (in queue) |
---|
261 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0); |
---|
262 | SendPacket(&data); |
---|
263 | |
---|
264 | GroupQueueInfo * ginfo = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddGroup(_player, bgTypeId, 0, false, 0); |
---|
265 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddPlayer(_player, ginfo); |
---|
266 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, _player->GetBattleGroundQueueIdFromLevel()); |
---|
267 | sLog.outDebug("Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,_player->GetGUIDLow(), _player->GetName()); |
---|
268 | } |
---|
269 | } |
---|
270 | |
---|
271 | void WorldSession::HandleBattleGroundPlayerPositionsOpcode( WorldPacket & /*recv_data*/ ) |
---|
272 | { |
---|
273 | // empty opcode |
---|
274 | sLog.outDebug("WORLD: Recvd MSG_BATTLEGROUND_PLAYER_POSITIONS Message"); |
---|
275 | |
---|
276 | BattleGround *bg = _player->GetBattleGround(); |
---|
277 | if(!bg) // can't be received if player not in battleground |
---|
278 | return; |
---|
279 | |
---|
280 | if(bg->GetTypeID() == BATTLEGROUND_WS) |
---|
281 | { |
---|
282 | uint32 count1 = 0; |
---|
283 | uint32 count2 = 0; |
---|
284 | |
---|
285 | Player *ap = objmgr.GetPlayer(((BattleGroundWS*)bg)->GetAllianceFlagPickerGUID()); |
---|
286 | if(ap) ++count2; |
---|
287 | |
---|
288 | Player *hp = objmgr.GetPlayer(((BattleGroundWS*)bg)->GetHordeFlagPickerGUID()); |
---|
289 | if(hp) ++count2; |
---|
290 | |
---|
291 | WorldPacket data(MSG_BATTLEGROUND_PLAYER_POSITIONS, (4+4+16*count1+16*count2)); |
---|
292 | data << count1; // alliance flag holders count |
---|
293 | /*for(uint8 i = 0; i < count1; i++) |
---|
294 | { |
---|
295 | data << uint64(0); // guid |
---|
296 | data << (float)0; // x |
---|
297 | data << (float)0; // y |
---|
298 | }*/ |
---|
299 | data << count2; // horde flag holders count |
---|
300 | if(ap) |
---|
301 | { |
---|
302 | data << (uint64)ap->GetGUID(); |
---|
303 | data << (float)ap->GetPositionX(); |
---|
304 | data << (float)ap->GetPositionY(); |
---|
305 | } |
---|
306 | if(hp) |
---|
307 | { |
---|
308 | data << (uint64)hp->GetGUID(); |
---|
309 | data << (float)hp->GetPositionX(); |
---|
310 | data << (float)hp->GetPositionY(); |
---|
311 | } |
---|
312 | |
---|
313 | SendPacket(&data); |
---|
314 | } |
---|
315 | } |
---|
316 | |
---|
317 | void WorldSession::HandleBattleGroundPVPlogdataOpcode( WorldPacket & /*recv_data*/ ) |
---|
318 | { |
---|
319 | sLog.outDebug( "WORLD: Recvd MSG_PVP_LOG_DATA Message"); |
---|
320 | |
---|
321 | BattleGround *bg = _player->GetBattleGround(); |
---|
322 | if(!bg) |
---|
323 | return; |
---|
324 | |
---|
325 | WorldPacket data; |
---|
326 | sBattleGroundMgr.BuildPvpLogDataPacket(&data, bg); |
---|
327 | SendPacket(&data); |
---|
328 | |
---|
329 | sLog.outDebug( "WORLD: Sent MSG_PVP_LOG_DATA Message"); |
---|
330 | } |
---|
331 | |
---|
332 | void WorldSession::HandleBattleGroundListOpcode( WorldPacket &recv_data ) |
---|
333 | { |
---|
334 | CHECK_PACKET_SIZE(recv_data, 4); |
---|
335 | |
---|
336 | sLog.outDebug( "WORLD: Recvd CMSG_BATTLEFIELD_LIST Message"); |
---|
337 | |
---|
338 | uint32 bgTypeId; |
---|
339 | recv_data >> bgTypeId; // id from DBC |
---|
340 | |
---|
341 | if(bgTypeId >= MAX_BATTLEGROUND_TYPES) |
---|
342 | { |
---|
343 | sLog.outError("Battleground: invalid bgtype received."); |
---|
344 | return; |
---|
345 | } |
---|
346 | |
---|
347 | BattlemasterListEntry const* bl = sBattlemasterListStore.LookupEntry(bgTypeId); |
---|
348 | |
---|
349 | if(!bl) |
---|
350 | return; |
---|
351 | |
---|
352 | WorldPacket data; |
---|
353 | sBattleGroundMgr.BuildBattleGroundListPacket(&data, _player->GetGUID(), _player, bgTypeId); |
---|
354 | SendPacket( &data ); |
---|
355 | } |
---|
356 | |
---|
357 | void WorldSession::HandleBattleGroundPlayerPortOpcode( WorldPacket &recv_data ) |
---|
358 | { |
---|
359 | CHECK_PACKET_SIZE(recv_data, 1+1+4+2+1); |
---|
360 | |
---|
361 | sLog.outDebug( "WORLD: Recvd CMSG_BATTLEFIELD_PORT Message"); |
---|
362 | |
---|
363 | uint8 type; // arenatype if arena |
---|
364 | uint8 unk2; // unk, can be 0x0 (may be if was invited?) and 0x1 |
---|
365 | uint32 instanceId; |
---|
366 | uint32 bgTypeId; // type id from dbc |
---|
367 | uint16 unk; // 0x1F90 constant? |
---|
368 | uint8 action; // enter battle 0x1, leave queue 0x0 |
---|
369 | |
---|
370 | recv_data >> type >> unk2 >> bgTypeId >> unk >> action; |
---|
371 | |
---|
372 | if(bgTypeId >= MAX_BATTLEGROUND_TYPES) |
---|
373 | { |
---|
374 | sLog.outError("Battleground: invalid bgtype received."); |
---|
375 | // update battleground slots for the player to fix his UI and sent data. |
---|
376 | // this is a HACK, I don't know why the client starts sending invalid packets in the first place. |
---|
377 | // it usually happens with extremely high latency (if debugging / stepping in the code for example) |
---|
378 | if(_player->InBattleGroundQueue()) |
---|
379 | { |
---|
380 | // update all queues, send invitation info if player is invited, queue info if queued |
---|
381 | for (uint32 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++) |
---|
382 | { |
---|
383 | uint32 queue_id = _player->GetBattleGroundQueueId(i); |
---|
384 | if(!queue_id) |
---|
385 | continue; |
---|
386 | BattleGroundQueue::QueuedPlayersMap::iterator itrPlayerStatus = sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID()); |
---|
387 | // if the player is not in queue, contine |
---|
388 | if(itrPlayerStatus == sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end()) |
---|
389 | continue; |
---|
390 | |
---|
391 | // no group information, this should never happen |
---|
392 | if(!itrPlayerStatus->second.GroupInfo) |
---|
393 | continue; |
---|
394 | |
---|
395 | BattleGround * bg = NULL; |
---|
396 | |
---|
397 | // get possibly needed data from groupinfo |
---|
398 | bgTypeId = itrPlayerStatus->second.GroupInfo->BgTypeId; |
---|
399 | uint8 arenatype = itrPlayerStatus->second.GroupInfo->ArenaType; |
---|
400 | uint8 israted = itrPlayerStatus->second.GroupInfo->IsRated; |
---|
401 | uint8 status = 0; |
---|
402 | |
---|
403 | |
---|
404 | if(!itrPlayerStatus->second.GroupInfo->IsInvitedToBGInstanceGUID) |
---|
405 | { |
---|
406 | // not invited to bg, get template |
---|
407 | bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId); |
---|
408 | status = STATUS_WAIT_QUEUE; |
---|
409 | } |
---|
410 | else |
---|
411 | { |
---|
412 | // get the bg we're invited to |
---|
413 | BattleGround * bg = sBattleGroundMgr.GetBattleGround(itrPlayerStatus->second.GroupInfo->IsInvitedToBGInstanceGUID); |
---|
414 | status = STATUS_WAIT_JOIN; |
---|
415 | } |
---|
416 | |
---|
417 | // if bg not found, then continue |
---|
418 | if(!bg) |
---|
419 | continue; |
---|
420 | |
---|
421 | // don't invite if already in the instance |
---|
422 | if(_player->InBattleGround() && _player->GetBattleGround() && _player->GetBattleGround()->GetInstanceID() == bg->GetInstanceID()) |
---|
423 | continue; |
---|
424 | |
---|
425 | // re - invite player with proper data |
---|
426 | WorldPacket data; |
---|
427 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, itrPlayerStatus->second.GroupInfo->Team?itrPlayerStatus->second.GroupInfo->Team:_player->GetTeam(), i, status, INVITE_ACCEPT_WAIT_TIME, 0, arenatype, israted); |
---|
428 | SendPacket(&data); |
---|
429 | } |
---|
430 | } |
---|
431 | return; |
---|
432 | } |
---|
433 | |
---|
434 | uint32 bgQueueTypeId = 0; |
---|
435 | // get the bg what we were invited to |
---|
436 | BattleGroundQueue::QueuedPlayersMap::iterator itrPlayerStatus; |
---|
437 | bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bgTypeId,type); |
---|
438 | itrPlayerStatus = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID()); |
---|
439 | |
---|
440 | if(itrPlayerStatus == sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end()) |
---|
441 | { |
---|
442 | sLog.outError("Battleground: itrplayerstatus not found."); |
---|
443 | return; |
---|
444 | } |
---|
445 | instanceId = itrPlayerStatus->second.GroupInfo->IsInvitedToBGInstanceGUID; |
---|
446 | |
---|
447 | // if action == 1, then instanceId is _required_ |
---|
448 | if(!instanceId && action == 1) |
---|
449 | { |
---|
450 | sLog.outError("Battleground: instance not found."); |
---|
451 | return; |
---|
452 | } |
---|
453 | |
---|
454 | BattleGround *bg = sBattleGroundMgr.GetBattleGround(instanceId); |
---|
455 | |
---|
456 | // bg template might and must be used in case of leaving queue, when instance is not created yet |
---|
457 | if(!bg && action == 0) |
---|
458 | bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId); |
---|
459 | |
---|
460 | if(!bg) |
---|
461 | { |
---|
462 | sLog.outError("Battleground: bg not found."); |
---|
463 | return; |
---|
464 | } |
---|
465 | |
---|
466 | bgTypeId = bg->GetTypeID(); |
---|
467 | |
---|
468 | if(_player->InBattleGroundQueue()) |
---|
469 | { |
---|
470 | uint32 queueSlot = 0; |
---|
471 | uint32 team = 0; |
---|
472 | uint32 arenatype = 0; |
---|
473 | uint32 israted = 0; |
---|
474 | uint32 rating = 0; |
---|
475 | // get the team info from the queue |
---|
476 | BattleGroundQueue::QueuedPlayersMap::iterator pitr = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID()); |
---|
477 | if(pitr !=sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end() |
---|
478 | && pitr->second.GroupInfo ) |
---|
479 | { |
---|
480 | team = pitr->second.GroupInfo->Team; |
---|
481 | arenatype = pitr->second.GroupInfo->ArenaType; |
---|
482 | israted = pitr->second.GroupInfo->IsRated; |
---|
483 | rating = pitr->second.GroupInfo->ArenaTeamRating; |
---|
484 | } |
---|
485 | else |
---|
486 | { |
---|
487 | sLog.outError("Battleground: Invalid player queue info!"); |
---|
488 | return; |
---|
489 | } |
---|
490 | WorldPacket data; |
---|
491 | switch(action) |
---|
492 | { |
---|
493 | case 1: // port to battleground |
---|
494 | if(!_player->IsInvitedForBattleGroundQueueType(bgQueueTypeId)) |
---|
495 | return; // cheating? |
---|
496 | // resurrect the player |
---|
497 | if(!_player->isAlive()) |
---|
498 | { |
---|
499 | _player->ResurrectPlayer(1.0f,false); |
---|
500 | _player->SpawnCorpseBones(); |
---|
501 | } |
---|
502 | // stop taxi flight at port |
---|
503 | if(_player->isInFlight()) |
---|
504 | { |
---|
505 | _player->GetMotionMaster()->MovementExpired(); |
---|
506 | _player->m_taxi.ClearTaxiDestinations(); |
---|
507 | } |
---|
508 | _player->RemoveFromGroup(); |
---|
509 | queueSlot = _player->GetBattleGroundQueueIndex(bgQueueTypeId); |
---|
510 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_IN_PROGRESS, 0, bg->GetStartTime()); |
---|
511 | _player->GetSession()->SendPacket(&data); |
---|
512 | // remove battleground queue status from BGmgr |
---|
513 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].RemovePlayer(_player->GetGUID(), false); |
---|
514 | // this is still needed here if battleground "jumping" shouldn't add deserter debuff |
---|
515 | // also this required to prevent stuck at old battleground after SetBattleGroundId set to new |
---|
516 | if( BattleGround *currentBg = _player->GetBattleGround() ) |
---|
517 | currentBg->RemovePlayerAtLeave(_player->GetGUID(), false, true); |
---|
518 | |
---|
519 | // set the destination instance id |
---|
520 | _player->SetBattleGroundId(bg->GetInstanceID()); |
---|
521 | // set the destination team |
---|
522 | _player->SetBGTeam(team); |
---|
523 | // bg->HandleBeforeTeleportToBattleGround(_player); |
---|
524 | sBattleGroundMgr.SendToBattleGround(_player, instanceId); |
---|
525 | // add only in HandleMoveWorldPortAck() |
---|
526 | // bg->AddPlayer(_player,team); |
---|
527 | sLog.outDebug("Battleground: player %s (%u) joined battle for bg %u, bgtype %u, queue type %u.",_player->GetName(),_player->GetGUIDLow(),bg->GetInstanceID(),bg->GetTypeID(),bgQueueTypeId); |
---|
528 | break; |
---|
529 | case 0: // leave queue |
---|
530 | queueSlot = _player->GetBattleGroundQueueIndex(bgQueueTypeId); |
---|
531 | _player->RemoveBattleGroundQueueId(bgQueueTypeId); // must be called this way, because if you move this call to queue->removeplayer, it causes bugs |
---|
532 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_NONE, 0, 0); |
---|
533 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].RemovePlayer(_player->GetGUID(), true); |
---|
534 | // player left queue, we should update it, maybe now his group fits in |
---|
535 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId,_player->GetBattleGroundQueueIdFromLevel(),arenatype,israted,rating); |
---|
536 | SendPacket(&data); |
---|
537 | sLog.outDebug("Battleground: player %s (%u) left queue for bgtype %u, queue type %u.",_player->GetName(),_player->GetGUIDLow(),bg->GetTypeID(),bgQueueTypeId); |
---|
538 | break; |
---|
539 | default: |
---|
540 | sLog.outError("Battleground port: unknown action %u", action); |
---|
541 | break; |
---|
542 | } |
---|
543 | } |
---|
544 | } |
---|
545 | |
---|
546 | void WorldSession::HandleBattleGroundLeaveOpcode( WorldPacket & /*recv_data*/ ) |
---|
547 | { |
---|
548 | //CHECK_PACKET_SIZE(recv_data, 1+1+4+2); |
---|
549 | |
---|
550 | sLog.outDebug( "WORLD: Recvd CMSG_LEAVE_BATTLEFIELD Message"); |
---|
551 | |
---|
552 | //uint8 unk1, unk2; |
---|
553 | //uint32 bgTypeId; // id from DBC |
---|
554 | //uint16 unk3; |
---|
555 | |
---|
556 | //recv_data >> unk1 >> unk2 >> bgTypeId >> unk3; - no used currently |
---|
557 | |
---|
558 | //if(bgTypeId >= MAX_BATTLEGROUND_TYPES) // cheating? but not important in this case |
---|
559 | // return; |
---|
560 | |
---|
561 | // not allow leave battleground in combat |
---|
562 | if(_player->isInCombat()) |
---|
563 | if(BattleGround* bg = _player->GetBattleGround()) |
---|
564 | if(bg->GetStatus() != STATUS_WAIT_LEAVE) |
---|
565 | return; |
---|
566 | |
---|
567 | _player->LeaveBattleground(); |
---|
568 | } |
---|
569 | |
---|
570 | void WorldSession::HandleBattlefieldStatusOpcode( WorldPacket & /*recv_data*/ ) |
---|
571 | { |
---|
572 | // empty opcode |
---|
573 | sLog.outDebug( "WORLD: Battleground status" ); |
---|
574 | |
---|
575 | WorldPacket data; |
---|
576 | |
---|
577 | // TODO: we must put player back to battleground in case disconnect (< 5 minutes offline time) or teleport player on login(!) from battleground map to entry point |
---|
578 | if(_player->InBattleGround()) |
---|
579 | { |
---|
580 | BattleGround *bg = _player->GetBattleGround(); |
---|
581 | if(bg) |
---|
582 | { |
---|
583 | uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bg->GetTypeID(), bg->GetArenaType()); |
---|
584 | uint32 queueSlot = _player->GetBattleGroundQueueIndex(bgQueueTypeId); |
---|
585 | if((bg->GetStatus() <= STATUS_IN_PROGRESS)) |
---|
586 | { |
---|
587 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_IN_PROGRESS, 0, bg->GetStartTime()); |
---|
588 | SendPacket(&data); |
---|
589 | } |
---|
590 | for (uint32 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++) |
---|
591 | { |
---|
592 | uint32 queue_id = _player->GetBattleGroundQueueId(i); // battlegroundqueueid stores the type id, not the instance id, so this is definitely wrong |
---|
593 | uint8 arenatype = sBattleGroundMgr.BGArenaType(queue_id); |
---|
594 | uint8 isRated = 0; |
---|
595 | if (i == queueSlot || !queue_id) // we need to get the instance ids |
---|
596 | continue; |
---|
597 | BattleGroundQueue::QueuedPlayersMap::iterator itrPlayerStatus = sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID()); |
---|
598 | if(itrPlayerStatus == sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end()) |
---|
599 | continue; |
---|
600 | if(itrPlayerStatus->second.GroupInfo) |
---|
601 | { |
---|
602 | arenatype = itrPlayerStatus->second.GroupInfo->ArenaType; |
---|
603 | isRated = itrPlayerStatus->second.GroupInfo->IsRated; |
---|
604 | } |
---|
605 | BattleGround *bg2 = sBattleGroundMgr.GetBattleGroundTemplate(sBattleGroundMgr.BGTemplateId(queue_id)); // try this |
---|
606 | if(bg2) |
---|
607 | { |
---|
608 | //in this call is small bug, this call should be filled by player's waiting time in queue |
---|
609 | //this call nulls all timers for client : |
---|
610 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg2, _player->GetTeam(), i, STATUS_WAIT_QUEUE, 0, 0,arenatype,isRated); |
---|
611 | SendPacket(&data); |
---|
612 | } |
---|
613 | } |
---|
614 | } |
---|
615 | } |
---|
616 | else |
---|
617 | { |
---|
618 | // we should update all queues? .. i'm not sure if this code is correct |
---|
619 | for (uint32 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++) |
---|
620 | { |
---|
621 | uint32 queue_id = _player->GetBattleGroundQueueId(i); |
---|
622 | if(!queue_id) |
---|
623 | continue; |
---|
624 | uint32 bgTypeId = sBattleGroundMgr.BGTemplateId(queue_id); |
---|
625 | uint8 arenatype = sBattleGroundMgr.BGArenaType(queue_id); |
---|
626 | uint8 isRated = 0; |
---|
627 | BattleGround *bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId); |
---|
628 | BattleGroundQueue::QueuedPlayersMap::iterator itrPlayerStatus = sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID()); |
---|
629 | if(itrPlayerStatus == sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end()) |
---|
630 | continue; |
---|
631 | if(itrPlayerStatus->second.GroupInfo) |
---|
632 | { |
---|
633 | arenatype = itrPlayerStatus->second.GroupInfo->ArenaType; |
---|
634 | isRated = itrPlayerStatus->second.GroupInfo->IsRated; |
---|
635 | } |
---|
636 | if(bg && queue_id) |
---|
637 | { |
---|
638 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), i, STATUS_WAIT_QUEUE, 0, 0, arenatype, isRated); |
---|
639 | SendPacket(&data); |
---|
640 | } |
---|
641 | } |
---|
642 | } |
---|
643 | /* else // not sure if it needed... |
---|
644 | { |
---|
645 | for (uint32 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++) |
---|
646 | { |
---|
647 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, NULL, _player->GetTeam(),i , STATUS_NONE, 0, 0); |
---|
648 | SendPacket(&data); |
---|
649 | } |
---|
650 | }*/ |
---|
651 | } |
---|
652 | |
---|
653 | void WorldSession::HandleAreaSpiritHealerQueryOpcode( WorldPacket & recv_data ) |
---|
654 | { |
---|
655 | sLog.outDebug("WORLD: CMSG_AREA_SPIRIT_HEALER_QUERY"); |
---|
656 | |
---|
657 | CHECK_PACKET_SIZE(recv_data, 8); |
---|
658 | |
---|
659 | BattleGround *bg = _player->GetBattleGround(); |
---|
660 | if(!bg) |
---|
661 | return; |
---|
662 | |
---|
663 | uint64 guid; |
---|
664 | recv_data >> guid; |
---|
665 | |
---|
666 | Creature *unit = ObjectAccessor::GetCreature(*_player, guid); |
---|
667 | if(!unit) |
---|
668 | return; |
---|
669 | |
---|
670 | if(!unit->isSpiritService()) // it's not spirit service |
---|
671 | return; |
---|
672 | |
---|
673 | sBattleGroundMgr.SendAreaSpiritHealerQueryOpcode(_player, bg, guid); |
---|
674 | } |
---|
675 | |
---|
676 | void WorldSession::HandleAreaSpiritHealerQueueOpcode( WorldPacket & recv_data ) |
---|
677 | { |
---|
678 | sLog.outDebug("WORLD: CMSG_AREA_SPIRIT_HEALER_QUEUE"); |
---|
679 | |
---|
680 | CHECK_PACKET_SIZE(recv_data, 8); |
---|
681 | |
---|
682 | BattleGround *bg = _player->GetBattleGround(); |
---|
683 | if(!bg) |
---|
684 | return; |
---|
685 | |
---|
686 | uint64 guid; |
---|
687 | recv_data >> guid; |
---|
688 | |
---|
689 | Creature *unit = ObjectAccessor::GetCreature(*_player, guid); |
---|
690 | if(!unit) |
---|
691 | return; |
---|
692 | |
---|
693 | if(!unit->isSpiritService()) // it's not spirit service |
---|
694 | return; |
---|
695 | |
---|
696 | bg->AddPlayerToResurrectQueue(guid, _player->GetGUID()); |
---|
697 | } |
---|
698 | |
---|
699 | void WorldSession::HandleBattleGroundArenaJoin( WorldPacket & recv_data ) |
---|
700 | { |
---|
701 | CHECK_PACKET_SIZE(recv_data, 8+1+1+1); |
---|
702 | |
---|
703 | sLog.outDebug("WORLD: CMSG_BATTLEMASTER_JOIN_ARENA"); |
---|
704 | recv_data.hexlike(); |
---|
705 | |
---|
706 | // ignore if we already in BG or BG queue |
---|
707 | if(_player->InBattleGround()) |
---|
708 | return; |
---|
709 | |
---|
710 | uint64 guid; // arena Battlemaster guid |
---|
711 | uint8 type; // 2v2, 3v3 or 5v5 |
---|
712 | uint8 asGroup; // asGroup |
---|
713 | uint8 isRated; // isRated |
---|
714 | Group * grp; |
---|
715 | |
---|
716 | recv_data >> guid >> type >> asGroup >> isRated; |
---|
717 | |
---|
718 | Creature *unit = ObjectAccessor::GetCreature(*_player, guid); |
---|
719 | if(!unit) |
---|
720 | return; |
---|
721 | |
---|
722 | if(!unit->isBattleMaster()) // it's not battle master |
---|
723 | return; |
---|
724 | |
---|
725 | uint8 arenatype = 0; |
---|
726 | uint32 arenaRating = 0; |
---|
727 | |
---|
728 | switch(type) |
---|
729 | { |
---|
730 | case 0: |
---|
731 | arenatype = ARENA_TYPE_2v2; |
---|
732 | break; |
---|
733 | case 1: |
---|
734 | arenatype = ARENA_TYPE_3v3; |
---|
735 | break; |
---|
736 | case 2: |
---|
737 | arenatype = ARENA_TYPE_5v5; |
---|
738 | break; |
---|
739 | default: |
---|
740 | sLog.outError("Unknown arena type %u at HandleBattleGroundArenaJoin()", type); |
---|
741 | return; |
---|
742 | } |
---|
743 | |
---|
744 | //check existance |
---|
745 | BattleGround* bg = NULL; |
---|
746 | if( !(bg = sBattleGroundMgr.GetBattleGroundTemplate(BATTLEGROUND_AA)) ) |
---|
747 | { |
---|
748 | sLog.outError("Battleground: template bg (all arenas) not found"); |
---|
749 | return; |
---|
750 | } |
---|
751 | |
---|
752 | uint8 bgTypeId = bg->GetTypeID(); |
---|
753 | uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bgTypeId, arenatype); |
---|
754 | |
---|
755 | // check queueing conditions |
---|
756 | if(!asGroup) |
---|
757 | { |
---|
758 | // check if already in queue |
---|
759 | if (_player->GetBattleGroundQueueIndex(bgQueueTypeId) < PLAYER_MAX_BATTLEGROUND_QUEUES) |
---|
760 | //player is already in this queue |
---|
761 | return; |
---|
762 | // check if has free queue slots |
---|
763 | if(!_player->HasFreeBattleGroundQueueId()) |
---|
764 | return; |
---|
765 | } |
---|
766 | else |
---|
767 | { |
---|
768 | grp = _player->GetGroup(); |
---|
769 | // no group found, error |
---|
770 | if(!grp) |
---|
771 | return; |
---|
772 | uint32 err = grp->CanJoinBattleGroundQueue(bgTypeId, bgQueueTypeId, arenatype, arenatype, (bool)isRated, type); |
---|
773 | switch(err) |
---|
774 | { |
---|
775 | // TODO: add error-based feedback to players in all cases |
---|
776 | case BG_JOIN_ERR_GROUP_TOO_MANY: |
---|
777 | { |
---|
778 | WorldPacket data; |
---|
779 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_ARENA_GROUP_TOO_LARGE), NULL); |
---|
780 | SendPacket(&data); |
---|
781 | } |
---|
782 | return; |
---|
783 | break; |
---|
784 | case BG_JOIN_ERR_GROUP_NOT_ENOUGH: |
---|
785 | { |
---|
786 | WorldPacket data; |
---|
787 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_ARENA_NOT_ENOUGH_PLAYERS), NULL); |
---|
788 | SendPacket(&data); |
---|
789 | } |
---|
790 | return; |
---|
791 | break; |
---|
792 | case BG_JOIN_ERR_MIXED_ARENATEAM: |
---|
793 | { |
---|
794 | WorldPacket data; |
---|
795 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_ARENA_YOUR_TEAM_ONLY), NULL); |
---|
796 | SendPacket(&data); |
---|
797 | } |
---|
798 | return; |
---|
799 | break; |
---|
800 | case BG_JOIN_ERR_OFFLINE_MEMBER: |
---|
801 | { |
---|
802 | WorldPacket data; |
---|
803 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_BG_GROUP_OFFLINE_MEMBER), NULL); |
---|
804 | SendPacket(&data); |
---|
805 | } |
---|
806 | return; |
---|
807 | break; |
---|
808 | case BG_JOIN_ERR_MIXED_FACTION: |
---|
809 | { |
---|
810 | WorldPacket data; |
---|
811 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_BG_GROUP_MIXED_FACTION), NULL); |
---|
812 | SendPacket(&data); |
---|
813 | } |
---|
814 | return; |
---|
815 | break; |
---|
816 | case BG_JOIN_ERR_MIXED_LEVELS: |
---|
817 | { |
---|
818 | WorldPacket data; |
---|
819 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_BG_GROUP_MIXED_LEVELS), NULL); |
---|
820 | SendPacket(&data); |
---|
821 | } |
---|
822 | return; |
---|
823 | break; |
---|
824 | case BG_JOIN_ERR_GROUP_MEMBER_ALREADY_IN_QUEUE: |
---|
825 | { |
---|
826 | WorldPacket data; |
---|
827 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_BG_GROUP_MEMBER_ALREADY_IN_QUEUE), NULL); |
---|
828 | SendPacket(&data); |
---|
829 | } |
---|
830 | return; |
---|
831 | break; |
---|
832 | case BG_JOIN_ERR_GROUP_DESERTER: |
---|
833 | { |
---|
834 | WorldPacket data; |
---|
835 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_BG_GROUP_MEMBER_DESERTER), NULL); |
---|
836 | SendPacket(&data); |
---|
837 | } |
---|
838 | return; |
---|
839 | break; |
---|
840 | case BG_JOIN_ERR_ALL_QUEUES_USED: |
---|
841 | { |
---|
842 | WorldPacket data; |
---|
843 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetTrinityString(LANG_BG_GROUP_MEMBER_NO_FREE_QUEUE_SLOTS), NULL); |
---|
844 | SendPacket(&data); |
---|
845 | } |
---|
846 | return; |
---|
847 | break; |
---|
848 | // all ok, can join |
---|
849 | case BG_JOIN_ERR_OK: |
---|
850 | break; |
---|
851 | // not the above? shouldn't happen, don't let join |
---|
852 | default: |
---|
853 | return; |
---|
854 | break; |
---|
855 | }; |
---|
856 | } |
---|
857 | |
---|
858 | uint32 ateamId = 0; |
---|
859 | |
---|
860 | if(isRated) |
---|
861 | { |
---|
862 | ateamId = _player->GetArenaTeamId(type); |
---|
863 | // check real arenateam existence only here (if it was moved to group->CanJoin .. () then we would ahve to get it twice) |
---|
864 | ArenaTeam * at = objmgr.GetArenaTeamById(ateamId); |
---|
865 | if(!at) |
---|
866 | { |
---|
867 | _player->GetSession()->SendNotInArenaTeamPacket(arenatype); |
---|
868 | return; |
---|
869 | } |
---|
870 | // get the team rating for queueing |
---|
871 | arenaRating = at->GetRating(); |
---|
872 | // the arenateam id must match for everyone in the group |
---|
873 | // get the personal ratings for queueing |
---|
874 | uint32 avg_pers_rating = 0; |
---|
875 | for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next()) |
---|
876 | { |
---|
877 | Player *member = itr->getSource(); |
---|
878 | |
---|
879 | // calc avg personal rating |
---|
880 | avg_pers_rating += member->GetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (type*6) + 5); |
---|
881 | } |
---|
882 | |
---|
883 | if( arenatype ) |
---|
884 | avg_pers_rating /= arenatype; |
---|
885 | |
---|
886 | // if avg personal rating is more than 150 points below the teams rating, the team will be queued against an opponent matching or similar to the average personal rating |
---|
887 | if(avg_pers_rating + 150 < arenaRating) |
---|
888 | arenaRating = avg_pers_rating; |
---|
889 | } |
---|
890 | |
---|
891 | if(asGroup) |
---|
892 | { |
---|
893 | GroupQueueInfo * ginfo = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddGroup(_player, bgTypeId, arenatype, isRated, arenaRating, ateamId); |
---|
894 | sLog.outDebug("Battleground: arena join as group start"); |
---|
895 | if(isRated) |
---|
896 | sLog.outDebug("Battleground: arena team id %u, leader %s queued with rating %u for type %u",_player->GetArenaTeamId(type),_player->GetName(),arenaRating,arenatype); |
---|
897 | for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next()) |
---|
898 | { |
---|
899 | Player *member = itr->getSource(); |
---|
900 | if(!member) continue; |
---|
901 | |
---|
902 | uint32 queueSlot = member->AddBattleGroundQueueId(bgQueueTypeId);// add to queue |
---|
903 | |
---|
904 | // store entry point coords (same as leader entry point) |
---|
905 | member->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation()); |
---|
906 | |
---|
907 | WorldPacket data; |
---|
908 | // send status packet (in queue) |
---|
909 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, member->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0, arenatype, isRated); |
---|
910 | member->GetSession()->SendPacket(&data); |
---|
911 | sBattleGroundMgr.BuildGroupJoinedBattlegroundPacket(&data, bgTypeId); |
---|
912 | member->GetSession()->SendPacket(&data); |
---|
913 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddPlayer(member, ginfo); |
---|
914 | sLog.outDebug("Battleground: player joined queue for arena as group bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,member->GetGUIDLow(), member->GetName()); |
---|
915 | } |
---|
916 | sLog.outDebug("Battleground: arena join as group end"); |
---|
917 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, _player->GetBattleGroundQueueIdFromLevel(), arenatype, isRated, arenaRating); |
---|
918 | } |
---|
919 | else |
---|
920 | { |
---|
921 | uint32 queueSlot = _player->AddBattleGroundQueueId(bgQueueTypeId); |
---|
922 | |
---|
923 | // store entry point coords |
---|
924 | _player->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation()); |
---|
925 | |
---|
926 | WorldPacket data; |
---|
927 | // send status packet (in queue) |
---|
928 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0, arenatype, isRated); |
---|
929 | SendPacket(&data); |
---|
930 | GroupQueueInfo * ginfo = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddGroup(_player, bgTypeId, arenatype, isRated, arenaRating); |
---|
931 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddPlayer(_player, ginfo); |
---|
932 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, _player->GetBattleGroundQueueIdFromLevel(), arenatype, isRated, arenaRating); |
---|
933 | sLog.outDebug("Battleground: player joined queue for arena, skirmish, bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,_player->GetGUIDLow(), _player->GetName()); |
---|
934 | } |
---|
935 | } |
---|
936 | |
---|
937 | void WorldSession::HandleBattleGroundReportAFK( WorldPacket & recv_data ) |
---|
938 | { |
---|
939 | CHECK_PACKET_SIZE(recv_data, 8); |
---|
940 | |
---|
941 | uint64 playerGuid; |
---|
942 | recv_data >> playerGuid; |
---|
943 | Player *reportedPlayer = objmgr.GetPlayer(playerGuid); |
---|
944 | |
---|
945 | if(!reportedPlayer) |
---|
946 | { |
---|
947 | sLog.outDebug("WorldSession::HandleBattleGroundReportAFK: player not found"); |
---|
948 | return; |
---|
949 | } |
---|
950 | |
---|
951 | sLog.outDebug("WorldSession::HandleBattleGroundReportAFK: %s reported %s", _player->GetName(), reportedPlayer->GetName()); |
---|
952 | |
---|
953 | reportedPlayer->ReportedAfkBy(_player); |
---|
954 | } |
---|