示例#1
0
 public void default_event_touch_start(LSL_Types.LSLInteger num_detected)
 {
     LSL_Types.LSLInteger i = 0;
     LSL_Types.LSLInteger j = 14;
     LSL_Types.LSLFloat f = 0.0;
     LSL_Types.LSLFloat g = 14.0;
     LSL_Types.LSLString s = "";
     LSL_Types.LSLString t = "Hi there";
     LSL_Types.list l = new LSL_Types.list();
     LSL_Types.list m = new LSL_Types.list(1, 2, 3);
     LSL_Types.Vector3 v = new LSL_Types.Vector3(0.0, 0.0, 0.0);
     LSL_Types.Vector3 w = new LSL_Types.Vector3(1.0, 0.1, 0.5);
     LSL_Types.Quaternion r = new LSL_Types.Quaternion(0.0, 0.0, 0.0, 0.0);
     LSL_Types.Quaternion u = new LSL_Types.Quaternion(0.8, 0.7, 0.6, llSomeFunc());
     LSL_Types.LSLString k = "";
     LSL_Types.LSLString n = "ping";
 }
        List<SensedEntity> doAgentSensor(SenseRepeatClass ts)
        {
            List<SensedEntity> sensedEntities = new List<SensedEntity>();

            // If nobody about quit fast
            IEntityCountModule entityCountModule =
                ts.host.ParentEntity.Scene.RequestModuleInterface<IEntityCountModule>();
            if (entityCountModule != null && entityCountModule.RootAgents == 0)
                return sensedEntities;

            ISceneChildEntity SensePoint = ts.host;
            Vector3 fromRegionPos = SensePoint.AbsolutePosition;
            Quaternion q = SensePoint.GetRotationOffset();
            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);
            Vector3 toRegionPos;
            double dis;

            Action<IScenePresence> senseEntity = delegate(IScenePresence 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)
            {
                IScenePresence sp;
                // Try direct lookup by UUID
                if (!ts.host.ParentEntity.Scene.TryGetScenePresence(ts.keyID, out sp))
                    return sensedEntities;
                senseEntity(sp);
            }
            else if (!string.IsNullOrEmpty(ts.name))
            {
                IScenePresence sp;
                // Try lookup by name will return if/when found
                if (!ts.host.ParentEntity.Scene.TryGetAvatarByName(ts.name, out sp))
                    return sensedEntities;
                if (((ts.type & AGENT) != 0) && ts.host.ParentEntity.Scene.TryGetAvatarByName(ts.name, out sp))
                    senseEntity(sp);
                if ((ts.type & AGENT_BY_USERNAME) != 0)
                {
                    ts.host.ParentEntity.Scene.ForEachScenePresence(
                        delegate(IScenePresence ssp)
                            {
                                if (ssp.Name.Replace(" ", ".").ToLower() == ts.name)
                                    senseEntity(ssp);
                            }
                        );
                }
            }
            else
            {
                ts.host.ParentEntity.Scene.ForEachScenePresence(senseEntity);
            }
            return sensedEntities;
        }
        List<SensedEntity> doObjectSensor(SenseRepeatClass ts)
        {
            List<ISceneEntity> Entities;
            List<SensedEntity> sensedEntities = new List<SensedEntity>();

            ISceneChildEntity SensePoint = ts.host;

            Vector3 fromRegionPos = SensePoint.AbsolutePosition;

            // 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)
            {
                IEntity e = null;
                ts.host.ParentEntity.Scene.Entities.TryGetValue(ts.keyID, out e);
                if (e == null || !(e is ISceneEntity))
                    return sensedEntities;
                Entities = new List<ISceneEntity> {e as ISceneEntity};
            }
            else
            {
                Entities =
                    new List<ISceneEntity>(ts.host.ParentEntity.Scene.Entities.GetEntities(fromRegionPos,
                                                                                           (float) ts.range));
            }

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

            Quaternion q = SensePoint.GetRotationOffset();
            if (SensePoint.ParentEntity.RootChild.IsAttachment)
            {
                // In attachments, the sensor cone always orients with the
                // avatar rotation. This may include a nonzero elevation if
                // in mouselook.

                IScenePresence avatar =
                    ts.host.ParentEntity.Scene.GetScenePresence(SensePoint.ParentEntity.RootChild.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);

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

            bool nameSearch = !string.IsNullOrEmpty(ts.name);

            foreach (ISceneEntity 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 ISceneEntity)) // 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 = (ent).RootChild;
                    if (part.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;
                                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;
                        }

                        if (keep)
                        {
                            // add distance for sorting purposes later
                            sensedEntities.Add(new SensedEntity(dis, ent.UUID));
                        }
                    }
                }
            }
            return sensedEntities;
        }
