Example #1
0
        public void TestSitAndStandWithSitTarget()
        {
            TestHelpers.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));

            Vector3    startPos  = new Vector3(128, 128, 30);
            INPCModule npcModule = scene.RequestModuleInterface <INPCModule>();
            UUID       npcId     = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance);

            ScenePresence   npc  = scene.GetScenePresence(npcId);
            SceneObjectPart part = SceneHelpers.AddSceneObject(scene);

            part.SitTargetPosition = new Vector3(0, 0, 1);
            npcModule.Sit(npc.UUID, part.UUID, scene);

            Assert.That(part.SitTargetAvatar, Is.EqualTo(npcId));
            Assert.That(npc.ParentID, Is.EqualTo(part.LocalId));
            Assert.That(
                npc.AbsolutePosition,
                Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT));

            npcModule.Stand(npc.UUID, scene);

            Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
            Assert.That(npc.ParentID, Is.EqualTo(0));
        }
Example #2
0
 public void RemoveNPCModule(INPCModule mod)
 {
     if (g_NPCModules.ContainsKey(mod.NPCModuleName()))
     {
         g_NPCModules.Remove(mod.NPCModuleName());
     }
 }
Example #3
0
        public void TestCreate()
        {
            TestHelpers.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
//            ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);

            // 8 is the index of the first baked texture in AvatarAppearance
            UUID originalFace8TextureId = TestHelpers.ParseTail(0x10);

            Primitive.TextureEntry     originalTe  = new Primitive.TextureEntry(UUID.Zero);
            Primitive.TextureEntryFace originalTef = originalTe.CreateFace(8);
            originalTef.TextureID = originalFace8TextureId;

            // We also need to add the texture to the asset service, otherwise the AvatarFactoryModule will tell
            // ScenePresence.SendInitialData() to reset our entire appearance.
            scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId));

            afm.SetAppearance(sp, originalTe, null);

            INPCModule npcModule = scene.RequestModuleInterface <INPCModule>();
            UUID       npcId     = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, sp.Appearance);

            ScenePresence npc = scene.GetScenePresence(npcId);

            Assert.That(npc, Is.Not.Null);
            Assert.That(npc.Appearance.Texture.FaceTextures[8].TextureID, Is.EqualTo(originalFace8TextureId));
            Assert.That(umm.GetUserName(npc.UUID), Is.EqualTo(string.Format("{0} {1}", npc.Firstname, npc.Lastname)));
        }
Example #4
0
        public bool AddNPCModule(INPCModule mod)
        {
            if (g_NPCModules == null)
            {
                g_NPCModules = new Dictionary <string, INPCModule>();
            }
            if (g_NPCModules.ContainsKey(mod.NPCModuleName()))
            {
                return(false);
            }
            switch (mod.NPCModuleTarget())
            {
            case NPC_MODULE_TARGET.AI:
                gAI.SetNPCModule(mod);
                break;

            case NPC_MODULE_TARGET.BODY:
                break;

            case NPC_MODULE_TARGET.PERCEPTION:
                break;
            }
            g_NPCModules.Add(mod.NPCModuleName(), mod);
            return(true);
        }
Example #5
0
        public int getRealAvatars()
        {
            int _agents = 0;

            INPCModule module = m_scene.RequestModuleInterface <INPCModule>();

            if (module != null)
            {
                m_scene.ForEachRootScenePresence(
                    delegate(ScenePresence ssp)
                {
                    if (!ssp.IsNPC)
                    {
                        _agents++;
                    }
                }
                    );
            }
            else
            {
                try
                {
                    m_scene.ForEachClient(c => { _agents++; });
                }
                catch (Exception _error)
                {
                    m_log.Error("FATAL ERROR: " + _error.Message);
                }
            }

            return(_agents);
        }
