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

#include "InstanceSaveMgr.h"

Public Member Functions

 InstanceSave (uint16 MapId, uint32 InstanceId, Difficulty difficulty, time_t resetTime, time_t extendedResetTime)
 
 ~InstanceSave ()
 
uint32 GetInstanceId () const
 
uint32 GetMapId () const
 
Difficulty GetDifficulty () const
 
void InsertToDB ()
 
std::string GetInstanceData () const
 
void SetInstanceData (std::string str)
 
uint32 GetCompletedEncounterMask () const
 
void SetCompletedEncounterMask (uint32 mask)
 
time_t GetResetTime () const
 
time_t GetExtendedResetTime () const
 
time_t GetResetTimeForDB ()
 
void SetResetTime (time_t resetTime)
 
void SetExtendedResetTime (time_t extendedResetTime)
 
bool CanReset () const
 
void SetCanReset (bool canReset)
 
InstanceTemplate const * GetTemplate ()
 
MapEntry const * GetMapEntry ()
 
void AddPlayer (ObjectGuid guid)
 
bool RemovePlayer (ObjectGuid guid, InstanceSaveMgr *ism)
 

Private Attributes

GuidList m_playerList
 
time_t m_resetTime
 
time_t m_extendedResetTime
 
uint32 m_instanceid
 
uint32 m_mapid
 
Difficulty m_difficulty
 
bool m_canReset
 
std::string m_instanceData
 
uint32 m_completedEncounterMask
 
std::mutex _lock
 

Friends

class InstanceSaveMgr
 

Detailed Description

Constructor & Destructor Documentation

◆ InstanceSave()

InstanceSave::InstanceSave ( uint16  MapId,
uint32  InstanceId,
Difficulty  difficulty,
time_t  resetTime,
time_t  extendedResetTime 
)
153 : m_resetTime(resetTime), m_extendedResetTime(extendedResetTime), m_instanceid(InstanceId), m_mapid(MapId), m_difficulty(IsSharedDifficultyMap(MapId) ? Difficulty(difficulty % 2) : difficulty), m_canReset(true), m_instanceData(""), m_completedEncounterMask(0)
154{
155 sScriptMgr->OnConstructInstanceSave(this);
156}
bool IsSharedDifficultyMap(uint32 mapid)
Definition: DBCStores.cpp:822
#define sScriptMgr
Definition: ScriptMgr.h:2702
Difficulty
Definition: DBCEnums.h:271
uint32 m_instanceid
Definition: InstanceSaveMgr.h:94
uint32 m_mapid
Definition: InstanceSaveMgr.h:95
std::string m_instanceData
Definition: InstanceSaveMgr.h:98
Difficulty m_difficulty
Definition: InstanceSaveMgr.h:96
bool m_canReset
Definition: InstanceSaveMgr.h:97
time_t m_resetTime
Definition: InstanceSaveMgr.h:92
time_t m_extendedResetTime
Definition: InstanceSaveMgr.h:93
uint32 m_completedEncounterMask
Definition: InstanceSaveMgr.h:99

References sScriptMgr.

◆ ~InstanceSave()

InstanceSave::~InstanceSave ( )
159{
160 ASSERT(m_playerList.empty());
161
162 sScriptMgr->OnDestructInstanceSave(this);
163}
#define ASSERT
Definition: Errors.h:68
GuidList m_playerList
Definition: InstanceSaveMgr.h:91

References ASSERT, m_playerList, and sScriptMgr.

Member Function Documentation

◆ AddPlayer()

void InstanceSave::AddPlayer ( ObjectGuid  guid)
219{
220 std::lock_guard<std::mutex> guard(_lock);
221 m_playerList.push_back(guid);
222}
std::mutex _lock
Definition: InstanceSaveMgr.h:101

References _lock, and m_playerList.

Referenced by InstanceSaveMgr::PlayerBindToInstance().

◆ CanReset()

◆ GetCompletedEncounterMask()

