Пример #1
0
 public DetectParams()
 {
     Key = UUID.Zero;
     OffsetPos = new LSL_Types.Vector3();
     LinkNum = 0;
     Group = UUID.Zero;
     Name = String.Empty;
     Owner = UUID.Zero;
     Position = new LSL_Types.Vector3();
     Rotation = new LSL_Types.Quaternion();
     Type = 0;
     Velocity = new LSL_Types.Vector3();
     initializeSurfaceTouch();
 }
Пример #2
0
        public bool PostObjectEvent(UUID itemID, string name, Object[] p)
        {
            SceneObjectPart part = m_Scene.GetSceneObjectPart(itemID);
            if (part == null)
                return false;

            Object[] lsl_p = new Object[p.Length];
            for (int i = 0; i < p.Length ; i++)
            {
                if (p[i] is int)
                    lsl_p[i] = new LSL_Types.LSLInteger((int)p[i]);
                else if (p[i] is string)
                    lsl_p[i] = new LSL_Types.LSLString((string)p[i]);
                else if (p[i] is Vector3)
                    lsl_p[i] = new LSL_Types.Vector3((Vector3)p[i]);
                else if (p[i] is Quaternion)
                    lsl_p[i] = new LSL_Types.Quaternion((Quaternion)p[i]);
                else if (p[i] is float)
                    lsl_p[i] = new LSL_Types.LSLFloat((float)p[i]);
                else
                    lsl_p[i] = p[i];
            }

            return PostObjectEvent(part.LocalId, new EventParams(name, lsl_p, new DetectParams[0]));
        }
Пример #3
0
        public void Populate(Scene scene)
        {
            SceneObjectPart part = scene.GetSceneObjectPart(Key);
            if (part == null) // Avatar, maybe?
            {
                ScenePresence presence = scene.GetScenePresence(Key);
                if (presence == null)
                    return;

                Name = presence.Firstname + " " + presence.Lastname;
                Owner = Key;
                Position = new LSL_Types.Vector3(presence.AbsolutePosition);
                Rotation = new LSL_Types.Quaternion(
                        presence.Rotation.X,
                        presence.Rotation.Y,
                        presence.Rotation.Z,
                        presence.Rotation.W);
                Velocity = new LSL_Types.Vector3(presence.Velocity);

                if (presence.PresenceType != PresenceType.Npc)
                {
                    Type = AGENT;
                }
                else
                {
                    Type = OS_NPC;

                    INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
                    INPC npcData = npcModule.GetNPC(presence.UUID, presence.Scene);

                    if (npcData.SenseAsAgent)
                    {
                        Type |= AGENT;
                    }
                }

                if (presence.Velocity != Vector3.Zero)
                    Type |= ACTIVE;

                Group = presence.ControllingClient.ActiveGroupId;

                return;
            }

            part = part.ParentGroup.RootPart; // We detect objects only

            LinkNum = 0; // Not relevant

            Group = part.GroupID;
            Name = part.Name;
            Owner = part.OwnerID;
            if (part.Velocity == Vector3.Zero)
                Type = PASSIVE;
            else
                Type = ACTIVE;

            foreach (SceneObjectPart p in part.ParentGroup.Parts)
            {
                if (p.Inventory.ContainsScripts())
                {
                    Type |= SCRIPTED; // Scripted
                    break;
                }
            }

            Position = new LSL_Types.Vector3(part.AbsolutePosition);

            Quaternion wr = part.ParentGroup.GroupRotation;
            Rotation = new LSL_Types.Quaternion(wr.X, wr.Y, wr.Z, wr.W);

            Velocity = new LSL_Types.Vector3(part.Velocity);
        }
Пример #4
0
        private List<SensedEntity> doAgentSensor(SensorInfo ts)
        {
            List<SensedEntity> sensedEntities = new List<SensedEntity>();

            // If nobody about quit fast
            if (m_CmdManager.m_ScriptEngine.World.GetRootAgentCount() == 0)
                return sensedEntities;

            SceneObjectPart SensePoint = ts.host;
            Vector3 fromRegionPos = SensePoint.GetWorldPosition();
            
            Quaternion q = SensePoint.GetWorldRotation();
            if (SensePoint.ParentGroup.IsAttachment)
            {
                // In attachments, rotate the sensor cone with the
                // avatar rotation. This may include a nonzero elevation if
                // in mouselook.
                // This will not include the rotation and position of the
                // attachment point (e.g. your head when a sensor is in your
                // hair attached to your scull. Your hair  will turn with
                // your head but the sensor will stay with your (global)
                // avatar rotation and position.
                // Position of a sensor in a child prim attached to an avatar
                // will be still wrong. 
                ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
                q = avatar.GetWorldRotation() * q;
            }

            LSL_Types.Quaternion r = new LSL_Types.Quaternion(q);
            LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
            double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
            bool attached = (SensePoint.ParentGroup.AttachmentPoint != 0);
            Vector3 toRegionPos;
            double dis;
            
            Action<ScenePresence> senseEntity = new Action<ScenePresence>(presence =>
            {
//                m_log.DebugFormat(
//                    "[SENSOR REPEAT]: Inspecting scene presence {0}, type {1} on sensor sweep for {2}, type {3}",
//                    presence.Name, presence.PresenceType, ts.name, ts.type);

                if ((ts.type & NPC) == 0 && (ts.type & OS_NPC) == 0 && presence.PresenceType == PresenceType.Npc)
                {
                    INPC npcData = m_npcModule.GetNPC(presence.UUID, presence.Scene);
                    if (npcData == null || !npcData.SenseAsAgent)
                    {
//                        m_log.DebugFormat(
//                            "[SENSOR REPEAT]: Discarding NPC {0} from agent sense sweep for script item id {1}",
//                            presence.Name, ts.itemID);
                        return;
                    }
                }

                if ((ts.type & AGENT) == 0)
                {
                    if (presence.PresenceType == PresenceType.User)
                    {
                        return;
                    }
                    else
                    {
                        INPC npcData = m_npcModule.GetNPC(presence.UUID, presence.Scene);
                        if (npcData != null && npcData.SenseAsAgent)
                        {
//                            m_log.DebugFormat(
//                                "[SENSOR REPEAT]: Discarding NPC {0} from non-agent sense sweep for script item id {1}",
//                                presence.Name, ts.itemID);
                            return;
                        }
                    }
                }

                if (presence.IsDeleted || presence.IsChildAgent || presence.GodLevel > 0.0)
                    return;
                
                // if the object the script is in is attached and the avatar is the owner
                // then this one is not wanted
                if (attached && presence.UUID == SensePoint.OwnerID)
                    return;

                toRegionPos = presence.AbsolutePosition;
                dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos));

                // Disabled for now since all osNpc* methods check for appropriate ownership permission.
                // Perhaps could be re-enabled as an NPC setting at some point since being able to make NPCs not
                // sensed might be useful.
//                if (presence.PresenceType == PresenceType.Npc && npcModule != null)
//                {
//                    UUID npcOwner = npcModule.GetOwner(presence.UUID);
//                    if (npcOwner != UUID.Zero && npcOwner != SensePoint.OwnerID)
//                        return;
//                }

                // are they in range
                if (dis <= ts.range)
                {
                    // Are they in the required angle of view
                    if (ts.arc < Math.PI)
                    {
                        // not omni-directional. Can you see it ?
                        // vec forward_dir = llRot2Fwd(llGetRot())
                        // vec obj_dir = toRegionPos-fromRegionPos
                        // dot=dot(forward_dir,obj_dir)
                        // mag_fwd = mag(forward_dir)
                        // mag_obj = mag(obj_dir)
                        // ang = acos(dot /(mag_fwd*mag_obj))
                        double ang_obj = 0;
                        try
                        {
                            LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(
                                toRegionPos - fromRegionPos);
                            double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir);
                            double mag_obj = LSL_Types.Vector3.Mag(obj_dir);
                            ang_obj = Math.Acos(dot / (mag_fwd * mag_obj));
                        }
                        catch
                        {
                        }
                        if (ang_obj <= ts.arc)
                        {
                            sensedEntities.Add(new SensedEntity(dis, presence.UUID));
                        }
                    }
                    else
                    {
                        sensedEntities.Add(new SensedEntity(dis, presence.UUID));
                    }
                }
            });

            // If this is an avatar sense by key try to get them directly
            // rather than getting a list to scan through
            if (ts.keyID != UUID.Zero)
            {
                ScenePresence sp;
                // Try direct lookup by UUID
                if (!m_CmdManager.m_ScriptEngine.World.TryGetScenePresence(ts.keyID, out sp))
                    return sensedEntities;
                senseEntity(sp);
            }
            else if (ts.name != null && ts.name != "")
            {
                ScenePresence sp;
                // Try lookup by name will return if/when found
                if (((ts.type & AGENT) != 0) && m_CmdManager.m_ScriptEngine.World.TryGetAvatarByName(ts.name, out sp))
                    senseEntity(sp);
                if ((ts.type & AGENT_BY_USERNAME) != 0)
                {
                    m_CmdManager.m_ScriptEngine.World.ForEachRootScenePresence(
                        delegate (ScenePresence ssp)
                        {
                            if (ssp.Lastname == "Resident")
                            {
                                if (ssp.Firstname.ToLower() == ts.name)
                                    senseEntity(ssp);
                                return;
                            }
                            if (ssp.Name.Replace(" ", ".").ToLower() == ts.name)
                                senseEntity(ssp);
                        }
                    );
                }

                return sensedEntities;
            }
            else
            {
                m_CmdManager.m_ScriptEngine.World.ForEachRootScenePresence(senseEntity);
            }
            return sensedEntities;
        }
Пример #5
0
        public bool PostScriptEvent(UUID itemID, string name, Object[] p)
        {
            Object[] lsl_p = new Object[p.Length];
            for (int i = 0; i < p.Length ; i++)
            {
                if (p[i] is int)
                    lsl_p[i] = new LSL_Types.LSLInteger((int)p[i]);
                else if (p[i] is string)
                    lsl_p[i] = new LSL_Types.LSLString((string)p[i]);
                else if (p[i] is Vector3)
                    lsl_p[i] = new LSL_Types.Vector3((Vector3)p[i]);
                else if (p[i] is Quaternion)
                    lsl_p[i] = new LSL_Types.Quaternion((Quaternion)p[i]);
                else if (p[i] is float)
                    lsl_p[i] = new LSL_Types.LSLFloat((float)p[i]);
                else
                    lsl_p[i] = p[i];
            }

            return PostScriptEvent(itemID, new EventParams(name, lsl_p, new DetectParams[0]));
        }
Пример #6
0
        public void TestExplicitCastLSLStringToQuaternion()
        {
            TestHelpers.InMethod();

            string quaternionString = "<0.00000, 0.70711, 0.00000, 0.70711>";
            LSL_Types.LSLString quaternionLSLString = new LSL_Types.LSLString(quaternionString);

            LSL_Types.Quaternion expectedQuaternion = new LSL_Types.Quaternion(0.0, 0.70711, 0.0, 0.70711);
            LSL_Types.Quaternion stringQuaternion = (LSL_Types.Quaternion) quaternionString;
            LSL_Types.Quaternion LSLStringQuaternion = (LSL_Types.Quaternion) quaternionLSLString;

            Assert.AreEqual(expectedQuaternion, stringQuaternion);
            Assert.AreEqual(expectedQuaternion, LSLStringQuaternion);
        }