Example #6
0
        public void TestSitAndStandWithNoSitTarget()
        {
            TestHelpers.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));

            // FIXME: To get this to work for now, we are going to place the npc right next to the target so that
            // the autopilot doesn't trigger
            Vector3 startPos = new Vector3(1, 1, 1);

            INPCModule npcModule = scene.RequestModuleInterface <INPCModule>();
            UUID       npcId     = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance);

            ScenePresence   npc  = scene.GetScenePresence(npcId);
            SceneObjectPart part = SceneHelpers.AddSceneObject(scene);

            npcModule.Sit(npc.UUID, part.UUID, scene);

            Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
            Assert.That(npc.ParentID, Is.EqualTo(part.LocalId));

            // FIXME: This is different for live avatars - z position is adjusted.  This is half the height of the
            // default avatar.
            // Curiously, Vector3.ToString() will not display the last two places of the float.  For example,
            // printing out npc.AbsolutePosition will give <0, 0, 0.8454993> not <0, 0, 0.845499337>
            Assert.That(
                npc.AbsolutePosition,
                Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, 0.845499337f)));

            npcModule.Stand(npc.UUID, scene);

            Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
            Assert.That(npc.ParentID, Is.EqualTo(0));
        }
Example #7
0
 public SensorRepeat(AsyncCommandManager CmdManager)
 {
     m_CmdManager    = CmdManager;
     maximumRange    = CmdManager.m_ScriptEngine.Config.GetDouble("SensorMaxRange", 96.0d);
     maximumToReturn = CmdManager.m_ScriptEngine.Config.GetInt("SensorMaxResults", 16);
     m_npcModule     = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface <INPCModule>();
 }
Example #8
0
        private void TestAddRemoveNPCs(int numberOfNpcs)
        {
            ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
//            ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);

            // 8 is the index of the first baked texture in AvatarAppearance
            UUID originalFace8TextureId = TestHelpers.ParseTail(0x10);

            Primitive.TextureEntry     originalTe  = new Primitive.TextureEntry(UUID.Zero);
            Primitive.TextureEntryFace originalTef = originalTe.CreateFace(8);
            originalTef.TextureID = originalFace8TextureId;

            // We also need to add the texture to the asset service, otherwise the AvatarFactoryModule will tell
            // ScenePresence.SendInitialData() to reset our entire appearance.
            scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId));

            afm.SetAppearance(sp, originalTe, null, new WearableCacheItem[0]);

            INPCModule npcModule = scene.RequestModuleInterface <INPCModule>();

            List <UUID> npcs = new List <UUID>();

            long      startGcMemory = GC.GetTotalMemory(true);
            Stopwatch sw            = new Stopwatch();

            sw.Start();

            for (int i = 0; i < numberOfNpcs; i++)
            {
                npcs.Add(
                    npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, scene, sp.Appearance));
            }

            for (int i = 0; i < numberOfNpcs; i++)
            {
                Assert.That(npcs[i], Is.Not.Null);

                ScenePresence npc = scene.GetScenePresence(npcs[i]);
                Assert.That(npc, Is.Not.Null);
            }

            for (int i = 0; i < numberOfNpcs; i++)
            {
                Assert.That(npcModule.DeleteNPC(npcs[i], scene), Is.True);
                ScenePresence npc = scene.GetScenePresence(npcs[i]);
                Assert.That(npc, Is.Null);
            }

            sw.Stop();

            long endGcMemory = GC.GetTotalMemory(true);

            Console.WriteLine("Took {0} ms", sw.ElapsedMilliseconds);
            Console.WriteLine(
                "End {0} MB, Start {1} MB, Diff {2} MB",
                endGcMemory / 1024 / 1024,
                startGcMemory / 1024 / 1024,
                (endGcMemory - startGcMemory) / 1024 / 1024);
        }
        /// <summary>
        /// Update the attachment asset for the new sog details if they have changed.
        /// </summary>
        /// <remarks>
        /// This is essential for preserving attachment attributes such as permission.  Unlike normal scene objects,
        /// these details are not stored on the region.
        /// </remarks>
        /// <param name="sp"></param>
        /// <param name="grp"></param>
        private void UpdateKnownItem(IScenePresence sp, SceneObjectGroup grp, bool saveAllScripted)
        {
            // Saving attachments for NPCs messes them up for the real owner!
            INPCModule module = m_scene.RequestModuleInterface <INPCModule>();

            if (module != null)
            {
                if (module.IsNPC(sp.UUID, m_scene))
                {
                    return;
                }
            }

            if (grp.HasGroupChanged || (saveAllScripted && grp.ContainsScripts()))
            {
                m_log.DebugFormat(
                    "[ATTACHMENTS MODULE]: Updating asset for attachment {0}, attachpoint {1}",
                    grp.UUID, grp.AttachmentPoint);

                string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp);

                InventoryItemBase item = new InventoryItemBase(grp.GetFromItemID(), sp.UUID);
                item = m_scene.InventoryService.GetItem(item);

                if (item != null)
                {
                    AssetBase asset = m_scene.CreateAsset(
                        grp.GetPartName(grp.LocalId),
                        grp.GetPartDescription(grp.LocalId),
                        (sbyte)AssetType.Object,
                        Utils.StringToBytes(sceneObjectXml),
                        sp.UUID);
                    m_scene.AssetService.Store(asset);

                    item.AssetID     = asset.FullID;
                    item.Description = asset.Description;
                    item.Name        = asset.Name;
                    item.AssetType   = asset.Type;
                    item.InvType     = (int)InventoryType.Object;

                    m_scene.InventoryService.UpdateItem(item);

                    // this gets called when the agent logs off!
                    if (sp.ControllingClient != null)
                    {
                        sp.ControllingClient.SendInventoryItemCreateUpdate(item, 0);
                    }
                }
                grp.HasGroupChanged = false; // Prevent it being saved over and over
            }
            else
            {
                m_log.DebugFormat(
                    "[ATTACHMENTS MODULE]: Don't need to update asset for unchanged attachment {0}, attachpoint {1}",
                    grp.UUID, grp.AttachmentPoint);
            }
        }
