Beispiel #1
0
 public void InjectCollisionEnd(ScriptInstance instance,
                                LSLKey targetPrim,
                                LSLKey sourceLinkset,
                                string name,
                                int objType,
                                Vector3 position,
                                Quaternion rotation,
                                Vector3 velocity,
                                int linkNumber)
 {
     lock (instance)
     {
         ObjectPart part;
         if (instance.Part.ObjectGroup.Scene.Primitives.TryGetValue(targetPrim, out part))
         {
             var di = new DetectInfo
             {
                 Key        = sourceLinkset,
                 Name       = name,
                 Group      = UGI.Unknown,
                 ObjType    = (DetectedTypeFlags)objType,
                 Owner      = instance.Part.Owner,
                 Position   = position,
                 Rotation   = rotation,
                 Velocity   = velocity,
                 LinkNumber = linkNumber
             };
             var ev = new CollisionEvent {
                 Type = CollisionEvent.CollisionType.End
             };
             ev.Detected.Add(di);
             part.PostEvent(ev);
         }
     }
 }
Beispiel #2
0
            internal void Init(ref DetectInfo detectInfo, MyCubeGrid myGrid, GridAi myAi, GridAi targetAi)
            {
                EntInfo   = detectInfo.EntInfo;
                Target    = detectInfo.Parent;
                PartCount = detectInfo.PartCount;
                FatCount  = detectInfo.FatCount;
                IsStatic  = Target.Physics.IsStatic;
                IsGrid    = detectInfo.IsGrid;
                LargeGrid = detectInfo.LargeGrid;
                MyGrid    = myGrid;
                MyAi      = myAi;
                TargetAi  = targetAi;
                Velocity  = Target.Physics.LinearVelocity;
                VelLenSqr = Velocity.LengthSquared();
                var targetSphere = Target.PositionComp.WorldVolume;

                TargetPos    = targetSphere.Center;
                TargetRadius = targetSphere.Radius;
                var myCenter = myAi.GridVolume.Center;

                if (!MyUtils.IsZero(Velocity, 1E-02F))
                {
                    var targetMag = myCenter - TargetPos;
                    Approaching = MathFuncs.IsDotProductWithinTolerance(ref Velocity, ref targetMag, myAi.Session.ApproachDegrees);
                }
                else
                {
                    Approaching   = false;
                    TargetHeading = Vector3D.Zero;
                }

                if (targetAi != null)
                {
                    OffenseRating = targetAi.Construct.OptimalDps / myAi.Construct.OptimalDps;
                    if (OffenseRating <= 0 && detectInfo.Armed)
                    {
                        OffenseRating = 0.0001f;
                    }
                }
                else if (detectInfo.Armed)
                {
                    OffenseRating = 0.0001f;
                }
                else
                {
                    OffenseRating = 0;
                }
                var myRadius       = myAi.MyGrid.PositionComp.LocalVolume.Radius;
                var sphereDistance = MyUtils.GetSmallestDistanceToSphere(ref myCenter, ref targetSphere);

                if (sphereDistance <= myRadius)
                {
                    sphereDistance = 0;
                }
                else
                {
                    sphereDistance -= myRadius;
                }
                DistSqr = sphereDistance * sphereDistance;
            }
        //获取时间段t1-t2之间监测点deviceID检测结果数以及检测结果
        public DetectInfo GetResultInfo(string DeviceID, DateTime t1, DateTime t2)
        {
            DetectInfo d_info = new DetectInfo();
            //保存总检测记录数
            string sqlall = "SELECT COUNT(*) FROM detectioninfo  WHERE Device_ID = '" + DeviceID + "'" +
                            " AND test_time BETWEEN  '" + t1 + "'" +
                            " AND '" + t2 + "'";

            d_info.m_num = ReadHistoryDataCount(sqlall);
            //保存合格记录数
            string sql = "SELECT COUNT(*) FROM detectioninfo  WHERE Device_ID = '" + DeviceID + "'" +
                         " AND test_time BETWEEN  '" + t1 + "'" +
                         " AND '" + t2 + "'" +
                         " AND Juge_result  = '合格'";

            d_info.m_good = ReadHistoryDataCount(sql);
            //保存黄色记录数
            /*   SystemSet ss = new SystemSet();*/



            //读取黄色警报数量
            sql = "SELECT COUNT(*) FROM detectioninfo INNER JOIN ftinfor ON (detectioninfo.p_name = ftinfor.ftestitems AND detectioninfo.type = ftinfor.fsample AND detectioninfo.standard = ftinfor.standards)  WHERE Device_ID = '" + DeviceID + "'" +
                  " AND test_time BETWEEN '" + t1 + "'" +
                  " AND '" + t2 + "'" +
                  " AND Juge_result  = '不合格'" +
                  " AND (Detect_result-comparemax) >=  comparemax * alarm_yellow  AND (Detect_result-comparemax) < comparemax * alarm_pitch ";
            d_info.m_yellownum = ReadHistoryDataCount(sql);

            //读取粉色警报数量
            sql = "SELECT COUNT(*) FROM detectioninfo INNER JOIN ftinfor ON (detectioninfo.p_name = ftinfor.ftestitems AND detectioninfo.type = ftinfor.fsample AND detectioninfo.standard = ftinfor.standards)   WHERE Device_ID = '" + DeviceID + "'" +
                  " AND test_time BETWEEN '" + t1 + "'" +
                  " AND '" + t2 + "'" +
                  " AND Juge_result  = '不合格'" +
                  " AND (Detect_result-comparemax) >= comparemax * alarm_pitch  AND (Detect_result-comparemax) < comparemax* alarm_red";
            d_info.m_fensenum = ReadHistoryDataCount(sql);
            //读取红色色警报数量
            sql = "SELECT COUNT(*) FROM detectioninfo INNER JOIN ftinfor ON (detectioninfo.p_name = ftinfor.ftestitems AND detectioninfo.type = ftinfor.fsample AND detectioninfo.standard = ftinfor.standards)   WHERE Device_ID = '" + DeviceID + "'" +
                  " AND test_time BETWEEN '" + t1 + "'" +
                  " AND '" + t2 + "'" +
                  " AND Juge_result  = '不合格'" +
                  " AND (Detect_result-comparemax) >= comparemax* alarm_red";
            d_info.m_rednum = ReadHistoryDataCount(sql);



            d_info.m_rate = (double)d_info.m_good / (double)d_info.m_num;

            DataSet dataSet = new DataSet();
            int     ret     = database.ReadDataBase(sqlall, "company", dataSet);

            if (ret == 0)
            {
                System.Data.DataTable dtInfo = new System.Data.DataTable();
                d_info.table = dtInfo;
            }
            return(d_info);
        }
        public void HandleObjectGrabUpdate(Message m)
        {
            var req = (ObjectGrabUpdate)m;

            if (req.CircuitSessionID != req.SessionID ||
                req.CircuitAgentID != req.AgentID)
            {
                return;
            }

            var e = new TouchEvent
            {
                Detected = new List <DetectInfo>(),
                Type     = TouchEvent.TouchType.Continuous
            };
            ObjectPart part;

            if (!Primitives.TryGetValue(req.ObjectID, out part))
            {
                return;
            }

            IAgent agent;

            if (!Agents.TryGetValue(req.AgentID, out agent))
            {
                return;
            }

            Object.ObjectGroup objgrp = part.ObjectGroup;
            if (objgrp != null && (part.Flags & PrimitiveFlags.Touch) == 0)
            {
                /* only allow when no touch event is active */
                GrabMovement(agent, objgrp, part, req.GrabPosition);
            }

            var detectdata = new DetectInfo();

            AddDetectAgentData(agent, ref detectdata);
            detectdata.GrabOffset = req.GrabPosition;
            detectdata.LinkNumber = part.LinkNumber;
            if (req.ObjectData.Count > 0)
            {
                var grabdata = req.ObjectData[0];
                detectdata.TouchBinormal = grabdata.Binormal;
                detectdata.TouchNormal   = grabdata.Normal;
                detectdata.TouchFace     = grabdata.FaceIndex;
                detectdata.TouchPosition = grabdata.Position;
                detectdata.TouchST       = grabdata.STCoord;
                detectdata.TouchUV       = grabdata.UVCoord;
            }
            e.Detected.Add(detectdata);

            part.PostTouchEvent(e);
        }
 private void AddDetectAgentData(IAgent agent, ref DetectInfo detectdata)
 {
     detectdata.Key      = agent.ID;
     detectdata.Group    = agent.Group;
     detectdata.Owner    = agent.Owner;
     detectdata.Name     = agent.Name;
     detectdata.ObjType  = agent.DetectedType;
     detectdata.Position = agent.GlobalPosition;
     detectdata.Velocity = agent.Velocity;
     detectdata.Rotation = agent.GlobalRotation;
 }
        public void DoTouch(UUID objectKey, int linkNum)
        {
            ObjectGroup grp;
            ObjectPart  part;

            if (!CurrentScene.ObjectGroups.TryGetValue(objectKey, out grp))
            {
                return;
            }
            else if (!grp.TryGetValue(linkNum, out part))
            {
                return;
            }
            var dInfo = new DetectInfo
            {
                LinkNumber    = linkNum,
                TouchFace     = -1,
                Name          = NamedOwner.FullName,
                GrabOffset    = part.LocalPosition * -1f,
                Group         = Group,
                Key           = ID,
                ObjType       = DetectedTypeFlags.Npc | ((SittingOnObject != null) ? DetectedTypeFlags.Passive : DetectedTypeFlags.Active),
                Owner         = Owner,
                Position      = GlobalPosition,
                Rotation      = GlobalRotation,
                TouchBinormal = Vector3.Zero,
                TouchNormal   = Vector3.Zero,
                TouchST       = new Vector3(-1f, -1f, 0),
                TouchUV       = new Vector3(-1f, -1f, 0)
            };
            var te = new TouchEvent
            {
                Type = TouchEvent.TouchType.Start
            };

            te.Detected.Add(dInfo);
            part.PostTouchEvent(te);

            te = new TouchEvent
            {
                Type = TouchEvent.TouchType.Continuous
            };
            te.Detected.Add(dInfo);
            part.PostTouchEvent(te);

            te = new TouchEvent
            {
                Type = TouchEvent.TouchType.End
            };
            te.Detected.Add(dInfo);
            part.PostTouchEvent(te);
        }
Beispiel #7
0
            internal void Init(ref DetectInfo detectInfo, MyCubeGrid myGrid, GridAi myAi, GridAi targetAi)
            {
                EntInfo   = detectInfo.EntInfo;
                Target    = detectInfo.Parent;
                PartCount = detectInfo.PartCount;
                FatCount  = detectInfo.FatCount;
                IsGrid    = detectInfo.IsGrid;
                LargeGrid = detectInfo.LargeGrid;
                MyGrid    = myGrid;
                MyAi      = myAi;
                TargetAi  = targetAi;
                Velocity  = Target.Physics.LinearVelocity;
                VelLenSqr = Velocity.LengthSquared();
                var targetSphere = Target.PositionComp.WorldVolume;

                TargetPos    = targetSphere.Center;
                TargetRadius = targetSphere.Radius;
                if (!MyUtils.IsZero(Velocity, 1E-02F))
                {
                    TargetDir = Vector3D.Normalize(Velocity);
                    var refDir = Vector3D.Normalize(myAi.GridVolume.Center - TargetPos);
                    Approaching = MathFuncs.IsDotProductWithinTolerance(ref TargetDir, ref refDir, myAi.Session.ApproachDegrees);
                }
                else
                {
                    TargetDir   = Vector3D.Zero;
                    Approaching = false;
                }

                if (targetAi != null)
                {
                    OffenseRating = targetAi.Construct.OptimalDps / myAi.Construct.OptimalDps;
                }
                else if (detectInfo.Armed)
                {
                    OffenseRating = 0.0001f;
                }
                else
                {
                    OffenseRating = 0;
                }

                var targetDist = Vector3D.Distance(myAi.GridVolume.Center, TargetPos) - TargetRadius;

                targetDist -= myAi.GridVolume.Radius;
                if (targetDist < 0)
                {
                    targetDist = 0;
                }
                DistSqr = targetDist * targetDist;
            }
        public void HandleObjectGrab(Message m)
        {
            var req = (ObjectGrab)m;

            if (req.CircuitSessionID != req.SessionID ||
                req.CircuitAgentID != req.AgentID)
            {
                return;
            }

            var e = new TouchEvent
            {
                Detected = new List <DetectInfo>(),
                Type     = TouchEvent.TouchType.Start
            };
            ObjectPart part;

            if (!Primitives.TryGetValue(req.ObjectLocalID, out part))
            {
                return;
            }

            IAgent agent;

            if (!Agents.TryGetValue(req.AgentID, out agent))
            {
                return;
            }

            var detectdata = new DetectInfo();

            AddDetectAgentData(agent, ref detectdata);
            detectdata.GrabOffset = req.GrabOffset;
            detectdata.LinkNumber = part.LinkNumber;
            if (req.ObjectData.Count > 0)
            {
                var grabdata = req.ObjectData[0];
                detectdata.TouchBinormal = grabdata.Binormal;
                detectdata.TouchNormal   = grabdata.Normal;
                detectdata.TouchFace     = grabdata.FaceIndex;
                detectdata.TouchPosition = grabdata.Position;
                detectdata.TouchST       = grabdata.STCoord;
                detectdata.TouchUV       = grabdata.UVCoord;
            }
            e.Detected.Add(detectdata);

            part.PostTouchEvent(e);
        }