Пример #7
0
        private List<SensedEntity> doObjectSensor(SensorInfo ts)
        {
            List<EntityBase> Entities;
            List<SensedEntity> sensedEntities = new List<SensedEntity>();

            // If this is an object sense by key try to get it directly
            // rather than getting a list to scan through
            if (ts.keyID != UUID.Zero)
            {
                EntityBase e = null;
                m_CmdManager.m_ScriptEngine.World.Entities.TryGetValue(ts.keyID, out e);
                if (e == null)
                    return sensedEntities;
                Entities = new List<EntityBase>();
                Entities.Add(e);
            }
            else
            {
                Entities = new List<EntityBase>(m_CmdManager.m_ScriptEngine.World.GetEntities());
            }
            SceneObjectPart SensePoint = ts.host;

            Vector3 fromRegionPos = SensePoint.GetWorldPosition();

            // pre define some things to avoid repeated definitions in the loop body
            Vector3 toRegionPos;
            double dis;
            int objtype;
            SceneObjectPart part;
            float dx;
            float dy;
            float dz;

            Quaternion q = SensePoint.GetWorldRotation();
            if (SensePoint.ParentGroup.IsAttachment)
            {
                // In attachments, rotate the sensor cone with the
                // avatar rotation. This may include a nonzero elevation if
                // in mouselook.
                // This will not include the rotation and position of the
                // attachment point (e.g. your head when a sensor is in your
                // hair attached to your scull. Your hair  will turn with
                // your head but the sensor will stay with your (global)
                // avatar rotation and position.
                // Position of a sensor in a child prim attached to an avatar
                // will be still wrong. 
                ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
                q = avatar.GetWorldRotation() * q;
            }

            LSL_Types.Quaternion r = new LSL_Types.Quaternion(q);
            LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
            double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);

            Vector3 ZeroVector = new Vector3(0, 0, 0);

            bool nameSearch = (ts.name != null && ts.name != "");

            foreach (EntityBase ent in Entities)
            {
                bool keep = true;

                if (nameSearch && ent.Name != ts.name) // Wrong name and it is a named search
                    continue;

                if (ent.IsDeleted) // taken so long to do this it has gone from the scene
                    continue;

                if (!(ent is SceneObjectGroup)) // dont bother if it is a pesky avatar
                    continue;
                toRegionPos = ent.AbsolutePosition;

                // Calculation is in line for speed
                dx = toRegionPos.X - fromRegionPos.X;
                dy = toRegionPos.Y - fromRegionPos.Y;
                dz = toRegionPos.Z - fromRegionPos.Z;

                // Weed out those that will not fit in a cube the size of the range
                // no point calculating if they are within a sphere the size of the range
                // if they arent even in the cube
                if (Math.Abs(dx) > ts.range || Math.Abs(dy) > ts.range || Math.Abs(dz) > ts.range)
                    dis = ts.range + 1.0;
                else
                    dis = Math.Sqrt(dx * dx + dy * dy + dz * dz);

                if (keep && dis <= ts.range && ts.host.UUID != ent.UUID)
                {
                    // In Range and not the object containing the script, is it the right Type ?
                    objtype = 0;

                    part = ((SceneObjectGroup)ent).RootPart;
                    if (part.ParentGroup.AttachmentPoint != 0) // Attached so ignore
                        continue;

                    if (part.Inventory.ContainsScripts())
                    {
                        objtype |= ACTIVE | SCRIPTED; // Scripted and active. It COULD have one hidden ...
                    }
                    else
                    {
                        if (ent.Velocity.Equals(ZeroVector))
                        {
                            objtype |= PASSIVE; // Passive non-moving
                        }
                        else
                        {
                            objtype |= ACTIVE; // moving so active
                        }
                    }

                    // If any of the objects attributes match any in the requested scan type
                    if (((ts.type & objtype) != 0))
                    {
                        // Right type too, what about the other params , key and name ?
                        if (ts.arc < Math.PI)
                        {
                            // not omni-directional. Can you see it ?
                            // vec forward_dir = llRot2Fwd(llGetRot())
                            // vec obj_dir = toRegionPos-fromRegionPos
                            // dot=dot(forward_dir,obj_dir)
                            // mag_fwd = mag(forward_dir)
                            // mag_obj = mag(obj_dir)
                            // ang = acos(dot /(mag_fwd*mag_obj))
                            double ang_obj = 0;
                            try
                            {
                                Vector3 diff = toRegionPos - fromRegionPos;
                                double dot = LSL_Types.Vector3.Dot(forward_dir, diff);
                                double mag_obj = LSL_Types.Vector3.Mag(diff);
                                ang_obj = Math.Acos(dot / (mag_fwd * mag_obj));
                            }
                            catch
                            {
                            }

                            if (ang_obj > ts.arc) keep = false;
                        }

                        if (keep == true)
                        {
                            // add distance for sorting purposes later
                            sensedEntities.Add(new SensedEntity(dis, ent.UUID));
                        }
                    }
                }
            }
            return sensedEntities;
        }
Пример #8
0
        private List<SensedEntity> doAgentSensor(SenseRepeatClass ts)
        {
            List<ScenePresence> presences;
            List<SensedEntity> sensedEntities = new List<SensedEntity>();

            // If this is an avatar sense by key try to get them directly
            // rather than getting a list to scan through
            if (ts.keyID != UUID.Zero)
            {
                ScenePresence p = m_CmdManager.m_ScriptEngine.World.GetScenePresence(ts.keyID);
                if (p == null)
                    return sensedEntities;
                presences = new List<ScenePresence>();
                presences.Add(p);
            }
            else
            {
                presences = new List<ScenePresence>(m_CmdManager.m_ScriptEngine.World.GetScenePresences());
            }

            // If nobody about quit fast
            if (presences.Count == 0)
                return sensedEntities;

            SceneObjectPart SensePoint = ts.host;

            Vector3 fromRegionPos = SensePoint.AbsolutePosition;

            Quaternion q = SensePoint.RotationOffset;
            LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
            LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
            double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);

            bool attached = (SensePoint.AttachmentPoint != 0);
            bool nameSearch = (ts.name != null && ts.name != "");
            Vector3 toRegionPos;
            double dis;

            for (int i = 0; i < presences.Count; i++)
            {
                ScenePresence presence = presences[i];
                bool keep = true;

                if (presence.IsDeleted)
                    continue;

                if (presence.IsChildAgent)
                    keep = false;
                toRegionPos = presence.AbsolutePosition;

                dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos));

                // are they in range
                if (keep && dis <= ts.range)
                {
                    // if the object the script is in is attached and the avatar is the owner
                    // then this one is not wanted
                    if (attached && presence.UUID == SensePoint.OwnerID)
                        keep = false;

                    // check the name if needed
                    if (keep && nameSearch && ts.name != presence.Name)
                        keep = false;

                    // Are they in the required angle of view
                    if (keep && ts.arc < Math.PI)
                    {
                        // not omni-directional. Can you see it ?
                        // vec forward_dir = llRot2Fwd(llGetRot())
                        // vec obj_dir = toRegionPos-fromRegionPos
                        // dot=dot(forward_dir,obj_dir)
                        // mag_fwd = mag(forward_dir)
                        // mag_obj = mag(obj_dir)
                        // ang = acos(dot /(mag_fwd*mag_obj))
                        double ang_obj = 0;
                        try
                        {
                            Vector3 diff = toRegionPos - fromRegionPos;
                            LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(diff.X, diff.Y, diff.Z);
                            double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir);
                            double mag_obj = LSL_Types.Vector3.Mag(obj_dir);
                            ang_obj = Math.Acos(dot / (mag_fwd * mag_obj));
                        }
                        catch
                        {
                        }
                        if (ang_obj > ts.arc) keep = false;
                    }
                }
                else
                {
                    keep = false;
                }

                // Do not report gods, not even minor ones
                if (keep && presence.GodLevel > 0.0)
                    keep = false;

                if (keep) // add to list with distance
                {
                    sensedEntities.Add(new SensedEntity(dis, presence.UUID));
                }

                // If this is a search by name and we have just found it then no more to do 
                if (nameSearch && ts.name == presence.Name)
                    return sensedEntities;
            }
            return sensedEntities;
        }
