فهرست منبع

Overload INPCModule.CreateNPC() to allow agentID to be specified. Note: this is intended for use in region modules and is not exposed to scripts.

dahlia 10 سال پیش
والد
کامیت
a8e64cd59a

+ 26 - 0
OpenSim/Region/Framework/Interfaces/INPCModule.cs

@@ -71,6 +71,32 @@ namespace OpenSim.Region.Framework.Interfaces
                 UUID owner, bool senseAsAgent, Scene scene,
                 AvatarAppearance appearance);
 
+        /// <summary>
+        /// Create an NPC with a user-supplied agentID
+        /// </summary>
+        /// <param name="firstname"></param>
+        /// <param name="lastname"></param>
+        /// <param name="position"></param>
+        /// <param name="agentID"></param>
+        /// The desired agent ID
+        /// <param name="owner"></param>
+        /// <param name="senseAsAgent">
+        /// Make the NPC show up as an agent on LSL sensors. The default is
+        /// that they show up as the NPC type instead, but this is currently
+        /// an OpenSim-only extension.
+        /// </param>
+        /// <param name="scene"></param>
+        /// <param name="appearance">
+        /// The avatar appearance to use for the new NPC.
+        /// </param>
+        /// <returns>
+        /// The UUID of the ScenePresence created. UUID.Zero if there was a
+        /// failure.
+        /// </returns>
+        UUID CreateNPC(string firstname, string lastname,
+                Vector3 position, UUID agentID, UUID owner, bool senseAsAgent, Scene scene,
+                AvatarAppearance appearance);
+
         /// <summary>
         /// Check if the agent is an NPC.
         /// </summary>

+ 14 - 1
OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs

@@ -61,7 +61,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
         private readonly string m_firstname;
         private readonly string m_lastname;
         private readonly Vector3 m_startPos;
-        private readonly UUID m_uuid = UUID.Random();
+        private readonly UUID m_uuid;
         private readonly Scene m_scene;
         private readonly UUID m_ownerID;
 
@@ -71,6 +71,19 @@ namespace OpenSim.Region.OptionalModules.World.NPC
             m_firstname = firstname;
             m_lastname = lastname;
             m_startPos = position;
+            m_uuid = UUID.Random();
+            m_scene = scene;
+            m_ownerID = ownerID;
+            SenseAsAgent = senseAsAgent;
+        }
+
+        public NPCAvatar(
+            string firstname, string lastname, UUID agentID, Vector3 position, UUID ownerID, bool senseAsAgent, Scene scene)
+        {
+            m_firstname = firstname;
+            m_lastname = lastname;
+            m_startPos = position;
+            m_uuid = agentID;
             m_scene = scene;
             m_ownerID = ownerID;
             SenseAsAgent = senseAsAgent;

+ 24 - 2
OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs

@@ -140,8 +140,30 @@ namespace OpenSim.Region.OptionalModules.World.NPC
                 Vector3 position, UUID owner, bool senseAsAgent, Scene scene,
                 AvatarAppearance appearance)
         {
-            NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position,
-                    owner, senseAsAgent, scene);
+            return CreateNPC(firstname, lastname, position, UUID.Zero, owner, senseAsAgent, scene, appearance);
+        }
+
+        public UUID CreateNPC(string firstname, string lastname,
+                Vector3 position, UUID agentID, UUID owner, bool senseAsAgent, Scene scene,
+                AvatarAppearance appearance)
+        {
+            NPCAvatar npcAvatar = null;
+
+            try
+            {
+                if (agentID == UUID.Zero)
+                    npcAvatar = new NPCAvatar(firstname, lastname, position,
+                            owner, senseAsAgent, scene);
+                else
+                    npcAvatar = new NPCAvatar(firstname, lastname, agentID, position,
+                        owner, senseAsAgent, scene);
+            }
+            catch (Exception e)
+            {
+                m_log.Info("[NPC MODULE]: exception creating NPC avatar: " + e.ToString());
+                return UUID.Zero;
+            }
+
             npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
                     int.MaxValue);