uint32 InstanceSave::GetCompletedEncounterMask ( ) const
inline

◆ GetDifficulty()

◆ GetExtendedResetTime()

◆ GetInstanceData()

std::string InstanceSave::GetInstanceData ( ) const
inline
69{ return m_instanceData; }

References m_instanceData.

Referenced by MapInstanced::CreateInstance().

◆ GetInstanceId()

◆ GetMapEntry()

MapEntry const * InstanceSave::GetMapEntry ( )
214{
215 return sMapStore.LookupEntry(m_mapid);
216}
DBCStorage< MapEntry > sMapStore(MapEntryfmt)

References m_mapid, and sMapStore.

◆ GetMapId()

◆ GetResetTime()

◆ GetResetTimeForDB()

time_t InstanceSave::GetResetTimeForDB ( )
198{
199 // only save the reset time for normal instances
200 MapEntry const* entry = sMapStore.LookupEntry(GetMapId());
201 if (!entry || entry->map_type == MAP_RAID || GetDifficulty() == DUNGEON_DIFFICULTY_HEROIC)
202 return 0;
203 else
204 return GetResetTime();
205}
@ MAP_RAID
Definition: DBCEnums.h:353
@ DUNGEON_DIFFICULTY_HEROIC
Definition: DBCEnums.h:275
uint32 GetMapId() const
Definition: InstanceSaveMgr.h:62
Difficulty GetDifficulty() const
Definition: InstanceSaveMgr.h:63
time_t GetResetTime() const
Definition: InstanceSaveMgr.h:75
Definition: DBCStructure.h:1308
uint32 map_type
Definition: DBCStructure.h:1311

References DUNGEON_DIFFICULTY_HEROIC, GetDifficulty(), GetMapId(), GetResetTime(), MAP_RAID, MapEntry::map_type, and sMapStore.

Referenced by InsertToDB().

◆ GetTemplate()

InstanceTemplate const * InstanceSave::GetTemplate ( )
209{
210 return sObjectMgr->GetInstanceTemplate(m_mapid);
211}
#define sObjectMgr
Definition: ObjectMgr.h:1640

References m_mapid, and sObjectMgr.

◆ InsertToDB()

void InstanceSave::InsertToDB ( )
166{
167 std::string data;
168 uint32 completedEncounters = 0;
169
170 Map* map = sMapMgr->FindMap(GetMapId(), m_instanceid);
171 if (map)
172 {
173 ASSERT(map->IsDungeon());
174 if (InstanceScript* instanceScript = map->ToInstanceMap()->GetInstanceScript())
175 {
176 data = instanceScript->GetSaveData();
177 completedEncounters = instanceScript->GetCompletedEncounterMask();
178
179 // pussywizard:
180 SetInstanceData(data);
181 SetCompletedEncounterMask(completedEncounters);
182 }
183 }
184
186 stmt->SetData(0, m_instanceid);
187 stmt->SetData(1, GetMapId());
188 stmt->SetData(2, uint32(GetResetTimeForDB()));
189 stmt->SetData(3, uint8(GetDifficulty()));
190 stmt->SetData(4, completedEncounters);
191 stmt->SetData(5, data);
192 CharacterDatabase.Execute(stmt);
193
194 sScriptMgr->OnInstanceSave(this);
195}
std::uint8_t uint8
Definition: Define.h:110
std::uint32_t uint32
Definition: Define.h:108
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
@ CHAR_INS_INSTANCE_SAVE
Definition: CharacterDatabase.h:211
#define sMapMgr
Definition: MapMgr.h:221
Definition: PreparedStatement.h:158
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:78
time_t GetResetTimeForDB()
Definition: InstanceSaveMgr.cpp:197
void SetInstanceData(std::string str)
Definition: InstanceSaveMgr.h:70
void SetCompletedEncounterMask(uint32 mask)
Definition: InstanceSaveMgr.h:72
Definition: InstanceScript.h:140
Definition: Map.h:312
bool IsDungeon() const
Definition: Map.h:447
InstanceMap * ToInstanceMap()
Definition: Map.h:544
InstanceScript * GetInstanceScript()
Definition: Map.h:825