示例#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.WorldPosition;
            
            Quaternion q = SensePoint.WorldRotation;
            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);

                // Don't proceed if the avatar for this attachment has since been removed from the scene.
                if (avatar == null)
                    return sensedEntities;

                q = avatar.WorldRotation * 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 (!string.IsNullOrEmpty(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;
        }
        public static void Deserialize(string xml, ScriptInstance instance)
        {
            XmlDocument doc = new XmlDocument();

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

            instance.PluginData = new Object[0];

            // Avoid removal of whitepace from LSL string vars
            doc.PreserveWhitespace = true;
            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;

                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 "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.EnqueueEvent(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;
                }
              }
            }
        }
示例#6
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.WorldPosition;

            // 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.WorldRotation;
            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);

                // Don't proceed if the avatar for this attachment has since been removed from the scene.
                if (avatar == null)
                    return sensedEntities;

                q = avatar.WorldRotation * 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 = !string.IsNullOrEmpty(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;
        }
示例#7
0
 private void Load()
 {
     Rotation = prim.OSSL.llGetRot();
 }
示例#8
0
        public void Populate(IScene scene)
        {
            ISceneChildEntity part = scene.GetSceneObjectPart(Key);
            Vector3           tmp;

            if (part == null) // Avatar, maybe?
            {
                IScenePresence presence = scene.GetScenePresence(Key);
                if (presence == null)
                {
                    return;
                }

                Name  = presence.Name;
                Owner = Key;

                tmp      = presence.AbsolutePosition;
                Position = new LSL_Types.Vector3(
                    tmp.X,
                    tmp.Y,
                    tmp.Z);
                Quaternion rtmp = presence.Rotation;
                Rotation = new LSL_Types.Quaternion(
                    rtmp.X,
                    rtmp.Y,
                    rtmp.Z,
                    rtmp.W);
                tmp      = presence.Velocity;
                Velocity = new LSL_Types.Vector3(
                    tmp.X,
                    tmp.Y,
                    tmp.Z);

                Type = 0x01; // Avatar
                if (presence.Velocity != Vector3.Zero)
                {
                    Type |= 0x02; // Active
                }
                Group = presence.ControllingClient.ActiveGroupId;

                return;
            }

            part = part.ParentEntity.RootChild; // 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 (ISceneChildEntity p in part.ParentEntity.ChildrenEntities())
            {
                if (p.Inventory.ContainsScripts())
                {
                    Type |= 0x08; // Scripted
                    break;
                }
            }
            tmp      = part.AbsolutePosition;
            Position = new LSL_Types.Vector3(tmp.X,
                                             tmp.Y,
                                             tmp.Z);

            Quaternion wr = part.ParentEntity.GroupRotation;

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

            tmp      = part.Velocity;
            Velocity = new LSL_Types.Vector3(tmp.X,
                                             tmp.Y,
                                             tmp.Z);
        }
        private List <SensedEntity> doObjectSensor(SenseRepeatClass 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.AbsolutePosition;

            // 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.RotationOffset;

            if (SensePoint.ParentGroup.RootPart.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.RootPart.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);

            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.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;
                                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;
                            }
                        }

                        if (keep == true)
                        {
                            // add distance for sorting purposes later
                            sensedEntities.Add(new SensedEntity(dis, ent.UUID));
                        }
                    }
                }
            }
            return(sensedEntities);
        }
示例#10
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;

            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);
            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 (!m_CmdManager.m_ScriptEngine.World.TryGetAvatarByName(ts.name, out sp))
                {
                    return(sensedEntities);
                }
                senseEntity(sp);
            }
            else
            {
                m_CmdManager.m_ScriptEngine.World.ForEachScenePresence(senseEntity);
            }
            return(sensedEntities);
        }
