root/trunk/src/game/BattleGroundEY.cpp @ 44

Revision 44, 41.1 kB (checked in by yumileroy, 17 years ago)

[svn] * Merge Temp dev SVN with Assembla.
* Changes include:

  • Implementation of w12x's Outdoor PvP and Game Event Systems.
  • Temporary removal of IRC Chat Bot (until infinite loop when disabled is fixed).
  • All mangos -> trinity (to convert your mangos_string table, please run mangos_string_to_trinity_string.sql).
  • Improved Config cleanup.
  • And many more changes.

Original author: Seline
Date: 2008-10-14 11:57:03-05:00

Line 
1/*
2 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
3 *
4 * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "Object.h"
22#include "Player.h"
23#include "BattleGround.h"
24#include "BattleGroundEY.h"
25#include "Creature.h"
26#include "Chat.h"
27#include "ObjectMgr.h"
28#include "MapManager.h"
29#include "Language.h"
30#include "World.h"
31#include "Util.h"
32
33BattleGroundEY::BattleGroundEY()
34{
35    m_BuffChange = true;
36    m_BgObjects.resize(BG_EY_OBJECT_MAX);
37    m_BgCreatures.resize(BG_EY_CREATURES_MAX);
38    m_Points_Trigger[FEL_REALVER] = TR_FEL_REALVER_BUFF;
39    m_Points_Trigger[BLOOD_ELF] = TR_BLOOD_ELF_BUFF;
40    m_Points_Trigger[DRAENEI_RUINS] = TR_DRAENEI_RUINS_BUFF;
41    m_Points_Trigger[MAGE_TOWER] = TR_MAGE_TOWER_BUFF;
42}
43
44BattleGroundEY::~BattleGroundEY()
45{
46}
47
48void BattleGroundEY::Update(time_t diff)
49{
50    BattleGround::Update(diff);
51    // after bg start we get there (once)
52    if (GetStatus() == STATUS_WAIT_JOIN && GetPlayersSize())
53    {
54        ModifyStartDelayTime(diff);
55
56        if(!(m_Events & 0x01))
57        {
58            m_Events |= 0x01;
59
60            // setup here, only when at least one player has ported to the map
61            if(!SetupBattleGround())
62            {
63                EndNow();
64                return;
65            }
66
67            SpawnBGObject(BG_EY_OBJECT_DOOR_A, RESPAWN_IMMEDIATELY);
68            SpawnBGObject(BG_EY_OBJECT_DOOR_H, RESPAWN_IMMEDIATELY);
69
70            for(uint32 i = BG_EY_OBJECT_A_BANNER_FEL_REALVER_CENTER; i < BG_EY_OBJECT_MAX; ++i)
71                SpawnBGObject(i, RESPAWN_ONE_DAY);
72
73            SetStartDelayTime(START_DELAY0);
74        }
75        // After 1 minute, warning is signalled
76        else if(GetStartDelayTime() <= START_DELAY1 && !(m_Events & 0x04))
77        {
78            m_Events |= 0x04;
79            SendMessageToAll(GetTrinityString(LANG_BG_EY_ONE_MINUTE));
80        }
81        // After 1,5 minute, warning is signalled
82        else if(GetStartDelayTime() <= START_DELAY2 && !(m_Events & 0x08))
83        {
84            m_Events |= 0x08;
85            SendMessageToAll(GetTrinityString(LANG_BG_EY_HALF_MINUTE));
86        }
87        // After 2 minutes, gates OPEN ! x)
88        else if(GetStartDelayTime() < 0 && !(m_Events & 0x10))
89        {
90            m_Events |= 0x10;
91            SpawnBGObject(BG_EY_OBJECT_DOOR_A, RESPAWN_ONE_DAY);
92            SpawnBGObject(BG_EY_OBJECT_DOOR_H, RESPAWN_ONE_DAY);
93
94            for(uint32 i = BG_EY_OBJECT_N_BANNER_FEL_REALVER_CENTER; i <= BG_EY_OBJECT_FLAG_NETHERSTORM; ++i)
95                SpawnBGObject(i, RESPAWN_IMMEDIATELY);
96            for(uint32 i = 0; i < EY_POINTS_MAX; ++i)
97            {
98                //randomly spawn buff
99                uint8 buff = urand(0, 2);
100                SpawnBGObject(BG_EY_OBJECT_SPEEDBUFF_FEL_REALVER + buff + i * 3, RESPAWN_IMMEDIATELY);
101            }
102
103            SendMessageToAll(GetTrinityString(LANG_BG_EY_BEGIN));
104
105            PlaySoundToAll(SOUND_BG_START);
106            if(sWorld.getConfig(CONFIG_BG_START_MUSIC))
107                PlaySoundToAll(SOUND_BG_START_L70ETC); //MUSIC
108            SetStatus(STATUS_IN_PROGRESS);
109
110            for(BattleGroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
111                if(Player *plr = objmgr.GetPlayer(itr->first))
112                    plr->RemoveAurasDueToSpell(SPELL_PREPARATION);
113        }
114    }
115    else if(GetStatus() == STATUS_IN_PROGRESS)
116    {
117        m_PointAddingTimer -= diff;
118        if(m_PointAddingTimer <= 0)
119        {
120            m_PointAddingTimer = BG_EY_FPOINTS_TICK_TIME;
121            if (m_TeamPointsCount[BG_TEAM_ALLIANCE] > 0)
122                AddPoints(ALLIANCE, BG_EY_TickPoints[m_TeamPointsCount[BG_TEAM_ALLIANCE] - 1]);
123            if (m_TeamPointsCount[BG_TEAM_HORDE] > 0)
124                AddPoints(HORDE, BG_EY_TickPoints[m_TeamPointsCount[BG_TEAM_HORDE] - 1]);
125        }
126
127        if(m_FlagState == BG_EY_FLAG_STATE_WAIT_RESPAWN || m_FlagState == BG_EY_FLAG_STATE_ON_GROUND)
128        {
129            m_FlagsTimer -= diff;
130
131            if(m_FlagsTimer < 0)
132            {
133                m_FlagsTimer = 0;
134                if (m_FlagState == BG_EY_FLAG_STATE_WAIT_RESPAWN)
135                    RespawnFlag(true);
136                else
137                    RespawnFlagAfterDrop();
138            }
139        }
140
141        m_TowerCapCheckTimer -= diff;
142        if(m_TowerCapCheckTimer <= 0)
143        {
144            //check if player joined point
145            /*I used this order of calls, because although we will check if one player is in gameobject's distance 2 times
146              but we can count of players on current point in CheckSomeoneLeftPoint
147            */
148            this->CheckSomeoneJoinedPoint();
149            //check if player left point
150            this->CheckSomeoneLeftPoint();
151            this->UpdatePointStatuses();
152            m_TowerCapCheckTimer = BG_EY_FPOINTS_TICK_TIME;
153        }
154    }
155}
156
157void BattleGroundEY::AddPoints(uint32 Team, uint32 Points)
158{
159    uint8 team_index = GetTeamIndexByTeamId(Team);
160    m_TeamScores[team_index] += Points;
161    m_HonorScoreTics[team_index] += Points;
162    if (m_HonorScoreTics[team_index] >= BG_HONOR_SCORE_TICKS)
163    {
164        RewardHonorToTeam(20, Team);
165        m_HonorScoreTics[team_index] -= BG_HONOR_SCORE_TICKS;
166    }
167    UpdateTeamScore(Team);
168}
169
170void BattleGroundEY::CheckSomeoneJoinedPoint()
171{
172    GameObject *obj = NULL;
173    for (uint8 i = 0; i < EY_POINTS_MAX; ++i)
174    {
175        obj = HashMapHolder<GameObject>::Find(m_BgObjects[BG_EY_OBJECT_TOWER_CAP_FEL_REALVER + i]);
176        if (obj)
177        {
178            uint8 j = 0;
179            while (j < m_PlayersNearPoint[EY_POINTS_MAX].size())
180            {
181                Player *plr = objmgr.GetPlayer(m_PlayersNearPoint[EY_POINTS_MAX][j]);
182                if(!plr)
183                {
184                    sLog.outError("BattleGroundEY: Player " I64FMTD " not found!", m_PlayersNearPoint[EY_POINTS_MAX][j]);
185                    ++j;
186                    continue;
187                }
188                if (plr->isAlive() && plr->IsWithinDistInMap(obj, BG_EY_POINT_RADIUS))
189                {
190                    //player joined point!
191                    //show progress bar
192                    UpdateWorldStateForPlayer(PROGRESS_BAR_PERCENT_GREY, BG_EY_PROGRESS_BAR_PERCENT_GREY, plr);
193                    UpdateWorldStateForPlayer(PROGRESS_BAR_STATUS, m_PointBarStatus[i], plr);
194                    UpdateWorldStateForPlayer(PROGRESS_BAR_SHOW, BG_EY_PROGRESS_BAR_SHOW, plr);
195                    //add player to point
196                    m_PlayersNearPoint[i].push_back(m_PlayersNearPoint[EY_POINTS_MAX][j]);
197                    //remove player from "free space"
198                    m_PlayersNearPoint[EY_POINTS_MAX].erase(m_PlayersNearPoint[EY_POINTS_MAX].begin() + j);
199                }
200                else
201                    ++j;
202            }
203        }
204    }
205}
206
207void BattleGroundEY::CheckSomeoneLeftPoint()
208{
209    //reset current point counts
210    for (uint8 i = 0; i < 2*EY_POINTS_MAX; ++i)
211        m_CurrentPointPlayersCount[i] = 0;
212    GameObject *obj = NULL;
213    for(uint8 i = 0; i < EY_POINTS_MAX; ++i)
214    {
215        obj = HashMapHolder<GameObject>::Find(m_BgObjects[BG_EY_OBJECT_TOWER_CAP_FEL_REALVER + i]);
216        if(obj)
217        {
218            uint8 j = 0;
219            while (j < m_PlayersNearPoint[i].size())
220            {
221                Player *plr = objmgr.GetPlayer(m_PlayersNearPoint[i][j]);
222                if (!plr)
223                {
224                    sLog.outError("BattleGroundEY: Player " I64FMTD " not found!", m_PlayersNearPoint[i][j]);
225                    //move not existed player to "free space" - this will cause many error showing in log, but it is a very important bug
226                    m_PlayersNearPoint[EY_POINTS_MAX].push_back(m_PlayersNearPoint[i][j]);
227                    m_PlayersNearPoint[i].erase(m_PlayersNearPoint[i].begin() + j);
228                    ++j;
229                    continue;
230                }
231                if (!plr->isAlive() || !plr->IsWithinDistInMap(obj, BG_EY_POINT_RADIUS))
232                    //move player out of point (add him to players that are out of points
233                {
234                    m_PlayersNearPoint[EY_POINTS_MAX].push_back(m_PlayersNearPoint[i][j]);
235                    m_PlayersNearPoint[i].erase(m_PlayersNearPoint[i].begin() + j);
236                    this->UpdateWorldStateForPlayer(PROGRESS_BAR_SHOW, BG_EY_PROGRESS_BAR_DONT_SHOW, plr);
237                }
238                else
239                {
240                    //player is neat flag, so update count:
241                    m_CurrentPointPlayersCount[2 * i + GetTeamIndexByTeamId(plr->GetTeam())]++;
242                    ++j;
243                }
244            }
245        }
246    }
247}
248
249void BattleGroundEY::UpdatePointStatuses()
250{
251    for(uint8 point = 0; point < EY_POINTS_MAX; ++point)
252    {
253        if (m_PlayersNearPoint[point].empty())
254            continue;
255        //count new point bar status:
256        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;
257
258        if (m_PointBarStatus[point] > BG_EY_PROGRESS_BAR_ALI_CONTROLLED)
259            //point is fully alliance's
260            m_PointBarStatus[point] = BG_EY_PROGRESS_BAR_ALI_CONTROLLED;
261        if (m_PointBarStatus[point] < BG_EY_PROGRESS_BAR_HORDE_CONTROLLED)
262            //point is fully horde's
263            m_PointBarStatus[point] = BG_EY_PROGRESS_BAR_HORDE_CONTROLLED;
264
265        uint32 pointOwnerTeamId = 0;
266        //find which team should own this point
267        if (m_PointBarStatus[point] <= BG_EY_PROGRESS_BAR_NEUTRAL_LOW)
268            pointOwnerTeamId = HORDE;
269        else if (m_PointBarStatus[point] >= BG_EY_PROGRESS_BAR_NEUTRAL_HIGH)
270            pointOwnerTeamId = ALLIANCE;
271        else
272            pointOwnerTeamId = EY_POINT_NO_OWNER;
273
274        for (uint8 i = 0; i < m_PlayersNearPoint[point].size(); ++i)
275        {
276            Player *plr = objmgr.GetPlayer(m_PlayersNearPoint[point][i]);
277            if (plr)
278            {
279                this->UpdateWorldStateForPlayer(PROGRESS_BAR_STATUS, m_PointBarStatus[point], plr);
280                                                            //if point owner changed we must evoke event!
281                if (pointOwnerTeamId != m_PointOwnedByTeam[point])
282                {
283                    //point was uncontrolled and player is from team which captured point
284                    if (m_PointState[point] == EY_POINT_STATE_UNCONTROLLED && plr->GetTeam() == pointOwnerTeamId)
285                        this->EventTeamCapturedPoint(plr, point);
286
287                    //point was under control and player isn't from team which controlled it
288                    if (m_PointState[point] == EY_POINT_UNDER_CONTROL && plr->GetTeam() != m_PointOwnedByTeam[point])
289                        this->EventTeamLostPoint(plr, point);
290                }
291            }
292        }
293    }
294}
295
296void BattleGroundEY::UpdateTeamScore(uint32 Team)
297{
298    uint32 score = GetTeamScore(Team);
299    if(score >= EY_MAX_TEAM_SCORE)
300    {
301        score = EY_MAX_TEAM_SCORE;
302        EndBattleGround(Team);
303    }
304
305    if(Team == ALLIANCE)
306        UpdateWorldState(EY_ALLIANCE_RESOURCES, score);
307    else
308        UpdateWorldState(EY_HORDE_RESOURCES, score);
309}
310
311void BattleGroundEY::UpdatePointsCount(uint32 Team)
312{
313    if(Team == ALLIANCE)
314        UpdateWorldState(EY_ALLIANCE_BASE, m_TeamPointsCount[BG_TEAM_ALLIANCE]);
315    else
316        UpdateWorldState(EY_HORDE_BASE, m_TeamPointsCount[BG_TEAM_HORDE]);
317}
318
319void BattleGroundEY::UpdatePointsIcons(uint32 Team, uint32 Point)
320{
321    //we MUST firstly send 0, after that we can send 1!!!
322    if (m_PointState[Point] == EY_POINT_UNDER_CONTROL)
323    {
324        UpdateWorldState(m_PointsIconStruct[Point].WorldStateControlIndex, 0);
325        if(Team == ALLIANCE)
326            UpdateWorldState(m_PointsIconStruct[Point].WorldStateAllianceControlledIndex, 1);
327        else
328            UpdateWorldState(m_PointsIconStruct[Point].WorldStateHordeControlledIndex, 1);
329    }
330    else
331    {
332        if(Team == ALLIANCE)
333            UpdateWorldState(m_PointsIconStruct[Point].WorldStateAllianceControlledIndex, 0);
334        else
335            UpdateWorldState(m_PointsIconStruct[Point].WorldStateHordeControlledIndex, 0);
336        UpdateWorldState(m_PointsIconStruct[Point].WorldStateControlIndex, 1);
337    }
338}
339
340void BattleGroundEY::AddPlayer(Player *plr)
341{
342    BattleGround::AddPlayer(plr);
343    //create score and add it to map
344    BattleGroundEYScore* sc = new BattleGroundEYScore;
345
346    m_PlayersNearPoint[EY_POINTS_MAX].push_back(plr->GetGUID());
347
348    m_PlayerScores[plr->GetGUID()] = sc;
349}
350
351void BattleGroundEY::RemovePlayer(Player *plr, uint64 guid)
352{
353    // sometimes flag aura not removed :(
354    for (int j = EY_POINTS_MAX; j >= 0; --j)
355    {
356        for(int i = 0; i < m_PlayersNearPoint[j].size(); ++i)
357            if(m_PlayersNearPoint[j][i] == guid)
358                m_PlayersNearPoint[j].erase(m_PlayersNearPoint[j].begin() + i);
359    }
360    if(IsFlagPickedup())
361    {
362        if(m_FlagKeeper == guid)
363        {
364            if(plr)
365                this->EventPlayerDroppedFlag(plr);
366            else
367            {
368                SetFlagPicker(0);
369                RespawnFlag(true);
370            }
371        }
372    }
373}
374
375void BattleGroundEY::HandleAreaTrigger(Player *Source, uint32 Trigger)
376{
377    if(GetStatus() != STATUS_IN_PROGRESS)
378        return;
379
380    if(!Source->isAlive())                                  //hack code, must be removed later
381        return;
382
383    switch(Trigger)
384    {
385        case TR_BLOOD_ELF_POINT:
386            if(m_PointState[BLOOD_ELF] == EY_POINT_UNDER_CONTROL && m_PointOwnedByTeam[BLOOD_ELF] == Source->GetTeam())
387                if(m_FlagState && GetFlagPickerGUID() == Source->GetGUID())
388                    EventPlayerCapturedFlag(Source, BG_EY_OBJECT_FLAG_BLOOD_ELF);
389            break;
390        case TR_FEL_REALVER_POINT:
391            if(m_PointState[FEL_REALVER] == EY_POINT_UNDER_CONTROL && m_PointOwnedByTeam[FEL_REALVER] == Source->GetTeam())
392                if(m_FlagState && GetFlagPickerGUID() == Source->GetGUID())
393                    EventPlayerCapturedFlag(Source, BG_EY_OBJECT_FLAG_FEL_REALVER);
394            break;
395        case TR_MAGE_TOWER_POINT:
396            if(m_PointState[MAGE_TOWER] == EY_POINT_UNDER_CONTROL && m_PointOwnedByTeam[MAGE_TOWER] == Source->GetTeam())
397                if(m_FlagState && GetFlagPickerGUID() == Source->GetGUID())
398                    EventPlayerCapturedFlag(Source, BG_EY_OBJECT_FLAG_MAGE_TOWER);
399            break;
400        case TR_DRAENEI_RUINS_POINT:
401            if(m_PointState[DRAENEI_RUINS] == EY_POINT_UNDER_CONTROL && m_PointOwnedByTeam[DRAENEI_RUINS] == Source->GetTeam())
402                if(m_FlagState && GetFlagPickerGUID() == Source->GetGUID())
403                    EventPlayerCapturedFlag(Source, BG_EY_OBJECT_FLAG_DRAENEI_RUINS);
404            break;
405        case 4512:
406        case 4515:
407        case 4517:
408        case 4519:
409        case 4530:
410        case 4531:
411        case 4568:
412        case 4569:
413        case 4570:
414        case 4571:
415            break;
416        default:
417            sLog.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", Trigger);
418            Source->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", Trigger);
419            break;
420    }
421}
422
423bool BattleGroundEY::SetupBattleGround()
424{
425        // doors
426    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)
427        || !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)
428        // banners (alliance)
429        || !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)
430        || !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)
431        || !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)
432        || !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)
433        || !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)
434        || !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)
435        || !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)
436        || !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)
437        || !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)
438        || !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)
439        || !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)
440        || !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)
441        // banners (horde)
442        || !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)
443        || !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)
444        || !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)
445        || !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)
446        || !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)
447        || !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)
448        || !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)
449        || !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)
450        || !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)
451        || !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)
452        || !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)
453        || !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)
454        // banners (natural)
455        || !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)
456        || !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)
457        || !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)
458        || !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)
459        || !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)
460        || !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)
461        || !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)
462        || !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)
463        || !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)
464        || !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)
465        || !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)
466        || !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)
467        // flags
468        || !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)
469        || !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)
470        || !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)
471        || !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)
472        || !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)
473        // tower cap
474        || !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)
475        || !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)
476        || !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)
477        || !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)
478        )
479    {
480        sLog.outErrorDb("BatteGroundEY: Failed to spawn some object BattleGround not created!");
481        return false;
482    }
483
484    //buffs
485    for (int i = 0; i < EY_POINTS_MAX; ++i)
486    {
487        AreaTriggerEntry const* at = sAreaTriggerStore.LookupEntry(m_Points_Trigger[i]);
488        if( !at )
489        {
490            sLog.outError("BattleGroundEY: Unknown trigger: %u", m_Points_Trigger[i]);
491            continue;
492        }
493        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)
494            || !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)
495            || !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)
496            )
497            sLog.outError("BattleGroundEY: Cannot spawn buff");
498    }
499
500    WorldSafeLocsEntry const *sg = NULL;
501    sg = sWorldSafeLocsStore.LookupEntry(EY_GRAVEYARD_MAIN_ALLIANCE);
502    if( !sg || !AddSpiritGuide(EY_SPIRIT_MAIN_ALLIANCE, sg->x, sg->y, sg->z, 3.124139f, ALLIANCE) )
503    {
504        sLog.outErrorDb("BatteGroundEY: Failed to spawn spirit guide! BattleGround not created!");
505        return false;
506    }
507
508    sg = sWorldSafeLocsStore.LookupEntry(EY_GRAVEYARD_MAIN_HORDE);
509    if( !sg || !AddSpiritGuide(EY_SPIRIT_MAIN_HORDE, sg->x, sg->y, sg->z, 3.193953f, HORDE) )
510    {
511        sLog.outErrorDb("BatteGroundEY: Failed to spawn spirit guide! BattleGround not created!");
512        return false;
513    }
514
515    return true;
516}
517
518void BattleGroundEY::ResetBGSubclass()
519{
520    m_TeamScores[BG_TEAM_ALLIANCE] = 0;
521    m_TeamScores[BG_TEAM_HORDE] = 0;
522    m_TeamPointsCount[BG_TEAM_ALLIANCE] = 0;
523    m_TeamPointsCount[BG_TEAM_HORDE] = 0;
524    m_HonorScoreTics[BG_TEAM_ALLIANCE] = 0;
525    m_HonorScoreTics[BG_TEAM_HORDE] = 0;
526    m_FlagState = BG_EY_FLAG_STATE_ON_BASE;
527    m_FlagCapturedBgObjectType = 0;
528    m_FlagKeeper = 0;
529    m_DroppedFlagGUID = 0;
530    m_PointAddingTimer = 0;
531    m_TowerCapCheckTimer = 0;
532
533    for(uint8 i = 0; i < EY_POINTS_MAX; ++i)
534    {
535        m_PointOwnedByTeam[i] = EY_POINT_NO_OWNER;
536        m_PointState[i] = EY_POINT_STATE_UNCONTROLLED;
537        m_PointBarStatus[i] = BG_EY_PROGRESS_BAR_STATE_MIDDLE;
538        m_PlayersNearPoint[i].clear();
539        m_PlayersNearPoint[i].reserve(15);                  //tip size
540    }
541    m_PlayersNearPoint[EY_PLAYERS_OUT_OF_POINTS].clear();
542    m_PlayersNearPoint[EY_PLAYERS_OUT_OF_POINTS].reserve(30);
543}
544
545void BattleGroundEY::RespawnFlag(bool send_message)
546{
547    if (m_FlagCapturedBgObjectType > 0)
548        SpawnBGObject(m_FlagCapturedBgObjectType, RESPAWN_ONE_DAY);
549
550    m_FlagCapturedBgObjectType = 0;
551    m_FlagState = BG_EY_FLAG_STATE_ON_BASE;
552    SpawnBGObject(BG_EY_OBJECT_FLAG_NETHERSTORM, RESPAWN_IMMEDIATELY);
553
554    if(send_message)
555    {
556        SendMessageToAll(GetTrinityString(LANG_BG_EY_RESETED_FLAG));
557        PlaySoundToAll(BG_EY_SOUND_FLAG_RESET);             // flags respawned sound...
558    }
559
560    UpdateWorldState(NETHERSTORM_FLAG, 1);
561}
562
563void BattleGroundEY::RespawnFlagAfterDrop()
564{
565    RespawnFlag(true);
566
567    GameObject *obj = HashMapHolder<GameObject>::Find(GetDroppedFlagGUID());
568    if(obj)
569        obj->Delete();
570    else
571        sLog.outError("BattleGroundEY: Unknown dropped flag guid: %u",GetDroppedFlagGUID());
572
573    SetDroppedFlagGUID(0);
574}
575
576void BattleGroundEY::HandleKillPlayer(Player *player, Player *killer)
577{
578    if(GetStatus() != STATUS_IN_PROGRESS)
579        return;
580
581    BattleGround::HandleKillPlayer(player, killer);
582    EventPlayerDroppedFlag(player);
583}
584
585void BattleGroundEY::EventPlayerDroppedFlag(Player *Source)
586{
587    if(GetStatus() != STATUS_IN_PROGRESS)
588    {
589        // if not running, do not cast things at the dropper player, neither send unnecessary messages
590        // just take off the aura
591        if(IsFlagPickedup() && GetFlagPickerGUID() == Source->GetGUID())
592        {
593            SetFlagPicker(0);
594            Source->RemoveAurasDueToSpell(BG_EY_NETHERSTORM_FLAG_SPELL);
595        }
596        return;
597    }
598
599    if(!IsFlagPickedup())
600        return;
601
602    if(GetFlagPickerGUID() != Source->GetGUID())
603        return;
604
605    const char *message = "";
606    uint8 type = 0;
607
608    SetFlagPicker(0);
609    Source->RemoveAurasDueToSpell(BG_EY_NETHERSTORM_FLAG_SPELL);
610    m_FlagState = BG_EY_FLAG_STATE_ON_GROUND;
611    m_FlagsTimer = BG_EY_FLAG_RESPAWN_TIME;
612    Source->CastSpell(Source, SPELL_RECENTLY_DROPPED_FLAG, true);
613    Source->CastSpell(Source, BG_EY_PLAYER_DROPPED_FLAG_SPELL, true);
614    if(Source->GetTeam() == ALLIANCE)
615    {
616        message = GetTrinityString(LANG_BG_EY_DROPPED_FLAG);
617        type = CHAT_MSG_BG_SYSTEM_ALLIANCE;
618    }
619    else
620    {
621        message = GetTrinityString(LANG_BG_EY_DROPPED_FLAG);
622        type = CHAT_MSG_BG_SYSTEM_HORDE;
623    }
624    //this does not work correctly :( (it should remove flag carrier name)
625    UpdateWorldState(NETHERSTORM_FLAG_STATE_HORDE, BG_EY_FLAG_STATE_WAIT_RESPAWN);
626    UpdateWorldState(NETHERSTORM_FLAG_STATE_ALLIANCE, BG_EY_FLAG_STATE_WAIT_RESPAWN);
627
628    WorldPacket data;
629    ChatHandler::FillMessageData(&data, Source->GetSession(), type, LANG_UNIVERSAL, NULL, Source->GetGUID(), message, NULL);
630    SendPacketToAll(&data);
631}
632
633void BattleGroundEY::EventPlayerClickedOnFlag(Player *Source, GameObject* target_obj)
634{
635    if(GetStatus() != STATUS_IN_PROGRESS || this->IsFlagPickedup() || !Source->IsWithinDistInMap(target_obj, 10))
636        return;
637
638    const char *message;
639    uint8 type = 0;
640    message = GetTrinityString(LANG_BG_EY_HAS_TAKEN_FLAG);
641
642    if(Source->GetTeam() == ALLIANCE)
643    {
644        UpdateWorldState(NETHERSTORM_FLAG_STATE_ALLIANCE, BG_EY_FLAG_STATE_ON_PLAYER);
645        type = CHAT_MSG_BG_SYSTEM_ALLIANCE;
646        PlaySoundToAll(BG_EY_SOUND_FLAG_PICKED_UP_ALLIANCE);
647    }
648    else
649    {
650        UpdateWorldState(NETHERSTORM_FLAG_STATE_HORDE, BG_EY_FLAG_STATE_ON_PLAYER);
651        type = CHAT_MSG_BG_SYSTEM_HORDE;
652        PlaySoundToAll(BG_EY_SOUND_FLAG_PICKED_UP_HORDE);
653    }
654
655    if (m_FlagState == BG_EY_FLAG_STATE_ON_BASE)
656        UpdateWorldState(NETHERSTORM_FLAG, 0);
657    m_FlagState = BG_EY_FLAG_STATE_ON_PLAYER;
658
659    SpawnBGObject(BG_EY_OBJECT_FLAG_NETHERSTORM, RESPAWN_ONE_DAY);
660    SetFlagPicker(Source->GetGUID());
661    //get flag aura on player
662    Source->CastSpell(Source, BG_EY_NETHERSTORM_FLAG_SPELL, true);
663    Source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
664
665    WorldPacket data;
666    ChatHandler::FillMessageData(&data, Source->GetSession(), type, LANG_UNIVERSAL, NULL, Source->GetGUID(), message, NULL);
667    SendPacketToAll(&data);
668}
669
670void BattleGroundEY::EventTeamLostPoint(Player *Source, uint32 Point)
671{
672    if(GetStatus() != STATUS_IN_PROGRESS)
673        return;
674
675    //Natural point
676    uint8 message_type = 0;
677    const char *message = "";
678    uint32 Team = m_PointOwnedByTeam[Point];
679
680    if(!Team)
681        return;
682
683    if (Team == ALLIANCE)
684    {
685        m_TeamPointsCount[BG_TEAM_ALLIANCE]--;
686        message_type = CHAT_MSG_BG_SYSTEM_ALLIANCE;
687        message = GetTrinityString(m_LoosingPointTypes[Point].MessageIdAlliance);
688        SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeAlliance, RESPAWN_ONE_DAY);
689        SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeAlliance + 1, RESPAWN_ONE_DAY);
690        SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeAlliance + 2, RESPAWN_ONE_DAY);
691    }
692    else
693    {
694        m_TeamPointsCount[BG_TEAM_HORDE]--;
695        message_type = CHAT_MSG_BG_SYSTEM_HORDE;
696        message = GetTrinityString(m_LoosingPointTypes[Point].MessageIdHorde);
697        SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeHorde, RESPAWN_ONE_DAY);
698        SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeHorde + 1, RESPAWN_ONE_DAY);
699        SpawnBGObject(m_LoosingPointTypes[Point].DespawnObjectTypeHorde + 2, RESPAWN_ONE_DAY);
700    }
701
702    SpawnBGObject(m_LoosingPointTypes[Point].SpawnNeutralObjectType, RESPAWN_IMMEDIATELY);
703    SpawnBGObject(m_LoosingPointTypes[Point].SpawnNeutralObjectType + 1, RESPAWN_IMMEDIATELY);
704    SpawnBGObject(m_LoosingPointTypes[Point].SpawnNeutralObjectType + 2, RESPAWN_IMMEDIATELY);
705
706    //buff isn't despawned
707
708    m_PointOwnedByTeam[Point] = EY_POINT_NO_OWNER;
709    m_PointState[Point] = EY_POINT_NO_OWNER;
710
711    WorldPacket data;
712    ChatHandler::FillMessageData(&data, Source->GetSession(), message_type, LANG_UNIVERSAL, NULL, Source->GetGUID(), message, NULL);
713    SendPacketToAll(&data);
714
715    UpdatePointsIcons(Team, Point);
716    UpdatePointsCount(Team);
717}
718
719void BattleGroundEY::EventTeamCapturedPoint(Player *Source, uint32 Point)
720{
721    if(GetStatus() != STATUS_IN_PROGRESS)
722        return;
723
724    uint8 type = 0;
725    const char *message = "";
726    uint32 Team = Source->GetTeam();
727
728    SpawnBGObject(m_CapturingPointTypes[Point].DespawnNeutralObjectType, RESPAWN_ONE_DAY);
729    SpawnBGObject(m_CapturingPointTypes[Point].DespawnNeutralObjectType + 1, RESPAWN_ONE_DAY);
730    SpawnBGObject(m_CapturingPointTypes[Point].DespawnNeutralObjectType + 2, RESPAWN_ONE_DAY);
731
732    if (Team == ALLIANCE)
733    {
734        m_TeamPointsCount[BG_TEAM_ALLIANCE]++;
735        type = CHAT_MSG_BG_SYSTEM_ALLIANCE;
736        message = GetTrinityString(m_CapturingPointTypes[Point].MessageIdAlliance);
737        SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeAlliance, RESPAWN_IMMEDIATELY);
738        SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeAlliance + 1, RESPAWN_IMMEDIATELY);
739        SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeAlliance + 2, RESPAWN_IMMEDIATELY);
740    }
741    else
742    {
743        m_TeamPointsCount[BG_TEAM_HORDE]++;
744        type = CHAT_MSG_BG_SYSTEM_HORDE;
745        message = GetTrinityString(m_CapturingPointTypes[Point].MessageIdHorde);
746        SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeHorde, RESPAWN_IMMEDIATELY);
747        SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeHorde + 1, RESPAWN_IMMEDIATELY);
748        SpawnBGObject(m_CapturingPointTypes[Point].SpawnObjectTypeHorde + 2, RESPAWN_IMMEDIATELY);
749    }
750
751    //buff isn't respawned
752
753    m_PointOwnedByTeam[Point] = Team;
754    m_PointState[Point] = EY_POINT_UNDER_CONTROL;
755
756    WorldPacket data;
757    ChatHandler::FillMessageData(&data, Source->GetSession(), type, LANG_UNIVERSAL, NULL, Source->GetGUID(), message, NULL);
758    SendPacketToAll(&data);
759
760    if(m_BgCreatures[Point])
761        DelCreature(Point);
762
763    WorldSafeLocsEntry const *sg = NULL;
764    sg = sWorldSafeLocsStore.LookupEntry(m_CapturingPointTypes[Point].GraveYardId);
765    if(!sg || !AddSpiritGuide(Point, sg->x, sg->y, sg->z, 3.124139f, Team))
766        sLog.outError("BatteGroundEY: Failed to spawn spirit guide! point: %u, team: u, graveyard_id: %u", Point, Team, m_CapturingPointTypes[Point].GraveYardId);
767
768    UpdatePointsIcons(Team, Point);
769    UpdatePointsCount(Team);
770}
771
772void BattleGroundEY::EventPlayerCapturedFlag(Player *Source, uint32 BgObjectType)
773{
774    if(GetStatus() != STATUS_IN_PROGRESS || this->GetFlagPickerGUID() != Source->GetGUID())
775        return;
776
777    uint8 type = 0;
778    uint8 team_id = 0;
779    const char *message = "";
780
781    SetFlagPicker(0);
782    m_FlagState = BG_EY_FLAG_STATE_WAIT_RESPAWN;
783    Source->RemoveAurasDueToSpell(BG_EY_NETHERSTORM_FLAG_SPELL);
784
785    Source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
786    if(Source->GetTeam() == ALLIANCE)
787    {
788        PlaySoundToAll(BG_EY_SOUND_FLAG_CAPTURED_ALLIANCE);
789        team_id = BG_TEAM_ALLIANCE;
790        message = GetTrinityString(LANG_BG_EY_CAPTURED_FLAG_A);
791        type = CHAT_MSG_BG_SYSTEM_ALLIANCE;
792    }
793    else
794    {
795        PlaySoundToAll(BG_EY_SOUND_FLAG_CAPTURED_HORDE);
796        team_id = BG_TEAM_HORDE;
797        message = GetTrinityString(LANG_BG_EY_CAPTURED_FLAG_H);
798        type = CHAT_MSG_BG_SYSTEM_HORDE;
799    }
800
801    SpawnBGObject(BgObjectType, RESPAWN_IMMEDIATELY);
802
803    m_FlagsTimer = BG_EY_FLAG_RESPAWN_TIME;
804    m_FlagCapturedBgObjectType = BgObjectType;
805
806    WorldPacket data;
807    ChatHandler::FillMessageData(&data, Source->GetSession(), type, LANG_UNIVERSAL, NULL, Source->GetGUID(), message, NULL);
808    SendPacketToAll(&data);
809
810    if(m_TeamPointsCount[team_id] > 0)
811        AddPoints(Source->GetTeam(), BG_EY_FlagPoints[m_TeamPointsCount[team_id] - 1]);
812
813    UpdatePlayerScore(Source, SCORE_FLAG_CAPTURES, 1);
814}
815
816void BattleGroundEY::UpdatePlayerScore(Player *Source, uint32 type, uint32 value)
817{
818    std::map<uint64, BattleGroundScore*>::iterator itr = m_PlayerScores.find(Source->GetGUID());
819
820    if(itr == m_PlayerScores.end())                         // player not found
821        return;
822
823    switch(type)
824    {
825        case SCORE_FLAG_CAPTURES:                           // flags captured
826            ((BattleGroundEYScore*)itr->second)->FlagCaptures += value;
827            break;
828        default:
829            BattleGround::UpdatePlayerScore(Source, type, value);
830            break;
831    }
832}
833
834void BattleGroundEY::FillInitialWorldStates(WorldPacket& data)
835{
836    data << uint32(EY_HORDE_BASE) << uint32(m_TeamPointsCount[BG_TEAM_HORDE]);
837    data << uint32(EY_ALLIANCE_BASE) << uint32(m_TeamPointsCount[BG_TEAM_ALLIANCE]);
838    data << uint32(0xab6) << uint32(0x0);
839    data << uint32(0xab5) << uint32(0x0);
840    data << uint32(0xab4) << uint32(0x0);
841    data << uint32(0xab3) << uint32(0x0);
842    data << uint32(0xab2) << uint32(0x0);
843    data << uint32(0xab1) << uint32(0x0);
844    data << uint32(0xab0) << uint32(0x0);
845    data << uint32(0xaaf) << uint32(0x0);
846
847    data << uint32(DRAENEI_RUINS_HORDE_CONTROL)     << uint32(m_PointOwnedByTeam[DRAENEI_RUINS] == HORDE && m_PointState[DRAENEI_RUINS] == EY_POINT_UNDER_CONTROL);
848
849    data << uint32(DRAENEI_RUINS_ALLIANCE_CONTROL)  << uint32(m_PointOwnedByTeam[DRAENEI_RUINS] == ALLIANCE && m_PointState[DRAENEI_RUINS] == EY_POINT_UNDER_CONTROL);
850
851    data << uint32(DRAENEI_RUINS_UNCONTROL)         << uint32(m_PointState[DRAENEI_RUINS] != EY_POINT_UNDER_CONTROL);
852
853    data << uint32(MAGE_TOWER_ALLIANCE_CONTROL)     << uint32(m_PointOwnedByTeam[MAGE_TOWER] == ALLIANCE && m_PointState[MAGE_TOWER] == EY_POINT_UNDER_CONTROL);
854
855    data << uint32(MAGE_TOWER_HORDE_CONTROL)        << uint32(m_PointOwnedByTeam[MAGE_TOWER] == HORDE && m_PointState[MAGE_TOWER] == EY_POINT_UNDER_CONTROL);
856
857    data << uint32(MAGE_TOWER_UNCONTROL)            << uint32(m_PointState[MAGE_TOWER] != EY_POINT_UNDER_CONTROL);
858
859    data << uint32(FEL_REAVER_HORDE_CONTROL)        << uint32(m_PointOwnedByTeam[FEL_REALVER] == HORDE && m_PointState[FEL_REALVER] == EY_POINT_UNDER_CONTROL);
860
861    data << uint32(FEL_REAVER_ALLIANCE_CONTROL)     << uint32(m_PointOwnedByTeam[FEL_REALVER] == ALLIANCE && m_PointState[FEL_REALVER] == EY_POINT_UNDER_CONTROL);
862
863    data << uint32(FEL_REAVER_UNCONTROL)            << uint32(m_PointState[FEL_REALVER] != EY_POINT_UNDER_CONTROL);
864
865    data << uint32(BLOOD_ELF_HORDE_CONTROL)         << uint32(m_PointOwnedByTeam[BLOOD_ELF] == HORDE && m_PointState[BLOOD_ELF] == EY_POINT_UNDER_CONTROL);
866
867    data << uint32(BLOOD_ELF_ALLIANCE_CONTROL)      << uint32(m_PointOwnedByTeam[BLOOD_ELF] == ALLIANCE && m_PointState[BLOOD_ELF] == EY_POINT_UNDER_CONTROL);
868
869    data << uint32(BLOOD_ELF_UNCONTROL)             << uint32(m_PointState[BLOOD_ELF] != EY_POINT_UNDER_CONTROL);
870
871    data << uint32(NETHERSTORM_FLAG)                << uint32(m_FlagState == BG_EY_FLAG_STATE_ON_BASE);
872
873    data << uint32(0xad2) << uint32(0x1);
874    data << uint32(0xad1) << uint32(0x1);
875    data << uint32(0xabe) << uint32(GetTeamScore(HORDE));
876    data << uint32(0xabd) << uint32(GetTeamScore(ALLIANCE));
877    data << uint32(0xa05) << uint32(0x8e);
878    data << uint32(0xaa0) << uint32(0x0);
879    data << uint32(0xa9f) << uint32(0x0);
880    data << uint32(0xa9e) << uint32(0x0);
881    data << uint32(0xc0d) << uint32(0x17b);
882}
883
884WorldSafeLocsEntry const *BattleGroundEY::GetClosestGraveYard(float x, float y, float z, uint32 team)
885{
886    uint32 g_id = 0;
887
888    if(team == ALLIANCE)
889        g_id = EY_GRAVEYARD_MAIN_ALLIANCE;
890    else if(team == HORDE)
891        g_id = EY_GRAVEYARD_MAIN_HORDE;
892    else
893        return NULL;
894
895    float distance, nearestDistance;
896
897    WorldSafeLocsEntry const* entry = NULL;
898    WorldSafeLocsEntry const* nearestEntry = NULL;
899    entry = sWorldSafeLocsStore.LookupEntry(g_id);
900    nearestEntry = entry;
901
902    if(!entry)
903    {
904        sLog.outError("BattleGroundEY: Not found the main team graveyard. Graveyard system isn't working!");
905        return NULL;
906    }
907
908    distance = (entry->x - x)*(entry->x - x) + (entry->y - y)*(entry->y - y) + (entry->z - z)*(entry->z - z);
909    nearestDistance = distance;
910
911    for(uint8 i = 0; i < EY_POINTS_MAX; ++i)
912    {
913        if(m_PointOwnedByTeam[i]==team && m_PointState[i]==EY_POINT_UNDER_CONTROL)
914        {
915            entry = sWorldSafeLocsStore.LookupEntry(m_CapturingPointTypes[i].GraveYardId);
916            if(!entry)
917                sLog.outError("BattleGroundEY: Not found graveyard: %u",m_CapturingPointTypes[i].GraveYardId);
918            else
919            {
920                distance = (entry->x - x)*(entry->x - x) + (entry->y - y)*(entry->y - y) + (entry->z - z)*(entry->z - z);
921                if(distance < nearestDistance)
922                {
923                    nearestDistance = distance;
924                    nearestEntry = entry;
925                }
926            }
927        }
928    }
929
930    return nearestEntry;
931}
Note: See TracBrowser for help on using the browser.