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

#include <Map.h>

Public Member Functions

 InstanceMap (uint32 id, time_t, uint32 InstanceId, uint8 SpawnMode, Map *_parent)
 
 ~InstanceMap ()
 
bool AddPlayerToMap (Player *player, bool initPlayer=true) override
 
void RemovePlayerFromMap (Player *, bool) override
 
void Update (const uint32) override
 
void CreateInstanceData (bool load)
 
bool Reset (uint8 method)
 
uint32 GetScriptId () const
 
InstanceScriptGetInstanceScript ()
 
void PermBindAllPlayers (Player *source)
 
void UnloadAll () override
 
EnterState CannotEnter (Player *player) override
 
void SendResetWarnings (uint32 timeLeft) const
 
void SetResetSchedule (bool on)
 
bool HasPermBoundPlayers () const
 
uint32 GetMaxPlayers () const
 
uint32 GetMaxResetDelay () const
 
virtual void InitVisibilityDistance () override
 
- Public Member Functions inherited from Map
 Map (uint32 id, time_t, uint32 InstanceId, uint8 SpawnMode, Map *_parent=NULL)
 
virtual ~Map ()
 
MapEntry constGetEntry () const
 
bool CanUnload (uint32 diff)
 
template<class T >
bool AddToMap (T *)
 
template<class T >
void RemoveFromMap (T *, bool)
 
void VisitNearbyCellsOf (WorldObject *obj, TypeContainerVisitor< Trinity::ObjectUpdater, GridTypeMapContainer > &gridVisitor, TypeContainerVisitor< Trinity::ObjectUpdater, WorldTypeMapContainer > &worldVisitor)
 
float GetVisibilityRange () const
 
void PlayerRelocation (Player *, float x, float y, float z, float orientation)
 
void CreatureRelocation (Creature *creature, float x, float y, float z, float ang, bool respawnRelocationOnFail=true)
 
void GameObjectRelocation (GameObject *go, float x, float y, float z, float orientation, bool respawnRelocationOnFail=true)
 
void DynamicObjectRelocation (DynamicObject *go, float x, float y, float z, float orientation)
 
template<class T , class CONTAINER >
void Visit (const Cell &cell, TypeContainerVisitor< T, CONTAINER > &visitor)
 
bool IsRemovalGrid (float x, float y) const
 
bool IsGridLoaded (float x, float y) const
 
bool GetUnloadLock (const GridCoord &p) const
 
void SetUnloadLock (const GridCoord &p, bool on)
 
void LoadGrid (float x, float y)
 
bool UnloadGrid (NGridType &ngrid, bool pForce)
 
void ResetGridExpiry (NGridType &grid, float factor=1) const
 
time_t GetGridExpiry (void) const
 
uint32 GetId (void) const
 
Map constGetParent () const
 
float GetHeight (float x, float y, float z, bool checkVMap=true, float maxSearchDist=DEFAULT_HEIGHT_SEARCH) const
 
float GetMinHeight (float x, float y) const
 
ZLiquidStatus getLiquidStatus (float x, float y, float z, uint8 ReqLiquidType, LiquidData *data=nullptr) const
 
uint32 GetAreaId (float x, float y, float z, bool *isOutdoors) const
 
bool GetAreaInfo (float x, float y, float z, uint32 &mogpflags, int32 &adtId, int32 &rootId, int32 &groupId) const
 
uint32 GetAreaId (float x, float y, float z) const
 
uint32 GetZoneId (float x, float y, float z) const
 
void GetZoneAndAreaId (uint32 &zoneid, uint32 &areaid, float x, float y, float z) const
 
bool IsOutdoors (float x, float y, float z) const
 
uint8 GetTerrainType (float x, float y) const
 
float GetWaterLevel (float x, float y) const
 
bool IsInWater (float x, float y, float z, LiquidData *data=nullptr) const
 
bool IsUnderWater (float x, float y, float z) const
 
void MoveAllCreaturesInMoveList ()
 
void MoveAllGameObjectsInMoveList ()
 
void MoveAllDynamicObjectsInMoveList ()
 
void RemoveAllObjectsInRemoveList ()
 
virtual void RemoveAllPlayers ()
 
bool CreatureRespawnRelocation (Creature *c, bool diffGridOnly)
 
bool GameObjectRespawnRelocation (GameObject *go, bool diffGridOnly)
 
bool CheckGridIntegrity (Creature *c, bool moved) const
 
uint32 GetInstanceId () const
 
uint8 GetSpawnMode () const
 
const char * GetMapName () const
 
Difficulty GetDifficultyID () const
 
MapDifficultyEntry constGetMapDifficulty () const
 
uint32 GetDifficultyLootBonusTreeMod () const
 
bool Instanceable () const
 
bool IsDungeon () const
 
bool IsNonRaidDungeon () const
 
bool IsRaid () const
 
bool IsRaidOrHeroicDungeon () const
 
bool IsHeroic () const
 
bool Is25ManRaid () const
 
bool IsBattleground () const
 
bool IsBattleArena () const
 
bool IsBattlegroundOrArena () const
 
bool IsGarrison () const
 
bool GetEntrancePos (int32 &mapid, float &x, float &y)
 
void AddObjectToRemoveList (WorldObject *obj)
 
void AddObjectToSwitchList (WorldObject *obj, bool on)
 
virtual void DelayedUpdate (const uint32 diff)
 
void UpdateObjectVisibility (WorldObject *obj, Cell cell, CellCoord cellpair)
 
void UpdateObjectsVisibilityFor (Player *player, Cell cell, CellCoord cellpair)
 
void resetMarkedCells ()
 
bool isCellMarked (uint32 pCellId)
 
void markCell (uint32 pCellId)
 
bool HavePlayers () const
 
uint32 GetPlayersCountExceptGMs () const
 
bool ActiveObjectsNearGrid (NGridType const &ngrid) const
 
