TrinityCore
BattlegroundAB.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 "BattlegroundAB.h"
19#include "BattlegroundMgr.h"
20#include "BattlegroundPackets.h"
21#include "BattlegroundScore.h"
22#include "Creature.h"
23#include "GameObject.h"
24#include "Log.h"
25#include "Map.h"
26#include "ObjectMgr.h"
27#include "Player.h"
28#include "SpellInfo.h"
29
31{
34};
35
36BattlegroundAB::BattlegroundAB(BattlegroundTemplate const* battlegroundTemplate) : Battleground(battlegroundTemplate)
37{
39 BgObjects.resize(0);
40 BgCreatures.resize(0);
41 m_lastTick = 0;
42
43 for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
44 {
45 m_HonorScoreTics[i] = 0;
47 }
48
49 m_HonorTics = 0;
51}
52
54
56{
58 {
59 // Accumulate points
60 m_lastTick += diff;
62 {
64
65 uint8 ally = 0, horde = 0;
66 _CalculateTeamNodes(ally, horde);
67 uint8 points[PVP_TEAMS_COUNT] = { ally, horde };
68
69 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
70 {
71 if (!points[team])
72 continue;
73
74 m_TeamScores[team] += BG_AB_TickPoints[points[team]];
75 m_HonorScoreTics[team] += BG_AB_TickPoints[points[team]];
76 m_ReputationScoreTics[team] += BG_AB_TickPoints[points[team]];
77
79 {
82 }
83
84 if (m_HonorScoreTics[team] >= m_HonorTics)
85 {
88 }
89
91 {
92 if (team == TEAM_ALLIANCE)
93 {
96 }
97 else
98 {
101 }
103 }
104
107
108 if (team == TEAM_ALLIANCE)
110 else
112 // update achievement flags
113 // we increased m_TeamScores[team] so we just need to check if it is 500 more than other teams resources
114 uint8 otherTeam = (team + 1) % PVP_TEAMS_COUNT;
115 if (m_TeamScores[team] > m_TeamScores[otherTeam] + 500)
116 {
117 if (team == TEAM_ALLIANCE)
119 else
121 }
122 }
123
126 }
127
128 // Test win condition
133 }
134}
135
137{
138 // Achievement: Let's Get This Done
140}
141
143{
144 alliance = 0;
145 horde = 0;
146
147 if (BattlegroundMap* map = FindBgMap())
148 {
149 for (ObjectGuid const& guid : _capturePoints)
150 {
151 if (GameObject* capturePoint = map->GetGameObject(guid))
152 {
153 int32 wsValue = map->GetWorldStateValue(capturePoint->GetGOInfo()->capturePoint.worldState1);
155 {
157 ++alliance;
158 break;
160 ++horde;
161 break;
162 default:
163 break;
164 }
165 }
166 }
167 }
168}
169
171{
172 // How many bases each team owns
173 uint8 ally = 0, horde = 0;
174 _CalculateTeamNodes(ally, horde);
175
176 if (ally > horde)
177 return ALLIANCE;
178 else if (horde > ally)
179 return HORDE;
180
181 // If the values are equal, fall back to the original result (based on number of players on each team)
183}
184
185void BattlegroundAB::ProcessEvent(WorldObject* /*source*/, uint32 eventId, WorldObject* invoker)
186{
187 switch (eventId)
188 {
190 {
192 if (Creature* creature = GetBgMap()->GetCreature(guid))
193 creature->DespawnOrUnsummon();
194
196 if (GameObject* gameObject = GetBgMap()->GetGameObject(guid))
197 gameObject->DespawnOrUnsummon();
198
199 for (ObjectGuid const& guid : _doors)
200 {
201 if (GameObject* gameObject = GetBgMap()->GetGameObject(guid))
202 {
203 gameObject->UseDoorOrButton();
204 gameObject->DespawnOrUnsummon(3s);
205 }
206 }
207 break;
208 }
213 if (Player* player = invoker->ToPlayer())
215 break;
220 if (Player* player = invoker->ToPlayer())
222 break;
226 break;
231 if (Player* player = invoker->ToPlayer())
233 break;
238 if (Player* player = invoker->ToPlayer())
240 break;
244 break;
249 if (Player* player = invoker->ToPlayer())
251 break;
256 if (Player* player = invoker->ToPlayer())
258 break;
262 break;
267 if (Player* player = invoker->ToPlayer())
269 break;
274 if (Player* player = invoker->ToPlayer())
276 break;
280 break;
285 if (Player* player = invoker->ToPlayer())
287 break;
292 if (Player* player = invoker->ToPlayer())
294 break;
298 break;
303 if (Player* player = invoker->ToPlayer())
305 break;
310 if (Player* player = invoker->ToPlayer())
312 break;
316 break;
321 if (Player* player = invoker->ToPlayer())
323 break;
328 if (Player* player = invoker->ToPlayer())
330 break;
334 break;
339 if (Player* player = invoker->ToPlayer())
341 break;
346 if (Player* player = invoker->ToPlayer())
348 break;
352 break;
357 if (Player* player = invoker->ToPlayer())
359 break;
364 if (Player* player = invoker->ToPlayer())
366 break;
370 break;
375 if (Player* player = invoker->ToPlayer())
377 break;
382 if (Player* player = invoker->ToPlayer())
384 break;
388 break;
389 default:
390 TC_LOG_WARN("bg.events", "BattlegroundAB::ProcessEvent: Unhandled event %u.", eventId);
391 break;
392 }
393}
394
396{
397 switch (creature->GetEntry())
398 {
401 _creaturesToRemoveOnMatchStart.push_back(creature->GetGUID());
402 break;
403 default:
404 break;
405 }
406}
407
409{
410 if (gameObject->GetGOInfo()->type == GAMEOBJECT_TYPE_CAPTURE_POINT)
411 _capturePoints.push_back(gameObject->GetGUID());
412
413 switch (gameObject->GetEntry())
414 {
416 _gameobjectsToRemoveOnMatchStart.push_back(gameObject->GetGUID());
417 break;
420 _doors.push_back(gameObject->GetGUID());
421 break;
422 default:
423 break;
424 }
425}
426
428{
431
432 return true;
433}
434
436{
437 //call parent's class reset
439
442 m_lastTick = 0;
448 bool isBGWeekend = sBattlegroundMgr->IsBGWeekend(GetTypeID());
451
454 _doors.clear();
455 _capturePoints.clear();
456}
457
459{
460 // Win reward
461 if (winner == ALLIANCE)
463 if (winner == HORDE)
465 // Complete map_end rewards (even if no team wins)
468
470}
471
473{
474 return sObjectMgr->GetClosestGraveyard(player->GetWorldLocation(), player->GetTeam(), player);
475}
476
478{
480}
ArathiBasinPvpStats
@ PVP_STAT_BASES_DEFENDED
@ PVP_STAT_BASES_ASSAULTED
#define BG_AB_ABBGWeekendReputationTicks
@ AB_EXPLOIT_TELEPORT_LOCATION_ALLIANCE
@ AB_EXPLOIT_TELEPORT_LOCATION_HORDE
const uint32 BG_AB_TickPoints[6]
@ BG_AB_NPC_THE_BLACK_BRIDE
@ BG_AB_NPC_RADULF_LEDER
@ BG_AB_TEXT_ALLIANCE_NEAR_VICTORY
@ BG_AB_TEXT_HORDE_NEAR_VICTORY
const uint32 BG_AB_TickInterval
@ AB_EVENT_CONTESTED_FARM_HORDE
@ AB_EVENT_CAPTURE_STABLES_HORDE
@ AB_EVENT_CONTESTED_GOLD_MINE_ALLIANCE
@ AB_EVENT_CAPTURE_BLACKSMITH_HORDE
@ AB_EVENT_CONTESTED_BLACKSMITH_HORDE
@ AB_EVENT_CAPTURE_GOLD_MINE_ALLIANCE
@ AB_EVENT_DEFENDED_LUMBER_MILL_ALLIANCE
@ AB_EVENT_CAPTURE_FARM_HORDE
@ AB_EVENT_DEFENDED_STABLES_HORDE
@ AB_EVENT_DEFENDED_BLACKSMITH_HORDE
@ AB_EVENT_CAPTURE_FARM_ALLIANCE
@ AB_EVENT_CONTESTED_LUMBER_MILL_HORDE
@ AB_EVENT_CONTESTED_STABLES_HORDE
@ AB_EVENT_CONTESTED_GOLD_MINE_HORDE
@ AB_EVENT_DEFENDED_FARM_HORDE
@ AB_EVENT_CONTESTED_LUMBER_MILL_ALLIANCE
@ AB_EVENT_CONTESTED_BLACKSMITH_ALLIANCE
@ AB_EVENT_CAPTURE_LUMBER_MILL_ALLIANCE
@ AB_EVENT_CONTESTED_FARM_ALLIANCE
@ AB_EVENT_DEFENDED_STABLES_ALLIANCE
@ AB_EVENT_DEFENDED_BLACKSMITH_ALLIANCE
@ AB_EVENT_CONTESTED_STABLES_ALLIANCE
@ AB_EVENT_DEFENDED_FARM_ALLIANCE
@ AB_EVENT_DEFENDED_GOLD_MINE_ALLIANCE
@ AB_EVENT_DEFENDED_GOLD_MINE_HORDE
@ AB_EVENT_CAPTURE_STABLES_ALLIANCE
@ AB_EVENT_CAPTURE_GOLD_MINE_HORDE
@ AB_EVENT_START_BATTLE
@ AB_EVENT_CAPTURE_BLACKSMITH_ALLIANCE
@ AB_EVENT_DEFENDED_LUMBER_MILL_HORDE
@ AB_EVENT_CAPTURE_LUMBER_MILL_HORDE
@ BG_AB_OBJECTID_GHOST_GATE
@ BG_AB_OBJECTID_ALLIANCE_DOOR
@ BG_AB_OBJECTID_HORDE_DOOR
#define BG_AB_NotABBGWeekendReputationTicks
#define BG_AB_NotABBGWeekendHonorTicks
#define BG_AB_ABBGWeekendHonorTicks
@ BG_AB_WS_HAD_500_DISADVANTAGE_ALLIANCE
@ BG_AB_WS_STABLES_HORDE_CONTROL_STATE
@ BG_AB_WS_LUMBER_MILL_HORDE_CONTROL_STATE
@ BG_AB_WS_LUMBER_MILL_ALLIANCE_CONTROL_STATE
@ BG_AB_WS_GOLD_MINE_ALLIANCE_CONTROL_STATE
@ BG_AB_WS_HAD_500_DISADVANTAGE_HORDE
@ BG_AB_WS_GOLD_MINE_HORDE_CONTROL_STATE
@ BG_AB_WS_FARM_ALLIANCE_CONTROL_STATE
@ BG_AB_WS_RESOURCES_HORDE
@ BG_AB_WS_FARM_HORDE_CONTROL_STATE
@ BG_AB_WS_RESOURCES_ALLY
@ BG_AB_WS_BLACKSMITH_HORDE_CONTROL_STATE
@ BG_AB_WS_OCCUPIED_BASES_HORDE
@ BG_AB_WS_RESOURCES_MAX
@ BG_AB_WS_STABLES_ALLIANCE_CONTROL_STATE
@ BG_AB_WS_RESOURCES_WARNING
@ BG_AB_WS_OCCUPIED_BASES_ALLY
@ BG_AB_WS_BLACKSMITH_ALLIANCE_CONTROL_STATE
@ BG_AB_WARNING_NEAR_VICTORY_SCORE
@ BG_AB_MAX_TEAM_SCORE
@ BG_AB_SOUND_NEAR_VICTORY_ALLIANCE
@ BG_AB_SOUND_NODE_CAPTURED_HORDE
@ BG_AB_SOUND_NODE_ASSAULTED_ALLIANCE
@ BG_AB_SOUND_NODE_ASSAULTED_HORDE
@ BG_AB_SOUND_NEAR_VICTORY_HORDE
@ BG_AB_SOUND_NODE_CAPTURED_ALLIANCE
#define sBattlegroundMgr
@ STATUS_IN_PROGRESS
Definition: Battleground.h:167
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
#define TC_LOG_WARN(filterType__,...)
Definition: Log.h:162
#define sObjectMgr
Definition: ObjectMgr.h:1946
@ GAMEOBJECT_TYPE_CAPTURE_POINT
@ TEAM_ALLIANCE
@ TEAM_HORDE
uint8 constexpr PVP_TEAMS_COUNT
Team
@ ALLIANCE
@ HORDE
@ CHAT_MSG_BG_SYSTEM_NEUTRAL
WorldSafeLocsEntry const * GetClosestGraveyard(Player *player) override
void StartingEventOpenDoors() override
GuidVector _capturePoints
GuidVector _creaturesToRemoveOnMatchStart
bool SetupBattleground() override
uint32 m_ReputationTics
void EndBattleground(Team winner) override
void OnCreatureCreate(Creature *creature) override
void Reset() override
GuidVector _doors
uint32 m_HonorScoreTics[PVP_TEAMS_COUNT]
GuidVector _gameobjectsToRemoveOnMatchStart
bool m_IsInformedNearVictory
void ProcessEvent(WorldObject *obj, uint32 eventId, WorldObject *invoker=nullptr) override
BattlegroundAB(BattlegroundTemplate const *battlegroundTemplate)
uint32 m_ReputationScoreTics[PVP_TEAMS_COUNT]
void PostUpdateImpl(uint32 diff) override
Post-update hook.
WorldSafeLocsEntry const * GetExploitTeleportLocation(Team team) override
Team GetPrematureWinner() override
void _CalculateTeamNodes(uint8 &alliance, uint8 &horde)
void OnGameObjectCreate(GameObject *gameObject) override
virtual Team GetPrematureWinner()
virtual void Reset()
void PlaySoundToAll(uint32 SoundID)
GuidVector BgObjects
Definition: Battleground.h:443
void RewardHonorToTeam(uint32 Honor, Team team)
BattlegroundMap * GetBgMap() const
BattlegroundMap * FindBgMap() const
Definition: Battleground.h:351
BattlegroundTypeId GetTypeID() const
void TriggerGameEvent(uint32 gameEventId, WorldObject *source=nullptr, WorldObject *target=nullptr) override
int32 m_TeamScores[PVP_TEAMS_COUNT]
Definition: Battleground.h:565
GuidVector BgCreatures
Definition: Battleground.h:444
void UpdateWorldState(int32 worldStateId, int32 value, bool hidden=false)
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
Definition: Battleground.h:284
uint32 GetBonusHonorFromKill(uint32 kills) const
void UpdatePvpStat(Player *player, uint32 pvpStatId, uint32 value)
GameObjectTemplate const * GetGOInfo() const
Definition: GameObject.h:202
uint32 GetEntry() const
Definition: Object.h:161
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:159
static Player * ToPlayer(Object *o)
Definition: Object.h:213
Team GetTeam() const
Definition: Player.h:2235
constexpr WorldLocation GetWorldLocation() const
Definition: Position.h:196
TC_GAME_API GameObject * GetGameObject(WorldObject const &u, ObjectGuid const &guid)
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)