OpenSim.Region.ScriptEngine.Shared.Api.LSL_Api.GetLinkEntity C# (CSharp) Method

GetLinkEntity() public method

Get a given link entity from a linkset (linked objects and any sitting avatars).
If there are any ScenePresence's in the linkset (i.e. because they are sat upon one of the prims), then these are counted as extra entities that correspond to linknums beyond the number of prims in the linkset. The ScenePresences receive linknums in the order in which they sat.
public GetLinkEntity ( SceneObjectPart part, int linknum ) : ISceneEntity
part OpenSim.Region.Framework.Scenes.SceneObjectPart
linknum int /// Can be either a non-negative integer or ScriptBaseClass.LINK_THIS (-4). /// If ScriptBaseClass.LINK_THIS then the entity containing the script is returned. /// If the linkset has one entity and a linknum of zero is given, then the single entity is returned. If any /// positive integer is given in this case then null is returned. /// If the linkset has more than one entity and a linknum greater than zero but equal to or less than the number /// of entities, then the entity which corresponds to that linknum is returned. /// Otherwise, if a positive linknum is given which is greater than the number of entities in the linkset, then /// null is returned. ///
return ISceneEntity
        public ISceneEntity GetLinkEntity(SceneObjectPart part, int linknum)
        {
            if (linknum < 0)
            {
                if (linknum == ScriptBaseClass.LINK_THIS)
                    return part;
                else
                    return null;
            }

            int actualPrimCount = part.ParentGroup.PrimCount;
            List<ScenePresence> sittingAvatars = part.ParentGroup.GetSittingAvatars();
            int adjustedPrimCount = actualPrimCount + sittingAvatars.Count;

            // Special case for a single prim.  In this case the linknum is zero.  However, this will not match a single
            // prim that has any avatars sat upon it (in which case the root prim is link 1).
            if (linknum == 0)
            {
                if (actualPrimCount == 1 && sittingAvatars.Count == 0)
                    return part;

                return null;
            }
            // Special case to handle a single prim with sitting avatars.  GetLinkPart() would only match zero but
            // here we must match 1 (ScriptBaseClass.LINK_ROOT).
            else if (linknum == ScriptBaseClass.LINK_ROOT && actualPrimCount == 1)
            {
                if (sittingAvatars.Count > 0)
                    return part.ParentGroup.RootPart;
                else
                    return null;
            }
            else if (linknum <= adjustedPrimCount)
            {
                if (linknum <= actualPrimCount)
                {
                    return part.ParentGroup.GetLinkNumPart(linknum);
                }
                else
                {
                    return sittingAvatars[linknum - actualPrimCount - 1];
                }
            }
            else
            {
                return null;
            }
        }
LSL_Api