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

Revision 34, 28.7 kB (checked in by yumileroy, 17 years ago)

[svn] * Removing useless data accidentally committed.
* Applying ImpConfig? patch.
* Note: QUEUE_FOR_GM currently disabled as it's not compatible with the ACE patch. Anyone care to rewrite it?
* Note2: This is untested - I may have done some mistakes here and there. Will try to compile now.

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