public void TestGetVector3ItemForVector3Item()
        {
            LSL_Types.Vector3 testValue = new LSL_Types.Vector3(92.34, 58.98754, -0.10987);
            LSL_Types.list    testList  = new LSL_Types.list(testValue);

            Assert.AreEqual(testValue, testList.GetVector3Item(0));
        }
示例#2
0
 public static LSL_Types.Vector3 Negate(LSL_Types.Vector3 vec)
 {
     vec.x = (-vec.x);
     vec.y = (-vec.y);
     vec.z = (-vec.z);
     return(vec);
 }
示例#3
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]).X, ((Vector3)p[i]).Y, ((Vector3)p[i]).Z);
                }
                else if (p[i] is Quaternion)
                {
                    lsl_p[i] = new LSL_Types.Quaternion(((Quaternion)p[i]).X, ((Quaternion)p[i]).Y, ((Quaternion)p[i]).Z, ((Quaternion)p[i]).W);
                }
                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])));
        }
        // Set prim params for a sphere and check results.
        public void CheckllSetPrimitiveParams(string primTest,
                                              LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
                                              float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primDimple, float primHollowCheck)
        {
            // Set the prim params.
            m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
                                                             ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
                                                             primCut, primHollow, primTwist, primDimple));

            // Get params for prim to validate settings.
            LSL_Types.list primParams =
                m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));

            // Validate settings.
            CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
            Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
                            "TestllSetPrimitiveParams " + primTest + " prim type check fail");
            Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
                            "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
            CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
            Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
                            "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
            CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
            CheckllSetPrimitiveParamsVector(primDimple, m_lslApi.llList2Vector(primParams, 6), primTest + " prim dimple");
        }
        public void TestCastVector3ItemToVector3()
        {
            LSL_Types.Vector3 testValue = new LSL_Types.Vector3(12.34, 56.987654, 0.00987);
            LSL_Types.list    testList  = new LSL_Types.list(testValue);

            Assert.AreEqual(testValue, (LSL_Types.Vector3)testList.Data[0]);
        }
示例#6
0
 public void aaSetCenterOfGravity(LSL_Types.Vector3 position)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.High, "AASetCenterOfGravity", m_host, "AA");
     if (m_host.ParentEntity.Scene.Permissions.CanIssueEstateCommand(m_host.OwnerID, true))
     {
         m_host.ParentEntity.Scene.PhysicsScene.PointOfGravity = new Vector3((float)position.x, (float)position.y, (float)position.z);
     }
 }
示例#7
0
 private void initializeSurfaceTouch()
 {
     touchST       = new LSL_Types.Vector3(-1.0, -1.0, 0.0);
     touchNormal   = new LSL_Types.Vector3();
     touchBinormal = new LSL_Types.Vector3();
     touchPos      = new LSL_Types.Vector3();
     touchUV       = new LSL_Types.Vector3(-1.0, -1.0, 0.0);
     touchFace     = -1;
 }