Example #10
0
        private void recreateNPC()
        {
            INPCModule module = m_scene.RequestModuleInterface <INPCModule>();

            foreach (NPCData data in m_npcs)
            {
                module.CreateNPC(data.FirstName, data.LastName, data.Position, data.AgentID, data.Owner, data.GroupTitle, data.GroupUUID, data.SenseAsAgent, m_scene, data.Appearance);
            }

            m_npcs = new List <NPCData>();
        }
 public void SetNPCModule(INPCModule mod)
 {
     if (gPathfinders == null)
     {
         InitPathfinders();
     }
     switch (mod.NPCModuleType())
     {
     case NPC_MODULE_TYPE.PATHFINDER:
         gPathfinders.Add(mod.NPCModuleName(), mod as INPCPathfinder);
         break;
     }
 }
Example #12
0
        public void GridKickUser(UUID agentID, string reason)
        {
            int godlevel = 240; // grid god default

            ScenePresence sp = m_scene.GetScenePresence(agentID);

            if (sp == null || sp.IsChildAgent)
            {
                IMessageTransferModule transferModule =
                    m_scene.RequestModuleInterface <IMessageTransferModule>();
                if (transferModule != null)
                {
                    m_log.DebugFormat("[GODS]: Sending nonlocal kill for agent {0}", agentID);
                    transferModule.SendInstantMessage(new GridInstantMessage(
                                                          m_scene, Constants.servicesGodAgentID, "GRID", agentID, (byte)250, false,
                                                          reason, UUID.Zero, true,
                                                          new Vector3(), new byte[] { 0 }, true),
                                                      delegate(bool success) { });
                }
                return;
            }

            if (sp.IsDeleted)
            {
                return;
            }

            if (godlevel <= sp.GodController.GodLevel) // no god wars
            {
                if (m_dialogModule != null)
                {
                    m_dialogModule.SendAlertToUser(sp.UUID, "GRID kick detected and ignored, kick reason: " + reason);
                }
                return;
            }

            if (sp.IsNPC)
            {
                INPCModule npcmodule = sp.Scene.RequestModuleInterface <INPCModule>();
                if (npcmodule != null)
                {
                    npcmodule.DeleteNPC(sp.UUID, sp.Scene);
                    return;
                }
            }
            sp.ControllingClient.Kick(reason);
            sp.Scene.CloseAgent(sp.UUID, true);
        }
Example #13
0
 private void KickPresence(ScenePresence sp, string reason)
 {
     if (sp.IsDeleted || sp.IsChildAgent)
     {
         return;
     }
     if (sp.IsNPC)
     {
         INPCModule npcmodule = sp.Scene.RequestModuleInterface <INPCModule>();
         if (npcmodule != null)
         {
             npcmodule.DeleteNPC(sp.UUID, sp.Scene);
             return;
         }
     }
     sp.ControllingClient.Kick(reason);
     sp.Scene.CloseAgent(sp.UUID, true);
 }
Example #14
0
        public void deleteAllNPC()
        {
            m_npcs = new List <NPCData>();

            try
            {
                INPCModule module = m_scene.RequestModuleInterface <INPCModule>();

                if (module != null)
                {
                    m_scene.ForEachRootScenePresence(
                        delegate(ScenePresence ssp)
                    {
                        if (ssp.IsNPC)
                        {
                            NPCData data      = new NPCData();
                            data.FirstName    = ssp.Firstname;
                            data.LastName     = ssp.Lastname;
                            data.Position     = ssp.AbsolutePosition;
                            data.AgentID      = ssp.UUID;
                            data.Owner        = module.GetOwner(ssp.UUID);
                            data.GroupTitle   = ssp.Grouptitle;
                            data.GroupUUID    = UUID.Zero;
                            data.SenseAsAgent = !ssp.IsNPC;
                            data.Appearance   = ssp.Appearance;
                            m_npcs.Add(data);

                            module.DeleteNPC(ssp.UUID, m_scene);
                            m_log.Info("Remove NPC " + ssp.Firstname + " " + ssp.Lastname);
                        }
                    }
                        );
                }
                else
                {
                    m_log.Error("WARNING: CANT FOUND A NPC MODULE!");
                }
            }
            catch (Exception _error)
            {
                m_log.Error("FATAL ERROR: " + _error.Message);
            }
        }
Example #15
0
        public void TestAttachments()
        {
            TestHelpers.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            UUID userId = TestHelpers.ParseTail(0x1);

            UserAccountHelpers.CreateUserWithInventory(scene, userId);
            ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId);

            UUID   attItemId  = TestHelpers.ParseTail(0x2);
            UUID   attAssetId = TestHelpers.ParseTail(0x3);
            string attName    = "att";

            UserInventoryHelpers.CreateInventoryItem(scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object);

            am.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest);

            INPCModule npcModule = scene.RequestModuleInterface <INPCModule>();
            UUID       npcId     = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, sp.Appearance);

            ScenePresence npc = scene.GetScenePresence(npcId);

            // Check scene presence status
            Assert.That(npc.HasAttachments(), Is.True);
            List <SceneObjectGroup> attachments = npc.GetAttachments();

            Assert.That(attachments.Count, Is.EqualTo(1));
            SceneObjectGroup attSo = attachments[0];

            // Just for now, we won't test the name since this is (wrongly) the asset part name rather than the item
            // name.  TODO: Do need to fix ultimately since the item may be renamed before being passed on to an NPC.
//            Assert.That(attSo.Name, Is.EqualTo(attName));

            Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
            Assert.That(attSo.IsAttachment);
            Assert.That(attSo.UsesPhysics, Is.False);
            Assert.That(attSo.IsTemporary, Is.False);
            Assert.That(attSo.OwnerID, Is.EqualTo(npc.UUID));
        }