References ASSERT, CHAR_INS_INSTANCE_SAVE, CharacterDatabase, GetDifficulty(), InstanceMap::GetInstanceScript(), GetMapId(), GetResetTimeForDB(), Map::IsDungeon(), m_instanceid, SetCompletedEncounterMask(), PreparedStatementBase::SetData(), SetInstanceData(), sMapMgr, sScriptMgr, and Map::ToInstanceMap().

Referenced by InstanceSaveMgr::AddInstanceSave().

◆ RemovePlayer()

bool InstanceSave::RemovePlayer ( ObjectGuid  guid,
InstanceSaveMgr ism 
)
225{
226 bool deleteSave = false;
227 {
228 std::lock_guard lg(_lock);
229 m_playerList.remove(guid);
230
231 // ism passed as an argument to avoid calling via singleton (might result in a deadlock)
232 deleteSave = ism->DeleteInstanceSaveIfNeeded(this, false, false);
233 }
234
235 // Delete save now (avoid mutex memory corruption)
236 if (deleteSave)
237 {
238 delete this;
239 }
240
241 return deleteSave;
242}
bool DeleteInstanceSaveIfNeeded(uint32 InstanceId, bool skipMapCheck)
Definition: InstanceSaveMgr.cpp:114

References _lock, InstanceSaveMgr::DeleteInstanceSaveIfNeeded(), and m_playerList.

Referenced by InstanceSaveMgr::LoadCharacterBinds(), InstanceSaveMgr::PlayerBindToInstance(), InstanceSaveMgr::PlayerUnbindInstance(), and InstanceSaveMgr::PlayerUnbindInstanceNotExtended().

◆ SetCanReset()

void InstanceSave::SetCanReset ( bool  canReset)
inline
82{ m_canReset = canReset; }

References m_canReset.

Referenced by InstanceSaveMgr::PlayerBindToInstance().

◆ SetCompletedEncounterMask()

void InstanceSave::SetCompletedEncounterMask ( uint32  mask)
inline

◆ SetExtendedResetTime()

void InstanceSave::SetExtendedResetTime ( time_t  extendedResetTime)
inline
79{ m_extendedResetTime = extendedResetTime; }

References m_extendedResetTime.

◆ SetInstanceData()

void InstanceSave::SetInstanceData ( std::string  str)
inline

◆ SetResetTime()

void InstanceSave::SetResetTime ( time_t  resetTime)
inline
78{ m_resetTime = resetTime; }

References m_resetTime.

Referenced by InstanceSaveMgr::LoadInstanceSaves().

Friends And Related Function Documentation

◆ InstanceSaveMgr

friend class InstanceSaveMgr
friend

Member Data Documentation

◆ _lock

std::mutex InstanceSave::_lock
private

Referenced by AddPlayer(), and RemovePlayer().

◆ m_canReset

bool InstanceSave::m_canReset
private

Referenced by CanReset(), and SetCanReset().

◆ m_completedEncounterMask

uint32 InstanceSave::m_completedEncounterMask
private

◆ m_difficulty

Difficulty InstanceSave::m_difficulty
private

Referenced by GetDifficulty().

◆ m_extendedResetTime

time_t InstanceSave::m_extendedResetTime
private

◆ m_instanceData

std::string InstanceSave::m_instanceData
private

Referenced by GetInstanceData(), and SetInstanceData().

◆ m_instanceid

uint32 InstanceSave::m_instanceid
private

Referenced by GetInstanceId(), and InsertToDB().

◆ m_mapid

uint32 InstanceSave::m_mapid
private

Referenced by GetMapEntry(), GetMapId(), and GetTemplate().

◆ m_playerList

◆ m_resetTime

time_t InstanceSave::m_resetTime
private

Referenced by GetResetTime(), and SetResetTime().