OregonCore  revision fb2a440-git
Your Favourite TBC server
BattlegroundEY.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "Object.h"
19 #include "Player.h"
20 #include "Battleground.h"
21 #include "BattlegroundEY.h"
22 #include "Creature.h"
23 #include "ObjectMgr.h"
24 #include "MapManager.h"
25 #include "Language.h"
26 #include "Utilities/Util.h"
27 
28 // these variables aren't used outside of this file, so declare them only here
30 {
31  330, // normal honor
32  200 // holiday
33 };
34 
36 {
37  m_BuffChange = true;
44 
49 }
50 
52 {
53 }
54 
56 {
58  // after bg start we get there (once)
60  {
61  m_PointAddingTimer -= diff;
62  if (m_PointAddingTimer <= 0)
63  {
69  }
70 
72  {
73  m_FlagsTimer -= diff;
74 
75  if (m_FlagsTimer < 0)
76  {
77  m_FlagsTimer = 0;
79  RespawnFlag(true);
80  else
82  }
83  }
84 
85  m_TowerCapCheckTimer -= diff;
86  if (m_TowerCapCheckTimer <= 0)
87  {
88  //check if player joined point
89  /*I used this order of calls, because although we will check if one player is in gameobject's distance 2 times
90  but we can count of players on current point in CheckSomeoneLeftPoint
91  */
93  //check if player left point
97  }
98  }
99 }
100 
102 {
105 
108 }
109 
111 {
114 
117  for (uint32 i = 0; i < EY_POINTS_MAX; ++i)
118  {
119  //randomly spawn buff
120  uint8 buff = urand(0, 2);
122  }
123 }
124 
126 {
127  uint8 team_index = GetTeamIndexByTeamId(Team);
128  m_TeamScores[team_index] += Points;
129  m_score[team_index] = m_TeamScores[team_index];
130  m_HonorScoreTics[team_index] += Points;
132  {
133  RewardHonorToTeam(20, Team);
135  }
136  UpdateTeamScore(Team);
137 }
138 
140 {
141  GameObject* obj = NULL;
142  for (uint8 i = 0; i < EY_POINTS_MAX; ++i)
143  {
145  if (obj)
146  {
147  uint8 j = 0;
148  while (j < m_PlayersNearPoint[EY_POINTS_MAX].size())
149  {
150  Player* plr = sObjectMgr.GetPlayer(m_PlayersNearPoint[EY_POINTS_MAX][j]);
151  if (plr && plr->CanCaptureTowerPoint() && plr->IsWithinDistInMap(obj, BG_EY_POINT_RADIUS))
152  {
153  //player joined point!
154  //show progress bar
158  //add player to point
159  m_PlayersNearPoint[i].push_back(m_PlayersNearPoint[EY_POINTS_MAX][j]);
160  //remove player from "free space"
161  m_PlayersNearPoint[EY_POINTS_MAX].erase(m_PlayersNearPoint[EY_POINTS_MAX].begin() + j);
162  }
163  else
164  ++j;
165  }
166  }
167  }
168 }
169 
171 {
172  //reset current point counts
173  for (uint8 i = 0; i < 2 * EY_POINTS_MAX; ++i)
175  GameObject* obj = NULL;
176  for (uint8 i = 0; i < EY_POINTS_MAX; ++i)
177  {
179  if (obj)
180  {
181  uint8 j = 0;
182  while (j < m_PlayersNearPoint[i].size())
183  {
184  Player* plr = sObjectMgr.GetPlayer(m_PlayersNearPoint[i][j]);
185  if (!plr)
186  {
187  sLog.outError("BattlegroundEY: Player (GUID: %u) not found!", GUID_LOPART(m_PlayersNearPoint[i][j]));
188  //move not existed player to "free space" - this will cause many error showing in log, but it is a very important bug
190  m_PlayersNearPoint[i].erase(m_PlayersNearPoint[i].begin() + j);
191  ++j;
192  continue;
193  }
194  if (!plr->CanCaptureTowerPoint() || !plr->IsWithinDistInMap(obj, BG_EY_POINT_RADIUS))
195  //move player out of point (add him to players that are out of points
196  {
198  m_PlayersNearPoint[i].erase(m_PlayersNearPoint[i].begin() + j);
200  }
201  else
202  {
203  //player is neat flag, so update count:
205  ++j;
206  }
207  }
208  }
209  }
210 }
211 
213 {
214  for (uint8 point = 0; point < EY_POINTS_MAX; ++point)
215  {
216  if (m_PlayersNearPoint[point].empty())
217  continue;
218  //count new point bar status:
220 
222  //point is fully alliance's
225  //point is fully horde's
227 
228  uint32 pointOwnerTeamId = 0;
229  //find which team should own this point
231  pointOwnerTeamId = HORDE;
233  pointOwnerTeamId = ALLIANCE;
234  else
235  pointOwnerTeamId = EY_POINT_NO_OWNER;
236 
237  for (uint8 i = 0; i < m_PlayersNearPoint[point].size(); ++i)
238  {
239  Player* plr = sObjectMgr.GetPlayer(m_PlayersNearPoint[point][i]);
240  if (plr)
241  {
243  //if point owner changed we must evoke event!
244  if (pointOwnerTeamId != m_PointOwnedByTeam[point])
245  {
246  //point was uncontrolled and player is from team which captured point
247  if (m_PointState[point] == EY_POINT_STATE_UNCONTROLLED && plr->GetTeam() == pointOwnerTeamId)
248  this->EventTeamCapturedPoint(plr, point);
249 
250  //point was under control and player isn't from team which controlled it
251  if (m_PointState[point] == EY_POINT_UNDER_CONTROL && plr->GetTeam() != m_PointOwnedByTeam[point])
252  this->EventTeamLostPoint(plr, point);
253  }
254  }
255  }
256  }
257 }
258 
260 {
261  uint32 score = GetTeamScore(Team);
262  if (score >= EY_MAX_TEAM_SCORE)
263  {
264  score = EY_MAX_TEAM_SCORE;
265  EndBattleground(Team);
266  }
267 
268  if (Team == ALLIANCE)
270  else
272 }
273 
275 {
276  if (Team == ALLIANCE)
278  else
280 }
281 
283 {
284  //we MUST firstly send 0, after that we can send 1!!!
285  if (m_PointState[Point] == EY_POINT_UNDER_CONTROL)
286  {
287  UpdateWorldState(m_PointsIconStruct[Point].WorldStateControlIndex, 0);
288  if (Team == ALLIANCE)
289  UpdateWorldState(m_PointsIconStruct[Point].WorldStateAllianceControlledIndex, 1);
290  else
291  UpdateWorldState(m_PointsIconStruct[Point].WorldStateHordeControlledIndex, 1);
292  }
293  else
294  {
295  if (Team == ALLIANCE)
296  UpdateWorldState(m_PointsIconStruct[Point].WorldStateAllianceControlledIndex, 0);
297  else
298  UpdateWorldState(m_PointsIconStruct[Point].WorldStateHordeControlledIndex, 0);
299  UpdateWorldState(m_PointsIconStruct[Point].WorldStateControlIndex, 1);
300  }
301 }
302 
304 {
306  //create score and add it to map
308 
309  m_PlayersNearPoint[EY_POINTS_MAX].push_back(plr->GetGUID());
310 
311  m_PlayerScores[plr->GetGUID()] = sc;
312 }
313 
315 {
316  // sometimes flag aura not removed :(
317  for (int j = EY_POINTS_MAX; j >= 0; --j)
318  {
319  for (unsigned int i = 0; i < m_PlayersNearPoint[j].size(); ++i)
320  if (m_PlayersNearPoint[j][i] == guid)
321  m_PlayersNearPoint[j].erase(m_PlayersNearPoint[j].begin() + i);
322  }
323  if (IsFlagPickedup())
324  {
325  if (m_FlagKeeper == guid)
326  {
327  if (plr)
329  else
330  {
331  SetFlagPicker(0);
332  RespawnFlag(true);
333  }
334  }
335  }
336 }
337 
339 {
340  if (GetStatus() != STATUS_IN_PROGRESS)
341  return;
342 
343  if (!Source->IsAlive()) //hack code, must be removed later
344  return;
345 
346  switch (Trigger)
347  {
348  case TR_BLOOD_ELF_POINT:
350  if (m_FlagState && GetFlagPickerGUID() == Source->GetGUID())
352  break;
353  case TR_FEL_REAVER_POINT:
355  if (m_FlagState && GetFlagPickerGUID() == Source->GetGUID())
357  break;
358  case TR_MAGE_TOWER_POINT:
360  if (m_FlagState && GetFlagPickerGUID() == Source->GetGUID())
362  break;
365  if (m_FlagState && GetFlagPickerGUID() == Source->GetGUID())
367  break;
368  case 4512:
369  case 4515:
370  case 4517:
371  case 4519:
372  case 4530:
373  case 4531:
374  case 4568:
375  case 4569:
376  case 4570:
377  case 4571:
378  break;
379  default:
380  sLog.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", Trigger);
381  Source->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", Trigger);
382  break;
383  }
384 }
385 
387 {
388  // doors
389  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)
390  || !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)
391  // banners (alliance)
392  || !AddObject(BG_EY_OBJECT_A_BANNER_FEL_REAVER_CENTER, BG_OBJECT_A_BANNER_EY_ENTRY, 2057.46f, 1735.07f, 1187.91f, -0.925024f, 0, 0, 0.446198f, -0.894934f, RESPAWN_ONE_DAY)
393  || !AddObject(BG_EY_OBJECT_A_BANNER_FEL_REAVER_LEFT, BG_OBJECT_A_BANNER_EY_ENTRY, 2032.25f, 1729.53f, 1190.33f, 1.8675f, 0, 0, 0.803857f, 0.594823f, RESPAWN_ONE_DAY)
394  || !AddObject(BG_EY_OBJECT_A_BANNER_FEL_REAVER_RIGHT, BG_OBJECT_A_BANNER_EY_ENTRY, 2092.35f, 1775.46f, 1187.08f, -0.401426f, 0, 0, 0.199368f, -0.979925f, RESPAWN_ONE_DAY)
395  || !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)
396  || !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)
397  || !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)
398  || !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)
399  || !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)
400  || !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)
401  || !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)
402  || !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)
403  || !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)
404  // banners (horde)
405  || !AddObject(BG_EY_OBJECT_H_BANNER_FEL_REAVER_CENTER, BG_OBJECT_H_BANNER_EY_ENTRY, 2057.46f, 1735.07f, 1187.91f, -0.925024f, 0, 0, 0.446198f, -0.894934f, RESPAWN_ONE_DAY)
406  || !AddObject(BG_EY_OBJECT_H_BANNER_FEL_REAVER_LEFT, BG_OBJECT_H_BANNER_EY_ENTRY, 2032.25f, 1729.53f, 1190.33f, 1.8675f, 0, 0, 0.803857f, 0.594823f, RESPAWN_ONE_DAY)
407  || !AddObject(BG_EY_OBJECT_H_BANNER_FEL_REAVER_RIGHT, BG_OBJECT_H_BANNER_EY_ENTRY, 2092.35f, 1775.46f, 1187.08f, -0.401426f, 0, 0, 0.199368f, -0.979925f, RESPAWN_ONE_DAY)
408  || !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)
409  || !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)
410  || !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)
411  || !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)
412  || !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)
413  || !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)
414  || !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)
415  || !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)
416  || !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)
417  // banners (natural)
418  || !AddObject(BG_EY_OBJECT_N_BANNER_FEL_REAVER_CENTER, BG_OBJECT_N_BANNER_EY_ENTRY, 2057.46f, 1735.07f, 1187.91f, -0.925024f, 0, 0, 0.446198f, -0.894934f, RESPAWN_ONE_DAY)
419  || !AddObject(BG_EY_OBJECT_N_BANNER_FEL_REAVER_LEFT, BG_OBJECT_N_BANNER_EY_ENTRY, 2032.25f, 1729.53f, 1190.33f, 1.8675f, 0, 0, 0.803857f, 0.594823f, RESPAWN_ONE_DAY)
420  || !AddObject(BG_EY_OBJECT_N_BANNER_FEL_REAVER_RIGHT, BG_OBJECT_N_BANNER_EY_ENTRY, 2092.35f, 1775.46f, 1187.08f, -0.401426f, 0, 0, 0.199368f, -0.979925f, RESPAWN_ONE_DAY)
421  || !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)
422  || !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)
423  || !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)
424  || !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)
425  || !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)
426  || !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)
427  || !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)
428  || !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)
429  || !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)
430  // flags
431  || !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)
432  || !AddObject(BG_EY_OBJECT_FLAG_FEL_REAVER, BG_OBJECT_FLAG1_EY_ENTRY, 2044.28f, 1729.68f, 1189.96f, -0.017453f, 0, 0, 0.008727f, -0.999962f, RESPAWN_ONE_DAY)
433  || !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)
434  || !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)
435  || !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)
436  // tower cap
437  || !AddObject(BG_EY_OBJECT_TOWER_CAP_FEL_REAVER, BG_OBJECT_FR_TOWER_CAP_EY_ENTRY, 2024.600708f, 1742.819580f, 1195.157715f, 2.443461f, 0, 0, 0.939693f, 0.342020f, RESPAWN_ONE_DAY)
438  || !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)
439  || !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)
440  || !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)
441  )
442  {
443  sLog.outErrorDb("BatteGroundEY: Failed to spawn some object Battleground not created!");
444  return false;
445  }
446 
447  //buffs
448  for (int i = 0; i < EY_POINTS_MAX; ++i)
449  {
450  AreaTriggerEntry const* at = sAreaTriggerStore.LookupEntry(m_Points_Trigger[i]);
451  if (!at)
452  {
453  sLog.outError("BattlegroundEY: Unknown trigger: %u", m_Points_Trigger[i]);
454  continue;
455  }
456  if ( !AddObject(BG_EY_OBJECT_SPEEDBUFF_FEL_REAVER + i * 3, Buff_Entries[0], at->x, at->y, at->z, 0.907571f, 0, 0, 0.438371f, 0.898794f, RESPAWN_ONE_DAY)
457  || !AddObject(BG_EY_OBJECT_SPEEDBUFF_FEL_REAVER + i * 3 + 1, Buff_Entries[1], at->x, at->y, at->z, 0.907571f, 0, 0, 0.438371f, 0.898794f, RESPAWN_ONE_DAY)
458  || !AddObject(BG_EY_OBJECT_SPEEDBUFF_FEL_REAVER + i * 3 + 2, Buff_Entries[2], at->x, at->y, at->z, 0.907571f, 0, 0, 0.438371f, 0.898794f, RESPAWN_ONE_DAY)
459  )
460  sLog.outError("BattlegroundEY: Cannot spawn buff");
461  }
462 
463  WorldSafeLocsEntry const* sg = NULL;
465  if (!sg || !AddSpiritGuide(EY_SPIRIT_MAIN_ALLIANCE, sg->x, sg->y, sg->z, 3.124139f, ALLIANCE))
466  {
467  sLog.outErrorDb("BatteGroundEY: Failed to spawn spirit guide! Battleground not created!");
468  return false;
469  }
470 
472  if (!sg || !AddSpiritGuide(EY_SPIRIT_MAIN_HORDE, sg->x, sg->y, sg->z, 3.193953f, HORDE))
473  {
474  sLog.outErrorDb("BatteGroundEY: Failed to spawn spirit guide! Battleground not created!");
475  return false;
476  }
477 
478  return true;
479 }
480 
482 {
491  m_FlagKeeper = 0;
492  m_DroppedFlagGUID = 0;
493  m_PointAddingTimer = 0;
495 
496  for (uint8 i = 0; i < EY_POINTS_MAX; ++i)
497  {
501  m_PlayersNearPoint[i].clear();
502  m_PlayersNearPoint[i].reserve(15); //tip size
503  }
506 }
507 
508 void BattlegroundEY::RespawnFlag(bool send_message)
509 {
512 
516 
517  if (send_message)
518  {
520  PlaySoundToAll(BG_EY_SOUND_FLAG_RESET); // flags respawned sound...
521  }
522 
524 }
525 
527 {
528  RespawnFlag(true);
529 
531  if (obj)
532  obj->Delete();
533  else
534  sLog.outError("BattlegroundEY: Unknown dropped flag guid: %u", GUID_LOPART(GetDroppedFlagGUID()));
535 
537 }
538 
540 {
541  if (GetStatus() != STATUS_IN_PROGRESS)
542  return;
543 
544  Battleground::HandleKillPlayer(player, killer);
545  EventPlayerDroppedFlag(player);
546 }
547 
549 {
550  if (GetStatus() != STATUS_IN_PROGRESS)
551  {
552  // if not running, do not cast things at the dropper player, neither send unnecessary messages
553  // just take off the aura
554  if (IsFlagPickedup() && GetFlagPickerGUID() == Source->GetGUID())
555  {
556  SetFlagPicker(0);
558  }
559  return;
560  }
561 
562  if (!IsFlagPickedup())
563  return;
564 
565  if (GetFlagPickerGUID() != Source->GetGUID())
566  return;
567 
568  SetFlagPicker(0);
572  Source->CastSpell(Source, SPELL_RECENTLY_DROPPED_FLAG, true);
573  Source->CastSpell(Source, BG_EY_PLAYER_DROPPED_FLAG_SPELL, true);
574  //this does not work correctly :((it should remove flag carrier name)
577 
578  if (Source->GetTeam() == ALLIANCE)
580  else
582 }
583 
585 {
586  if (GetStatus() != STATUS_IN_PROGRESS || IsFlagPickedup() || !Source->IsWithinDistInMap(target_obj, 10))
587  return;
588 
589  if (Source->GetTeam() == ALLIANCE)
590  {
593  }
594  else
595  {
598  }
599 
603 
605  SetFlagPicker(Source->GetGUID());
606  //get flag aura on player
607  Source->CastSpell(Source, BG_EY_NETHERSTORM_FLAG_SPELL, true);
609 
610  if (Source->GetTeam() == ALLIANCE)
612  else
614 }
615 
617 {
618  if (GetStatus() != STATUS_IN_PROGRESS)
619  return;
620 
621  //Natural point
622  uint32 Team = m_PointOwnedByTeam[Point];
623 
624  if (!Team)
625  return;
626 
627  if (Team == ALLIANCE)
628  {
630  SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeAlliance, RESPAWN_ONE_DAY);
631  SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeAlliance + 1, RESPAWN_ONE_DAY);
632  SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeAlliance + 2, RESPAWN_ONE_DAY);
633  }
634  else
635  {
637  SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeHorde, RESPAWN_ONE_DAY);
638  SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeHorde + 1, RESPAWN_ONE_DAY);
639  SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeHorde + 2, RESPAWN_ONE_DAY);
640  }
641 
642  SpawnBGObject(m_LoosingPointTypes[Point].SpawnNeutralObjectType, RESPAWN_IMMEDIATELY);
643  SpawnBGObject(m_LoosingPointTypes[Point].SpawnNeutralObjectType + 1, RESPAWN_IMMEDIATELY);
644  SpawnBGObject(m_LoosingPointTypes[Point].SpawnNeutralObjectType + 2, RESPAWN_IMMEDIATELY);
645 
646  //buff isn't despawned
647 
650 
651  if (Team == ALLIANCE)
652  SendMessageToAll(m_LoosingPointTypes[Point].MessageIdAlliance, CHAT_MSG_BG_SYSTEM_ALLIANCE, Source);
653  else
654  SendMessageToAll(m_LoosingPointTypes[Point].MessageIdHorde, CHAT_MSG_BG_SYSTEM_HORDE, Source);
655 
656  UpdatePointsIcons(Team, Point);
657  UpdatePointsCount(Team);
658 }
659 
661 {
662  if (GetStatus() != STATUS_IN_PROGRESS)
663  return;
664 
665  uint32 Team = Source->GetTeam();
666 
667  SpawnBGObject(m_CapturingPointTypes[Point].DespawnNeutralObjectType, RESPAWN_ONE_DAY);
668  SpawnBGObject(m_CapturingPointTypes[Point].DespawnNeutralObjectType + 1, RESPAWN_ONE_DAY);
669  SpawnBGObject(m_CapturingPointTypes[Point].DespawnNeutralObjectType + 2, RESPAWN_ONE_DAY);
670 
671  if (Team == ALLIANCE)
672  {
674  SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeAlliance, RESPAWN_IMMEDIATELY);
675  SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeAlliance + 1, RESPAWN_IMMEDIATELY);
676  SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeAlliance + 2, RESPAWN_IMMEDIATELY);
677  }
678  else
679  {
681  SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeHorde, RESPAWN_IMMEDIATELY);
682  SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeHorde + 1, RESPAWN_IMMEDIATELY);
683  SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeHorde + 2, RESPAWN_IMMEDIATELY);
684  }
685 
686  //buff isn't respawned
687 
688  m_PointOwnedByTeam[Point] = Team;
690 
691  if (Team == ALLIANCE)
692  SendMessageToAll(m_CapturingPointTypes[Point].MessageIdAlliance, CHAT_MSG_BG_SYSTEM_ALLIANCE, Source);
693  else
694  SendMessageToAll(m_CapturingPointTypes[Point].MessageIdHorde, CHAT_MSG_BG_SYSTEM_HORDE, Source);
695 
696  if (m_BgCreatures[Point])
697  DelCreature(Point);
698 
699  WorldSafeLocsEntry const* sg = NULL;
700  sg = sWorldSafeLocsStore.LookupEntry(m_CapturingPointTypes[Point].GraveYardId);
701  if (!sg || !AddSpiritGuide(Point, sg->x, sg->y, sg->z, 3.124139f, Team))
702  sLog.outError("BatteGroundEY: Failed to spawn spirit guide! point: %u, team: %u, graveyard_id: %u",
703  Point, Team, m_CapturingPointTypes[Point].GraveYardId);
704 
705  // SpawnBGCreature(Point,RESPAWN_IMMEDIATELY);
706 
707  UpdatePointsIcons(Team, Point);
708  UpdatePointsCount(Team);
709 }
710 
712 {
713  if (GetStatus() != STATUS_IN_PROGRESS || GetFlagPickerGUID() != Source->GetGUID())
714  return;
715 
716  SetFlagPicker(0);
719 
721 
722  if (Source->GetTeam() == ALLIANCE)
724  else
726 
727  SpawnBGObject(BgObjectType, RESPAWN_IMMEDIATELY);
728 
730  m_FlagCapturedBgObjectType = BgObjectType;
731 
732  uint8 team_id = 0;
733  if (Source->GetTeam() == ALLIANCE)
734  {
735  team_id = BG_TEAM_ALLIANCE;
737  }
738  else
739  {
740  team_id = BG_TEAM_HORDE;
742  }
743 
744  if (m_TeamPointsCount[team_id] > 0)
745  AddPoints(Source->GetTeam(), BG_EY_FlagPoints[m_TeamPointsCount[team_id] - 1]);
746 
748 }
749 
751 {
752  std::map<uint64, BattlegroundScore*>::iterator itr = m_PlayerScores.find(Source->GetGUID());
753  if (itr == m_PlayerScores.end()) // player not found
754  return;
755 
756  switch (type)
757  {
758  case SCORE_FLAG_CAPTURES: // flags captured
759  ((BattlegroundEYScore*)itr->second)->FlagCaptures += value;
760  break;
761  default:
762  Battleground::UpdatePlayerScore(Source, type, value);
763  break;
764  }
765 }
766 
768 {
771  data << uint32(0xab6) << uint32(0x0);
772  data << uint32(0xab5) << uint32(0x0);
773  data << uint32(0xab4) << uint32(0x0);
774  data << uint32(0xab3) << uint32(0x0);
775  data << uint32(0xab2) << uint32(0x0);
776  data << uint32(0xab1) << uint32(0x0);
777  data << uint32(0xab0) << uint32(0x0);
778  data << uint32(0xaaf) << uint32(0x0);
779 
781 
783 
785 
787 
789 
791 
793 
795 
797 
799 
801 
803 
805 
806  data << uint32(0xad2) << uint32(0x1);
807  data << uint32(0xad1) << uint32(0x1);
808  data << uint32(0xabe) << uint32(GetTeamScore(HORDE));
809  data << uint32(0xabd) << uint32(GetTeamScore(ALLIANCE));
810  data << uint32(0xa05) << uint32(0x8e);
811  data << uint32(0xaa0) << uint32(0x0);
812  data << uint32(0xa9f) << uint32(0x0);
813  data << uint32(0xa9e) << uint32(0x0);
814  data << uint32(0xc0d) << uint32(0x17b);
815 }
816 
818 {
819  uint32 g_id = 0;
820 
821  switch (player->GetTeam())
822  {
823  case ALLIANCE:
825  break;
826  case HORDE:
828  break;
829  default:
830  return NULL;
831  }
832 
833  float distance, nearestDistance;
834 
835  WorldSafeLocsEntry const* entry = NULL;
836  WorldSafeLocsEntry const* nearestEntry = NULL;
837  entry = sWorldSafeLocsStore.LookupEntry(g_id);
838  nearestEntry = entry;
839 
840  if (!entry)
841  {
842  sLog.outError("BattlegroundEY: Not found the main team graveyard. Graveyard system isn't working!");
843  return NULL;
844  }
845 
846  float plr_x = player->GetPositionX();
847  float plr_y = player->GetPositionY();
848  float plr_z = player->GetPositionZ();
849 
850  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);
851  nearestDistance = distance;
852 
853  for (uint8 i = 0; i < EY_POINTS_MAX; ++i)
854  {
855  if (m_PointOwnedByTeam[i] == player->GetTeam() && m_PointState[i] == EY_POINT_UNDER_CONTROL)
856  {
857  entry = sWorldSafeLocsStore.LookupEntry(m_CapturingPointTypes[i].GraveYardId);
858  if (!entry)
859  sLog.outError("BattlegroundEY: Not found graveyard: %u", m_CapturingPointTypes[i].GraveYardId);
860  else
861  {
862  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);
863  if (distance < nearestDistance)
864  {
865  nearestDistance = distance;
866  nearestEntry = entry;
867  }
868  }
869  }
870  }
871 
872  return nearestEntry;
873 }
874 
uint32 GetTeamScore(uint32 Team) const
const uint32 BG_EY_FlagPoints[EY_POINTS_MAX]
DBCStorage< WorldSafeLocsEntry > sWorldSafeLocsStore(WorldSafeLocsEntryfmt)
bool AddObject(uint32 type, uint32 entry, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime=0)
void RemovePlayer(Player *plr, uint64 guid)
void RespawnFlagAfterDrop()
uint8 m_CurrentPointPlayersCount[2 *EY_POINTS_MAX]
void UpdatePointsIcons(uint32 Team, uint32 Point)
uint32 m_StartMessageIds[BG_STARTING_EVENT_COUNT]
Definition: Battleground.h:728
virtual void AddPlayer(Player *plr)
int32 m_TeamScores[BG_TEAMS_COUNT]
Definition: Battleground.h:704
virtual void HandleKillPlayer(Player *player, Player *killer)
void PSendMessageToAll(int32 entry, ChatMsg type, Player const *source,...)
void AddPoints(uint32 Team, uint32 Points)
#define GUID_LOPART(x)
Definition: ObjectGuid.h:110
PlayersNearPointType m_PlayersNearPoint[EY_POINTS_MAX+1]
void SetFlagPicker(uint64 guid)
void SetDroppedFlagGUID(uint64 guid)
virtual void ResetBGSubclass()
#define BG_EY_FLAG_RESPAWN_TIME
virtual bool SetupBattleground()
void Update(uint32 diff)
void EventTeamLostPoint(Player *Source, uint32 Point)
#define BG_EY_FPOINTS_TICK_TIME
void UpdatePlayerScore(Player *Source, uint32 type, uint32 value)
int32 m_TowerCapCheckTimer
uint8 m_PointState[EY_POINTS_MAX]
uint64 GetFlagPickerGUID() const
#define sLog
Log class singleton.
Definition: Log.h:187
virtual WorldSafeLocsEntry const * GetClosestGraveYard(Player *player)
void EventTeamCapturedPoint(Player *Source, uint32 Point)
const uint8 BG_EY_TickPoints[EY_POINTS_MAX]
static T * Find(uint64 guid)
void SpawnBGObject(uint32 type, uint32 respawntime)
DBCStorage< AreaTriggerEntry > sAreaTriggerStore(AreaTriggerEntryfmt)
void UpdateWorldState(uint32 Field, uint32 Value)
uint32 GetStatus() const
Definition: Battleground.h:317
BattlegroundScoreMap m_PlayerScores
Definition: Battleground.h:713
#define sObjectMgr
Definition: ObjectMgr.h:1285
uint8 GetTeamIndexByTeamId(uint32 Team) const
Definition: Battleground.h:609
bool AddSpiritGuide(uint32 type, float x, float y, float z, float o, uint32 team)
uint32 m_FlagCapturedBgObjectType
virtual void AddPlayer(Player *plr)
uint32 m_HonorScoreTics[2]
void EventPlayerCapturedFlag(Player *Source, uint32 BgObjectType)
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true) const
Definition: Object.h:774
void RemoveAurasDueToSpell(uint32 spellId, Aura *except=NULL)
Definition: Unit.cpp:4371
BGCreatures m_BgCreatures
Definition: Battleground.h:673
const BattlegroundEYLoosingPointStruct m_LoosingPointTypes[EY_POINTS_MAX]
Team
void RespawnFlag(bool send_message)
ACE_UINT8 uint8
Definition: Define.h:73
BGObjects m_BgObjects
Definition: Battleground.h:672
void PlaySoundToAll(uint32 SoundID)
virtual void StartingEventOpenDoors()
int32 m_PointAddingTimer
void RemoveAurasWithInterruptFlags(uint32 flags, uint32 except=0)
Definition: Unit.cpp:736
bool IsAlive() const
Definition: Unit.h:1336
float GetPositionY() const
Definition: Position.h:98
virtual void FillInitialWorldStates(WorldPacket &data)
void CastSpell(Unit *Victim, uint32 spellId, bool triggered, Item *castItem=NULL, Aura *triggeredByAura=NULL, uint64 originalCaster=0)
Definition: Unit.cpp:1223
#define EY_MAX_TEAM_SCORE
etc mysql my cnf *Then change max_allowed_packet to a bigger value
float GetPositionZ() const
Definition: Position.h:99
virtual void UpdatePlayerScore(Player *Source, uint32 type, uint32 value)
uint32 m_Points_Trigger[EY_POINTS_MAX]
virtual void StartingEventCloseDoors()
virtual void EventPlayerClickedOnFlag(Player *Source, GameObject *target_obj)
void RewardHonorToTeam(uint32 Honor, uint32 TeamID)
void CheckSomeoneLeftPoint()
const char * GetName() const
Definition: Object.h:704
int32 m_PointBarStatus[EY_POINTS_MAX]
ACE_UINT64 uint64
Definition: Define.h:70
bool CanCaptureTowerPoint()
Definition: Player.cpp:20496
void UpdatePointStatuses()
bool DelCreature(uint32 type)
uint32 BG_EY_HonorScoreTicks[BG_HONOR_MODE_NUM]
uint64 GetDroppedFlagGUID() const
void HandleKillPlayer(Player *player, Player *killer)
const BattlegroundEYPointIconsStruct m_PointsIconStruct[EY_POINTS_MAX]
void HandleAreaTrigger(Player *Source, uint32 Trigger)
uint64 m_DroppedFlagGUID
bool IsFlagPickedup() const
uint32 m_TeamPointsCount[2]
uint32 GetTeam() const
Definition: Player.h:2063
const BattlegroundEYCapturingPointStruct m_CapturingPointTypes[EY_POINTS_MAX]
void UpdateWorldStateForPlayer(uint32 Field, uint32 Value, Player *Source)
void SendAreaTriggerMessage(const char *Text,...) ATTR_PRINTF(2
WorldSession * GetSession() const
Definition: Player.h:1944
uint32 m_score[2]
Definition: Battleground.h:731
void EndBattleground(uint32 winner)
void CheckSomeoneJoinedPoint()
ACE_UINT32 uint32
Definition: Define.h:71
float GetPositionX() const
Definition: Position.h:97
const uint32 Buff_Entries[3]
Definition: Battleground.h:110
void UpdateTeamScore(uint32 Team)
uint32 m_PointOwnedByTeam[EY_POINTS_MAX]
Definition: Player.h:922
virtual void EventPlayerDroppedFlag(Player *Source)
void UpdatePointsCount(uint32 Team)
BGHonorMode m_HonorMode
Definition: Battleground.h:733
uint32 urand(uint32 min, uint32 max)
Definition: Util.cpp:33
void SendMessageToAll(int32 entry, ChatMsg type, Player const *source=NULL)
void Delete()
Definition: GameObject.cpp:564
const uint64 & GetGUID() const
Definition: Object.h:162
virtual void Update(uint32 diff)