TrinityCore
Loading...
Searching...
No Matches
OutdoorPvPMgr.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 "OutdoorPvPMgr.h"
19#include "DatabaseEnv.h"
20#include "DisableMgr.h"
21#include "Log.h"
22#include "ObjectMgr.h"
23#include "Player.h"
24#include "ScriptMgr.h"
25
30
32{
33 for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
34 delete *itr;
35
36 m_OutdoorPvPSet.clear();
37
38 m_OutdoorPvPDatas.fill(0);
39
40 m_OutdoorPvPMap.clear();
41}
42
48
50{
51 uint32 oldMSTime = getMSTime();
52
53 // 0 1
54 QueryResult result = WorldDatabase.Query("SELECT TypeId, ScriptName FROM outdoorpvp_template");
55 if (!result)
56 {
57 TC_LOG_INFO("server.loading", ">> Loaded 0 outdoor PvP definitions. DB table `outdoorpvp_template` is empty.");
58 return;
59 }
60
61 uint32 count = 0;
62 uint32 typeId = 0;
63
64 do
65 {
66 Field* fields = result->Fetch();
67
68 typeId = fields[0].GetUInt8();
69
71 continue;
72
73 if (typeId >= MAX_OUTDOORPVP_TYPES)
74 {
75 TC_LOG_ERROR("sql.sql", "Invalid OutdoorPvPTypes value {} in outdoorpvp_template; skipped.", typeId);
76 continue;
77 }
78
79 OutdoorPvPTypes realTypeId = OutdoorPvPTypes(typeId);
80 m_OutdoorPvPDatas[realTypeId] = sObjectMgr->GetScriptId(fields[1].GetString());
81
82 ++count;
83 }
84 while (result->NextRow());
85
86 OutdoorPvP* pvp;
87 for (uint8 i = 1; i < MAX_OUTDOORPVP_TYPES; ++i)
88 {
89 if (!m_OutdoorPvPDatas[i])
90 {
91 TC_LOG_ERROR("sql.sql", "Could not initialize OutdoorPvP object for type ID {}; no entry in database.", uint32(i));
92 continue;
93 }
94
95 pvp = sScriptMgr->CreateOutdoorPvP(m_OutdoorPvPDatas[i]);
96 if (!pvp)
97 {
98 TC_LOG_ERROR("outdoorpvp", "Could not initialize OutdoorPvP object for type ID {}; got NULL pointer from script.", uint32(i));
99 continue;
100 }
101
102 if (!pvp->SetupOutdoorPvP())
103 {
104 TC_LOG_ERROR("outdoorpvp", "Could not initialize OutdoorPvP object for type ID {}; SetupOutdoorPvP failed.", uint32(i));
105 delete pvp;
106 continue;
107 }
108
109 m_OutdoorPvPSet.push_back(pvp);
110 }
111
112 TC_LOG_INFO("server.loading", ">> Loaded {} outdoor PvP definitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
113}
114
116{
117 m_OutdoorPvPMap[zoneid] = handle;
118}
119
121{
122 OutdoorPvPMap::iterator itr = m_OutdoorPvPMap.find(zoneid);
123 if (itr == m_OutdoorPvPMap.end())
124 return;
125
126 if (itr->second->HasPlayer(player))
127 return;
128
129 itr->second->HandlePlayerEnterZone(player, zoneid);
130 TC_LOG_DEBUG("outdoorpvp", "Player {} entered outdoorpvp id {}", player->GetGUID().ToString(), itr->second->GetTypeId());
131}
132
134{
135 OutdoorPvPMap::iterator itr = m_OutdoorPvPMap.find(zoneid);
136 if (itr == m_OutdoorPvPMap.end())
137 return;
138
139 // teleport: remove once in removefromworld, once in updatezone
140 if (!itr->second->HasPlayer(player))
141 return;
142
143 itr->second->HandlePlayerLeaveZone(player, zoneid);
144 TC_LOG_DEBUG("outdoorpvp", "Player {} left outdoorpvp id {}", player->GetGUID().ToString(), itr->second->GetTypeId());
145}
146
148{
149 OutdoorPvPMap::iterator itr = m_OutdoorPvPMap.find(zoneid);
150 if (itr == m_OutdoorPvPMap.end())
151 {
152 // no handle for this zone, return
153 return nullptr;
154 }
155 return itr->second;
156}
157
159{
160 m_UpdateTimer += diff;
162 {
163 for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
164 (*itr)->Update(m_UpdateTimer);
165 m_UpdateTimer = 0;
166 }
167}
168
170{
171 for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
172 {
173 if ((*itr)->HandleCustomSpell(player, spellId, go))
174 return true;
175 }
176 return false;
177}
178
180{
181 OutdoorPvPMap::iterator itr = m_OutdoorPvPMap.find(zoneId);
182 if (itr != m_OutdoorPvPMap.end())
183 return itr->second;
184 else
185 return nullptr;
186}
187
189{
190 for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
191 {
192 if ((*itr)->HandleOpenGo(player, go))
193 return true;
194 }
195 return false;
196}
197
198void OutdoorPvPMgr::HandleGossipOption(Player* player, Creature* creature, uint32 gossipid)
199{
200 for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
201 {
202 if ((*itr)->HandleGossipOption(player, creature, gossipid))
203 return;
204 }
205}
206
207bool OutdoorPvPMgr::CanTalkTo(Player* player, Creature* creature, GossipMenuItems const& gso)
208{
209 for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
210 {
211 if ((*itr)->CanTalkTo(player, creature, gso))
212 return true;
213 }
214 return false;
215}
216
218{
219 for (OutdoorPvPSet::iterator itr = m_OutdoorPvPSet.begin(); itr != m_OutdoorPvPSet.end(); ++itr)
220 {
221 if ((*itr)->HandleDropFlag(player, spellId))
222 return;
223 }
224}
225
227{
228 OutdoorPvPMap::iterator itr = m_OutdoorPvPMap.find(zoneid);
229 if (itr == m_OutdoorPvPMap.end())
230 return;
231
232 if (itr->second->HasPlayer(player))
233 itr->second->HandlePlayerResurrects(player, zoneid);
234}
235
237{
238 if (BroadcastText const* bct = sObjectMgr->GetBroadcastText(id))
239 return bct->GetText(locale);
240
241 TC_LOG_ERROR("outdoorpvp", "Can not find DefenseMessage (Zone: {}, Id: {}). BroadcastText (Id: {}) does not exist.", zoneId, id, id);
242 return "";
243}
LocaleConstant
Definition Common.h:48
std::shared_ptr< ResultSet > QueryResult
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
@ DISABLE_TYPE_OUTDOORPVP
Definition DisableMgr.h:32
#define TC_LOG_DEBUG(filterType__,...)
Definition Log.h:156
#define TC_LOG_ERROR(filterType__,...)
Definition Log.h:165
#define TC_LOG_INFO(filterType__,...)
Definition Log.h:159
#define sObjectMgr
Definition ObjectMgr.h:1721
#define OUTDOORPVP_OBJECTIVE_UPDATE_INTERVAL
OutdoorPvPTypes
Definition OutdoorPvP.h:28
@ MAX_OUTDOORPVP_TYPES
Definition OutdoorPvP.h:36
#define sScriptMgr
Definition ScriptMgr.h:1168
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:57
uint32 getMSTime()
Definition Timer.h:33
Class used to access individual fields of database query result.
Definition Field.h:92
uint8 GetUInt8() const
Definition Field.cpp:29
std::string ToString() const
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
bool HandleCustomSpell(Player *player, uint32 spellId, GameObject *go)
static OutdoorPvPMgr * instance()
OutdoorPvPMap m_OutdoorPvPMap
ZoneScript * GetZoneScript(uint32 zoneId)
void AddZone(uint32 zoneid, OutdoorPvP *handle)
void HandlePlayerLeaveZone(Player *player, uint32 areaflag)
OutdoorPvPSet m_OutdoorPvPSet
bool CanTalkTo(Player *player, Creature *creature, GossipMenuItems const &gso)
bool HandleOpenGo(Player *player, GameObject *go)
void Update(uint32 diff)
void HandleDropFlag(Player *player, uint32 spellId)
OutdoorPvP * GetOutdoorPvPToZoneId(uint32 zoneid)
OutdoorPvPScriptIds m_OutdoorPvPDatas
void HandlePlayerEnterZone(Player *player, uint32 areaflag)
uint32 m_UpdateTimer
void HandlePlayerResurrects(Player *player, uint32 areaflag)
void HandleGossipOption(Player *player, Creature *creature, uint32 gossipid)
std::string GetDefenseMessage(uint32 zoneId, uint32 id, LocaleConstant locale) const
virtual void HandlePlayerEnterZone(Player *player, uint32 zone)
virtual bool Update(uint32 diff)
virtual bool SetupOutdoorPvP()
Definition OutdoorPvP.h:216
bool IsDisabledFor(DisableType type, uint32 entry, WorldObject const *ref, uint8 flags)