| 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 "BattleGroundBE.h" |
|---|
| 25 | #include "Creature.h" |
|---|
| 26 | #include "ObjectMgr.h" |
|---|
| 27 | #include "MapManager.h" |
|---|
| 28 | #include "Language.h" |
|---|
| 29 | |
|---|
| 30 | BattleGroundBE::BattleGroundBE() |
|---|
| 31 | { |
|---|
| 32 | m_BgObjects.resize(BG_BE_OBJECT_MAX); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | BattleGroundBE::~BattleGroundBE() |
|---|
| 36 | { |
|---|
| 37 | |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | void BattleGroundBE::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_BE_OBJECT_DOOR_1; i <= BG_BE_OBJECT_DOOR_4; i++) |
|---|
| 59 | SpawnBGObject(i, RESPAWN_IMMEDIATELY); |
|---|
| 60 | |
|---|
| 61 | for(uint32 i = BG_BE_OBJECT_BUFF_1; i <= BG_BE_OBJECT_BUFF_2; i++) |
|---|
| 62 | SpawnBGObject(i, RESPAWN_ONE_DAY); |
|---|
| 63 | |
|---|
| 64 | SetStartDelayTime(START_DELAY1); |
|---|
| 65 | SendMessageToAll(LANG_ARENA_ONE_MINUTE); |
|---|
| 66 | } |
|---|
| 67 | // After 30 seconds, warning is signalled |
|---|
| 68 | else if (GetStartDelayTime() <= START_DELAY2 && !(m_Events & 0x04)) |
|---|
| 69 | { |
|---|
| 70 | m_Events |= 0x04; |
|---|
| 71 | SendMessageToAll(LANG_ARENA_THIRTY_SECONDS); |
|---|
| 72 | } |
|---|
| 73 | // After 15 seconds, warning is signalled |
|---|
| 74 | else if (GetStartDelayTime() <= START_DELAY3 && !(m_Events & 0x08)) |
|---|
| 75 | { |
|---|
| 76 | m_Events |= 0x08; |
|---|
| 77 | SendMessageToAll(LANG_ARENA_FIFTEEN_SECONDS); |
|---|
| 78 | } |
|---|
| 79 | // delay expired (1 minute) |
|---|
| 80 | else if (GetStartDelayTime() <= 0 && !(m_Events & 0x10)) |
|---|
| 81 | { |
|---|
| 82 | m_Events |= 0x10; |
|---|
| 83 | |
|---|
| 84 | for(uint32 i = BG_BE_OBJECT_DOOR_1; i <= BG_BE_OBJECT_DOOR_2; i++) |
|---|
| 85 | DoorOpen(i); |
|---|
| 86 | |
|---|
| 87 | for(uint32 i = BG_BE_OBJECT_BUFF_1; i <= BG_BE_OBJECT_BUFF_2; i++) |
|---|
| 88 | SpawnBGObject(i, 60); |
|---|
| 89 | |
|---|
| 90 | SendMessageToAll(LANG_ARENA_BEGUN); |
|---|
| 91 | SetStatus(STATUS_IN_PROGRESS); |
|---|
| 92 | SetStartDelayTime(0); |
|---|
| 93 | |
|---|
| 94 | for(BattleGroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr) |
|---|
| 95 | if(Player *plr = objmgr.GetPlayer(itr->first)) |
|---|
| 96 | plr->RemoveAurasDueToSpell(SPELL_ARENA_PREPARATION); |
|---|
| 97 | |
|---|
| 98 | if(!GetPlayersCountByTeam(ALLIANCE) && GetPlayersCountByTeam(HORDE)) |
|---|
| 99 | EndBattleGround(HORDE); |
|---|
| 100 | else if(GetPlayersCountByTeam(ALLIANCE) && !GetPlayersCountByTeam(HORDE)) |
|---|
| 101 | EndBattleGround(ALLIANCE); |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | /*if(GetStatus() == STATUS_IN_PROGRESS) |
|---|
| 106 | { |
|---|
| 107 | // update something |
|---|
| 108 | }*/ |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | void BattleGroundBE::AddPlayer(Player *plr) |
|---|
| 112 | { |
|---|
| 113 | BattleGround::AddPlayer(plr); |
|---|
| 114 | //create score and add it to map, default values are set in constructor |
|---|
| 115 | BattleGroundBEScore* sc = new BattleGroundBEScore; |
|---|
| 116 | |
|---|
| 117 | m_PlayerScores[plr->GetGUID()] = sc; |
|---|
| 118 | |
|---|
| 119 | UpdateWorldState(0x9f1, GetAlivePlayersCountByTeam(ALLIANCE)); |
|---|
| 120 | UpdateWorldState(0x9f0, GetAlivePlayersCountByTeam(HORDE)); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | void BattleGroundBE::RemovePlayer(Player *plr, uint64 guid) |
|---|
| 124 | { |
|---|
| 125 | if(GetStatus() == STATUS_WAIT_LEAVE) |
|---|
| 126 | return; |
|---|
| 127 | |
|---|
| 128 | UpdateWorldState(0x9f1, GetAlivePlayersCountByTeam(ALLIANCE)); |
|---|
| 129 | UpdateWorldState(0x9f0, GetAlivePlayersCountByTeam(HORDE)); |
|---|
| 130 | |
|---|
| 131 | if(!GetAlivePlayersCountByTeam(ALLIANCE) && GetPlayersCountByTeam(HORDE)) |
|---|
| 132 | EndBattleGround(HORDE); |
|---|
| 133 | else if(GetPlayersCountByTeam(ALLIANCE) && !GetAlivePlayersCountByTeam(HORDE)) |
|---|
| 134 | EndBattleGround(ALLIANCE); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | void BattleGroundBE::HandleKillPlayer(Player *player, Player *killer) |
|---|
| 138 | { |
|---|
| 139 | if(GetStatus() != STATUS_IN_PROGRESS) |
|---|
| 140 | return; |
|---|
| 141 | |
|---|
| 142 | if(!killer) |
|---|
| 143 | { |
|---|
| 144 | sLog.outError("Killer player not found"); |
|---|
| 145 | return; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | BattleGround::HandleKillPlayer(player,killer); |
|---|
| 149 | |
|---|
| 150 | UpdateWorldState(0x9f1, GetAlivePlayersCountByTeam(ALLIANCE)); |
|---|
| 151 | UpdateWorldState(0x9f0, GetAlivePlayersCountByTeam(HORDE)); |
|---|
| 152 | |
|---|
| 153 | if(!GetAlivePlayersCountByTeam(ALLIANCE)) |
|---|
| 154 | { |
|---|
| 155 | // all opponents killed |
|---|
| 156 | EndBattleGround(HORDE); |
|---|
| 157 | } |
|---|
| 158 | else if(!GetAlivePlayersCountByTeam(HORDE)) |
|---|
| 159 | { |
|---|
| 160 | // all opponents killed |
|---|
| 161 | EndBattleGround(ALLIANCE); |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | bool BattleGroundBE::HandlePlayerUnderMap(Player *player) |
|---|
| 166 | { |
|---|
| 167 | player->TeleportTo(GetMapId(),6238.930176,262.963470,0.889519,player->GetOrientation(),false); |
|---|
| 168 | return true; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | void BattleGroundBE::HandleAreaTrigger(Player *Source, uint32 Trigger) |
|---|
| 172 | { |
|---|
| 173 | // this is wrong way to implement these things. On official it done by gameobject spell cast. |
|---|
| 174 | if(GetStatus() != STATUS_IN_PROGRESS) |
|---|
| 175 | return; |
|---|
| 176 | |
|---|
| 177 | //uint32 SpellId = 0; |
|---|
| 178 | //uint64 buff_guid = 0; |
|---|
| 179 | switch(Trigger) |
|---|
| 180 | { |
|---|
| 181 | case 4538: // buff trigger? |
|---|
| 182 | //buff_guid = m_BgObjects[BG_BE_OBJECT_BUFF_1]; |
|---|
| 183 | break; |
|---|
| 184 | case 4539: // buff trigger? |
|---|
| 185 | //buff_guid = m_BgObjects[BG_BE_OBJECT_BUFF_2]; |
|---|
| 186 | break; |
|---|
| 187 | default: |
|---|
| 188 | sLog.outError("WARNING: Unhandled AreaTrigger in Battleground: %u", Trigger); |
|---|
| 189 | Source->GetSession()->SendAreaTriggerMessage("Warning: Unhandled AreaTrigger in Battleground: %u", Trigger); |
|---|
| 190 | break; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | //if(buff_guid) |
|---|
| 194 | // HandleTriggerBuff(buff_guid,Source); |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | void BattleGroundBE::FillInitialWorldStates(WorldPacket &data) |
|---|
| 198 | { |
|---|
| 199 | data << uint32(0x9f1) << uint32(GetAlivePlayersCountByTeam(ALLIANCE)); // 7 |
|---|
| 200 | data << uint32(0x9f0) << uint32(GetAlivePlayersCountByTeam(HORDE)); // 8 |
|---|
| 201 | data << uint32(0x9f3) << uint32(1); // 9 |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | void BattleGroundBE::ResetBGSubclass() |
|---|
| 205 | { |
|---|
| 206 | |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | bool BattleGroundBE::SetupBattleGround() |
|---|
| 210 | { |
|---|
| 211 | // gates |
|---|
| 212 | if( !AddObject(BG_BE_OBJECT_DOOR_1, BG_BE_OBJECT_TYPE_DOOR_1, 6287.277f, 282.1877f, 3.810925f, -2.260201f, 0, 0, 0.9044551f, -0.4265689f, RESPAWN_IMMEDIATELY) |
|---|
| 213 | || !AddObject(BG_BE_OBJECT_DOOR_2, BG_BE_OBJECT_TYPE_DOOR_2, 6189.546f, 241.7099f, 3.101481f, 0.8813917f, 0, 0, 0.4265689f, 0.9044551f, RESPAWN_IMMEDIATELY) |
|---|
| 214 | || !AddObject(BG_BE_OBJECT_DOOR_3, BG_BE_OBJECT_TYPE_DOOR_3, 6299.116f, 296.5494f, 3.308032f, 0.8813917f, 0, 0, 0.4265689f, 0.9044551f, RESPAWN_IMMEDIATELY) |
|---|
| 215 | || !AddObject(BG_BE_OBJECT_DOOR_4, BG_BE_OBJECT_TYPE_DOOR_4, 6177.708f, 227.3481f, 3.604374f, -2.260201f, 0, 0, 0.9044551f, -0.4265689f, RESPAWN_IMMEDIATELY) |
|---|
| 216 | // buffs |
|---|
| 217 | || !AddObject(BG_BE_OBJECT_BUFF_1, BG_BE_OBJECT_TYPE_BUFF_1, 6249.042f, 275.3239f, 11.22033f, -1.448624f, 0, 0, 0.6626201f, -0.7489557f, 120) |
|---|
| 218 | || !AddObject(BG_BE_OBJECT_BUFF_2, BG_BE_OBJECT_TYPE_BUFF_2, 6228.26f, 249.566f, 11.21812f, -0.06981307f, 0, 0, 0.03489945f, -0.9993908f, 120)) |
|---|
| 219 | { |
|---|
| 220 | sLog.outErrorDb("BatteGroundBE: Failed to spawn some object!"); |
|---|
| 221 | return false; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | return true; |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | void BattleGroundBE::UpdatePlayerScore(Player* Source, uint32 type, uint32 value) |
|---|
| 228 | { |
|---|
| 229 | |
|---|
| 230 | std::map<uint64, BattleGroundScore*>::iterator itr = m_PlayerScores.find(Source->GetGUID()); |
|---|
| 231 | |
|---|
| 232 | if(itr == m_PlayerScores.end()) // player not found... |
|---|
| 233 | return; |
|---|
| 234 | |
|---|
| 235 | //there is nothing special in this score |
|---|
| 236 | BattleGround::UpdatePlayerScore(Source,type,value); |
|---|
| 237 | |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | /* |
|---|
| 241 | 21:45:46 id:231310 [S2C] SMSG_INIT_WORLD_STATES (706 = 0x02C2) len: 86 |
|---|
| 242 | 0000: 32 02 00 00 76 0e 00 00 00 00 00 00 09 00 f3 09 | 2...v........... |
|---|
| 243 | 0010: 00 00 01 00 00 00 f1 09 00 00 01 00 00 00 f0 09 | ................ |
|---|
| 244 | 0020: 00 00 02 00 00 00 d4 08 00 00 00 00 00 00 d8 08 | ................ |
|---|
| 245 | 0030: 00 00 00 00 00 00 d7 08 00 00 00 00 00 00 d6 08 | ................ |
|---|
| 246 | 0040: 00 00 00 00 00 00 d5 08 00 00 00 00 00 00 d3 08 | ................ |
|---|
| 247 | 0050: 00 00 00 00 00 00 | ...... |
|---|
| 248 | |
|---|
| 249 | spell 32724 - Gold Team |
|---|
| 250 | spell 32725 - Green Team |
|---|
| 251 | 35774 Gold Team |
|---|
| 252 | 35775 Green Team |
|---|
| 253 | */ |
|---|