Пример #9
0
        private List<SensedEntity> doAgentSensor(SenseRepeatClass ts)
        {
            List<SensedEntity> sensedEntities = new List<SensedEntity>();

            // If nobody about quit fast
            if (m_CmdManager.m_ScriptEngine.World.GetRootAgentCount() == 0)
                return sensedEntities;

            SceneObjectPart SensePoint = ts.host;
            Vector3 fromRegionPos = SensePoint.AbsolutePosition;
            
            Quaternion q = SensePoint.RotationOffset;
            if (SensePoint.ParentGroup.IsAttachment)
            {
                // In attachments, the sensor cone always orients with the
                // avatar rotation. This may include a nonzero elevation if
                // in mouselook.
                ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
                q = avatar.Rotation;
            }

            LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
            LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
            double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
            bool attached = (SensePoint.ParentGroup.AttachmentPoint != 0);
            Vector3 toRegionPos;
            double dis;

            Action<ScenePresence> senseEntity = new Action<ScenePresence>(delegate(ScenePresence presence)
            {
                if (presence.IsDeleted || presence.IsChildAgent || presence.GodLevel > 0.0)
                    return;
                
                // if the object the script is in is attached and the avatar is the owner
                // then this one is not wanted
                if (attached && presence.UUID == SensePoint.OwnerID)
                    return;

                toRegionPos = presence.AbsolutePosition;
                dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos));

                // are they in range
                if (dis <= ts.range)
                {
                    // Are they in the required angle of view
                    if (ts.arc < Math.PI)
                    {
                        // not omni-directional. Can you see it ?
                        // vec forward_dir = llRot2Fwd(llGetRot())
                        // vec obj_dir = toRegionPos-fromRegionPos
                        // dot=dot(forward_dir,obj_dir)
                        // mag_fwd = mag(forward_dir)
                        // mag_obj = mag(obj_dir)
                        // ang = acos(dot /(mag_fwd*mag_obj))
                        double ang_obj = 0;
                        try
                        {
                            Vector3 diff = toRegionPos - fromRegionPos;
                            LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(diff.X, diff.Y, diff.Z);
                            double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir);
                            double mag_obj = LSL_Types.Vector3.Mag(obj_dir);
                            ang_obj = Math.Acos(dot / (mag_fwd * mag_obj));
                        }
                        catch
                        {
                        }
                        if (ang_obj <= ts.arc)
                        {
                            sensedEntities.Add(new SensedEntity(dis, presence.UUID));
                        }
                    }
                    else
                    {
                        sensedEntities.Add(new SensedEntity(dis, presence.UUID));
                    }
                }
            });

            // If this is an avatar sense by key try to get them directly
            // rather than getting a list to scan through
            if (ts.keyID != UUID.Zero)
            {
                ScenePresence sp;
                // Try direct lookup by UUID
                if (!m_CmdManager.m_ScriptEngine.World.TryGetScenePresence(ts.keyID, out sp))
                    return sensedEntities;
                senseEntity(sp);
            }
            else if (ts.name != null && ts.name != "")
            {
                ScenePresence sp;
                // Try lookup by name will return if/when found
                if (((ts.type & AGENT) != 0) && m_CmdManager.m_ScriptEngine.World.TryGetAvatarByName(ts.name, out sp))
                    senseEntity(sp);
                if ((ts.type & AGENT_BY_USERNAME) != 0)
                {
                    m_CmdManager.m_ScriptEngine.World.ForEachRootScenePresence(
                        delegate (ScenePresence ssp)
                        {
                            if (ssp.Lastname == "Resident")
                            {
                                if (ssp.Firstname.ToLower() == ts.name)
                                    senseEntity(ssp);
                                return;
                            }
                            if (ssp.Name.Replace(" ", ".").ToLower() == ts.name)
                                senseEntity(ssp);
                        }
                    );
                }

                return sensedEntities;
            }
            else
            {
                m_CmdManager.m_ScriptEngine.World.ForEachRootScenePresence(senseEntity);
            }
            return sensedEntities;
        }
Пример #10
0
        public void TestGetQuaternionItemForQuaternionItem()
        {
            LSL_Types.Quaternion testValue = new LSL_Types.Quaternion(12.64, 59.43723, 765.3421, 4.00987);
            LSL_Types.list testList = new LSL_Types.list(testValue);

            Assert.AreEqual(testValue, testList.GetQuaternionItem(0));
        }
Пример #11
0
        public LSL_Types.Quaternion SPGetRot(string vPresenceId)
        {
            LSL_Types.Quaternion rot = new LSL_Types.Quaternion(0, 0, 0, 1);

            UUID TempId = new UUID(vPresenceId);
            ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId);
            if (temppre != null)
            {
                rot.x = temppre.Rotation.X;
                rot.y = temppre.Rotation.Y;
                rot.z = temppre.Rotation.Z;
                rot.s = temppre.Rotation.W;
            }
            return rot;
        }
