mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 19:37:02 +00:00
[10113] Some cleanups in Instance loading code.
* Remove reduncent chekc and args for MapInstanced::CreateInstance(const uint32 mapId, Player * player) * Rename for avoid name duplication raw InstanceMap creating to MapInstanced::CreateInstanceMap * Move lookup code of player/group bounde instance save to Player::GetBoundInstanceSaveForSelfOrGroup
This commit is contained in:
parent
3eb2d2910e
commit
6f4481a591
6 changed files with 50 additions and 45 deletions
|
|
@ -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,30 +107,14 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player)
|
|||
map = _FindMap(NewInstanceId);
|
||||
ASSERT(map);
|
||||
}
|
||||
else
|
||||
{
|
||||
InstancePlayerBind *pBind = player->GetBoundInstance(GetId(), player->GetDifficulty(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 = 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)
|
||||
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 = CreateInstance(NewInstanceId, pSave, pSave->GetDifficulty());
|
||||
if (!map)
|
||||
map = CreateInstanceMap(NewInstanceId, pSave->GetDifficulty(), pSave);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -142,14 +123,13 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player)
|
|||
NewInstanceId = sMapMgr.GenerateInstanceId();
|
||||
|
||||
Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid());
|
||||
map = CreateInstance(NewInstanceId, NULL, diff);
|
||||
}
|
||||
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());
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 ***/
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "10112"
|
||||
#define REVISION_NR "10113"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue