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

Revision 2, 27.5 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

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