示例#11
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);

                // Don't proceed if the avatar for this attachment has since been removed from the scene.
                if (avatar == null)
                {
                    return(sensedEntities);
                }
                fromRegionPos = avatar.AbsolutePosition;
                q             = avatar.Rotation;
            }

            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 && 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         = Util.GetDistanceTo(toRegionPos, fromRegionPos);
                if (presence.IsSatOnObject && presence.ParentPart != null &&
                    presence.ParentPart.ParentGroup != null &&
                    presence.ParentPart.ParentGroup.RootPart != null)
                {
                    Vector3 rpos = presence.ParentPart.ParentGroup.RootPart.AbsolutePosition;
                    double dis2  = Util.GetDistanceTo(rpos, fromRegionPos);
                    if (dis > dis2)
                    {
                        dis = dis2;
                    }
                }

                // 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 (!string.IsNullOrEmpty(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);
        }
示例#12
0
        public void SetStoreVars(Dictionary <string, object> vars)
        {
            if (!m_useStateSaves)
            {
                return;
            }
            m_lastStateSaveValues = vars;
            m_stateSaveRequired   = false;
            //If something is setting the vars, we don't need to do a state save, as this came from a state save
            Type t = GetType();

            FieldInfo[] fields = t.GetFields(BindingFlags.NonPublic |
                                             BindingFlags.Public |
                                             BindingFlags.Instance |
                                             BindingFlags.DeclaredOnly);

            foreach (FieldInfo field in fields)
            {
                if (vars.ContainsKey(field.Name))
                {
                    object var = vars[field.Name];
                    if (field.FieldType == typeof(LSL_Types.list))
                    {
                        string         val = var.ToString();
                        int            end;
                        LSL_Types.list v = ParseValueToList(val, 0, out end);
                        field.SetValue(this, v);
                    }
                    else if (field.FieldType == typeof(LSL_Types.LSLInteger))
                    {
                        int val = int.Parse(var.ToString());
                        field.SetValue(this, new LSL_Types.LSLInteger(val));
                    }
                    else if (field.FieldType == typeof(LSL_Types.LSLString))
                    {
                        string val = var.ToString();
                        field.SetValue(this, new LSL_Types.LSLString(val));
                    }
                    else if (field.FieldType == typeof(LSL_Types.LSLFloat))
                    {
                        float val = float.Parse(var.ToString());
                        field.SetValue(this, new LSL_Types.LSLFloat(val));
                    }
                    else if (field.FieldType == typeof(Int32))
                    {
                        Int32 val = Int32.Parse(var.ToString());
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof(Double))
                    {
                        Double val = Double.Parse(var.ToString());
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof(Single))
                    {
                        Single val = Single.Parse(var.ToString());
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof(String))
                    {
                        String val = var.ToString();
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof(Byte))
                    {
                        Byte val = Byte.Parse(var.ToString());
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof(short))
                    {
                        short val = short.Parse(var.ToString());
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof(LSL_Types.Quaternion))
                    {
                        LSL_Types.Quaternion val = new LSL_Types.Quaternion(var.ToString());
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof(LSL_Types.Vector3))
                    {
                        LSL_Types.Vector3 val = new LSL_Types.Vector3(var.ToString());
                        field.SetValue(this, val);
                    }
                }
            }
            fields = null;
            t      = null;
        }
示例#13
0
        public static void Deserialize(string xml, ScriptInstance instance)
        {
            XmlDocument doc = new XmlDocument();

            doc.XmlResolver = null;

            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;

                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 "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;
                    }
                }
            }
        }
示例#14
0
 private void Load()
 {
     Rotation = prim.OSSL.llGetRot();
 }
示例#15
0
 public void default_event_touch_start(LSL_Types.LSLInteger num_detected)
 {
     LSL_Types.Vector3 y = new LSL_Types.Vector3(1.2, llGetMeAFloat(), 4.4);
     LSL_Types.Quaternion x = new LSL_Types.Quaternion(0.1, 0.1, one + 2, 0.9);
     y = new LSL_Types.Vector3(0.1, 0.1, 1.1 - three - two + eight * 8);
 }
