TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
InstanceSave Class Reference

#include <InstanceSaveMgr.h>

Public Types

typedef std::list< Player * > PlayerListType
 
typedef std::list< Group * > GroupListType
 

Public Member Functions

 InstanceSave (uint16 MapId, uint32 InstanceId, Difficulty difficulty, time_t resetTime, bool canReset)
 
 ~InstanceSave ()
 
uint32 GetPlayerCount () const
 
uint32 GetGroupCount () const
 
uint32 GetInstanceId () const
 
uint32 GetMapId () const
 
void SaveToDB ()
 
void DeleteFromDB ()
 
time_t GetResetTime () const
 
void SetResetTime (time_t resetTime)
 
time_t GetResetTimeForDB ()
 
InstanceTemplate constGetTemplate ()
 
MapEntry constGetMapEntry ()
 
void AddPlayer (Player *player)
 
bool RemovePlayer (Player *player)
 
void AddGroup (Group *group)
 
bool RemoveGroup (Group *group)
 
bool CanReset () const
 
void SetCanReset (bool canReset)
 
Difficulty GetDifficultyID () const
 
void SetToDelete (bool toDelete)
 

Private Member Functions

bool UnloadIfEmpty ()
 

Private Attributes

PlayerListType m_playerList
 
GroupListType m_groupList
 
time_t m_resetTime
 
uint32 m_instanceid
 
uint32 m_mapid
 
Difficulty m_difficulty
 
bool m_canReset
 
bool m_toDelete
 
std::mutex _playerListLock
 

Friends

class InstanceSaveManager
 

Member Typedef Documentation

typedef std::list<Group*> InstanceSave::GroupListType
typedef std::list<Player*> InstanceSave::PlayerListType

Constructor & Destructor Documentation

InstanceSave::InstanceSave ( uint16  MapId,
uint32  InstanceId,
Difficulty  difficulty,
time_t  resetTime,
bool  canReset 
)
177 : m_resetTime(resetTime), m_instanceid(InstanceId), m_mapid(MapId),
178  m_difficulty(difficulty), m_canReset(canReset), m_toDelete(false) { }
Difficulty m_difficulty
Definition: InstanceSaveMgr.h:141
bool m_canReset
Definition: InstanceSaveMgr.h:142
uint32 m_instanceid
Definition: InstanceSaveMgr.h:139
uint32 m_mapid
Definition: InstanceSaveMgr.h:140
bool m_toDelete
Definition: InstanceSaveMgr.h:143
time_t m_resetTime
Definition: InstanceSaveMgr.h:138
InstanceSave::~InstanceSave ( )
181 {
182  // the players and groups must be unbound before deleting the save
183  ASSERT(m_playerList.empty() && m_groupList.empty());
184 }
PlayerListType m_playerList
Definition: InstanceSaveMgr.h:136
#define ASSERT
Definition: Errors.h:55
GroupListType m_groupList
Definition: InstanceSaveMgr.h:137

Member Function Documentation

void InstanceSave::AddGroup ( Group group)
inline
103 { m_groupList.push_back(group); }
GroupListType m_groupList
Definition: InstanceSaveMgr.h:137

+ Here is the caller graph for this function:

void InstanceSave::AddPlayer ( Player player)
inline
84  {
85  std::lock_guard<std::mutex> lock(_playerListLock);
86  m_playerList.push_back(player);
87  }
PlayerListType m_playerList
Definition: InstanceSaveMgr.h:136
std::mutex _playerListLock
Definition: InstanceSaveMgr.h:145
bool InstanceSave::CanReset ( ) const
inline
116 { return m_canReset; }
bool m_canReset
Definition: InstanceSaveMgr.h:142

+ Here is the caller graph for this function:

void InstanceSave::DeleteFromDB ( )
238 {
240 }
uint32 GetInstanceId() const
Definition: InstanceSaveMgr.h:64
static void DeleteInstanceFromDB(uint32 instanceid)
Definition: InstanceSaveMgr.cpp:129

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Difficulty InstanceSave::GetDifficultyID ( ) const
inline
121 { return m_difficulty; }
Difficulty m_difficulty
Definition: InstanceSaveMgr.h:141