示例#8
0
 public void default_event_state_entry()
 {
     LSL_Types.Vector3 v = llGetPos();
     v.z += 4;
     v.z -= 4;
     v.z *= 4;
     v.z /= 4;
     v.z %= 4;
 }
 public void CheckllVecNorm(LSL_Types.Vector3 vec, LSL_Types.Vector3 vecNormCheck)
 {
     // Call LSL function to normalize the vector.
     LSL_Types.Vector3 vecNorm = m_lslApi.llVecNorm(vec);
     // Check each vector component against expected result.
     Assert.AreEqual(vecNorm.x, vecNormCheck.x, VECTOR_COMPONENT_ACCURACY, "TestllVecNorm vector check fail on x component");
     Assert.AreEqual(vecNorm.y, vecNormCheck.y, VECTOR_COMPONENT_ACCURACY, "TestllVecNorm vector check fail on y component");
     Assert.AreEqual(vecNorm.z, vecNormCheck.z, VECTOR_COMPONENT_ACCURACY, "TestllVecNorm vector check fail on z component");
 }
 public void CheckllSetPrimitiveParamsVector(LSL_Types.Vector3 vecCheck, LSL_Types.Vector3 vecReturned, string msg)
 {
     // Check each vector component against expected result.
     Assert.AreEqual(vecCheck.x, vecReturned.x, VECTOR_COMPONENT_ACCURACY,
                     "TestllSetPrimitiveParams " + msg + " vector check fail on x component");
     Assert.AreEqual(vecCheck.y, vecReturned.y, VECTOR_COMPONENT_ACCURACY,
                     "TestllSetPrimitiveParams " + msg + " vector check fail on y component");
     Assert.AreEqual(vecCheck.z, vecReturned.z, VECTOR_COMPONENT_ACCURACY,
                     "TestllSetPrimitiveParams " + msg + " vector check fail on z component");
 }
        /// <summary>
        /// Check an llRot2Euler conversion.
        /// </summary>
        /// <remarks>
        /// Testing Rot2Euler this way instead of comparing against expected angles because
        /// 1. There are several ways to get to the original Quaternion. For example a rotation
        ///    of PI and -PI will give the same result. But PI and -PI aren't equal.
        /// 2. This method checks to see if the calculated angles from a quaternion can be used
        ///    to create a new quaternion to produce the same rotation.
        /// However, can't compare the newly calculated quaternion against the original because
        /// once again, there are multiple quaternions that give the same result. For instance
        ///  <X, Y, Z, S> == <-X, -Y, -Z, -S>.  Additionally, the magnitude of S can be changed
        /// and will still result in the same rotation if the values for X, Y, Z are also changed
        /// to compensate.
        /// However, if two quaternions represent the same rotation, then multiplying the first
        /// quaternion by the conjugate of the second, will give a third quaternion representing
        /// a zero rotation. This can be tested for by looking at the X, Y, Z values which should
        /// be zero.
        /// </remarks>
        /// <param name="rot"></param>
        private void CheckllRot2Euler(LSL_Types.Quaternion rot)
        {
            // Call LSL function to convert quaternion rotaion to euler radians.
            LSL_Types.Vector3 eulerCalc = m_lslApi.llRot2Euler(rot);
            // Now use the euler radians to recalculate a new quaternion rotation
            LSL_Types.Quaternion newRot = m_lslApi.llEuler2Rot(eulerCalc);
            // Multiple original quaternion by conjugate of quaternion calculated with angles.
            LSL_Types.Quaternion check = rot * new LSL_Types.Quaternion(-newRot.x, -newRot.y, -newRot.z, newRot.s);

            Assert.AreEqual(0.0, check.x, VECTOR_COMPONENT_ACCURACY, "TestllRot2Euler X bounds check fail");
            Assert.AreEqual(0.0, check.y, VECTOR_COMPONENT_ACCURACY, "TestllRot2Euler Y bounds check fail");
            Assert.AreEqual(0.0, check.z, VECTOR_COMPONENT_ACCURACY, "TestllRot2Euler Z bounds check fail");
        }
示例#12
0
 private void CheckllRot2Euler(LSL_Types.Quaternion rot, LSL_Types.Vector3 eulerCheck)
 {
     // Call LSL function to convert quaternion rotaion to euler radians.
     LSL_Types.Vector3 eulerCalc = m_lslApi.llRot2Euler(rot);
     // Check upper and lower bounds of x, y and z.
     // This type of check is performed as opposed to comparing for equal numbers, in order to allow slight
     // differences in accuracy.
     Assert.Greater(eulerCalc.x, eulerCheck.x - ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler X lower bounds check fail");
     Assert.Less(eulerCalc.x, eulerCheck.x + ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler X upper bounds check fail");
     Assert.Greater(eulerCalc.y, eulerCheck.y - ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Y lower bounds check fail");
     Assert.Less(eulerCalc.y, eulerCheck.y + ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Y upper bounds check fail");
     Assert.Greater(eulerCalc.z, eulerCheck.z - ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Z lower bounds check fail");
     Assert.Less(eulerCalc.z, eulerCheck.z + ANGLE_ACCURACY_IN_RADIANS, "TestllRot2Euler Z upper bounds check fail");
 }
示例#13
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();
 }
 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";
 }
示例#15
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";
 }
示例#16
0
 public void default_event_touch_start(LSL_Types.LSLInteger num_detected)
 {
     LSL_Types.LSLFloat y = 1.0;
     y = 1.0E3;
     y = 1.0e3;
     y = 1.0E+3;
     y = 1.0e+3;
     y = 1.0E-3;
     y = 1.0e-3;
     y = -1.0E3;
     y = -1.0e3;
     y = -1.0E+3;
     y = -1.0e+3;
     y = -1.0E-3;
     y = -1.0e-3;
     y = 12.0 + -1.0E3 - 1.0e-2;
     LSL_Types.Vector3 v = new LSL_Types.Vector3(0.0, 0.0, 0.0);
 }
        // Set prim params for a sculpted prim and check results.
        public void CheckllSetPrimitiveParams(string primTest,
                                              LSL_Types.Vector3 primSize, int primType, string primMap, int primSculptType)
        {
            // Set the prim params.
            m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
                                                             ScriptBaseClass.PRIM_TYPE, primType, primMap, primSculptType));

            // Get params for prim to validate settings.
            LSL_Types.list primParams =
                m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));

            // Validate settings.
            CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
            Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
                            "TestllSetPrimitiveParams " + primTest + " prim type check fail");
            Assert.AreEqual(primMap, (string)m_lslApi.llList2String(primParams, 2),
                            "TestllSetPrimitiveParams " + primTest + " prim map check fail");
            Assert.AreEqual(primSculptType, m_lslApi.llList2Integer(primParams, 3),
                            "TestllSetPrimitiveParams " + primTest + " prim type scuplt check fail");
        }
