root/trunk/src/game/BattleGroundNA.cpp @ 23

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

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

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

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18
19#include "Object.h"
20#include "Player.h"
21#include "BattleGround.h"
22#include "BattleGroundNA.h"
23#include "Creature.h"
24#include "ObjectMgr.h"
25#include "MapManager.h"
26#include "Language.h"
27
28BattleGroundNA::BattleGroundNA()
29{
30    m_BgObjects.resize(BG_NA_OBJECT_MAX);
31}
32
33BattleGroundNA::~BattleGroundNA()
34{
35
36}
37
38void BattleGroundNA::Update(time_t diff)
39{
40    BattleGround::Update(diff);
41
42    // after bg start we get there
43    if (GetStatus() == STATUS_WAIT_JOIN && GetPlayersSize())
44    {
45        ModifyStartDelayTime(diff);
46
47        if (!(m_Events & 0x01))
48        {
49            m_Events |= 0x01;
50            // setup here, only when at least one player has ported to the map
51            if(!SetupBattleGround())
52            {
53                EndNow();
54                return;
55            }
56            for(uint32 i = BG_NA_OBJECT_DOOR_1; i <= BG_NA_OBJECT_DOOR_4; i++)
57                SpawnBGObject(i, RESPAWN_IMMEDIATELY);
58
59            SetStartDelayTime(START_DELAY1);
60            SendMessageToAll(LANG_ARENA_ONE_MINUTE);
61        }
62        // After 30 seconds, warning is signalled
63        else if (GetStartDelayTime() <= START_DELAY2 && !(m_Events & 0x04))
64        {
65            m_Events |= 0x04;
66            SendMessageToAll(LANG_ARENA_THIRTY_SECONDS);
67        }
68        // After 15 seconds, warning is signalled
69        else if (GetStartDelayTime() <= START_DELAY3 && !(m_Events & 0x08))
70        {
71            m_Events |= 0x08;
72            SendMessageToAll(LANG_ARENA_FIFTEEN_SECONDS);
73        }
74        // delay expired (1 minute)
75        else if (GetStartDelayTime() <= 0 && !(m_Events & 0x10))
76        {
77            m_Events |= 0x10;
78
79            for(uint32 i = BG_NA_OBJECT_DOOR_1; i <= BG_NA_OBJECT_DOOR_2; i++)
80                DoorOpen(i);
81
82            for(uint32 i = BG_NA_OBJECT_BUFF_1; i <= BG_NA_OBJECT_BUFF_2; i++)
83                SpawnBGObject(i, 60);
84
85            SendMessageToAll(LANG_ARENA_BEGUN);
86            SetStatus(STATUS_IN_PROGRESS);
87            SetStartDelayTime(0);
88
89            for(BattleGroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
90                if(Player *plr = objmgr.GetPlayer(itr->first))
91                    plr->RemoveAurasDueToSpell(SPELL_ARENA_PREPARATION);
92
93            if(!GetPlayersCountByTeam(ALLIANCE) && GetPlayersCountByTeam(HORDE))
94                EndBattleGround(HORDE);
95            else if(GetPlayersCountByTeam(ALLIANCE) && !GetPlayersCountByTeam(HORDE))
96                EndBattleGround(ALLIANCE);
97        }
98    }
99
100    /*if(GetStatus() == STATUS_IN_PROGRESS)
101    {
102        // update something
103    }*/
104}
105
106void BattleGroundNA::AddPlayer(Player *plr)
107{
108    BattleGround::AddPlayer(plr);
109    //create score and add it to map, default values are set in constructor
110    BattleGroundNAScore* sc = new BattleGroundNAScore;
111
112    m_PlayerScores[plr->GetGUID()] = sc;
113
114    UpdateWorldState(0xa0f, GetAlivePlayersCountByTeam(ALLIANCE));
115    UpdateWorldState(0xa10, GetAlivePlayersCountByTeam(HORDE));
116}
117
118void BattleGroundNA::RemovePlayer(Player* /*plr*/, uint64 /*guid*/)
119{
120    if(GetStatus() == STATUS_WAIT_LEAVE)
121        return;
122
123    UpdateWorldState(0xa0f, GetAlivePlayersCountByTeam(ALLIANCE));
124    UpdateWorldState(0xa10, GetAlivePlayersCountByTeam(HORDE));
125
126    if(!GetAlivePlayersCountByTeam(ALLIANCE) && GetPlayersCountByTeam(HORDE))
127        EndBattleGround(HORDE);
128    else if(GetPlayersCountByTeam(ALLIANCE) && !GetAlivePlayersCountByTeam(HORDE))
129        EndBattleGround(ALLIANCE);
130}
131
132void BattleGroundNA::HandleKillPlayer(Player *player, Player *killer)
133{
134    if(GetStatus() != STATUS_IN_PROGRESS)
135        return;
136
137    if(!killer)
138    {
139        sLog.outError("BattleGroundNA: Killer player not found");
140        return;
141    }
142
143    BattleGround::HandleKillPlayer(player,killer);
144
145    UpdateWorldState(0xa0f, GetAlivePlayersCountByTeam(ALLIANCE));
146    UpdateWorldState(0xa10, GetAlivePlayersCountByTeam(HORDE));
147
148    if(!GetAlivePlayersCountByTeam(ALLIANCE))
149    {
150        // all opponents killed
151        EndBattleGround(HORDE);
152    }
153    else if(!GetAlivePlayersCountByTeam(HORDE))
154    {
155        // all opponents killed
156        EndBattleGround(ALLIANCE);
157    }
158}
159
160bool BattleGroundNA::HandlePlayerUnderMap(Player *player)
161{
162    player->TeleportTo(GetMapId(),4055.504395,2919.660645,13.611241,player->GetOrientation(),false);
163    return true;
164}
165
166void BattleGroundNA::HandleAreaTrigger(Player *Source, uint32 Trigger)
167{
168    if(GetStatus() != STATUS_IN_PROGRESS)
169        return;
170
171    //uint32 SpellId = 0;
172    //uint64 buff_guid = 0;
173    switch(Trigger)
174    {
175        case 4536:                                          // buff trigger?
176        case 4537:                                          // buff trigger?
177            break;
178        default:
179            sLog.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", Trigger);
180            Source->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", Trigger);
181            break;
182    }
183
184    //if(buff_guid)
185    //    HandleTriggerBuff(buff_guid,Source);
186}
187
188void BattleGroundNA::FillInitialWorldStates(WorldPacket &data)
189{
190    data << uint32(0xa0f) << uint32(GetAlivePlayersCountByTeam(ALLIANCE));           // 7
191    data << uint32(0xa10) << uint32(GetAlivePlayersCountByTeam(HORDE));           // 8
192    data << uint32(0xa11) << uint32(1);           // 9
193}
194
195void BattleGroundNA::ResetBGSubclass()
196{
197
198}
199
200bool BattleGroundNA::SetupBattleGround()
201{
202    // gates
203    if(    !AddObject(BG_NA_OBJECT_DOOR_1, BG_NA_OBJECT_TYPE_DOOR_1, 4031.854, 2966.833, 12.6462, -2.648788, 0, 0, 0.9697962, -0.2439165, RESPAWN_IMMEDIATELY)
204        || !AddObject(BG_NA_OBJECT_DOOR_2, BG_NA_OBJECT_TYPE_DOOR_2, 4081.179, 2874.97, 12.39171, 0.4928045, 0, 0, 0.2439165, 0.9697962, RESPAWN_IMMEDIATELY)
205        || !AddObject(BG_NA_OBJECT_DOOR_3, BG_NA_OBJECT_TYPE_DOOR_3, 4023.709, 2981.777, 10.70117, -2.648788, 0, 0, 0.9697962, -0.2439165, RESPAWN_IMMEDIATELY)
206        || !AddObject(BG_NA_OBJECT_DOOR_4, BG_NA_OBJECT_TYPE_DOOR_4, 4090.064, 2858.438, 10.23631, 0.4928045, 0, 0, 0.2439165, 0.9697962, RESPAWN_IMMEDIATELY)
207    // buffs
208        || !AddObject(BG_NA_OBJECT_BUFF_1, BG_NA_OBJECT_TYPE_BUFF_1, 4009.189941, 2895.250000, 13.052700, -1.448624, 0, 0, 0.6626201, -0.7489557, 120)
209        || !AddObject(BG_NA_OBJECT_BUFF_2, BG_NA_OBJECT_TYPE_BUFF_2, 4103.330078, 2946.350098, 13.051300, -0.06981307, 0, 0, 0.03489945, -0.9993908, 120))
210    {
211        sLog.outErrorDb("BatteGroundNA: Failed to spawn some object!");
212        return false;
213    }
214
215    return true;
216}
217
218/*
21920:12:14 id:036668 [S2C] SMSG_INIT_WORLD_STATES (706 = 0x02C2) len: 86
2200000: 2f 02 00 00 72 0e 00 00 00 00 00 00 09 00 11 0a  |  /...r...........
2210010: 00 00 01 00 00 00 0f 0a 00 00 00 00 00 00 10 0a  |  ................
2220020: 00 00 00 00 00 00 d4 08 00 00 00 00 00 00 d8 08  |  ................
2230030: 00 00 00 00 00 00 d7 08 00 00 00 00 00 00 d6 08  |  ................
2240040: 00 00 00 00 00 00 d5 08 00 00 00 00 00 00 d3 08  |  ................
2250050: 00 00 00 00 00 00                                |  ......
226*/
Note: See TracBrowser for help on using the browser.