2 * Copyright (C) 2005-2010 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
21 #include "BattleGround.h"
22 #include "BattleGroundEY.h"
24 #include "ObjectMgr.h"
25 #include "BattleGroundMgr.h"
27 #include "WorldPacket.h"
29 #include "MapManager.h"
31 BattleGroundEY::BattleGroundEY()
34 m_BgObjects
.resize(BG_EY_OBJECT_MAX
);
36 m_Points_Trigger
[FEL_REALVER
] = TR_FEL_REALVER_BUFF
;
37 m_Points_Trigger
[BLOOD_ELF
] = TR_BLOOD_ELF_BUFF
;
38 m_Points_Trigger
[DRAENEI_RUINS
] = TR_DRAENEI_RUINS_BUFF
;
39 m_Points_Trigger
[MAGE_TOWER
] = TR_MAGE_TOWER_BUFF
;
41 m_StartMessageIds
[BG_STARTING_EVENT_FIRST
] = 0;
42 m_StartMessageIds
[BG_STARTING_EVENT_SECOND
] = LANG_BG_EY_START_ONE_MINUTE
;
43 m_StartMessageIds
[BG_STARTING_EVENT_THIRD
] = LANG_BG_EY_START_HALF_MINUTE
;
44 m_StartMessageIds
[BG_STARTING_EVENT_FOURTH
] = LANG_BG_EY_HAS_BEGUN
;
47 BattleGroundEY::~BattleGroundEY()
51 void BattleGroundEY::Update(uint32 diff
)
53 BattleGround::Update(diff
);
55 if (GetStatus() == STATUS_IN_PROGRESS
)
57 m_PointAddingTimer
-= diff
;
58 if (m_PointAddingTimer
<= 0)
60 m_PointAddingTimer
= BG_EY_FPOINTS_TICK_TIME
;
61 if (m_TeamPointsCount
[BG_TEAM_ALLIANCE
] > 0)
62 AddPoints(ALLIANCE
, BG_EY_TickPoints
[m_TeamPointsCount
[BG_TEAM_ALLIANCE
] - 1]);
63 if (m_TeamPointsCount
[BG_TEAM_HORDE
] > 0)
64 AddPoints(HORDE
, BG_EY_TickPoints
[m_TeamPointsCount
[BG_TEAM_HORDE
] - 1]);
67 if (m_FlagState
== BG_EY_FLAG_STATE_WAIT_RESPAWN
|| m_FlagState
== BG_EY_FLAG_STATE_ON_GROUND
)
74 if (m_FlagState
== BG_EY_FLAG_STATE_WAIT_RESPAWN
)
77 RespawnFlagAfterDrop();
81 m_TowerCapCheckTimer
-= diff
;
82 if (m_TowerCapCheckTimer
<= 0)
84 //check if player joined point
85 /*I used this order of calls, because although we will check if one player is in gameobject's distance 2 times
86 but we can count of players on current point in CheckSomeoneLeftPoint
88 CheckSomeoneJoinedPoint();
89 //check if player left point
90 CheckSomeoneLeftPoint();
91 UpdatePointStatuses();
92 m_TowerCapCheckTimer
= BG_EY_FPOINTS_TICK_TIME
;
97 void BattleGroundEY::StartingEventCloseDoors()
101 void BattleGroundEY::StartingEventOpenDoors()
103 // eye-doors are despawned, not opened
104 SpawnEvent(BG_EVENT_DOOR
, 0, false);
106 for(uint32 i
= 0; i
< BG_EY_NODES_MAX
; ++i
)
108 //randomly spawn buff
109 uint8 buff
= urand(0, 2);
110 SpawnBGObject(m_BgObjects
[BG_EY_OBJECT_SPEEDBUFF_FEL_REALVER
+ buff
+ i
* 3], RESPAWN_IMMEDIATELY
);
114 void BattleGroundEY::AddPoints(uint32 Team
, uint32 Points
)
116 BattleGroundTeamId team_index
= GetTeamIndexByTeamId(Team
);
117 m_TeamScores
[team_index
] += Points
;
118 m_HonorScoreTics
[team_index
] += Points
;
119 if (m_HonorScoreTics
[team_index
] >= m_HonorTics
)
121 RewardHonorToTeam(GetBonusHonorFromKill(1), Team
);
122 m_HonorScoreTics
[team_index
] -= m_HonorTics
;
124 UpdateTeamScore(Team
);
127 void BattleGroundEY::CheckSomeoneJoinedPoint()
129 for (uint8 i
= 0; i
< BG_EY_NODES_MAX
; ++i
)
132 while (j
< m_PlayersNearPoint
[BG_EY_NODES_MAX
].size())
134 Player
*plr
= sObjectMgr
.GetPlayer(m_PlayersNearPoint
[BG_EY_NODES_MAX
][j
]);
137 sLog
.outError("BattleGroundEY:CheckSomeoneJoinedPoint: Player (GUID: %u) not found!", GUID_LOPART(m_PlayersNearPoint
[BG_EY_NODES_MAX
][j
]));
141 if (plr
->CanCaptureTowerPoint() &&
142 plr
->IsWithinDist3d(BG_EY_NodePositions
[i
][0], BG_EY_NodePositions
[i
][1], BG_EY_NodePositions
[i
][2], BG_EY_POINT_RADIUS
))
144 //player joined point!
146 UpdateWorldStateForPlayer(PROGRESS_BAR_PERCENT_GREY
, BG_EY_PROGRESS_BAR_PERCENT_GREY
, plr
);
147 UpdateWorldStateForPlayer(PROGRESS_BAR_STATUS
, m_PointBarStatus
[i
], plr
);
148 UpdateWorldStateForPlayer(PROGRESS_BAR_SHOW
, BG_EY_PROGRESS_BAR_SHOW
, plr
);
149 //add player to point
150 m_PlayersNearPoint
[i
].push_back(m_PlayersNearPoint
[BG_EY_NODES_MAX
][j
]);
151 //remove player from "free space"
152 m_PlayersNearPoint
[BG_EY_NODES_MAX
].erase(m_PlayersNearPoint
[BG_EY_NODES_MAX
].begin() + j
);
160 void BattleGroundEY::CheckSomeoneLeftPoint()
162 //reset current point counts
163 for (uint8 i
= 0; i
< 2*BG_EY_NODES_MAX
; ++i
)
164 m_CurrentPointPlayersCount
[i
] = 0;
165 for(uint8 i
= 0; i
< BG_EY_NODES_MAX
; ++i
)
168 while (j
< m_PlayersNearPoint
[i
].size())
170 Player
*plr
= sObjectMgr
.GetPlayer(m_PlayersNearPoint
[i
][j
]);
173 sLog
.outError("BattleGroundEY:CheckSomeoneLeftPoint Player (GUID: %u) not found!", GUID_LOPART(m_PlayersNearPoint
[i
][j
]));
174 //move not existed player to "free space" - this will cause many error showing in log, but it is a very important bug
175 m_PlayersNearPoint
[BG_EY_NODES_MAX
].push_back(m_PlayersNearPoint
[i
][j
]);
176 m_PlayersNearPoint
[i
].erase(m_PlayersNearPoint
[i
].begin() + j
);
180 if (!plr
->CanCaptureTowerPoint() ||
181 !plr
->IsWithinDist3d(BG_EY_NodePositions
[i
][0], BG_EY_NodePositions
[i
][1], BG_EY_NodePositions
[i
][2], BG_EY_POINT_RADIUS
))
182 //move player out of point (add him to players that are out of points
184 m_PlayersNearPoint
[BG_EY_NODES_MAX
].push_back(m_PlayersNearPoint
[i
][j
]);
185 m_PlayersNearPoint
[i
].erase(m_PlayersNearPoint
[i
].begin() + j
);
186 UpdateWorldStateForPlayer(PROGRESS_BAR_SHOW
, BG_EY_PROGRESS_BAR_DONT_SHOW
, plr
);
190 //player is neat flag, so update count:
191 m_CurrentPointPlayersCount
[2 * i
+ GetTeamIndexByTeamId(plr
->GetTeam())]++;
198 void BattleGroundEY::UpdatePointStatuses()
200 for(uint8 point
= 0; point
< BG_EY_NODES_MAX
; ++point
)
202 if (m_PlayersNearPoint
[point
].empty())
204 //count new point bar status:
205 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
;
207 if (m_PointBarStatus
[point
] > BG_EY_PROGRESS_BAR_ALI_CONTROLLED
)
208 //point is fully alliance's
209 m_PointBarStatus
[point
] = BG_EY_PROGRESS_BAR_ALI_CONTROLLED
;
210 if (m_PointBarStatus
[point
] < BG_EY_PROGRESS_BAR_HORDE_CONTROLLED
)
211 //point is fully horde's
212 m_PointBarStatus
[point
] = BG_EY_PROGRESS_BAR_HORDE_CONTROLLED
;
214 uint32 pointOwnerTeamId
= 0;
215 //find which team should own this point
216 if (m_PointBarStatus
[point
] <= BG_EY_PROGRESS_BAR_NEUTRAL_LOW
)
217 pointOwnerTeamId
= HORDE
;
218 else if (m_PointBarStatus
[point
] >= BG_EY_PROGRESS_BAR_NEUTRAL_HIGH
)
219 pointOwnerTeamId
= ALLIANCE
;
221 pointOwnerTeamId
= EY_POINT_NO_OWNER
;
223 for (uint8 i
= 0; i
< m_PlayersNearPoint
[point
].size(); ++i
)
225 Player
*plr
= sObjectMgr
.GetPlayer(m_PlayersNearPoint
[point
][i
]);
228 UpdateWorldStateForPlayer(PROGRESS_BAR_STATUS
, m_PointBarStatus
[point
], plr
);
229 //if point owner changed we must evoke event!
230 if (pointOwnerTeamId
!= m_PointOwnedByTeam
[point
])
232 //point was uncontrolled and player is from team which captured point
233 if (m_PointState
[point
] == EY_POINT_STATE_UNCONTROLLED
&& plr
->GetTeam() == pointOwnerTeamId
)
234 EventTeamCapturedPoint(plr
, point
);
236 //point was under control and player isn't from team which controlled it
237 if (m_PointState
[point
] == EY_POINT_UNDER_CONTROL
&& plr
->GetTeam() != m_PointOwnedByTeam
[point
])
238 EventTeamLostPoint(plr
, point
);
245 void BattleGroundEY::UpdateTeamScore(uint32 Team
)
247 uint32 score
= GetTeamScore(Team
);
249 if (score
>= BG_EY_MAX_TEAM_SCORE
)
251 score
= BG_EY_MAX_TEAM_SCORE
;
252 EndBattleGround(Team
);
255 if (Team
== ALLIANCE
)
256 UpdateWorldState(EY_ALLIANCE_RESOURCES
, score
);
258 UpdateWorldState(EY_HORDE_RESOURCES
, score
);
261 void BattleGroundEY::EndBattleGround(uint32 winner
)
264 if (winner
== ALLIANCE
)
265 RewardHonorToTeam(GetBonusHonorFromKill(1), ALLIANCE
);
267 RewardHonorToTeam(GetBonusHonorFromKill(1), HORDE
);
268 //complete map reward
269 RewardHonorToTeam(GetBonusHonorFromKill(1), ALLIANCE
);
270 RewardHonorToTeam(GetBonusHonorFromKill(1), HORDE
);
272 BattleGround::EndBattleGround(winner
);
275 void BattleGroundEY::UpdatePointsCount(uint32 Team
)
277 if (Team
== ALLIANCE
)
278 UpdateWorldState(EY_ALLIANCE_BASE
, m_TeamPointsCount
[BG_TEAM_ALLIANCE
]);
280 UpdateWorldState(EY_HORDE_BASE
, m_TeamPointsCount
[BG_TEAM_HORDE
]);
283 void BattleGroundEY::UpdatePointsIcons(uint32 Team
, uint32 Point
)
285 //we MUST firstly send 0, after that we can send 1!!!
286 if (m_PointState
[Point
] == EY_POINT_UNDER_CONTROL
)
288 UpdateWorldState(PointsIconStruct
[Point
].WorldStateControlIndex
, 0);
289 if (Team
== ALLIANCE
)
290 UpdateWorldState(PointsIconStruct
[Point
].WorldStateAllianceControlledIndex
, 1);
292 UpdateWorldState(PointsIconStruct
[Point
].WorldStateHordeControlledIndex
, 1);
296 if (Team
== ALLIANCE
)
297 UpdateWorldState(PointsIconStruct
[Point
].WorldStateAllianceControlledIndex
, 0);
299 UpdateWorldState(PointsIconStruct
[Point
].WorldStateHordeControlledIndex
, 0);
300 UpdateWorldState(PointsIconStruct
[Point
].WorldStateControlIndex
, 1);
304 void BattleGroundEY::AddPlayer(Player
*plr
)
306 BattleGround::AddPlayer(plr
);
307 //create score and add it to map
308 BattleGroundEYScore
* sc
= new BattleGroundEYScore
;
310 m_PlayersNearPoint
[BG_EY_NODES_MAX
].push_back(plr
->GetGUID());
312 m_PlayerScores
[plr
->GetGUID()] = sc
;
315 void BattleGroundEY::RemovePlayer(Player
*plr
, uint64 guid
)
317 // sometimes flag aura not removed :(
318 for (int j
= BG_EY_NODES_MAX
; j
>= 0; --j
)
320 for(size_t i
= 0; i
< m_PlayersNearPoint
[j
].size(); ++i
)
321 if (m_PlayersNearPoint
[j
][i
] == guid
)
322 m_PlayersNearPoint
[j
].erase(m_PlayersNearPoint
[j
].begin() + i
);
324 if (IsFlagPickedup())
326 if (m_FlagKeeper
== guid
)
329 EventPlayerDroppedFlag(plr
);
339 void BattleGroundEY::HandleAreaTrigger(Player
*Source
, uint32 Trigger
)
341 if (GetStatus() != STATUS_IN_PROGRESS
)
344 if(!Source
->isAlive()) //hack code, must be removed later
349 case TR_BLOOD_ELF_POINT
:
350 if (m_PointState
[BLOOD_ELF
] == EY_POINT_UNDER_CONTROL
&& m_PointOwnedByTeam
[BLOOD_ELF
] == Source
->GetTeam())
351 if (m_FlagState
&& GetFlagPickerGUID() == Source
->GetGUID())
352 EventPlayerCapturedFlag(Source
, BG_EY_NODE_BLOOD_ELF
);
354 case TR_FEL_REALVER_POINT
:
355 if (m_PointState
[FEL_REALVER
] == EY_POINT_UNDER_CONTROL
&& m_PointOwnedByTeam
[FEL_REALVER
] == Source
->GetTeam())
356 if (m_FlagState
&& GetFlagPickerGUID() == Source
->GetGUID())
357 EventPlayerCapturedFlag(Source
, BG_EY_NODE_FEL_REALVER
);
359 case TR_MAGE_TOWER_POINT
:
360 if (m_PointState
[MAGE_TOWER
] == EY_POINT_UNDER_CONTROL
&& m_PointOwnedByTeam
[MAGE_TOWER
] == Source
->GetTeam())
361 if (m_FlagState
&& GetFlagPickerGUID() == Source
->GetGUID())
362 EventPlayerCapturedFlag(Source
, BG_EY_NODE_MAGE_TOWER
);
364 case TR_DRAENEI_RUINS_POINT
:
365 if (m_PointState
[DRAENEI_RUINS
] == EY_POINT_UNDER_CONTROL
&& m_PointOwnedByTeam
[DRAENEI_RUINS
] == Source
->GetTeam())
366 if (m_FlagState
&& GetFlagPickerGUID() == Source
->GetGUID())
367 EventPlayerCapturedFlag(Source
, BG_EY_NODE_DRAENEI_RUINS
);
381 sLog
.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", Trigger
);
382 Source
->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", Trigger
);
387 bool BattleGroundEY::SetupBattleGround()
390 for (int i
= 0; i
< BG_EY_NODES_MAX
; ++i
)
392 AreaTriggerEntry
const* at
= sAreaTriggerStore
.LookupEntry(m_Points_Trigger
[i
]);
395 sLog
.outError("BattleGroundEY: Unknown trigger: %u", m_Points_Trigger
[i
]);
398 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
)
399 || !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
)
400 || !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
)
402 sLog
.outError("BattleGroundEY: Cannot spawn buff");
408 void BattleGroundEY::Reset()
410 //call parent's class reset
411 BattleGround::Reset();
413 m_TeamScores
[BG_TEAM_ALLIANCE
] = 0;
414 m_TeamScores
[BG_TEAM_HORDE
] = 0;
415 m_TeamPointsCount
[BG_TEAM_ALLIANCE
] = 0;
416 m_TeamPointsCount
[BG_TEAM_HORDE
] = 0;
417 m_HonorScoreTics
[BG_TEAM_ALLIANCE
] = 0;
418 m_HonorScoreTics
[BG_TEAM_HORDE
] = 0;
419 m_FlagState
= BG_EY_FLAG_STATE_ON_BASE
;
421 m_DroppedFlagGUID
= 0;
422 m_PointAddingTimer
= 0;
423 m_TowerCapCheckTimer
= 0;
424 bool isBGWeekend
= BattleGroundMgr::IsBGWeekend(GetTypeID());
425 m_HonorTics
= (isBGWeekend
) ? BG_EY_EYWeekendHonorTicks
: BG_EY_NotEYWeekendHonorTicks
;
427 for(uint8 i
= 0; i
< BG_EY_NODES_MAX
; ++i
)
429 m_PointOwnedByTeam
[i
] = EY_POINT_NO_OWNER
;
430 m_PointState
[i
] = EY_POINT_STATE_UNCONTROLLED
;
431 m_PointBarStatus
[i
] = BG_EY_PROGRESS_BAR_STATE_MIDDLE
;
432 m_PlayersNearPoint
[i
].clear();
433 m_PlayersNearPoint
[i
].reserve(15); //tip size
434 m_ActiveEvents
[i
] = BG_EYE_NEUTRAL_TEAM
; // neutral team owns every node
436 // the flag in the middle is spawned at beginning
437 m_ActiveEvents
[BG_EY_EVENT_CAPTURE_FLAG
] = BG_EY_EVENT2_FLAG_CENTER
;
439 m_PlayersNearPoint
[EY_PLAYERS_OUT_OF_POINTS
].clear();
440 m_PlayersNearPoint
[EY_PLAYERS_OUT_OF_POINTS
].reserve(30);
443 void BattleGroundEY::RespawnFlag(bool send_message
)
445 m_FlagState
= BG_EY_FLAG_STATE_ON_BASE
;
446 // will despawn captured flags at the node and spawn in center
447 SpawnEvent(BG_EY_EVENT_CAPTURE_FLAG
, BG_EY_EVENT2_FLAG_CENTER
, true);
451 SendMessageToAll(LANG_BG_EY_RESETED_FLAG
, CHAT_MSG_BG_SYSTEM_NEUTRAL
);
452 PlaySoundToAll(BG_EY_SOUND_FLAG_RESET
); // flags respawned sound...
455 UpdateWorldState(NETHERSTORM_FLAG
, 1);
458 void BattleGroundEY::RespawnFlagAfterDrop()
462 GameObject
*obj
= GetBgMap()->GetGameObject(GetDroppedFlagGUID());
466 sLog
.outError("BattleGroundEY: Unknown dropped flag guid: %u",GUID_LOPART(GetDroppedFlagGUID()));
468 SetDroppedFlagGUID(0);
471 void BattleGroundEY::HandleKillPlayer(Player
*player
, Player
*killer
)
473 if (GetStatus() != STATUS_IN_PROGRESS
)
476 BattleGround::HandleKillPlayer(player
, killer
);
477 EventPlayerDroppedFlag(player
);
480 void BattleGroundEY::EventPlayerDroppedFlag(Player
*Source
)
482 if (GetStatus() != STATUS_IN_PROGRESS
)
484 // if not running, do not cast things at the dropper player, neither send unnecessary messages
485 // just take off the aura
486 if (IsFlagPickedup() && GetFlagPickerGUID() == Source
->GetGUID())
489 Source
->RemoveAurasDueToSpell(BG_EY_NETHERSTORM_FLAG_SPELL
);
494 if (!IsFlagPickedup())
497 if (GetFlagPickerGUID() != Source
->GetGUID())
501 Source
->RemoveAurasDueToSpell(BG_EY_NETHERSTORM_FLAG_SPELL
);
502 m_FlagState
= BG_EY_FLAG_STATE_ON_GROUND
;
503 m_FlagsTimer
= BG_EY_FLAG_RESPAWN_TIME
;
504 Source
->CastSpell(Source
, SPELL_RECENTLY_DROPPED_FLAG
, true);
505 Source
->CastSpell(Source
, BG_EY_PLAYER_DROPPED_FLAG_SPELL
, true);
506 //this does not work correctly :( (it should remove flag carrier name)
507 UpdateWorldState(NETHERSTORM_FLAG_STATE_HORDE
, BG_EY_FLAG_STATE_WAIT_RESPAWN
);
508 UpdateWorldState(NETHERSTORM_FLAG_STATE_ALLIANCE
, BG_EY_FLAG_STATE_WAIT_RESPAWN
);
510 if (Source
->GetTeam() == ALLIANCE
)
511 SendMessageToAll(LANG_BG_EY_DROPPED_FLAG
, CHAT_MSG_BG_SYSTEM_ALLIANCE
, NULL
);
513 SendMessageToAll(LANG_BG_EY_DROPPED_FLAG
, CHAT_MSG_BG_SYSTEM_HORDE
, NULL
);
516 void BattleGroundEY::EventPlayerClickedOnFlag(Player
*Source
, GameObject
* target_obj
)
518 if (GetStatus() != STATUS_IN_PROGRESS
|| IsFlagPickedup() || !Source
->IsWithinDistInMap(target_obj
, 10))
521 if (Source
->GetTeam() == ALLIANCE
)
523 UpdateWorldState(NETHERSTORM_FLAG_STATE_ALLIANCE
, BG_EY_FLAG_STATE_ON_PLAYER
);
524 PlaySoundToAll(BG_EY_SOUND_FLAG_PICKED_UP_ALLIANCE
);
528 UpdateWorldState(NETHERSTORM_FLAG_STATE_HORDE
, BG_EY_FLAG_STATE_ON_PLAYER
);
529 PlaySoundToAll(BG_EY_SOUND_FLAG_PICKED_UP_HORDE
);
532 if (m_FlagState
== BG_EY_FLAG_STATE_ON_BASE
)
533 UpdateWorldState(NETHERSTORM_FLAG
, 0);
534 m_FlagState
= BG_EY_FLAG_STATE_ON_PLAYER
;
536 // despawn center-flag
537 SpawnEvent(BG_EY_EVENT_CAPTURE_FLAG
, BG_EY_EVENT2_FLAG_CENTER
, false);
539 SetFlagPicker(Source
->GetGUID());
540 //get flag aura on player
541 Source
->CastSpell(Source
, BG_EY_NETHERSTORM_FLAG_SPELL
, true);
542 Source
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
544 if (Source
->GetTeam() == ALLIANCE
)
545 PSendMessageToAll(LANG_BG_EY_HAS_TAKEN_FLAG
, CHAT_MSG_BG_SYSTEM_ALLIANCE
, NULL
, Source
->GetName());
547 PSendMessageToAll(LANG_BG_EY_HAS_TAKEN_FLAG
, CHAT_MSG_BG_SYSTEM_HORDE
, NULL
, Source
->GetName());
550 void BattleGroundEY::EventTeamLostPoint(Player
*Source
, uint32 Point
)
552 if (GetStatus() != STATUS_IN_PROGRESS
)
556 uint32 Team
= m_PointOwnedByTeam
[Point
];
561 if (Team
== ALLIANCE
)
562 m_TeamPointsCount
[BG_TEAM_ALLIANCE
]--;
564 m_TeamPointsCount
[BG_TEAM_HORDE
]--;
566 // it's important to set the OwnedBy before despawning spiritguides, else
567 // player won't get teleported away
568 m_PointOwnedByTeam
[Point
] = EY_POINT_NO_OWNER
;
569 m_PointState
[Point
] = EY_POINT_NO_OWNER
;
571 SpawnEvent(Point
, BG_EYE_NEUTRAL_TEAM
, true); // will despawn alliance/horde
573 //buff isn't despawned
575 if (Team
== ALLIANCE
)
576 SendMessageToAll(LoosingPointTypes
[Point
].MessageIdAlliance
,CHAT_MSG_BG_SYSTEM_ALLIANCE
, Source
);
578 SendMessageToAll(LoosingPointTypes
[Point
].MessageIdHorde
,CHAT_MSG_BG_SYSTEM_HORDE
, Source
);
580 UpdatePointsIcons(Team
, Point
);
581 UpdatePointsCount(Team
);
584 void BattleGroundEY::EventTeamCapturedPoint(Player
*Source
, uint32 Point
)
586 if (GetStatus() != STATUS_IN_PROGRESS
)
589 uint32 Team
= Source
->GetTeam();
591 m_TeamPointsCount
[GetTeamIndexByTeamId(Team
)]++;
592 SpawnEvent(Point
, GetTeamIndexByTeamId(Team
), true);
594 //buff isn't respawned
596 m_PointOwnedByTeam
[Point
] = Team
;
597 m_PointState
[Point
] = EY_POINT_UNDER_CONTROL
;
599 if (Team
== ALLIANCE
)
600 SendMessageToAll(CapturingPointTypes
[Point
].MessageIdAlliance
,CHAT_MSG_BG_SYSTEM_ALLIANCE
, Source
);
602 SendMessageToAll(CapturingPointTypes
[Point
].MessageIdHorde
,CHAT_MSG_BG_SYSTEM_HORDE
, Source
);
604 UpdatePointsIcons(Team
, Point
);
605 UpdatePointsCount(Team
);
608 void BattleGroundEY::EventPlayerCapturedFlag(Player
*Source
, BG_EY_Nodes node
)
610 if (GetStatus() != STATUS_IN_PROGRESS
|| GetFlagPickerGUID() != Source
->GetGUID())
614 m_FlagState
= BG_EY_FLAG_STATE_WAIT_RESPAWN
;
615 Source
->RemoveAurasDueToSpell(BG_EY_NETHERSTORM_FLAG_SPELL
);
617 Source
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
619 if (Source
->GetTeam() == ALLIANCE
)
620 PlaySoundToAll(BG_EY_SOUND_FLAG_CAPTURED_ALLIANCE
);
622 PlaySoundToAll(BG_EY_SOUND_FLAG_CAPTURED_HORDE
);
624 SpawnEvent(BG_EY_EVENT_CAPTURE_FLAG
, node
, true);
626 m_FlagsTimer
= BG_EY_FLAG_RESPAWN_TIME
;
629 if (Source
->GetTeam() == ALLIANCE
)
631 team_id
= BG_TEAM_ALLIANCE
;
632 SendMessageToAll(LANG_BG_EY_CAPTURED_FLAG_A
, CHAT_MSG_BG_SYSTEM_ALLIANCE
, Source
);
636 team_id
= BG_TEAM_HORDE
;
637 SendMessageToAll(LANG_BG_EY_CAPTURED_FLAG_H
, CHAT_MSG_BG_SYSTEM_HORDE
, Source
);
640 if (m_TeamPointsCount
[team_id
] > 0)
641 AddPoints(Source
->GetTeam(), BG_EY_FlagPoints
[m_TeamPointsCount
[team_id
] - 1]);
643 UpdatePlayerScore(Source
, SCORE_FLAG_CAPTURES
, 1);
646 void BattleGroundEY::UpdatePlayerScore(Player
*Source
, uint32 type
, uint32 value
)
648 BattleGroundScoreMap::iterator itr
= m_PlayerScores
.find(Source
->GetGUID());
649 if(itr
== m_PlayerScores
.end()) // player not found
654 case SCORE_FLAG_CAPTURES
: // flags captured
655 ((BattleGroundEYScore
*)itr
->second
)->FlagCaptures
+= value
;
658 BattleGround::UpdatePlayerScore(Source
, type
, value
);
663 void BattleGroundEY::FillInitialWorldStates(WorldPacket
& data
)
665 data
<< uint32(EY_HORDE_BASE
) << uint32(m_TeamPointsCount
[BG_TEAM_HORDE
]);
666 data
<< uint32(EY_ALLIANCE_BASE
) << uint32(m_TeamPointsCount
[BG_TEAM_ALLIANCE
]);
667 data
<< uint32(0xab6) << uint32(0x0);
668 data
<< uint32(0xab5) << uint32(0x0);
669 data
<< uint32(0xab4) << uint32(0x0);
670 data
<< uint32(0xab3) << uint32(0x0);
671 data
<< uint32(0xab2) << uint32(0x0);
672 data
<< uint32(0xab1) << uint32(0x0);
673 data
<< uint32(0xab0) << uint32(0x0);
674 data
<< uint32(0xaaf) << uint32(0x0);
676 data
<< uint32(DRAENEI_RUINS_HORDE_CONTROL
) << uint32(m_PointOwnedByTeam
[DRAENEI_RUINS
] == HORDE
&& m_PointState
[DRAENEI_RUINS
] == EY_POINT_UNDER_CONTROL
);
678 data
<< uint32(DRAENEI_RUINS_ALLIANCE_CONTROL
) << uint32(m_PointOwnedByTeam
[DRAENEI_RUINS
] == ALLIANCE
&& m_PointState
[DRAENEI_RUINS
] == EY_POINT_UNDER_CONTROL
);
680 data
<< uint32(DRAENEI_RUINS_UNCONTROL
) << uint32(m_PointState
[DRAENEI_RUINS
] != EY_POINT_UNDER_CONTROL
);
682 data
<< uint32(MAGE_TOWER_ALLIANCE_CONTROL
) << uint32(m_PointOwnedByTeam
[MAGE_TOWER
] == ALLIANCE
&& m_PointState
[MAGE_TOWER
] == EY_POINT_UNDER_CONTROL
);
684 data
<< uint32(MAGE_TOWER_HORDE_CONTROL
) << uint32(m_PointOwnedByTeam
[MAGE_TOWER
] == HORDE
&& m_PointState
[MAGE_TOWER
] == EY_POINT_UNDER_CONTROL
);
686 data
<< uint32(MAGE_TOWER_UNCONTROL
) << uint32(m_PointState
[MAGE_TOWER
] != EY_POINT_UNDER_CONTROL
);
688 data
<< uint32(FEL_REAVER_HORDE_CONTROL
) << uint32(m_PointOwnedByTeam
[FEL_REALVER
] == HORDE
&& m_PointState
[FEL_REALVER
] == EY_POINT_UNDER_CONTROL
);
690 data
<< uint32(FEL_REAVER_ALLIANCE_CONTROL
) << uint32(m_PointOwnedByTeam
[FEL_REALVER
] == ALLIANCE
&& m_PointState
[FEL_REALVER
] == EY_POINT_UNDER_CONTROL
);
692 data
<< uint32(FEL_REAVER_UNCONTROL
) << uint32(m_PointState
[FEL_REALVER
] != EY_POINT_UNDER_CONTROL
);
694 data
<< uint32(BLOOD_ELF_HORDE_CONTROL
) << uint32(m_PointOwnedByTeam
[BLOOD_ELF
] == HORDE
&& m_PointState
[BLOOD_ELF
] == EY_POINT_UNDER_CONTROL
);
696 data
<< uint32(BLOOD_ELF_ALLIANCE_CONTROL
) << uint32(m_PointOwnedByTeam
[BLOOD_ELF
] == ALLIANCE
&& m_PointState
[BLOOD_ELF
] == EY_POINT_UNDER_CONTROL
);
698 data
<< uint32(BLOOD_ELF_UNCONTROL
) << uint32(m_PointState
[BLOOD_ELF
] != EY_POINT_UNDER_CONTROL
);
700 data
<< uint32(NETHERSTORM_FLAG
) << uint32(m_FlagState
== BG_EY_FLAG_STATE_ON_BASE
);
702 data
<< uint32(0xad2) << uint32(0x1);
703 data
<< uint32(0xad1) << uint32(0x1);
704 data
<< uint32(0xabe) << uint32(GetTeamScore(HORDE
));
705 data
<< uint32(0xabd) << uint32(GetTeamScore(ALLIANCE
));
706 data
<< uint32(0xa05) << uint32(0x8e);
707 data
<< uint32(0xaa0) << uint32(0x0);
708 data
<< uint32(0xa9f) << uint32(0x0);
709 data
<< uint32(0xa9e) << uint32(0x0);
710 data
<< uint32(0xc0d) << uint32(0x17b);
713 WorldSafeLocsEntry
const *BattleGroundEY::GetClosestGraveYard(Player
* player
)
717 switch(player
->GetTeam())
719 case ALLIANCE
: g_id
= EY_GRAVEYARD_MAIN_ALLIANCE
; break;
720 case HORDE
: g_id
= EY_GRAVEYARD_MAIN_HORDE
; break;
721 default: return NULL
;
724 float distance
, nearestDistance
;
726 WorldSafeLocsEntry
const* entry
= NULL
;
727 WorldSafeLocsEntry
const* nearestEntry
= NULL
;
728 entry
= sWorldSafeLocsStore
.LookupEntry(g_id
);
729 nearestEntry
= entry
;
733 sLog
.outError("BattleGroundEY: Not found the main team graveyard. Graveyard system isn't working!");
737 float plr_x
= player
->GetPositionX();
738 float plr_y
= player
->GetPositionY();
739 float plr_z
= player
->GetPositionZ();
742 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
);
743 nearestDistance
= distance
;
745 for(uint8 i
= 0; i
< BG_EY_NODES_MAX
; ++i
)
747 if (m_PointOwnedByTeam
[i
]==player
->GetTeam() && m_PointState
[i
]==EY_POINT_UNDER_CONTROL
)
749 entry
= sWorldSafeLocsStore
.LookupEntry(CapturingPointTypes
[i
].GraveYardId
);
751 sLog
.outError("BattleGroundEY: Not found graveyard: %u",CapturingPointTypes
[i
].GraveYardId
);
754 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
);
755 if (distance
< nearestDistance
)
757 nearestDistance
= distance
;
758 nearestEntry
= entry
;
767 bool BattleGroundEY::IsAllNodesConrolledByTeam(uint32 team
) const
770 for(int i
= 0; i
< BG_EY_NODES_MAX
; ++i
)
771 if (m_PointOwnedByTeam
[i
] == team
&& m_PointState
[i
] == EY_POINT_UNDER_CONTROL
)
774 return count
== BG_EY_NODES_MAX
;