void AddWorldObject (WorldObject *obj)
 
void RemoveWorldObject (WorldObject *obj)
 
void SendToPlayers (WorldPacket const *data) const
 
PlayerList constGetPlayers () const
 
void ScriptsStart (std::map< uint32, std::multimap< uint32, ScriptInfo > > const &scripts, uint32 id, Object *source, Object *target)
 Put scripts in the execution queue. More...
 
void ScriptCommandStart (ScriptInfo const &script, uint32 delay, Object *source, Object *target)
 
template<class T >
void AddToActive (T *obj)
 
template<class T >
void RemoveFromActive (T *obj)
 
template<class T >
void SwitchGridContainers (T *obj, bool on)
 
template<class NOTIFIER >
void VisitAll (const float &x, const float &y, float radius, NOTIFIER &notifier)
 
template<class NOTIFIER >
void VisitFirstFound (const float &x, const float &y, float radius, NOTIFIER &notifier)
 
template<class NOTIFIER >
void VisitWorld (const float &x, const float &y, float radius, NOTIFIER &notifier)
 
template<class NOTIFIER >
void VisitGrid (const float &x, const float &y, float radius, NOTIFIER &notifier)
 
void UpdateIteratorBack (Player *player)
 
TempSummonSummonCreature (uint32 entry, Position const &pos, SummonPropertiesEntry const *properties=NULL, uint32 duration=0, Unit *summoner=NULL, uint32 spellId=0, uint32 vehId=0)
 
void SummonCreatureGroup (uint8 group, std::list< TempSummon * > *list=NULL)
 
AreaTriggerGetAreaTrigger (ObjectGuid const &guid)
 
CorpseGetCorpse (ObjectGuid const &guid)
 
CreatureGetCreature (ObjectGuid const &guid)
 
DynamicObjectGetDynamicObject (ObjectGuid const &guid)
 
GameObjectGetGameObject (ObjectGuid const &guid)
 
PetGetPet (ObjectGuid const &guid)
 
TransportGetTransport (ObjectGuid const &guid)
 
MapStoredObjectTypesContainerGetObjectsStore ()
 
CreatureBySpawnIdContainerGetCreatureBySpawnIdStore ()
 
GameObjectBySpawnIdContainerGetGameObjectBySpawnIdStore ()
 
std::unordered_set< Corpse * >
const
GetCorpsesInCell (uint32 cellId) const
 
CorpseGetCorpseByPlayer (ObjectGuid const &ownerGuid) const
 
MapInstancedToMapInstanced ()
 
MapInstanced constToMapInstanced () const
 
InstanceMapToInstanceMap ()
 
InstanceMap constToInstanceMap () const
 
BattlegroundMapToBattlegroundMap ()
 
BattlegroundMap constToBattlegroundMap () const
 
float GetWaterOrGroundLevel (float x, float y, float z, float *ground=NULL, bool swim=false) const
 
float GetHeight (uint32 phasemask, float x, float y, float z, bool vmap=true, float maxSearchDist=DEFAULT_HEIGHT_SEARCH) const
 
bool isInLineOfSight (float x1, float y1, float z1, float x2, float y2, float z2, uint32 phasemask) const
 
void Balance ()
 
void RemoveGameObjectModel (const GameObjectModel &model)
 
void InsertGameObjectModel (const GameObjectModel &model)
 
bool ContainsGameObjectModel (const GameObjectModel &model) const
 
bool getObjectHitPos (uint32 phasemask, float x1, float y1, float z1, float x2, float y2, float z2, float &rx, float &ry, float &rz, float modifyDist)
 
virtual ObjectGuid::LowType GetOwnerGuildId (uint32=TEAM_OTHER) const
 
time_t GetLinkedRespawnTime (ObjectGuid guid) const
 
time_t GetCreatureRespawnTime (ObjectGuid::LowType dbGuid) const
 
time_t GetGORespawnTime (ObjectGuid::LowType dbGuid) const
 
void SaveCreatureRespawnTime (ObjectGuid::LowType dbGuid, time_t respawnTime)
 
void RemoveCreatureRespawnTime (ObjectGuid::LowType dbGuid)
 
void SaveGORespawnTime (ObjectGuid::LowType dbGuid, time_t respawnTime)
 
void RemoveGORespawnTime (ObjectGuid::LowType dbGuid)
 
void LoadRespawnTimes ()
 
void DeleteRespawnTimes ()
 
void LoadCorpseData ()
 
void DeleteCorpseData ()
 
void AddCorpse (Corpse *corpse)
 
void RemoveCorpse (Corpse *corpse)
 
CorpseConvertCorpseToBones (ObjectGuid const &ownerGuid, bool insignia=false)
 
void RemoveOldCorpses ()
 
void SendInitTransports (Player *player)
 
void SendRemoveTransports (Player *player)
 
void SendUpdateTransportVisibility (Player *player, std::set< uint32 > const &previousPhases)
 
void SendZoneDynamicInfo (Player *player)
 
void SetZoneMusic (uint32 zoneId, uint32 musicId)
 
void SetZoneWeather (uint32 zoneId, WeatherState weatherId, float weatherGrade)
 
void SetZoneOverrideLight (uint32 zoneId, uint32 lightId, uint32 fadeInTime)
 
void UpdateAreaDependentAuras ()
 
template<HighGuid high>
ObjectGuid::LowType GenerateLowGuid ()
 
void AddUpdateObject (Object *obj)
 
void RemoveUpdateObject (Object *obj)
 
template<>
void AddToGrid (Creature *obj, Cell const &cell)
 
template<>
void AddToGrid (GameObject *obj, Cell const &cell)
 
template<>
void AddToGrid (DynamicObject *obj, Cell const &cell)
 
template<>
void AddToGrid (Corpse *obj, Cell const &cell)
 
template<>
void SwitchGridContainers (Creature *obj, bool on)
 