Пример #12
0
        public static void Deserialize(string xml, ScriptInstance instance)
        {
            XmlDocument doc = new XmlDocument();

            Dictionary<string, object> vars = instance.GetVars();

            instance.PluginData = new Object[0];

            doc.LoadXml(xml);

            XmlNodeList rootL = doc.GetElementsByTagName("ScriptState");
            if (rootL.Count != 1)
            {
                return;
            }
            XmlNode rootNode = rootL[0];

            if (rootNode != null)
            {
                object varValue;
                XmlNodeList partL = rootNode.ChildNodes;
                instance.Run = true;

                foreach (XmlNode part in partL)
                {
                    switch (part.Name)
                    {
                    case "State":
                        instance.State=part.InnerText;
                        break;
                    case "Running":
                        instance.Running=bool.Parse(part.InnerText);
                        break;
                    case "Run":
                        instance.Run = bool.Parse(part.InnerText);
                        break;
                    case "Variables":
                        XmlNodeList varL = part.ChildNodes;
                        foreach (XmlNode var in varL)
                        {
                            string varName;
                            varValue=ReadTypedValue(var, out varName);

                            if (vars.ContainsKey(varName))
                                vars[varName] = varValue;
                        }
                        instance.SetVars(vars);
                        break;
                    case "Queue":
                        XmlNodeList itemL = part.ChildNodes;
                        foreach (XmlNode item in itemL)
                        {
                            List<Object> parms = new List<Object>();
                            List<DetectParams> detected =
                                    new List<DetectParams>();

                            string eventName =
                                    item.Attributes.GetNamedItem("event").Value;
                            XmlNodeList eventL = item.ChildNodes;
                            foreach (XmlNode evt in eventL)
                            {
                                switch (evt.Name)
                                {
                                case "Params":
                                    XmlNodeList prms = evt.ChildNodes;
                                    foreach (XmlNode pm in prms)
                                        parms.Add(ReadTypedValue(pm));

                                    break;
                                case "Detected":
                                    XmlNodeList detL = evt.ChildNodes;
                                    foreach (XmlNode det in detL)
                                    {
                                        string vect =
                                                det.Attributes.GetNamedItem(
                                                "pos").Value;
                                        LSL_Types.Vector3 v =
                                                new LSL_Types.Vector3(vect);

                                        int d_linkNum=0;
                                        UUID d_group = UUID.Zero;
                                        string d_name = String.Empty;
                                        UUID d_owner = UUID.Zero;
                                        LSL_Types.Vector3 d_position =
                                            new LSL_Types.Vector3();
                                        LSL_Types.Quaternion d_rotation =
                                            new LSL_Types.Quaternion();
                                        int d_type = 0;
                                        LSL_Types.Vector3 d_velocity =
                                            new LSL_Types.Vector3();

                                        try
                                        {
                                            string tmp;

                                            tmp = det.Attributes.GetNamedItem(
                                                    "linkNum").Value;
                                            int.TryParse(tmp, out d_linkNum);

                                            tmp = det.Attributes.GetNamedItem(
                                                    "group").Value;
                                            UUID.TryParse(tmp, out d_group);

                                            d_name = det.Attributes.GetNamedItem(
                                                    "name").Value;

                                            tmp = det.Attributes.GetNamedItem(
                                                    "owner").Value;
                                            UUID.TryParse(tmp, out d_owner);

                                            tmp = det.Attributes.GetNamedItem(
                                                    "position").Value;
                                            d_position =
                                                new LSL_Types.Vector3(tmp);

                                            tmp = det.Attributes.GetNamedItem(
                                                    "rotation").Value;
                                            d_rotation =
                                                new LSL_Types.Quaternion(tmp);

                                            tmp = det.Attributes.GetNamedItem(
                                                    "type").Value;
                                            int.TryParse(tmp, out d_type);

                                            tmp = det.Attributes.GetNamedItem(
                                                    "velocity").Value;
                                            d_velocity =
                                                new LSL_Types.Vector3(tmp);

                                        }
                                        catch (Exception) // Old version XML
                                        {
                                        }

                                        UUID uuid = new UUID();
                                        UUID.TryParse(det.InnerText,
                                                out uuid);

                                        DetectParams d = new DetectParams();
                                        d.Key = uuid;
                                        d.OffsetPos = v;
                                        d.LinkNum = d_linkNum;
                                        d.Group = d_group;
                                        d.Name = d_name;
                                        d.Owner = d_owner;
                                        d.Position = d_position;
                                        d.Rotation = d_rotation;
                                        d.Type = d_type;
                                        d.Velocity = d_velocity;

                                        detected.Add(d);
                                    }
                                    break;
                                }
                            }
                            EventParams ep = new EventParams(
                                    eventName, parms.ToArray(),
                                    detected.ToArray());
                            instance.EventQueue.Enqueue(ep);
                        }
                        break;
                    case "Plugins":
                        instance.PluginData = ReadList(part).Data;
                        break;
                    case "Permissions":
                        string tmpPerm;
                        int mask = 0;
                        tmpPerm = part.Attributes.GetNamedItem("mask").Value;
                        if (tmpPerm != null)
                        {
                            int.TryParse(tmpPerm, out mask);
                            if (mask != 0)
                            {
                                tmpPerm = part.Attributes.GetNamedItem("granter").Value;
                                if (tmpPerm != null)
                                {
                                    UUID granter = new UUID();
                                    UUID.TryParse(tmpPerm, out granter);
                                    if (granter != UUID.Zero)
                                    {
                                        instance.ScriptTask.PermsMask = mask;
                                        instance.ScriptTask.PermsGranter = granter;
                                    }
                                }
                            }
                        }
                        break;
                    case "MinEventDelay":
                        double minEventDelay = 0.0;
                        double.TryParse(part.InnerText, NumberStyles.Float, Culture.NumberFormatInfo, out minEventDelay);
                        instance.MinEventDelay = minEventDelay;
                        break;
                }
              }
            }
        }
