public void MakeRootAgent(Vector3 pos, bool isFlying)
{
m_log.DebugFormat(
"[SCENE]: Upgrading child to root agent for {0} in {1}",
Name, m_scene.RegionInfo.RegionName);
//m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
if (gm != null)
m_grouptitle = gm.GetGroupTitle(m_uuid);
m_rootRegionHandle = m_scene.RegionInfo.RegionHandle;
m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
// Moved this from SendInitialData to ensure that m_appearance is initialized
// before the inventory is processed in MakeRootAgent. This fixes a race condition
// related to the handling of attachments
//m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance);
if (m_scene.TestBorderCross(pos, Cardinals.E))
{
Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
pos.X = crossedBorder.BorderLine.Z - 1;
}
if (m_scene.TestBorderCross(pos, Cardinals.N))
{
Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
pos.Y = crossedBorder.BorderLine.Z - 1;
}
if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
{
m_log.WarnFormat(
"[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
pos, Name, UUID);
if (pos.X < 0f) pos.X = 0f;
if (pos.Y < 0f) pos.Y = 0f;
if (pos.Z < 0f) pos.Z = 0f;
}
float localAVHeight = 1.56f;
if (m_appearance != null)
{
if (m_appearance.AvatarHeight > 0)
localAVHeight = m_appearance.AvatarHeight;
}
{
if(m_scene.Voxels.IsInsideTerrain(pos))
{
Vector3 newPos=m_scene.Voxels.FindNearestAirVoxel(pos,true);
newPos.Z+=localAVHeight / 2;
pos=newPos;
}
}
float posZLimit = 0;
AbsolutePosition = pos;
if (m_appearance != null)
{
if (m_appearance.AvatarHeight > 0)
SetHeight(m_appearance.AvatarHeight);
}
else
{
m_log.ErrorFormat("[SCENE PRESENCE]: null appearance in MakeRoot in {0}", Scene.RegionInfo.RegionName);
// emergency; this really shouldn't happen
m_appearance = new AvatarAppearance(UUID);
}
AddToPhysicalScene(isFlying);
if (m_appearance != null)
{
if (m_appearance.AvatarHeight > 0)
SetHeight(m_appearance.AvatarHeight);
}
if (m_forceFly)
{
m_physicsActor.Flying = true;
}
else if (m_flyDisabled)
{
m_physicsActor.Flying = false;
}
// Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
// avatar to return to the standing position in mid-air. On login it looks like this is being sent
// elsewhere anyway
// Animator.SendAnimPack();
m_scene.SwapRootAgentCount(false);
//CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(m_uuid);
//if (userInfo != null)
// userInfo.FetchInventory();
//else
// m_log.ErrorFormat("[SCENE]: Could not find user info for {0} when making it a root agent", m_uuid);
// On the next prim update, all objects will be sent
//
m_sceneViewer.Reset();
m_isChildAgent = false;
// send the animations of the other presences to me
m_scene.ForEachScenePresence(delegate(ScenePresence presence)
{
if (presence != this)
presence.Animator.SendAnimPackToClient(ControllingClient);
});
m_scene.EventManager.TriggerOnMakeRootAgent(this);
}