root/trunk/src/game/BattleGroundWS.cpp @ 28

Revision 9, 28.5 kB (checked in by yumileroy, 17 years ago)

[svn] -enabled instantiated battlegrounds
-enabled arena matches
-rewritten battleground queuing to support joining as group
-removed queue announcements

Original author: w12x
Date: 2008-10-05 08:48:32-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include "Object.h"
20#include "Player.h"
21#include "BattleGround.h"
22#include "BattleGroundWS.h"
23#include "Creature.h"
24#include "GameObject.h"
25#include "Chat.h"
26#include "MapManager.h"
27#include "Language.h"
28
29BattleGroundWS::BattleGroundWS()
30{
31    m_BgObjects.resize(BG_WS_OBJECT_MAX);
32    m_BgCreatures.resize(BG_CREATURES_MAX_WS);
33}
34
35BattleGroundWS::~BattleGroundWS()
36{
37}
38
39void BattleGroundWS::Update(time_t diff)
40{
41    BattleGround::Update(diff);
42
43    // after bg start we get there (once)
44    if (GetStatus() == STATUS_WAIT_JOIN && GetPlayersSize())
45    {
46        ModifyStartDelayTime(diff);
47
48        if(!(m_Events & 0x01))
49        {
50            m_Events |= 0x01;
51
52            // setup here, only when at least one player has ported to the map
53            if(!SetupBattleGround())
54            {
55                EndNow();
56                return;
57            }
58
59            for(uint32 i = BG_WS_OBJECT_DOOR_A_1; i <= BG_WS_OBJECT_DOOR_H_4; i++)
60            {
61                SpawnBGObject(i, RESPAWN_IMMEDIATELY);
62                DoorClose(i);
63            }
64            for(uint32 i = BG_WS_OBJECT_A_FLAG; i <= BG_WS_OBJECT_BERSERKBUFF_2; i++)
65                SpawnBGObject(i, RESPAWN_ONE_DAY);
66
67            SetStartDelayTime(START_DELAY0);
68        }
69        // After 1 minute, warning is signalled
70        else if(GetStartDelayTime() <= START_DELAY1 && !(m_Events & 0x04))
71        {
72            m_Events |= 0x04;
73            SendMessageToAll(GetMangosString(LANG_BG_WS_ONE_MINUTE));
74        }
75        // After 1,5 minute, warning is signalled
76        else if(GetStartDelayTime() <= START_DELAY2 && !(m_Events & 0x08))
77        {
78            m_Events |= 0x08;
79            SendMessageToAll(GetMangosString(LANG_BG_WS_HALF_MINUTE));
80        }
81        // After 2 minutes, gates OPEN ! x)
82        else if(GetStartDelayTime() < 0 && !(m_Events & 0x10))
83        {
84            m_Events |= 0x10;
85            for(uint32 i = BG_WS_OBJECT_DOOR_A_1; i <= BG_WS_OBJECT_DOOR_A_4; i++)
86                DoorOpen(i);
87            for(uint32 i = BG_WS_OBJECT_DOOR_H_1; i <= BG_WS_OBJECT_DOOR_H_2; i++)
88                DoorOpen(i);
89
90            SpawnBGObject(BG_WS_OBJECT_DOOR_A_5, RESPAWN_ONE_DAY);
91            SpawnBGObject(BG_WS_OBJECT_DOOR_A_6, RESPAWN_ONE_DAY);
92            SpawnBGObject(BG_WS_OBJECT_DOOR_H_3, RESPAWN_ONE_DAY);
93            SpawnBGObject(BG_WS_OBJECT_DOOR_H_4, RESPAWN_ONE_DAY);
94
95            for(uint32 i = BG_WS_OBJECT_A_FLAG; i <= BG_WS_OBJECT_BERSERKBUFF_2; i++)
96                SpawnBGObject(i, RESPAWN_IMMEDIATELY);
97
98            SendMessageToAll(GetMangosString(LANG_BG_WS_BEGIN));
99
100            PlaySoundToAll(SOUND_BG_START);
101            SetStatus(STATUS_IN_PROGRESS);
102
103            for(BattleGroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
104                if(Player* plr = objmgr.GetPlayer(itr->first))
105                    plr->RemoveAurasDueToSpell(SPELL_PREPARATION);
106        }
107    }
108    else if(GetStatus() == STATUS_IN_PROGRESS)
109    {
110        if(m_FlagState[BG_TEAM_ALLIANCE] == BG_WS_FLAG_STATE_WAIT_RESPAWN)
111        {
112            m_FlagsTimer[BG_TEAM_ALLIANCE] -= diff;
113
114            if(m_FlagsTimer[BG_TEAM_ALLIANCE] < 0)
115            {
116                m_FlagsTimer[BG_TEAM_ALLIANCE] = 0;
117                RespawnFlag(ALLIANCE, true);
118            }
119        }
120        if(m_FlagState[BG_TEAM_ALLIANCE] == BG_WS_FLAG_STATE_ON_GROUND)
121        {
122            m_FlagsDropTimer[BG_TEAM_ALLIANCE] -= diff;
123
124            if(m_FlagsDropTimer[BG_TEAM_ALLIANCE] < 0)
125            {
126                m_FlagsDropTimer[BG_TEAM_ALLIANCE] = 0;
127                RespawnFlagAfterDrop(ALLIANCE);
128            }
129        }
130        if(m_FlagState[BG_TEAM_HORDE] == BG_WS_FLAG_STATE_WAIT_RESPAWN)
131        {
132            m_FlagsTimer[BG_TEAM_HORDE] -= diff;
133
134            if(m_FlagsTimer[BG_TEAM_HORDE] < 0)
135            {
136                m_FlagsTimer[BG_TEAM_HORDE] = 0;
137                RespawnFlag(HORDE, true);
138            }
139        }
140        if(m_FlagState[BG_TEAM_HORDE] == BG_WS_FLAG_STATE_ON_GROUND)
141        {
142            m_FlagsDropTimer[BG_TEAM_HORDE] -= diff;
143
144            if(m_FlagsDropTimer[BG_TEAM_HORDE] < 0)
145            {
146                m_FlagsDropTimer[BG_TEAM_HORDE] = 0;
147                RespawnFlagAfterDrop(HORDE);
148            }
149        }
150    }
151}
152
153void BattleGroundWS::AddPlayer(Player *plr)
154{
155    BattleGround::AddPlayer(plr);
156    //create score and add it to map, default values are set in constructor
157    BattleGroundWGScore* sc = new BattleGroundWGScore;
158
159    m_PlayerScores[plr->GetGUID()] = sc;
160}
161
162void BattleGroundWS::RespawnFlag(uint32 Team, bool captured)
163{
164    if(Team == ALLIANCE)
165    {
166        sLog.outDebug("Respawn Alliance flag");
167        m_FlagState[BG_TEAM_ALLIANCE] = BG_WS_FLAG_STATE_ON_BASE;
168    }
169    else
170    {
171        sLog.outDebug("Respawn Horde flag");
172        m_FlagState[BG_TEAM_HORDE] = BG_WS_FLAG_STATE_ON_BASE;
173    }
174
175    if(captured)
176    {
177        //when map_update will be allowed for battlegrounds this code will be useless
178        SpawnBGObject(BG_WS_OBJECT_H_FLAG, RESPAWN_IMMEDIATELY);
179        SpawnBGObject(BG_WS_OBJECT_A_FLAG, RESPAWN_IMMEDIATELY);
180        SendMessageToAll(GetMangosString(LANG_BG_WS_F_PLACED));
181        PlaySoundToAll(BG_WS_SOUND_FLAGS_RESPAWNED);        // flag respawned sound...
182    }
183}
184
185void BattleGroundWS::RespawnFlagAfterDrop(uint32 team)
186{
187    if(GetStatus() != STATUS_IN_PROGRESS)
188        return;
189
190    RespawnFlag(team,false);
191    if(team == ALLIANCE)
192    {
193        SpawnBGObject(BG_WS_OBJECT_A_FLAG, RESPAWN_IMMEDIATELY);
194        SendMessageToAll(GetMangosString(LANG_BG_WS_ALLIANCE_FLAG_RESPAWNED));
195    }
196    else
197    {
198        SpawnBGObject(BG_WS_OBJECT_H_FLAG, RESPAWN_IMMEDIATELY);
199        SendMessageToAll(GetMangosString(LANG_BG_WS_HORDE_FLAG_RESPAWNED));
200    }
201
202    PlaySoundToAll(BG_WS_SOUND_FLAGS_RESPAWNED);
203
204    GameObject *obj = HashMapHolder<GameObject>::Find(GetDroppedFlagGUID(team));
205    if(obj)
206        obj->Delete();
207    else
208        sLog.outError("unknown droped flag bg, guid: %u",GetDroppedFlagGUID(team));
209
210    SetDroppedFlagGUID(0,team);
211}
212
213void BattleGroundWS::EventPlayerCapturedFlag(Player *Source)
214{
215    if(GetStatus() != STATUS_IN_PROGRESS)
216        return;
217
218    uint8 type = 0;
219    uint32 winner = 0;
220    const char *message = "";
221
222    //TODO FIX reputation and honor gains for low level players!
223
224    Source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
225    if(Source->GetTeam() == ALLIANCE)
226    {
227        if (!this->IsHordeFlagPickedup())
228            return;
229        SetHordeFlagPicker(0);                              // must be before aura remove to prevent 2 events (drop+capture) at the same time
230                                                            // horde flag in base (but not respawned yet)
231        m_FlagState[BG_TEAM_HORDE] = BG_WS_FLAG_STATE_WAIT_RESPAWN;
232                                                            // Drop Horde Flag from Player
233        Source->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG);
234        message = GetMangosString(LANG_BG_WS_CAPTURED_HF);
235        type = CHAT_MSG_BG_SYSTEM_ALLIANCE;
236        if(GetTeamScore(ALLIANCE) < BG_WS_MAX_TEAM_SCORE)
237            AddPoint(ALLIANCE, 1);
238        PlaySoundToAll(BG_WS_SOUND_FLAG_CAPTURED_ALLIANCE);
239        RewardReputationToTeam(890, 35, ALLIANCE);          // +35 reputation
240        RewardHonorToTeam(40, ALLIANCE);                    // +40 bonushonor
241    }
242    else
243    {
244        if (!this->IsAllianceFlagPickedup())
245            return;
246        SetAllianceFlagPicker(0);                           // must be before aura remove to prevent 2 events (drop+capture) at the same time
247                                                            // alliance flag in base (but not respawned yet)
248        m_FlagState[BG_TEAM_ALLIANCE] = BG_WS_FLAG_STATE_WAIT_RESPAWN;
249                                                            // Drop Alliance Flag from Player
250        Source->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG);
251        message = GetMangosString(LANG_BG_WS_CAPTURED_AF);
252        type = CHAT_MSG_BG_SYSTEM_HORDE;
253        if(GetTeamScore(HORDE) < BG_WS_MAX_TEAM_SCORE)
254            AddPoint(HORDE, 1);
255        PlaySoundToAll(BG_WS_SOUND_FLAG_CAPTURED_HORDE);
256        RewardReputationToTeam(889, 35, HORDE);             // +35 reputation
257        RewardHonorToTeam(40, HORDE);                       // +40 bonushonor
258    }
259
260    SpawnBGObject(BG_WS_OBJECT_H_FLAG, BG_WS_FLAG_RESPAWN_TIME);
261    SpawnBGObject(BG_WS_OBJECT_A_FLAG, BG_WS_FLAG_RESPAWN_TIME);
262
263    WorldPacket data;
264    ChatHandler::FillMessageData(&data, Source->GetSession(), type, LANG_UNIVERSAL, NULL, Source->GetGUID(), message, NULL);
265    SendPacketToAll(&data);
266
267    UpdateFlagState(Source->GetTeam(), 1);                  // flag state none
268    UpdateTeamScore(Source->GetTeam());
269    // only flag capture should be updated
270    UpdatePlayerScore(Source, SCORE_FLAG_CAPTURES, 1);      // +1 flag captures...
271
272    if(GetTeamScore(ALLIANCE) == BG_WS_MAX_TEAM_SCORE)
273        winner = ALLIANCE;
274
275    if(GetTeamScore(HORDE) == BG_WS_MAX_TEAM_SCORE)
276        winner = HORDE;
277
278    if(winner)
279    {
280        UpdateWorldState(BG_WS_FLAG_UNK_ALLIANCE, 0);
281        UpdateWorldState(BG_WS_FLAG_UNK_HORDE, 0);
282        UpdateWorldState(BG_WS_FLAG_STATE_ALLIANCE, 1);
283        UpdateWorldState(BG_WS_FLAG_STATE_HORDE, 1);
284
285        EndBattleGround(winner);
286    }
287    else
288    {
289        m_FlagsTimer[GetTeamIndexByTeamId(Source->GetTeam()) ? 0 : 1] = BG_WS_FLAG_RESPAWN_TIME;
290    }
291}
292
293void BattleGroundWS::EventPlayerDroppedFlag(Player *Source)
294{
295    if(GetStatus() != STATUS_IN_PROGRESS)
296    {
297        // if not running, do not cast things at the dropper player (prevent spawning the "dropped" flag), neither send unnecessary messages
298        // just take off the aura
299        if(Source->GetTeam() == ALLIANCE)
300        {
301            if(!this->IsHordeFlagPickedup())
302                return;
303            if(GetHordeFlagPickerGUID() == Source->GetGUID())
304            {
305                SetHordeFlagPicker(0);
306                Source->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG);
307            }
308        }
309        else
310        {
311            if(!this->IsAllianceFlagPickedup())
312                return;
313            if(GetAllianceFlagPickerGUID() == Source->GetGUID())
314            {
315                SetAllianceFlagPicker(0);
316                Source->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG);
317            }
318        }
319        return;
320    }
321
322    const char *message = "";
323    uint8 type = 0;
324    bool set = false;
325
326    if(Source->GetTeam() == ALLIANCE)
327    {
328        if(!this->IsHordeFlagPickedup())
329            return;
330        if(GetHordeFlagPickerGUID() == Source->GetGUID())
331        {
332            SetHordeFlagPicker(0);
333            Source->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG);
334            m_FlagState[BG_TEAM_HORDE] = BG_WS_FLAG_STATE_ON_GROUND;
335            message = GetMangosString(LANG_BG_WS_DROPPED_HF);
336            type = CHAT_MSG_BG_SYSTEM_HORDE;
337            Source->CastSpell(Source, BG_WS_SPELL_WARSONG_FLAG_DROPPED, true);
338            set = true;
339        }
340    }
341    else
342    {
343        if(!this->IsAllianceFlagPickedup())
344            return;
345        if(GetAllianceFlagPickerGUID() == Source->GetGUID())
346        {
347            SetAllianceFlagPicker(0);
348            Source->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG);
349            m_FlagState[BG_TEAM_ALLIANCE] = BG_WS_FLAG_STATE_ON_GROUND;
350            message = GetMangosString(LANG_BG_WS_DROPPED_AF);
351            type = CHAT_MSG_BG_SYSTEM_ALLIANCE;
352            Source->CastSpell(Source, BG_WS_SPELL_SILVERWING_FLAG_DROPPED, true);
353            set = true;
354        }
355    }
356
357    if (set)
358    {
359        Source->CastSpell(Source, SPELL_RECENTLY_DROPPED_FLAG, true);
360        UpdateFlagState(Source->GetTeam(), 1);
361
362        WorldPacket data;
363        ChatHandler::FillMessageData(&data, Source->GetSession(), type, LANG_UNIVERSAL, NULL, Source->GetGUID(), message, NULL);
364        SendPacketToAll(&data);
365
366        if(Source->GetTeam() == ALLIANCE)
367            UpdateWorldState(BG_WS_FLAG_UNK_HORDE, uint32(-1));
368        else
369            UpdateWorldState(BG_WS_FLAG_UNK_ALLIANCE, uint32(-1));
370
371        m_FlagsDropTimer[GetTeamIndexByTeamId(Source->GetTeam()) ? 0 : 1] = BG_WS_FLAG_DROP_TIME;
372    }
373}
374
375void BattleGroundWS::EventPlayerClickedOnFlag(Player *Source, GameObject* target_obj)
376{
377    if(GetStatus() != STATUS_IN_PROGRESS)
378        return;
379
380    const char *message;
381    uint8 type = 0;
382
383    //alliance flag picked up from base
384    if(Source->GetTeam() == HORDE && this->GetFlagState(ALLIANCE) == BG_WS_FLAG_STATE_ON_BASE
385        && this->m_BgObjects[BG_WS_OBJECT_A_FLAG] == target_obj->GetGUID())
386    {
387        message = GetMangosString(LANG_BG_WS_PICKEDUP_AF);
388        type = CHAT_MSG_BG_SYSTEM_HORDE;
389        PlaySoundToAll(BG_WS_SOUND_ALLIANCE_FLAG_PICKED_UP);
390        SpawnBGObject(BG_WS_OBJECT_A_FLAG, RESPAWN_ONE_DAY);
391        SetAllianceFlagPicker(Source->GetGUID());
392        m_FlagState[BG_TEAM_ALLIANCE] = BG_WS_FLAG_STATE_ON_PLAYER;
393        //update world state to show correct flag carrier
394        UpdateFlagState(HORDE, BG_WS_FLAG_STATE_ON_PLAYER);
395        UpdateWorldState(BG_WS_FLAG_UNK_ALLIANCE, 1);
396        Source->CastSpell(Source, BG_WS_SPELL_SILVERWING_FLAG, true);
397    }
398
399    //horde flag picked up from base
400    if (Source->GetTeam() == ALLIANCE && this->GetFlagState(HORDE) == BG_WS_FLAG_STATE_ON_BASE
401        && this->m_BgObjects[BG_WS_OBJECT_H_FLAG] == target_obj->GetGUID())
402    {
403        message = GetMangosString(LANG_BG_WS_PICKEDUP_HF);
404        type = CHAT_MSG_BG_SYSTEM_ALLIANCE;
405        PlaySoundToAll(BG_WS_SOUND_HORDE_FLAG_PICKED_UP);
406        SpawnBGObject(BG_WS_OBJECT_H_FLAG, RESPAWN_ONE_DAY);
407        SetHordeFlagPicker(Source->GetGUID());
408        m_FlagState[BG_TEAM_HORDE] = BG_WS_FLAG_STATE_ON_PLAYER;
409        //update world state to show correct flag carrier
410        UpdateFlagState(ALLIANCE, BG_WS_FLAG_STATE_ON_PLAYER);
411        UpdateWorldState(BG_WS_FLAG_UNK_HORDE, 1);
412        Source->CastSpell(Source, BG_WS_SPELL_WARSONG_FLAG, true);
413    }
414
415    //Alliance flag on ground(not in base) (returned or picked up again from ground!)
416    if(this->GetFlagState(ALLIANCE) == BG_WS_FLAG_STATE_ON_GROUND && Source->IsWithinDistInMap(target_obj, 10))
417    {
418        if(Source->GetTeam() == ALLIANCE)
419        {
420            message = GetMangosString(LANG_BG_WS_RETURNED_AF);
421            type = CHAT_MSG_BG_SYSTEM_ALLIANCE;
422            UpdateFlagState(HORDE, BG_WS_FLAG_STATE_WAIT_RESPAWN);
423            RespawnFlag(ALLIANCE, false);
424            SpawnBGObject(BG_WS_OBJECT_A_FLAG, RESPAWN_IMMEDIATELY);
425            PlaySoundToAll(BG_WS_SOUND_FLAG_RETURNED);
426            UpdatePlayerScore(Source, SCORE_FLAG_RETURNS, 1);
427        }
428        else
429        {
430            message = GetMangosString(LANG_BG_WS_PICKEDUP_AF);
431            type = CHAT_MSG_BG_SYSTEM_HORDE;
432            PlaySoundToAll(BG_WS_SOUND_ALLIANCE_FLAG_PICKED_UP);
433            SpawnBGObject(BG_WS_OBJECT_A_FLAG, RESPAWN_ONE_DAY);
434            SetAllianceFlagPicker(Source->GetGUID());
435            Source->CastSpell(Source, BG_WS_SPELL_SILVERWING_FLAG, true);
436            m_FlagState[BG_TEAM_ALLIANCE] = BG_WS_FLAG_STATE_ON_PLAYER;
437            UpdateFlagState(HORDE, BG_WS_FLAG_STATE_ON_PLAYER);
438            UpdateWorldState(BG_WS_FLAG_UNK_ALLIANCE, 1);
439        }
440        //called in HandleGameObjectUseOpcode:
441        //target_obj->Delete();
442    }
443
444    //Horde flag on ground(not in base) (returned or picked up again)
445    if(this->GetFlagState(HORDE) == BG_WS_FLAG_STATE_ON_GROUND && Source->IsWithinDistInMap(target_obj, 10))
446    {
447        if(Source->GetTeam() == HORDE)
448        {
449            message = GetMangosString(LANG_BG_WS_RETURNED_HF);
450            type = CHAT_MSG_BG_SYSTEM_HORDE;
451            UpdateFlagState(ALLIANCE, BG_WS_FLAG_STATE_WAIT_RESPAWN);
452            RespawnFlag(HORDE, false);
453            SpawnBGObject(BG_WS_OBJECT_H_FLAG, RESPAWN_IMMEDIATELY);
454            PlaySoundToAll(BG_WS_SOUND_FLAG_RETURNED);
455            UpdatePlayerScore(Source, SCORE_FLAG_RETURNS, 1);
456        }
457        else
458        {
459            message = GetMangosString(LANG_BG_WS_PICKEDUP_HF);
460            type = CHAT_MSG_BG_SYSTEM_ALLIANCE;
461            PlaySoundToAll(BG_WS_SOUND_HORDE_FLAG_PICKED_UP);
462            SpawnBGObject(BG_WS_OBJECT_H_FLAG, RESPAWN_ONE_DAY);
463            SetHordeFlagPicker(Source->GetGUID());
464            Source->CastSpell(Source, BG_WS_SPELL_WARSONG_FLAG, true);
465            m_FlagState[BG_TEAM_HORDE] = BG_WS_FLAG_STATE_ON_PLAYER;
466            UpdateFlagState(ALLIANCE, BG_WS_FLAG_STATE_ON_PLAYER);
467            UpdateWorldState(BG_WS_FLAG_UNK_HORDE, 1);
468        }
469        //called in HandleGameObjectUseOpcode:
470        //target_obj->Delete();
471    }
472
473    if (!type)
474        return;
475
476    WorldPacket data;
477    ChatHandler::FillMessageData(&data, Source->GetSession(), type, LANG_UNIVERSAL, NULL, Source->GetGUID(), message, NULL);
478    SendPacketToAll(&data);
479    Source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
480}
481
482void BattleGroundWS::RemovePlayer(Player *plr, uint64 guid)
483{
484    // sometimes flag aura not removed :(
485    if(IsAllianceFlagPickedup() && m_FlagKeepers[BG_TEAM_ALLIANCE] == guid)
486    {
487        if(!plr)
488        {
489            sLog.outError("BattleGroundWS: Removing offline player who has the FLAG!!");
490            this->SetAllianceFlagPicker(0);
491            this->RespawnFlag(ALLIANCE, false);
492        }
493        else
494            this->EventPlayerDroppedFlag(plr);
495    }
496    if(IsHordeFlagPickedup() && m_FlagKeepers[BG_TEAM_HORDE] == guid)
497    {
498        if(!plr)
499        {
500            sLog.outError("BattleGroundWS: Removing offline player who has the FLAG!!");
501            this->SetHordeFlagPicker(0);
502            this->RespawnFlag(HORDE, false);
503        }
504        else
505            this->EventPlayerDroppedFlag(plr);
506    }
507}
508
509void BattleGroundWS::UpdateFlagState(uint32 team, uint32 value)
510{
511    if(team == ALLIANCE)
512        UpdateWorldState(BG_WS_FLAG_STATE_ALLIANCE, value);
513    else
514        UpdateWorldState(BG_WS_FLAG_STATE_HORDE, value);
515}
516
517void BattleGroundWS::UpdateTeamScore(uint32 team)
518{
519    if(team == ALLIANCE)
520        UpdateWorldState(BG_WS_FLAG_CAPTURES_ALLIANCE, GetTeamScore(team));
521    else
522        UpdateWorldState(BG_WS_FLAG_CAPTURES_HORDE, GetTeamScore(team));
523}
524
525void BattleGroundWS::HandleAreaTrigger(Player *Source, uint32 Trigger)
526{
527    // this is wrong way to implement these things. On official it done by gameobject spell cast.
528    if(GetStatus() != STATUS_IN_PROGRESS)
529        return;
530
531    //uint32 SpellId = 0;
532    //uint64 buff_guid = 0;
533    switch(Trigger)
534    {
535        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().
536            //buff_guid = m_BgObjects[BG_WS_OBJECT_SPEEDBUFF_1];
537            break;
538        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().
539            //buff_guid = m_BgObjects[BG_WS_OBJECT_SPEEDBUFF_2];
540            break;
541        case 3706:                                          // Alliance elixir of regeneration spawn
542            //buff_guid = m_BgObjects[BG_WS_OBJECT_REGENBUFF_1];
543            break;
544        case 3708:                                          // Horde elixir of regeneration spawn
545            //buff_guid = m_BgObjects[BG_WS_OBJECT_REGENBUFF_2];
546            break;
547        case 3707:                                          // Alliance elixir of berserk spawn
548            //buff_guid = m_BgObjects[BG_WS_OBJECT_BERSERKBUFF_1];
549            break;
550        case 3709:                                          // Horde elixir of berserk spawn
551            //buff_guid = m_BgObjects[BG_WS_OBJECT_BERSERKBUFF_2];
552            break;
553        case 3646:                                          // Alliance Flag spawn
554            if(m_FlagState[BG_TEAM_HORDE] && !m_FlagState[BG_TEAM_ALLIANCE])
555                if(GetHordeFlagPickerGUID() == Source->GetGUID())
556                    EventPlayerCapturedFlag(Source);
557            break;
558        case 3647:                                          // Horde Flag spawn
559            if(m_FlagState[BG_TEAM_ALLIANCE] && !m_FlagState[BG_TEAM_HORDE])
560                if(GetAllianceFlagPickerGUID() == Source->GetGUID())
561                    EventPlayerCapturedFlag(Source);
562            break;
563        case 3649:                                          // unk1
564        case 3688:                                          // unk2
565        case 4628:                                          // unk3
566        case 4629:                                          // unk4
567            break;
568        default:
569            sLog.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", Trigger);
570            Source->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", Trigger);
571            break;
572    }
573
574    //if(buff_guid)
575    //    HandleTriggerBuff(buff_guid,Source);
576}
577
578bool BattleGroundWS::SetupBattleGround()
579{
580    // flags
581    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)
582        || !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)
583        // buffs
584        || !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)
585        || !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)
586        || !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)
587        || !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)
588        || !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)
589        || !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)
590        // alliance gates
591        || !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)
592        || !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)
593        || !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)
594        || !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)
595        || !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)
596        || !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)
597        // horde gates
598        || !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)
599        || !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)
600        || !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)
601        || !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)
602        )
603    {
604        sLog.outErrorDb("BatteGroundWS: Failed to spawn some object BattleGround not created!");
605        return false;
606    }
607
608    WorldSafeLocsEntry const *sg = sWorldSafeLocsStore.LookupEntry(WS_GRAVEYARD_MAIN_ALLIANCE);
609    if(!sg || !AddSpiritGuide(WS_SPIRIT_MAIN_ALLIANCE, sg->x, sg->y, sg->z, 3.124139f, ALLIANCE))
610    {
611        sLog.outErrorDb("BatteGroundWS: Failed to spawn Alliance spirit guide! BattleGround not created!");
612        return false;
613    }
614
615    sg = sWorldSafeLocsStore.LookupEntry(WS_GRAVEYARD_MAIN_HORDE);
616    if(!sg || !AddSpiritGuide(WS_SPIRIT_MAIN_HORDE, sg->x, sg->y, sg->z, 3.193953f, HORDE))
617    {
618        sLog.outErrorDb("BatteGroundWS: Failed to spawn Horde spirit guide! BattleGround not created!");
619        return false;
620    }
621
622    sLog.outDebug("BatteGroundWS: BG objects and spirit guides spawned");
623
624    return true;
625}
626
627void BattleGroundWS::ResetBGSubclass()
628{
629    m_FlagKeepers[BG_TEAM_ALLIANCE]     = 0;
630    m_FlagKeepers[BG_TEAM_HORDE]        = 0;
631    m_DroppedFlagGUID[BG_TEAM_ALLIANCE] = 0;
632    m_DroppedFlagGUID[BG_TEAM_HORDE]    = 0;
633    m_FlagState[BG_TEAM_ALLIANCE]       = BG_WS_FLAG_STATE_ON_BASE;
634    m_FlagState[BG_TEAM_HORDE]          = BG_WS_FLAG_STATE_ON_BASE;
635    m_TeamScores[BG_TEAM_ALLIANCE]      = 0;
636    m_TeamScores[BG_TEAM_HORDE]         = 0;
637
638    /* Spirit nodes is static at this BG and then not required deleting at BG reset.
639    if(m_BgCreatures[WS_SPIRIT_MAIN_ALLIANCE])
640        DelCreature(WS_SPIRIT_MAIN_ALLIANCE);
641
642    if(m_BgCreatures[WS_SPIRIT_MAIN_HORDE])
643        DelCreature(WS_SPIRIT_MAIN_HORDE);
644    */
645}
646
647void BattleGroundWS::HandleKillPlayer(Player *player, Player *killer)
648{
649    if(GetStatus() != STATUS_IN_PROGRESS)
650        return;
651
652    EventPlayerDroppedFlag(player);
653
654    BattleGround::HandleKillPlayer(player, killer);
655}
656
657void BattleGroundWS::UpdatePlayerScore(Player *Source, uint32 type, uint32 value)
658{
659
660    std::map<uint64, BattleGroundScore*>::iterator itr = m_PlayerScores.find(Source->GetGUID());
661
662    if(itr == m_PlayerScores.end())                         // player not found
663        return;
664
665    switch(type)
666    {
667        case SCORE_FLAG_CAPTURES:                           // flags captured
668            ((BattleGroundWGScore*)itr->second)->FlagCaptures += value;
669            break;
670        case SCORE_FLAG_RETURNS:                            // flags returned
671            ((BattleGroundWGScore*)itr->second)->FlagReturns += value;
672            break;
673        default:
674            BattleGround::UpdatePlayerScore(Source, type, value);
675            break;
676    }
677}
678
679void BattleGroundWS::FillInitialWorldStates(WorldPacket& data)
680{
681    data << uint32(BG_WS_FLAG_CAPTURES_ALLIANCE) << uint32(GetTeamScore(ALLIANCE));
682    data << uint32(BG_WS_FLAG_CAPTURES_HORDE) << uint32(GetTeamScore(HORDE));
683
684    if(m_FlagState[BG_TEAM_ALLIANCE] == BG_WS_FLAG_STATE_ON_GROUND)
685        data << uint32(BG_WS_FLAG_UNK_ALLIANCE) << uint32(-1);
686    else if (m_FlagState[BG_TEAM_ALLIANCE] == BG_WS_FLAG_STATE_ON_PLAYER)
687        data << uint32(BG_WS_FLAG_UNK_ALLIANCE) << uint32(1);
688    else
689        data << uint32(BG_WS_FLAG_UNK_ALLIANCE) << uint32(0);
690
691    if(m_FlagState[BG_TEAM_HORDE] == BG_WS_FLAG_STATE_ON_GROUND)
692        data << uint32(BG_WS_FLAG_UNK_HORDE) << uint32(-1);
693    else if (m_FlagState[BG_TEAM_HORDE] == BG_WS_FLAG_STATE_ON_PLAYER)
694        data << uint32(BG_WS_FLAG_UNK_HORDE) << uint32(1);
695    else
696        data << uint32(BG_WS_FLAG_UNK_HORDE) << uint32(0);
697
698    data << uint32(BG_WS_FLAG_CAPTURES_MAX) << uint32(BG_WS_MAX_TEAM_SCORE);
699
700    if (m_FlagState[BG_TEAM_HORDE] == BG_WS_FLAG_STATE_ON_PLAYER)
701        data << uint32(BG_WS_FLAG_STATE_HORDE) << uint32(2);
702    else
703        data << uint32(BG_WS_FLAG_STATE_HORDE) << uint32(1);
704
705    if (m_FlagState[BG_TEAM_ALLIANCE] == BG_WS_FLAG_STATE_ON_PLAYER)
706        data << uint32(BG_WS_FLAG_STATE_ALLIANCE) << uint32(2);
707    else
708        data << uint32(BG_WS_FLAG_STATE_ALLIANCE) << uint32(1);
709
710}
Note: See TracBrowser for help on using the browser.