root/trunk/src/game/BattleGroundRL.cpp @ 230

Revision 230, 7.4 kB (checked in by yumileroy, 17 years ago)

[svn] *** Source: MaNGOS ***
* Implement localization of creature/gameobject name that say/yell. Author: evilstar (rewrited by: Vladimir)
* Fix auth login queue. Author: Derex
* Allowed switching INVTYPE_HOLDABLE items during combat, used correct spells for triggering global cooldown at weapon switch. Author: mobel/simak
* Fixed some format arg type/value pairs. Other warnings. Author: Vladimir
* [238_world.sql] Allow have team dependent graveyards at entrance map for instances. Author: Vladimir

NOTE:
Entrance map graveyards selected by same way as local (by distance from entrance) Until DB support will work in old way base at current DB data.

Original author: visagalis
Date: 2008-11-14 17:03:03-06: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 "BattleGroundRL.h"
25#include "Creature.h"
26#include "ObjectMgr.h"
27#include "MapManager.h"
28#include "Language.h"
29
30BattleGroundRL::BattleGroundRL()
31{
32    m_BgObjects.resize(BG_RL_OBJECT_MAX);
33}
34
35BattleGroundRL::~BattleGroundRL()
36{
37
38}
39
40void BattleGroundRL::Update(time_t diff)
41{
42    BattleGround::Update(diff);
43
44    if (GetStatus() == STATUS_WAIT_JOIN && GetPlayersSize())
45    {
46        ModifyStartDelayTime(diff);
47
48        if (!(m_Events & 0x01))
49        {
50            m_Events |= 0x01;
51
52            // setup here, only when at least one player has ported to the map
53            if(!SetupBattleGround())
54            {
55                EndNow();
56                return;
57            }
58
59            for(uint32 i = BG_RL_OBJECT_DOOR_1; i <= BG_RL_OBJECT_DOOR_2; i++)
60                SpawnBGObject(i, RESPAWN_IMMEDIATELY);
61
62            SetStartDelayTime(START_DELAY1);
63            SendMessageToAll(LANG_ARENA_ONE_MINUTE);
64        }
65        // After 30 seconds, warning is signalled
66        else if (GetStartDelayTime() <= START_DELAY2 && !(m_Events & 0x04))
67        {
68            m_Events |= 0x04;
69            SendMessageToAll(LANG_ARENA_THIRTY_SECONDS);
70        }
71        // After 15 seconds, warning is signalled
72        else if (GetStartDelayTime() <= START_DELAY3 && !(m_Events & 0x08))
73        {
74            m_Events |= 0x08;
75            SendMessageToAll(LANG_ARENA_FIFTEEN_SECONDS);
76        }
77        // delay expired (1 minute)
78        else if (GetStartDelayTime() <= 0 && !(m_Events & 0x10))
79        {
80            m_Events |= 0x10;
81
82            for(uint32 i = BG_RL_OBJECT_DOOR_1; i <= BG_RL_OBJECT_DOOR_2; i++)
83                DoorOpen(i);
84
85            for(uint32 i = BG_RL_OBJECT_BUFF_1; i <= BG_RL_OBJECT_BUFF_2; i++)
86                SpawnBGObject(i, 60);
87
88            SendMessageToAll(LANG_ARENA_BEGUN);
89            SetStatus(STATUS_IN_PROGRESS);
90            SetStartDelayTime(0);
91
92            for(BattleGroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
93                if(Player *plr = objmgr.GetPlayer(itr->first))
94                    plr->RemoveAurasDueToSpell(SPELL_ARENA_PREPARATION);
95
96            if(!GetPlayersCountByTeam(ALLIANCE) && GetPlayersCountByTeam(HORDE))
97                EndBattleGround(HORDE);
98            else if(GetPlayersCountByTeam(ALLIANCE) && !GetPlayersCountByTeam(HORDE))
99                EndBattleGround(ALLIANCE);
100        }
101    }
102
103    /*if(GetStatus() == STATUS_IN_PROGRESS)
104    {
105        // update something
106    }*/
107}
108
109void BattleGroundRL::AddPlayer(Player *plr)
110{
111    BattleGround::AddPlayer(plr);
112    //create score and add it to map, default values are set in constructor
113    BattleGroundRLScore* sc = new BattleGroundRLScore;
114
115    m_PlayerScores[plr->GetGUID()] = sc;
116
117    UpdateWorldState(0xbb8, GetAlivePlayersCountByTeam(ALLIANCE));
118    UpdateWorldState(0xbb9, GetAlivePlayersCountByTeam(HORDE));
119}
120
121void BattleGroundRL::RemovePlayer(Player* /*plr*/, uint64 /*guid*/)
122{
123    if(GetStatus() == STATUS_WAIT_LEAVE)
124        return;
125
126    UpdateWorldState(0xbb8, GetAlivePlayersCountByTeam(ALLIANCE));
127    UpdateWorldState(0xbb9, GetAlivePlayersCountByTeam(HORDE));
128
129    if(!GetAlivePlayersCountByTeam(ALLIANCE) && GetPlayersCountByTeam(HORDE))
130        EndBattleGround(HORDE);
131    else if(GetPlayersCountByTeam(ALLIANCE) && !GetAlivePlayersCountByTeam(HORDE))
132        EndBattleGround(ALLIANCE);
133}
134
135void BattleGroundRL::HandleKillPlayer(Player *player, Player *killer)
136{
137    if(GetStatus() != STATUS_IN_PROGRESS)
138        return;
139
140    if(!killer)
141    {
142        sLog.outError("Killer player not found");
143        return;
144    }
145
146    BattleGround::HandleKillPlayer(player,killer);
147
148    UpdateWorldState(0xbb8, GetAlivePlayersCountByTeam(ALLIANCE));
149    UpdateWorldState(0xbb9, GetAlivePlayersCountByTeam(HORDE));
150
151    if(!GetAlivePlayersCountByTeam(ALLIANCE))
152    {
153        // all opponents killed
154        EndBattleGround(HORDE);
155    }
156    else if(!GetAlivePlayersCountByTeam(HORDE))
157    {
158        // all opponents killed
159        EndBattleGround(ALLIANCE);
160    }
161}
162
163bool BattleGroundRL::HandlePlayerUnderMap(Player *player)
164{
165    player->TeleportTo(GetMapId(),1285.810547,1667.896851,39.957642,player->GetOrientation(),false);
166    return true;
167}
168
169void BattleGroundRL::HandleAreaTrigger(Player *Source, uint32 Trigger)
170{
171    // this is wrong way to implement these things. On official it done by gameobject spell cast.
172    if(GetStatus() != STATUS_IN_PROGRESS)
173        return;
174
175    //uint32 SpellId = 0;
176    //uint64 buff_guid = 0;
177    switch(Trigger)
178    {
179        case 4696:                                          // buff trigger?
180        case 4697:                                          // buff trigger?
181            break;
182        default:
183            sLog.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", Trigger);
184            Source->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", Trigger);
185            break;
186    }
187
188    //if(buff_guid)
189    //    HandleTriggerBuff(buff_guid,Source);
190}
191
192void BattleGroundRL::FillInitialWorldStates(WorldPacket &data)
193{
194    data << uint32(0xbb8) << uint32(GetAlivePlayersCountByTeam(ALLIANCE));           // 7
195    data << uint32(0xbb9) << uint32(GetAlivePlayersCountByTeam(HORDE));           // 8
196    data << uint32(0xbba) << uint32(1);           // 9
197}
198
199void BattleGroundRL::ResetBGSubclass()
200{
201
202}
203
204bool BattleGroundRL::SetupBattleGround()
205{
206    // gates
207    if(    !AddObject(BG_RL_OBJECT_DOOR_1, BG_RL_OBJECT_TYPE_DOOR_1, 1293.561, 1601.938, 31.60557, -1.457349, 0, 0, -0.6658813, 0.7460576, RESPAWN_IMMEDIATELY)
208        || !AddObject(BG_RL_OBJECT_DOOR_2, BG_RL_OBJECT_TYPE_DOOR_2, 1278.648, 1730.557, 31.60557, 1.684245, 0, 0, 0.7460582, 0.6658807, RESPAWN_IMMEDIATELY)
209    // buffs
210        || !AddObject(BG_RL_OBJECT_BUFF_1, BG_RL_OBJECT_TYPE_BUFF_1, 1328.719971, 1632.719971, 36.730400, -1.448624, 0, 0, 0.6626201, -0.7489557, 120)
211        || !AddObject(BG_RL_OBJECT_BUFF_2, BG_RL_OBJECT_TYPE_BUFF_2, 1243.300049, 1699.170044, 34.872601, -0.06981307, 0, 0, 0.03489945, -0.9993908, 120))
212    {
213        sLog.outErrorDb("BatteGroundRL: Failed to spawn some object!");
214        return false;
215    }
216
217    return true;
218}
219
220/*
221Packet S->C, id 600, SMSG_INIT_WORLD_STATES (706), len 86
2220000: 3C 02 00 00 80 0F 00 00 00 00 00 00 09 00 BA 0B | <...............
2230010: 00 00 01 00 00 00 B9 0B 00 00 02 00 00 00 B8 0B | ................
2240020: 00 00 00 00 00 00 D8 08 00 00 00 00 00 00 D7 08 | ................
2250030: 00 00 00 00 00 00 D6 08 00 00 00 00 00 00 D5 08 | ................
2260040: 00 00 00 00 00 00 D3 08 00 00 00 00 00 00 D4 08 | ................
2270050: 00 00 00 00 00 00                               | ......
228*/
Note: See TracBrowser for help on using the browser.