示例#1
0
 public bool LinkPartToSOG(SceneObjectGroup grp, SceneObjectPart part, int linkNum)
 {
     part.SetParentLocalId(grp.RootPart.LocalId);
     part.SetParent(grp);
     // Insert in terms of link numbers, the new links
     // before the current ones (with the exception of 
     // the root prim. Shuffle the old ones up
     foreach (ISceneEntity otherPart in grp.ChildrenEntities())
     {
         if (otherPart.LinkNum >= linkNum)
         {
             // Don't update root prim link number
             otherPart.LinkNum += 1;
         }
     }
     part.LinkNum = linkNum;
     return LinkPartToEntity(grp, part);
 }
        /// <summary>
        /// Move the given scene object into a new region
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="grp">Scene Object Group that we're crossing</param>
        /// <param name="attemptedPos"></param>
        /// <returns>
        /// true if the crossing itself was successful, false on failure
        /// </returns>
        protected bool CrossPrimGroupIntoNewRegion(GridRegion destination, SceneObjectGroup grp, Vector3 attemptedPos)
        {
            bool successYN = false;
            if (destination != null)
            {
                if(grp.SitTargetAvatar.Count != 0)
                {
                    bool success = false;
                    foreach (UUID avID in grp.SitTargetAvatar)
                    {
                        IScenePresence SP = grp.Scene.GetScenePresence(avID);
                        SP.Velocity = grp.RootChild.PhysActor.Velocity;
                        InternalCross(SP, attemptedPos, false, destination);
                        success = grp.Scene.GetScenePresence(avID).IsChildAgent;
                    }
                    if(success)
                    {
                        foreach(ISceneChildEntity part in grp.ChildrenEntities())
                            part.SitTargetAvatar.Clear();

                        IBackupModule backup = grp.Scene.RequestModuleInterface<IBackupModule>();
                        if(backup != null)
                            return backup.DeleteSceneObjects(new[] { grp }, false, false);
                        return true;//They do all the work adding the prim in the other region
                    }
                    return false;
                }

                SceneObjectGroup copiedGroup = (SceneObjectGroup)grp.Copy(false);
                copiedGroup.SetAbsolutePosition(true, attemptedPos);
                if (grp.Scene != null)
                    successYN = grp.Scene.RequestModuleInterface<ISimulationService>().CreateObject(destination, copiedGroup);

                if (successYN)
                {
                    // We remove the object here
                    try
                    {
                        foreach (ISceneChildEntity part in grp.ChildrenEntities())
                            part.SitTargetAvatar.Clear();

                        IBackupModule backup = grp.Scene.RequestModuleInterface<IBackupModule>();
                        if (backup != null)
                            return backup.DeleteSceneObjects(new[] { grp }, false, true);
                    }
                    catch (Exception e)
                    {
                        MainConsole.Instance.ErrorFormat(
                            "[ENTITY TRANSFER MODULE]: Exception deleting the old object left behind on a border crossing for {0}, {1}",
                            grp, e);
                    }
                }
                else
                {
                    if (!grp.IsDeleted)
                    {
                        if (grp.RootPart.PhysActor != null)
                        {
                            grp.RootPart.PhysActor.CrossingFailure();
                        }
                    }

                    MainConsole.Instance.ErrorFormat("[ENTITY TRANSFER MODULE]: Prim crossing failed for {0}", grp);
                }
            }
            else
            {
                MainConsole.Instance.Error("[ENTITY TRANSFER MODULE]: destination was unexpectedly null in Scene.CrossPrimGroupIntoNewRegion()");
            }

            return successYN;
        }
        /// <summary>
        /// Move the given scene object into a new region
        /// </summary>
        /// <param name="newRegionHandle"></param>
        /// <param name="grp">Scene Object Group that we're crossing</param>
        /// <returns>
        /// true if the crossing itself was successful, false on failure
        /// </returns>
        protected bool CrossPrimGroupIntoNewRegion(GridRegion destination, SceneObjectGroup grp, Vector3 attemptedPos)
        {
            bool successYN = false;
            grp.RootPart.ClearUpdateScheduleOnce();
            if (destination != null)
            {
                if (grp.SitTargetAvatar.Count != 0)
                {
                    lock (grp.SitTargetAvatar)
                    {
                        foreach (UUID avID in grp.SitTargetAvatar)
                        {
                            IScenePresence SP = grp.Scene.GetScenePresence(avID);
                            CrossAgentToNewRegionAsync(SP, grp.AbsolutePosition, destination, false);
                        }
                    }
                }

                SceneObjectGroup copiedGroup = (SceneObjectGroup)grp.Copy(false);
                copiedGroup.SetAbsolutePosition(true, attemptedPos);
                if (grp.Scene != null && grp.Scene.SimulationService != null)
                    successYN = grp.Scene.SimulationService.CreateObject(destination, copiedGroup);

                if (successYN)
                {
                    // We remove the object here
                    try
                    {
                        foreach (ISceneChildEntity part in grp.ChildrenEntities())
                        {
                            part.SitTargetAvatar.Clear();
                        }
                        IBackupModule backup = grp.Scene.RequestModuleInterface<IBackupModule>();
                        if (backup != null)
                            return backup.DeleteSceneObjects(new SceneObjectGroup[1] { grp }, false);
                    }
                    catch (Exception e)
                    {
                        m_log.ErrorFormat(
                            "[ENTITY TRANSFER MODULE]: Exception deleting the old object left behind on a border crossing for {0}, {1}",
                            grp, e);
                    }
                }
                else
                {
                    if (!grp.IsDeleted)
                    {
                        if (grp.RootPart.PhysActor != null)
                        {
                            grp.RootPart.PhysActor.CrossingFailure();
                        }
                    }

                    m_log.ErrorFormat("[ENTITY TRANSFER MODULE]: Prim crossing failed for {0}", grp);
                }
            }
            else
            {
                m_log.Error("[ENTITY TRANSFER MODULE]: destination was unexpectedly null in Scene.CrossPrimGroupIntoNewRegion()");
            }

            return successYN;
        }