[6982] Implemented gmlevel-based command security
[getmangos.git] / src / game / BattleGroundAB.cpp
blob5200a3f5fd7918fa64866049db0f9b59fd9a6306
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Object.h"
20 #include "Player.h"
21 #include "BattleGround.h"
22 #include "BattleGroundAB.h"
23 #include "Creature.h"
24 #include "Chat.h"
25 #include "ObjectMgr.h"
26 #include "MapManager.h"
27 #include "Language.h"
28 #include "Util.h"
30 BattleGroundAB::BattleGroundAB()
32 m_BuffChange = true;
33 m_BgObjects.resize(BG_AB_OBJECT_MAX);
34 m_BgCreatures.resize(BG_AB_ALL_NODES_COUNT);
37 BattleGroundAB::~BattleGroundAB()
41 void BattleGroundAB::Update(time_t diff)
43 BattleGround::Update(diff);
45 if( GetStatus() == STATUS_WAIT_JOIN && GetPlayersSize() )
47 ModifyStartDelayTime(diff);
49 if( !(m_Events & 0x01) )
51 m_Events |= 0x01;
53 // setup here, only when at least one player has ported to the map
54 if(!SetupBattleGround())
56 EndNow();
57 return;
60 sLog.outDebug("Arathi Basin: entering state STATUS_WAIT_JOIN ...");
62 // despawn banners, auras and buffs
63 for (int obj = BG_AB_OBJECT_BANNER_NEUTRAL; obj < BG_AB_DYNAMIC_NODES_COUNT * 8; ++obj)
64 SpawnBGObject(obj, RESPAWN_ONE_DAY);
65 for (int i = 0; i < BG_AB_DYNAMIC_NODES_COUNT * 3; ++i)
66 SpawnBGObject(BG_AB_OBJECT_SPEEDBUFF_STABLES + i, RESPAWN_ONE_DAY);
68 // Starting doors
69 SpawnBGObject(BG_AB_OBJECT_GATE_A, RESPAWN_IMMEDIATELY);
70 SpawnBGObject(BG_AB_OBJECT_GATE_H, RESPAWN_IMMEDIATELY);
71 DoorClose(BG_AB_OBJECT_GATE_A);
72 DoorClose(BG_AB_OBJECT_GATE_H);
74 // Starting base spirit guides
75 _NodeOccupied(BG_AB_SPIRIT_ALIANCE,ALLIANCE);
76 _NodeOccupied(BG_AB_SPIRIT_HORDE,HORDE);
78 SetStartDelayTime(START_DELAY0);
80 // After 1 minute, warning is signalled
81 else if( GetStartDelayTime() <= START_DELAY1 && !(m_Events & 0x04) )
83 m_Events |= 0x04;
84 SendMessageToAll(GetMangosString(LANG_BG_AB_ONEMINTOSTART));
86 // After 1,5 minute, warning is signalled
87 else if( GetStartDelayTime() <= START_DELAY2 && !(m_Events & 0x08) )
89 m_Events |= 0x08;
90 SendMessageToAll(GetMangosString(LANG_BG_AB_HALFMINTOSTART));
92 // After 2 minutes, gates OPEN ! x)
93 else if( GetStartDelayTime() < 0 && !(m_Events & 0x10) )
95 m_Events |= 0x10;
96 SendMessageToAll(GetMangosString(LANG_BG_AB_STARTED));
98 // spawn neutral banners
99 for (int banner = BG_AB_OBJECT_BANNER_NEUTRAL, i = 0; i < 5; banner += 8, ++i)
100 SpawnBGObject(banner, RESPAWN_IMMEDIATELY);
101 for (int i = 0; i < BG_AB_DYNAMIC_NODES_COUNT; ++i)
103 //randomly select buff to spawn
104 uint8 buff = urand(0, 2);
105 SpawnBGObject(BG_AB_OBJECT_SPEEDBUFF_STABLES + buff + i * 3, RESPAWN_IMMEDIATELY);
107 DoorOpen(BG_AB_OBJECT_GATE_A);
108 DoorOpen(BG_AB_OBJECT_GATE_H);
110 PlaySoundToAll(SOUND_BG_START);
111 SetStatus(STATUS_IN_PROGRESS);
113 for(BattleGroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
114 if(Player* plr = objmgr.GetPlayer(itr->first))
115 plr->RemoveAurasDueToSpell(SPELL_PREPARATION);
119 else if( GetStatus() == STATUS_IN_PROGRESS )
121 int team_points[2] = { 0, 0 };
123 for (int node = 0; node < BG_AB_DYNAMIC_NODES_COUNT; ++node)
125 // 3 sec delay to spawn new banner instead previous despawned one
126 if( m_BannerTimers[node].timer )
128 if( m_BannerTimers[node].timer > diff )
129 m_BannerTimers[node].timer -= diff;
130 else
132 m_BannerTimers[node].timer = 0;
133 _CreateBanner(node, m_BannerTimers[node].type, m_BannerTimers[node].teamIndex, false);
137 // 1-minute to occupy a node from contested state
138 if( m_NodeTimers[node] )
140 if( m_NodeTimers[node] > diff )
141 m_NodeTimers[node] -= diff;
142 else
144 m_NodeTimers[node] = 0;
145 // Change from contested to occupied !
146 uint8 teamIndex = m_Nodes[node]-1;
147 m_prevNodes[node] = m_Nodes[node];
148 m_Nodes[node] += 2;
149 // burn current contested banner
150 _DelBanner(node, BG_AB_NODE_TYPE_CONTESTED, teamIndex);
151 // create new occupied banner
152 _CreateBanner(node, BG_AB_NODE_TYPE_OCCUPIED, teamIndex, true);
153 _SendNodeUpdate(node);
154 _NodeOccupied(node,(teamIndex == 0) ? ALLIANCE:HORDE);
155 // Message to chatlog
156 char buf[256];
157 uint8 type = (teamIndex == 0) ? CHAT_MSG_BG_SYSTEM_ALLIANCE : CHAT_MSG_BG_SYSTEM_HORDE;
158 sprintf(buf, GetMangosString(LANG_BG_AB_NODE_TAKEN), (teamIndex == 0) ? GetMangosString(LANG_BG_AB_ALLY) : GetMangosString(LANG_BG_AB_HORDE), _GetNodeName(node));
159 WorldPacket data;
160 ChatHandler::FillMessageData(&data, NULL, type, LANG_UNIVERSAL, NULL, 0, buf, NULL);
161 SendPacketToAll(&data);
162 PlaySoundToAll((teamIndex == 0) ? SOUND_NODE_CAPTURED_ALLIANCE : SOUND_NODE_CAPTURED_HORDE);
166 for (int team = 0; team < 2; ++team)
167 if( m_Nodes[node] == team + BG_AB_NODE_TYPE_OCCUPIED )
168 ++team_points[team];
171 // Accumulate points
172 for (int team = 0; team < 2; ++team)
174 int points = team_points[team];
175 if( !points )
176 continue;
177 m_lastTick[team] += diff;
178 if( m_lastTick[team] > BG_AB_TickIntervals[points] )
180 m_lastTick[team] -= BG_AB_TickIntervals[points];
181 m_TeamScores[team] += BG_AB_TickPoints[points];
182 m_HonorScoreTics[team] += BG_AB_TickPoints[points];
183 m_ReputationScoreTics[team] += BG_AB_TickPoints[points];
184 if( m_ReputationScoreTics[team] >= 200 )
186 (team == BG_TEAM_ALLIANCE) ? RewardReputationToTeam(509, 10, ALLIANCE) : RewardReputationToTeam(510, 10, HORDE);
187 m_ReputationScoreTics[team] -= 200;
189 if( m_HonorScoreTics[team] >= BG_HONOR_SCORE_TICKS )
191 (team == BG_TEAM_ALLIANCE) ? RewardHonorToTeam(20, ALLIANCE) : RewardHonorToTeam(20, HORDE);
192 m_HonorScoreTics[team] -= BG_HONOR_SCORE_TICKS;
194 if( !m_IsInformedNearVictory && m_TeamScores[team] > 1800 )
196 if( team == BG_TEAM_ALLIANCE )
197 SendMessageToAll(GetMangosString(LANG_BG_AB_A_NEAR_VICTORY));
198 else
199 SendMessageToAll(GetMangosString(LANG_BG_AB_H_NEAR_VICTORY));
200 PlaySoundToAll(SOUND_NEAR_VICTORY);
201 m_IsInformedNearVictory = true;
204 if( m_TeamScores[team] > 2000 )
205 m_TeamScores[team] = 2000;
206 if( team == BG_TEAM_ALLIANCE )
207 UpdateWorldState(BG_AB_OP_RESOURCES_ALLY, m_TeamScores[team]);
208 if( team == BG_TEAM_HORDE )
209 UpdateWorldState(BG_AB_OP_RESOURCES_HORDE, m_TeamScores[team]);
213 // Test win condition
214 if( m_TeamScores[BG_TEAM_ALLIANCE] >= 2000 )
215 EndBattleGround(ALLIANCE);
216 if( m_TeamScores[BG_TEAM_HORDE] >= 2000 )
217 EndBattleGround(HORDE);
221 void BattleGroundAB::AddPlayer(Player *plr)
223 BattleGround::AddPlayer(plr);
224 //create score and add it to map, default values are set in the constructor
225 BattleGroundABScore* sc = new BattleGroundABScore;
227 m_PlayerScores[plr->GetGUID()] = sc;
230 void BattleGroundAB::RemovePlayer(Player * /*plr*/, uint64 /*guid*/)
235 void BattleGroundAB::HandleAreaTrigger(Player *Source, uint32 Trigger)
237 if( GetStatus() != STATUS_IN_PROGRESS )
238 return;
240 switch(Trigger)
242 case 3948: // Arathi Basin Alliance Exit.
243 if( Source->GetTeam() != ALLIANCE )
244 Source->GetSession()->SendAreaTriggerMessage("Only The Alliance can use that portal");
245 else
246 Source->LeaveBattleground();
247 break;
248 case 3949: // Arathi Basin Horde Exit.
249 if( Source->GetTeam() != HORDE )
250 Source->GetSession()->SendAreaTriggerMessage("Only The Horde can use that portal");
251 else
252 Source->LeaveBattleground();
253 break;
254 case 3866: // Stables
255 case 3869: // Gold Mine
256 case 3867: // Farm
257 case 3868: // Lumber Mill
258 case 3870: // Black Smith
259 case 4020: // Unk1
260 case 4021: // Unk2
261 //break;
262 default:
263 //sLog.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", Trigger);
264 //Source->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", Trigger);
265 break;
269 /* type: 0-neutral, 1-contested, 3-occupied
270 teamIndex: 0-ally, 1-horde */
271 void BattleGroundAB::_CreateBanner(uint8 node, uint8 type, uint8 teamIndex, bool delay)
273 // Just put it into the queue
274 if( delay )
276 m_BannerTimers[node].timer = 2000;
277 m_BannerTimers[node].type = type;
278 m_BannerTimers[node].teamIndex = teamIndex;
279 return;
282 uint8 obj = node*8 + type + teamIndex;
284 SpawnBGObject(obj, RESPAWN_IMMEDIATELY);
286 // handle aura with banner
287 if( !type )
288 return;
289 obj = node * 8 + ((type == BG_AB_NODE_TYPE_OCCUPIED) ? (5 + teamIndex) : 7);
290 SpawnBGObject(obj, RESPAWN_IMMEDIATELY);
293 void BattleGroundAB::_DelBanner(uint8 node, uint8 type, uint8 teamIndex)
295 uint8 obj = node*8 + type + teamIndex;
296 SpawnBGObject(obj, RESPAWN_ONE_DAY);
298 // handle aura with banner
299 if( !type )
300 return;
301 obj = node * 8 + ((type == BG_AB_NODE_TYPE_OCCUPIED) ? (5 + teamIndex) : 7);
302 SpawnBGObject(obj, RESPAWN_ONE_DAY);
305 const char* BattleGroundAB::_GetNodeName(uint8 node)
307 switch (node)
309 case BG_AB_NODE_STABLES:
310 return GetMangosString(LANG_BG_AB_NODE_STABLES);
311 case BG_AB_NODE_BLACKSMITH:
312 return GetMangosString(LANG_BG_AB_NODE_BLACKSMITH);
313 case BG_AB_NODE_FARM:
314 return GetMangosString(LANG_BG_AB_NODE_FARM);
315 case BG_AB_NODE_LUMBER_MILL:
316 return GetMangosString(LANG_BG_AB_NODE_LUMBER_MILL);
317 case BG_AB_NODE_GOLD_MINE:
318 return GetMangosString(LANG_BG_AB_NODE_GOLD_MINE);
319 default:
320 ASSERT(0);
322 return "";
325 void BattleGroundAB::FillInitialWorldStates(WorldPacket& data)
327 const uint8 plusArray[] = {0, 2, 3, 0, 1};
329 // Node icons
330 for (uint8 node = 0; node < BG_AB_DYNAMIC_NODES_COUNT; ++node)
331 data << uint32(BG_AB_OP_NODEICONS[node]) << uint32((m_Nodes[node]==0)?1:0);
333 // Node occupied states
334 for (uint8 node = 0; node < BG_AB_DYNAMIC_NODES_COUNT; ++node)
335 for (uint8 i = 1; i < BG_AB_DYNAMIC_NODES_COUNT; ++i)
336 data << uint32(BG_AB_OP_NODESTATES[node] + plusArray[i]) << uint32((m_Nodes[node]==i)?1:0);
338 // How many bases each team owns
339 uint8 ally = 0, horde = 0;
340 for (uint8 node = 0; node < BG_AB_DYNAMIC_NODES_COUNT; ++node)
341 if( m_Nodes[node] == BG_AB_NODE_STATUS_ALLY_OCCUPIED )
342 ++ally;
343 else if( m_Nodes[node] == BG_AB_NODE_STATUS_HORDE_OCCUPIED )
344 ++horde;
346 data << uint32(BG_AB_OP_OCCUPIED_BASES_ALLY) << uint32(ally);
347 data << uint32(BG_AB_OP_OCCUPIED_BASES_HORDE) << uint32(horde);
349 // Team scores
350 data << uint32(BG_AB_OP_RESOURCES_MAX) << uint32(BG_AB_MAX_TEAM_SCORE);
351 data << uint32(BG_AB_OP_RESOURCES_WARNING) << uint32(BG_AB_WARNING_SCORE);
352 data << uint32(BG_AB_OP_RESOURCES_ALLY) << uint32(m_TeamScores[BG_TEAM_ALLIANCE]);
353 data << uint32(BG_AB_OP_RESOURCES_HORDE) << uint32(m_TeamScores[BG_TEAM_HORDE]);
355 // other unknown
356 data << uint32(0x745) << uint32(0x2); // 37 1861 unk
359 void BattleGroundAB::_SendNodeUpdate(uint8 node)
361 // Send node owner state update to refresh map icons on client
362 const uint8 plusArray[] = {0, 2, 3, 0, 1};
364 if( m_prevNodes[node] )
365 UpdateWorldState(BG_AB_OP_NODESTATES[node] + plusArray[m_prevNodes[node]], 0);
366 else
367 UpdateWorldState(BG_AB_OP_NODEICONS[node], 0);
369 UpdateWorldState(BG_AB_OP_NODESTATES[node] + plusArray[m_Nodes[node]], 1);
371 // How many bases each team owns
372 uint8 ally = 0, horde = 0;
373 for (uint8 i = 0; i < BG_AB_DYNAMIC_NODES_COUNT; ++i)
374 if( m_Nodes[i] == BG_AB_NODE_STATUS_ALLY_OCCUPIED )
375 ++ally;
376 else if( m_Nodes[i] == BG_AB_NODE_STATUS_HORDE_OCCUPIED )
377 ++horde;
379 UpdateWorldState(BG_AB_OP_OCCUPIED_BASES_ALLY, ally);
380 UpdateWorldState(BG_AB_OP_OCCUPIED_BASES_HORDE, horde);
383 void BattleGroundAB::_NodeOccupied(uint8 node,Team team)
385 if( !AddSpiritGuide(node, BG_AB_SpiritGuidePos[node][0], BG_AB_SpiritGuidePos[node][1], BG_AB_SpiritGuidePos[node][2], BG_AB_SpiritGuidePos[node][3], team) )
386 sLog.outError("Failed to spawn spirit guide! point: %u, team: %u,", node, team);
387 // SpawnBGCreature(node,RESPAWN_IMMEDIATELY);
389 uint8 capturedNodes = 0;
390 for (uint8 i = 0; i < BG_AB_DYNAMIC_NODES_COUNT; ++i)
392 if( m_Nodes[node] == GetTeamIndexByTeamId(team) + BG_AB_NODE_TYPE_OCCUPIED && !m_NodeTimers[i])
393 ++capturedNodes;
395 if(capturedNodes >= 5)
396 CastSpellOnTeam(SPELL_AB_QUEST_REWARD_5_BASES, team);
397 if(capturedNodes >= 4)
398 CastSpellOnTeam(SPELL_AB_QUEST_REWARD_4_BASES, team);
401 void BattleGroundAB::_NodeDeOccupied(uint8 node)
403 if( node >= BG_AB_DYNAMIC_NODES_COUNT)
404 return;
406 // Those who are waiting to resurrect at this node are taken to the closest own node's graveyard
407 std::vector<uint64> ghost_list = m_ReviveQueue[m_BgCreatures[node]];
408 if( !ghost_list.empty() )
410 WorldSafeLocsEntry const *ClosestGrave = NULL;
411 Player *plr;
412 for (std::vector<uint64>::iterator itr = ghost_list.begin(); itr != ghost_list.end(); ++itr)
414 plr = objmgr.GetPlayer(*ghost_list.begin());
415 if( !plr )
416 continue;
417 if( !ClosestGrave )
418 ClosestGrave = GetClosestGraveYard(plr->GetPositionX(), plr->GetPositionY(), plr->GetPositionZ(), plr->GetTeam());
420 plr->TeleportTo(GetMapId(), ClosestGrave->x, ClosestGrave->y, ClosestGrave->z, plr->GetOrientation());
424 if( m_BgCreatures[node] )
425 DelCreature(node);
427 // buff object isn't despawned
430 /* Invoked if a player used a banner as a gameobject */
431 void BattleGroundAB::EventPlayerClickedOnFlag(Player *source, GameObject* /*target_obj*/)
433 if( GetStatus() != STATUS_IN_PROGRESS )
434 return;
436 uint8 node = BG_AB_NODE_STABLES;
437 GameObject* obj=HashMapHolder<GameObject>::Find(m_BgObjects[node*8+7]);
438 while ( (node < BG_AB_DYNAMIC_NODES_COUNT) && ((!obj) || (!source->IsWithinDistInMap(obj,10))))
440 ++node;
441 obj=HashMapHolder<GameObject>::Find(m_BgObjects[node*8+BG_AB_OBJECT_AURA_CONTESTED]);
444 if( node == BG_AB_DYNAMIC_NODES_COUNT)
446 // this means our player isn't close to any of banners - maybe cheater ??
447 return;
450 uint8 teamIndex = GetTeamIndexByTeamId(source->GetTeam());
452 // Message to chatlog
453 char buf[256];
454 uint8 type = (teamIndex == 0) ? CHAT_MSG_BG_SYSTEM_ALLIANCE : CHAT_MSG_BG_SYSTEM_HORDE;
456 // Check if player really could use this banner, not cheated
457 if( !(m_Nodes[node] == 0 || teamIndex == m_Nodes[node]%2) )
458 return;
460 source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
461 uint32 sound = 0;
462 // If node is neutral, change to contested
463 if( m_Nodes[node] == BG_AB_NODE_TYPE_NEUTRAL )
465 UpdatePlayerScore(source, SCORE_BASES_ASSAULTED, 1);
466 m_prevNodes[node] = m_Nodes[node];
467 m_Nodes[node] = teamIndex + 1;
468 // burn current neutral banner
469 _DelBanner(node, BG_AB_NODE_TYPE_NEUTRAL, 0);
470 // create new contested banner
471 _CreateBanner(node, BG_AB_NODE_TYPE_CONTESTED, teamIndex, true);
472 _SendNodeUpdate(node);
473 m_NodeTimers[node] = BG_AB_FLAG_CAPTURING_TIME;
474 sprintf(buf, GetMangosString(LANG_BG_AB_NODE_CLAIMED), _GetNodeName(node), (teamIndex == 0) ? GetMangosString(LANG_BG_AB_ALLY) : GetMangosString(LANG_BG_AB_HORDE));
475 sound = SOUND_NODE_CLAIMED;
477 // If node is contested
478 else if( (m_Nodes[node] == BG_AB_NODE_STATUS_ALLY_CONTESTED) || (m_Nodes[node] == BG_AB_NODE_STATUS_HORDE_CONTESTED) )
480 // If last state is NOT occupied, change node to enemy-contested
481 if( m_prevNodes[node] < BG_AB_NODE_TYPE_OCCUPIED )
483 UpdatePlayerScore(source, SCORE_BASES_ASSAULTED, 1);
484 m_prevNodes[node] = m_Nodes[node];
485 m_Nodes[node] = teamIndex + BG_AB_NODE_TYPE_CONTESTED;
486 // burn current contested banner
487 _DelBanner(node, BG_AB_NODE_TYPE_CONTESTED, !teamIndex);
488 // create new contested banner
489 _CreateBanner(node, BG_AB_NODE_TYPE_CONTESTED, teamIndex, true);
490 _SendNodeUpdate(node);
491 m_NodeTimers[node] = BG_AB_FLAG_CAPTURING_TIME;
492 sprintf(buf, GetMangosString(LANG_BG_AB_NODE_ASSAULTED), _GetNodeName(node));
494 // If contested, change back to occupied
495 else
497 UpdatePlayerScore(source, SCORE_BASES_DEFENDED, 1);
498 m_prevNodes[node] = m_Nodes[node];
499 m_Nodes[node] = teamIndex + BG_AB_NODE_TYPE_OCCUPIED;
500 // burn current contested banner
501 _DelBanner(node, BG_AB_NODE_TYPE_CONTESTED, !teamIndex);
502 // create new occupied banner
503 _CreateBanner(node, BG_AB_NODE_TYPE_OCCUPIED, teamIndex, true);
504 _SendNodeUpdate(node);
505 m_NodeTimers[node] = 0;
506 _NodeOccupied(node,(teamIndex == 0) ? ALLIANCE:HORDE);
507 sprintf(buf, GetMangosString(LANG_BG_AB_NODE_DEFENDED), _GetNodeName(node));
509 sound = (teamIndex == 0) ? SOUND_NODE_ASSAULTED_ALLIANCE : SOUND_NODE_ASSAULTED_HORDE;
511 // If node is occupied, change to enemy-contested
512 else
514 UpdatePlayerScore(source, SCORE_BASES_ASSAULTED, 1);
515 m_prevNodes[node] = m_Nodes[node];
516 m_Nodes[node] = teamIndex + BG_AB_NODE_TYPE_CONTESTED;
517 // burn current occupied banner
518 _DelBanner(node, BG_AB_NODE_TYPE_OCCUPIED, !teamIndex);
519 // create new contested banner
520 _CreateBanner(node, BG_AB_NODE_TYPE_CONTESTED, teamIndex, true);
521 _SendNodeUpdate(node);
522 _NodeDeOccupied(node);
523 m_NodeTimers[node] = BG_AB_FLAG_CAPTURING_TIME;
524 sprintf(buf, GetMangosString(LANG_BG_AB_NODE_ASSAULTED), _GetNodeName(node));
525 sound = (teamIndex == 0) ? SOUND_NODE_ASSAULTED_ALLIANCE : SOUND_NODE_ASSAULTED_HORDE;
527 WorldPacket data;
528 ChatHandler::FillMessageData(&data, source->GetSession(), type, LANG_UNIVERSAL, NULL, source->GetGUID(), buf, NULL);
529 SendPacketToAll(&data);
530 // If node is occupied again, send "X has taken the Y" msg.
531 if( m_Nodes[node] >= BG_AB_NODE_TYPE_OCCUPIED )
533 sprintf(buf, GetMangosString(LANG_BG_AB_NODE_TAKEN), (teamIndex == 0) ? GetMangosString(LANG_BG_AB_ALLY) : GetMangosString(LANG_BG_AB_HORDE), _GetNodeName(node));
534 ChatHandler::FillMessageData(&data, NULL, type, LANG_UNIVERSAL, NULL, 0, buf, NULL);
535 SendPacketToAll(&data);
537 PlaySoundToAll(sound);
540 bool BattleGroundAB::SetupBattleGround()
542 for (int i = 0 ; i < BG_AB_DYNAMIC_NODES_COUNT; ++i)
544 if( !AddObject(BG_AB_OBJECT_BANNER_NEUTRAL + 8*i,BG_AB_OBJECTID_NODE_BANNER_0 + i,BG_AB_NodePositions[i][0],BG_AB_NodePositions[i][1],BG_AB_NodePositions[i][2],BG_AB_NodePositions[i][3], 0, 0, sin(BG_AB_NodePositions[i][3]/2), cos(BG_AB_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
545 || !AddObject(BG_AB_OBJECT_BANNER_CONT_A + 8*i,BG_AB_OBJECTID_BANNER_CONT_A,BG_AB_NodePositions[i][0],BG_AB_NodePositions[i][1],BG_AB_NodePositions[i][2],BG_AB_NodePositions[i][3], 0, 0, sin(BG_AB_NodePositions[i][3]/2), cos(BG_AB_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
546 || !AddObject(BG_AB_OBJECT_BANNER_CONT_H + 8*i,BG_AB_OBJECTID_BANNER_CONT_H,BG_AB_NodePositions[i][0],BG_AB_NodePositions[i][1],BG_AB_NodePositions[i][2],BG_AB_NodePositions[i][3], 0, 0, sin(BG_AB_NodePositions[i][3]/2), cos(BG_AB_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
547 || !AddObject(BG_AB_OBJECT_BANNER_ALLY + 8*i,BG_AB_OBJECTID_BANNER_A,BG_AB_NodePositions[i][0],BG_AB_NodePositions[i][1],BG_AB_NodePositions[i][2],BG_AB_NodePositions[i][3], 0, 0, sin(BG_AB_NodePositions[i][3]/2), cos(BG_AB_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
548 || !AddObject(BG_AB_OBJECT_BANNER_HORDE + 8*i,BG_AB_OBJECTID_BANNER_H,BG_AB_NodePositions[i][0],BG_AB_NodePositions[i][1],BG_AB_NodePositions[i][2],BG_AB_NodePositions[i][3], 0, 0, sin(BG_AB_NodePositions[i][3]/2), cos(BG_AB_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
549 || !AddObject(BG_AB_OBJECT_AURA_ALLY + 8*i,BG_AB_OBJECTID_AURA_A,BG_AB_NodePositions[i][0],BG_AB_NodePositions[i][1],BG_AB_NodePositions[i][2],BG_AB_NodePositions[i][3], 0, 0, sin(BG_AB_NodePositions[i][3]/2), cos(BG_AB_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
550 || !AddObject(BG_AB_OBJECT_AURA_HORDE + 8*i,BG_AB_OBJECTID_AURA_H,BG_AB_NodePositions[i][0],BG_AB_NodePositions[i][1],BG_AB_NodePositions[i][2],BG_AB_NodePositions[i][3], 0, 0, sin(BG_AB_NodePositions[i][3]/2), cos(BG_AB_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
551 || !AddObject(BG_AB_OBJECT_AURA_CONTESTED + 8*i,BG_AB_OBJECTID_AURA_C,BG_AB_NodePositions[i][0],BG_AB_NodePositions[i][1],BG_AB_NodePositions[i][2],BG_AB_NodePositions[i][3], 0, 0, sin(BG_AB_NodePositions[i][3]/2), cos(BG_AB_NodePositions[i][3]/2),RESPAWN_ONE_DAY)
554 sLog.outErrorDb("BatteGroundAB: Failed to spawn some object BattleGround not created!");
555 return false;
558 if( !AddObject(BG_AB_OBJECT_GATE_A,BG_AB_OBJECTID_GATE_A,BG_AB_DoorPositions[0][0],BG_AB_DoorPositions[0][1],BG_AB_DoorPositions[0][2],BG_AB_DoorPositions[0][3],BG_AB_DoorPositions[0][4],BG_AB_DoorPositions[0][5],BG_AB_DoorPositions[0][6],BG_AB_DoorPositions[0][7],RESPAWN_IMMEDIATELY)
559 || !AddObject(BG_AB_OBJECT_GATE_H,BG_AB_OBJECTID_GATE_H,BG_AB_DoorPositions[1][0],BG_AB_DoorPositions[1][1],BG_AB_DoorPositions[1][2],BG_AB_DoorPositions[1][3],BG_AB_DoorPositions[1][4],BG_AB_DoorPositions[1][5],BG_AB_DoorPositions[1][6],BG_AB_DoorPositions[1][7],RESPAWN_IMMEDIATELY)
562 sLog.outErrorDb("BatteGroundAB: Failed to spawn door object BattleGround not created!");
563 return false;
565 //buffs
566 for (int i = 0; i < BG_AB_DYNAMIC_NODES_COUNT; ++i)
568 if( !AddObject(BG_AB_OBJECT_SPEEDBUFF_STABLES + 3 * i, Buff_Entries[0], BG_AB_BuffPositions[i][0], BG_AB_BuffPositions[i][1], BG_AB_BuffPositions[i][2], BG_AB_BuffPositions[i][3], 0, 0, sin(BG_AB_BuffPositions[i][3]/2), cos(BG_AB_BuffPositions[i][3]/2), RESPAWN_ONE_DAY)
569 || !AddObject(BG_AB_OBJECT_SPEEDBUFF_STABLES + 3 * i + 1, Buff_Entries[1], BG_AB_BuffPositions[i][0], BG_AB_BuffPositions[i][1], BG_AB_BuffPositions[i][2], BG_AB_BuffPositions[i][3], 0, 0, sin(BG_AB_BuffPositions[i][3]/2), cos(BG_AB_BuffPositions[i][3]/2), RESPAWN_ONE_DAY)
570 || !AddObject(BG_AB_OBJECT_SPEEDBUFF_STABLES + 3 * i + 2, Buff_Entries[2], BG_AB_BuffPositions[i][0], BG_AB_BuffPositions[i][1], BG_AB_BuffPositions[i][2], BG_AB_BuffPositions[i][3], 0, 0, sin(BG_AB_BuffPositions[i][3]/2), cos(BG_AB_BuffPositions[i][3]/2), RESPAWN_ONE_DAY)
572 sLog.outErrorDb("BatteGroundAB: Failed to spawn buff object!");
575 return true;
578 void BattleGroundAB::ResetBGSubclass()
580 m_TeamScores[BG_TEAM_ALLIANCE] = 0;
581 m_TeamScores[BG_TEAM_HORDE] = 0;
582 m_lastTick[BG_TEAM_ALLIANCE] = 0;
583 m_lastTick[BG_TEAM_HORDE] = 0;
584 m_HonorScoreTics[BG_TEAM_ALLIANCE] = 0;
585 m_HonorScoreTics[BG_TEAM_HORDE] = 0;
586 m_ReputationScoreTics[BG_TEAM_ALLIANCE] = 0;
587 m_ReputationScoreTics[BG_TEAM_HORDE] = 0;
588 m_IsInformedNearVictory = false;
589 for (uint8 i = 0; i < BG_AB_DYNAMIC_NODES_COUNT; ++i)
591 m_Nodes[i] = 0;
592 m_prevNodes[i] = 0;
593 m_NodeTimers[i] = 0;
594 m_BannerTimers[i].timer = 0;
597 for (uint8 i = 0; i < BG_AB_ALL_NODES_COUNT; ++i)
598 if(m_BgCreatures[i])
599 DelCreature(i);
602 WorldSafeLocsEntry const* BattleGroundAB::GetClosestGraveYard(float x, float y, float /*z*/, uint32 team)
604 uint8 teamIndex = GetTeamIndexByTeamId(team);
606 // Is there any occupied node for this team?
607 std::vector<uint8> nodes;
608 for (uint8 i = 0; i < BG_AB_DYNAMIC_NODES_COUNT; ++i)
609 if( m_Nodes[i] == teamIndex + 3 )
610 nodes.push_back(i);
612 WorldSafeLocsEntry const* good_entry = NULL;
613 // If so, select the closest node to place ghost on
614 if( !nodes.empty() )
616 float mindist = 999999.0f;
617 for (uint8 i = 0; i < nodes.size(); ++i)
619 WorldSafeLocsEntry const*entry = sWorldSafeLocsStore.LookupEntry( BG_AB_GraveyardIds[nodes[i]] );
620 if( !entry )
621 continue;
622 float dist = (entry->x - x)*(entry->x - x)+(entry->y - y)*(entry->y - y);
623 if( mindist > dist )
625 mindist = dist;
626 good_entry = entry;
629 nodes.clear();
631 // If not, place ghost on starting location
632 if( !good_entry )
633 good_entry = sWorldSafeLocsStore.LookupEntry( BG_AB_GraveyardIds[teamIndex+5] );
635 return good_entry;
638 void BattleGroundAB::UpdatePlayerScore(Player *Source, uint32 type, uint32 value)
640 std::map<uint64, BattleGroundScore*>::iterator itr = m_PlayerScores.find(Source->GetGUID());
642 if( itr == m_PlayerScores.end() ) // player not found...
643 return;
645 switch(type)
647 case SCORE_BASES_ASSAULTED:
648 ((BattleGroundABScore*)itr->second)->BasesAssaulted += value;
649 break;
650 case SCORE_BASES_DEFENDED:
651 ((BattleGroundABScore*)itr->second)->BasesDefended += value;
652 break;
653 default:
654 BattleGround::UpdatePlayerScore(Source,type,value);
655 break;