template<>
void SwitchGridContainers (GameObject *obj, bool on)
 
template<>
void DeleteFromWorld (Player *player)
 
template<>
void DeleteFromWorld (Transport *transport)
 
template<>
void InitializeObject (Creature *obj)
 
template<>
void InitializeObject (GameObject *obj)
 
template<>
bool AddToMap (Transport *obj)
 
template<>
void RemoveFromMap (Transport *obj, bool remove)
 
template<>
void AddToActive (Creature *c)
 
template<>
void AddToActive (DynamicObject *d)
 
template<>
void RemoveFromActive (Creature *c)
 
template<>
void RemoveFromActive (DynamicObject *obj)
 
- Public Member Functions inherited from GridRefManager< NGridType >
GridReference< NGridType > * getFirst ()
 
GridReference< NGridType > * getLast ()
 
iterator begin ()
 
iterator end ()
 
iterator rbegin ()
 
iterator rend ()
 
- Public Member Functions inherited from RefManager< GridRefManager< NGridType >, NGridType >
 RefManager ()
 
virtual ~RefManager ()
 
Reference< GridRefManager
< NGridType >, NGridType > * 
getFirst ()
 
Reference< GridRefManager
< NGridType >, NGridType >
const
getFirst () const
 
Reference< GridRefManager
< NGridType >, NGridType > * 
getLast ()
 
Reference< GridRefManager
< NGridType >, NGridType >
const
getLast () const
 
iterator begin ()
 
iterator end ()
 
iterator rbegin ()
 
iterator rend ()
 
void clearReferences ()
 
- Public Member Functions inherited from LinkedListHead
 LinkedListHead ()
 
virtual ~LinkedListHead ()
 
bool isEmpty () const
 
LinkedListElementgetFirst ()
 
LinkedListElement constgetFirst () const
 
LinkedListElementgetLast ()
 
LinkedListElement constgetLast () const
 
void insertFirst (LinkedListElement *pElem)
 
void insertLast (LinkedListElement *pElem)
 
uint32 getSize () const
 
void incSize ()
 
void decSize ()
 

Private Attributes

bool m_resetAfterUnload
 
bool m_unloadWhenEmpty
 
InstanceScripti_data
 
uint32 i_script_id
 

Additional Inherited Members

- Public Types inherited from Map
enum  EnterState {
  CAN_ENTER = 0, CANNOT_ENTER_ALREADY_IN_MAP = 1, CANNOT_ENTER_NO_ENTRY, CANNOT_ENTER_UNINSTANCED_DUNGEON,
  CANNOT_ENTER_DIFFICULTY_UNAVAILABLE, CANNOT_ENTER_NOT_IN_RAID, CANNOT_ENTER_CORPSE_IN_DIFFERENT_INSTANCE, CANNOT_ENTER_INSTANCE_BIND_MISMATCH,
  CANNOT_ENTER_TOO_MANY_INSTANCES, CANNOT_ENTER_MAX_PLAYERS, CANNOT_ENTER_ZONE_IN_COMBAT, CANNOT_ENTER_UNSPECIFIED_REASON
}
 
typedef MapRefManager PlayerList
 
typedef
std::unordered_multimap
< ObjectGuid::LowType,
Creature * > 
CreatureBySpawnIdContainer
 
typedef
std::unordered_multimap
< ObjectGuid::LowType,
GameObject * > 
GameObjectBySpawnIdContainer
 
- Public Types inherited from GridRefManager< NGridType >
typedef
LinkedListHead::Iterator
< GridReference< NGridType > > 
iterator
 
- Public Types inherited from RefManager< GridRefManager< NGridType >, NGridType >
typedef
LinkedListHead::Iterator
< Reference< GridRefManager
< NGridType >, NGridType > > 
iterator
 
- Public Types inherited from LinkedListHead
typedef Iterator
< LinkedListElement
iterator
 
- Static Public Member Functions inherited from Map
static bool ExistMap (uint32 mapid, int gx, int gy)
 
static bool ExistVMap (uint32 mapid, int gx, int gy)
 
static void InitStateMachine ()
 
static void DeleteStateMachine ()
 
static void DeleteRespawnTimesInDB (uint16 mapId, uint32 instanceId)
 
- Public Attributes inherited from Map
CreatureGroupHolderType CreatureGroupHolder
 
- Protected Types inherited from Map
typedef std::set< WorldObject * > ActiveNonPlayers
 
typedef std::set< Transport * > TransportsContainer
 
- Protected Member Functions inherited from Map
void SetUnloadReferenceLock (const GridCoord &p, bool on)
 
virtual void LoadGridObjects (NGridType *grid, Cell const &cell)
 
- Protected Attributes inherited from Map
std::mutex _mapLock
 
std::mutex _gridLock
 
MapEntry consti_mapEntry
 
uint8 i_spawnMode
 
uint32 i_InstanceId
 
uint32 m_unloadTimer
 
float m_VisibleDistance
 
DynamicMapTree _dynamicTree
 
MapRefManager m_mapRefManager
 
MapRefManager::iterator m_mapRefIter
 
int32 m_VisibilityNotifyPeriod
 
ActiveNonPlayers m_activeNonPlayers
 
ActiveNonPlayers::iterator m_activeNonPlayersIter
 
TransportsContainer _transports
 
TransportsContainer::iterator _transportsUpdateIter
 

Constructor & Destructor Documentation

