TrinityCore
OutdoorPvPHP.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 "OutdoorPvPHP.h"
19#include "GameObject.h"
20#include "Map.h"
21#include "ObjectAccessor.h"
22#include "Player.h"
23#include "ScriptMgr.h"
24#include "WorldStatePackets.h"
25
27uint32 const OutdoorPvPHPBuffZones[OutdoorPvPHPBuffZonesNum] = { 3483, 3563, 3562, 3713, 3714, 3836 }; // HP, citadel, ramparts, blood furnace, shattered halls, mag's lair
28
30{
34
35 ControlZoneHandlers[HP_GO_ENTRY_TOWER_S] = std::make_unique<HPControlZoneHandler>(this);
45
46 ControlZoneHandlers[HP_GO_ENTRY_TOWER_N] = std::make_unique<HPControlZoneHandler>(this);
56
57 ControlZoneHandlers[HP_GO_ENTRY_TOWER_W] = std::make_unique<HPControlZoneHandler>(this);
67}
68
70{
73
74 // add the zones affected by the pvp buff
75 for (uint32 i = 0; i < OutdoorPvPHPBuffZonesNum; ++i)
77
78 return true;
79}
80
82{
84 _controlZoneGUIDs.insert(go->GetGUID());
85
86 switch (go->GetEntry())
87 {
88 case 183514:
90 break;
91 case 182525:
93 break;
94 case 183515:
96 break;
97 default:
98 break;
99 }
100
102}
103
105{
106 // add buffs
107 if (player->GetTeam() == ALLIANCE)
108 {
110 player->CastSpell(player, AllianceBuff, true);
111 }
112 else
113 {
115 player->CastSpell(player, HordeBuff, true);
116 }
118}
119
121{
122 // remove buffs
123 if (player->GetTeam() == ALLIANCE)
124 {
126 }
127 else
128 {
130 }
132}
133
135{
136 OutdoorPvP::Update(diff);
139 else if (m_HordeTowersControlled == 3)
141 else
142 {
145 }
148}
149
151{
153 initWorldStates.MapID = player->GetMapId();
154 initWorldStates.AreaID = player->GetZoneId();
155 initWorldStates.SubareaID = player->GetAreaId();
156 initWorldStates.Worldstates.emplace_back(HP_UI_TOWER_DISPLAY_A, 0);
157 initWorldStates.Worldstates.emplace_back(HP_UI_TOWER_DISPLAY_H, 0);
158 initWorldStates.Worldstates.emplace_back(HP_UI_TOWER_COUNT_H, 0);
159 initWorldStates.Worldstates.emplace_back(HP_UI_TOWER_COUNT_A, 0);
160
161 for (auto& itr : ControlZoneHandlers)
162 {
163 HPControlZoneHandler* handler = static_cast<HPControlZoneHandler*>(itr.second.get());
164 initWorldStates.Worldstates.emplace_back(handler->GetWorldStateNeutral(), 0);
165 initWorldStates.Worldstates.emplace_back(handler->GetWorldStateHorde(), 0);
166 initWorldStates.Worldstates.emplace_back(handler->GetWorldStateAlliance(), 0);
167 }
168
169 player->SendDirectMessage(initWorldStates.Write());
170}
171
173{
174 if (killed->GetTypeId() != TYPEID_PLAYER)
175 return;
176
177 // need to check if player is inside an capture zone
178 bool isInsideCaptureZone = false;
179 for (ObjectGuid const& guid : _controlZoneGUIDs)
180 {
181 if (GameObject* gameObject = GetMap()->GetGameObject(guid))
182 {
183 if (GuidUnorderedSet const* insidePlayerGuids = gameObject->GetInsidePlayers())
184 {
185 if (insidePlayerGuids->contains(player->GetGUID()))
186 {
187 isInsideCaptureZone = true;
188 break;
189 }
190 }
191 }
192 }
193
194 if (isInsideCaptureZone)
195 {
196 if (player->GetTeam() == ALLIANCE && killed->ToPlayer()->GetTeam() != ALLIANCE)
197 player->CastSpell(player, AlliancePlayerKillReward, true);
198 else if (player->GetTeam() == HORDE && killed->ToPlayer()->GetTeam() != HORDE)
199 player->CastSpell(player, HordePlayerKillReward, true);
200 }
201}
202
204{
206}
207
209{
211}
212
214{
216}
217
219{
221}
222
224 _flagGuid(ObjectGuid::Empty), _textCaptureAlliance(0), _textCaptureHorde(0),
225 _flagArtKitNeutral(0), _flagArtKitHorde(0), _flagArtKitAlliance(0),
226 _worldstateNeutral(0), _worldstateHorde(0), _worldstateAlliance(0),
227 _killCredit(0)
228{
229}
230
232{
234
235 controlZone->SetGoArtKit(1);
236 controlZone->SendCustomAnim(0);
237 if (GameObject* flag = controlZone->GetMap()->GetGameObject(_flagGuid))
238 flag->SetGoArtKit(_flagArtKitHorde);
239
240 controlZone->GetMap()->SetWorldStateValue(_worldstateHorde, 1, false);
241 controlZone->GetMap()->SetWorldStateValue(_worldstateAlliance, 0, false);
242 controlZone->GetMap()->SetWorldStateValue(_worldstateNeutral, 0, false);
243
245
246 if (GuidUnorderedSet const* guidSet = controlZone->GetInsidePlayers())
247 for (ObjectGuid const& guid : *guidSet)
248 if (Player* player = ObjectAccessor::GetPlayer(*controlZone, guid))
249 if (player->GetTeam() == HORDE)
250 player->KilledMonsterCredit(_killCredit);
251}
252
254{
256
257 controlZone->SetGoArtKit(2);
258 controlZone->SendCustomAnim(1);
259 if (GameObject* flag = controlZone->GetMap()->GetGameObject(_flagGuid))
260 flag->SetGoArtKit(_flagArtKitAlliance);
261
262 controlZone->GetMap()->SetWorldStateValue(_worldstateHorde, 0, false);
263 controlZone->GetMap()->SetWorldStateValue(_worldstateAlliance, 1, false);
264 controlZone->GetMap()->SetWorldStateValue(_worldstateNeutral, 0, false);
265
267
268 if (GuidUnorderedSet const* guidSet = controlZone->GetInsidePlayers())
269 for (ObjectGuid const& guid : *guidSet)
270 if (Player* player = ObjectAccessor::GetPlayer(*controlZone, guid))
271 if (player->GetTeam() == ALLIANCE)
272 player->KilledMonsterCredit(_killCredit);
273}
274
276{
278 GetOutdoorPvPHP()->SetHordeTowersControlled(GetOutdoorPvPHP()->GetHordeTowersControlled() - 1);
279}
280
282{
284 GetOutdoorPvPHP()->SetAllianceTowersControlled(GetOutdoorPvPHP()->GetAllianceTowersControlled() - 1);
285}
286
288{
290 controlZone->SetGoArtKit(21);
291 controlZone->SendCustomAnim(2);
292 if (GameObject* flag = controlZone->GetMap()->GetGameObject(_flagGuid))
293 flag->SetGoArtKit(_flagArtKitNeutral);
294
295 controlZone->GetMap()->SetWorldStateValue(_worldstateHorde, 0, false);
296 controlZone->GetMap()->SetWorldStateValue(_worldstateAlliance, 0, false);
297 controlZone->GetMap()->SetWorldStateValue(_worldstateNeutral, 1, false);
298}
299
301{
303}
304
306{
307 public:
309
310 OutdoorPvP* GetOutdoorPvP(Map* map) const override
311 {
312 return new OutdoorPvPHP(map);
313 }
314};
315
317{
319}
uint32_t uint32
Definition: Define.h:142
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition: ObjectGuid.h:396
@ TYPEID_PLAYER
Definition: ObjectGuid.h:41
void AddSC_outdoorpvp_hp()
uint32 const OutdoorPvPHPBuffZones[OutdoorPvPHPBuffZonesNum]
uint32 const OutdoorPvPHPBuffZonesNum
@ AllianceBuff
Definition: OutdoorPvPHP.h:38
@ HordePlayerKillReward
Definition: OutdoorPvPHP.h:37
@ HordeBuff
Definition: OutdoorPvPHP.h:39
@ AlliancePlayerKillReward
Definition: OutdoorPvPHP.h:36
@ HP_UI_TOWER_S_N
Definition: OutdoorPvPHP.h:60
@ HP_UI_TOWER_W_A
Definition: OutdoorPvPHP.h:66
@ HP_UI_TOWER_W_H
Definition: OutdoorPvPHP.h:67
@ HP_UI_TOWER_COUNT_A
Definition: OutdoorPvPHP.h:56
@ HP_UI_TOWER_N_A
Definition: OutdoorPvPHP.h:62
@ HP_UI_TOWER_W_N
Definition: OutdoorPvPHP.h:68
@ HP_UI_TOWER_DISPLAY_A
Definition: OutdoorPvPHP.h:52
@ HP_UI_TOWER_N_N
Definition: OutdoorPvPHP.h:64
@ HP_UI_TOWER_DISPLAY_H
Definition: OutdoorPvPHP.h:53
@ HP_UI_TOWER_COUNT_H
Definition: OutdoorPvPHP.h:55
@ HP_UI_TOWER_S_H
Definition: OutdoorPvPHP.h:59
@ HP_UI_TOWER_N_H
Definition: OutdoorPvPHP.h:63
@ HP_UI_TOWER_S_A
Definition: OutdoorPvPHP.h:58
@ HP_GO_ENTRY_TOWER_W
Definition: OutdoorPvPHP.h:91
@ HP_GO_ENTRY_TOWER_N
Definition: OutdoorPvPHP.h:92
@ HP_GO_ENTRY_TOWER_S
Definition: OutdoorPvPHP.h:93
@ HP_KILL_CREDIT_TOWER_S
Definition: OutdoorPvPHP.h:98
@ HP_KILL_CREDIT_TOWER_W
Definition: OutdoorPvPHP.h:100
@ HP_KILL_CREDIT_TOWER_N
Definition: OutdoorPvPHP.h:99
@ TEXT_OVERLOOK_TAKEN_ALLIANCE
Definition: OutdoorPvPHP.h:26
@ TEXT_BROKEN_HILL_TAKEN_HORDE
Definition: OutdoorPvPHP.h:31
@ TEXT_STADIUM_TAKEN_ALLIANCE
Definition: OutdoorPvPHP.h:28
@ TEXT_STADIUM_TAKEN_HORDE
Definition: OutdoorPvPHP.h:29
@ TEXT_OVERLOOK_TAKEN_HORDE
Definition: OutdoorPvPHP.h:27
@ TEXT_BROKEN_HILL_TAKEN_ALLIANCE
Definition: OutdoorPvPHP.h:30
@ OUTDOOR_PVP_HP
Definition: OutdoorPvP.h:30
@ GAMEOBJECT_TYPE_CONTROL_ZONE
@ 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
GameobjectTypes GetGoType() const
Definition: GameObject.h:279
void SendCustomAnim(uint32 anim)
void SetGoArtKit(uint32 artkit)
HPControlZoneHandler(OutdoorPvPHP *pvp)
void HandleNeutralEventAlliance(GameObject *controlZone) override
void SetTextCaptureAlliance(uint32 text)
Definition: OutdoorPvPHP.h:112
void SetKillCredit(uint32 credit)
Definition: OutdoorPvPHP.h:119
void SetFlagArtKitNeutral(uint32 artKit)
Definition: OutdoorPvPHP.h:113
uint32 GetWorldStateNeutral()
Definition: OutdoorPvPHP.h:127
void SetTextCaptureHorde(uint32 text)
Definition: OutdoorPvPHP.h:111
uint32 GetWorldStateHorde()
Definition: OutdoorPvPHP.h:128
void HandleProgressEventHorde(GameObject *controlZone) override
void SetFlagArtKitAlliance(uint32 artKit)
Definition: OutdoorPvPHP.h:115
void SetFlagGuid(ObjectGuid const &guid)
Definition: OutdoorPvPHP.h:110
void HandleNeutralEvent(GameObject *controlZone) override
uint32 GetWorldStateAlliance()
Definition: OutdoorPvPHP.h:129
OutdoorPvPHP * GetOutdoorPvPHP() const
void SetWorldstateNeutral(uint32 id)
Definition: OutdoorPvPHP.h:116
void SetWorldstateHorde(uint32 id)
Definition: OutdoorPvPHP.h:117
void SetFlagArtKitHorde(uint32 artKit)
Definition: OutdoorPvPHP.h:114
void HandleNeutralEventHorde(GameObject *controlZone) override
void HandleProgressEventAlliance(GameObject *controlZone) override
void SetWorldstateAlliance(uint32 id)
Definition: OutdoorPvPHP.h:118
Definition: Map.h:189
void SetWorldStateValue(int32 worldStateId, int32 value, bool hidden)
Definition: Map.cpp:468
GameObject * GetGameObject(ObjectGuid const &guid)
Definition: Map.cpp:3489
TypeID GetTypeId() const
Definition: Object.h:173
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
OutdoorPvP * GetOutdoorPvP() const
Definition: OutdoorPvP.h:121
OutdoorPvPHP(Map *map)
void HandlePlayerEnterZone(Player *player, uint32 zone) override
void SetAllianceTowersControlled(uint32 count)
GuidUnorderedSet _controlZoneGUIDs
Definition: OutdoorPvPHP.h:171
HPControlZoneHandler & GetControlZoneTowerSouthHandler()
Definition: OutdoorPvPHP.h:174
void OnGameObjectCreate(GameObject *go) override
uint32 m_AllianceTowersControlled
Definition: OutdoorPvPHP.h:168
uint32 GetHordeTowersControlled() const
HPControlZoneHandler & GetControlZoneTowerWestHandler()
Definition: OutdoorPvPHP.h:175
void HandleKillImpl(Player *player, Unit *killed) override
void HandlePlayerLeaveZone(Player *player, uint32 zone) override
void SendRemoveWorldStates(Player *player) override
uint32 m_HordeTowersControlled
Definition: OutdoorPvPHP.h:169
HPControlZoneHandler & GetControlZoneTowerNorthHandler()
Definition: OutdoorPvPHP.h:173
void SetHordeTowersControlled(uint32 count)
uint32 GetAllianceTowersControlled() const
bool SetupOutdoorPvP() override
void Update(uint32 diff) override
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 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
Definition: Unit.h:627
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)