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