AzeorthCore 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 
)
151 : 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)
152{
153 sScriptMgr->OnConstructInstanceSave(this);
154}
bool IsSharedDifficultyMap(uint32 mapid)
Definition: DBCStores.cpp:817
#define sScriptMgr
Definition: ScriptMgr.h:2690
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 ( )
157{
158 ASSERT(m_playerList.empty());
159
160 sScriptMgr->OnDestructInstanceSave(this);
161}
#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)
217{
218 std::lock_guard<std::mutex> guard(_lock);
219 m_playerList.push_back(guid);
220}
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 ( )
212{
213 return sMapStore.LookupEntry(m_mapid);
214}
DBCStorage< MapEntry > sMapStore(MapEntryfmt)

References m_mapid, and sMapStore.

◆ GetMapId()

◆ GetResetTime()

◆ GetResetTimeForDB()

time_t InstanceSave::GetResetTimeForDB ( )
196{
197 // only save the reset time for normal instances
198 MapEntry const* entry = sMapStore.LookupEntry(GetMapId());
199 if (!entry || entry->map_type == MAP_RAID || GetDifficulty() == DUNGEON_DIFFICULTY_HEROIC)
200 return 0;
201 else
202 return GetResetTime();
203}
@ 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 ( )
207{
208 return sObjectMgr->GetInstanceTemplate(m_mapid);
209}
#define sObjectMgr
Definition: ObjectMgr.h:1612

References m_mapid, and sObjectMgr.

◆ InsertToDB()

void InstanceSave::InsertToDB ( )
164{
165 std::string data;
166 uint32 completedEncounters = 0;
167
168 Map* map = sMapMgr->FindMap(GetMapId(), m_instanceid);
169 if (map)
170 {
171 ASSERT(map->IsDungeon());
172 if (InstanceScript* instanceScript = map->ToInstanceMap()->GetInstanceScript())
173 {
174 data = instanceScript->GetSaveData();
175 completedEncounters = instanceScript->GetCompletedEncounterMask();
176
177 // pussywizard:
178 SetInstanceData(data);
179 SetCompletedEncounterMask(completedEncounters);
180 }
181 }
182
184 stmt->SetData(0, m_instanceid);
185 stmt->SetData(1, GetMapId());
186 stmt->SetData(2, uint32(GetResetTimeForDB()));
187 stmt->SetData(3, uint8(GetDifficulty()));
188 stmt->SetData(4, completedEncounters);
189 stmt->SetData(5, data);
190 CharacterDatabase.Execute(stmt);
191
192 sScriptMgr->OnInstanceSave(this);
193}
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:212
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:195
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 
)
223{
224 bool deleteSave = false;
225 {
226 std::lock_guard lg(_lock);
227 m_playerList.remove(guid);
228
229 // ism passed as an argument to avoid calling via singleton (might result in a deadlock)
230 deleteSave = ism->DeleteInstanceSaveIfNeeded(this, false, false);
231 }
232
233 // Delete save now (avoid mutex memory corruption)
234 if (deleteSave)
235 {
236 delete this;
237 }
238
239 return deleteSave;
240}
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().