AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
OutdoorPvPMgr Class Reference

#include "OutdoorPvPMgr.h"

Public Member Functions

void InitOutdoorPvP ()
 
void Die ()
 
void HandlePlayerEnterZone (Player *player, uint32 areaflag)
 
void HandlePlayerLeaveZone (Player *player, uint32 areaflag)
 
void HandlePlayerResurrects (Player *player, uint32 areaflag)
 
OutdoorPvPGetOutdoorPvPToZoneId (uint32 zoneid)
 
bool HandleCustomSpell (Player *player, uint32 spellId, GameObject *go)
 
bool HandleOpenGo (Player *player, GameObject *go)
 
ZoneScriptGetZoneScript (uint32 zoneId)
 
void AddZone (uint32 zoneid, OutdoorPvP *handle)
 
void Update (uint32 diff)
 
void HandleGossipOption (Player *player, Creature *creatured, uint32 gossipid)
 
bool CanTalkTo (Player *player, Creature *creature, GossipMenuItems const &gso)
 
void HandleDropFlag (Player *player, uint32 spellId)
 

Static Public Member Functions

static OutdoorPvPMgrinstance ()
 

Public Attributes

std::mutex _lock
 

Private Member Functions

 OutdoorPvPMgr ()
 
 ~OutdoorPvPMgr ()=default
 

Private Attributes

std::vector< std::unique_ptr< OutdoorPvP > > m_OutdoorPvPSet
 
std::map< uint32, OutdoorPvP * > m_OutdoorPvPMap
 
std::map< OutdoorPvPTypes, std::unique_ptr< OutdoorPvPData > > m_OutdoorPvPDatas
 
uint32 m_UpdateTimer
 

Detailed Description

Constructor & Destructor Documentation

◆ OutdoorPvPMgr()

OutdoorPvPMgr::OutdoorPvPMgr ( )
private
25{
26 m_UpdateTimer = 0;
27 //LOG_DEBUG("outdoorpvp", "Instantiating OutdoorPvPMgr");
28}
uint32 m_UpdateTimer
Definition: OutdoorPvPMgr.h:99

References m_UpdateTimer.

◆ ~OutdoorPvPMgr()

OutdoorPvPMgr::~OutdoorPvPMgr ( )
privatedefault

Member Function Documentation

◆ AddZone()

void OutdoorPvPMgr::AddZone ( uint32  zoneid,
OutdoorPvP handle 
)
111{
112 m_OutdoorPvPMap[zoneid] = handle;
113}
std::map< uint32, OutdoorPvP * > m_OutdoorPvPMap
Definition: OutdoorPvPMgr.h:93

References m_OutdoorPvPMap.

◆ CanTalkTo()

bool OutdoorPvPMgr::CanTalkTo ( Player player,
Creature creature,
GossipMenuItems const &  gso 
)
227{
228 for (auto& itr : m_OutdoorPvPSet)
229 {
230 if (itr->CanTalkTo(player, creature, gso))
231 {
232 return true;
233 }
234 }
235
236 return false;
237}
std::vector< std::unique_ptr< OutdoorPvP > > m_OutdoorPvPSet
Definition: OutdoorPvPMgr.h:89

References m_OutdoorPvPSet.

◆ Die()

void OutdoorPvPMgr::Die ( )
37{
38 m_OutdoorPvPSet.clear();
39 m_OutdoorPvPDatas.clear();
40}
std::map< OutdoorPvPTypes, std::unique_ptr< OutdoorPvPData > > m_OutdoorPvPDatas
Definition: OutdoorPvPMgr.h:96

References m_OutdoorPvPDatas, and m_OutdoorPvPSet.

◆ GetOutdoorPvPToZoneId()

OutdoorPvP * OutdoorPvPMgr::GetOutdoorPvPToZoneId ( uint32  zoneid)
147{
148 auto itr = m_OutdoorPvPMap.find(zoneid);
149 if (itr == m_OutdoorPvPMap.end())
150 {
151 // no handle for this zone, return
152 return nullptr;
153 }
154
155 return itr->second;
156}

References m_OutdoorPvPMap.

◆ GetZoneScript()

ZoneScript * OutdoorPvPMgr::GetZoneScript ( uint32  zoneId)
188{
189 auto itr = m_OutdoorPvPMap.find(zoneId);
190 if (itr != m_OutdoorPvPMap.end())
191 {
192 return itr->second;
193 }
194
195 return nullptr;
196}

References m_OutdoorPvPMap.

◆ HandleCustomSpell()

bool OutdoorPvPMgr::HandleCustomSpell ( Player player,
uint32  spellId,
GameObject go 
)
174{
175 // pussywizard: no mutex because not affecting other players
176 for (auto& itr : m_OutdoorPvPSet)
177 {
178 if (itr->HandleCustomSpell(player, spellId, go))
179 {
180 return true;
181 }
182 }
183
184 return false;
185}

References m_OutdoorPvPSet.

◆ HandleDropFlag()

void OutdoorPvPMgr::HandleDropFlag ( Player player,
uint32  spellId 
)
240{
241 // pussywizard: no mutex because not affecting other players
242 for (auto& itr : m_OutdoorPvPSet)
243 {
244 if (itr->HandleDropFlag(player, spellId))
245 {
246 return;
247 }
248 }
249}

References m_OutdoorPvPSet.

◆ HandleGossipOption()

void OutdoorPvPMgr::HandleGossipOption ( Player player,
Creature creatured,
uint32  gossipid 
)
214{
215 std::lock_guard<std::mutex> guard(_lock); // pussywizard
216
217 for (auto& itr : m_OutdoorPvPSet)
218 {
219 if (itr->HandleGossipOption(player, creature, gossipid))
220 {
221 return;
222 }
223 }
224}
std::mutex _lock
Definition: OutdoorPvPMgr.h:84

References _lock, and m_OutdoorPvPSet.

◆ HandleOpenGo()

bool OutdoorPvPMgr::HandleOpenGo ( Player player,
GameObject go 
)
199{
200 std::lock_guard<std::mutex> guard(_lock); // pussywizard
201
202 for (auto& itr : m_OutdoorPvPSet)
203 {
204 if (itr->HandleOpenGo(player, go))
205 {
206 return true;
207 }
208 }
209
210 return false;
211}

References _lock, and m_OutdoorPvPSet.

◆ HandlePlayerEnterZone()

void OutdoorPvPMgr::HandlePlayerEnterZone ( Player player,
uint32  areaflag 
)
116{
117 auto itr = m_OutdoorPvPMap.find(zoneid);
118 if (itr == m_OutdoorPvPMap.end())
119 return;
120
121 std::lock_guard<std::mutex> guard(_lock); // pussywizard
122
123 if (itr->second->HasPlayer(player))
124 return;
125
126 itr->second->HandlePlayerEnterZone(player, zoneid);
127 LOG_DEBUG("outdoorpvp", "Player {} entered outdoorpvp id {}", player->GetGUID().ToString(), itr->second->GetTypeId());
128}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:112
std::string ToString() const
Definition: ObjectGuid.cpp:47

References _lock, Object::GetGUID(), LOG_DEBUG, m_OutdoorPvPMap, and ObjectGuid::ToString().

◆ HandlePlayerLeaveZone()

void OutdoorPvPMgr::HandlePlayerLeaveZone ( Player player,
uint32  areaflag 
)
131{
132 auto itr = m_OutdoorPvPMap.find(zoneid);
133 if (itr == m_OutdoorPvPMap.end())
134 return;
135
136 std::lock_guard<std::mutex> guard(_lock); // pussywizard
137
138 // teleport: remove once in removefromworld, once in updatezone
139 if (!itr->second->HasPlayer(player))
140 return;
141
142 itr->second->HandlePlayerLeaveZone(player, zoneid);
143 LOG_DEBUG("outdoorpvp", "Player {} left outdoorpvp id {}", player->GetGUID().ToString(), itr->second->GetTypeId());
144}

References _lock, Object::GetGUID(), LOG_DEBUG, m_OutdoorPvPMap, and ObjectGuid::ToString().

◆ HandlePlayerResurrects()

void OutdoorPvPMgr::HandlePlayerResurrects ( Player player,
uint32  areaflag 
)
252{
253 auto itr = m_OutdoorPvPMap.find(zoneid);
254 if (itr == m_OutdoorPvPMap.end())
255 return;
256
257 // pussywizard: no mutex because not affecting other players
258
259 if (itr->second->HasPlayer(player))
260 {
261 itr->second->HandlePlayerResurrects(player, zoneid);
262 }
263}

References m_OutdoorPvPMap.

◆ InitOutdoorPvP()