InstanceMap::InstanceMap ( uint32  id,
time_t  expiry,
uint32  InstanceId,
uint8  SpawnMode,
Map _parent 
)
3037  : Map(id, expiry, InstanceId, SpawnMode, _parent),
3038  m_resetAfterUnload(false), m_unloadWhenEmpty(false),
3039  i_data(NULL), i_script_id(0)
3040 {
3041  //lets initialize visibility distance for dungeons
3043 
3044  // the timer is started by default, and stopped when the first player joins
3045  // this make sure it gets unloaded if for some reason no player joins
3047 }
Definition: World.h:255
virtual void InitVisibilityDistance() override
Definition: Map.cpp:3055
InstanceScript * i_data
Definition: Map.h:786
arena_t NULL
Definition: jemalloc_internal.h:624
#define sWorld
Definition: World.h:887
uint32 i_script_id
Definition: Map.h:787
T max(const T &x, const T &y)
Definition: g3dmath.h:320
bool m_resetAfterUnload
Definition: Map.h:784
uint32 m_unloadTimer
Definition: Map.h:643
Map(uint32 id, time_t, uint32 InstanceId, uint8 SpawnMode, Map *_parent=NULL)
Definition: Map.cpp:227
uint32_t uint32
Definition: g3dmath.h:168
#define MIN_UNLOAD_DELAY
Definition: Map.h:251
bool m_unloadWhenEmpty
Definition: Map.h:785

+ Here is the call graph for this function:

InstanceMap::~InstanceMap ( )
3050 {
3051  delete i_data;
3052  i_data = NULL;
3053 }
InstanceScript * i_data
Definition: Map.h:786
arena_t NULL
Definition: jemalloc_internal.h:624

Member Function Documentation

bool InstanceMap::AddPlayerToMap ( Player player,
bool  initPlayer = true 
)
overridevirtual
Todo:
Not sure about checking player level: already done in HandleAreaTriggerOpcode

Reimplemented from Map.