Пример #13
0
        public void Populate(Scene scene)
        {
            SceneObjectPart part = scene.GetSceneObjectPart(Key);
            if (part == null) // Avatar, maybe?
            {
                ScenePresence presence = scene.GetScenePresence(Key);
                if (presence == null)
                    return;

                Name = presence.Firstname + " " + presence.Lastname;
                Owner = Key;
                Position = new LSL_Types.Vector3(
                        presence.AbsolutePosition.X,
                        presence.AbsolutePosition.Y,
                        presence.AbsolutePosition.Z);
                Rotation = new LSL_Types.Quaternion(
                        presence.Rotation.X,
                        presence.Rotation.Y,
                        presence.Rotation.Z,
                        presence.Rotation.W);
                Velocity = new LSL_Types.Vector3(
                        presence.Velocity.X,
                        presence.Velocity.Y,
                        presence.Velocity.Z);

                Type = 0x01; // Avatar
                if (presence.Velocity != Vector3.Zero)
                    Type |= 0x02; // Active

                Group = presence.ControllingClient.ActiveGroupId;

                return;
            }

            part=part.ParentGroup.RootPart; // We detect objects only

            LinkNum = 0; // Not relevant

            Group = part.GroupID;
            Name = part.Name;
            Owner = part.OwnerID;
            if (part.Velocity == Vector3.Zero)
                Type = 0x04; // Passive
            else
                Type = 0x02; // Passive

            foreach (SceneObjectPart p in part.ParentGroup.Parts)
            {
                if (p.Inventory.ContainsScripts())
                {
                    Type |= 0x08; // Scripted
                    break;
                }
            }

            Position = new LSL_Types.Vector3(part.AbsolutePosition.X,
                                             part.AbsolutePosition.Y,
                                             part.AbsolutePosition.Z);

            Quaternion wr = part.ParentGroup.GroupRotation;
            Rotation = new LSL_Types.Quaternion(wr.X, wr.Y, wr.Z, wr.W);

            Velocity = new LSL_Types.Vector3(part.Velocity.X,
                                             part.Velocity.Y,
                                             part.Velocity.Z);
        }