TrinityCore
OutdoorPvP.h
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 #ifndef OUTDOOR_PVP_H_
19 #define OUTDOOR_PVP_H_
20 
21 #include "Position.h"
22 #include "QuaternionData.h"
23 #include "SharedDefines.h"
24 #include "ZoneScript.h"
25 #include <map>
26 
28 {
34 
36 };
37 
39 {
47 };
48 
49 #define OTHER_TEAM(a) (a == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE)
50 
51 // struct for go spawning
52 struct go_type
53 {
58 };
59 
60 // struct for creature spawning
62 {
66 };
67 
68 class Creature;
69 class GameObject;
70 class Map;
71 class OutdoorPvP;
72 class Player;
73 class Unit;
74 class WorldPacket;
75 struct GossipMenuItems;
76 
77 namespace WorldPackets
78 {
79  namespace WorldState
80  {
81  class InitWorldStates;
82  }
83 }
84 
86 {
87  public:
88 
90 
91  virtual ~OPvPCapturePoint() { }
92 
94 
95  // send world state update to all players present
96  void SendUpdateWorldState(uint32 field, uint32 value);
97 
98  // send kill notify to players in the controlling faction
99  void SendObjectiveComplete(uint32 id, ObjectGuid guid);
100 
101  // used when player is activated/inactivated in the area
102  virtual bool HandlePlayerEnter(Player* player);
103  virtual void HandlePlayerLeave(Player* player);
104 
105  // checks if player is in range of a capture credit marker
106  bool IsInsideObjective(Player* player) const;
107 
108  virtual bool HandleCustomSpell(Player* player, uint32 spellId, GameObject* go);
109 
110  virtual int32 HandleOpenGo(Player* player, GameObject* go);
111 
112  // returns true if the state of the objective has changed, in this case, the OutdoorPvP must send a world state ui update.
113  virtual bool Update(uint32 diff);
114 
115  virtual void ChangeState() = 0;
116 
117  virtual void ChangeTeam(TeamId /*oldTeam*/) { }
118 
119  virtual void SendChangePhase();
120 
121  virtual bool HandleGossipOption(Player* /*player*/, Creature* /*guid*/, uint32 /*gossipId*/) { return false; }
122 
123  virtual bool CanTalkTo(Player* /*player*/, Creature* /*creature*/, GossipMenuItems const& /*gso*/) { return false; }
124 
125  virtual bool HandleDropFlag(Player* /*player*/, uint32 /*spellId*/) { return false; }
126 
127  virtual void DeleteSpawns();
128 
130 
132 
133  void AddGO(uint32 type, ObjectGuid::LowType guid);
134  void AddCre(uint32 type, ObjectGuid::LowType guid);
135 
136  bool SetCapturePointData(uint32 entry, uint32 map, Position const& pos, QuaternionData const& rot);
137 
138  protected:
139 
140  bool AddObject(uint32 type, uint32 entry, uint32 map, Position const& pos, QuaternionData const& rot);
141  bool AddCreature(uint32 type, uint32 entry, uint32 map, Position const& pos, TeamId teamId = TEAM_NEUTRAL, uint32 spawntimedelay = 0);
142 
143  bool DelObject(uint32 type);
144  bool DelCreature(uint32 type);
145 
146  bool DelCapturePoint();
147 
148  protected:
149 
150  // active players in the area of the objective, 0 - alliance, 1 - horde
151  GuidSet m_activePlayers[2];
152 
153  // total shift needed to capture the objective
154  float m_maxValue;
155  float m_minValue;
156 
157  // maximum speed of capture
158  float m_maxSpeed;
159 
160  // the status of the objective
161  float m_value;
162 
164 
165  // objective states
168 
169  // neutral value on capture bar
171 
172  // pointer to the OutdoorPvP this objective belongs to
174 
175  // map to store the various gameobjects and creatures spawned by the objective
176  // type, guid
177  std::map<uint32, ObjectGuid::LowType> m_Objects;
178  std::map<uint32, ObjectGuid::LowType> m_Creatures;
179  std::map<ObjectGuid::LowType, uint32> m_ObjectTypes;
180  std::map<ObjectGuid::LowType, uint32> m_CreatureTypes;
181 };
182 
183 // base class for specific outdoor pvp handlers
185 {
186  friend class OutdoorPvPMgr;
187 
188  public:
189 
190  // ctor
191  OutdoorPvP();
192 
193  // dtor
194  virtual ~OutdoorPvP();
195 
196  // deletes all gos/creatures spawned by the pvp
197  void DeleteSpawns();
198 
200 
202 
203  // called when a player triggers an areatrigger
204  virtual bool HandleAreaTrigger(Player* /*player*/, uint32 /*trigger*/, bool /*entered*/) { return false; }
205 
206  // called on custom spell
207  virtual bool HandleCustomSpell(Player* player, uint32 spellId, GameObject* go);
208 
209  // called on go use
210  virtual bool HandleOpenGo(Player* player, GameObject* go);
211 
212  // setup stuff
213  virtual bool SetupOutdoorPvP() {return true;}
214 
215  void OnGameObjectCreate(GameObject* go) override;
216  void OnGameObjectRemove(GameObject* go) override;
217  void OnCreatureCreate(Creature*) override { }
218 
219  // send world state update to all players present
220  void SendUpdateWorldState(uint32 field, uint32 value);
221 
222  // called by OutdoorPvPMgr, updates the objectives and if needed, sends new worldstateui information
223  virtual bool Update(uint32 diff);
224 
225  // handle npc/player kill
226  virtual void HandleKill(Player* killer, Unit* killed);
227  virtual void HandleKillImpl(Player* /*killer*/, Unit* /*killed*/) { }
228 
229  // checks if player is in range of a capture credit marker
230  bool IsInsideObjective(Player* player) const;
231 
232  // awards rewards for player kill
233  virtual void AwardKillBonus(Player* /*player*/) { }
234 
235  uint32 GetTypeId() const {return m_TypeId;}
236 
237  virtual bool HandleDropFlag(Player* player, uint32 spellId);
238 
239  virtual bool HandleGossipOption(Player* player, Creature* creature, uint32 gossipid);
240 
241  virtual bool CanTalkTo(Player* player, Creature* c, GossipMenuItems const& gso);
242 
243  void TeamApplyBuff(TeamId team, uint32 spellId, uint32 spellId2 = 0);
244 
246  {
247  switch (team)
248  {
249  case ALLIANCE:
250  return TEAM_ALLIANCE;
251  case HORDE:
252  return TEAM_HORDE;
253  default:
254  return TEAM_NEUTRAL;
255  }
256  }
257 
258  void SendDefenseMessage(uint32 zoneId, uint32 id);
259 
260  Map* GetMap() const { return m_map; }
261 
262  protected:
263 
264  // the map of the objectives belonging to this outdoorpvp
265  OPvPCapturePointMap m_capturePoints;
266 
267  GuidSet m_players[2];
268 
270 
272 
273  // world state stuff
274  virtual void SendRemoveWorldStates(Player* /*player*/) { }
275 
276  void BroadcastPacket(WorldPacket const* data) const;
277 
278  virtual void HandlePlayerEnterZone(Player* player, uint32 zone);
279  virtual void HandlePlayerLeaveZone(Player* player, uint32 zone);
280 
281  virtual void HandlePlayerResurrects(Player* player, uint32 zone);
282 
283  void AddCapturePoint(OPvPCapturePoint* cp);
284 
285  OPvPCapturePoint* GetCapturePoint(ObjectGuid::LowType guid) const;
286 
287  void RegisterZone(uint32 zoneid);
288 
289  bool HasPlayer(Player const* player) const;
290 
291  void TeamCastSpell(TeamId team, int32 spellId);
292 
293  template<class Worker>
294  void BroadcastWorker(Worker& _worker, uint32 zoneId);
295 
296  // Hack to store map because this code is just shit
297  void SetMapFromZone(uint32 zone);
298 
300 };
301 
302 #endif /*OUTDOOR_PVP_H_*/
virtual bool CanTalkTo(Player *, Creature *, GossipMenuItems const &)
Definition: OutdoorPvP.h:123
uint32 map
Definition: OutdoorPvP.h:64
Position pos
Definition: OutdoorPvP.h:56
TeamId m_team
Definition: OutdoorPvP.h:163
void Update(uint32 diff)
Definition: OutdoorPvPMgr.cpp:159
static TeamId GetTeamIdByTeam(uint32 team)
Definition: OutdoorPvP.h:245
OutdoorPvP * m_PvP
Definition: OutdoorPvP.h:173
virtual void HandleKillImpl(Player *, Unit *)
Definition: OutdoorPvP.h:227
uint32 entry
Definition: OutdoorPvP.h:63
std::map< uint32, ObjectGuid::LowType > m_Creatures
Definition: OutdoorPvP.h:178
ObjectiveStates
Definition: OutdoorPvP.h:38
Definition: OutdoorPvP.h:45
virtual void ChangeTeam(TeamId)
Definition: OutdoorPvP.h:117
Definition: OutdoorPvP.h:85
std::set< ObjectGuid > GuidSet
Definition: ObjectGuid.h:371
virtual void SendRemoveWorldStates(Player *)
Definition: OutdoorPvP.h:274
Definition: OutdoorPvP.h:29
void HandleDropFlag(Player *player, uint32 spellId)
Definition: OutdoorPvPMgr.cpp:218
constexpr auto data(C &c)
Definition: advstd.h:96
uint64 LowType
Definition: ObjectGuid.h:258
Definition: OutdoorPvPMgr.h:35
virtual bool HandleAreaTrigger(Player *, uint32, bool)
Definition: OutdoorPvP.h:204
virtual void AwardKillBonus(Player *)
Definition: OutdoorPvP.h:233
OPvPCapturePointMap m_capturePoints
Definition: OutdoorPvP.h:265
void OnCreatureCreate(Creature *) override
Definition: OutdoorPvP.h:217
float m_value
Definition: OutdoorPvP.h:161
Definition: Creature.h:69
void HandleGossipOption(Player *player, Creature *creature, uint32 gossipid)
Definition: OutdoorPvPMgr.cpp:199
std::map< ObjectGuid::LowType, uint32 > m_CreatureTypes
Definition: OutdoorPvP.h:180
virtual bool HandleGossipOption(Player *, Creature *, uint32)
Definition: OutdoorPvP.h:121
Map * GetMap() const
Definition: OutdoorPvP.h:260
Definition: SharedDefines.h:1081
Definition: SharedDefines.h:1087
Map * m_map
Definition: OutdoorPvP.h:299
void HandlePlayerResurrects(Player *player, uint32 areaflag)
Definition: OutdoorPvPMgr.cpp:227
uint32 map
Definition: OutdoorPvP.h:55
Definition: ObjectMgr.h:693
Definition: ZoneScript.h:30
Definition: OutdoorPvP.h:35
ObjectGuid::LowType m_capturePointSpawnId
Definition: OutdoorPvP.h:129
Definition: OutdoorPvP.h:42
Position pos
Definition: OutdoorPvP.h:65
QuaternionData rot
Definition: OutdoorPvP.h:57
OutdoorPvPTypes
Definition: OutdoorPvP.h:27
void AddObject(T *object)
Definition: ObjectAccessor.h:99
std::map< ObjectGuid::LowType, OPvPCapturePoint * > OPvPCapturePointMap
Definition: OutdoorPvP.h:199
int32_t int32
Definition: Define.h:148
uint32_t uint32
Definition: Define.h:152
Definition: WorldStatePackets.h:27
Definition: SharedDefines.h:1079
Definition: GameObject.h:81
GameObject * m_capturePoint
Definition: OutdoorPvP.h:131
Definition: OutdoorPvP.h:44
void HandlePlayerEnterZone(Player *player, uint32 areaflag)
Definition: OutdoorPvPMgr.cpp:121
Definition: Map.h:252
TeamId
Definition: SharedDefines.h:1077
Definition: SharedDefines.h:1086
Definition: AuctionHouseMgr.h:36
float m_maxValue
Definition: OutdoorPvP.h:154
uint32 m_neutralValuePct
Definition: OutdoorPvP.h:170
std::map< uint32, ObjectGuid::LowType > m_Objects
Definition: OutdoorPvP.h:177
Definition: OutdoorPvP.h:61
Definition: QuaternionData.h:23
Definition: OutdoorPvP.h:184
Definition: OutdoorPvP.h:41
uint32 m_TypeId
Definition: OutdoorPvP.h:269
float m_minValue
Definition: OutdoorPvP.h:155
#define TC_GAME_API
Definition: Define.h:136
virtual void FillInitialWorldStates(WorldPackets::WorldState::InitWorldStates &)
Definition: OutdoorPvP.h:201
std::map< ObjectGuid::LowType, uint32 > m_ObjectTypes
Definition: OutdoorPvP.h:179
uint32 entry
Definition: OutdoorPvP.h:54
Definition: Position.h:27
virtual bool SetupOutdoorPvP()
Definition: OutdoorPvP.h:213
Definition: OutdoorPvP.h:31
Definition: OutdoorPvP.h:30
bool CanTalkTo(Player *player, Creature *creature, GossipMenuItems const &gso)
Definition: OutdoorPvPMgr.cpp:208
virtual ~OPvPCapturePoint()
Definition: OutdoorPvP.h:91
Definition: ObjectGuid.h:248
bool HandleCustomSpell(Player *player, uint32 spellId, GameObject *go)
Definition: OutdoorPvPMgr.cpp:170
bool HandleOpenGo(Player *player, GameObject *go)
Definition: OutdoorPvPMgr.cpp:189
Definition: OutdoorPvP.h:46
bool m_sendUpdate
Definition: OutdoorPvP.h:271
virtual void FillInitialWorldStates(WorldPackets::WorldState::InitWorldStates &)
Definition: OutdoorPvP.h:93
uint32 GetTypeId() const
Definition: OutdoorPvP.h:235
Definition: SharedDefines.h:1080
Definition: OutdoorPvP.h:32
ObjectiveStates m_OldState
Definition: OutdoorPvP.h:166
Definition: Unit.h:737
Definition: Player.h:1081
ObjectiveStates m_State
Definition: OutdoorPvP.h:167
void HandlePlayerLeaveZone(Player *player, uint32 areaflag)
Definition: OutdoorPvPMgr.cpp:134
Definition: WorldPacket.h:24
float m_maxSpeed
Definition: OutdoorPvP.h:158
Definition: OutdoorPvP.h:52
Definition: OutdoorPvP.h:40
virtual bool HandleDropFlag(Player *, uint32)
Definition: OutdoorPvP.h:125
Definition: OutdoorPvP.h:33