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

Revision 102, 41.3 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

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