diff --git a/src/game/MapInstanced.cpp b/src/game/MapInstanced.cpp index c1f7c0224..c2ab7f28d 100644 --- a/src/game/MapInstanced.cpp +++ b/src/game/MapInstanced.cpp @@ -94,13 +94,10 @@ void MapInstanced::UnloadAll(bool pForce) /// returns a new or existing Instance /// in case of battlegrounds it will only return an existing map, those maps are created by bg-system -Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player) +Map* MapInstanced::CreateInstance(Player * player) { - if(GetId() != mapId || !player) - return NULL; - - Map* map = NULL; - uint32 NewInstanceId = 0; // instanceId of the resulting map + Map* map; + uint32 NewInstanceId; // instanceId of the resulting map if(IsBattleGroundOrArena()) { @@ -110,46 +107,29 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player) map = _FindMap(NewInstanceId); ASSERT(map); } + else if (InstanceSave* pSave = player->GetBoundInstanceSaveForSelfOrGroup(GetId())) + { + // solo/perm/group + NewInstanceId = pSave->GetInstanceId(); + map = _FindMap(NewInstanceId); + // it is possible that the save exists but the map doesn't + if (!map) + map = CreateInstanceMap(NewInstanceId, pSave->GetDifficulty(), pSave); + } else { - InstancePlayerBind *pBind = player->GetBoundInstance(GetId(), player->GetDifficulty(IsRaid())); - InstanceSave *pSave = pBind ? pBind->save : NULL; + // if no instanceId via group members or instance saves is found + // the instance will be created for the first time + NewInstanceId = sMapMgr.GenerateInstanceId(); - // the player's permanent player bind is taken into consideration first - // then the player's group bind and finally the solo bind. - if(!pBind || !pBind->perm) - { - InstanceGroupBind *groupBind = NULL; - Group *group = player->GetGroup(); - // use the player's difficulty setting (it may not be the same as the group's) - if(group && (groupBind = group->GetBoundInstance(this,player->GetDifficulty(IsRaid())))) - pSave = groupBind->save; - } - - if(pSave) - { - // solo/perm/group - NewInstanceId = pSave->GetInstanceId(); - map = _FindMap(NewInstanceId); - // it is possible that the save exists but the map doesn't - if(!map) - map = CreateInstance(NewInstanceId, pSave, pSave->GetDifficulty()); - } - else - { - // if no instanceId via group members or instance saves is found - // the instance will be created for the first time - NewInstanceId = sMapMgr.GenerateInstanceId(); - - Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid()); - map = CreateInstance(NewInstanceId, NULL, diff); - } + Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid()); + map = CreateInstanceMap(NewInstanceId, diff); } return map; } -InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave *save, Difficulty difficulty) +InstanceMap* MapInstanced::CreateInstanceMap(uint32 InstanceId, Difficulty difficulty, InstanceSave *save) { // load/create a map Guard guard(*this); @@ -157,12 +137,12 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave *save, // make sure we have a valid map id if (!sMapStore.LookupEntry(GetId())) { - sLog.outError("CreateInstance: no entry for map %d", GetId()); + sLog.outError("CreateInstanceMap: no entry for map %d", GetId()); ASSERT(false); } if (!ObjectMgr::GetInstanceTemplate(GetId())) { - sLog.outError("CreateInstance: no instance template for map %d", GetId()); + sLog.outError("CreateInstanceMap: no instance template for map %d", GetId()); ASSERT(false); } @@ -170,7 +150,7 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave *save, if (!GetMapDifficultyData(GetId(),difficulty)) difficulty = DUNGEON_DIFFICULTY_NORMAL; - DEBUG_LOG("MapInstanced::CreateInstance: %s map instance %d for %d created with difficulty %s", save?"":"new ", InstanceId, GetId(), difficulty?"heroic":"normal"); + DEBUG_LOG("MapInstanced::CreateInstanceMap: %s map instance %d for %d created with difficulty %d", save?"":"new ", InstanceId, GetId(), difficulty); InstanceMap *map = new InstanceMap(GetId(), GetGridExpiry(), InstanceId, difficulty, this); ASSERT(map->IsDungeon()); diff --git a/src/game/MapInstanced.h b/src/game/MapInstanced.h index 79dca285b..45edb4e3f 100644 --- a/src/game/MapInstanced.h +++ b/src/game/MapInstanced.h @@ -37,7 +37,7 @@ class MANGOS_DLL_DECL MapInstanced : public Map void RemoveAllObjectsInRemoveList(); void UnloadAll(bool pForce); - Map* CreateInstance(const uint32 mapId, Player * player); + Map* CreateInstance(Player* player); Map* FindMap(uint32 InstanceId) const { return _FindMap(InstanceId); } void DestroyInstance(uint32 InstanceId); void DestroyInstance(InstancedMaps::iterator &itr); @@ -61,7 +61,7 @@ class MANGOS_DLL_DECL MapInstanced : public Map private: - InstanceMap* CreateInstance(uint32 InstanceId, InstanceSave *save, Difficulty difficulty); + InstanceMap* CreateInstanceMap(uint32 InstanceId, Difficulty difficulty, InstanceSave *save = NULL); InstancedMaps m_InstancedMaps; diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp index 5f9622d2f..23711e7b6 100644 --- a/src/game/MapManager.cpp +++ b/src/game/MapManager.cpp @@ -120,7 +120,8 @@ Map* MapManager::CreateMap(uint32 id, const WorldObject* obj) //if(!obj->IsInWorld()) sLog.outError("GetMap: called for map %d with object (typeid %d, guid %d, mapid %d, instanceid %d) who is not in world!", id, obj->GetTypeId(), obj->GetGUIDLow(), obj->GetMapId(), obj->GetInstanceId()); Map *m = _createBaseMap(id); - if (m && (obj->GetTypeId() == TYPEID_PLAYER) && m->Instanceable()) m = ((MapInstanced*)m)->CreateInstance(id, (Player*)obj); + if (m && (obj->GetTypeId() == TYPEID_PLAYER) && m->Instanceable()) + m = ((MapInstanced*)m)->CreateInstance((Player*)obj); return m; } diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 4ad4549d2..e44d34d3d 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -16423,6 +16423,29 @@ InstancePlayerBind* Player::BindToInstance(InstanceSave *save, bool permanent, b return NULL; } +InstanceSave* Player::GetBoundInstanceSaveForSelfOrGroup(uint32 mapid) +{ + MapEntry const* mapEntry = sMapStore.LookupEntry(mapid); + if(!mapEntry) + return NULL; + + InstancePlayerBind *pBind = GetBoundInstance(mapid, GetDifficulty(mapEntry->IsRaid())); + InstanceSave *pSave = pBind ? pBind->save : NULL; + + // the player's permanent player bind is taken into consideration first + // then the player's group bind and finally the solo bind. + if(!pBind || !pBind->perm) + { + InstanceGroupBind *groupBind = NULL; + Group *group = GetGroup(); + // use the player's difficulty setting (it may not be the same as the group's) + if(group && (groupBind = group->GetBoundInstance(this))) + pSave = groupBind->save; + } + + return pSave; +} + void Player::SendRaidInfo() { uint32 counter = 0; diff --git a/src/game/Player.h b/src/game/Player.h index 548d4645f..059aa2b57 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -2302,6 +2302,7 @@ class MANGOS_DLL_SPEC Player : public Unit void SendRaidInfo(); void SendSavedInstances(); static void ConvertInstancesToGroup(Player *player, Group *group = NULL, uint64 player_guid = 0); + InstanceSave* GetBoundInstanceSaveForSelfOrGroup(uint32 mapid); /*********************************************************/ /*** GROUP SYSTEM ***/ diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 8c6e5adf5..b33cab190 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10112" + #define REVISION_NR "10113" #endif // __REVISION_NR_H__