Example #16
0
        /// <summary>
        /// Update the attachment asset for the new sog details if they have changed.
        /// </summary>
        /// <remarks>
        /// This is essential for preserving attachment attributes such as permission.  Unlike normal scene objects,
        /// these details are not stored on the region.
        /// </remarks>
        /// <param name="sp"></param>
        /// <param name="grp"></param>
        /// <param name="saveAllScripted"></param>
        private void UpdateKnownItem(IScenePresence sp, SceneObjectGroup grp, string scriptedState)
        {
            if (grp.FromItemID == UUID.Zero)
            {
                // We can't save temp attachments
                grp.HasGroupChanged = false;
                return;
            }

            // Saving attachments for NPCs messes them up for the real owner!
            INPCModule module = m_scene.RequestModuleInterface <INPCModule>();

            if (module != null)
            {
                if (module.IsNPC(sp.UUID, m_scene))
                {
                    return;
                }
            }

            if (grp.HasGroupChanged)
            {
                m_log.DebugFormat(
                    "[ATTACHMENTS MODULE]: Updating asset for attachment {0}, attachpoint {1}",
                    grp.UUID, grp.AttachmentPoint);

                string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp, scriptedState);

                InventoryItemBase item = new InventoryItemBase(grp.FromItemID, sp.UUID);
                item = m_scene.InventoryService.GetItem(item);

                if (item != null)
                {
                    AssetBase asset = m_scene.CreateAsset(
                        grp.GetPartName(grp.LocalId),
                        grp.GetPartDescription(grp.LocalId),
                        (sbyte)AssetType.Object,
                        Utils.StringToBytes(sceneObjectXml),
                        sp.UUID);
                    m_scene.AssetService.Store(asset);

                    item.AssetID     = asset.FullID;
                    item.Description = asset.Description;
                    item.Name        = asset.Name;
                    item.AssetType   = asset.Type;
                    item.InvType     = (int)InventoryType.Object;

                    m_scene.InventoryService.UpdateItem(item);

                    // If the name of the object has been changed whilst attached then we want to update the inventory
                    // item in the viewer.
                    if (sp.ControllingClient != null)
                    {
                        sp.ControllingClient.SendInventoryItemCreateUpdate(item, 0);
                    }
                }

                grp.HasGroupChanged = false; // Prevent it being saved over and over
            }
//            else
//            {
//                m_log.DebugFormat(
//                    "[ATTACHMENTS MODULE]: Don't need to update asset for unchanged attachment {0}, attachpoint {1}",
//                    grp.UUID, grp.AttachmentPoint);
//            }
        }
Example #17
0
 public bool ContainsModule(INPCModule mod)
 {
     return(g_NPCModules != null && g_NPCModules.ContainsKey(mod.NPCModuleName()));
 }
Example #18
0
        private void KillAvatar(uint killerObjectLocalID, ScenePresence deadAvatar)
        {
            string        deadAvatarMessage;
            ScenePresence killingAvatar = null;
//            string killingAvatarMessage;

            // check to see if it is an NPC and just remove it
            INPCModule NPCmodule = deadAvatar.Scene.RequestModuleInterface <INPCModule>();

            if (NPCmodule != null && NPCmodule.DeleteNPC(deadAvatar.UUID, deadAvatar.Scene))
            {
                return;
            }

            if (killerObjectLocalID == 0)
            {
                deadAvatarMessage = "You committed suicide!";
            }
            else
            {
                // Try to get the avatar responsible for the killing
                killingAvatar = deadAvatar.Scene.GetScenePresence(killerObjectLocalID);
                if (killingAvatar == null)
                {
                    // Try to get the object which was responsible for the killing
                    SceneObjectPart part = deadAvatar.Scene.GetSceneObjectPart(killerObjectLocalID);
                    if (part == null)
                    {
                        // Cause of death: Unknown
                        deadAvatarMessage = "You died!";
                    }
                    else
                    {
                        // Try to find the avatar wielding the killing object
                        killingAvatar = deadAvatar.Scene.GetScenePresence(part.OwnerID);
                        if (killingAvatar == null)
                        {
                            IUserManagement userManager = deadAvatar.Scene.RequestModuleInterface <IUserManagement>();
                            string          userName    = "******";
                            if (userManager != null)
                            {
                                userName = userManager.GetUserName(part.OwnerID);
                            }
                            deadAvatarMessage = String.Format("You impaled yourself on {0} owned by {1}!", part.Name, userName);
                        }
                        else
                        {
                            //                            killingAvatarMessage = String.Format("You fragged {0}!", deadAvatar.Name);
                            deadAvatarMessage = String.Format("You got killed by {0}!", killingAvatar.Name);
                        }
                    }
                }
                else
                {
//                    killingAvatarMessage = String.Format("You fragged {0}!", deadAvatar.Name);
                    deadAvatarMessage = String.Format("You got killed by {0}!", killingAvatar.Name);
                }
            }
            try
            {
                deadAvatar.ControllingClient.SendAgentAlertMessage(deadAvatarMessage, true);
                if (killingAvatar != null)
                {
                    killingAvatar.ControllingClient.SendAlertMessage("You fragged " + deadAvatar.Firstname + " " + deadAvatar.Lastname);
                }
            }
            catch (InvalidOperationException)
            { }

            deadAvatar.setHealthWithUpdate(100.0f);
            deadAvatar.Scene.TeleportClientHome(deadAvatar.UUID, deadAvatar.ControllingClient);
        }
