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 
)
152 : 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)
153{
154 sScriptMgr->OnConstructInstanceSave(this);
155}
#define sScriptMgr
Definition: ScriptMgr.h:708
bool IsSharedDifficultyMap(uint32 mapid)
Definition: DBCStores.cpp:829
Difficulty
Definition: DBCEnums.h:266
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 ( )
158{
159 ASSERT(m_playerList.empty());
160
161 sScriptMgr->OnDestructInstanceSave(this);
162}
#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)
218{
219 std::lock_guard<std::mutex> guard(_lock);
220 m_playerList.push_back(guid);
221}
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 ( )
213{
214 return sMapStore.LookupEntry(m_mapid);
215}
DBCStorage< MapEntry > sMapStore(MapEntryfmt)

References m_mapid, and sMapStore.

◆ GetMapId()

◆ GetResetTime()

◆ GetResetTimeForDB()

time_t InstanceSave::GetResetTimeForDB ( )
197{
198 // only save the reset time for normal instances
199 MapEntry const* entry = sMapStore.LookupEntry(GetMapId());
200 if (!entry || entry->map_type == MAP_RAID || GetDifficulty() == DUNGEON_DIFFICULTY_HEROIC)
201 return 0;
202 else
203 return GetResetTime();
204}
@ MAP_RAID
Definition: DBCEnums.h:348
@ DUNGEON_DIFFICULTY_HEROIC
Definition: DBCEnums.h:270
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:1325
uint32 map_type
Definition: DBCStructure.h:1328

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

Referenced by InsertToDB().

◆ GetTemplate()

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

References m_mapid, and sObjectMgr.

◆ InsertToDB()

void InstanceSave::InsertToDB ( )
165{
166 std::string data;
167 uint32 completedEncounters = 0;
168
169 Map* map = sMapMgr->FindMap(GetMapId(), m_instanceid);
170 if (map)
171 {
172 ASSERT(map->IsDungeon());
173 if (InstanceScript* instanceScript = map->ToInstanceMap()->GetInstanceScript())
174 {
175 data = instanceScript->GetSaveData();
176 completedEncounters = instanceScript->GetCompletedEncounterMask();
177
178 // pussywizard:
179 SetInstanceData(data);
180 SetCompletedEncounterMask(completedEncounters);
181 }
182 }
183
185 stmt->SetData(0, m_instanceid);
186 stmt->SetData(1, GetMapId());
187 stmt->SetData(2, uint32(GetResetTimeForDB()));
188 stmt->SetData(3, uint8(GetDifficulty()));
189 stmt->SetData(4, completedEncounters);
190 stmt->SetData(5, data);
191 CharacterDatabase.Execute(stmt);
192
193 sScriptMgr->OnInstanceSave(this);
194}
std::uint8_t uint8
Definition: Define.h:109
std::uint32_t uint32
Definition: Define.h:107
#define sMapMgr
Definition: MapMgr.h:221
@ CHAR_INS_INSTANCE_SAVE
Definition: CharacterDatabase.h:211
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
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:196
void SetInstanceData(std::string str)
Definition: InstanceSaveMgr.h:70
void SetCompletedEncounterMask(uint32 mask)
Definition: InstanceSaveMgr.h:72
Definition: InstanceScript.h:142
Definition: Map.h:313
bool IsDungeon() const
Definition: Map.h:448
InstanceMap * ToInstanceMap()
Definition: Map.h:546
InstanceScript * GetInstanceScript()
Definition: Map.h:831

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

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().