aboutsummaryrefslogtreecommitdiff
path: root/src/game/Player.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/Player.cpp')
-rw-r--r--src/game/Player.cpp45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index 7ea38d6ba0d..004019ec1e6 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -548,7 +548,7 @@ bool Player::Create( uint32 guidlow, const std::string& name, uint8 race, uint8
for (uint8 i = 0; i < PLAYER_SLOTS_COUNT; i++)
m_items[i] = NULL;
- SetMapId(info->mapId);
+ SetLocationMapId(info->mapId);
Relocate(info->positionX,info->positionY,info->positionZ);
ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(class_);
@@ -558,6 +558,8 @@ bool Player::Create( uint32 guidlow, const std::string& name, uint8 race, uint8
return false;
}
+ SetMap(MapManager::Instance().CreateMap(info->mapId, this));
+
uint8 powertype = cEntry->powerType;
SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE);
@@ -12442,7 +12444,11 @@ void Player::PrepareQuestMenu( uint64 guid )
}
else
{
- GameObject *pGameObject = GetMap()->GetGameObject(guid);
+ //we should obtain map pointer from GetMap() in 99% of cases. Special case
+ //only for quests which cast teleport spells on player
+ Map * _map = IsInWorld() ? GetMap() : MapManager::Instance().FindMap(GetMapId(), GetInstanceId());
+ ASSERT(_map);
+ GameObject *pGameObject = _map->GetGameObject(guid);
if( pGameObject )
{
pObject = (Object*)pGameObject;
@@ -14242,7 +14248,8 @@ bool Player::MinimalLoadFromDB( QueryResult *result, uint32 guid )
m_name = fields[2].GetCppString();
Relocate(fields[3].GetFloat(),fields[4].GetFloat(),fields[5].GetFloat());
- SetMapId(fields[6].GetUInt32());
+ SetLocationMapId(fields[6].GetUInt32());
+
// the instance id is not needed at character enum
m_Played_time[0] = fields[7].GetUInt32();
@@ -14551,10 +14558,10 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
// init saved position, and fix it later if problematic
uint32 transGUID = fields[31].GetUInt32();
Relocate(fields[13].GetFloat(),fields[14].GetFloat(),fields[15].GetFloat(),fields[17].GetFloat());
- SetMapId(fields[16].GetUInt32());
+ SetLocationMapId(fields[16].GetUInt32());
SetDifficulty(fields[39].GetUInt32()); // may be changed in _LoadGroup
- SetInstanceId(fields[47].GetFloat());
+ SetLocationInstanceId(fields[47].GetFloat());
_LoadGroup(holder->GetResult(PLAYER_LOGIN_QUERY_LOADGROUP));
@@ -14628,7 +14635,7 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
else
{
const WorldLocation& _loc = GetBattleGroundEntryPoint();
- SetMapId(_loc.mapid);
+ SetLocationMapId(_loc.mapid);
Relocate(_loc.coord_x, _loc.coord_y, _loc.coord_z, _loc.orientation);
//RemoveArenaAuras(true);
}
@@ -14641,7 +14648,7 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
if(!mapEntry || mapEntry->IsBattleGroundOrArena())
{
// return to BG master
- SetMapId(fields[43].GetUInt32());
+ SetLocationMapId(fields[43].GetUInt32());
Relocate(fields[44].GetFloat(),fields[45].GetFloat(),fields[46].GetFloat(),fields[47].GetFloat());
// check entry point and fix to homebind if need
@@ -14695,7 +14702,7 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
m_transport = *iter;
m_transport->AddPassenger(this);
- SetMapId(m_transport->GetMapId());
+ SetLocationMapId(m_transport->GetMapId());
break;
}
}
@@ -14730,18 +14737,18 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
// This fixes the crash. But it is not needed for a new db
if(InstanceSave *pSave = GetInstanceSave(GetMapId()))
if(pSave->GetInstanceId() != GetInstanceId())
- SetInstanceId(pSave->GetInstanceId());
+ SetLocationInstanceId(pSave->GetInstanceId());
// NOW player must have valid map
// load the player's map here if it's not already loaded
- Map *map = GetMap();
+ Map *map = MapManager::Instance().CreateMap(GetMapId(), this);
if (!map)
{
AreaTrigger const* at = objmgr.GetGoBackTrigger(GetMapId());
if(at)
{
- SetMapId(at->target_mapId);
+ SetLocationMapId(at->target_mapId);
Relocate(at->target_X, at->target_Y, at->target_Z, GetOrientation());
sLog.outError("Player (guidlow %d) is teleported to gobacktrigger (Map: %u X: %f Y: %f Z: %f O: %f).",guid,GetMapId(),GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
}
@@ -14751,7 +14758,7 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
sLog.outError("Player (guidlow %d) is teleported to home (Map: %u X: %f Y: %f Z: %f O: %f).",guid,GetMapId(),GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
}
- map = GetMap();
+ map = MapManager::Instance().CreateMap(GetMapId(), this);
if(!map)
{
sLog.outError("ERROR: Player (guidlow %d) have invalid coordinates (X: %f Y: %f Z: %f O: %f). Teleport to default race/class locations.",guid,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
@@ -14771,9 +14778,7 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
}
}
- // since the player may not be bound to the map yet, make sure subsequent
- // getmap calls won't create new maps
- SetInstanceId(map->GetInstanceId());
+ SetMap(map);
// if the player is in an instance and it has been reset in the meantime teleport him to the entrance
if(GetInstanceId() && !sInstanceSaveManager.GetInstanceSave(GetInstanceId()))
@@ -14952,15 +14957,19 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
{
sLog.outError("Character %u have wrong data in taxi destination list, teleport to homebind.",GetGUIDLow());
RelocateToHomebind();
- SaveRecallPosition(); // save as recall also to prevent recall and fall from sky
}
else // have start node, to it
{
sLog.outError("Character %u have too short taxi destination list, teleport to original node.",GetGUIDLow());
- SetMapId(nodeEntry->map_id);
+ SetLocationMapId(nodeEntry->map_id);
Relocate(nodeEntry->x, nodeEntry->y, nodeEntry->z,0.0f);
- SaveRecallPosition(); // save as recall also to prevent recall and fall from sky
}
+
+ //we can be relocated from taxi and still have an outdated Map pointer!
+ //so we need to get a new Map pointer!
+ SetMap(MapManager::Instance().CreateMap(GetMapId(), this));
+ SaveRecallPosition(); // save as recall also to prevent recall and fall from sky
+
m_taxi.ClearTaxiDestinations();
}
else if(uint32 node_id = m_taxi.GetTaxiSource())