OregonCore  revision be9e804-git
Your Favourite TBC server
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, DungeonDifficulty difficulty, time_t resetTime, bool canReset)
 
 ~InstanceSave ()
 
uint8 GetPlayerCount ()
 
uint8 GetGroupCount ()
 
uint32 GetInstanceId ()
 
uint32 GetMapId ()
 
void SaveToDB ()
 
void DeleteFromDB ()
 
time_t GetResetTime ()
 
void SetResetTime (time_t resetTime)
 
time_t GetResetTimeForDB ()
 
InstanceTemplate const * GetTemplate ()
 
MapEntry const * GetMapEntry ()
 
void AddPlayer (Player *player)
 
bool RemovePlayer (Player *player)
 
void AddGroup (Group *group)
 
bool RemoveGroup (Group *group)
 
bool CanReset ()
 
void SetCanReset (bool canReset)
 
DungeonDifficulty GetDifficulty ()
 

Private Member Functions

bool UnloadIfEmpty ()
 

Private Attributes

uint16 m_mapid
 
uint32 m_instanceid
 
time_t m_resetTime
 
DungeonDifficulty m_difficulty
 
bool m_canReset
 
PlayerListType m_playerList
 
GroupListType m_groupList
 

Friends

class InstanceSaveManager
 

Detailed Description

Definition at line 41 of file InstanceSaveMgr.h.

Member Typedef Documentation

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

Definition at line 138 of file InstanceSaveMgr.h.

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

Definition at line 137 of file InstanceSaveMgr.h.

Constructor & Destructor Documentation

InstanceSave::InstanceSave ( uint16  MapId,
uint32  InstanceId,
DungeonDifficulty  difficulty,
time_t  resetTime,
bool  canReset 
)

Definition at line 145 of file InstanceSaveMgr.cpp.

146  : m_mapid(MapId), m_instanceid(InstanceId), m_resetTime(resetTime),
147  m_difficulty(difficulty), m_canReset(canReset)
148 {
149 }
DungeonDifficulty m_difficulty
InstanceSave::~InstanceSave ( )

Definition at line 151 of file InstanceSaveMgr.cpp.

References ASSERT, m_groupList, and m_playerList.

152 {
153  // the players and groups must be unbound before deleting the save
154  ASSERT(m_playerList.empty() && m_groupList.empty());
155 }
PlayerListType m_playerList
#define ASSERT
Definition: Errors.h:29
GroupListType m_groupList

Member Function Documentation

void InstanceSave::AddGroup ( Group group)
inline

Definition at line 108 of file InstanceSaveMgr.h.

References m_groupList.

Referenced by Group::BindToInstance().

109  {
110  m_groupList.push_back(group);
111  }
GroupListType m_groupList
void InstanceSave::AddPlayer ( Player player)
inline

Definition at line 98 of file InstanceSaveMgr.h.

References m_playerList.

Referenced by Player::BindToInstance().

99  {
100  m_playerList.push_back(player);
101  }
PlayerListType m_playerList
bool InstanceSave::CanReset ( )
inline
void InstanceSave::DeleteFromDB ( )
uint8 InstanceSave::GetGroupCount ( )
inline

Definition at line 59 of file InstanceSaveMgr.h.

References m_groupList.

Referenced by InstanceMap::AddPlayerToMap().

60  {
61  return m_groupList.size();
62  }
GroupListType m_groupList
MapEntry const * InstanceSave::GetMapEntry ( )

Definition at line 196 of file InstanceSaveMgr.cpp.

References m_mapid, and sMapStore.

Referenced by SetResetTime().

197 {
198  return sMapStore.LookupEntry(m_mapid);
199 }
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
uint8 InstanceSave::GetPlayerCount ( )
inline

Definition at line 55 of file InstanceSaveMgr.h.

References m_playerList.

Referenced by InstanceMap::AddPlayerToMap().

56  {
57  return m_playerList.size();
58  }
PlayerListType m_playerList
time_t InstanceSave::GetResetTime ( )
inline
time_t InstanceSave::GetResetTimeForDB ( )

Definition at line 180 of file InstanceSaveMgr.cpp.

References DIFFICULTY_HEROIC, GetDifficulty(), GetMapId(), GetResetTime(), MapEntry::IsRaid(), and sMapStore.

Referenced by SaveToDB(), and SetResetTime().

181 {
182  // only save the reset time for normal instances
183  const MapEntry* entry = sMapStore.LookupEntry(GetMapId());
184  if (!entry || entry->IsRaid() || GetDifficulty() == DIFFICULTY_HEROIC)
185  return 0;
186  else
187  return GetResetTime();
188 }
DungeonDifficulty GetDifficulty()
uint32 GetMapId()
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
time_t GetResetTime()
bool IsRaid() const
Definition: DBCStructure.h:558
InstanceTemplate const * InstanceSave::GetTemplate ( )

Definition at line 191 of file InstanceSaveMgr.cpp.

References m_mapid, and sObjectMgr.

Referenced by SetResetTime().

192 {
193  return sObjectMgr.GetInstanceTemplate(m_mapid);
194 }
#define sObjectMgr
Definition: ObjectMgr.h:1317
bool InstanceSave::RemoveGroup ( Group group)
inline

Definition at line 112 of file InstanceSaveMgr.h.

References m_groupList, and UnloadIfEmpty().

Referenced by Group::BindToInstance(), and Group::ResetInstances().

113  {
114  m_groupList.remove(group);
115  return UnloadIfEmpty();
116  }
GroupListType m_groupList
bool InstanceSave::RemovePlayer ( Player player)
inline

Definition at line 102 of file InstanceSaveMgr.h.

References m_playerList, and UnloadIfEmpty().

Referenced by Player::BindToInstance(), and Player::ResetInstances().

103  {
104  m_playerList.remove(player);
105  return UnloadIfEmpty();
106  }
PlayerListType m_playerList
void InstanceSave::SaveToDB ( )

Definition at line 160 of file InstanceSaveMgr.cpp.

References ASSERT, CharacterDatabase, Database::escape_string(), MapManager::FindMap(), GetDifficulty(), GetMapId(), GetResetTimeForDB(), Oregon::Singleton< MapManager, Oregon::ClassLevelLockable< MapManager, ACE_Thread_Mutex > >::Instance(), Map::IsDungeon(), m_instanceid, Database::PExecute(), and UI64FMTD.

Referenced by InstanceSaveManager::AddInstanceSave(), and GetMapId().

161 {
162  // save instance data too
163  std::string data;
164 
166  if (map)
167  {
168  ASSERT(map->IsDungeon());
169  if (InstanceData* iData = ((InstanceMap*)map)->GetInstanceData())
170  {
171  data = iData->GetSaveData();
172  if (!data.empty())
174  }
175  }
176 
177  CharacterDatabase.PExecute("INSERT INTO instance VALUES ('%u', '%u', '" UI64FMTD "', '%u', '%s')", m_instanceid, GetMapId(), (uint64)GetResetTimeForDB(), GetDifficulty(), data.c_str());
178 }
DungeonDifficulty GetDifficulty()
uint32 GetMapId()
unsigned long escape_string(char *to, const char *from, unsigned long length)
Definition: Database.cpp:212
bool IsDungeon() const
Definition: Map.h:427
#define UI64FMTD
Definition: Common.h:149
time_t GetResetTimeForDB()
bool PExecute(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:441
Definition: Map.h:266
Map * FindMap(uint32 mapid, uint32 instanceId=0) const
Definition: MapManager.cpp:137
ACE_UINT64 uint64
Definition: Define.h:70
#define ASSERT
Definition: Errors.h:29
DatabaseType CharacterDatabase
Accessor to the character database.
Definition: Main.cpp:54
void InstanceSave::SetCanReset ( bool  canReset)
inline

Definition at line 125 of file InstanceSaveMgr.h.

References m_canReset.

Referenced by Player::BindToInstance().

126  {
127  m_canReset = canReset;
128  }
void InstanceSave::SetResetTime ( time_t  resetTime)
inline

Definition at line 87 of file InstanceSaveMgr.h.

References GetMapEntry(), GetResetTimeForDB(), GetTemplate(), and m_resetTime.

88  {
89  m_resetTime = resetTime;
90  }
bool InstanceSave::UnloadIfEmpty ( )
private

Definition at line 207 of file InstanceSaveMgr.cpp.

References GetInstanceId(), m_groupList, m_playerList, and sInstanceSaveMgr.

Referenced by RemoveGroup(), and RemovePlayer().

208 {
209  if (m_playerList.empty() && m_groupList.empty())
210  {
211  if (!sInstanceSaveMgr.lock_instLists)
212  sInstanceSaveMgr.RemoveInstanceSave(GetInstanceId());
213  return false;
214  }
215  else
216  return true;
217 }
PlayerListType m_playerList
uint32 GetInstanceId()
#define sInstanceSaveMgr
GroupListType m_groupList

Friends And Related Function Documentation

friend class InstanceSaveManager
friend

Definition at line 43 of file InstanceSaveMgr.h.

Member Data Documentation

bool InstanceSave::m_canReset
private

Definition at line 148 of file InstanceSaveMgr.h.

Referenced by CanReset(), and SetCanReset().

DungeonDifficulty InstanceSave::m_difficulty
private

Definition at line 147 of file InstanceSaveMgr.h.

Referenced by GetDifficulty().

GroupListType InstanceSave::m_groupList
private
uint32 InstanceSave::m_instanceid
private

Definition at line 145 of file InstanceSaveMgr.h.

Referenced by GetInstanceId(), and SaveToDB().

uint16 InstanceSave::m_mapid
private

Definition at line 144 of file InstanceSaveMgr.h.

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

time_t InstanceSave::m_resetTime
private

Definition at line 146 of file InstanceSaveMgr.h.

Referenced by GetResetTime(), and SetResetTime().


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