示例#16
0
        public void SetStoreVars(Dictionary<string, object> vars)
        {
            if (!m_useStateSaves)
                return;
            m_lastStateSaveValues = vars;
            m_stateSaveRequired = false;
            //If something is setting the vars, we don't need to do a state save, as this came from a state save
            Type t = GetType();

            FieldInfo[] fields = t.GetFields(BindingFlags.NonPublic |
                                             BindingFlags.Public |
                                             BindingFlags.Instance |
                                             BindingFlags.DeclaredOnly);

            foreach (FieldInfo field in fields)
            {
                if (vars.ContainsKey(field.Name))
                {
                    object var = vars[field.Name];
                    if (field.FieldType == typeof (LSL_Types.list))
                    {
                        string val = var.ToString();
                        int end;
                        LSL_Types.list v = ParseValueToList(val, 0, out end);
                        field.SetValue(this, v);
                    }
                    else if (field.FieldType == typeof (LSL_Types.LSLInteger))
                    {
                        int val = int.Parse(var.ToString());
                        field.SetValue(this, new LSL_Types.LSLInteger(val));
                    }
                    else if (field.FieldType == typeof (LSL_Types.LSLString))
                    {
                        string val = var.ToString();
                        field.SetValue(this, new LSL_Types.LSLString(val));
                    }
                    else if (field.FieldType == typeof (LSL_Types.LSLFloat))
                    {
                        float val = float.Parse(var.ToString());
                        field.SetValue(this, new LSL_Types.LSLFloat(val));
                    }
                    else if (field.FieldType == typeof (Int32))
                    {
                        Int32 val = Int32.Parse(var.ToString());
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof (Double))
                    {
                        Double val = Double.Parse(var.ToString());
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof (Single))
                    {
                        Single val = Single.Parse(var.ToString());
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof (String))
                    {
                        String val = var.ToString();
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof (Byte))
                    {
                        Byte val = Byte.Parse(var.ToString());
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof (short))
                    {
                        short val = short.Parse(var.ToString());
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof (LSL_Types.Quaternion))
                    {
                        LSL_Types.Quaternion val = new LSL_Types.Quaternion(var.ToString());
                        field.SetValue(this, val);
                    }
                    else if (field.FieldType == typeof (LSL_Types.Vector3))
                    {
                        LSL_Types.Vector3 val = new LSL_Types.Vector3(var.ToString());
                        field.SetValue(this, val);
                    }
                }
            }
            fields = null;
            t = null;
        }
示例#17
0
        List <SensedEntity> doAgentSensor(SenseRepeatClass ts)
        {
            List <SensedEntity> sensedEntities = new List <SensedEntity>();

            // If nobody about quit fast
            IEntityCountModule entityCountModule =
                ts.host.ParentEntity.Scene.RequestModuleInterface <IEntityCountModule>();

            if (entityCountModule != null && entityCountModule.RootAgents == 0)
            {
                return(sensedEntities);
            }

            ISceneChildEntity SensePoint    = ts.host;
            Vector3           fromRegionPos = SensePoint.AbsolutePosition;
            Quaternion        q             = SensePoint.GetRotationOffset();

            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);
            Vector3 toRegionPos;
            double  dis;

            Action <IScenePresence> senseEntity = delegate(IScenePresence 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)
            {
                IScenePresence sp;
                // Try direct lookup by UUID
                if (!ts.host.ParentEntity.Scene.TryGetScenePresence(ts.keyID, out sp))
                {
                    return(sensedEntities);
                }
                senseEntity(sp);
            }
            else if (!string.IsNullOrEmpty(ts.name))
            {
                IScenePresence sp;
                // Try lookup by name will return if/when found
                if (!ts.host.ParentEntity.Scene.TryGetAvatarByName(ts.name, out sp))
                {
                    return(sensedEntities);
                }
                if (((ts.type & AGENT) != 0) && ts.host.ParentEntity.Scene.TryGetAvatarByName(ts.name, out sp))
                {
                    senseEntity(sp);
                }
                if ((ts.type & AGENT_BY_USERNAME) != 0)
                {
                    ts.host.ParentEntity.Scene.ForEachScenePresence(
                        delegate(IScenePresence ssp)
                    {
                        if (ssp.Name.Replace(" ", ".").ToLower() == ts.name)
                        {
                            senseEntity(ssp);
                        }
                    }
                        );
                }
            }
            else
            {
                ts.host.ParentEntity.Scene.ForEachScenePresence(senseEntity);
            }
            return(sensedEntities);
        }