[2] | 1 | /* |
---|
[102] | 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
[44] | 4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
[2] | 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 |
---|
[44] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[2] | 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 |
---|
[44] | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[2] | 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 | |
---|
| 30 | BattleGroundRL::BattleGroundRL() |
---|
| 31 | { |
---|
| 32 | m_BgObjects.resize(BG_RL_OBJECT_MAX); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | BattleGroundRL::~BattleGroundRL() |
---|
| 36 | { |
---|
| 37 | |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | void 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 | |
---|
[9] | 52 | // setup here, only when at least one player has ported to the map |
---|
| 53 | if(!SetupBattleGround()) |
---|
| 54 | { |
---|
| 55 | EndNow(); |
---|
| 56 | return; |
---|
| 57 | } |
---|
| 58 | |
---|
[2] | 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 | |
---|
[9] | 85 | for(uint32 i = BG_RL_OBJECT_BUFF_1; i <= BG_RL_OBJECT_BUFF_2; i++) |
---|
| 86 | SpawnBGObject(i, 60); |
---|
| 87 | |
---|
[2] | 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); |
---|
[9] | 95 | |
---|
| 96 | if(!GetPlayersCountByTeam(ALLIANCE) && GetPlayersCountByTeam(HORDE)) |
---|
| 97 | EndBattleGround(HORDE); |
---|
| 98 | else if(GetPlayersCountByTeam(ALLIANCE) && !GetPlayersCountByTeam(HORDE)) |
---|
| 99 | EndBattleGround(ALLIANCE); |
---|
[2] | 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | /*if(GetStatus() == STATUS_IN_PROGRESS) |
---|
| 104 | { |
---|
| 105 | // update something |
---|
| 106 | }*/ |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | void 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; |
---|
[9] | 116 | |
---|
| 117 | UpdateWorldState(0xbb8, GetAlivePlayersCountByTeam(ALLIANCE)); |
---|
| 118 | UpdateWorldState(0xbb9, GetAlivePlayersCountByTeam(HORDE)); |
---|
[2] | 119 | } |
---|
| 120 | |
---|
[230] | 121 | void BattleGroundRL::RemovePlayer(Player* /*plr*/, uint64 /*guid*/) |
---|
[2] | 122 | { |
---|
[9] | 123 | if(GetStatus() == STATUS_WAIT_LEAVE) |
---|
| 124 | return; |
---|
[2] | 125 | |
---|
[9] | 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); |
---|
[2] | 133 | } |
---|
| 134 | |
---|
| 135 | void 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 | |
---|
[9] | 146 | BattleGround::HandleKillPlayer(player,killer); |
---|
[2] | 147 | |
---|
[9] | 148 | UpdateWorldState(0xbb8, GetAlivePlayersCountByTeam(ALLIANCE)); |
---|
| 149 | UpdateWorldState(0xbb9, GetAlivePlayersCountByTeam(HORDE)); |
---|
[2] | 150 | |
---|
[9] | 151 | if(!GetAlivePlayersCountByTeam(ALLIANCE)) |
---|
[2] | 152 | { |
---|
| 153 | // all opponents killed |
---|
[9] | 154 | EndBattleGround(HORDE); |
---|
[2] | 155 | } |
---|
[9] | 156 | else if(!GetAlivePlayersCountByTeam(HORDE)) |
---|
| 157 | { |
---|
| 158 | // all opponents killed |
---|
| 159 | EndBattleGround(ALLIANCE); |
---|
| 160 | } |
---|
[2] | 161 | } |
---|
| 162 | |
---|
[9] | 163 | bool BattleGroundRL::HandlePlayerUnderMap(Player *player) |
---|
| 164 | { |
---|
| 165 | player->TeleportTo(GetMapId(),1285.810547,1667.896851,39.957642,player->GetOrientation(),false); |
---|
| 166 | return true; |
---|
| 167 | } |
---|
| 168 | |
---|
[2] | 169 | void 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 | |
---|
[9] | 192 | void 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 | |
---|
[2] | 199 | void BattleGroundRL::ResetBGSubclass() |
---|
| 200 | { |
---|
[9] | 201 | |
---|
[2] | 202 | } |
---|
| 203 | |
---|
| 204 | bool BattleGroundRL::SetupBattleGround() |
---|
| 205 | { |
---|
| 206 | // gates |
---|
[9] | 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)) |
---|
[2] | 212 | { |
---|
| 213 | sLog.outErrorDb("BatteGroundRL: Failed to spawn some object!"); |
---|
| 214 | return false; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | return true; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | /* |
---|
| 221 | Packet S->C, id 600, SMSG_INIT_WORLD_STATES (706), len 86 |
---|
| 222 | 0000: 3C 02 00 00 80 0F 00 00 00 00 00 00 09 00 BA 0B | <............... |
---|
| 223 | 0010: 00 00 01 00 00 00 B9 0B 00 00 02 00 00 00 B8 0B | ................ |
---|
| 224 | 0020: 00 00 00 00 00 00 D8 08 00 00 00 00 00 00 D7 08 | ................ |
---|
| 225 | 0030: 00 00 00 00 00 00 D6 08 00 00 00 00 00 00 D5 08 | ................ |
---|
| 226 | 0040: 00 00 00 00 00 00 D3 08 00 00 00 00 00 00 D4 08 | ................ |
---|
| 227 | 0050: 00 00 00 00 00 00 | ...... |
---|
| 228 | */ |
---|