TrinityCore
Loading...
Searching...
No Matches
battleground_arathi_basin.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "BattlegroundScript.h"
19#include "Battleground.h"
20#include "BattlegroundMgr.h"
21#include "BattlegroundPackets.h"
22#include "Creature.h"
23#include "GameObject.h"
24#include "GameTime.h"
25#include "Log.h"
26#include "Map.h"
27#include "ScriptMgr.h"
28
30{
31 // Tick intervals and given points: case 0, 1, 2, 3, 4, 5 captured nodes
32 static constexpr uint32 BG_AB_TickInterval = 2000;
33 static constexpr uint32 BG_AB_TickPoints[6] = { 0, 2, 3, 4, 7, 60 };
34 static constexpr uint32 NORMAL_HONOR_TICKS = 160;
35 static constexpr uint32 WEEKEND_HONOR_TICKS = 260;
36 static constexpr uint32 NORMAL_REPUTATION_TICKS = 120;
37 static constexpr uint32 WEEKEND_REPUTATION_TICKS = 160;
38
44
45 enum Events
46 {
47 AB_EVENT_START_BATTLE = 9158, // Achievement: Let's Get This Done
48
55
62
69
76
83 };
84
95
101
107
113
126
128 {
135
136 BG_AB_WS_STABLE_ICON = 1842, // Stable map icon (NONE)
137 BG_AB_WS_STABLE_STATE_ALIENCE = 1767, // Stable map state (ALIENCE)
138 BG_AB_WS_STABLE_STATE_HORDE = 1768, // Stable map state (HORDE)
139 BG_AB_WS_STABLE_STATE_CON_ALI = 1769, // Stable map state (CON ALIENCE)
140 BG_AB_WS_STABLE_STATE_CON_HOR = 1770, // Stable map state (CON HORDE)
141 BG_AB_WS_FARM_ICON = 1845, // Farm map icon (NONE)
142 BG_AB_WS_FARM_STATE_ALIENCE = 1772, // Farm state (ALIENCE)
143 BG_AB_WS_FARM_STATE_HORDE = 1773, // Farm state (HORDE)
144 BG_AB_WS_FARM_STATE_CON_ALI = 1774, // Farm state (CON ALIENCE)
145 BG_AB_WS_FARM_STATE_CON_HOR = 1775, // Farm state (CON HORDE)
146 BG_AB_WS_BLACKSMITH_ICON = 1846, // Blacksmith map icon (NONE)
147 BG_AB_WS_BLACKSMITH_STATE_ALIENCE = 1782, // Blacksmith map state (ALIENCE)
148 BG_AB_WS_BLACKSMITH_STATE_HORDE = 1783, // Blacksmith map state (HORDE)
149 BG_AB_WS_BLACKSMITH_STATE_CON_ALI = 1784, // Blacksmith map state (CON ALIENCE)
150 BG_AB_WS_BLACKSMITH_STATE_CON_HOR = 1785, // Blacksmith map state (CON HORDE)
151 BG_AB_WS_LUMBERMILL_ICON = 1844, // Lumber Mill map icon (NONE)
152 BG_AB_WS_LUMBERMILL_STATE_ALIENCE = 1792, // Lumber Mill map state (ALIENCE)
153 BG_AB_WS_LUMBERMILL_STATE_HORDE = 1793, // Lumber Mill map state (HORDE)
154 BG_AB_WS_LUMBERMILL_STATE_CON_ALI = 1794, // Lumber Mill map state (CON ALIENCE)
155 BG_AB_WS_LUMBERMILL_STATE_CON_HOR = 1795, // Lumber Mill map state (CON HORDE)
156 BG_AB_WS_GOLDMINE_ICON = 1843, // Gold Mine map icon (NONE)
157 BG_AB_WS_GOLDMINE_STATE_ALIENCE = 1787, // Gold Mine map state (ALIENCE)
158 BG_AB_WS_GOLDMINE_STATE_HORDE = 1788, // Gold Mine map state (HORDE)
159 BG_AB_WS_GOLDMINE_STATE_CON_ALI = 1789, // Gold Mine map state (CON ALIENCE
160 BG_AB_WS_GOLDMINE_STATE_CON_HOR = 1790, // Gold Mine map state (CON HORDE)
161
164
165 BG_AB_WS_FARM_ICON_NEW = 8808, // Farm map icon
166 BG_AB_WS_LUMBER_MILL_ICON_NEW = 8805, // Lumber Mill map icon
167 BG_AB_WS_BLACKSMITH_ICON_NEW = 8799, // Blacksmith map icon
168 BG_AB_WS_GOLD_MINE_ICON_NEW = 8809, // Gold Mine map icon
169 BG_AB_WS_STABLES_ICON_NEW = 5834, // Stable map icon
170
181 };
182
184 {
185 bool const isBGWeekend = sBattlegroundMgr->IsBGWeekend(battleground->GetTypeID());
186
189 _honorScoreTics = { { 0, 0 } };
190 _reputationScoreTics = { { 0, 0 } };
191 }
192
200
201 void OnUpdate(uint32 diff) override
202 {
204 return;
205
206 // Accumulate points
207 _lastTick += diff;
209 {
211
212 uint8 ally = 0, horde = 0;
213 _CalculateTeamNodes(ally, horde);
214 uint8 points[PVP_TEAMS_COUNT] = { ally, horde };
215
216 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
217 {
218 if (!points[team])
219 continue;
220
221 battleground->AddPoint(team == TEAM_HORDE ? HORDE : ALLIANCE, BG_AB_TickPoints[points[team]]);
222 _honorScoreTics[team] += BG_AB_TickPoints[points[team]];
223 _reputationScoreTics[team] += BG_AB_TickPoints[points[team]];
224
226 {
229 }
230
231 if (_honorScoreTics[team] >= _honorTics)
232 {
235 }
236
237 const uint32 teamScore = battleground->GetTeamScore(static_cast<TeamId>(team));
239 {
240 if (team == TEAM_ALLIANCE)
241 {
244 }
245 else
246 {
249 }
251 }
252
253 if (teamScore > BG_AB_MAX_TEAM_SCORE)
255
256 if (team == TEAM_ALLIANCE)
258 else
260
261 // update achievement flags
262 // we increased m_TeamScores[team] so we just need to check if it is 500 more than other teams resources
263 uint8 otherTeam = (team + 1) % PVP_TEAMS_COUNT;
264 if (teamScore > battleground->GetTeamScore(static_cast<TeamId>(otherTeam)) + 500)
265 {
266 if (team == TEAM_ALLIANCE)
268 else
270 }
271 }
272
275 }
276
277 // Test win condition
284 }
285
286 void OnStart() override
287 {
288 // Achievement: Let's Get This Done
290 }
291
292 void _CalculateTeamNodes(uint8& alliance, uint8& horde) const
293 {
294 alliance = 0;
295 horde = 0;
296
297 for (ObjectGuid const& guid : _capturePoints)
298 {
299 if (GameObject const* capturePoint = battlegroundMap->GetGameObject(guid))
300 {
301 int32 const wsValue = battlegroundMap->GetWorldStateValue(capturePoint->GetGOInfo()->capturePoint.worldState1);
303 {
305 ++alliance;
306 break;
308 ++horde;
309 break;
310 default:
311 break;
312 }
313 }
314 }
315 }
316
318 {
319 // How many bases each team owns
320 uint8 ally = 0, horde = 0;
321 _CalculateTeamNodes(ally, horde);
322
323 if (ally > horde)
324 return ALLIANCE;
325 if (horde > ally)
326 return HORDE;
327
328 // If the values are equal, fall back to the original result (based on number of players on each team)
330 }
331
332 void ProcessEvent(WorldObject* /*source*/, uint32 eventId, WorldObject* invoker) override
333 {
334 switch (eventId)
335 {
337 {
339 if (Creature* creature = battlegroundMap->GetCreature(guid))
340 creature->DespawnOrUnsummon();
341
343 if (GameObject* gameObject = battlegroundMap->GetGameObject(guid))
344 gameObject->DespawnOrUnsummon();
345
346 for (ObjectGuid const& guid : _doors)
347 {
348 if (GameObject* gameObject = battlegroundMap->GetGameObject(guid))
349 {
350 gameObject->UseDoorOrButton();
351 gameObject->DespawnOrUnsummon(3s);
352 }
353 }
354 break;
355 }
360 if (Player* player = invoker->ToPlayer())
362 break;
367 if (Player* player = invoker->ToPlayer())
369 break;
373 break;
378 if (Player* player = invoker->ToPlayer())
380 break;
385 if (Player* player = invoker->ToPlayer())
387 break;
391 break;
396 if (Player* player = invoker->ToPlayer())
398 break;
403 if (Player* player = invoker->ToPlayer())
405 break;
409 break;
414 if (Player* player = invoker->ToPlayer())
416 break;
421 if (Player* player = invoker->ToPlayer())
423 break;
427 break;
432 if (Player* player = invoker->ToPlayer())
434 break;
439 if (Player* player = invoker->ToPlayer())
441 break;
445 break;
450 if (Player* player = invoker->ToPlayer())
452 break;
457 if (Player* player = invoker->ToPlayer())
459 break;
463 break;
468 if (Player* player = invoker->ToPlayer())
470 break;
475 if (Player* player = invoker->ToPlayer())
477 break;
481 break;
486 if (Player* player = invoker->ToPlayer())
488 break;
493 if (Player* player = invoker->ToPlayer())
495 break;
499 break;
504 if (Player* player = invoker->ToPlayer())
506 break;
511 if (Player* player = invoker->ToPlayer())
513 break;
517 break;
522 if (Player* player = invoker->ToPlayer())
524 break;
529 if (Player* player = invoker->ToPlayer())
531 break;
535 break;
536 default:
537 TC_LOG_WARN("bg.events", "BattlegroundAB::ProcessEvent: Unhandled event %u.", eventId);
538 break;
539 }
540 }
541
542 void OnCreatureCreate(Creature* creature) override
543 {
544 switch (creature->GetEntry())
545 {
548 _creaturesToRemoveOnMatchStart.push_back(creature->GetGUID());
549 break;
550 default:
551 break;
552 }
553 }
554
555 void OnGameObjectCreate(GameObject* gameObject) override
556 {
557 if (gameObject->GetGOInfo()->type == GAMEOBJECT_TYPE_CAPTURE_POINT)
558 _capturePoints.push_back(gameObject->GetGUID());
559
560 switch (gameObject->GetEntry())
561 {
563 _gameobjectsToRemoveOnMatchStart.push_back(gameObject->GetGUID());
564 break;
567 _doors.push_back(gameObject->GetGUID());
568 break;
569 default:
570 break;
571 }
572 }
573
574 void OnEnd(Team winner) override
575 {
577
578 // Win reward
579 if (winner == ALLIANCE)
581 if (winner == HORDE)
583 // Complete map_end rewards (even if no team wins)
586 }
587
588private:
590 std::array<uint32, PVP_TEAMS_COUNT> _honorScoreTics;
591 std::array<uint32, PVP_TEAMS_COUNT> _reputationScoreTics;
595
600};
601
#define sBattlegroundMgr
@ STATUS_IN_PROGRESS
uint8_t uint8
Definition Define.h:156
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
#define TC_LOG_WARN(filterType__, message__,...)
Definition Log.h:187
std::vector< ObjectGuid > GuidVector
Definition ObjectGuid.h:434
#define RegisterBattlegroundMapScript(script_name, mapId)
Definition ScriptMgr.h:1447
@ GAMEOBJECT_TYPE_CAPTURE_POINT
@ TEAM_ALLIANCE
@ TEAM_HORDE
uint8 constexpr PVP_TEAMS_COUNT
@ TEAM_OTHER
@ ALLIANCE
@ HORDE
@ CHAT_MSG_BG_SYSTEM_NEUTRAL
void AddSC_battleground_arathi_basin()
ObjectGuid const & GetGUID() const
Definition BaseEntity.h:163
Battleground * battleground
void TriggerGameEvent(uint32 gameEventId, WorldObject *source=nullptr, WorldObject *target=nullptr) override
BattlegroundMap * battlegroundMap
virtual void OnEnd(Team winner)
virtual Team GetPrematureWinner()
void UpdateWorldState(int32 worldStateId, int32 value, bool hidden=false) const
void PlaySoundToAll(uint32 SoundID)
uint32 GetTeamScore(TeamId teamId) const
void RewardHonorToTeam(uint32 Honor, Team team)
BattlegroundTypeId GetTypeID() const
virtual void EndBattleground(Team winner)
void SendBroadcastText(uint32 id, ChatMsg msgType, WorldObject const *target=nullptr)
void RewardReputationToTeam(uint32 faction_id, uint32 Reputation, Team team)
BattlegroundStatus GetStatus() const
void AddPoint(Team team, uint32 points=1)
void SetTeamPoint(Team team, uint32 points=0)
uint32 GetBonusHonorFromKill(uint32 kills) const
void UpdatePvpStat(Player *player, uint32 pvpStatId, uint32 value)
GameObjectTemplate const * GetGOInfo() const
Definition GameObject.h:203
int32 GetWorldStateValue(int32 worldStateId) const
Definition Map.cpp:427
GameObject * GetGameObject(ObjectGuid const &guid)
Definition Map.cpp:3552
Creature * GetCreature(ObjectGuid const &guid)
Definition Map.cpp:3542
Player * ToPlayer()
Definition Object.h:126
uint32 GetEntry() const
Definition Object.h:89
void ProcessEvent(WorldObject *, uint32 eventId, WorldObject *invoker) override
static constexpr uint32 BG_AB_TickInterval
battleground_arathi_basin(BattlegroundMap *map)
void OnCreatureCreate(Creature *creature) override
std::array< uint32, PVP_TEAMS_COUNT > _reputationScoreTics
static constexpr uint32 WEEKEND_REPUTATION_TICKS
void _CalculateTeamNodes(uint8 &alliance, uint8 &horde) const
static constexpr uint32 WEEKEND_HONOR_TICKS
static constexpr uint32 NORMAL_HONOR_TICKS
static constexpr uint32 BG_AB_TickPoints[6]
static constexpr uint32 NORMAL_REPUTATION_TICKS
void OnUpdate(uint32 diff) override
std::array< uint32, PVP_TEAMS_COUNT > _honorScoreTics
void OnGameObjectCreate(GameObject *gameObject) override