+ Here is the caller graph for this function:

uint32 InstanceSave::GetGroupCount ( ) const
inline
59 { return uint32(m_groupList.size()); }
uint32_t uint32
Definition: g3dmath.h:168
GroupListType m_groupList
Definition: InstanceSaveMgr.h:137

+ Here is the caller graph for this function:

uint32 InstanceSave::GetInstanceId ( ) const
inline
64 { return m_instanceid; }
uint32 m_instanceid
Definition: InstanceSaveMgr.h:139

+ Here is the caller graph for this function:

MapEntry const * InstanceSave::GetMapEntry ( )
233 {
234  return sMapStore.LookupEntry(m_mapid);
235 }
uint32 m_mapid
Definition: InstanceSaveMgr.h:140
DBCStorage< MapEntry > sMapStore(Mapfmt)
uint32 InstanceSave::GetMapId ( ) const
inline
65 { return m_mapid; }
uint32 m_mapid
Definition: InstanceSaveMgr.h:140

+ Here is the caller graph for this function:

uint32 InstanceSave::GetPlayerCount ( ) const
inline
58 { return uint32(m_playerList.size()); }
PlayerListType m_playerList
Definition: InstanceSaveMgr.h:136
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the caller graph for this function:

time_t InstanceSave::GetResetTime ( ) const
inline
74 { return m_resetTime; }
time_t m_resetTime
Definition: InstanceSaveMgr.h:138

+ Here is the caller graph for this function:

time_t InstanceSave::GetResetTimeForDB ( )
217 {
218  // only save the reset time for normal instances
219  const MapEntry* entry = sMapStore.LookupEntry(GetMapId());
220  if (!entry || entry->IsRaid() || GetDifficultyID() == DIFFICULTY_HEROIC)
221  return 0;
222  else
223  return GetResetTime();
224 }
Definition: DBCEnums.h:406
Definition: DBCStructure.h:830
bool IsRaid() const
Definition: DBCStructure.h:860
uint32 GetMapId() const
Definition: InstanceSaveMgr.h:65
Difficulty GetDifficultyID() const
Definition: InstanceSaveMgr.h:121
DBCStorage< MapEntry > sMapStore(Mapfmt)
time_t GetResetTime() const
Definition: InstanceSaveMgr.h:74

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

InstanceTemplate const * InstanceSave::GetTemplate ( )
228 {
229  return sObjectMgr->GetInstanceTemplate(m_mapid);
230 }
#define sObjectMgr
Definition: ObjectMgr.h:1567
uint32 m_mapid
Definition: InstanceSaveMgr.h:140
bool InstanceSave::RemoveGroup ( Group group)
inline
105  {
106  m_groupList.remove(group);
107  bool isStillValid = UnloadIfEmpty();
108  if (m_toDelete)
109  delete this;
110  return isStillValid;
111  }
bool m_toDelete
Definition: InstanceSaveMgr.h:143
bool UnloadIfEmpty()
Definition: InstanceSaveMgr.cpp:243
GroupListType m_groupList
Definition: InstanceSaveMgr.h:137

+ Here is the caller graph for this function:

bool InstanceSave::RemovePlayer ( Player player)
inline
90  {
91  _playerListLock.lock();
92  m_playerList.remove(player);
93  bool isStillValid = UnloadIfEmpty();
94  _playerListLock.unlock();
95 
96  //delete here if needed, after releasing the lock
97  if (m_toDelete)
98  delete this;
99 
100  return isStillValid;
101  }
PlayerListType m_playerList
Definition: InstanceSaveMgr.h:136
std::mutex _playerListLock
Definition: InstanceSaveMgr.h:145
bool m_toDelete
Definition: InstanceSaveMgr.h:143
bool UnloadIfEmpty()
Definition: InstanceSaveMgr.cpp:243
void InstanceSave::SaveToDB ( )
190 {
191  // save instance data too
192  std::string data;
193  uint32 completedEncounters = 0;
194 
195  Map* map = sMapMgr->FindMap(GetMapId(), m_instanceid);
196  if (map)
197  {
198  ASSERT(map->IsDungeon());
199  if (InstanceScript* instanceScript = ((InstanceMap*)map)->GetInstanceScript())
200  {
201  data = instanceScript->GetSaveData();
202  completedEncounters = instanceScript->GetCompletedEncounterMask();
203  }
204  }
205 
207  stmt->setUInt32(0, m_instanceid);
208  stmt->setUInt16(1, GetMapId());
209  stmt->setUInt32(2, uint32(GetResetTimeForDB()));
210  stmt->setUInt8(3, uint8(GetDifficultyID()));
211  stmt->setUInt32(4, completedEncounters);
212  stmt->setString(5, data);
214 }
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
void setUInt8(const uint8 index, const uint8 value)
Definition: PreparedStatement.cpp:97
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
bool IsDungeon() const
Definition: Map.h:395
Definition: PreparedStatement.h:74
Definition: Map.h:758
time_t GetResetTimeForDB()
Definition: InstanceSaveMgr.cpp:216
uint32 m_instanceid
Definition: InstanceSaveMgr.h:139
void setUInt16(const uint8 index, const uint16 value)
Definition: PreparedStatement.cpp:106
uint32_t uint32
Definition: Define.h:150
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
Definition: Map.h:259
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
uint32 GetMapId() const
Definition: InstanceSaveMgr.h:65
uint8_t uint8
Definition: g3dmath.h:164
Definition: CharacterDatabase.h:241
Difficulty GetDifficultyID() const
Definition: InstanceSaveMgr.h:121
#define sMapMgr
Definition: MapManager.h:194
Definition: InstanceScript.h:141
#define ASSERT
Definition: Errors.h:55
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void InstanceSave::SetCanReset ( bool  canReset)
inline
117 { m_canReset = canReset; }
bool m_canReset
Definition: InstanceSaveMgr.h:142
void InstanceSave::SetResetTime ( time_t  resetTime)
inline
75 { m_resetTime = resetTime; }
time_t m_resetTime
Definition: InstanceSaveMgr.h:138
void InstanceSave::SetToDelete ( bool  toDelete)
inline
125  {
126  m_toDelete = toDelete;
127  }
bool m_toDelete
Definition: InstanceSaveMgr.h:143
bool InstanceSave::UnloadIfEmpty ( )
private
244 {
245  if (m_playerList.empty() && m_groupList.empty())
246  {
247  // don't remove the save if there are still players inside the map
248  if (Map* map = sMapMgr->FindMap(GetMapId(), GetInstanceId()))
249  if (map->HavePlayers())
250  return true;
251 
252  if (!sInstanceSaveMgr->lock_instLists)
253  sInstanceSaveMgr->RemoveInstanceSave(GetInstanceId());
254 
255  return false;
256  }
257  else
258  return true;
259 }
PlayerListType m_playerList
Definition: InstanceSaveMgr.h:136
Definition: Map.h:259
#define sInstanceSaveMgr
Definition: InstanceSaveMgr.h:243
uint32 GetMapId() const
Definition: InstanceSaveMgr.h:65
#define sMapMgr
Definition: MapManager.h:194
GroupListType m_groupList
Definition: InstanceSaveMgr.h:137
uint32 GetInstanceId() const
Definition: InstanceSaveMgr.h:64

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class InstanceSaveManager
friend

Member Data Documentation

std::mutex InstanceSave::_playerListLock
private
bool InstanceSave::m_canReset
private
Difficulty InstanceSave::m_difficulty
private
GroupListType InstanceSave::m_groupList
private
uint32 InstanceSave::m_instanceid
private
uint32 InstanceSave::m_mapid
private
PlayerListType InstanceSave::m_playerList
private
Todo:
: Check if maybe it's enough to just store the number of players/groups
time_t InstanceSave::m_resetTime
private
bool InstanceSave::m_toDelete
private

The documentation for this class was generated from the following files: