TrinityCore
Loading...
Searching...
No Matches
battleground_battle_for_gilneas.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 "Battleground.h"
19#include "BattlegroundPackets.h"
20#include "BattlegroundScript.h"
21#include "GameObject.h"
22#include "Map.h"
23#include "Player.h"
24#include "ScriptMgr.h"
25#include "Timer.h"
26
28{
29 namespace GameObjects
30 {
31 static constexpr uint32 CapturePointLighthouse = 228050;
32 static constexpr uint32 CapturePointWaterworks = 228052;
33 static constexpr uint32 CapturePointMines = 228053;
34
35 static constexpr uint32 AllianceDoor = 207177;
36 static constexpr uint32 HordeGate1 = 207178;
37 static constexpr uint32 HordeGate2 = 205495;
38 static constexpr uint32 AllianceGate = 205496;
39 }
40
41 namespace PvpStats
42 {
43 static constexpr uint32 BasesAssaulted = 370;
44 static constexpr uint32 BasesDefended = 371;
45 }
46
47 namespace Sounds
48 {
49 static constexpr uint32 PvpFlagTakenAlliance = 8174;
50 static constexpr uint32 PvpFlagCapturedAlliance = 8173;
51 static constexpr uint32 PvpFlagCapturedHorde = 8213;
52 static constexpr uint32 PvpFlagTakenHorde = 8212;
53 }
54
55 namespace WorldStates
56 {
57 static constexpr uint32 OccupiedBasesHorde = 1778;
58 static constexpr uint32 OccupiedBasesAlliance = 1779;
59 static constexpr uint32 ResourcesAlliance = 1776;
60 static constexpr uint32 ResourcesHorde = 1777;
61
62 static constexpr uint32 HadResourceDisadvantageAlliance = 3645;
63 static constexpr uint32 HadResourceDisadvantageHorde = 3644;
64
65 static constexpr uint32 HordeLighthouse = 17355;
66 static constexpr uint32 AllianceLighthouse = 17356;
67 static constexpr uint32 HordeWaterworks = 17358;
68 static constexpr uint32 AllianceWaterworks = 17357;
69 static constexpr uint32 HordeMines = 17360;
70 static constexpr uint32 AllianceMines = 17359;
71 }
72
73 namespace Texts
74 {
75 static constexpr uint32 AllianceNearVictory = 10598;
76 static constexpr uint32 HordeNearVictory = 10599;
77 }
78
79 namespace Events
80 {
81 static constexpr uint32 StartBattle = 35912;
82 }
83}
84
86{
87 // 0 - uncontrolled, 1 - partially controlled, 2 - fully controlled
90};
91
93{
94 static constexpr uint32 TICK_POINTS[4] = { 0, 1, 3, 30 };
95
96 static constexpr uint32 WARNING_NEAR_VICTORY_SCORE = 1200;
97 static constexpr uint32 MAX_TEAM_SCORE = 1500;
98
108
109 void OnUpdate(uint32 diff) override
110 {
112 return;
113
114 // Accumulate points
115 _tickTracker.Update(diff);
116 if (_tickTracker.Passed())
117 {
119
120 uint8 ally = 0, horde = 0;
121 CalculateTeamNodes(ally, horde);
122 uint8 const points[PVP_TEAMS_COUNT] = { ally, horde };
123
124 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
125 {
126 if (!points[team])
127 continue;
128
129 battleground->AddPoint(team == TEAM_HORDE ? HORDE : ALLIANCE, TICK_POINTS[points[team]]);
130
131 const uint32 teamScore = battleground->GetTeamScore(static_cast<TeamId>(team));
132 if (!_isInformedNearVictory[team] && teamScore > WARNING_NEAR_VICTORY_SCORE)
133 {
134 if (team == TEAM_ALLIANCE)
136 else
138
139 _isInformedNearVictory[team] = true;
140 }
141
142 if (teamScore > MAX_TEAM_SCORE)
144
145 if (team == TEAM_ALLIANCE)
147 else
149
150 // update achievement flags
151 // we increased m_TeamScores[team] so we just need to check if it is 500 more than other teams resources
152 TeamId const otherTeamId = GetOtherTeam(static_cast<TeamId>(team));
153 if (teamScore > battleground->GetTeamScore(otherTeamId) + 500)
154 {
155 if (team == TEAM_ALLIANCE)
157 else
159 }
160 }
161
164 }
165
166 // Test win condition
173 }
174
175 void OnStart() override
176 {
178 for (ObjectGuid const& guid : _doors)
179 {
180 if (GameObject* gameObject = battlegroundMap->GetGameObject(guid))
181 {
182 gameObject->UseDoorOrButton();
183 gameObject->DespawnOrUnsummon(3s);
184 }
185 }
186 }
187
188 void ProcessEvent(WorldObject* source, uint32 eventId, WorldObject* invoker) override
189 {
190 if (GameObject const* capturePoint = Object::ToGameObject(source))
191 {
192 if (capturePoint->GetGoType() != GAMEOBJECT_TYPE_CAPTURE_POINT)
193 return;
194
195 if (capturePoint->GetGOInfo()->capturePoint.ContestedEventAlliance == eventId || capturePoint->GetGOInfo()->capturePoint.ContestedEventHorde == eventId)
196 HandleAssaultPoint(capturePoint, Object::ToPlayer(invoker));
197 else if (capturePoint->GetGOInfo()->capturePoint.DefendedEventAlliance == eventId || capturePoint->GetGOInfo()->capturePoint.DefendedEventHorde == eventId)
198 HandleDefendPoint(capturePoint, Object::ToPlayer(invoker));
199 else if (capturePoint->GetGOInfo()->capturePoint.CaptureEventAlliance == eventId)
200 HandleCapturePoint(capturePoint, TEAM_ALLIANCE);
201 else if (capturePoint->GetGOInfo()->capturePoint.CaptureEventHorde == eventId)
202 HandleCapturePoint(capturePoint, TEAM_HORDE);
203 }
204 }
205
206 void HandleAssaultPoint(GameObject const* capturePoint, Player* player)
207 {
208 if (!player)
209 return;
210
211 Team const team = battleground->GetPlayerTeam(player->GetGUID());
212 if (team == ALLIANCE)
213 {
214 UpdateWorldState(_capturePointData[capturePoint->GetEntry()].WorldStateAllianceControlState, 1);
215 UpdateWorldState(_capturePointData[capturePoint->GetEntry()].WorldStateHordeControlState, 0);
217 }
218 else if (team == HORDE)
219 {
220 UpdateWorldState(_capturePointData[capturePoint->GetEntry()].WorldStateAllianceControlState, 0);
221 UpdateWorldState(_capturePointData[capturePoint->GetEntry()].WorldStateHordeControlState, 1);
223 }
224
226 }
227
228 void HandleDefendPoint(GameObject const* capturePoint, Player* player)
229 {
230 if (!player)
231 return;
232
233 Team const team = battleground->GetPlayerTeam(player->GetGUID());
234 if (team == ALLIANCE)
235 {
236 UpdateWorldState(_capturePointData[capturePoint->GetEntry()].WorldStateAllianceControlState, 2);
237 UpdateWorldState(_capturePointData[capturePoint->GetEntry()].WorldStateHordeControlState, 0);
239 }
240 else if (team == HORDE)
241 {
242 UpdateWorldState(_capturePointData[capturePoint->GetEntry()].WorldStateAllianceControlState, 0);
243 UpdateWorldState(_capturePointData[capturePoint->GetEntry()].WorldStateHordeControlState, 2);
245 }
246
248 }
249
250 void HandleCapturePoint(GameObject const* capturePoint, TeamId const teamId)
251 {
252 if (teamId == TEAM_ALLIANCE)
253 {
254 UpdateWorldState(_capturePointData[capturePoint->GetEntry()].WorldStateAllianceControlState, 2);
255 UpdateWorldState(_capturePointData[capturePoint->GetEntry()].WorldStateHordeControlState, 0);
257 }
258 else if (teamId == TEAM_HORDE)
259 {
260 UpdateWorldState(_capturePointData[capturePoint->GetEntry()].WorldStateAllianceControlState, 0);
261 UpdateWorldState(_capturePointData[capturePoint->GetEntry()].WorldStateHordeControlState, 2);
263 }
264 }
265
266 void CalculateTeamNodes(uint8& alliance, uint8& horde) const
267 {
268 alliance = 0;
269 horde = 0;
270
271 for (ObjectGuid const& guid : _capturePoints)
272 {
273 if (GameObject const* capturePoint = battlegroundMap->GetGameObject(guid))
274 {
275 int32 const wsValue = battlegroundMap->GetWorldStateValue(capturePoint->GetGOInfo()->capturePoint.worldState1);
277 {
279 ++alliance;
280 break;
282 ++horde;
283 break;
284 default:
285 break;
286 }
287 }
288 }
289 }
290
291 void OnGameObjectCreate(GameObject* gameobject) override
292 {
293 if (gameobject->GetGoType() == GAMEOBJECT_TYPE_CAPTURE_POINT)
294 _capturePoints.emplace_back(gameobject->GetGUID());
295
296 switch (gameobject->GetEntry())
297 {
302 _doors.emplace_back(gameobject->GetGUID());
303 break;
304 default:
305 break;
306 }
307 }
308
309private:
313 std::array<bool, PVP_TEAMS_COUNT> _isInformedNearVictory;
314 std::unordered_map<uint32, BattleForGilneasCapturePointData> _capturePointData;
315};
316
@ STATUS_IN_PROGRESS
uint8_t uint8
Definition Define.h:156
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
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
constexpr TeamId GetOtherTeam(TeamId team)
uint8 constexpr PVP_TEAMS_COUNT
@ TEAM_OTHER
@ ALLIANCE
@ HORDE
@ CHAT_MSG_BG_SYSTEM_NEUTRAL
void AddSC_battleground_battle_for_gilneas()
Sounds
ObjectGuid const & GetGUID() const
Definition BaseEntity.h:163
Battleground * battleground
void TriggerGameEvent(uint32 gameEventId, WorldObject *source=nullptr, WorldObject *target=nullptr) override
BattlegroundMap * battlegroundMap
void UpdateWorldState(int32 worldStateId, int32 value, bool hidden=false) const
void PlaySoundToAll(uint32 SoundID)
uint32 GetTeamScore(TeamId teamId) const
virtual void EndBattleground(Team winner)
void SendBroadcastText(uint32 id, ChatMsg msgType, WorldObject const *target=nullptr)
BattlegroundStatus GetStatus() const
void AddPoint(Team team, uint32 points=1)
Team GetPlayerTeam(ObjectGuid guid) const
void SetTeamPoint(Team team, uint32 points=0)
void UpdatePvpStat(Player *player, uint32 pvpStatId, uint32 value)
GameobjectTypes GetGoType() const
Definition GameObject.h:282
int32 GetWorldStateValue(int32 worldStateId) const
Definition Map.cpp:427
GameObject * GetGameObject(ObjectGuid const &guid)
Definition Map.cpp:3552
Player * ToPlayer()
Definition Object.h:126
GameObject * ToGameObject()
Definition Object.h:131
uint32 GetEntry() const
Definition Object.h:89
static constexpr uint32 PvpFlagCapturedAlliance
void Update(int32 diff)
Definition Timer.h:121
bool Passed() const
Definition Timer.h:131
void Reset(int32 expiry)
Definition Timer.h:136
void HandleAssaultPoint(GameObject const *capturePoint, Player *player)
void HandleCapturePoint(GameObject const *capturePoint, TeamId const teamId)
void ProcessEvent(WorldObject *source, uint32 eventId, WorldObject *invoker) override
void CalculateTeamNodes(uint8 &alliance, uint8 &horde) const
void OnGameObjectCreate(GameObject *gameobject) override
void HandleDefendPoint(GameObject const *capturePoint, Player *player)
std::unordered_map< uint32, BattleForGilneasCapturePointData > _capturePointData
std::array< bool, PVP_TEAMS_COUNT > _isInformedNearVictory