[7918] Improve portability in work with uint64 string format specifiers and in code...
[getmangos.git] / src / game / BattleGroundEY.cpp
blob7a63b67298fc74ebdb87570bb1617c91c864a031
1 /*
2 * Copyright (C) 2005-2009 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 "BattleGroundEY.h"
23 #include "Creature.h"
24 #include "ObjectMgr.h"
25 #include "Language.h"
26 #include "WorldPacket.h"
27 #include "Util.h"
29 BattleGroundEY::BattleGroundEY()
31 m_BuffChange = true;
32 m_BgObjects.resize(BG_EY_OBJECT_MAX);
33 m_BgCreatures.resize(BG_EY_CREATURES_MAX);
34 m_Points_Trigger[FEL_REALVER] = TR_FEL_REALVER_BUFF;
35 m_Points_Trigger[BLOOD_ELF] = TR_BLOOD_ELF_BUFF;
36 m_Points_Trigger[DRAENEI_RUINS] = TR_DRAENEI_RUINS_BUFF;
37 m_Points_Trigger[MAGE_TOWER] = TR_MAGE_TOWER_BUFF;
39 m_StartMessageIds[BG_STARTING_EVENT_FIRST] = LANG_BG_EY_START_TWO_MINUTES;
40 m_StartMessageIds[BG_STARTING_EVENT_SECOND] = LANG_BG_EY_START_ONE_MINUTE;
41 m_StartMessageIds[BG_STARTING_EVENT_THIRD] = LANG_BG_EY_START_HALF_MINUTE;
42 m_StartMessageIds[BG_STARTING_EVENT_FOURTH] = LANG_BG_EY_HAS_BEGUN;
45 BattleGroundEY::~BattleGroundEY()
49 void BattleGroundEY::Update(uint32 diff)
51 BattleGround::Update(diff);
53 if (GetStatus() == STATUS_IN_PROGRESS)
55 m_PointAddingTimer -= diff;
56 if (m_PointAddingTimer <= 0)
58 m_PointAddingTimer = BG_EY_FPOINTS_TICK_TIME;
59 if (m_TeamPointsCount[BG_TEAM_ALLIANCE] > 0)
60 AddPoints(ALLIANCE, BG_EY_TickPoints[m_TeamPointsCount[BG_TEAM_ALLIANCE] - 1]);
61 if (m_TeamPointsCount[BG_TEAM_HORDE] > 0)
62 AddPoints(HORDE, BG_EY_TickPoints[m_TeamPointsCount[BG_TEAM_HORDE] - 1]);
65 if (m_FlagState == BG_EY_FLAG_STATE_WAIT_RESPAWN || m_FlagState == BG_EY_FLAG_STATE_ON_GROUND)
67 m_FlagsTimer -= diff;
69 if (m_FlagsTimer < 0)
71 m_FlagsTimer = 0;
72 if (m_FlagState == BG_EY_FLAG_STATE_WAIT_RESPAWN)
73 RespawnFlag(true);
74 else
75 RespawnFlagAfterDrop();
79 m_TowerCapCheckTimer -= diff;
80 if (m_TowerCapCheckTimer <= 0)
82 //check if player joined point
83 /*I used this order of calls, because although we will check if one player is in gameobject's distance 2 times
84 but we can count of players on current point in CheckSomeoneLeftPoint
86 CheckSomeoneJoinedPoint();
87 //check if player left point
88 CheckSomeoneLeftPoint();
89 UpdatePointStatuses();
90 m_TowerCapCheckTimer = BG_EY_FPOINTS_TICK_TIME;
95 void BattleGroundEY::StartingEventCloseDoors()
97 SpawnBGObject(BG_EY_OBJECT_DOOR_A, RESPAWN_IMMEDIATELY);
98 SpawnBGObject(BG_EY_OBJECT_DOOR_H, RESPAWN_IMMEDIATELY);
100 for(uint32 i = BG_EY_OBJECT_A_BANNER_FEL_REALVER_CENTER; i < BG_EY_OBJECT_MAX; ++i)
101 SpawnBGObject(i, RESPAWN_ONE_DAY);
104 void BattleGroundEY::StartingEventOpenDoors()
106 SpawnBGObject(BG_EY_OBJECT_DOOR_A, RESPAWN_ONE_DAY);
107 SpawnBGObject(BG_EY_OBJECT_DOOR_H, RESPAWN_ONE_DAY);
109 for(uint32 i = BG_EY_OBJECT_N_BANNER_FEL_REALVER_CENTER; i <= BG_EY_OBJECT_FLAG_NETHERSTORM; ++i)
110 SpawnBGObject(i, RESPAWN_IMMEDIATELY);
111 for(uint32 i = 0; i < EY_POINTS_MAX; ++i)
113 //randomly spawn buff
114 uint8 buff = urand(0, 2);
115 SpawnBGObject(BG_EY_OBJECT_SPEEDBUFF_FEL_REALVER + buff + i * 3, RESPAWN_IMMEDIATELY);
119 void BattleGroundEY::AddPoints(uint32 Team, uint32 Points)
121 uint8 team_index = GetTeamIndexByTeamId(Team);
122 m_TeamScores[team_index] += Points;
123 m_HonorScoreTics[team_index] += Points;
124 if (m_HonorScoreTics[team_index] >= m_HonorTics )
126 RewardHonorToTeam(GetBonusHonorFromKill(1), Team);
127 m_HonorScoreTics[team_index] -= m_HonorTics;
129 UpdateTeamScore(Team);
132 void BattleGroundEY::CheckSomeoneJoinedPoint()
134 GameObject *obj = NULL;
135 for (uint8 i = 0; i < EY_POINTS_MAX; ++i)
137 obj = HashMapHolder<GameObject>::Find(m_BgObjects[BG_EY_OBJECT_TOWER_CAP_FEL_REALVER + i]);
138 if (obj)
140 uint8 j = 0;
141 while (j < m_PlayersNearPoint[EY_POINTS_MAX].size())
143 Player *plr = objmgr.GetPlayer(m_PlayersNearPoint[EY_POINTS_MAX][j]);
144 if (!plr)
146 sLog.outError("BattleGroundEY: Player (GUID: %u) not found!", GUID_LOPART(m_PlayersNearPoint[EY_POINTS_MAX][j]));
147 ++j;
148 continue;
150 if (plr->CanCaptureTowerPoint() && plr->IsWithinDistInMap(obj, BG_EY_POINT_RADIUS))
152 //player joined point!
153 //show progress bar
154 UpdateWorldStateForPlayer(PROGRESS_BAR_PERCENT_GREY, BG_EY_PROGRESS_BAR_PERCENT_GREY, plr);
155 UpdateWorldStateForPlayer(PROGRESS_BAR_STATUS, m_PointBarStatus[i], plr);
156 UpdateWorldStateForPlayer(PROGRESS_BAR_SHOW, BG_EY_PROGRESS_BAR_SHOW, plr);
157 //add player to point
158 m_PlayersNearPoint[i].push_back(m_PlayersNearPoint[EY_POINTS_MAX][j]);
159 //remove player from "free space"
160 m_PlayersNearPoint[EY_POINTS_MAX].erase(m_PlayersNearPoint[EY_POINTS_MAX].begin() + j);
162 else
163 ++j;
169 void BattleGroundEY::CheckSomeoneLeftPoint()
171 //reset current point counts
172 for (uint8 i = 0; i < 2*EY_POINTS_MAX; ++i)
173 m_CurrentPointPlayersCount[i] = 0;
174 GameObject *obj = NULL;
175 for(uint8 i = 0; i < EY_POINTS_MAX; ++i)
177 obj = HashMapHolder<GameObject>::Find(m_BgObjects[BG_EY_OBJECT_TOWER_CAP_FEL_REALVER + i]);
178 if (obj)
180 uint8 j = 0;
181 while (j < m_PlayersNearPoint[i].size())
183 Player *plr = objmgr.GetPlayer(m_PlayersNearPoint[i][j]);
184 if (!plr)
186 sLog.outError("BattleGroundEY: Player (GUID: %u) not found!", GUID_LOPART(m_PlayersNearPoint[i][j]));
187 //move not existed player to "free space" - this will cause many error showing in log, but it is a very important bug
188 m_PlayersNearPoint[EY_POINTS_MAX].push_back(m_PlayersNearPoint[i][j]);
189 m_PlayersNearPoint[i].erase(m_PlayersNearPoint[i].begin() + j);
190 ++j;
191 continue;
193 if (!plr->CanCaptureTowerPoint() || !plr->IsWithinDistInMap(obj, BG_EY_POINT_RADIUS))
194 //move player out of point (add him to players that are out of points
196 m_PlayersNearPoint[EY_POINTS_MAX].push_back(m_PlayersNearPoint[i][j]);
197 m_PlayersNearPoint[i].erase(m_PlayersNearPoint[i].begin() + j);
198 UpdateWorldStateForPlayer(PROGRESS_BAR_SHOW, BG_EY_PROGRESS_BAR_DONT_SHOW, plr);
200 else
202 //player is neat flag, so update count:
203 m_CurrentPointPlayersCount[2 * i + GetTeamIndexByTeamId(plr->GetTeam())]++;
204 ++j;
211 void BattleGroundEY::UpdatePointStatuses()
213 for(uint8 point = 0; point < EY_POINTS_MAX; ++point)
215 if (m_PlayersNearPoint[point].empty())
216 continue;
217 //count new point bar status:
218 m_PointBarStatus[point] += (m_CurrentPointPlayersCount[2 * point] - m_CurrentPointPlayersCount[2 * point + 1] < BG_EY_POINT_MAX_CAPTURERS_COUNT) ? m_CurrentPointPlayersCount[2 * point] - m_CurrentPointPlayersCount[2 * point + 1] : BG_EY_POINT_MAX_CAPTURERS_COUNT;
220 if (m_PointBarStatus[point] > BG_EY_PROGRESS_BAR_ALI_CONTROLLED)
221 //point is fully alliance's
222 m_PointBarStatus[point] = BG_EY_PROGRESS_BAR_ALI_CONTROLLED;
223 if (m_PointBarStatus[point] < BG_EY_PROGRESS_BAR_HORDE_CONTROLLED)
224 //point is fully horde's
225 m_PointBarStatus[point] = BG_EY_PROGRESS_BAR_HORDE_CONTROLLED;
227 uint32 pointOwnerTeamId = 0;
228 //find which team should own this point
229 if (m_PointBarStatus[point] <= BG_EY_PROGRESS_BAR_NEUTRAL_LOW)
230 pointOwnerTeamId = HORDE;
231 else if (m_PointBarStatus[point] >= BG_EY_PROGRESS_BAR_NEUTRAL_HIGH)
232 pointOwnerTeamId = ALLIANCE;
233 else
234 pointOwnerTeamId = EY_POINT_NO_OWNER;
236 for (uint8 i = 0; i < m_PlayersNearPoint[point].size(); ++i)
238 Player *plr = objmgr.GetPlayer(m_PlayersNearPoint[point][i]);
239 if (plr)
241 UpdateWorldStateForPlayer(PROGRESS_BAR_STATUS, m_PointBarStatus[point], plr);
242 //if point owner changed we must evoke event!
243 if (pointOwnerTeamId != m_PointOwnedByTeam[point])
245 //point was uncontrolled and player is from team which captured point
246 if (m_PointState[point] == EY_POINT_STATE_UNCONTROLLED && plr->GetTeam() == pointOwnerTeamId)
247 EventTeamCapturedPoint(plr, point);
249 //point was under control and player isn't from team which controlled it
250 if (m_PointState[point] == EY_POINT_UNDER_CONTROL && plr->GetTeam() != m_PointOwnedByTeam[point])
251 EventTeamLostPoint(plr, point);
258 void BattleGroundEY::UpdateTeamScore(uint32 Team)
260 uint32 score = GetTeamScore(Team);
261 //TODO there should be some sound played when one team is near victory!! - and define variables
262 /*if (!m_IsInformedNearVictory && score >= BG_EY_WARNING_NEAR_VICTORY_SCORE)
264 if (Team == ALLIANCE)
265 SendMessageToAll(LANG_BG_EY_A_NEAR_VICTORY, CHAT_MSG_BG_SYSTEM_NEUTRAL);
266 else
267 SendMessageToAll(LANG_BG_EY_H_NEAR_VICTORY, CHAT_MSG_BG_SYSTEM_NEUTRAL);
268 PlaySoundToAll(BG_EY_SOUND_NEAR_VICTORY);
269 m_IsInformedNearVictory = true;
272 if (score >= BG_EY_MAX_TEAM_SCORE)
274 score = BG_EY_MAX_TEAM_SCORE;
275 EndBattleGround(Team);
278 if (Team == ALLIANCE)
279 UpdateWorldState(EY_ALLIANCE_RESOURCES, score);
280 else
281 UpdateWorldState(EY_HORDE_RESOURCES, score);
284 void BattleGroundEY::EndBattleGround(uint32 winner)
286 //win reward
287 if (winner == ALLIANCE)
288 RewardHonorToTeam(GetBonusHonorFromKill(1), ALLIANCE);
289 if (winner == HORDE)
290 RewardHonorToTeam(GetBonusHonorFromKill(1), HORDE);
291 //complete map reward
292 RewardHonorToTeam(GetBonusHonorFromKill(1), ALLIANCE);
293 RewardHonorToTeam(GetBonusHonorFromKill(1), HORDE);
295 BattleGround::EndBattleGround(winner);
298 void BattleGroundEY::UpdatePointsCount(uint32 Team)
300 if (Team == ALLIANCE)
301 UpdateWorldState(EY_ALLIANCE_BASE, m_TeamPointsCount[BG_TEAM_ALLIANCE]);
302 else
303 UpdateWorldState(EY_HORDE_BASE, m_TeamPointsCount[BG_TEAM_HORDE]);
306 void BattleGroundEY::UpdatePointsIcons(uint32 Team, uint32 Point)
308 //we MUST firstly send 0, after that we can send 1!!!
309 if (m_PointState[Point] == EY_POINT_UNDER_CONTROL)
311 UpdateWorldState(m_PointsIconStruct[Point].WorldStateControlIndex, 0);
312 if (Team == ALLIANCE)
313 UpdateWorldState(m_PointsIconStruct[Point].WorldStateAllianceControlledIndex, 1);
314 else
315 UpdateWorldState(m_PointsIconStruct[Point].WorldStateHordeControlledIndex, 1);
317 else
319 if (Team == ALLIANCE)
320 UpdateWorldState(m_PointsIconStruct[Point].WorldStateAllianceControlledIndex, 0);
321 else
322 UpdateWorldState(m_PointsIconStruct[Point].WorldStateHordeControlledIndex, 0);
323 UpdateWorldState(m_PointsIconStruct[Point].WorldStateControlIndex, 1);
327 void BattleGroundEY::AddPlayer(Player *plr)
329 BattleGround::AddPlayer(plr);
330 //create score and add it to map
331 BattleGroundEYScore* sc = new BattleGroundEYScore;
333 m_PlayersNearPoint[EY_POINTS_MAX].push_back(plr->GetGUID());
335 m_PlayerScores[plr->GetGUID()] = sc;
338 void BattleGroundEY::RemovePlayer(Player *plr, uint64 guid)
340 // sometimes flag aura not removed :(
341 for (int j = EY_POINTS_MAX; j >= 0; --j)
343 for(size_t i = 0; i < m_PlayersNearPoint[j].size(); ++i)
344 if (m_PlayersNearPoint[j][i] == guid)
345 m_PlayersNearPoint[j].erase(m_PlayersNearPoint[j].begin() + i);
347 if (IsFlagPickedup())
349 if (m_FlagKeeper == guid)
351 if (plr)
352 EventPlayerDroppedFlag(plr);
353 else
355 SetFlagPicker(0);
356 RespawnFlag(true);
362 void BattleGroundEY::HandleAreaTrigger(Player *Source, uint32 Trigger)
364 if (GetStatus() != STATUS_IN_PROGRESS)
365 return;
367 if(!Source->isAlive()) //hack code, must be removed later
368 return;
370 switch(Trigger)
372 case TR_BLOOD_ELF_POINT:
373 if (m_PointState[BLOOD_ELF] == EY_POINT_UNDER_CONTROL && m_PointOwnedByTeam[BLOOD_ELF] == Source->GetTeam())
374 if (m_FlagState && GetFlagPickerGUID() == Source->GetGUID())
375 EventPlayerCapturedFlag(Source, BG_EY_OBJECT_FLAG_BLOOD_ELF);
376 break;
377 case TR_FEL_REALVER_POINT:
378 if (m_PointState[FEL_REALVER] == EY_POINT_UNDER_CONTROL && m_PointOwnedByTeam[FEL_REALVER] == Source->GetTeam())
379 if (m_FlagState && GetFlagPickerGUID() == Source->GetGUID())
380 EventPlayerCapturedFlag(Source, BG_EY_OBJECT_FLAG_FEL_REALVER);
381 break;
382 case TR_MAGE_TOWER_POINT:
383 if (m_PointState[MAGE_TOWER] == EY_POINT_UNDER_CONTROL && m_PointOwnedByTeam[MAGE_TOWER] == Source->GetTeam())
384 if (m_FlagState && GetFlagPickerGUID() == Source->GetGUID())
385 EventPlayerCapturedFlag(Source, BG_EY_OBJECT_FLAG_MAGE_TOWER);
386 break;
387 case TR_DRAENEI_RUINS_POINT:
388 if (m_PointState[DRAENEI_RUINS] == EY_POINT_UNDER_CONTROL && m_PointOwnedByTeam[DRAENEI_RUINS] == Source->GetTeam())
389 if (m_FlagState && GetFlagPickerGUID() == Source->GetGUID())
390 EventPlayerCapturedFlag(Source, BG_EY_OBJECT_FLAG_DRAENEI_RUINS);
391 break;
392 case 4512:
393 case 4515:
394 case 4517:
395 case 4519:
396 case 4530:
397 case 4531:
398 case 4568:
399 case 4569:
400 case 4570:
401 case 4571:
402 break;
403 default:
404 sLog.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", Trigger);
405 Source->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", Trigger);
406 break;
410 bool BattleGroundEY::SetupBattleGround()
412 // doors
413 if (!AddObject(BG_EY_OBJECT_DOOR_A, BG_OBJECT_A_DOOR_EY_ENTRY, 2527.6f, 1596.91f, 1262.13f, -3.12414f, -0.173642f, -0.001515f, 0.98477f, -0.008594f, RESPAWN_IMMEDIATELY)
414 || !AddObject(BG_EY_OBJECT_DOOR_H, BG_OBJECT_H_DOOR_EY_ENTRY, 1803.21f, 1539.49f, 1261.09f, 3.14159f, 0.173648f, 0, 0.984808f, 0, RESPAWN_IMMEDIATELY)
415 // banners (alliance)
416 || !AddObject(BG_EY_OBJECT_A_BANNER_FEL_REALVER_CENTER, BG_OBJECT_A_BANNER_EY_ENTRY, 2057.46f, 1735.07f, 1187.91f, -0.925024f, 0, 0, 0.446198f, -0.894934f, RESPAWN_ONE_DAY)
417 || !AddObject(BG_EY_OBJECT_A_BANNER_FEL_REALVER_LEFT, BG_OBJECT_A_BANNER_EY_ENTRY, 2032.25f, 1729.53f, 1190.33f, 1.8675f, 0, 0, 0.803857f, 0.594823f, RESPAWN_ONE_DAY)
418 || !AddObject(BG_EY_OBJECT_A_BANNER_FEL_REALVER_RIGHT, BG_OBJECT_A_BANNER_EY_ENTRY, 2092.35f, 1775.46f, 1187.08f, -0.401426f, 0, 0, 0.199368f, -0.979925f, RESPAWN_ONE_DAY)
419 || !AddObject(BG_EY_OBJECT_A_BANNER_BLOOD_ELF_CENTER, BG_OBJECT_A_BANNER_EY_ENTRY, 2047.19f, 1349.19f, 1189.0f, -1.62316f, 0, 0, 0.725374f, -0.688354f, RESPAWN_ONE_DAY)
420 || !AddObject(BG_EY_OBJECT_A_BANNER_BLOOD_ELF_LEFT, BG_OBJECT_A_BANNER_EY_ENTRY, 2074.32f, 1385.78f, 1194.72f, 0.488692f, 0, 0, 0.241922f, 0.970296f, RESPAWN_ONE_DAY)
421 || !AddObject(BG_EY_OBJECT_A_BANNER_BLOOD_ELF_RIGHT, BG_OBJECT_A_BANNER_EY_ENTRY, 2025.13f, 1386.12f, 1192.74f, 2.3911f, 0, 0, 0.930418f, 0.366501f, RESPAWN_ONE_DAY)
422 || !AddObject(BG_EY_OBJECT_A_BANNER_DRAENEI_RUINS_CENTER, BG_OBJECT_A_BANNER_EY_ENTRY, 2276.8f, 1400.41f, 1196.33f, 2.44346f, 0, 0, 0.939693f, 0.34202f, RESPAWN_ONE_DAY)
423 || !AddObject(BG_EY_OBJECT_A_BANNER_DRAENEI_RUINS_LEFT, BG_OBJECT_A_BANNER_EY_ENTRY, 2305.78f, 1404.56f, 1199.38f, 1.74533f, 0, 0, 0.766044f, 0.642788f, RESPAWN_ONE_DAY)
424 || !AddObject(BG_EY_OBJECT_A_BANNER_DRAENEI_RUINS_RIGHT, BG_OBJECT_A_BANNER_EY_ENTRY, 2245.4f, 1366.41f, 1195.28f, 2.21657f, 0, 0, 0.894934f, 0.446198f, RESPAWN_ONE_DAY)
425 || !AddObject(BG_EY_OBJECT_A_BANNER_MAGE_TOWER_CENTER, BG_OBJECT_A_BANNER_EY_ENTRY, 2270.84f, 1784.08f, 1186.76f, 2.42601f, 0, 0, 0.936672f, 0.350207f, RESPAWN_ONE_DAY)
426 || !AddObject(BG_EY_OBJECT_A_BANNER_MAGE_TOWER_LEFT, BG_OBJECT_A_BANNER_EY_ENTRY, 2269.13f, 1737.7f, 1186.66f, 0.994838f, 0, 0, 0.477159f, 0.878817f, RESPAWN_ONE_DAY)
427 || !AddObject(BG_EY_OBJECT_A_BANNER_MAGE_TOWER_RIGHT, BG_OBJECT_A_BANNER_EY_ENTRY, 2300.86f, 1741.25f, 1187.7f, -0.785398f, 0, 0, 0.382683f, -0.92388f, RESPAWN_ONE_DAY)
428 // banners (horde)
429 || !AddObject(BG_EY_OBJECT_H_BANNER_FEL_REALVER_CENTER, BG_OBJECT_H_BANNER_EY_ENTRY, 2057.46f, 1735.07f, 1187.91f, -0.925024f, 0, 0, 0.446198f, -0.894934f, RESPAWN_ONE_DAY)
430 || !AddObject(BG_EY_OBJECT_H_BANNER_FEL_REALVER_LEFT, BG_OBJECT_H_BANNER_EY_ENTRY, 2032.25f, 1729.53f, 1190.33f, 1.8675f, 0, 0, 0.803857f, 0.594823f, RESPAWN_ONE_DAY)
431 || !AddObject(BG_EY_OBJECT_H_BANNER_FEL_REALVER_RIGHT, BG_OBJECT_H_BANNER_EY_ENTRY, 2092.35f, 1775.46f, 1187.08f, -0.401426f, 0, 0, 0.199368f, -0.979925f, RESPAWN_ONE_DAY)
432 || !AddObject(BG_EY_OBJECT_H_BANNER_BLOOD_ELF_CENTER, BG_OBJECT_H_BANNER_EY_ENTRY, 2047.19f, 1349.19f, 1189.0f, -1.62316f, 0, 0, 0.725374f, -0.688354f, RESPAWN_ONE_DAY)
433 || !AddObject(BG_EY_OBJECT_H_BANNER_BLOOD_ELF_LEFT, BG_OBJECT_H_BANNER_EY_ENTRY, 2074.32f, 1385.78f, 1194.72f, 0.488692f, 0, 0, 0.241922f, 0.970296f, RESPAWN_ONE_DAY)
434 || !AddObject(BG_EY_OBJECT_H_BANNER_BLOOD_ELF_RIGHT, BG_OBJECT_H_BANNER_EY_ENTRY, 2025.13f, 1386.12f, 1192.74f, 2.3911f, 0, 0, 0.930418f, 0.366501f, RESPAWN_ONE_DAY)
435 || !AddObject(BG_EY_OBJECT_H_BANNER_DRAENEI_RUINS_CENTER, BG_OBJECT_H_BANNER_EY_ENTRY, 2276.8f, 1400.41f, 1196.33f, 2.44346f, 0, 0, 0.939693f, 0.34202f, RESPAWN_ONE_DAY)
436 || !AddObject(BG_EY_OBJECT_H_BANNER_DRAENEI_RUINS_LEFT, BG_OBJECT_H_BANNER_EY_ENTRY, 2305.78f, 1404.56f, 1199.38f, 1.74533f, 0, 0, 0.766044f, 0.642788f, RESPAWN_ONE_DAY)
437 || !AddObject(BG_EY_OBJECT_H_BANNER_DRAENEI_RUINS_RIGHT, BG_OBJECT_H_BANNER_EY_ENTRY, 2245.4f, 1366.41f, 1195.28f, 2.21657f, 0, 0, 0.894934f, 0.446198f, RESPAWN_ONE_DAY)
438 || !AddObject(BG_EY_OBJECT_H_BANNER_MAGE_TOWER_CENTER, BG_OBJECT_H_BANNER_EY_ENTRY, 2270.84f, 1784.08f, 1186.76f, 2.42601f, 0, 0, 0.936672f, 0.350207f, RESPAWN_ONE_DAY)
439 || !AddObject(BG_EY_OBJECT_H_BANNER_MAGE_TOWER_LEFT, BG_OBJECT_H_BANNER_EY_ENTRY, 2269.13f, 1737.7f, 1186.66f, 0.994838f, 0, 0, 0.477159f, 0.878817f, RESPAWN_ONE_DAY)
440 || !AddObject(BG_EY_OBJECT_H_BANNER_MAGE_TOWER_RIGHT, BG_OBJECT_H_BANNER_EY_ENTRY, 2300.86f, 1741.25f, 1187.7f, -0.785398f, 0, 0, 0.382683f, -0.92388f, RESPAWN_ONE_DAY)
441 // banners (natural)
442 || !AddObject(BG_EY_OBJECT_N_BANNER_FEL_REALVER_CENTER, BG_OBJECT_N_BANNER_EY_ENTRY, 2057.46f, 1735.07f, 1187.91f, -0.925024f, 0, 0, 0.446198f, -0.894934f, RESPAWN_ONE_DAY)
443 || !AddObject(BG_EY_OBJECT_N_BANNER_FEL_REALVER_LEFT, BG_OBJECT_N_BANNER_EY_ENTRY, 2032.25f, 1729.53f, 1190.33f, 1.8675f, 0, 0, 0.803857f, 0.594823f, RESPAWN_ONE_DAY)
444 || !AddObject(BG_EY_OBJECT_N_BANNER_FEL_REALVER_RIGHT, BG_OBJECT_N_BANNER_EY_ENTRY, 2092.35f, 1775.46f, 1187.08f, -0.401426f, 0, 0, 0.199368f, -0.979925f, RESPAWN_ONE_DAY)
445 || !AddObject(BG_EY_OBJECT_N_BANNER_BLOOD_ELF_CENTER, BG_OBJECT_N_BANNER_EY_ENTRY, 2047.19f, 1349.19f, 1189.0f, -1.62316f, 0, 0, 0.725374f, -0.688354f, RESPAWN_ONE_DAY)
446 || !AddObject(BG_EY_OBJECT_N_BANNER_BLOOD_ELF_LEFT, BG_OBJECT_N_BANNER_EY_ENTRY, 2074.32f, 1385.78f, 1194.72f, 0.488692f, 0, 0, 0.241922f, 0.970296f, RESPAWN_ONE_DAY)
447 || !AddObject(BG_EY_OBJECT_N_BANNER_BLOOD_ELF_RIGHT, BG_OBJECT_N_BANNER_EY_ENTRY, 2025.13f, 1386.12f, 1192.74f, 2.3911f, 0, 0, 0.930418f, 0.366501f, RESPAWN_ONE_DAY)
448 || !AddObject(BG_EY_OBJECT_N_BANNER_DRAENEI_RUINS_CENTER, BG_OBJECT_N_BANNER_EY_ENTRY, 2276.8f, 1400.41f, 1196.33f, 2.44346f, 0, 0, 0.939693f, 0.34202f, RESPAWN_ONE_DAY)
449 || !AddObject(BG_EY_OBJECT_N_BANNER_DRAENEI_RUINS_LEFT, BG_OBJECT_N_BANNER_EY_ENTRY, 2305.78f, 1404.56f, 1199.38f, 1.74533f, 0, 0, 0.766044f, 0.642788f, RESPAWN_ONE_DAY)
450 || !AddObject(BG_EY_OBJECT_N_BANNER_DRAENEI_RUINS_RIGHT, BG_OBJECT_N_BANNER_EY_ENTRY, 2245.4f, 1366.41f, 1195.28f, 2.21657f, 0, 0, 0.894934f, 0.446198f, RESPAWN_ONE_DAY)
451 || !AddObject(BG_EY_OBJECT_N_BANNER_MAGE_TOWER_CENTER, BG_OBJECT_N_BANNER_EY_ENTRY, 2270.84f, 1784.08f, 1186.76f, 2.42601f, 0, 0, 0.936672f, 0.350207f, RESPAWN_ONE_DAY)
452 || !AddObject(BG_EY_OBJECT_N_BANNER_MAGE_TOWER_LEFT, BG_OBJECT_N_BANNER_EY_ENTRY, 2269.13f, 1737.7f, 1186.66f, 0.994838f, 0, 0, 0.477159f, 0.878817f, RESPAWN_ONE_DAY)
453 || !AddObject(BG_EY_OBJECT_N_BANNER_MAGE_TOWER_RIGHT, BG_OBJECT_N_BANNER_EY_ENTRY, 2300.86f, 1741.25f, 1187.7f, -0.785398f, 0, 0, 0.382683f, -0.92388f, RESPAWN_ONE_DAY)
454 // flags
455 || !AddObject(BG_EY_OBJECT_FLAG_NETHERSTORM, BG_OBJECT_FLAG2_EY_ENTRY, 2174.782227f, 1569.054688f, 1160.361938f, -1.448624f, 0, 0, 0.662620f, -0.748956f, RESPAWN_ONE_DAY)
456 || !AddObject(BG_EY_OBJECT_FLAG_FEL_REALVER, BG_OBJECT_FLAG1_EY_ENTRY, 2044.28f, 1729.68f, 1189.96f, -0.017453f, 0, 0, 0.008727f, -0.999962f, RESPAWN_ONE_DAY)
457 || !AddObject(BG_EY_OBJECT_FLAG_BLOOD_ELF, BG_OBJECT_FLAG1_EY_ENTRY, 2048.83f, 1393.65f, 1194.49f, 0.20944f, 0, 0, 0.104528f, 0.994522f, RESPAWN_ONE_DAY)
458 || !AddObject(BG_EY_OBJECT_FLAG_DRAENEI_RUINS, BG_OBJECT_FLAG1_EY_ENTRY, 2286.56f, 1402.36f, 1197.11f, 3.72381f, 0, 0, 0.957926f, -0.287016f, RESPAWN_ONE_DAY)
459 || !AddObject(BG_EY_OBJECT_FLAG_MAGE_TOWER, BG_OBJECT_FLAG1_EY_ENTRY, 2284.48f, 1731.23f, 1189.99f, 2.89725f, 0, 0, 0.992546f, 0.121869f, RESPAWN_ONE_DAY)
460 // tower cap
461 || !AddObject(BG_EY_OBJECT_TOWER_CAP_FEL_REALVER, BG_OBJECT_FR_TOWER_CAP_EY_ENTRY, 2024.600708f, 1742.819580f, 1195.157715f, 2.443461f, 0, 0, 0.939693f, 0.342020f, RESPAWN_ONE_DAY)
462 || !AddObject(BG_EY_OBJECT_TOWER_CAP_BLOOD_ELF, BG_OBJECT_BE_TOWER_CAP_EY_ENTRY, 2050.493164f, 1372.235962f, 1194.563477f, 1.710423f, 0, 0, 0.754710f, 0.656059f, RESPAWN_ONE_DAY)
463 || !AddObject(BG_EY_OBJECT_TOWER_CAP_DRAENEI_RUINS, BG_OBJECT_DR_TOWER_CAP_EY_ENTRY, 2301.010498f, 1386.931641f, 1197.183472f, 1.570796f, 0, 0, 0.707107f, 0.707107f, RESPAWN_ONE_DAY)
464 || !AddObject(BG_EY_OBJECT_TOWER_CAP_MAGE_TOWER, BG_OBJECT_HU_TOWER_CAP_EY_ENTRY, 2282.121582f, 1760.006958f, 1189.707153f, 1.919862f, 0, 0, 0.819152f, 0.573576f, RESPAWN_ONE_DAY)
467 sLog.outErrorDb("BatteGroundEY: Failed to spawn some object BattleGround not created!");
468 return false;
471 //buffs
472 for (int i = 0; i < EY_POINTS_MAX; ++i)
474 AreaTriggerEntry const* at = sAreaTriggerStore.LookupEntry(m_Points_Trigger[i]);
475 if (!at)
477 sLog.outError("BattleGroundEY: Unknown trigger: %u", m_Points_Trigger[i]);
478 continue;
480 if (!AddObject(BG_EY_OBJECT_SPEEDBUFF_FEL_REALVER + i * 3, Buff_Entries[0], at->x, at->y, at->z, 0.907571f, 0, 0, 0.438371f, 0.898794f, RESPAWN_ONE_DAY)
481 || !AddObject(BG_EY_OBJECT_SPEEDBUFF_FEL_REALVER + i * 3 + 1, Buff_Entries[1], at->x, at->y, at->z, 0.907571f, 0, 0, 0.438371f, 0.898794f, RESPAWN_ONE_DAY)
482 || !AddObject(BG_EY_OBJECT_SPEEDBUFF_FEL_REALVER + i * 3 + 2, Buff_Entries[2], at->x, at->y, at->z, 0.907571f, 0, 0, 0.438371f, 0.898794f, RESPAWN_ONE_DAY)
484 sLog.outError("BattleGroundEY: Cannot spawn buff");
487 WorldSafeLocsEntry const *sg = NULL;
488 sg = sWorldSafeLocsStore.LookupEntry(EY_GRAVEYARD_MAIN_ALLIANCE);
489 if (!sg || !AddSpiritGuide(EY_SPIRIT_MAIN_ALLIANCE, sg->x, sg->y, sg->z, 3.124139f, ALLIANCE))
491 sLog.outErrorDb("BatteGroundEY: Failed to spawn spirit guide! BattleGround not created!");
492 return false;
495 sg = sWorldSafeLocsStore.LookupEntry(EY_GRAVEYARD_MAIN_HORDE);
496 if (!sg || !AddSpiritGuide(EY_SPIRIT_MAIN_HORDE, sg->x, sg->y, sg->z, 3.193953f, HORDE))
498 sLog.outErrorDb("BatteGroundEY: Failed to spawn spirit guide! BattleGround not created!");
499 return false;
502 return true;
505 void BattleGroundEY::Reset()
507 //call parent's class reset
508 BattleGround::Reset();
510 m_TeamScores[BG_TEAM_ALLIANCE] = 0;
511 m_TeamScores[BG_TEAM_HORDE] = 0;
512 m_TeamPointsCount[BG_TEAM_ALLIANCE] = 0;
513 m_TeamPointsCount[BG_TEAM_HORDE] = 0;
514 m_HonorScoreTics[BG_TEAM_ALLIANCE] = 0;
515 m_HonorScoreTics[BG_TEAM_HORDE] = 0;
516 m_FlagState = BG_EY_FLAG_STATE_ON_BASE;
517 m_FlagCapturedBgObjectType = 0;
518 m_FlagKeeper = 0;
519 m_DroppedFlagGUID = 0;
520 m_PointAddingTimer = 0;
521 m_TowerCapCheckTimer = 0;
522 bool isBGWeekend = false; //TODO FIXME - call sBattleGroundMgr.IsBGWeekend(m_TypeID); - you must also implement that call!
523 m_HonorTics = (isBGWeekend) ? BG_EY_EYWeekendHonorTicks : BG_EY_NotEYWeekendHonorTicks;
525 for(uint8 i = 0; i < EY_POINTS_MAX; ++i)
527 m_PointOwnedByTeam[i] = EY_POINT_NO_OWNER;
528 m_PointState[i] = EY_POINT_STATE_UNCONTROLLED;
529 m_PointBarStatus[i] = BG_EY_PROGRESS_BAR_STATE_MIDDLE;
530 m_PlayersNearPoint[i].clear();
531 m_PlayersNearPoint[i].reserve(15); //tip size
533 m_PlayersNearPoint[EY_PLAYERS_OUT_OF_POINTS].clear();
534 m_PlayersNearPoint[EY_PLAYERS_OUT_OF_POINTS].reserve(30);
537 void BattleGroundEY::RespawnFlag(bool send_message)
539 if (m_FlagCapturedBgObjectType > 0)
540 SpawnBGObject(m_FlagCapturedBgObjectType, RESPAWN_ONE_DAY);
542 m_FlagCapturedBgObjectType = 0;
543 m_FlagState = BG_EY_FLAG_STATE_ON_BASE;
544 SpawnBGObject(BG_EY_OBJECT_FLAG_NETHERSTORM, RESPAWN_IMMEDIATELY);
546 if (send_message)
548 SendMessageToAll(LANG_BG_EY_RESETED_FLAG, CHAT_MSG_BG_SYSTEM_NEUTRAL);
549 PlaySoundToAll(BG_EY_SOUND_FLAG_RESET); // flags respawned sound...
552 UpdateWorldState(NETHERSTORM_FLAG, 1);
555 void BattleGroundEY::RespawnFlagAfterDrop()
557 RespawnFlag(true);
559 GameObject *obj = HashMapHolder<GameObject>::Find(GetDroppedFlagGUID());
560 if (obj)
561 obj->Delete();
562 else
563 sLog.outError("BattleGroundEY: Unknown dropped flag guid: %u",GUID_LOPART(GetDroppedFlagGUID()));
565 SetDroppedFlagGUID(0);
568 void BattleGroundEY::HandleKillPlayer(Player *player, Player *killer)
570 if (GetStatus() != STATUS_IN_PROGRESS)
571 return;
573 BattleGround::HandleKillPlayer(player, killer);
574 EventPlayerDroppedFlag(player);
577 void BattleGroundEY::EventPlayerDroppedFlag(Player *Source)
579 if (GetStatus() != STATUS_IN_PROGRESS)
581 // if not running, do not cast things at the dropper player, neither send unnecessary messages
582 // just take off the aura
583 if (IsFlagPickedup() && GetFlagPickerGUID() == Source->GetGUID())
585 SetFlagPicker(0);
586 Source->RemoveAurasDueToSpell(BG_EY_NETHERSTORM_FLAG_SPELL);
588 return;
591 if (!IsFlagPickedup())
592 return;
594 if (GetFlagPickerGUID() != Source->GetGUID())
595 return;
597 SetFlagPicker(0);
598 Source->RemoveAurasDueToSpell(BG_EY_NETHERSTORM_FLAG_SPELL);
599 m_FlagState = BG_EY_FLAG_STATE_ON_GROUND;
600 m_FlagsTimer = BG_EY_FLAG_RESPAWN_TIME;
601 Source->CastSpell(Source, SPELL_RECENTLY_DROPPED_FLAG, true);
602 Source->CastSpell(Source, BG_EY_PLAYER_DROPPED_FLAG_SPELL, true);
603 //this does not work correctly :( (it should remove flag carrier name)
604 UpdateWorldState(NETHERSTORM_FLAG_STATE_HORDE, BG_EY_FLAG_STATE_WAIT_RESPAWN);
605 UpdateWorldState(NETHERSTORM_FLAG_STATE_ALLIANCE, BG_EY_FLAG_STATE_WAIT_RESPAWN);
607 if (Source->GetTeam() == ALLIANCE)
608 SendMessageToAll(LANG_BG_EY_DROPPED_FLAG, CHAT_MSG_BG_SYSTEM_ALLIANCE, NULL);
609 else
610 SendMessageToAll(LANG_BG_EY_DROPPED_FLAG, CHAT_MSG_BG_SYSTEM_HORDE, NULL);
613 void BattleGroundEY::EventPlayerClickedOnFlag(Player *Source, GameObject* target_obj)
615 if (GetStatus() != STATUS_IN_PROGRESS || IsFlagPickedup() || !Source->IsWithinDistInMap(target_obj, 10))
616 return;
618 if (Source->GetTeam() == ALLIANCE)
620 UpdateWorldState(NETHERSTORM_FLAG_STATE_ALLIANCE, BG_EY_FLAG_STATE_ON_PLAYER);
621 PlaySoundToAll(BG_EY_SOUND_FLAG_PICKED_UP_ALLIANCE);
623 else
625 UpdateWorldState(NETHERSTORM_FLAG_STATE_HORDE, BG_EY_FLAG_STATE_ON_PLAYER);
626 PlaySoundToAll(BG_EY_SOUND_FLAG_PICKED_UP_HORDE);
629 if (m_FlagState == BG_EY_FLAG_STATE_ON_BASE)
630 UpdateWorldState(NETHERSTORM_FLAG, 0);
631 m_FlagState = BG_EY_FLAG_STATE_ON_PLAYER;
633 SpawnBGObject(BG_EY_OBJECT_FLAG_NETHERSTORM, RESPAWN_ONE_DAY);
634 SetFlagPicker(Source->GetGUID());
635 //get flag aura on player
636 Source->CastSpell(Source, BG_EY_NETHERSTORM_FLAG_SPELL, true);
637 Source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
639 if (Source->GetTeam() == ALLIANCE)
640 PSendMessageToAll(LANG_BG_EY_HAS_TAKEN_FLAG, CHAT_MSG_BG_SYSTEM_ALLIANCE, NULL, Source->GetName());
641 else
642 PSendMessageToAll(LANG_BG_EY_HAS_TAKEN_FLAG, CHAT_MSG_BG_SYSTEM_HORDE, NULL, Source->GetName());
645 void BattleGroundEY::EventTeamLostPoint(Player *Source, uint32 Point)
647 if (GetStatus() != STATUS_IN_PROGRESS)
648 return;
650 //Natural point
651 uint32 Team = m_PointOwnedByTeam[Point];
653 if (!Team)
654 return;
656 if (Team == ALLIANCE)
658 m_TeamPointsCount[BG_TEAM_ALLIANCE]--;
659 SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeAlliance, RESPAWN_ONE_DAY);
660 SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeAlliance + 1, RESPAWN_ONE_DAY);
661 SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeAlliance + 2, RESPAWN_ONE_DAY);
663 else
665 m_TeamPointsCount[BG_TEAM_HORDE]--;
666 SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeHorde, RESPAWN_ONE_DAY);
667 SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeHorde + 1, RESPAWN_ONE_DAY);
668 SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeHorde + 2, RESPAWN_ONE_DAY);
671 SpawnBGObject(m_LoosingPointTypes[Point].SpawnNeutralObjectType, RESPAWN_IMMEDIATELY);
672 SpawnBGObject(m_LoosingPointTypes[Point].SpawnNeutralObjectType + 1, RESPAWN_IMMEDIATELY);
673 SpawnBGObject(m_LoosingPointTypes[Point].SpawnNeutralObjectType + 2, RESPAWN_IMMEDIATELY);
675 //buff isn't despawned
677 m_PointOwnedByTeam[Point] = EY_POINT_NO_OWNER;
678 m_PointState[Point] = EY_POINT_NO_OWNER;
680 if (Team == ALLIANCE)
681 SendMessageToAll(m_LoosingPointTypes[Point].MessageIdAlliance,CHAT_MSG_BG_SYSTEM_ALLIANCE, Source);
682 else
683 SendMessageToAll(m_LoosingPointTypes[Point].MessageIdHorde,CHAT_MSG_BG_SYSTEM_HORDE, Source);
685 UpdatePointsIcons(Team, Point);
686 UpdatePointsCount(Team);
689 void BattleGroundEY::EventTeamCapturedPoint(Player *Source, uint32 Point)
691 if (GetStatus() != STATUS_IN_PROGRESS)
692 return;
694 uint32 Team = Source->GetTeam();
696 SpawnBGObject(m_CapturingPointTypes[Point].DespawnNeutralObjectType, RESPAWN_ONE_DAY);
697 SpawnBGObject(m_CapturingPointTypes[Point].DespawnNeutralObjectType + 1, RESPAWN_ONE_DAY);
698 SpawnBGObject(m_CapturingPointTypes[Point].DespawnNeutralObjectType + 2, RESPAWN_ONE_DAY);
700 if (Team == ALLIANCE)
702 m_TeamPointsCount[BG_TEAM_ALLIANCE]++;
703 SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeAlliance, RESPAWN_IMMEDIATELY);
704 SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeAlliance + 1, RESPAWN_IMMEDIATELY);
705 SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeAlliance + 2, RESPAWN_IMMEDIATELY);
707 else
709 m_TeamPointsCount[BG_TEAM_HORDE]++;
710 SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeHorde, RESPAWN_IMMEDIATELY);
711 SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeHorde + 1, RESPAWN_IMMEDIATELY);
712 SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeHorde + 2, RESPAWN_IMMEDIATELY);
715 //buff isn't respawned
717 m_PointOwnedByTeam[Point] = Team;
718 m_PointState[Point] = EY_POINT_UNDER_CONTROL;
720 if (Team == ALLIANCE)
721 SendMessageToAll(m_CapturingPointTypes[Point].MessageIdAlliance,CHAT_MSG_BG_SYSTEM_ALLIANCE, Source);
722 else
723 SendMessageToAll(m_CapturingPointTypes[Point].MessageIdHorde,CHAT_MSG_BG_SYSTEM_HORDE, Source);
725 if (m_BgCreatures[Point])
726 DelCreature(Point);
728 WorldSafeLocsEntry const *sg = NULL;
729 sg = sWorldSafeLocsStore.LookupEntry(m_CapturingPointTypes[Point].GraveYardId);
730 if (!sg || !AddSpiritGuide(Point, sg->x, sg->y, sg->z, 3.124139f, Team))
731 sLog.outError("BatteGroundEY: Failed to spawn spirit guide! point: %u, team: %u, graveyard_id: %u",
732 Point, Team, m_CapturingPointTypes[Point].GraveYardId);
734 // SpawnBGCreature(Point,RESPAWN_IMMEDIATELY);
736 UpdatePointsIcons(Team, Point);
737 UpdatePointsCount(Team);
740 void BattleGroundEY::EventPlayerCapturedFlag(Player *Source, uint32 BgObjectType)
742 if (GetStatus() != STATUS_IN_PROGRESS || GetFlagPickerGUID() != Source->GetGUID())
743 return;
745 SetFlagPicker(0);
746 m_FlagState = BG_EY_FLAG_STATE_WAIT_RESPAWN;
747 Source->RemoveAurasDueToSpell(BG_EY_NETHERSTORM_FLAG_SPELL);
749 Source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
751 if (Source->GetTeam() == ALLIANCE)
752 PlaySoundToAll(BG_EY_SOUND_FLAG_CAPTURED_ALLIANCE);
753 else
754 PlaySoundToAll(BG_EY_SOUND_FLAG_CAPTURED_HORDE);
756 SpawnBGObject(BgObjectType, RESPAWN_IMMEDIATELY);
758 m_FlagsTimer = BG_EY_FLAG_RESPAWN_TIME;
759 m_FlagCapturedBgObjectType = BgObjectType;
761 uint8 team_id = 0;
762 if (Source->GetTeam() == ALLIANCE)
764 team_id = BG_TEAM_ALLIANCE;
765 SendMessageToAll(LANG_BG_EY_CAPTURED_FLAG_A, CHAT_MSG_BG_SYSTEM_ALLIANCE, Source);
767 else
769 team_id = BG_TEAM_HORDE;
770 SendMessageToAll(LANG_BG_EY_CAPTURED_FLAG_H, CHAT_MSG_BG_SYSTEM_HORDE, Source);
773 if (m_TeamPointsCount[team_id] > 0)
774 AddPoints(Source->GetTeam(), BG_EY_FlagPoints[m_TeamPointsCount[team_id] - 1]);
776 UpdatePlayerScore(Source, SCORE_FLAG_CAPTURES, 1);
779 void BattleGroundEY::UpdatePlayerScore(Player *Source, uint32 type, uint32 value)
781 std::map<uint64, BattleGroundScore*>::iterator itr = m_PlayerScores.find(Source->GetGUID());
783 if(itr == m_PlayerScores.end()) // player not found
784 return;
786 switch(type)
788 case SCORE_FLAG_CAPTURES: // flags captured
789 ((BattleGroundEYScore*)itr->second)->FlagCaptures += value;
790 break;
791 default:
792 BattleGround::UpdatePlayerScore(Source, type, value);
793 break;
797 void BattleGroundEY::FillInitialWorldStates(WorldPacket& data)
799 data << uint32(EY_HORDE_BASE) << uint32(m_TeamPointsCount[BG_TEAM_HORDE]);
800 data << uint32(EY_ALLIANCE_BASE) << uint32(m_TeamPointsCount[BG_TEAM_ALLIANCE]);
801 data << uint32(0xab6) << uint32(0x0);
802 data << uint32(0xab5) << uint32(0x0);
803 data << uint32(0xab4) << uint32(0x0);
804 data << uint32(0xab3) << uint32(0x0);
805 data << uint32(0xab2) << uint32(0x0);
806 data << uint32(0xab1) << uint32(0x0);
807 data << uint32(0xab0) << uint32(0x0);
808 data << uint32(0xaaf) << uint32(0x0);
810 data << uint32(DRAENEI_RUINS_HORDE_CONTROL) << uint32(m_PointOwnedByTeam[DRAENEI_RUINS] == HORDE && m_PointState[DRAENEI_RUINS] == EY_POINT_UNDER_CONTROL);
812 data << uint32(DRAENEI_RUINS_ALLIANCE_CONTROL) << uint32(m_PointOwnedByTeam[DRAENEI_RUINS] == ALLIANCE && m_PointState[DRAENEI_RUINS] == EY_POINT_UNDER_CONTROL);
814 data << uint32(DRAENEI_RUINS_UNCONTROL) << uint32(m_PointState[DRAENEI_RUINS] != EY_POINT_UNDER_CONTROL);
816 data << uint32(MAGE_TOWER_ALLIANCE_CONTROL) << uint32(m_PointOwnedByTeam[MAGE_TOWER] == ALLIANCE && m_PointState[MAGE_TOWER] == EY_POINT_UNDER_CONTROL);
818 data << uint32(MAGE_TOWER_HORDE_CONTROL) << uint32(m_PointOwnedByTeam[MAGE_TOWER] == HORDE && m_PointState[MAGE_TOWER] == EY_POINT_UNDER_CONTROL);
820 data << uint32(MAGE_TOWER_UNCONTROL) << uint32(m_PointState[MAGE_TOWER] != EY_POINT_UNDER_CONTROL);
822 data << uint32(FEL_REAVER_HORDE_CONTROL) << uint32(m_PointOwnedByTeam[FEL_REALVER] == HORDE && m_PointState[FEL_REALVER] == EY_POINT_UNDER_CONTROL);
824 data << uint32(FEL_REAVER_ALLIANCE_CONTROL) << uint32(m_PointOwnedByTeam[FEL_REALVER] == ALLIANCE && m_PointState[FEL_REALVER] == EY_POINT_UNDER_CONTROL);
826 data << uint32(FEL_REAVER_UNCONTROL) << uint32(m_PointState[FEL_REALVER] != EY_POINT_UNDER_CONTROL);
828 data << uint32(BLOOD_ELF_HORDE_CONTROL) << uint32(m_PointOwnedByTeam[BLOOD_ELF] == HORDE && m_PointState[BLOOD_ELF] == EY_POINT_UNDER_CONTROL);
830 data << uint32(BLOOD_ELF_ALLIANCE_CONTROL) << uint32(m_PointOwnedByTeam[BLOOD_ELF] == ALLIANCE && m_PointState[BLOOD_ELF] == EY_POINT_UNDER_CONTROL);
832 data << uint32(BLOOD_ELF_UNCONTROL) << uint32(m_PointState[BLOOD_ELF] != EY_POINT_UNDER_CONTROL);
834 data << uint32(NETHERSTORM_FLAG) << uint32(m_FlagState == BG_EY_FLAG_STATE_ON_BASE);
836 data << uint32(0xad2) << uint32(0x1);
837 data << uint32(0xad1) << uint32(0x1);
838 data << uint32(0xabe) << uint32(GetTeamScore(HORDE));
839 data << uint32(0xabd) << uint32(GetTeamScore(ALLIANCE));
840 data << uint32(0xa05) << uint32(0x8e);
841 data << uint32(0xaa0) << uint32(0x0);
842 data << uint32(0xa9f) << uint32(0x0);
843 data << uint32(0xa9e) << uint32(0x0);
844 data << uint32(0xc0d) << uint32(0x17b);
847 WorldSafeLocsEntry const *BattleGroundEY::GetClosestGraveYard(Player* player)
849 uint32 g_id = 0;
851 switch(player->GetTeam())
853 case ALLIANCE: g_id = EY_GRAVEYARD_MAIN_ALLIANCE; break;
854 case HORDE: g_id = EY_GRAVEYARD_MAIN_HORDE; break;
855 default: return NULL;
858 float distance, nearestDistance;
860 WorldSafeLocsEntry const* entry = NULL;
861 WorldSafeLocsEntry const* nearestEntry = NULL;
862 entry = sWorldSafeLocsStore.LookupEntry(g_id);
863 nearestEntry = entry;
865 if (!entry)
867 sLog.outError("BattleGroundEY: Not found the main team graveyard. Graveyard system isn't working!");
868 return NULL;
871 float plr_x = player->GetPositionX();
872 float plr_y = player->GetPositionY();
873 float plr_z = player->GetPositionZ();
876 distance = (entry->x - plr_x)*(entry->x - plr_x) + (entry->y - plr_y)*(entry->y - plr_y) + (entry->z - plr_z)*(entry->z - plr_z);
877 nearestDistance = distance;
879 for(uint8 i = 0; i < EY_POINTS_MAX; ++i)
881 if (m_PointOwnedByTeam[i]==player->GetTeam() && m_PointState[i]==EY_POINT_UNDER_CONTROL)
883 entry = sWorldSafeLocsStore.LookupEntry(m_CapturingPointTypes[i].GraveYardId);
884 if (!entry)
885 sLog.outError("BattleGroundEY: Not found graveyard: %u",m_CapturingPointTypes[i].GraveYardId);
886 else
888 distance = (entry->x - plr_x)*(entry->x - plr_x) + (entry->y - plr_y)*(entry->y - plr_y) + (entry->z - plr_z)*(entry->z - plr_z);
889 if (distance < nearestDistance)
891 nearestDistance = distance;
892 nearestEntry = entry;
898 return nearestEntry;