TrinityCore
OutdoorPvPTF.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 "GameObject.h"
19#include "Map.h"
20#include "ObjectAccessor.h"
21#include "OutdoorPvPTF.h"
22#include "Player.h"
23#include "ScriptMgr.h"
24#include "WorldStatePackets.h"
25
28{
29 3519 /*Terokkar Forest*/,
30 3791 /*Sethekk Halls*/,
31 3789 /*Shadow Labyrinth*/,
32 3792 /*Mana-Tombs*/,
33 3790 /*Auchenai Crypts*/
34};
35
36// locked for 6 hours after capture
37uint32 const TF_LOCK_TIME = 3600 * 6 * 1000;
38
39// update lock timer every 1/4 minute (overkill, but this way it's sure the timer won't "jump" 2 minutes at once.)
41
42// blessing of auchindoun, used in TeamCastSpell which uses signed int, so signed
43int32 const TF_CAPTURE_BUFF = 33377;
44
45uint32 const TF_ALLY_QUEST = 11505;
46uint32 const TF_HORDE_QUEST = 11506;
47
49{
51 m_IsLocked = false;
56 hours_left = 6;
57 second_digit = 0;
58 first_digit = 0;
59
60 ControlZoneHandlers[TF_ENTRY_TOWER_NW] = std::make_unique<TFControlZoneHandler>(this, 2682, 2683, 2681);
61 ControlZoneHandlers[TF_ENTRY_TOWER_N] = std::make_unique<TFControlZoneHandler>(this, 2685, 2684, 2686);
62 ControlZoneHandlers[TF_ENTRY_TOWER_NE] = std::make_unique<TFControlZoneHandler>(this, 2689, 2688, 2690);
63 ControlZoneHandlers[TF_ENTRY_TOWER_SE] = std::make_unique<TFControlZoneHandler>(this, 2695, 2694, 2696);
64 ControlZoneHandlers[TF_ENTRY_TOWER_S] = std::make_unique<TFControlZoneHandler>(this, 2692, 2691, 2693);
65}
66
68{
70 initWorldStates.MapID = player->GetMapId();
71 initWorldStates.AreaID = player->GetZoneId();
72 initWorldStates.SubareaID = player->GetAreaId();
73 initWorldStates.Worldstates.emplace_back(TF_UI_TOWER_COUNT_H, 0);
74 initWorldStates.Worldstates.emplace_back(TF_UI_TOWER_COUNT_A, 0);
75 initWorldStates.Worldstates.emplace_back(TF_UI_TOWERS_CONTROLLED_DISPLAY, 0);
76
77 initWorldStates.Worldstates.emplace_back(TF_UI_LOCKED_TIME_MINUTES_FIRST_DIGIT, 0);
78 initWorldStates.Worldstates.emplace_back(TF_UI_LOCKED_TIME_MINUTES_SECOND_DIGIT, 0);
79 initWorldStates.Worldstates.emplace_back(TF_UI_LOCKED_TIME_HOURS, 0);
80
81 initWorldStates.Worldstates.emplace_back(TF_UI_LOCKED_DISPLAY_NEUTRAL, 0);
82 initWorldStates.Worldstates.emplace_back(TF_UI_LOCKED_DISPLAY_HORDE, 0);
83 initWorldStates.Worldstates.emplace_back(TF_UI_LOCKED_DISPLAY_ALLIANCE, 0);
84
85 for (auto& itr : ControlZoneHandlers)
86 {
87 TFControlZoneHandler* handler = static_cast<TFControlZoneHandler*>(itr.second.get());
88 initWorldStates.Worldstates.emplace_back(handler->GetWorldStateNeutral(), 0);
89 initWorldStates.Worldstates.emplace_back(handler->GetWorldStateHorde(), 0);
90 initWorldStates.Worldstates.emplace_back(handler->GetWorldStateAlliance(), 0);
91 }
92
93 player->SendDirectMessage(initWorldStates.Write());
94}
95
97{
99
100 if (m_IsLocked)
101 {
102 // lock timer is down, release lock
103 if (m_LockTimer < diff)
104 {
107 m_IsLocked = false;
108
109 for (ObjectGuid const& controlZoneGUID : _controlZoneGUIDs)
110 {
111 if (GameObject* gameObject = GetMap()->GetGameObject(controlZoneGUID))
112 {
113 gameObject->HandleCustomTypeCommand(GameObjectType::SetControlZoneValue());
114 gameObject->ActivateObject(GameObjectActions::MakeActive, 0);
115 }
116 }
117
122 }
123 else
124 {
125 // worldstateui update timer is down, update ui with new time data
126 if (m_LockTimerUpdate < diff)
127 {
129 uint32 minutes_left = m_LockTimer / 60000;
130 hours_left = minutes_left / 60;
131 minutes_left -= hours_left * 60;
132 second_digit = minutes_left % 10;
133 first_digit = minutes_left / 10;
134
138 } else m_LockTimerUpdate -= diff;
139 m_LockTimer -= diff;
140 }
141 }
142}
143
145{
146 if (player->GetTeam() == ALLIANCE)
147 {
149 player->CastSpell(player, TF_CAPTURE_BUFF, true);
150 }
151 else
152 {
154 player->CastSpell(player, TF_CAPTURE_BUFF, true);
155 }
157}
158
160{
161 // remove buffs
164}
165
167{
169}
170
172{
174}
175
177{
179}
180
182{
184}
185
187{
188 return m_IsLocked;
189}
190
192{
193 OutdoorPvP::ProcessEvent(obj, eventId, invoker);
194
197
198 // now check if everything is capped
203 else
204 {
207 }
208}
209
211{
212 m_IsLocked = true;
213
214 for (ObjectGuid const& controlZoneGUID : _controlZoneGUIDs)
215 if (GameObject* gameObject = GetMap()->GetGameObject(controlZoneGUID))
216 gameObject->ActivateObject(GameObjectActions::MakeInert, 0);
217
223}
224
226{
229
230 m_IsLocked = false;
233 hours_left = 6;
234 second_digit = 0;
235 first_digit = 0;
236
237 // add the zones affected by the pvp buff
238 for (uint8 i = 0; i < OutdoorPvPTFBuffZonesNum; ++i)
240
241 return true;
242}
243
245{
246 switch (go->GetEntry())
247 {
249 case TF_ENTRY_TOWER_N:
252 case TF_ENTRY_TOWER_S:
253 _controlZoneGUIDs.insert(go->GetGUID());
254 break;
255 default:
256 break;
257 }
258
260}
261
262TFControlZoneHandler::TFControlZoneHandler(OutdoorPvPTF* pvp, uint32 worldstateHorde, uint32 worldstateAlliance, uint32 worldstateNeutral) : OutdoorPvPControlZoneHandler(pvp),
263_worldstateHorde(worldstateHorde), _worldstateAlliance(worldstateAlliance), _worldstateNeutral(worldstateNeutral)
264{
265}
266
268{
269 controlZone->SetGoArtKit(1);
270 GetOutdoorPvPTF()->SetHordeTowersControlled(GetOutdoorPvPTF()->GetHordeTowersControlled() + 1);
272 controlZone->GetMap()->SetWorldStateValue(_worldstateHorde, 1, false);
273 controlZone->GetMap()->SetWorldStateValue(_worldstateAlliance, 0, false);
274 controlZone->GetMap()->SetWorldStateValue(_worldstateNeutral, 0, false);
275
276 if (GuidUnorderedSet const* guidSet = controlZone->GetInsidePlayers())
277 for (ObjectGuid const& guid : *guidSet)
278 if (Player* player = ObjectAccessor::GetPlayer(*controlZone, guid))
279 if (player->GetTeam() == HORDE)
280 player->AreaExploredOrEventHappens(TF_HORDE_QUEST);
281
283}
284
286{
287 controlZone->SetGoArtKit(2);
288 GetOutdoorPvPTF()->SetAllianceTowersControlled(GetOutdoorPvPTF()->GetAllianceTowersControlled() + 1);
290 controlZone->GetMap()->SetWorldStateValue(_worldstateHorde, 0, false);
291 controlZone->GetMap()->SetWorldStateValue(_worldstateAlliance, 1, false);
292 controlZone->GetMap()->SetWorldStateValue(_worldstateNeutral, 0, false);
293
294 if (GuidUnorderedSet const* guidSet = controlZone->GetInsidePlayers())
295 for (ObjectGuid const& guid : *guidSet)
296 if (Player* player = ObjectAccessor::GetPlayer(*controlZone, guid))
297 if (player->GetTeam() == ALLIANCE)
298 player->AreaExploredOrEventHappens(TF_ALLY_QUEST);
299
301}
302
304{
305 GetOutdoorPvPTF()->SetHordeTowersControlled(GetOutdoorPvPTF()->GetHordeTowersControlled() - 1);
308}
309
311{
312 GetOutdoorPvPTF()->SetAllianceTowersControlled(GetOutdoorPvPTF()->GetAllianceTowersControlled() - 1);
315}
316
318{
319 controlZone->SetGoArtKit(21);
320 controlZone->GetMap()->SetWorldStateValue(_worldstateHorde, 0, false);
321 controlZone->GetMap()->SetWorldStateValue(_worldstateAlliance, 0, false);
322 controlZone->GetMap()->SetWorldStateValue(_worldstateNeutral, 1, false);
324}
325
327{
329}
330
332{
333 public:
335
336 OutdoorPvP* GetOutdoorPvP(Map* map) const override
337 {
338 return new OutdoorPvPTF(map);
339 }
340};
341
343{
345}
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition: ObjectGuid.h:396
uint32 const OutdoorPvPTFBuffZones[OutdoorPvPTFBuffZonesNum]
uint32 const TF_HORDE_QUEST
uint32 const TF_ALLY_QUEST
uint32 const TF_LOCK_TIME_UPDATE
int32 const TF_CAPTURE_BUFF
void AddSC_outdoorpvp_tf()
uint8 const OutdoorPvPTFBuffZonesNum
uint32 const TF_LOCK_TIME
@ TF_UI_LOCKED_TIME_MINUTES_FIRST_DIGIT
Definition: OutdoorPvPTF.h:49
@ TF_UI_LOCKED_DISPLAY_ALLIANCE
Definition: OutdoorPvPTF.h:54
@ TF_UI_LOCKED_TIME_MINUTES_SECOND_DIGIT
Definition: OutdoorPvPTF.h:50
@ TF_UI_LOCKED_DISPLAY_NEUTRAL
Definition: OutdoorPvPTF.h:52
@ TF_UI_LOCKED_DISPLAY_HORDE
Definition: OutdoorPvPTF.h:53
@ TF_UI_TOWER_COUNT_H
Definition: OutdoorPvPTF.h:45
@ TF_UI_TOWERS_CONTROLLED_DISPLAY
Definition: OutdoorPvPTF.h:47
@ TF_UI_TOWER_COUNT_A
Definition: OutdoorPvPTF.h:46
@ TF_UI_LOCKED_TIME_HOURS
Definition: OutdoorPvPTF.h:51
@ TF_TOWER_NUM
Definition: OutdoorPvPTF.h:40
@ TEXT_SPIRIT_TOWER_LOSE_HORDE
Definition: OutdoorPvPTF.h:30
@ TEXT_SPIRIT_TOWER_TAKEN_ALLIANCE
Definition: OutdoorPvPTF.h:27
@ TEXT_SPIRIT_TOWER_TAKEN_HORDE
Definition: OutdoorPvPTF.h:28
@ TEXT_SPIRIT_TOWER_LOSE_ALLIANCE
Definition: OutdoorPvPTF.h:29
@ TF_ENTRY_TOWER_SE
Definition: OutdoorPvPTF.h:90
@ TF_ENTRY_TOWER_N
Definition: OutdoorPvPTF.h:88
@ TF_ENTRY_TOWER_NW
Definition: OutdoorPvPTF.h:87
@ TF_ENTRY_TOWER_S
Definition: OutdoorPvPTF.h:91
@ TF_ENTRY_TOWER_NE
Definition: OutdoorPvPTF.h:89
@ OUTDOOR_PVP_TF
Definition: OutdoorPvP.h:32
TeamId
@ TEAM_ALLIANCE
@ TEAM_HORDE
@ ALLIANCE
@ HORDE
virtual void HandleNeutralEventHorde(GameObject *controlZone)
Definition: ZoneScript.h:53
virtual void HandleProgressEventAlliance(GameObject *controlZone)
Definition: ZoneScript.h:52
virtual void HandleNeutralEventAlliance(GameObject *controlZone)
Definition: ZoneScript.h:54
virtual void HandleProgressEventHorde(GameObject *controlZone)
Definition: ZoneScript.h:51
virtual void HandleNeutralEvent(GameObject *controlZone)
Definition: ZoneScript.h:55
GuidUnorderedSet const * GetInsidePlayers() const
void SetGoArtKit(uint32 artkit)
Definition: Map.h:189
void SetWorldStateValue(int32 worldStateId, int32 value, bool hidden)
Definition: Map.cpp:468
uint32 GetEntry() const
Definition: Object.h:161
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:159
OutdoorPvP * GetOutdoorPvP() const
Definition: OutdoorPvP.h:121
void HandlePlayerEnterZone(Player *player, uint32 zone) override
void SendRemoveWorldStates(Player *player) override
void SetHordeTowersControlled(uint32 count)
void ProcessEvent(WorldObject *obj, uint32 eventId, WorldObject *invoker) override
uint32 GetHordeTowersControlled() const
void OnGameObjectCreate(GameObject *go) override
uint32 GetAllianceTowersControlled() const
uint32 m_HordeTowersControlled
Definition: OutdoorPvPTF.h:144
bool IsLocked() const
uint32 m_AllianceTowersControlled
Definition: OutdoorPvPTF.h:143
uint32 second_digit
Definition: OutdoorPvPTF.h:145
uint32 m_LockTimer
Definition: OutdoorPvPTF.h:141
void HandlePlayerLeaveZone(Player *player, uint32 zone) override
OutdoorPvPTF(Map *map)
void HandleCapture(TeamId team)
bool SetupOutdoorPvP() override
uint32 m_LockTimerUpdate
Definition: OutdoorPvPTF.h:142
void Update(uint32 diff) override
uint32 hours_left
Definition: OutdoorPvPTF.h:145
uint32 first_digit
Definition: OutdoorPvPTF.h:145
GuidUnorderedSet _controlZoneGUIDs
Definition: OutdoorPvPTF.h:146
void SetAllianceTowersControlled(uint32 count)
OutdoorPvP * GetOutdoorPvP(Map *map) const override
virtual void HandlePlayerEnterZone(Player *player, uint32 zone)
Definition: OutdoorPvP.cpp:64
uint32 m_TypeId
Definition: OutdoorPvP.h:208
virtual void Update(uint32 diff)
Definition: OutdoorPvP.cpp:80
void TeamApplyBuff(TeamId team, uint32 spellId, uint32 spellId2=0)
Definition: OutdoorPvP.cpp:200
void RegisterZone(uint32 zoneid)
Definition: OutdoorPvP.cpp:173
void SetWorldState(int32 worldStateId, int32 value)
Definition: OutdoorPvP.cpp:91
virtual void HandlePlayerLeaveZone(Player *player, uint32 zone)
Definition: OutdoorPvP.cpp:69
Map * GetMap() const
Definition: OutdoorPvP.h:195
void TeamCastSpell(TeamId team, int32 spellId)
Definition: OutdoorPvP.cpp:184
ControlZoneHandlerMap ControlZoneHandlers
Definition: OutdoorPvP.h:204
void ProcessEvent(WorldObject *target, uint32 eventId, WorldObject *invoker) override
Definition: OutdoorPvP.cpp:213
void SendDefenseMessage(uint32 zoneId, uint32 id)
Definition: OutdoorPvP.cpp:206
void SendDirectMessage(WorldPacket const *data) const
Definition: Player.cpp:6324
Team GetTeam() const
Definition: Player.h:2235
void HandleNeutralEventAlliance(GameObject *controlZone) override
uint32 GetWorldStateHorde()
Definition: OutdoorPvPTF.h:107
void HandleNeutralEvent(GameObject *controlZone) override
void HandleNeutralEventHorde(GameObject *controlZone) override
TFControlZoneHandler(OutdoorPvPTF *pvp, uint32 worldstateHorde, uint32 worldstateAlliance, uint32 worldstateNeutral)
void HandleProgressEventAlliance(GameObject *controlZone) override
uint32 GetWorldStateAlliance()
Definition: OutdoorPvPTF.h:108
uint32 GetWorldStateNeutral()
Definition: OutdoorPvPTF.h:109
void HandleProgressEventHorde(GameObject *controlZone) override
OutdoorPvPTF * GetOutdoorPvPTF() const
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint32 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition: Unit.cpp:3831
constexpr uint32 GetMapId() const
Definition: Position.h:201
Map * GetMap() const
Definition: Object.h:624
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition: Object.cpp:2896
uint32 GetAreaId() const
Definition: Object.h:546
uint32 GetZoneId() const
Definition: Object.h:545
std::vector< WorldStateInfo > Worldstates
WorldPacket const * Write() override
virtual void OnGameObjectCreate(GameObject *)
Definition: ZoneScript.h:74
TC_GAME_API GameObject * GetGameObject(WorldObject const &u, ObjectGuid const &guid)
TC_GAME_API Player * GetPlayer(Map const *, ObjectGuid const &guid)