3103 {
3105  // GMs still can teleport player in instance.
3106  // Is it needed?
3107 
3108  {
3109  std::lock_guard<std::mutex> lock(_mapLock);
3110  // Check moved to void WorldSession::HandleMoveWorldportAckOpcode()
3111  //if (!CanEnter(player))
3112  //return false;
3113 
3114  // Dungeon only code
3115  if (IsDungeon())
3116  {
3117  Group* group = player->GetGroup();
3118 
3119  // increase current instances (hourly limit)
3120  if (!group || !group->isLFGGroup())
3121  player->AddInstanceEnterTime(GetInstanceId(), time(NULL));
3122 
3123  // get or create an instance save for the map
3124  InstanceSave* mapSave = sInstanceSaveMgr->GetInstanceSave(GetInstanceId());
3125  if (!mapSave)
3126  {
3127  TC_LOG_DEBUG("maps", "InstanceMap::Add: creating instance save for map %d spawnmode %d with instance id %d", GetId(), GetSpawnMode(), GetInstanceId());
3128  mapSave = sInstanceSaveMgr->AddInstanceSave(GetId(), GetInstanceId(), Difficulty(GetSpawnMode()), 0, true);
3129  }
3130 
3131  ASSERT(mapSave);
3132 
3133  // check for existing instance binds
3134  InstancePlayerBind* playerBind = player->GetBoundInstance(GetId(), Difficulty(GetSpawnMode()));
3135  if (playerBind && playerBind->perm)
3136  {
3137  // cannot enter other instances if bound permanently
3138  if (playerBind->save != mapSave)
3139  {
3140  TC_LOG_ERROR("maps", "InstanceMap::Add: player %s(%s) is permanently bound to instance %s %d, %d, %d, %d, %d, %d but he is being put into instance %s %d, %d, %d, %d, %d, %d", player->GetName().c_str(), player->GetGUID().ToString().c_str(), GetMapName(), playerBind->save->GetMapId(), playerBind->save->GetInstanceId(), playerBind->save->GetDifficultyID(), playerBind->save->GetPlayerCount(), playerBind->save->GetGroupCount(), playerBind->save->CanReset(), GetMapName(), mapSave->GetMapId(), mapSave->GetInstanceId(), mapSave->GetDifficultyID(), mapSave->GetPlayerCount(), mapSave->GetGroupCount(), mapSave->CanReset());
3141  return false;
3142  }
3143  }
3144  else
3145  {
3146  if (group)
3147  {
3148  // solo saves should have been reset when the map was loaded
3149  InstanceGroupBind* groupBind = group->GetBoundInstance(this);
3150  if (playerBind && playerBind->save != mapSave)
3151  {
3152  TC_LOG_ERROR("maps", "InstanceMap::Add: player %s(%s) is being put into instance %s %d, %d, %d, %d, %d, %d but he is in group %s and is bound to instance %d, %d, %d, %d, %d, %d!", player->GetName().c_str(), player->GetGUID().ToString().c_str(), GetMapName(), mapSave->GetMapId(), mapSave->GetInstanceId(), mapSave->GetDifficultyID(), mapSave->GetPlayerCount(), mapSave->GetGroupCount(), mapSave->CanReset(), group->GetLeaderGUID().ToString().c_str(), playerBind->save->GetMapId(), playerBind->save->GetInstanceId(), playerBind->save->GetDifficultyID(), playerBind->save->GetPlayerCount(), playerBind->save->GetGroupCount(), playerBind->save->CanReset());
3153  if (groupBind)
3154  TC_LOG_ERROR("maps", "InstanceMap::Add: the group is bound to the instance %s %d, %d, %d, %d, %d, %d", GetMapName(), groupBind->save->GetMapId(), groupBind->save->GetInstanceId(), groupBind->save->GetDifficultyID(), groupBind->save->GetPlayerCount(), groupBind->save->GetGroupCount(), groupBind->save->CanReset());
3155  //ABORT();
3156  return false;
3157  }
3158  // bind to the group or keep using the group save
3159  if (!groupBind)
3160  group->BindToInstance(mapSave, false);
3161  else
3162  {
3163  // cannot jump to a different instance without resetting it
3164  if (groupBind->save != mapSave)
3165  {
3166  TC_LOG_ERROR("maps", "InstanceMap::Add: player %s(%s) is being put into instance %d, %d, %d but he is in group %s which is bound to instance %d, %d, %d!", player->GetName().c_str(), player->GetGUID().ToString().c_str(), mapSave->GetMapId(), mapSave->GetInstanceId(), mapSave->GetDifficultyID(), group->GetLeaderGUID().ToString().c_str(), groupBind->save->GetMapId(), groupBind->save->GetInstanceId(), groupBind->save->GetDifficultyID());
3167  TC_LOG_ERROR("maps", "MapSave players: %d, group count: %d", mapSave->GetPlayerCount(), mapSave->GetGroupCount());
3168  if (groupBind->save)
3169  TC_LOG_ERROR("maps", "GroupBind save players: %d, group count: %d", groupBind->save->GetPlayerCount(), groupBind->save->GetGroupCount());
3170  else
3171  TC_LOG_ERROR("maps", "GroupBind save NULL");
3172  return false;
3173  }
3174  // if the group/leader is permanently bound to the instance
3175  // players also become permanently bound when they enter
3176  if (groupBind->perm)
3177  {
3179  pendingRaidLock.TimeUntilLock = 60000;
3180  pendingRaidLock.CompletedMask = i_data ? i_data->GetCompletedEncounterMask() : 0;
3181  pendingRaidLock.Extending = false;
3182  pendingRaidLock.WarningOnly = false; // events it throws: 1 : INSTANCE_LOCK_WARNING 0 : INSTANCE_LOCK_STOP / INSTANCE_LOCK_START
3183  player->GetSession()->SendPacket(pendingRaidLock.Write());
3184  player->SetPendingBind(mapSave->GetInstanceId(), 60000);
3185  }
3186  }
3187  }
3188  else
3189  {
3190  // set up a solo bind or continue using it
3191  if (!playerBind)
3192  player->BindToInstance(mapSave, false);
3193  else
3194  // cannot jump to a different instance without resetting it
3195  ASSERT(playerBind->save == mapSave);
3196  }
3197  }
3198  }
3199 
3200  // for normal instances cancel the reset schedule when the
3201  // first player enters (no players yet)
3202  SetResetSchedule(false);
3203 
3204  TC_LOG_DEBUG("maps", "MAP: Player '%s' entered instance '%u' of map '%s'", player->GetName().c_str(), GetInstanceId(), GetMapName());
3205  // initialize unload state
3206  m_unloadTimer = 0;
3207  m_resetAfterUnload = false;
3208  m_unloadWhenEmpty = false;
3209  }
3210 
3211  // this will acquire the same mutex so it cannot be in the previous block
3212  Map::AddPlayerToMap(player, initPlayer);
3213 
3214  if (i_data)
3215  i_data->OnPlayerEnter(player);
3216 
3217  return true;
3218 }
bool Extending
Definition: InstancePackets.h:149
InstanceSave * save
Definition: Group.h:170
ObjectGuid GetLeaderGUID() const
Definition: Group.cpp:2529
int32 TimeUntilLock
Definition: InstancePackets.h:147
Difficulty
Definition: DBCEnums.h:402
uint8 GetSpawnMode() const
Definition: Map.h:369
InstanceScript * i_data
Definition: Map.h:786
InstanceGroupBind * BindToInstance(InstanceSave *save, bool permanent, bool load=false)
Definition: Group.cpp:2224
Definition: Group.h:168
void SetResetSchedule(bool on)
Definition: Map.cpp:3388
WorldPacket const * Write() override
Definition: InstancePackets.cpp:97
arena_t NULL
Definition: jemalloc_internal.h:624
virtual void OnPlayerEnter(Player *)
Definition: InstanceScript.h:190
bool IsDungeon() const
Definition: Map.h:395
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: InstancePackets.h:140
uint32 GetId(void) const
Definition: Map.h:325
bool m_resetAfterUnload
Definition: Map.h:784
bool WarningOnly
Definition: InstancePackets.h:150
uint32 CompletedMask
Definition: InstancePackets.h:148
uint32 m_unloadTimer
Definition: Map.h:643
uint32 GetGroupCount() const
Definition: InstanceSaveMgr.h:59
Definition: InstanceSaveMgr.h:44
#define sInstanceSaveMgr
Definition: InstanceSaveMgr.h:243
uint32 GetMapId() const
Definition: InstanceSaveMgr.h:65
bool isLFGGroup() const
Definition: Group.cpp:2504
uint32 GetPlayerCount() const
Definition: InstanceSaveMgr.h:58
std::mutex _mapLock
Definition: Map.h:637
Difficulty GetDifficultyID() const
Definition: InstanceSaveMgr.h:121
uint32 GetCompletedEncounterMask() const
Definition: InstanceScript.h:245
#define ASSERT
Definition: Errors.h:55
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
bool CanReset() const
Definition: InstanceSaveMgr.h:116
InstanceGroupBind * GetBoundInstance(Player *player)
Definition: Group.cpp:2191
virtual bool AddPlayerToMap(Player *player, bool initPlayer=true)
Definition: Map.cpp:513
bool m_unloadWhenEmpty
Definition: Map.h:785
const char * GetMapName() const
Definition: Map.cpp:2644
uint32 GetInstanceId() const
Definition: InstanceSaveMgr.h:64
uint32 GetInstanceId() const
Definition: Map.h:368
bool perm
Definition: Group.h:171
std::string ToString() const
Definition: ObjectGuid.cpp:99
Definition: Group.h:191

+ Here is the call graph for this function:

Map::EnterState InstanceMap::CannotEnter ( Player player)
overridevirtual

Reimplemented from Map.

3066 {
3067  if (player->GetMapRef().getTarget() == this)
3068  {
3069  TC_LOG_ERROR("maps", "InstanceMap::CannotEnter - player %s(%s) already in map %d, %d, %d!", player->GetName().c_str(), player->GetGUID().ToString().c_str(), GetId(), GetInstanceId(), GetSpawnMode());
3070  ABORT();
3072  }
3073 
3074  // allow GM's to enter
3075  if (player->IsGameMaster())
3076  return Map::CannotEnter(player);
3077 
3078  // cannot enter if the instance is full (player cap), GMs don't count
3079  uint32 maxPlayers = GetMaxPlayers();
3080  if (GetPlayersCountExceptGMs() >= maxPlayers)
3081  {
3082  TC_LOG_WARN("maps", "MAP: Instance '%u' of map '%s' cannot have more than '%u' players. Player '%s' rejected", GetInstanceId(), GetMapName(), maxPlayers, player->GetName().c_str());
3083  return CANNOT_ENTER_MAX_PLAYERS;
3084  }
3085 
3086  // cannot enter while an encounter is in progress (unless this is a relog, in which case it is permitted)
3087  if (!player->IsLoading() && IsRaid() && GetInstanceScript() && GetInstanceScript()->IsEncounterInProgress())
3089 
3090  // cannot enter if player is permanent saved to a different instance id
3091  if (InstancePlayerBind* playerBind = player->GetBoundInstance(GetId(), GetDifficultyID()))
3092  if (playerBind->perm && playerBind->save)
3093  if (playerBind->save->GetInstanceId() != GetInstanceId())
3095 
3096  return Map::CannotEnter(player);
3097 }
virtual bool IsEncounterInProgress() const
Definition: InstanceScript.cpp:52
uint8 GetSpawnMode() const
Definition: Map.h:369
bool IsRaid() const
Definition: Map.h:397
Difficulty GetDifficultyID() const
Definition: Map.h:390
uint32 GetId(void) const
Definition: Map.h:325
uint32_t uint32
Definition: Define.h:150
Definition: Map.h:382
InstanceScript * GetInstanceScript()
Definition: Map.h:769
#define ABORT
Definition: Errors.h:56
#define TC_LOG_WARN(filterType__,...)
Definition: Log.h:204
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
virtual EnterState CannotEnter(Player *)
Definition: Map.h:386
uint32 GetMaxPlayers() const
Definition: Map.cpp:3434
const char * GetMapName() const
Definition: Map.cpp:2644
uint32 GetInstanceId() const
Definition: Map.h:368
uint32 GetPlayersCountExceptGMs() const
Definition: Map.cpp:2905

+ Here is the call graph for this function:

void InstanceMap::CreateInstanceData ( bool  load)
Todo:
make a global storage for this
3241 {
3242  if (i_data != NULL)
3243  return;
3244 
3245  InstanceTemplate const* mInstance = sObjectMgr->GetInstanceTemplate(GetId());
3246  if (mInstance)
3247  {
3248  i_script_id = mInstance->ScriptId;
3249  i_data = sScriptMgr->CreateInstanceData(this);
3250  }
3251 
3252  if (!i_data)
3253  return;
3254 
3255  i_data->Initialize();
3256 
3257  if (load)
3258  {
3261  stmt->setUInt16(0, uint16(GetId()));
3262  stmt->setUInt32(1, i_InstanceId);
3264 
3265  if (result)
3266  {
3267  Field* fields = result->Fetch();
3268  std::string data = fields[0].GetString();
3269  i_data->SetCompletedEncountersMask(fields[1].GetUInt32());
3270  if (!data.empty())
3271  {
3272  TC_LOG_DEBUG("maps", "Loading instance data for `%s` with id %u", sObjectMgr->GetScriptName(i_script_id).c_str(), i_InstanceId);
3273  i_data->Load(data.c_str());
3274  }
3275  }
3276  }
3277 }
Definition: CharacterDatabase.h:391
void SetCompletedEncountersMask(uint32 newMask)
Definition: InstanceScript.h:242
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: Map.h:222
InstanceScript * i_data
Definition: Map.h:786
Class used to access individual fields of database query result.
Definition: Field.h:56
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
#define sObjectMgr
Definition: ObjectMgr.h:1567
uint32 i_script_id
Definition: Map.h:787
uint16_t uint16
Definition: g3dmath.h:166
Definition: PreparedStatement.h:74
uint32 GetId(void) const
Definition: Map.h:325
virtual void Load(char const *data)
Definition: InstanceScript.cpp:318
void setUInt16(const uint8 index, const uint16 value)
Definition: PreparedStatement.cpp:106
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
uint32 ScriptId
Definition: Map.h:225
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
virtual void Initialize()
Definition: InstanceScript.h:153
uint32 i_InstanceId
Definition: Map.h:642
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
#define sScriptMgr
Definition: ScriptMgr.h:837
std::string GetString() const
Definition: Field.h:276

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

InstanceScript* InstanceMap::GetInstanceScript ( )
inline
769 { return i_data; }
InstanceScript * i_data
Definition: Map.h:786

+ Here is the caller graph for this function:

uint32 InstanceMap::GetMaxPlayers ( ) const
3435 {
3436  MapDifficultyEntry const* mapDiff = GetMapDifficulty();
3437  if (mapDiff && mapDiff->MaxPlayers)
3438  return mapDiff->MaxPlayers;
3439 
3440  return GetEntry()->MaxPlayers;
3441 }
MapEntry const * GetEntry() const
Definition: Map.h:266
uint32 MaxPlayers
Definition: DBCStructure.h:892
uint32 MaxPlayers
Definition: DBCStructure.h:849
Definition: DBCStructure.h:885
MapDifficultyEntry const * GetMapDifficulty() const
Definition: Map.cpp:3403

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 InstanceMap::GetMaxResetDelay ( ) const
3444 {
3445  MapDifficultyEntry const* mapDiff = GetMapDifficulty();
3446  return mapDiff ? mapDiff->RaidDuration : 0;
3447 }
uint32 RaidDuration
Definition: DBCStructure.h:891
Definition: DBCStructure.h:885
MapDifficultyEntry const * GetMapDifficulty() const
Definition: Map.cpp:3403

+ Here is the call graph for this function:

uint32 InstanceMap::GetScriptId ( ) const
inline
768 { return i_script_id; }
uint32 i_script_id
Definition: Map.h:787

+ Here is the caller graph for this function:

bool InstanceMap::HasPermBoundPlayers ( ) const
3428 {
3430  stmt->setUInt16(0,GetInstanceId());
3431  return !!CharacterDatabase.Query(stmt);
3432 }
Definition: CharacterDatabase.h:392
Definition: PreparedStatement.h:74
void setUInt16(const uint8 index, const uint16 value)
Definition: PreparedStatement.cpp:106
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
uint32 GetInstanceId() const
Definition: Map.h:368

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void InstanceMap::InitVisibilityDistance ( )
overridevirtual

Reimplemented from Map.

3056 {
3057  //init visibility distance for instances
3060 }
float m_VisibleDistance
Definition: Map.h:644
static float GetMaxVisibleDistanceInInstances()
Definition: World.h:730
static int32 GetVisibilityNotifyPeriodInInstances()
Definition: World.h:734
int32 m_VisibilityNotifyPeriod
Definition: Map.h:650

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void InstanceMap::PermBindAllPlayers ( Player source)
3334 {
3335  if (!IsDungeon())
3336  return;
3337 
3338  InstanceSave* save = sInstanceSaveMgr->GetInstanceSave(GetInstanceId());
3339  if (!save)
3340  {
3341  TC_LOG_ERROR("maps", "Cannot bind player (%s, Name: %s), because no instance save is available for instance map (Name: %s, Entry: %u, InstanceId: %u)!", source->GetGUID().ToString().c_str(), source->GetName().c_str(), source->GetMap()->GetMapName(), source->GetMapId(), GetInstanceId());
3342  return;
3343  }
3344 
3345  Group* group = source->GetGroup();
3346  // group members outside the instance group don't get bound
3347  for (MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr)
3348  {
3349  Player* player = itr->GetSource();
3350  // players inside an instance cannot be bound to other instances
3351  // some players may already be permanently bound, in this case nothing happens
3352  InstancePlayerBind* bind = player->GetBoundInstance(save->GetMapId(), save->GetDifficultyID());
3353  if (!bind || !bind->perm)
3354  {
3355  player->BindToInstance(save, true);
3357  data.Gm = player->IsGameMaster();
3358  player->GetSession()->SendPacket(data.Write());
3359  if (!player->IsGameMaster())
3360  player->GetSession()->SendCalendarRaidLockout(save, true);
3361  }
3362 
3363  // if the leader is not in the instance the group will not get a perm bind
3364  if (group && group->GetLeaderGUID() == player->GetGUID())
3365  group->BindToInstance(save, true);
3366  }
3367 }
ObjectGuid GetLeaderGUID() const
Definition: Group.cpp:2529
InstanceGroupBind * BindToInstance(InstanceSave *save, bool permanent, bool load=false)
Definition: Group.cpp:2224
bool IsDungeon() const
Definition: Map.h:395
iterator begin()
Definition: MapRefManager.h:37
bool Gm
Definition: InstancePackets.h:116
WorldPacket const * Write() override
Definition: InstancePackets.cpp:76
Definition: InstanceSaveMgr.h:44
#define sInstanceSaveMgr
Definition: InstanceSaveMgr.h:243
uint32 GetMapId() const
Definition: InstanceSaveMgr.h:65
Definition: InstancePackets.h:109
Difficulty GetDifficultyID() const
Definition: InstanceSaveMgr.h:121
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
MapRefManager m_mapRefManager
Definition: Map.h:647
uint32 GetInstanceId() const
Definition: Map.h:368
iterator end()
Definition: MapRefManager.h:38
Definition: Group.h:191

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void InstanceMap::RemovePlayerFromMap ( Player player,
bool  remove 
)
overridevirtual

Reimplemented from Map.

3229 {
3230  TC_LOG_DEBUG("maps", "MAP: Removing player '%s' from instance '%u' of map '%s' before relocating to another map", player->GetName().c_str(), GetInstanceId(), GetMapName());
3231  //if last player set unload timer
3232  if (!m_unloadTimer && m_mapRefManager.getSize() == 1)
3234  Map::RemovePlayerFromMap(player, remove);
3235  // for normal instances schedule the reset after all players have left
3236  SetResetSchedule(true);
3237  sInstanceSaveMgr->UnloadInstanceSave(GetInstanceId());
3238 }
Definition: World.h:255
virtual void RemovePlayerFromMap(Player *, bool)
Definition: Map.cpp:872
void SetResetSchedule(bool on)
Definition: Map.cpp:3388
uint32 getSize() const
Definition: LinkedList.h:120
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
#define sWorld
Definition: World.h:887
T max(const T &x, const T &y)
Definition: g3dmath.h:320
uint32 m_unloadTimer
Definition: Map.h:643
#define sInstanceSaveMgr
Definition: InstanceSaveMgr.h:243
uint32_t uint32
Definition: g3dmath.h:168
#define MIN_UNLOAD_DELAY
Definition: Map.h:251
bool m_unloadWhenEmpty
Definition: Map.h:785
const char * GetMapName() const
Definition: Map.cpp:2644
MapRefManager m_mapRefManager
Definition: Map.h:647
uint32 GetInstanceId() const
Definition: Map.h:368

+ Here is the call graph for this function:

bool InstanceMap::Reset ( uint8  method)
3283 {
3284  // note: since the map may not be loaded when the instance needs to be reset
3285  // the instance must be deleted from the DB by InstanceSaveManager
3286 
3287  if (HavePlayers())
3288  {
3289  if (method == INSTANCE_RESET_ALL || method == INSTANCE_RESET_CHANGE_DIFFICULTY)
3290  {
3291  // notify the players to leave the instance so it can be reset
3292  for (MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr)
3293  itr->GetSource()->SendResetFailedNotify(GetId());
3294  }
3295  else
3296  {
3297  bool doUnload = true;
3298  if (method == INSTANCE_RESET_GLOBAL)
3299  {
3300  // set the homebind timer for players inside (1 minute)
3301  for (MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr)
3302  {
3303  InstancePlayerBind* bind = itr->GetSource()->GetBoundInstance(GetId(), GetDifficultyID());
3304  if (bind && bind->extendState && bind->save->GetInstanceId() == GetInstanceId())
3305  doUnload = false;
3306  else
3307  itr->GetSource()->m_InstanceValid = false;
3308  }
3309 
3310  if (doUnload && HasPermBoundPlayers()) // check if any unloaded players have a nonexpired save to this
3311  doUnload = false;
3312  }
3313 
3314  if (doUnload)
3315  {
3316  // the unload timer is not started
3317  // instead the map will unload immediately after the players have left
3318  m_unloadWhenEmpty = true;
3319  m_resetAfterUnload = true;
3320  }
3321  }
3322  }
3323  else
3324  {
3325  // unloaded at next update
3328  }
3329 
3330  return m_mapRefManager.isEmpty();
3331 }
Definition: Map.h:752
Difficulty GetDifficultyID() const
Definition: Map.h:390
Definition: Map.h:750
iterator begin()
Definition: MapRefManager.h:37
uint32 GetId(void) const
Definition: Map.h:325
bool m_resetAfterUnload
Definition: Map.h:784
uint32 m_unloadTimer
Definition: Map.h:643
bool HavePlayers() const
Definition: Map.h:423
bool isEmpty() const
Definition: LinkedList.h:102
bool HasPermBoundPlayers() const
Definition: Map.cpp:3427
#define MIN_UNLOAD_DELAY
Definition: Map.h:251
bool m_unloadWhenEmpty
Definition: Map.h:785
MapRefManager m_mapRefManager
Definition: Map.h:647
uint32 GetInstanceId() const
Definition: Map.h:368
iterator end()
Definition: MapRefManager.h:38

+ Here is the call graph for this function:

void InstanceMap::SendResetWarnings ( uint32  timeLeft) const
3383 {
3385  itr->GetSource()->SendInstanceResetWarning(GetId(), itr->GetSource()->GetDifficultyID(GetEntry()), timeLeft, true);
3386 }
iterator begin()
Definition: MapRefManager.h:37
uint32 GetId(void) const
Definition: Map.h:325
MapEntry const * GetEntry() const
Definition: Map.h:266
Definition: LinkedList.h:141
MapRefManager m_mapRefManager
Definition: Map.h:647
iterator end()
Definition: MapRefManager.h:38

+ Here is the call graph for this function:

void InstanceMap::SetResetSchedule ( bool  on)
3389 {
3390  // only for normal instances
3391  // the reset time is only scheduled when there are no payers inside
3392  // it is assumed that the reset time will rarely (if ever) change while the reset is scheduled
3393  if (IsDungeon() && !HavePlayers() && !IsRaidOrHeroicDungeon())
3394  {
3395  if (InstanceSave* save = sInstanceSaveMgr->GetInstanceSave(GetInstanceId()))
3396  sInstanceSaveMgr->ScheduleReset(on, save->GetResetTime(), InstanceSaveManager::InstResetEvent(0, GetId(), Difficulty(GetSpawnMode()), GetInstanceId()));
3397  else
3398  TC_LOG_ERROR("maps", "InstanceMap::SetResetSchedule: cannot turn schedule %s, there is no save information for instance (map [id: %u, name: %s], instance id: %u, difficulty: %u)",
3399  on ? "on" : "off", GetId(), GetMapName(), GetInstanceId(), Difficulty(GetSpawnMode()));
3400  }
3401 }
Difficulty
Definition: DBCEnums.h:402
uint8 GetSpawnMode() const
Definition: Map.h:369
Definition: InstanceSaveMgr.h:167
bool IsDungeon() const
Definition: Map.h:395
uint32 GetId(void) const
Definition: Map.h:325
bool HavePlayers() const
Definition: Map.h:423
Definition: InstanceSaveMgr.h:44
#define sInstanceSaveMgr
Definition: InstanceSaveMgr.h:243
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
bool IsRaidOrHeroicDungeon() const
Definition: Map.h:398
const char * GetMapName() const
Definition: Map.cpp:2644
uint32 GetInstanceId() const
Definition: Map.h:368

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void InstanceMap::UnloadAll ( )
overridevirtual

Reimplemented from Map.

3370 {
3371  ASSERT(!HavePlayers());
3372 
3373  if (m_resetAfterUnload)
3374  {
3376  DeleteCorpseData();
3377  }
3378 
3379  Map::UnloadAll();
3380 }
bool m_resetAfterUnload
Definition: Map.h:784
void DeleteRespawnTimes()
Definition: Map.cpp:3663
bool HavePlayers() const
Definition: Map.h:423
virtual void UnloadAll()
Definition: Map.cpp:1614
#define ASSERT
Definition: Errors.h:55
void DeleteCorpseData()
Definition: Map.cpp:3760

+ Here is the call graph for this function:

void InstanceMap::Update ( const uint32  t_diff)
overridevirtual

Reimplemented from Map.

3221 {
3222  Map::Update(t_diff);
3223 
3224  if (i_data)
3225  i_data->Update(t_diff);
3226 }
virtual void Update(uint32)
Definition: InstanceScript.h:163
InstanceScript * i_data
Definition: Map.h:786
virtual void Update(const uint32)
Definition: Map.cpp:682

+ Here is the call graph for this function:

Member Data Documentation

InstanceScript* InstanceMap::i_data
private
uint32 InstanceMap::i_script_id
private
bool InstanceMap::m_resetAfterUnload
private
bool InstanceMap::m_unloadWhenEmpty
private

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