OregonCore  revision fb2a440-git
Your Favourite TBC server
OutdoorPvPMgr.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 "OutdoorPvPMgr.h"
19 #include "OutdoorPvPHP.h"
20 #include "OutdoorPvPNA.h"
21 #include "OutdoorPvPTF.h"
22 #include "OutdoorPvPZM.h"
23 #include "OutdoorPvPSI.h"
24 #include "OutdoorPvPEP.h"
25 #include "ObjectMgr.h"
26 #include "Player.h"
27 
29 
31 {
32  m_UpdateTimer = 0;
33  //sLog.outDebug("Instantiating OutdoorPvPMgr");
34 }
35 
37 {
38  //sLog.outDebug("Deleting OutdoorPvPMgr");
39  for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
40  delete *itr;
41 }
42 
44 {
45  // create new opvp
46  OutdoorPvP* pOP = new OutdoorPvPHP;
47  // respawn, init variables
48  if (!pOP->SetupOutdoorPvP())
49  {
50  sLog.outDebug("OutdoorPvP : HP init failed.");
51  delete pOP;
52  }
53  else
54  {
55  m_OutdoorPvPSet.push_back(pOP);
56  sLog.outDebug("OutdoorPvP : HP successfully initiated.");
57  }
58 
59  pOP = new OutdoorPvPNA;
60  // respawn, init variables
61  if (!pOP->SetupOutdoorPvP())
62  {
63  sLog.outDebug("OutdoorPvP : NA init failed.");
64  delete pOP;
65  }
66  else
67  {
68  m_OutdoorPvPSet.push_back(pOP);
69  sLog.outDebug("OutdoorPvP : NA successfully initiated.");
70  }
71 
72  pOP = new OutdoorPvPTF;
73  // respawn, init variables
74  if (!pOP->SetupOutdoorPvP())
75  {
76  sLog.outDebug("OutdoorPvP : TF init failed.");
77  delete pOP;
78  }
79  else
80  {
81  m_OutdoorPvPSet.push_back(pOP);
82  sLog.outDebug("OutdoorPvP : TF successfully initiated.");
83  }
84 
85  pOP = new OutdoorPvPZM;
86  // respawn, init variables
87  if (!pOP->SetupOutdoorPvP())
88  {
89  sLog.outDebug("OutdoorPvP : ZM init failed.");
90  delete pOP;
91  }
92  else
93  {
94  m_OutdoorPvPSet.push_back(pOP);
95  sLog.outDebug("OutdoorPvP : ZM successfully initiated.");
96  }
97 
98  pOP = new OutdoorPvPSI;
99  // respawn, init variables
100  if (!pOP->SetupOutdoorPvP())
101  {
102  sLog.outDebug("OutdoorPvP : SI init failed.");
103  delete pOP;
104  }
105  else
106  {
107  m_OutdoorPvPSet.push_back(pOP);
108  sLog.outDebug("OutdoorPvP : SI successfully initiated.");
109  }
110 
111  pOP = new OutdoorPvPEP;
112  // respawn, init variables
113  if (!pOP->SetupOutdoorPvP())
114  {
115  sLog.outDebug("OutdoorPvP : EP init failed.");
116  delete pOP;
117  }
118  else
119  {
120  m_OutdoorPvPSet.push_back(pOP);
121  sLog.outDebug("OutdoorPvP : EP successfully initiated.");
122  }
123 }
124 
126 {
127  m_OutdoorPvPMap[zoneid] = handle;
128 }
129 
131 {
132  OutdoorPvPMap::iterator itr = m_OutdoorPvPMap.find(zoneid);
133  if (itr == m_OutdoorPvPMap.end())
134  return;
135 
136  if (itr->second->HasPlayer(plr))
137  return;
138 
139  itr->second->HandlePlayerEnterZone(plr, zoneid);
140  sLog.outDebug("Player %u entered outdoorpvp id %u", plr->GetGUIDLow(), itr->second->GetTypeId());
141 }
142 
144 {
145  OutdoorPvPMap::iterator itr = m_OutdoorPvPMap.find(zoneid);
146  if (itr == m_OutdoorPvPMap.end())
147  return;
148 
149  // teleport: remove once in removefromworld, once in updatezone
150  if (!itr->second->HasPlayer(plr))
151  return;
152 
153  itr->second->HandlePlayerLeaveZone(plr, zoneid);
154  sLog.outDebug("Player %u left outdoorpvp id %u", plr->GetGUIDLow(), itr->second->GetTypeId());
155 }
156 
158 {
159  OutdoorPvPMap::iterator itr = m_OutdoorPvPMap.find(zoneid);
160  if (itr == m_OutdoorPvPMap.end())
161  {
162  // no handle for this zone, return
163  return NULL;
164  }
165  return itr->second;
166 }
167 
169 {
170  m_UpdateTimer += diff;
172  {
173  for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
174  (*itr)->Update(m_UpdateTimer);
175  m_UpdateTimer = 0;
176  }
177 }
178 
180 {
181  for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
182  {
183  if ((*itr)->HandleCustomSpell(plr, spellId, go))
184  return true;
185  }
186  return false;
187 }
188 
190 {
191  OutdoorPvPMap::iterator itr = m_OutdoorPvPMap.find(zoneId);
192  if (itr != m_OutdoorPvPMap.end())
193  return itr->second;
194  else
195  return NULL;
196 }
197 
199 {
200  for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
201  {
202  if ((*itr)->HandleOpenGo(plr, guid))
203  return true;
204  }
205  return false;
206 }
207 
209 {
210  for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
211  {
212  if ((*itr)->HandleGossipOption(plr, guid, gossipid))
213  return;
214  }
215 }
216 
218 {
219  for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
220  {
221  if ((*itr)->CanTalkTo(plr, c, gso))
222  return true;
223  }
224  return false;
225 }
226 
228 {
229  for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
230  {
231  if ((*itr)->HandleDropFlag(plr, spellId))
232  return;
233  }
234 }
235 
bool CanTalkTo(Player *player, Creature *creature, GossipMenuItems gso)
void Update(uint32 diff)
void HandleGossipOption(Player *player, uint64 guid, uint32 gossipid)
uint32 m_UpdateTimer
Definition: OutdoorPvPMgr.h:76
OutdoorPvPSet m_OutdoorPvPSet
Definition: OutdoorPvPMgr.h:71
#define sLog
Log class singleton.
Definition: Log.h:187
bool HandleOpenGo(Player *plr, uint64 guid)
uint32 GetGUIDLow() const
Definition: Object.h:166
void HandlePlayerLeaveZone(Player *plr, uint32 areaflag)
OutdoorPvP * GetOutdoorPvPToZoneId(uint32 zoneid)
bool HandleCustomSpell(Player *plr, uint32 spellId, GameObject *go)
ZoneScript * GetZoneScript(uint32 zoneId)
void AddZone(uint32 zoneid, OutdoorPvP *handle)
#define OUTDOORPVP_OBJECTIVE_UPDATE_INTERVAL
Definition: OutdoorPvPMgr.h:21
OutdoorPvPMap m_OutdoorPvPMap
Definition: OutdoorPvPMgr.h:74
void InitOutdoorPvP()
INSTANTIATE_SINGLETON_1(OutdoorPvPMgr)
ACE_UINT64 uint64
Definition: Define.h:70
void HandlePlayerEnterZone(Player *plr, uint32 areaflag)
virtual bool SetupOutdoorPvP()
Definition: OutdoorPvP.h:192
void HandleDropFlag(Player *plr, uint32 spellId)
ACE_UINT32 uint32
Definition: Define.h:71
Definition: Player.h:922