示例#18
0
        public void TestDotProduct()
        {
            // The numbers we test for.
            Dictionary <string, double> expectsSet = new Dictionary <string, double>();

            expectsSet.Add("<1, 2, 3> * <2, 3, 4>", 20.0);
            expectsSet.Add("<1, 2, 3> * <0, 0, 0>", 0.0);

            double result;

            string[] parts;
            string[] delim = { "*" };

            foreach (KeyValuePair <string, double> ex in expectsSet)
            {
                parts  = ex.Key.Split(delim, System.StringSplitOptions.None);
                result = new LSL_Types.Vector3(parts[0]) * new LSL_Types.Vector3(parts[1]);
                Assert.AreEqual(ex.Value, result);
            }
        }
示例#19
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]).X, ((Vector3)p[i]).Y, ((Vector3)p[i]).Z);
                }
                else if (p[i] is Quaternion)
                {
                    lsl_p[i] = new LSL_Types.Quaternion(((Quaternion)p[i]).X, ((Quaternion)p[i]).Y, ((Quaternion)p[i]).Z, ((Quaternion)p[i]).W);
                }
                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])));
        }
        // Set prim params for a torus, tube or ring and check results.
        public void CheckllSetPrimitiveParams(string primTest,
                                              LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
                                              float primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primHoleSize,
                                              LSL_Types.Vector3 primShear, LSL_Types.Vector3 primProfCut, LSL_Types.Vector3 primTaper,
                                              float primRev, float primRadius, float primSkew, float primHollowCheck)
        {
            // Set the prim params.
            m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
                                                             ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
                                                             primCut, primHollow, primTwist, primHoleSize, primShear, primProfCut,
                                                             primTaper, primRev, primRadius, primSkew));

            // Get params for prim to validate settings.
            LSL_Types.list primParams =
                m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));

            // Valdate settings.
            CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
            Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
                            "TestllSetPrimitiveParams " + primTest + " prim type check fail");
            Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
                            "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
            CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
            Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
                            "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
            CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
            CheckllSetPrimitiveParamsVector(primHoleSize, m_lslApi.llList2Vector(primParams, 6), primTest + " prim hole size");
            CheckllSetPrimitiveParamsVector(primShear, m_lslApi.llList2Vector(primParams, 7), primTest + " prim shear");
            CheckllSetPrimitiveParamsVector(primProfCut, m_lslApi.llList2Vector(primParams, 8), primTest + " prim profile cut");
            CheckllSetPrimitiveParamsVector(primTaper, m_lslApi.llList2Vector(primParams, 9), primTest + " prim taper");
            Assert.AreEqual(primRev, m_lslApi.llList2Float(primParams, 10), FLOAT_ACCURACY,
                            "TestllSetPrimitiveParams " + primTest + " prim revolutions fail");
            Assert.AreEqual(primRadius, m_lslApi.llList2Float(primParams, 11), FLOAT_ACCURACY,
                            "TestllSetPrimitiveParams " + primTest + " prim radius fail");
            Assert.AreEqual(primSkew, m_lslApi.llList2Float(primParams, 12), FLOAT_ACCURACY,
                            "TestllSetPrimitiveParams " + primTest + " prim skew fail");
        }
示例#21
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);
     x = y.x + 1.1;
     y.x = 1.1;
 }
        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;
                }
              }
            }
        }
示例#23
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);
 }
