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

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

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.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 "BattleGroundNA.h"
25#include "Creature.h"
26#include "ObjectMgr.h"
27#include "MapManager.h"
28#include "Language.h"
29
30BattleGroundNA::BattleGroundNA()
31{
32    m_BgObjects.resize(BG_NA_OBJECT_MAX);
33}
34
35BattleGroundNA::~BattleGroundNA()
36{
37
38}
39
40void BattleGroundNA::Update(time_t diff)
41{
42    BattleGround::Update(diff);
43
44    // after bg start we get there
45    if (GetStatus() == STATUS_WAIT_JOIN && GetPlayersSize())
46    {
47        ModifyStartDelayTime(diff);
48
49        if (!(m_Events & 0x01))
50        {
51            m_Events |= 0x01;
52            // setup here, only when at least one player has ported to the map
53            if(!SetupBattleGround())
54            {
55                EndNow();
56                return;
57            }
58            for(uint32 i = BG_NA_OBJECT_DOOR_1; i <= BG_NA_OBJECT_DOOR_4; i++)
59                SpawnBGObject(i, RESPAWN_IMMEDIATELY);
60
61            SetStartDelayTime(START_DELAY1);
62            SendMessageToAll(LANG_ARENA_ONE_MINUTE);
63        }
64        // After 30 seconds, warning is signalled
65        else if (GetStartDelayTime() <= START_DELAY2 && !(m_Events & 0x04))
66        {
67            m_Events |= 0x04;
68            SendMessageToAll(LANG_ARENA_THIRTY_SECONDS);
69        }
70        // After 15 seconds, warning is signalled
71        else if (GetStartDelayTime() <= START_DELAY3 && !(m_Events & 0x08))
72        {
73            m_Events |= 0x08;
74            SendMessageToAll(LANG_ARENA_FIFTEEN_SECONDS);
75        }
76        // delay expired (1 minute)
77        else if (GetStartDelayTime() <= 0 && !(m_Events & 0x10))
78        {
79            m_Events |= 0x10;
80
81            for(uint32 i = BG_NA_OBJECT_DOOR_1; i <= BG_NA_OBJECT_DOOR_2; i++)
82                DoorOpen(i);
83
84            for(uint32 i = BG_NA_OBJECT_BUFF_1; i <= BG_NA_OBJECT_BUFF_2; i++)
85                SpawnBGObject(i, 60);
86
87            SendMessageToAll(LANG_ARENA_BEGUN);
88            SetStatus(STATUS_IN_PROGRESS);
89            SetStartDelayTime(0);
90
91            for(BattleGroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
92                if(Player *plr = objmgr.GetPlayer(itr->first))
93                    plr->RemoveAurasDueToSpell(SPELL_ARENA_PREPARATION);
94
95            if(!GetPlayersCountByTeam(ALLIANCE) && GetPlayersCountByTeam(HORDE))
96                EndBattleGround(HORDE);
97            else if(GetPlayersCountByTeam(ALLIANCE) && !GetPlayersCountByTeam(HORDE))
98                EndBattleGround(ALLIANCE);
99        }
100    }
101
102    /*if(GetStatus() == STATUS_IN_PROGRESS)
103    {
104        // update something
105    }*/
106}
107
108void BattleGroundNA::AddPlayer(Player *plr)
109{
110    BattleGround::AddPlayer(plr);
111    //create score and add it to map, default values are set in constructor
112    BattleGroundNAScore* sc = new BattleGroundNAScore;
113
114    m_PlayerScores[plr->GetGUID()] = sc;
115
116    UpdateWorldState(0xa0f, GetAlivePlayersCountByTeam(ALLIANCE));
117    UpdateWorldState(0xa10, GetAlivePlayersCountByTeam(HORDE));
118}
119
120void BattleGroundNA::RemovePlayer(Player* /*plr*/, uint64 /*guid*/)
121{
122    if(GetStatus() == STATUS_WAIT_LEAVE)
123        return;
124
125    UpdateWorldState(0xa0f, GetAlivePlayersCountByTeam(ALLIANCE));
126    UpdateWorldState(0xa10, GetAlivePlayersCountByTeam(HORDE));
127
128    if(!GetAlivePlayersCountByTeam(ALLIANCE) && GetPlayersCountByTeam(HORDE))
129        EndBattleGround(HORDE);
130    else if(GetPlayersCountByTeam(ALLIANCE) && !GetAlivePlayersCountByTeam(HORDE))
131        EndBattleGround(ALLIANCE);
132}
133
134void BattleGroundNA::HandleKillPlayer(Player *player, Player *killer)
135{
136    if(GetStatus() != STATUS_IN_PROGRESS)
137        return;
138
139    if(!killer)
140    {
141        sLog.outError("BattleGroundNA: Killer player not found");
142        return;
143    }
144
145    BattleGround::HandleKillPlayer(player,killer);
146
147    UpdateWorldState(0xa0f, GetAlivePlayersCountByTeam(ALLIANCE));
148    UpdateWorldState(0xa10, GetAlivePlayersCountByTeam(HORDE));
149
150    if(!GetAlivePlayersCountByTeam(ALLIANCE))
151    {
152        // all opponents killed
153        EndBattleGround(HORDE);
154    }
155    else if(!GetAlivePlayersCountByTeam(HORDE))
156    {
157        // all opponents killed
158        EndBattleGround(ALLIANCE);
159    }
160}
161
162bool BattleGroundNA::HandlePlayerUnderMap(Player *player)
163{
164    player->TeleportTo(GetMapId(),4055.504395,2919.660645,13.611241,player->GetOrientation(),false);
165    return true;
166}
167
168void BattleGroundNA::HandleAreaTrigger(Player *Source, uint32 Trigger)
169{
170    if(GetStatus() != STATUS_IN_PROGRESS)
171        return;
172
173    //uint32 SpellId = 0;
174    //uint64 buff_guid = 0;
175    switch(Trigger)
176    {
177        case 4536:                                          // buff trigger?
178        case 4537:                                          // buff trigger?
179            break;
180        default:
181            sLog.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", Trigger);
182            Source->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", Trigger);
183            break;
184    }
185
186    //if(buff_guid)
187    //    HandleTriggerBuff(buff_guid,Source);
188}
189
190void BattleGroundNA::FillInitialWorldStates(WorldPacket &data)
191{
192    data << uint32(0xa0f) << uint32(GetAlivePlayersCountByTeam(ALLIANCE));           // 7
193    data << uint32(0xa10) << uint32(GetAlivePlayersCountByTeam(HORDE));           // 8
194    data << uint32(0xa11) << uint32(1);           // 9
195}
196
197void BattleGroundNA::ResetBGSubclass()
198{
199
200}
201
202bool BattleGroundNA::SetupBattleGround()
203{
204    // gates
205    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)
206        || !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)
207        || !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)
208        || !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)
209    // buffs
210        || !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)
211        || !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))
212    {
213        sLog.outErrorDb("BatteGroundNA: Failed to spawn some object!");
214        return false;
215    }
216
217    return true;
218}
219
220/*
22120:12:14 id:036668 [S2C] SMSG_INIT_WORLD_STATES (706 = 0x02C2) len: 86
2220000: 2f 02 00 00 72 0e 00 00 00 00 00 00 09 00 11 0a  |  /...r...........
2230010: 00 00 01 00 00 00 0f 0a 00 00 00 00 00 00 10 0a  |  ................
2240020: 00 00 00 00 00 00 d4 08 00 00 00 00 00 00 d8 08  |  ................
2250030: 00 00 00 00 00 00 d7 08 00 00 00 00 00 00 d6 08  |  ................
2260040: 00 00 00 00 00 00 d5 08 00 00 00 00 00 00 d3 08  |  ................
2270050: 00 00 00 00 00 00                                |  ......
228*/
Note: See TracBrowser for help on using the browser.