Example #19
0
        public void Populate(Scene scene)
        {
            SceneObjectPart part = scene.GetSceneObjectPart(Key);

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

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

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

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

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

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

                Group = presence.ControllingClient.ActiveGroupId;

                return;
            }

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

            LinkNum = 0;                      // Not relevant

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

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

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

            Quaternion wr = part.ParentGroup.GroupRotation;

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

            Velocity = new LSL_Types.Vector3(part.Velocity);
        }
        private List <SensedEntity> doAgentSensor(SenseRepeatClass ts)
        {
            INPCModule npcModule = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface <INPCModule>();

            List <SensedEntity> sensedEntities = new List <SensedEntity>();

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

            SceneObjectPart SensePoint    = ts.host;
            Vector3         fromRegionPos = SensePoint.AbsolutePosition;

            Quaternion q = SensePoint.RotationOffset;

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

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

            Action <ScenePresence> senseEntity = new Action <ScenePresence>(presence =>
            {
//                m_log.DebugFormat(
//                    "[SENSOR REPEAT]: Inspecting scene presence {0}, type {1} on sensor sweep for {2}, type {3}",
//                    presence.Name, presence.PresenceType, ts.name, ts.type);

                if ((ts.type & NPC) == 0 && presence.PresenceType == PresenceType.Npc)
                {
                    INPC npcData = 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 = 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
                        {
                            Vector3 diff = toRegionPos - fromRegionPos;
                            LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(diff.X, diff.Y, diff.Z);
                            double dot     = LSL_Types.Vector3.Dot(forward_dir, obj_dir);
                            double mag_obj = LSL_Types.Vector3.Mag(obj_dir);
                            ang_obj        = Math.Acos(dot / (mag_fwd * mag_obj));
                        }
                        catch
                        {
                        }
                        if (ang_obj <= ts.arc)
                        {
                            sensedEntities.Add(new SensedEntity(dis, presence.UUID));
                        }
                    }
                    else
                    {
                        sensedEntities.Add(new SensedEntity(dis, presence.UUID));
                    }
                }
            });

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

                return(sensedEntities);
            }
            else
            {
                m_CmdManager.m_ScriptEngine.World.ForEachRootScenePresence(senseEntity);
            }
            return(sensedEntities);
        }
Example #21
0
        public void TestMove()
        {
            TestHelpers.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
//            ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);

            Vector3    startPos  = new Vector3(128, 128, 30);
            INPCModule npcModule = scene.RequestModuleInterface <INPCModule>();
            UUID       npcId     = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance);

            ScenePresence npc = scene.GetScenePresence(npcId);

            Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));

            // For now, we'll make the scene presence fly to simplify this test, but this needs to change.
            npc.Flying = true;

            scene.Update();
            Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));

            Vector3 targetPos = startPos + new Vector3(0, 10, 0);

            npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false);

            Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
            //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f)));
            Assert.That(
                npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001));

            scene.Update();

            // We should really check the exact figure.
            Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X));
            Assert.That(npc.AbsolutePosition.Y, Is.GreaterThan(startPos.Y));
            Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
            Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.X));

            for (int i = 0; i < 10; i++)
            {
                scene.Update();
            }

            double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);

            Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move");
            Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
            Assert.That(npc.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE));

            // Try a second movement
            startPos  = npc.AbsolutePosition;
            targetPos = startPos + new Vector3(10, 0, 0);
            npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false);

            Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
//            Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0, 1)));
            Assert.That(
                npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0, 1), 0.000001));

            scene.Update();

            // We should really check the exact figure.
            Assert.That(npc.AbsolutePosition.X, Is.GreaterThan(startPos.X));
            Assert.That(npc.AbsolutePosition.X, Is.LessThan(targetPos.X));
            Assert.That(npc.AbsolutePosition.Y, Is.EqualTo(startPos.Y));
            Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z));

            for (int i = 0; i < 10; i++)
            {
                scene.Update();
            }

            distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
            Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on second move");
            Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
        }