示例#24
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;
            Type  = part.Velocity == Vector3.Zero ? 0x04 : 0x02;

            foreach (ISceneChildEntity child in part.ParentEntity.ChildrenEntities())
            {
                if (child.Inventory.ContainsScripts())
                {
                    Type |= 0x08; // Scripted
                }
            }
            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);
        }
示例#25
0
 private void Load()
 {
     Position = prim.OSSL.llGetPos();
 }
示例#26
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(int))
                    {
                        int val = int.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(float))
                    {
                        float val = float.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;
        }
示例#27
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;
        }
示例#28
0
        private 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);
        }
示例#29
0
        private 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);
        }
示例#30
0
        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;
        }
示例#31
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;
        }
        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;
                    }
                }
            }
        }
示例#33
0
 private void Load()
 {
     Position = prim.OSSL.llGetPos();
 }
示例#34
0
        public void SetStoreVars(Dictionary <string, object> vars)
        {
            foreach (KeyValuePair <string, object> var in vars)
            {
                if (m_Fields.ContainsKey(var.Key))
                {
                    try
                    {
                        if (m_Fields[var.Key].FieldType == typeof(LSL_Types.list))
                        {
                            string         val = var.Value.ToString();
                            int            end;
                            LSL_Types.list v = ParseValueToList(val, 0, out end);
                            m_Fields[var.Key].SetValue(this, v);
                        }

                        else if (m_Fields[var.Key].FieldType == typeof(LSL_Types.LSLInteger))
                        {
                            int val = int.Parse(var.Value.ToString());
                            m_Fields[var.Key].SetValue(this, new LSL_Types.LSLInteger(val));
                        }
                        else if (m_Fields[var.Key].FieldType == typeof(LSL_Types.LSLString))
                        {
                            string val = var.Value.ToString();
                            m_Fields[var.Key].SetValue(this, new LSL_Types.LSLString(val));
                        }
                        else if (m_Fields[var.Key].FieldType == typeof(LSL_Types.LSLFloat))
                        {
                            float val = float.Parse(var.Value.ToString());
                            m_Fields[var.Key].SetValue(this, new LSL_Types.LSLFloat(val));
                        }
                        else if (m_Fields[var.Key].FieldType == typeof(Int32))
                        {
                            Int32 val = Int32.Parse(var.Value.ToString());
                            m_Fields[var.Key].SetValue(this, val);
                        }
                        else if (m_Fields[var.Key].FieldType == typeof(Double))
                        {
                            Double val = Double.Parse(var.Value.ToString());
                            m_Fields[var.Key].SetValue(this, val);
                        }
                        else if (m_Fields[var.Key].FieldType == typeof(Single))
                        {
                            Single val = Single.Parse(var.Value.ToString());
                            m_Fields[var.Key].SetValue(this, val);
                        }
                        else if (m_Fields[var.Key].FieldType == typeof(String))
                        {
                            String val = var.Value.ToString();
                            m_Fields[var.Key].SetValue(this, val);
                        }
                        else if (m_Fields[var.Key].FieldType == typeof(Byte))
                        {
                            Byte val = Byte.Parse(var.Value.ToString());
                            m_Fields[var.Key].SetValue(this, val);
                        }
                        else if (m_Fields[var.Key].FieldType == typeof(short))
                        {
                            short val = short.Parse(var.Value.ToString());
                            m_Fields[var.Key].SetValue(this, val);
                        }
                        else if (m_Fields[var.Key].FieldType == typeof(LSL_Types.Quaternion))
                        {
                            LSL_Types.Quaternion val = new LSL_Types.Quaternion(var.Value.ToString());
                            m_Fields[var.Key].SetValue(this, val);
                        }
                        else if (m_Fields[var.Key].FieldType == typeof(LSL_Types.Vector3))
                        {
                            LSL_Types.Vector3 val = new LSL_Types.Vector3(var.Value.ToString());
                            m_Fields[var.Key].SetValue(this, val);
                        }
                    }
                    catch (Exception) { }
                }
            }
        }
示例#35
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.Rotation * 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);
        }
示例#36
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;
        }
示例#37
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;
                UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, Key);
                if (account != null)
                {
                    Country = account.UserCountry;
                }

                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);

                Type = 0x01; // Avatar
                if (presence.PresenceType == PresenceType.Npc)
                {
                    Type = 0x20;
                }

                // Cope Impl. We don't use OS_NPC.
                //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);
        }
示例#38
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.Rotation * 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);
        }
示例#39
0
        private void processXstate(XmlDocument doc)
        {
            XmlNodeList rootL = doc.GetElementsByTagName("ScriptState");

            if (rootL.Count != 1)
            {
                throw new Exception("Xstate <ScriptState> missing");
            }

            XmlNode rootNode = rootL[0];

            if (rootNode == null)
            {
                throw new Exception("Xstate root missing");
            }

            string stateName = "";
            bool   running   = false;

            UUID   permsGranter  = UUID.Zero;
            int    permsMask     = 0;
            double minEventDelay = 0.0;

            Object[] pluginData    = new Object[0];
            UUID     experienceKey = UUID.Zero;

            LinkedList <EventParams> eventQueue = new LinkedList <EventParams>();

            Dictionary <string, int> intNames      = new Dictionary <string, int>();
            Dictionary <string, int> doubleNames   = new Dictionary <string, int>();
            Dictionary <string, int> stringNames   = new Dictionary <string, int>();
            Dictionary <string, int> vectorNames   = new Dictionary <string, int>();
            Dictionary <string, int> rotationNames = new Dictionary <string, int>();
            Dictionary <string, int> listNames     = new Dictionary <string, int>();

            int nn = m_ObjCode.globalVarNames.Count;

            int[]          ints      = null;
            double[]       doubles   = null;
            string[]       strings   = null;
            LSL_Vector[]   vectors   = null;
            LSL_Rotation[] rotations = null;
            LSL_List[]     lists     = null;

            if (nn > 0)
            {
                if (m_ObjCode.globalVarNames.ContainsKey("iarIntegers"))
                {
                    getvarNames(m_ObjCode.globalVarNames["iarIntegers"], intNames);
                    ints = new int[m_ObjCode.globalVarNames["iarIntegers"].Count];
                }
                if (m_ObjCode.globalVarNames.ContainsKey("iarFloats"))
                {
                    getvarNames(m_ObjCode.globalVarNames["iarFloats"], doubleNames);
                    doubles = new double[m_ObjCode.globalVarNames["iarFloats"].Count];
                }
                if (m_ObjCode.globalVarNames.ContainsKey("iarVectors"))
                {
                    getvarNames(m_ObjCode.globalVarNames["iarVectors"], vectorNames);
                    vectors = new LSL_Vector[m_ObjCode.globalVarNames["iarVectors"].Count];
                }
                if (m_ObjCode.globalVarNames.ContainsKey("iarRotations"))
                {
                    getvarNames(m_ObjCode.globalVarNames["iarRotations"], rotationNames);
                    rotations = new LSL_Rotation[m_ObjCode.globalVarNames["iarRotations"].Count];
                }
                if (m_ObjCode.globalVarNames.ContainsKey("iarStrings"))
                {
                    getvarNames(m_ObjCode.globalVarNames["iarStrings"], stringNames);
                    strings = new string[m_ObjCode.globalVarNames["iarStrings"].Count];
                }
                if (m_ObjCode.globalVarNames.ContainsKey("iarLists"))
                {
                    getvarNames(m_ObjCode.globalVarNames["iarLists"], listNames);
                    lists = new LSL_List[m_ObjCode.globalVarNames["iarLists"].Count];
                }
            }

            int heapsz = 0;

            try
            {
                XmlNodeList partL = rootNode.ChildNodes;
                foreach (XmlNode part in partL)
                {
                    switch (part.Name)
                    {
                    case "State":
                        stateName = part.InnerText;
                        break;

                    case "Running":
                        running = bool.Parse(part.InnerText);
                        break;

                    case "ExperienceKey":
                        experienceKey = UUID.Parse(part.InnerText);
                        break;

                    case "Variables":
                        int         indx;
                        XmlNodeList varL = part.ChildNodes;
                        foreach (XmlNode var in varL)
                        {
                            string varName;
                            object o     = ReadXTypedValue(var, out varName);
                            Type   otype = o.GetType();
                            if (otype == typeof(LSL_Integer))
                            {
                                if (intNames.TryGetValue(varName, out indx))
                                {
                                    ints[indx] = ((LSL_Integer)o);
                                }
                                continue;
                            }
                            if (otype == typeof(LSL_Float))
                            {
                                if (doubleNames.TryGetValue(varName, out indx))
                                {
                                    doubles[indx] = ((LSL_Float)o);
                                }
                                continue;
                            }
                            if (otype == typeof(LSL_String))
                            {
                                if (stringNames.TryGetValue(varName, out indx))
                                {
                                    strings[indx] = ((LSL_String)o);
                                    heapsz       += ((LSL_String)o).Length;
                                }
                                continue;
                            }
                            if (otype == typeof(LSL_Rotation))
                            {
                                if (rotationNames.TryGetValue(varName, out indx))
                                {
                                    rotations[indx] = ((LSL_Rotation)o);
                                }
                                continue;
                            }
                            if (otype == typeof(LSL_Vector))
                            {
                                if (vectorNames.TryGetValue(varName, out indx))
                                {
                                    vectors[indx] = ((LSL_Vector)o);
                                }
                                continue;
                            }
                            if (otype == typeof(LSL_Key))
                            {
                                if (stringNames.TryGetValue(varName, out indx))
                                {
                                    strings[indx] = ((LSL_Key)o);
                                    heapsz       += ((LSL_String)o).Length;
                                }
                                continue;
                            }
                            if (otype == typeof(UUID))
                            {
                                if (stringNames.TryGetValue(varName, out indx))
                                {
                                    LSL_String id = ((UUID)o).ToString();
                                    strings[indx] = (id);
                                    heapsz       += id.Length;
                                }
                                continue;
                            }
                            if (otype == typeof(LSL_List))
                            {
                                if (listNames.TryGetValue(varName, out indx))
                                {
                                    LSL_List lo = (LSL_List)o;
                                    lists[indx] = (lo);
                                    heapsz     += lo.Size;
                                }
                                continue;
                            }
                        }
                        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(ReadXTypedValue(pm));
                                    }

                                    break;

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

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

                                        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_Rotation(tmp);

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

                                            tmp        = det.Attributes.GetNamedItem("velocity").Value;
                                            d_velocity = new LSL_Vector(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());
                            eventQueue.AddLast(ep);
                        }
                        break;

                    case "Plugins":
                        List <Object> olist  = new List <Object>();
                        XmlNodeList   itemLP = part.ChildNodes;
                        foreach (XmlNode item in itemLP)
                        {
                            olist.Add(ReadXTypedValue(item));
                        }
                        pluginData = olist.ToArray();
                        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)
                                    {
                                        permsMask    = mask;
                                        permsGranter = granter;
                                    }
                                }
                            }
                        }
                        break;

                    case "MinEventDelay":
                        double.TryParse(part.InnerText, out minEventDelay);
                        break;
                    }
                }
            }
            catch
            {
                throw new Exception("Xstate fail decode");
            }

            int k = 0;

            stateCode = 0;
            foreach (string sn in m_ObjCode.stateNames)
            {
                if (stateName == sn)
                {
                    stateCode = k;
                    break;
                }
                k++;
            }
            eventCode = ScriptEventCode.None;
            m_Running = running;
            doGblInit = false;

            m_Item.PermsGranter = permsGranter;
            m_Item.PermsMask    = permsMask;
            m_Item.ExperienceID = experienceKey;
            m_Part.Inventory.UpdateInventoryItem(m_Item, false, false);

            lock (m_RunLock)
            {
                glblVars.iarIntegers  = ints;
                glblVars.iarFloats    = doubles;
                glblVars.iarVectors   = vectors;
                glblVars.iarRotations = rotations;
                glblVars.iarStrings   = strings;
                glblVars.iarLists     = lists;

                AddArraysHeapUse(heapsz);
                CheckRunLockInvariants(true);
            }

            lock (m_QueueLock)
            {
                m_DetectParams = null;
                foreach (EventParams evt in m_EventQueue)
                {
                    eventQueue.AddLast(evt);
                }

                m_EventQueue = eventQueue;
                for (int i = m_EventCounts.Length; --i >= 0;)
                {
                    m_EventCounts[i] = 0;
                }
                foreach (EventParams evt in m_EventQueue)
                {
                    if (m_eventCodeMap.TryGetValue(evt.EventName, out ScriptEventCode evtCode))
                    {
                        m_EventCounts[(int)evtCode]++;
                    }
                }
            }

            AsyncCommandManager.CreateFromData(m_Engine,
                                               m_LocalID, m_ItemID, m_Part.UUID, pluginData);

            MinEventDelay = minEventDelay;
        }
示例#40
0
 public void default_event_state_entry()
 {
     LSL_Types.Vector3 v = new LSL_Types.Vector3(x, y, -0.5);
 }