void OutdoorPvPMgr::InitOutdoorPvP ( )
43{
44 uint32 oldMSTime = getMSTime();
45
46 // 0 1
47 QueryResult result = WorldDatabase.Query("SELECT TypeId, ScriptName FROM outdoorpvp_template");
48
49 if (!result)
50 {
51 LOG_WARN("server.loading", ">> Loaded 0 outdoor PvP definitions. DB table `outdoorpvp_template` is empty.");
52 LOG_INFO("server.loading", " ");
53 return;
54 }
55
56 uint32 count = 0;
57 uint32 typeId = 0;
58
59 for (auto const& fields : *result)
60 {
61 typeId = fields[0].Get<uint8>();
62
64 continue;
65
66 if (typeId >= MAX_OUTDOORPVP_TYPES)
67 {
68 LOG_ERROR("sql.sql", "Invalid OutdoorPvPTypes value {} in outdoorpvp_template; skipped.", typeId);
69 continue;
70 }
71
72 auto data = std::make_unique<OutdoorPvPData>();
73 auto realTypeId = OutdoorPvPTypes(typeId);
74 data->TypeId = realTypeId;
75 data->ScriptId = sObjectMgr->GetScriptId(fields[1].Get<std::string>());
76 m_OutdoorPvPDatas[realTypeId] = std::move(data);
77
78 ++count;
79 }
80
81 for (uint8 i = 1; i < MAX_OUTDOORPVP_TYPES; ++i)
82 {
83 auto iter = m_OutdoorPvPDatas.find(OutdoorPvPTypes(i));
84 if (iter == m_OutdoorPvPDatas.end())
85 {
86 LOG_ERROR("sql.sql", "Could not initialize OutdoorPvP object for type ID {}; no entry in database.", uint32(i));
87 continue;
88 }
89
90 auto pvp = std::unique_ptr<OutdoorPvP>(sScriptMgr->CreateOutdoorPvP(iter->second.get()));
91 if (!pvp)
92 {
93 LOG_ERROR("outdoorpvp", "Could not initialize OutdoorPvP object for type ID {}; got nullptr pointer from script.", uint32(i));
94 continue;
95 }
96
97 if (!pvp->SetupOutdoorPvP())
98 {
99 LOG_ERROR("outdoorpvp", "Could not initialize OutdoorPvP object for type ID {}; SetupOutdoorPvP failed.", uint32(i));
100 continue;
101 }
102
103 m_OutdoorPvPSet.emplace_back(std::move(pvp));
104 }
105
106 LOG_INFO("server.loading", ">> Loaded {} outdoor PvP definitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
107 LOG_INFO("server.loading", " ");
108}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
#define LOG_WARN(filterType__,...)
Definition: Log.h:161
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
std::uint8_t uint8
Definition: Define.h:109
std::uint32_t uint32
Definition: Define.h:107
#define sObjectMgr
Definition: ObjectMgr.h:1635
@ DISABLE_TYPE_OUTDOORPVP
Definition: DisableMgr.h:32
#define sScriptMgr
Definition: ScriptMgr.h:709
OutdoorPvPTypes
Definition: OutdoorPvP.h:28
#define MAX_OUTDOORPVP_TYPES
Definition: OutdoorPvP.h:38
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
bool IsDisabledFor(DisableType type, uint32 entry, Unit const *unit, uint8 flags)
Definition: DisableMgr.cpp:307

References DISABLE_TYPE_OUTDOORPVP, getMSTime(), GetMSTimeDiffToNow(), DisableMgr::IsDisabledFor(), LOG_ERROR, LOG_INFO, LOG_WARN, m_OutdoorPvPDatas, m_OutdoorPvPSet, MAX_OUTDOORPVP_TYPES, sObjectMgr, sScriptMgr, and WorldDatabase.

◆ instance()

OutdoorPvPMgr * OutdoorPvPMgr::instance ( )
static
31{
33 return &instance;
34}
Definition: OutdoorPvPMgr.h:39
static OutdoorPvPMgr * instance()
Definition: OutdoorPvPMgr.cpp:30

References instance().

Referenced by instance().

◆ Update()

void OutdoorPvPMgr::Update ( uint32  diff)
159{
160 m_UpdateTimer += diff;
161
163 {
164 for (auto const& itr : m_OutdoorPvPSet)
165 {
166 itr->Update(m_UpdateTimer);
167 }
168
169 m_UpdateTimer = 0;
170 }
171}
#define OUTDOORPVP_OBJECTIVE_UPDATE_INTERVAL
Definition: OutdoorPvPMgr.h:21

References m_OutdoorPvPSet, m_UpdateTimer, and OUTDOORPVP_OBJECTIVE_UPDATE_INTERVAL.

Member Data Documentation

◆ _lock

std::mutex OutdoorPvPMgr::_lock

◆ m_OutdoorPvPDatas

std::map<OutdoorPvPTypes, std::unique_ptr<OutdoorPvPData> > OutdoorPvPMgr::m_OutdoorPvPDatas
private

Referenced by Die(), and InitOutdoorPvP().

◆ m_OutdoorPvPMap

◆ m_OutdoorPvPSet

std::vector<std::unique_ptr<OutdoorPvP> > OutdoorPvPMgr::m_OutdoorPvPSet
private

◆ m_UpdateTimer

uint32 OutdoorPvPMgr::m_UpdateTimer
private

Referenced by OutdoorPvPMgr(), and Update().