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
21 #include "BattleGround.h"
22 #include "BattleGroundWS.h"
24 #include "GameObject.h"
25 #include "ObjectMgr.h"
26 #include "WorldPacket.h"
29 BattleGroundWS::BattleGroundWS()
31 m_BgObjects
.resize(BG_WS_OBJECT_MAX
);
32 m_BgCreatures
.resize(BG_CREATURES_MAX_WS
);
34 m_StartMessageIds
[BG_STARTING_EVENT_FIRST
] = LANG_BG_WS_START_TWO_MINUTES
;
35 m_StartMessageIds
[BG_STARTING_EVENT_SECOND
] = LANG_BG_WS_START_ONE_MINUTE
;
36 m_StartMessageIds
[BG_STARTING_EVENT_THIRD
] = LANG_BG_WS_START_HALF_MINUTE
;
37 m_StartMessageIds
[BG_STARTING_EVENT_FOURTH
] = LANG_BG_WS_HAS_BEGUN
;
40 BattleGroundWS::~BattleGroundWS()
44 void BattleGroundWS::Update(uint32 diff
)
46 BattleGround::Update(diff
);
48 if (GetStatus() == STATUS_IN_PROGRESS
)
50 if (m_FlagState
[BG_TEAM_ALLIANCE
] == BG_WS_FLAG_STATE_WAIT_RESPAWN
)
52 m_FlagsTimer
[BG_TEAM_ALLIANCE
] -= diff
;
54 if (m_FlagsTimer
[BG_TEAM_ALLIANCE
] < 0)
56 m_FlagsTimer
[BG_TEAM_ALLIANCE
] = 0;
57 RespawnFlag(ALLIANCE
, true);
60 if (m_FlagState
[BG_TEAM_ALLIANCE
] == BG_WS_FLAG_STATE_ON_GROUND
)
62 m_FlagsDropTimer
[BG_TEAM_ALLIANCE
] -= diff
;
64 if (m_FlagsDropTimer
[BG_TEAM_ALLIANCE
] < 0)
66 m_FlagsDropTimer
[BG_TEAM_ALLIANCE
] = 0;
67 RespawnFlagAfterDrop(ALLIANCE
);
70 if (m_FlagState
[BG_TEAM_HORDE
] == BG_WS_FLAG_STATE_WAIT_RESPAWN
)
72 m_FlagsTimer
[BG_TEAM_HORDE
] -= diff
;
74 if (m_FlagsTimer
[BG_TEAM_HORDE
] < 0)
76 m_FlagsTimer
[BG_TEAM_HORDE
] = 0;
77 RespawnFlag(HORDE
, true);
80 if (m_FlagState
[BG_TEAM_HORDE
] == BG_WS_FLAG_STATE_ON_GROUND
)
82 m_FlagsDropTimer
[BG_TEAM_HORDE
] -= diff
;
84 if (m_FlagsDropTimer
[BG_TEAM_HORDE
] < 0)
86 m_FlagsDropTimer
[BG_TEAM_HORDE
] = 0;
87 RespawnFlagAfterDrop(HORDE
);
93 void BattleGroundWS::StartingEventCloseDoors()
95 for(uint32 i
= BG_WS_OBJECT_DOOR_A_1
; i
<= BG_WS_OBJECT_DOOR_H_4
; ++i
)
98 SpawnBGObject(i
, RESPAWN_IMMEDIATELY
);
100 for(uint32 i
= BG_WS_OBJECT_A_FLAG
; i
<= BG_WS_OBJECT_BERSERKBUFF_2
; ++i
)
101 SpawnBGObject(i
, RESPAWN_ONE_DAY
);
104 void BattleGroundWS::StartingEventOpenDoors()
106 for(uint32 i
= BG_WS_OBJECT_DOOR_A_1
; i
<= BG_WS_OBJECT_DOOR_A_4
; ++i
)
108 for(uint32 i
= BG_WS_OBJECT_DOOR_H_1
; i
<= BG_WS_OBJECT_DOOR_H_2
; ++i
)
111 SpawnBGObject(BG_WS_OBJECT_DOOR_A_5
, RESPAWN_ONE_DAY
);
112 SpawnBGObject(BG_WS_OBJECT_DOOR_A_6
, RESPAWN_ONE_DAY
);
113 SpawnBGObject(BG_WS_OBJECT_DOOR_H_3
, RESPAWN_ONE_DAY
);
114 SpawnBGObject(BG_WS_OBJECT_DOOR_H_4
, RESPAWN_ONE_DAY
);
116 for(uint32 i
= BG_WS_OBJECT_A_FLAG
; i
<= BG_WS_OBJECT_BERSERKBUFF_2
; ++i
)
117 SpawnBGObject(i
, RESPAWN_IMMEDIATELY
);
120 void BattleGroundWS::AddPlayer(Player
*plr
)
122 BattleGround::AddPlayer(plr
);
123 //create score and add it to map, default values are set in constructor
124 BattleGroundWGScore
* sc
= new BattleGroundWGScore
;
126 m_PlayerScores
[plr
->GetGUID()] = sc
;
129 void BattleGroundWS::RespawnFlag(uint32 Team
, bool captured
)
131 if (Team
== ALLIANCE
)
133 sLog
.outDebug("Respawn Alliance flag");
134 m_FlagState
[BG_TEAM_ALLIANCE
] = BG_WS_FLAG_STATE_ON_BASE
;
138 sLog
.outDebug("Respawn Horde flag");
139 m_FlagState
[BG_TEAM_HORDE
] = BG_WS_FLAG_STATE_ON_BASE
;
144 //when map_update will be allowed for battlegrounds this code will be useless
145 SpawnBGObject(BG_WS_OBJECT_H_FLAG
, RESPAWN_IMMEDIATELY
);
146 SpawnBGObject(BG_WS_OBJECT_A_FLAG
, RESPAWN_IMMEDIATELY
);
147 SendMessageToAll(LANG_BG_WS_F_PLACED
, CHAT_MSG_BG_SYSTEM_NEUTRAL
);
148 PlaySoundToAll(BG_WS_SOUND_FLAGS_RESPAWNED
); // flag respawned sound...
152 void BattleGroundWS::RespawnFlagAfterDrop(uint32 team
)
154 if (GetStatus() != STATUS_IN_PROGRESS
)
157 RespawnFlag(team
,false);
158 if (team
== ALLIANCE
)
160 SpawnBGObject(BG_WS_OBJECT_A_FLAG
, RESPAWN_IMMEDIATELY
);
161 SendMessageToAll(LANG_BG_WS_ALLIANCE_FLAG_RESPAWNED
, CHAT_MSG_BG_SYSTEM_NEUTRAL
);
165 SpawnBGObject(BG_WS_OBJECT_H_FLAG
, RESPAWN_IMMEDIATELY
);
166 SendMessageToAll(LANG_BG_WS_HORDE_FLAG_RESPAWNED
, CHAT_MSG_BG_SYSTEM_NEUTRAL
);
169 PlaySoundToAll(BG_WS_SOUND_FLAGS_RESPAWNED
);
171 GameObject
*obj
= HashMapHolder
<GameObject
>::Find(GetDroppedFlagGUID(team
));
175 sLog
.outError("unknown droped flag bg, guid: %u",GUID_LOPART(GetDroppedFlagGUID(team
)));
177 SetDroppedFlagGUID(0,team
);
180 void BattleGroundWS::EventPlayerCapturedFlag(Player
*Source
)
182 if (GetStatus() != STATUS_IN_PROGRESS
)
187 Source
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
188 if (Source
->GetTeam() == ALLIANCE
)
190 if (!IsHordeFlagPickedup())
192 SetHordeFlagPicker(0); // must be before aura remove to prevent 2 events (drop+capture) at the same time
193 // horde flag in base (but not respawned yet)
194 m_FlagState
[BG_TEAM_HORDE
] = BG_WS_FLAG_STATE_WAIT_RESPAWN
;
195 // Drop Horde Flag from Player
196 Source
->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG
);
197 if (GetTeamScore(ALLIANCE
) < BG_WS_MAX_TEAM_SCORE
)
198 AddPoint(ALLIANCE
, 1);
199 PlaySoundToAll(BG_WS_SOUND_FLAG_CAPTURED_ALLIANCE
);
200 RewardReputationToTeam(890, m_ReputationCapture
, ALLIANCE
);
204 if (!IsAllianceFlagPickedup())
206 SetAllianceFlagPicker(0); // must be before aura remove to prevent 2 events (drop+capture) at the same time
207 // alliance flag in base (but not respawned yet)
208 m_FlagState
[BG_TEAM_ALLIANCE
] = BG_WS_FLAG_STATE_WAIT_RESPAWN
;
209 // Drop Alliance Flag from Player
210 Source
->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG
);
211 if (GetTeamScore(HORDE
) < BG_WS_MAX_TEAM_SCORE
)
213 PlaySoundToAll(BG_WS_SOUND_FLAG_CAPTURED_HORDE
);
214 RewardReputationToTeam(889, m_ReputationCapture
, HORDE
);
216 //for flag capture is reward 2 honorable kills
217 RewardHonorToTeam(GetBonusHonorFromKill(2), Source
->GetTeam());
219 SpawnBGObject(BG_WS_OBJECT_H_FLAG
, BG_WS_FLAG_RESPAWN_TIME
);
220 SpawnBGObject(BG_WS_OBJECT_A_FLAG
, BG_WS_FLAG_RESPAWN_TIME
);
222 if (Source
->GetTeam() == ALLIANCE
)
223 SendMessageToAll(LANG_BG_WS_CAPTURED_HF
, CHAT_MSG_BG_SYSTEM_ALLIANCE
, Source
);
225 SendMessageToAll(LANG_BG_WS_CAPTURED_AF
, CHAT_MSG_BG_SYSTEM_HORDE
, Source
);
227 UpdateFlagState(Source
->GetTeam(), 1); // flag state none
228 UpdateTeamScore(Source
->GetTeam());
229 // only flag capture should be updated
230 UpdatePlayerScore(Source
, SCORE_FLAG_CAPTURES
, 1); // +1 flag captures
232 if (GetTeamScore(ALLIANCE
) == BG_WS_MAX_TEAM_SCORE
)
235 if (GetTeamScore(HORDE
) == BG_WS_MAX_TEAM_SCORE
)
240 UpdateWorldState(BG_WS_FLAG_UNK_ALLIANCE
, 0);
241 UpdateWorldState(BG_WS_FLAG_UNK_HORDE
, 0);
242 UpdateWorldState(BG_WS_FLAG_STATE_ALLIANCE
, 1);
243 UpdateWorldState(BG_WS_FLAG_STATE_HORDE
, 1);
245 EndBattleGround(winner
);
249 m_FlagsTimer
[GetTeamIndexByTeamId(Source
->GetTeam()) ? 0 : 1] = BG_WS_FLAG_RESPAWN_TIME
;
253 void BattleGroundWS::EventPlayerDroppedFlag(Player
*Source
)
255 if (GetStatus() != STATUS_IN_PROGRESS
)
257 // if not running, do not cast things at the dropper player (prevent spawning the "dropped" flag), neither send unnecessary messages
258 // just take off the aura
259 if (Source
->GetTeam() == ALLIANCE
)
261 if (!this->IsHordeFlagPickedup())
263 if (GetHordeFlagPickerGUID() == Source
->GetGUID())
265 SetHordeFlagPicker(0);
266 Source
->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG
);
271 if (!this->IsAllianceFlagPickedup())
273 if (GetAllianceFlagPickerGUID() == Source
->GetGUID())
275 SetAllianceFlagPicker(0);
276 Source
->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG
);
284 if (Source
->GetTeam() == ALLIANCE
)
286 if (!IsHordeFlagPickedup())
288 if (GetHordeFlagPickerGUID() == Source
->GetGUID())
290 SetHordeFlagPicker(0);
291 Source
->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG
);
292 m_FlagState
[BG_TEAM_HORDE
] = BG_WS_FLAG_STATE_ON_GROUND
;
293 Source
->CastSpell(Source
, BG_WS_SPELL_WARSONG_FLAG_DROPPED
, true);
299 if (!IsAllianceFlagPickedup())
301 if (GetAllianceFlagPickerGUID() == Source
->GetGUID())
303 SetAllianceFlagPicker(0);
304 Source
->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG
);
305 m_FlagState
[BG_TEAM_ALLIANCE
] = BG_WS_FLAG_STATE_ON_GROUND
;
306 Source
->CastSpell(Source
, BG_WS_SPELL_SILVERWING_FLAG_DROPPED
, true);
313 Source
->CastSpell(Source
, SPELL_RECENTLY_DROPPED_FLAG
, true);
314 UpdateFlagState(Source
->GetTeam(), 1);
316 if (Source
->GetTeam() == ALLIANCE
)
318 SendMessageToAll(LANG_BG_WS_DROPPED_HF
, CHAT_MSG_BG_SYSTEM_HORDE
, Source
);
319 UpdateWorldState(BG_WS_FLAG_UNK_HORDE
, uint32(-1));
323 SendMessageToAll(LANG_BG_WS_DROPPED_AF
, CHAT_MSG_BG_SYSTEM_ALLIANCE
, Source
);
324 UpdateWorldState(BG_WS_FLAG_UNK_ALLIANCE
, uint32(-1));
327 m_FlagsDropTimer
[GetTeamIndexByTeamId(Source
->GetTeam()) ? 0 : 1] = BG_WS_FLAG_DROP_TIME
;
331 void BattleGroundWS::EventPlayerClickedOnFlag(Player
*Source
, GameObject
* target_obj
)
333 if (GetStatus() != STATUS_IN_PROGRESS
)
336 int32 message_id
= 0;
339 //alliance flag picked up from base
340 if(Source
->GetTeam() == HORDE
&& GetFlagState(ALLIANCE
) == BG_WS_FLAG_STATE_ON_BASE
341 && m_BgObjects
[BG_WS_OBJECT_A_FLAG
] == target_obj
->GetGUID())
343 message_id
= LANG_BG_WS_PICKEDUP_AF
;
344 type
= CHAT_MSG_BG_SYSTEM_HORDE
;
345 PlaySoundToAll(BG_WS_SOUND_ALLIANCE_FLAG_PICKED_UP
);
346 SpawnBGObject(BG_WS_OBJECT_A_FLAG
, RESPAWN_ONE_DAY
);
347 SetAllianceFlagPicker(Source
->GetGUID());
348 m_FlagState
[BG_TEAM_ALLIANCE
] = BG_WS_FLAG_STATE_ON_PLAYER
;
349 //update world state to show correct flag carrier
350 UpdateFlagState(HORDE
, BG_WS_FLAG_STATE_ON_PLAYER
);
351 UpdateWorldState(BG_WS_FLAG_UNK_ALLIANCE
, 1);
352 Source
->CastSpell(Source
, BG_WS_SPELL_SILVERWING_FLAG
, true);
355 //horde flag picked up from base
356 if (Source
->GetTeam() == ALLIANCE
&& GetFlagState(HORDE
) == BG_WS_FLAG_STATE_ON_BASE
357 && m_BgObjects
[BG_WS_OBJECT_H_FLAG
] == target_obj
->GetGUID())
359 message_id
= LANG_BG_WS_PICKEDUP_HF
;
360 type
= CHAT_MSG_BG_SYSTEM_ALLIANCE
;
361 PlaySoundToAll(BG_WS_SOUND_HORDE_FLAG_PICKED_UP
);
362 SpawnBGObject(BG_WS_OBJECT_H_FLAG
, RESPAWN_ONE_DAY
);
363 SetHordeFlagPicker(Source
->GetGUID());
364 m_FlagState
[BG_TEAM_HORDE
] = BG_WS_FLAG_STATE_ON_PLAYER
;
365 //update world state to show correct flag carrier
366 UpdateFlagState(ALLIANCE
, BG_WS_FLAG_STATE_ON_PLAYER
);
367 UpdateWorldState(BG_WS_FLAG_UNK_HORDE
, 1);
368 Source
->CastSpell(Source
, BG_WS_SPELL_WARSONG_FLAG
, true);
371 //Alliance flag on ground(not in base) (returned or picked up again from ground!)
372 if (GetFlagState(ALLIANCE
) == BG_WS_FLAG_STATE_ON_GROUND
&& Source
->IsWithinDistInMap(target_obj
, 10))
374 if (Source
->GetTeam() == ALLIANCE
)
376 message_id
= LANG_BG_WS_RETURNED_AF
;
377 type
= CHAT_MSG_BG_SYSTEM_ALLIANCE
;
378 UpdateFlagState(HORDE
, BG_WS_FLAG_STATE_WAIT_RESPAWN
);
379 RespawnFlag(ALLIANCE
, false);
380 SpawnBGObject(BG_WS_OBJECT_A_FLAG
, RESPAWN_IMMEDIATELY
);
381 PlaySoundToAll(BG_WS_SOUND_FLAG_RETURNED
);
382 UpdatePlayerScore(Source
, SCORE_FLAG_RETURNS
, 1);
386 message_id
= LANG_BG_WS_PICKEDUP_AF
;
387 type
= CHAT_MSG_BG_SYSTEM_HORDE
;
388 PlaySoundToAll(BG_WS_SOUND_ALLIANCE_FLAG_PICKED_UP
);
389 SpawnBGObject(BG_WS_OBJECT_A_FLAG
, RESPAWN_ONE_DAY
);
390 SetAllianceFlagPicker(Source
->GetGUID());
391 Source
->CastSpell(Source
, BG_WS_SPELL_SILVERWING_FLAG
, true);
392 m_FlagState
[BG_TEAM_ALLIANCE
] = BG_WS_FLAG_STATE_ON_PLAYER
;
393 UpdateFlagState(HORDE
, BG_WS_FLAG_STATE_ON_PLAYER
);
394 UpdateWorldState(BG_WS_FLAG_UNK_ALLIANCE
, 1);
396 //called in HandleGameObjectUseOpcode:
397 //target_obj->Delete();
400 //Horde flag on ground(not in base) (returned or picked up again)
401 if (GetFlagState(HORDE
) == BG_WS_FLAG_STATE_ON_GROUND
&& Source
->IsWithinDistInMap(target_obj
, 10))
403 if (Source
->GetTeam() == HORDE
)
405 message_id
= LANG_BG_WS_RETURNED_HF
;
406 type
= CHAT_MSG_BG_SYSTEM_HORDE
;
407 UpdateFlagState(ALLIANCE
, BG_WS_FLAG_STATE_WAIT_RESPAWN
);
408 RespawnFlag(HORDE
, false);
409 SpawnBGObject(BG_WS_OBJECT_H_FLAG
, RESPAWN_IMMEDIATELY
);
410 PlaySoundToAll(BG_WS_SOUND_FLAG_RETURNED
);
411 UpdatePlayerScore(Source
, SCORE_FLAG_RETURNS
, 1);
415 message_id
= LANG_BG_WS_PICKEDUP_HF
;
416 type
= CHAT_MSG_BG_SYSTEM_ALLIANCE
;
417 PlaySoundToAll(BG_WS_SOUND_HORDE_FLAG_PICKED_UP
);
418 SpawnBGObject(BG_WS_OBJECT_H_FLAG
, RESPAWN_ONE_DAY
);
419 SetHordeFlagPicker(Source
->GetGUID());
420 Source
->CastSpell(Source
, BG_WS_SPELL_WARSONG_FLAG
, true);
421 m_FlagState
[BG_TEAM_HORDE
] = BG_WS_FLAG_STATE_ON_PLAYER
;
422 UpdateFlagState(ALLIANCE
, BG_WS_FLAG_STATE_ON_PLAYER
);
423 UpdateWorldState(BG_WS_FLAG_UNK_HORDE
, 1);
425 //called in HandleGameObjectUseOpcode:
426 //target_obj->Delete();
432 SendMessageToAll(message_id
, type
, Source
);
433 Source
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
436 void BattleGroundWS::RemovePlayer(Player
*plr
, uint64 guid
)
438 // sometimes flag aura not removed :(
439 if (IsAllianceFlagPickedup() && m_FlagKeepers
[BG_TEAM_ALLIANCE
] == guid
)
443 sLog
.outError("BattleGroundWS: Removing offline player who has the FLAG!!");
444 SetAllianceFlagPicker(0);
445 RespawnFlag(ALLIANCE
, false);
448 EventPlayerDroppedFlag(plr
);
450 if (IsHordeFlagPickedup() && m_FlagKeepers
[BG_TEAM_HORDE
] == guid
)
454 sLog
.outError("BattleGroundWS: Removing offline player who has the FLAG!!");
455 SetHordeFlagPicker(0);
456 RespawnFlag(HORDE
, false);
459 EventPlayerDroppedFlag(plr
);
463 void BattleGroundWS::UpdateFlagState(uint32 team
, uint32 value
)
465 if (team
== ALLIANCE
)
466 UpdateWorldState(BG_WS_FLAG_STATE_ALLIANCE
, value
);
468 UpdateWorldState(BG_WS_FLAG_STATE_HORDE
, value
);
471 void BattleGroundWS::UpdateTeamScore(uint32 team
)
473 if (team
== ALLIANCE
)
474 UpdateWorldState(BG_WS_FLAG_CAPTURES_ALLIANCE
, GetTeamScore(team
));
476 UpdateWorldState(BG_WS_FLAG_CAPTURES_HORDE
, GetTeamScore(team
));
479 void BattleGroundWS::HandleAreaTrigger(Player
*Source
, uint32 Trigger
)
481 // this is wrong way to implement these things. On official it done by gameobject spell cast.
482 if (GetStatus() != STATUS_IN_PROGRESS
)
485 //uint32 SpellId = 0;
486 //uint64 buff_guid = 0;
489 case 3686: // Alliance elixir of speed spawn. Trigger not working, because located inside other areatrigger, can be replaced by IsWithinDist(object, dist) in BattleGround::Update().
490 //buff_guid = m_BgObjects[BG_WS_OBJECT_SPEEDBUFF_1];
492 case 3687: // Horde elixir of speed spawn. Trigger not working, because located inside other areatrigger, can be replaced by IsWithinDist(object, dist) in BattleGround::Update().
493 //buff_guid = m_BgObjects[BG_WS_OBJECT_SPEEDBUFF_2];
495 case 3706: // Alliance elixir of regeneration spawn
496 //buff_guid = m_BgObjects[BG_WS_OBJECT_REGENBUFF_1];
498 case 3708: // Horde elixir of regeneration spawn
499 //buff_guid = m_BgObjects[BG_WS_OBJECT_REGENBUFF_2];
501 case 3707: // Alliance elixir of berserk spawn
502 //buff_guid = m_BgObjects[BG_WS_OBJECT_BERSERKBUFF_1];
504 case 3709: // Horde elixir of berserk spawn
505 //buff_guid = m_BgObjects[BG_WS_OBJECT_BERSERKBUFF_2];
507 case 3646: // Alliance Flag spawn
508 if (m_FlagState
[BG_TEAM_HORDE
] && !m_FlagState
[BG_TEAM_ALLIANCE
])
509 if (GetHordeFlagPickerGUID() == Source
->GetGUID())
510 EventPlayerCapturedFlag(Source
);
512 case 3647: // Horde Flag spawn
513 if (m_FlagState
[BG_TEAM_ALLIANCE
] && !m_FlagState
[BG_TEAM_HORDE
])
514 if (GetAllianceFlagPickerGUID() == Source
->GetGUID())
515 EventPlayerCapturedFlag(Source
);
523 sLog
.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", Trigger
);
524 Source
->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", Trigger
);
529 // HandleTriggerBuff(buff_guid,Source);
532 bool BattleGroundWS::SetupBattleGround()
535 if (!AddObject(BG_WS_OBJECT_A_FLAG
, BG_OBJECT_A_FLAG_WS_ENTRY
, 1540.423f
, 1481.325f
, 351.8284f
, 3.089233f
, 0, 0, 0.9996573f
, 0.02617699f
, BG_WS_FLAG_RESPAWN_TIME
/1000)
536 || !AddObject(BG_WS_OBJECT_H_FLAG
, BG_OBJECT_H_FLAG_WS_ENTRY
, 916.0226f
, 1434.405f
, 345.413f
, 0.01745329f
, 0, 0, 0.008726535f
, 0.9999619f
, BG_WS_FLAG_RESPAWN_TIME
/1000)
538 || !AddObject(BG_WS_OBJECT_SPEEDBUFF_1
, BG_OBJECTID_SPEEDBUFF_ENTRY
, 1449.93f
, 1470.71f
, 342.6346f
, -1.64061f
, 0, 0, 0.7313537f
, -0.6819983f
, BUFF_RESPAWN_TIME
)
539 || !AddObject(BG_WS_OBJECT_SPEEDBUFF_2
, BG_OBJECTID_SPEEDBUFF_ENTRY
, 1005.171f
, 1447.946f
, 335.9032f
, 1.64061f
, 0, 0, 0.7313537f
, 0.6819984f
, BUFF_RESPAWN_TIME
)
540 || !AddObject(BG_WS_OBJECT_REGENBUFF_1
, BG_OBJECTID_REGENBUFF_ENTRY
, 1317.506f
, 1550.851f
, 313.2344f
, -0.2617996f
, 0, 0, 0.1305263f
, -0.9914448f
, BUFF_RESPAWN_TIME
)
541 || !AddObject(BG_WS_OBJECT_REGENBUFF_2
, BG_OBJECTID_REGENBUFF_ENTRY
, 1110.451f
, 1353.656f
, 316.5181f
, -0.6806787f
, 0, 0, 0.333807f
, -0.9426414f
, BUFF_RESPAWN_TIME
)
542 || !AddObject(BG_WS_OBJECT_BERSERKBUFF_1
, BG_OBJECTID_BERSERKERBUFF_ENTRY
, 1320.09f
, 1378.79f
, 314.7532f
, 1.186824f
, 0, 0, 0.5591929f
, 0.8290376f
, BUFF_RESPAWN_TIME
)
543 || !AddObject(BG_WS_OBJECT_BERSERKBUFF_2
, BG_OBJECTID_BERSERKERBUFF_ENTRY
, 1139.688f
, 1560.288f
, 306.8432f
, -2.443461f
, 0, 0, 0.9396926f
, -0.3420201f
, BUFF_RESPAWN_TIME
)
545 || !AddObject(BG_WS_OBJECT_DOOR_A_1
, BG_OBJECT_DOOR_A_1_WS_ENTRY
, 1503.335f
, 1493.466f
, 352.1888f
, 3.115414f
, 0, 0, 0.9999143f
, 0.01308903f
, RESPAWN_IMMEDIATELY
)
546 || !AddObject(BG_WS_OBJECT_DOOR_A_2
, BG_OBJECT_DOOR_A_2_WS_ENTRY
, 1492.478f
, 1457.912f
, 342.9689f
, 3.115414f
, 0, 0, 0.9999143f
, 0.01308903f
, RESPAWN_IMMEDIATELY
)
547 || !AddObject(BG_WS_OBJECT_DOOR_A_3
, BG_OBJECT_DOOR_A_3_WS_ENTRY
, 1468.503f
, 1494.357f
, 351.8618f
, 3.115414f
, 0, 0, 0.9999143f
, 0.01308903f
, RESPAWN_IMMEDIATELY
)
548 || !AddObject(BG_WS_OBJECT_DOOR_A_4
, BG_OBJECT_DOOR_A_4_WS_ENTRY
, 1471.555f
, 1458.778f
, 362.6332f
, 3.115414f
, 0, 0, 0.9999143f
, 0.01308903f
, RESPAWN_IMMEDIATELY
)
549 || !AddObject(BG_WS_OBJECT_DOOR_A_5
, BG_OBJECT_DOOR_A_5_WS_ENTRY
, 1492.347f
, 1458.34f
, 342.3712f
, -0.03490669f
, 0, 0, 0.01745246f
, -0.9998477f
, RESPAWN_IMMEDIATELY
)
550 || !AddObject(BG_WS_OBJECT_DOOR_A_6
, BG_OBJECT_DOOR_A_6_WS_ENTRY
, 1503.466f
, 1493.367f
, 351.7352f
, -0.03490669f
, 0, 0, 0.01745246f
, -0.9998477f
, RESPAWN_IMMEDIATELY
)
552 || !AddObject(BG_WS_OBJECT_DOOR_H_1
, BG_OBJECT_DOOR_H_1_WS_ENTRY
, 949.1663f
, 1423.772f
, 345.6241f
, -0.5756807f
, -0.01673368f
, -0.004956111f
, -0.2839723f
, 0.9586737f
, RESPAWN_IMMEDIATELY
)
553 || !AddObject(BG_WS_OBJECT_DOOR_H_2
, BG_OBJECT_DOOR_H_2_WS_ENTRY
, 953.0507f
, 1459.842f
, 340.6526f
, -1.99662f
, -0.1971825f
, 0.1575096f
, -0.8239487f
, 0.5073641f
, RESPAWN_IMMEDIATELY
)
554 || !AddObject(BG_WS_OBJECT_DOOR_H_3
, BG_OBJECT_DOOR_H_3_WS_ENTRY
, 949.9523f
, 1422.751f
, 344.9273f
, 0.0f
, 0, 0, 0, 1, RESPAWN_IMMEDIATELY
)
555 || !AddObject(BG_WS_OBJECT_DOOR_H_4
, BG_OBJECT_DOOR_H_4_WS_ENTRY
, 950.7952f
, 1459.583f
, 342.1523f
, 0.05235988f
, 0, 0, 0.02617695f
, 0.9996573f
, RESPAWN_IMMEDIATELY
)
558 sLog
.outErrorDb("BatteGroundWS: Failed to spawn some object BattleGround not created!");
562 WorldSafeLocsEntry
const *sg
= sWorldSafeLocsStore
.LookupEntry(WS_GRAVEYARD_MAIN_ALLIANCE
);
563 if (!sg
|| !AddSpiritGuide(WS_SPIRIT_MAIN_ALLIANCE
, sg
->x
, sg
->y
, sg
->z
, 3.124139f
, ALLIANCE
))
565 sLog
.outErrorDb("BatteGroundWS: Failed to spawn Alliance spirit guide! BattleGround not created!");
569 sg
= sWorldSafeLocsStore
.LookupEntry(WS_GRAVEYARD_MAIN_HORDE
);
570 if (!sg
|| !AddSpiritGuide(WS_SPIRIT_MAIN_HORDE
, sg
->x
, sg
->y
, sg
->z
, 3.193953f
, HORDE
))
572 sLog
.outErrorDb("BatteGroundWS: Failed to spawn Horde spirit guide! BattleGround not created!");
576 sLog
.outDebug("BatteGroundWS: BG objects and spirit guides spawned");
581 void BattleGroundWS::Reset()
583 //call parent's class reset
584 BattleGround::Reset();
586 m_FlagKeepers
[BG_TEAM_ALLIANCE
] = 0;
587 m_FlagKeepers
[BG_TEAM_HORDE
] = 0;
588 m_DroppedFlagGUID
[BG_TEAM_ALLIANCE
] = 0;
589 m_DroppedFlagGUID
[BG_TEAM_HORDE
] = 0;
590 m_FlagState
[BG_TEAM_ALLIANCE
] = BG_WS_FLAG_STATE_ON_BASE
;
591 m_FlagState
[BG_TEAM_HORDE
] = BG_WS_FLAG_STATE_ON_BASE
;
592 m_TeamScores
[BG_TEAM_ALLIANCE
] = 0;
593 m_TeamScores
[BG_TEAM_HORDE
] = 0;
594 bool isBGWeekend
= false; //TODO FIXME - call sBattleGroundMgr.IsBGWeekend(m_TypeID); - you must also implement that call!
595 m_ReputationCapture
= (isBGWeekend
) ? 45 : 35;
596 m_HonorWinKills
= (isBGWeekend
) ? 3 : 1;
597 m_HonorEndKills
= (isBGWeekend
) ? 4 : 2;
599 /* Spirit nodes is static at this BG and then not required deleting at BG reset.
600 if (m_BgCreatures[WS_SPIRIT_MAIN_ALLIANCE])
601 DelCreature(WS_SPIRIT_MAIN_ALLIANCE);
602 if (m_BgCreatures[WS_SPIRIT_MAIN_HORDE])
603 DelCreature(WS_SPIRIT_MAIN_HORDE);
607 void BattleGroundWS::EndBattleGround(uint32 winner
)
610 if (winner
== ALLIANCE
)
611 RewardHonorToTeam(GetBonusHonorFromKill(m_HonorWinKills
), ALLIANCE
);
613 RewardHonorToTeam(GetBonusHonorFromKill(m_HonorWinKills
), HORDE
);
614 //complete map_end rewards (even if no team wins)
615 RewardHonorToTeam(GetBonusHonorFromKill(m_HonorEndKills
), ALLIANCE
);
616 RewardHonorToTeam(GetBonusHonorFromKill(m_HonorEndKills
), HORDE
);
618 BattleGround::EndBattleGround(winner
);
621 void BattleGroundWS::HandleKillPlayer(Player
*player
, Player
*killer
)
623 if (GetStatus() != STATUS_IN_PROGRESS
)
626 EventPlayerDroppedFlag(player
);
628 BattleGround::HandleKillPlayer(player
, killer
);
631 void BattleGroundWS::UpdatePlayerScore(Player
*Source
, uint32 type
, uint32 value
)
634 BattleGroundScoreMap::iterator itr
= m_PlayerScores
.find(Source
->GetGUID());
635 if(itr
== m_PlayerScores
.end()) // player not found
640 case SCORE_FLAG_CAPTURES
: // flags captured
641 ((BattleGroundWGScore
*)itr
->second
)->FlagCaptures
+= value
;
643 case SCORE_FLAG_RETURNS
: // flags returned
644 ((BattleGroundWGScore
*)itr
->second
)->FlagReturns
+= value
;
647 BattleGround::UpdatePlayerScore(Source
, type
, value
);
652 WorldSafeLocsEntry
const* BattleGroundWS::GetClosestGraveYard(Player
* player
)
654 //if status in progress, it returns main graveyards with spiritguides
655 //else it will return the graveyard in the flagroom - this is especially good
656 //if a player dies in preparation phase - then the player can't cheat
657 //and teleport to the graveyard outside the flagroom
658 //and start running around, while the doors are still closed
659 if (player
->GetTeam() == ALLIANCE
)
661 if (GetStatus() == STATUS_IN_PROGRESS
)
662 return sWorldSafeLocsStore
.LookupEntry(WS_GRAVEYARD_MAIN_ALLIANCE
);
664 return sWorldSafeLocsStore
.LookupEntry(WS_GRAVEYARD_FLAGROOM_ALLIANCE
);
668 if (GetStatus() == STATUS_IN_PROGRESS
)
669 return sWorldSafeLocsStore
.LookupEntry(WS_GRAVEYARD_MAIN_HORDE
);
671 return sWorldSafeLocsStore
.LookupEntry(WS_GRAVEYARD_FLAGROOM_HORDE
);
675 void BattleGroundWS::FillInitialWorldStates(WorldPacket
& data
)
677 data
<< uint32(BG_WS_FLAG_CAPTURES_ALLIANCE
) << uint32(GetTeamScore(ALLIANCE
));
678 data
<< uint32(BG_WS_FLAG_CAPTURES_HORDE
) << uint32(GetTeamScore(HORDE
));
680 if (m_FlagState
[BG_TEAM_ALLIANCE
] == BG_WS_FLAG_STATE_ON_GROUND
)
681 data
<< uint32(BG_WS_FLAG_UNK_ALLIANCE
) << uint32(-1);
682 else if (m_FlagState
[BG_TEAM_ALLIANCE
] == BG_WS_FLAG_STATE_ON_PLAYER
)
683 data
<< uint32(BG_WS_FLAG_UNK_ALLIANCE
) << uint32(1);
685 data
<< uint32(BG_WS_FLAG_UNK_ALLIANCE
) << uint32(0);
687 if (m_FlagState
[BG_TEAM_HORDE
] == BG_WS_FLAG_STATE_ON_GROUND
)
688 data
<< uint32(BG_WS_FLAG_UNK_HORDE
) << uint32(-1);
689 else if (m_FlagState
[BG_TEAM_HORDE
] == BG_WS_FLAG_STATE_ON_PLAYER
)
690 data
<< uint32(BG_WS_FLAG_UNK_HORDE
) << uint32(1);
692 data
<< uint32(BG_WS_FLAG_UNK_HORDE
) << uint32(0);
694 data
<< uint32(BG_WS_FLAG_CAPTURES_MAX
) << uint32(BG_WS_MAX_TEAM_SCORE
);
696 if (m_FlagState
[BG_TEAM_HORDE
] == BG_WS_FLAG_STATE_ON_PLAYER
)
697 data
<< uint32(BG_WS_FLAG_STATE_HORDE
) << uint32(2);
699 data
<< uint32(BG_WS_FLAG_STATE_HORDE
) << uint32(1);
701 if (m_FlagState
[BG_TEAM_ALLIANCE
] == BG_WS_FLAG_STATE_ON_PLAYER
)
702 data
<< uint32(BG_WS_FLAG_STATE_ALLIANCE
) << uint32(2);
704 data
<< uint32(BG_WS_FLAG_STATE_ALLIANCE
) << uint32(1);