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

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

[svn] * First public release of Trinity
* Based on MaNGOS rev 6743 and SD2-685
* All new netcode based on the ACE framework (thanks Derex)
* Arenas working (thanks w12x)
* Outdoor PvP working (thanks w12x)
* World Game Events support added (thanks w12x)
* All new build system (thanks Derex and Neo2003)
* Lots of new conf options based on the ImpConfig? patch (thanks Dythzer / w12x / Seline)
* Small fix to WSG
* Lots of other small additions and fixes

Original author: runningnak3d
Date: 2008-10-14 16:17:28-05:00

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