diff options
Diffstat (limited to '')
6 files changed, 89 insertions, 41 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/INPCModule.cs b/OpenSim/Region/Framework/Interfaces/INPCModule.cs index 08b973d..5e5c4a1 100644 --- a/OpenSim/Region/Framework/Interfaces/INPCModule.cs +++ b/OpenSim/Region/Framework/Interfaces/INPCModule.cs | |||
@@ -40,9 +40,9 @@ namespace OpenSim.Region.Framework.Interfaces | |||
40 | /// <param name="lastname"></param> | 40 | /// <param name="lastname"></param> |
41 | /// <param name="position"></param> | 41 | /// <param name="position"></param> |
42 | /// <param name="scene"></param> | 42 | /// <param name="scene"></param> |
43 | /// <param name="cloneAppearanceFrom">The UUID of the avatar from which to clone the NPC's appearance from.</param> | 43 | /// <param name="appearance">The avatar appearance to use for the new NPC.</param> |
44 | /// <returns>The UUID of the ScenePresence created.</returns> | 44 | /// <returns>The UUID of the ScenePresence created.</returns> |
45 | UUID CreateNPC(string firstname, string lastname, Vector3 position, Scene scene, UUID cloneAppearanceFrom); | 45 | UUID CreateNPC(string firstname, string lastname, Vector3 position, Scene scene, AvatarAppearance appearance); |
46 | 46 | ||
47 | /// <summary> | 47 | /// <summary> |
48 | /// Check if the agent is an NPC. | 48 | /// Check if the agent is an NPC. |
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 580d7ef..c764c20 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | |||
@@ -45,7 +45,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
46 | 46 | ||
47 | private Dictionary<UUID, NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); | 47 | private Dictionary<UUID, NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); |
48 | private Dictionary<UUID, AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>(); | ||
49 | 48 | ||
50 | public void Initialise(Scene scene, IConfigSource source) | 49 | public void Initialise(Scene scene, IConfigSource source) |
51 | { | 50 | { |
@@ -124,28 +123,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
124 | } | 123 | } |
125 | } | 124 | } |
126 | 125 | ||
127 | private AvatarAppearance GetAppearance(UUID target, Scene scene) | ||
128 | { | ||
129 | if (m_appearanceCache.ContainsKey(target)) | ||
130 | return m_appearanceCache[target]; | ||
131 | |||
132 | ScenePresence originalPresence = scene.GetScenePresence(target); | ||
133 | |||
134 | if (originalPresence != null) | ||
135 | { | ||
136 | AvatarAppearance originalAppearance = originalPresence.Appearance; | ||
137 | m_appearanceCache.Add(target, originalAppearance); | ||
138 | return originalAppearance; | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | m_log.DebugFormat( | ||
143 | "[NPC MODULE]: Avatar {0} is not in the scene for us to grab baked textures from them. Using defaults.", target); | ||
144 | |||
145 | return new AvatarAppearance(); | ||
146 | } | ||
147 | } | ||
148 | |||
149 | public bool IsNPC(UUID agentId, Scene scene) | 126 | public bool IsNPC(UUID agentId, Scene scene) |
150 | { | 127 | { |
151 | ScenePresence sp = scene.GetScenePresence(agentId); | 128 | ScenePresence sp = scene.GetScenePresence(agentId); |
@@ -176,7 +153,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
176 | return true; | 153 | return true; |
177 | } | 154 | } |
178 | 155 | ||
179 | public UUID CreateNPC(string firstname, string lastname, Vector3 position, Scene scene, UUID cloneAppearanceFrom) | 156 | public UUID CreateNPC( |
157 | string firstname, string lastname, Vector3 position, Scene scene, AvatarAppearance appearance) | ||
180 | { | 158 | { |
181 | NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, scene); | 159 | NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, scene); |
182 | npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); | 160 | npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); |
@@ -191,8 +169,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
191 | acd.lastname = lastname; | 169 | acd.lastname = lastname; |
192 | acd.ServiceURLs = new Dictionary<string, object>(); | 170 | acd.ServiceURLs = new Dictionary<string, object>(); |
193 | 171 | ||
194 | AvatarAppearance originalAppearance = GetAppearance(cloneAppearanceFrom, scene); | 172 | AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); |
195 | AvatarAppearance npcAppearance = new AvatarAppearance(originalAppearance, true); | ||
196 | acd.Appearance = npcAppearance; | 173 | acd.Appearance = npcAppearance; |
197 | 174 | ||
198 | // for (int i = 0; i < acd.Appearance.Texture.FaceTextures.Length; i++) | 175 | // for (int i = 0; i < acd.Appearance.Texture.FaceTextures.Length; i++) |
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index 2742b67..f8afc5a 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs | |||
@@ -59,7 +59,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
59 | AvatarFactoryModule afm = new AvatarFactoryModule(); | 59 | AvatarFactoryModule afm = new AvatarFactoryModule(); |
60 | TestScene scene = SceneHelpers.SetupScene(); | 60 | TestScene scene = SceneHelpers.SetupScene(); |
61 | SceneHelpers.SetupSceneModules(scene, config, afm, new NPCModule()); | 61 | SceneHelpers.SetupSceneModules(scene, config, afm, new NPCModule()); |
62 | IClientAPI originalClient = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)).ControllingClient; | 62 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); |
63 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); | 63 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); |
64 | 64 | ||
65 | // 8 is the index of the first baked texture in AvatarAppearance | 65 | // 8 is the index of the first baked texture in AvatarAppearance |
@@ -72,10 +72,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
72 | // ScenePresence.SendInitialData() to reset our entire appearance. | 72 | // ScenePresence.SendInitialData() to reset our entire appearance. |
73 | scene.AssetService.Store(AssetHelpers.CreateAsset(originalFace8TextureId)); | 73 | scene.AssetService.Store(AssetHelpers.CreateAsset(originalFace8TextureId)); |
74 | 74 | ||
75 | afm.SetAppearanceFromClient(originalClient, originalTe, null); | 75 | afm.SetAppearanceFromClient(sp.ControllingClient, originalTe, null); |
76 | 76 | ||
77 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); | 77 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); |
78 | UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, originalClient.AgentId); | 78 | UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, sp.Appearance); |
79 | 79 | ||
80 | ScenePresence npc = scene.GetScenePresence(npcId); | 80 | ScenePresence npc = scene.GetScenePresence(npcId); |
81 | 81 | ||
@@ -96,12 +96,12 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
96 | 96 | ||
97 | TestScene scene = SceneHelpers.SetupScene(); | 97 | TestScene scene = SceneHelpers.SetupScene(); |
98 | SceneHelpers.SetupSceneModules(scene, config, new NPCModule()); | 98 | SceneHelpers.SetupSceneModules(scene, config, new NPCModule()); |
99 | IClientAPI originalClient = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)).ControllingClient; | 99 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); |
100 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); | 100 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); |
101 | 101 | ||
102 | Vector3 startPos = new Vector3(128, 128, 30); | 102 | Vector3 startPos = new Vector3(128, 128, 30); |
103 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); | 103 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); |
104 | UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, originalClient.AgentId); | 104 | UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance); |
105 | 105 | ||
106 | ScenePresence npc = scene.GetScenePresence(npcId); | 106 | ScenePresence npc = scene.GetScenePresence(npcId); |
107 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); | 107 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 91ac3b7..b18aa3b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -2135,11 +2135,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2135 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | 2135 | INPCModule module = World.RequestModuleInterface<INPCModule>(); |
2136 | if (module != null) | 2136 | if (module != null) |
2137 | { | 2137 | { |
2138 | ScenePresence clonePresence = World.GetScenePresence(new UUID(cloneFrom.m_string)); | ||
2139 | if (clonePresence == null) | ||
2140 | return new LSL_Key(UUID.Zero.ToString()); | ||
2141 | |||
2138 | UUID x = module.CreateNPC(firstname, | 2142 | UUID x = module.CreateNPC(firstname, |
2139 | lastname, | 2143 | lastname, |
2140 | new Vector3((float) position.x, (float) position.y, (float) position.z), | 2144 | new Vector3((float) position.x, (float) position.y, (float) position.z), |
2141 | World, | 2145 | World, |
2142 | new UUID(cloneFrom)); | 2146 | clonePresence.Appearance); |
2143 | 2147 | ||
2144 | return new LSL_Key(x.ToString()); | 2148 | return new LSL_Key(x.ToString()); |
2145 | } | 2149 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs index 2218a1f..7f778d7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs | |||
@@ -27,7 +27,9 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Reflection; | ||
30 | using System.Text; | 31 | using System.Text; |
32 | using log4net; | ||
31 | using Nini.Config; | 33 | using Nini.Config; |
32 | using NUnit.Framework; | 34 | using NUnit.Framework; |
33 | using OpenMetaverse; | 35 | using OpenMetaverse; |
@@ -35,6 +37,7 @@ using OpenMetaverse.Assets; | |||
35 | using OpenMetaverse.StructuredData; | 37 | using OpenMetaverse.StructuredData; |
36 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
37 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; | 39 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; |
40 | using OpenSim.Region.OptionalModules.World.NPC; | ||
38 | using OpenSim.Region.Framework.Scenes; | 41 | using OpenSim.Region.Framework.Scenes; |
39 | using OpenSim.Region.ScriptEngine.Shared; | 42 | using OpenSim.Region.ScriptEngine.Shared; |
40 | using OpenSim.Region.ScriptEngine.Shared.Api; | 43 | using OpenSim.Region.ScriptEngine.Shared.Api; |
@@ -61,9 +64,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
61 | config.Set("Enabled", "true"); | 64 | config.Set("Enabled", "true"); |
62 | config.Set("AllowOSFunctions", "true"); | 65 | config.Set("AllowOSFunctions", "true"); |
63 | config.Set("OSFunctionThreatLevel", "Severe"); | 66 | config.Set("OSFunctionThreatLevel", "Severe"); |
67 | config = initConfigSource.AddConfig("NPC"); | ||
68 | config.Set("Enabled", "true"); | ||
64 | 69 | ||
65 | m_scene = SceneHelpers.SetupScene(); | 70 | m_scene = SceneHelpers.SetupScene(); |
66 | SceneHelpers.SetupSceneModules(m_scene, new AvatarFactoryModule()); | 71 | SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule()); |
67 | 72 | ||
68 | m_engine = new XEngine.XEngine(); | 73 | m_engine = new XEngine.XEngine(); |
69 | m_engine.Initialise(initConfigSource); | 74 | m_engine.Initialise(initConfigSource); |
@@ -73,12 +78,72 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
73 | /// <summary> | 78 | /// <summary> |
74 | /// Test creation of an NPC where the appearance data comes from a notecard | 79 | /// Test creation of an NPC where the appearance data comes from a notecard |
75 | /// </summary> | 80 | /// </summary> |
76 | // [Test] | 81 | //[Test] |
77 | // public void TestOsNpcCreateFromNotecard() | 82 | public void TestOsNpcCreateFromNotecard() |
78 | // { | 83 | { |
79 | // TestHelpers.InMethod(); | 84 | TestHelpers.InMethod(); |
80 | //// log4net.Config.XmlConfigurator.Configure(); | 85 | log4net.Config.XmlConfigurator.Configure(); |
81 | // } | 86 | |
87 | // Store an avatar with a different height from default in a notecard. | ||
88 | UUID userId = TestHelpers.ParseTail(0x1); | ||
89 | float newHeight = 1.9f; | ||
90 | |||
91 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
92 | sp.Appearance.AvatarHeight = newHeight; | ||
93 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); | ||
94 | SceneObjectPart part = so.RootPart; | ||
95 | m_scene.AddSceneObject(so); | ||
96 | |||
97 | OSSL_Api osslApi = new OSSL_Api(); | ||
98 | osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); | ||
99 | |||
100 | string notecardName = "appearanceNc"; | ||
101 | osslApi.osOwnerSaveAppearance(notecardName); | ||
102 | |||
103 | // Try creating a bot using the appearance in the notecard. | ||
104 | string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName); | ||
105 | Assert.That(npcRaw, Is.Not.Null); | ||
106 | |||
107 | UUID npcId = new UUID(npcRaw); | ||
108 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
109 | Assert.That(npc, Is.Not.Null); | ||
110 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight)); | ||
111 | } | ||
112 | |||
113 | /// <summary> | ||
114 | /// Test creation of an NPC where the appearance data comes from an avatar already in the region. | ||
115 | /// </summary> | ||
116 | [Test] | ||
117 | public void TestOsNpcCreateFromAvatar() | ||
118 | { | ||
119 | TestHelpers.InMethod(); | ||
120 | // log4net.Config.XmlConfigurator.Configure(); | ||
121 | |||
122 | // Store an avatar with a different height from default in a notecard. | ||
123 | UUID userId = TestHelpers.ParseTail(0x1); | ||
124 | float newHeight = 1.9f; | ||
125 | |||
126 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
127 | sp.Appearance.AvatarHeight = newHeight; | ||
128 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); | ||
129 | SceneObjectPart part = so.RootPart; | ||
130 | m_scene.AddSceneObject(so); | ||
131 | |||
132 | OSSL_Api osslApi = new OSSL_Api(); | ||
133 | osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); | ||
134 | |||
135 | string notecardName = "appearanceNc"; | ||
136 | osslApi.osOwnerSaveAppearance(notecardName); | ||
137 | |||
138 | // Try creating a bot using the existing avatar's appearance | ||
139 | string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), sp.UUID.ToString()); | ||
140 | Assert.That(npcRaw, Is.Not.Null); | ||
141 | |||
142 | UUID npcId = new UUID(npcRaw); | ||
143 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
144 | Assert.That(npc, Is.Not.Null); | ||
145 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight)); | ||
146 | } | ||
82 | 147 | ||
83 | [Test] | 148 | [Test] |
84 | public void TestOsOwnerSaveAppearance() | 149 | public void TestOsOwnerSaveAppearance() |
diff --git a/prebuild.xml b/prebuild.xml index dff54a3..411ceb0 100644 --- a/prebuild.xml +++ b/prebuild.xml | |||
@@ -3143,11 +3143,13 @@ | |||
3143 | <Reference name="OpenSim.Framework.Communications"/> | 3143 | <Reference name="OpenSim.Framework.Communications"/> |
3144 | <Reference name="OpenSim.Region.CoreModules"/> | 3144 | <Reference name="OpenSim.Region.CoreModules"/> |
3145 | <Reference name="OpenSim.Region.Framework"/> | 3145 | <Reference name="OpenSim.Region.Framework"/> |
3146 | <Reference name="OpenSim.Region.OptionalModules"/> | ||
3146 | <Reference name="OpenSim.Region.ScriptEngine.Shared"/> | 3147 | <Reference name="OpenSim.Region.ScriptEngine.Shared"/> |
3147 | <Reference name="OpenSim.Region.ScriptEngine.Shared.Api"/> | 3148 | <Reference name="OpenSim.Region.ScriptEngine.Shared.Api"/> |
3148 | <Reference name="OpenSim.Region.ScriptEngine.XEngine"/> | 3149 | <Reference name="OpenSim.Region.ScriptEngine.XEngine"/> |
3149 | <Reference name="OpenSim.Services.Interfaces"/> | 3150 | <Reference name="OpenSim.Services.Interfaces"/> |
3150 | <Reference name="OpenSim.Tests.Common"/> | 3151 | <Reference name="OpenSim.Tests.Common"/> |
3152 | <Reference name="log4net"/> | ||
3151 | <Reference name="nunit.framework" path="../../../bin/"/> | 3153 | <Reference name="nunit.framework" path="../../../bin/"/> |
3152 | <Reference name="Nini" path="../../../bin/"/> | 3154 | <Reference name="Nini" path="../../../bin/"/> |
3153 | <Reference name="OpenMetaverse" path="../../../bin/"/> | 3155 | <Reference name="OpenMetaverse" path="../../../bin/"/> |