public void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osNpcTouch", m_host, "OSSL", m_itemID))
                return;

            IBotManager manager = World.RequestModuleInterface<IBotManager>();
            int linkNum = link_num.value;
            if (manager != null || (linkNum < 0 && linkNum != ScriptBaseClass.LINK_THIS))
            {
                UUID npcId;
                if (!UUID.TryParse(npcLSL_Key, out npcId) || !manager.CheckPermission(npcId, m_host.OwnerID))
                    return;


                IScenePresence sp = World.GetScenePresence(npcId);
                if (sp == null)
                    return;
                ISceneChildEntity child = World.GetSceneObjectPart(UUID.Parse(object_key));
                if (child == null)
                    //throw new Exception("Failed to find entity to touch");
                    return;

                SurfaceTouchEventArgs touchArgs = new SurfaceTouchEventArgs();

                World.EventManager.TriggerObjectGrab(child.ParentEntity.RootChild, child, Vector3.Zero, sp.ControllingClient,
                    touchArgs);
                World.EventManager.TriggerObjectGrabbing(child.ParentEntity.RootChild, child, Vector3.Zero,
                    sp.ControllingClient, touchArgs);
                World.EventManager.TriggerObjectDeGrab(child.ParentEntity.RootChild, child, sp.ControllingClient, touchArgs);                             
            }
        }
        void EventManager_OnObjectGrab(ISceneChildEntity part, ISceneChildEntity child, Vector3 offsetPos,
                                               IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs)
        {
            if (_OnTouchActive && m_localID == part.LocalId)
            {
                TouchEventArgs e = new TouchEventArgs
                                       {
                                           Avatar = new SPAvatar(m_rootScene, remoteClient.AgentId, m_security),
                                           TouchBiNormal = surfaceArgs.Binormal,
                                           TouchMaterialIndex = surfaceArgs.FaceIndex,
                                           TouchNormal = surfaceArgs.Normal,
                                           TouchPosition = surfaceArgs.Position,
                                           TouchST = new Vector2(surfaceArgs.STCoord.X, surfaceArgs.STCoord.Y),
                                           TouchUV = new Vector2(surfaceArgs.UVCoord.X, surfaceArgs.UVCoord.Y)
                                       };

                IObject sender = this;

                if (_OnTouch != null)
                    _OnTouch(sender, e);
            }
        }
        public void touch_end(ISceneChildEntity part, ISceneChildEntity child, IClientAPI remoteClient,
                              SurfaceTouchEventArgs surfaceArgs)
        {
            Dictionary<UUID, DetectParams> det = new Dictionary<UUID, DetectParams>();
            if (!CoalescedTouchEvents.TryGetValue(part.LocalId, out det))
                det = new Dictionary<UUID, DetectParams>();

            // Add to queue for all scripts in ObjectID object
            DetectParams detparam = new DetectParams();
            detparam = new DetectParams {Key = remoteClient.AgentId};

            detparam.Populate(part.ParentEntity.Scene);
            detparam.LinkNum = child.LinkNum;

            if (surfaceArgs != null)
                detparam.SurfaceTouchArgs = surfaceArgs;

            det[remoteClient.AgentId] = detparam;
            CoalescedTouchEvents[part.LocalId] = det;

            ScriptData[] datas = ScriptEngine.ScriptProtection.GetScripts(part.UUID);

            if (datas == null || datas.Length == 0)
                return;

            string functionName = "touch_end";
            object[] param = {new LSL_Types.LSLInteger(det.Count)};

            foreach (ScriptData ID in datas)
            {
                m_scriptEngine.AddToScriptQueue(ID, functionName, new List<DetectParams>(det.Values).ToArray(),
                                                EventPriority.FirstStart, param);
            }
            //Remove us from the det param list
            det.Remove(remoteClient.AgentId);
            CoalescedTouchEvents[part.LocalId] = det;
        }
 public void TriggerObjectGrabbing(ISceneChildEntity part, ISceneChildEntity child, Vector3 offsetPos,
     IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs)
 {
     ObjectGrabDelegate handlerObjectGrabbing = OnObjectGrabbing;
     if (handlerObjectGrabbing != null)
     {
         foreach (ObjectGrabDelegate d in handlerObjectGrabbing.GetInvocationList())
         {
             try
             {
                 d(part, child, offsetPos, remoteClient, surfaceArgs);
             }
             catch (Exception e)
             {
                 MainConsole.Instance.ErrorFormat(
                     "[EVENT MANAGER]: Delegate for TriggerObjectGrabbing failed - continuing.  {0} {1}",
                     e, e.StackTrace);
             }
         }
     }
 }
        public void botTouchObject(string bot, string objectID)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "botTouchObject", m_host, "bot", m_itemID))
                return;
            SurfaceTouchEventArgs touchArgs = new SurfaceTouchEventArgs();

            IScenePresence sp = World.GetScenePresence(UUID.Parse(bot));
            if (sp == null)
                return;
            ISceneChildEntity child = World.GetSceneObjectPart(UUID.Parse(objectID));
            if (child == null)
                throw new Exception("Failed to find entity to touch");

            World.EventManager.TriggerObjectGrab(child.ParentEntity.RootChild, child, Vector3.Zero, sp.ControllingClient,
                                                 touchArgs);
            World.EventManager.TriggerObjectGrabbing(child.ParentEntity.RootChild, child, Vector3.Zero,
                                                     sp.ControllingClient, touchArgs);
            World.EventManager.TriggerObjectDeGrab(child.ParentEntity.RootChild, child, sp.ControllingClient, touchArgs);
        }
 public void TriggerObjectDeGrab(ISceneChildEntity part, ISceneChildEntity child, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs)
 {
     ObjectDeGrabDelegate handlerObjectDeGrab = OnObjectDeGrab;
     if (handlerObjectDeGrab != null)
     {
         foreach (ObjectDeGrabDelegate d in handlerObjectDeGrab.GetInvocationList())
         {
             try
             {
                 d(part, child, remoteClient, surfaceArgs);
             }
             catch (Exception e)
             {
                 MainConsole.Instance.ErrorFormat("[Event Manager]: Delegate for TriggerObjectDeGrab failed - continuing.  {0} {1}", e, e.StackTrace);
             }
         }
     }
 }