clockwerk-opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ |
||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions are met: |
||
7 | * * Redistributions of source code must retain the above copyright |
||
8 | * notice, this list of conditions and the following disclaimer. |
||
9 | * * Redistributions in binary form must reproduce the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer in the |
||
11 | * documentation and/or other materials provided with the distribution. |
||
12 | * * Neither the name of the OpenSimulator Project nor the |
||
13 | * names of its contributors may be used to endorse or promote products |
||
14 | * derived from this software without specific prior written permission. |
||
15 | * |
||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
26 | */ |
||
27 | |||
28 | using System; |
||
29 | using System.Collections.Generic; |
||
30 | using System.Reflection; |
||
31 | using log4net; |
||
32 | using Nini.Config; |
||
33 | using NUnit.Framework; |
||
34 | using OpenMetaverse; |
||
35 | using OpenSim.Framework; |
||
36 | using OpenSim.Framework.Communications; |
||
37 | using OpenSim.Region.CoreModules.Avatar.Attachments; |
||
38 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; |
||
39 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; |
||
40 | using OpenSim.Region.CoreModules.Framework.UserManagement; |
||
41 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar; |
||
42 | using OpenSim.Region.Framework.Interfaces; |
||
43 | using OpenSim.Region.Framework.Scenes; |
||
44 | using OpenSim.Services.AvatarService; |
||
45 | using OpenSim.Tests.Common; |
||
46 | using OpenSim.Tests.Common.Mock; |
||
47 | |||
48 | namespace OpenSim.Region.OptionalModules.World.NPC.Tests |
||
49 | { |
||
50 | [TestFixture] |
||
51 | public class NPCModuleTests : OpenSimTestCase |
||
52 | { |
||
53 | private TestScene m_scene; |
||
54 | private AvatarFactoryModule m_afMod; |
||
55 | private UserManagementModule m_umMod; |
||
56 | private AttachmentsModule m_attMod; |
||
57 | private NPCModule m_npcMod; |
||
58 | |||
59 | [TestFixtureSetUp] |
||
60 | public void FixtureInit() |
||
61 | { |
||
62 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. |
||
63 | Util.FireAndForgetMethod = FireAndForgetMethod.None; |
||
64 | } |
||
65 | |||
66 | [TestFixtureTearDown] |
||
67 | public void TearDown() |
||
68 | { |
||
69 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple |
||
70 | // threads. Possibly, later tests should be rewritten not to worry about such things. |
||
71 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; |
||
72 | } |
||
73 | |||
74 | public void SetUpScene() |
||
75 | { |
||
76 | SetUpScene(256, 256); |
||
77 | } |
||
78 | |||
79 | public void SetUpScene(uint sizeX, uint sizeY) |
||
80 | { |
||
81 | IConfigSource config = new IniConfigSource(); |
||
82 | config.AddConfig("NPC"); |
||
83 | config.Configs["NPC"].Set("Enabled", "true"); |
||
84 | config.AddConfig("Modules"); |
||
85 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); |
||
86 | |||
87 | m_afMod = new AvatarFactoryModule(); |
||
88 | m_umMod = new UserManagementModule(); |
||
89 | m_attMod = new AttachmentsModule(); |
||
90 | m_npcMod = new NPCModule(); |
||
91 | |||
92 | m_scene = new SceneHelpers().SetupScene("test scene", UUID.Random(), 1000, 1000, sizeX, sizeY, config); |
||
93 | SceneHelpers.SetupSceneModules(m_scene, config, m_afMod, m_umMod, m_attMod, m_npcMod, new BasicInventoryAccessModule()); |
||
94 | } |
||
95 | |||
96 | [Test] |
||
97 | public void TestCreate() |
||
98 | { |
||
99 | TestHelpers.InMethod(); |
||
100 | // log4net.Config.XmlConfigurator.Configure(); |
||
101 | |||
102 | SetUpScene(); |
||
103 | |||
104 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); |
||
105 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); |
||
106 | |||
107 | // 8 is the index of the first baked texture in AvatarAppearance |
||
108 | UUID originalFace8TextureId = TestHelpers.ParseTail(0x10); |
||
109 | Primitive.TextureEntry originalTe = new Primitive.TextureEntry(UUID.Zero); |
||
110 | Primitive.TextureEntryFace originalTef = originalTe.CreateFace(8); |
||
111 | originalTef.TextureID = originalFace8TextureId; |
||
112 | |||
113 | // We also need to add the texture to the asset service, otherwise the AvatarFactoryModule will tell |
||
114 | // ScenePresence.SendInitialData() to reset our entire appearance. |
||
115 | m_scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId)); |
||
116 | |||
117 | m_afMod.SetAppearance(sp, originalTe, null, null); |
||
118 | |||
119 | UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance); |
||
120 | |||
121 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
122 | |||
123 | Assert.That(npc, Is.Not.Null); |
||
124 | Assert.That(npc.Appearance.Texture.FaceTextures[8].TextureID, Is.EqualTo(originalFace8TextureId)); |
||
125 | Assert.That(m_umMod.GetUserName(npc.UUID), Is.EqualTo(string.Format("{0} {1}", npc.Firstname, npc.Lastname))); |
||
126 | |||
127 | IClientAPI client; |
||
128 | Assert.That(m_scene.TryGetClient(npcId, out client), Is.True); |
||
129 | |||
130 | // Have to account for both SP and NPC. |
||
131 | Assert.That(m_scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(2)); |
||
132 | } |
||
133 | |||
134 | [Test] |
||
135 | public void TestRemove() |
||
136 | { |
||
137 | TestHelpers.InMethod(); |
||
138 | // log4net.Config.XmlConfigurator.Configure(); |
||
139 | |||
140 | SetUpScene(); |
||
141 | |||
142 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); |
||
143 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); |
||
144 | |||
145 | Vector3 startPos = new Vector3(128, 128, 30); |
||
146 | UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance); |
||
147 | |||
148 | m_npcMod.DeleteNPC(npcId, m_scene); |
||
149 | |||
150 | ScenePresence deletedNpc = m_scene.GetScenePresence(npcId); |
||
151 | |||
152 | Assert.That(deletedNpc, Is.Null); |
||
153 | IClientAPI client; |
||
154 | Assert.That(m_scene.TryGetClient(npcId, out client), Is.False); |
||
155 | |||
156 | // Have to account for SP still present. |
||
157 | Assert.That(m_scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1)); |
||
158 | } |
||
159 | |||
160 | [Test] |
||
161 | public void TestCreateWithAttachments() |
||
162 | { |
||
163 | TestHelpers.InMethod(); |
||
164 | // TestHelpers.EnableLogging(); |
||
165 | |||
166 | SetUpScene(); |
||
167 | |||
168 | UUID userId = TestHelpers.ParseTail(0x1); |
||
169 | UserAccountHelpers.CreateUserWithInventory(m_scene, userId); |
||
170 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); |
||
171 | |||
172 | UUID attItemId = TestHelpers.ParseTail(0x2); |
||
173 | UUID attAssetId = TestHelpers.ParseTail(0x3); |
||
174 | string attName = "att"; |
||
175 | |||
176 | UserInventoryHelpers.CreateInventoryItem(m_scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object); |
||
177 | |||
178 | m_attMod.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest); |
||
179 | |||
180 | UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance); |
||
181 | |||
182 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
183 | |||
184 | // Check scene presence status |
||
185 | Assert.That(npc.HasAttachments(), Is.True); |
||
186 | List<SceneObjectGroup> attachments = npc.GetAttachments(); |
||
187 | Assert.That(attachments.Count, Is.EqualTo(1)); |
||
188 | SceneObjectGroup attSo = attachments[0]; |
||
189 | |||
190 | // Just for now, we won't test the name since this is (wrongly) the asset part name rather than the item |
||
191 | // name. TODO: Do need to fix ultimately since the item may be renamed before being passed on to an NPC. |
||
192 | // Assert.That(attSo.Name, Is.EqualTo(attName)); |
||
193 | |||
194 | Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); |
||
195 | Assert.That(attSo.IsAttachment); |
||
196 | Assert.That(attSo.UsesPhysics, Is.False); |
||
197 | Assert.That(attSo.IsTemporary, Is.False); |
||
198 | Assert.That(attSo.OwnerID, Is.EqualTo(npc.UUID)); |
||
199 | } |
||
200 | |||
201 | [Test] |
||
202 | public void TestCreateWithMultiAttachments() |
||
203 | { |
||
204 | TestHelpers.InMethod(); |
||
205 | // TestHelpers.EnableLogging(); |
||
206 | |||
207 | SetUpScene(); |
||
208 | // m_attMod.DebugLevel = 1; |
||
209 | |||
210 | UUID userId = TestHelpers.ParseTail(0x1); |
||
211 | UserAccountHelpers.CreateUserWithInventory(m_scene, userId); |
||
212 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); |
||
213 | |||
214 | InventoryItemBase att1Item |
||
215 | = UserInventoryHelpers.CreateInventoryItem( |
||
216 | m_scene, "att1", TestHelpers.ParseTail(0x2), TestHelpers.ParseTail(0x3), sp.UUID, InventoryType.Object); |
||
217 | InventoryItemBase att2Item |
||
218 | = UserInventoryHelpers.CreateInventoryItem( |
||
219 | m_scene, "att2", TestHelpers.ParseTail(0x12), TestHelpers.ParseTail(0x13), sp.UUID, InventoryType.Object); |
||
220 | |||
221 | m_attMod.RezSingleAttachmentFromInventory(sp, att1Item.ID, (uint)AttachmentPoint.Chest); |
||
222 | m_attMod.RezSingleAttachmentFromInventory(sp, att2Item.ID, (uint)AttachmentPoint.Chest | 0x80); |
||
223 | |||
224 | UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance); |
||
225 | |||
226 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
227 | |||
228 | // Check scene presence status |
||
229 | Assert.That(npc.HasAttachments(), Is.True); |
||
230 | List<SceneObjectGroup> attachments = npc.GetAttachments(); |
||
231 | Assert.That(attachments.Count, Is.EqualTo(2)); |
||
232 | |||
233 | // Just for now, we won't test the name since this is (wrongly) the asset part name rather than the item |
||
234 | // name. TODO: Do need to fix ultimately since the item may be renamed before being passed on to an NPC. |
||
235 | // Assert.That(attSo.Name, Is.EqualTo(attName)); |
||
236 | |||
237 | TestAttachedObject(attachments[0], AttachmentPoint.Chest, npc.UUID); |
||
238 | TestAttachedObject(attachments[1], AttachmentPoint.Chest, npc.UUID); |
||
239 | |||
240 | // Attached objects on the same point must have different FromItemIDs to be shown to other avatars, at least |
||
241 | // on Singularity 1.8.5. Otherwise, only one (the first ObjectUpdate sent) appears. |
||
242 | Assert.AreNotEqual(attachments[0].FromItemID, attachments[1].FromItemID); |
||
243 | } |
||
244 | |||
245 | private void TestAttachedObject(SceneObjectGroup attSo, AttachmentPoint attPoint, UUID ownerId) |
||
246 | { |
||
247 | Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)attPoint)); |
||
248 | Assert.That(attSo.IsAttachment); |
||
249 | Assert.That(attSo.UsesPhysics, Is.False); |
||
250 | Assert.That(attSo.IsTemporary, Is.False); |
||
251 | Assert.That(attSo.OwnerID, Is.EqualTo(ownerId)); |
||
252 | } |
||
253 | |||
254 | [Test] |
||
255 | public void TestLoadAppearance() |
||
256 | { |
||
257 | TestHelpers.InMethod(); |
||
258 | // log4net.Config.XmlConfigurator.Configure(); |
||
259 | |||
260 | SetUpScene(); |
||
261 | |||
262 | UUID userId = TestHelpers.ParseTail(0x1); |
||
263 | UserAccountHelpers.CreateUserWithInventory(m_scene, userId); |
||
264 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); |
||
265 | |||
266 | UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance); |
||
267 | |||
268 | // Now add the attachment to the original avatar and use that to load a new appearance |
||
269 | // TODO: Could also run tests loading from a notecard though this isn't much different for our purposes here |
||
270 | UUID attItemId = TestHelpers.ParseTail(0x2); |
||
271 | UUID attAssetId = TestHelpers.ParseTail(0x3); |
||
272 | string attName = "att"; |
||
273 | |||
274 | UserInventoryHelpers.CreateInventoryItem(m_scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object); |
||
275 | |||
276 | m_attMod.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest); |
||
277 | |||
278 | m_npcMod.SetNPCAppearance(npcId, sp.Appearance, m_scene); |
||
279 | |||
280 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
281 | |||
282 | // Check scene presence status |
||
283 | Assert.That(npc.HasAttachments(), Is.True); |
||
284 | List<SceneObjectGroup> attachments = npc.GetAttachments(); |
||
285 | Assert.That(attachments.Count, Is.EqualTo(1)); |
||
286 | SceneObjectGroup attSo = attachments[0]; |
||
287 | |||
288 | // Just for now, we won't test the name since this is (wrongly) the asset part name rather than the item |
||
289 | // name. TODO: Do need to fix ultimately since the item may be renamed before being passed on to an NPC. |
||
290 | // Assert.That(attSo.Name, Is.EqualTo(attName)); |
||
291 | |||
292 | Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest)); |
||
293 | Assert.That(attSo.IsAttachment); |
||
294 | Assert.That(attSo.UsesPhysics, Is.False); |
||
295 | Assert.That(attSo.IsTemporary, Is.False); |
||
296 | Assert.That(attSo.OwnerID, Is.EqualTo(npc.UUID)); |
||
297 | } |
||
298 | |||
299 | [Test] |
||
300 | public void TestMove() |
||
301 | { |
||
302 | TestHelpers.InMethod(); |
||
303 | // log4net.Config.XmlConfigurator.Configure(); |
||
304 | |||
305 | SetUpScene(); |
||
306 | |||
307 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); |
||
308 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); |
||
309 | |||
310 | Vector3 startPos = new Vector3(128, 128, 30); |
||
311 | UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance); |
||
312 | |||
313 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
314 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
||
315 | |||
316 | // For now, we'll make the scene presence fly to simplify this test, but this needs to change. |
||
317 | npc.Flying = true; |
||
318 | |||
319 | m_scene.Update(1); |
||
320 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
||
321 | |||
322 | Vector3 targetPos = startPos + new Vector3(0, 10, 0); |
||
323 | m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false); |
||
324 | |||
325 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
||
326 | //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f))); |
||
327 | Assert.That( |
||
328 | npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001)); |
||
329 | |||
330 | m_scene.Update(1); |
||
331 | |||
332 | // We should really check the exact figure. |
||
333 | Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X)); |
||
334 | Assert.That(npc.AbsolutePosition.Y, Is.GreaterThan(startPos.Y)); |
||
335 | Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z)); |
||
336 | Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.X)); |
||
337 | |||
338 | m_scene.Update(10); |
||
339 | |||
340 | double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos); |
||
341 | Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move"); |
||
342 | Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos)); |
||
343 | Assert.That(npc.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE)); |
||
344 | |||
345 | // Try a second movement |
||
346 | startPos = npc.AbsolutePosition; |
||
347 | targetPos = startPos + new Vector3(10, 0, 0); |
||
348 | m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false); |
||
349 | |||
350 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
||
351 | // Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0, 1))); |
||
352 | Assert.That( |
||
353 | npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0, 1), 0.000001)); |
||
354 | |||
355 | m_scene.Update(1); |
||
356 | |||
357 | // We should really check the exact figure. |
||
358 | Assert.That(npc.AbsolutePosition.X, Is.GreaterThan(startPos.X)); |
||
359 | Assert.That(npc.AbsolutePosition.X, Is.LessThan(targetPos.X)); |
||
360 | Assert.That(npc.AbsolutePosition.Y, Is.EqualTo(startPos.Y)); |
||
361 | Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z)); |
||
362 | |||
363 | m_scene.Update(10); |
||
364 | |||
365 | distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos); |
||
366 | Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on second move"); |
||
367 | Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos)); |
||
368 | } |
||
369 | |||
370 | [Test] |
||
371 | public void TestMoveInVarRegion() |
||
372 | { |
||
373 | TestHelpers.InMethod(); |
||
374 | // TestHelpers.EnableLogging(); |
||
375 | |||
376 | SetUpScene(512, 512); |
||
377 | |||
378 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); |
||
379 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); |
||
380 | |||
381 | Vector3 startPos = new Vector3(128, 246, 30); |
||
382 | UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance); |
||
383 | |||
384 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
385 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
||
386 | |||
387 | // For now, we'll make the scene presence fly to simplify this test, but this needs to change. |
||
388 | npc.Flying = true; |
||
389 | |||
390 | m_scene.Update(1); |
||
391 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
||
392 | |||
393 | Vector3 targetPos = startPos + new Vector3(0, 20, 0); |
||
394 | m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false); |
||
395 | |||
396 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
||
397 | //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f))); |
||
398 | Assert.That( |
||
399 | npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001)); |
||
400 | |||
401 | m_scene.Update(1); |
||
402 | |||
403 | // We should really check the exact figure. |
||
404 | Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X)); |
||
405 | Assert.That(npc.AbsolutePosition.Y, Is.GreaterThan(startPos.Y)); |
||
406 | Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z)); |
||
407 | Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.X)); |
||
408 | |||
409 | for (int i = 0; i < 20; i++) |
||
410 | { |
||
411 | m_scene.Update(1); |
||
412 | // Console.WriteLine("pos: {0}", npc.AbsolutePosition); |
||
413 | } |
||
414 | |||
415 | double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos); |
||
416 | Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move"); |
||
417 | Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos)); |
||
418 | Assert.That(npc.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE)); |
||
419 | } |
||
420 | |||
421 | [Test] |
||
422 | public void TestSitAndStandWithSitTarget() |
||
423 | { |
||
424 | TestHelpers.InMethod(); |
||
425 | // log4net.Config.XmlConfigurator.Configure(); |
||
426 | |||
427 | SetUpScene(); |
||
428 | |||
429 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); |
||
430 | |||
431 | Vector3 startPos = new Vector3(128, 128, 30); |
||
432 | UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance); |
||
433 | |||
434 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
435 | SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart; |
||
436 | |||
437 | part.SitTargetPosition = new Vector3(0, 0, 1); |
||
438 | m_npcMod.Sit(npc.UUID, part.UUID, m_scene); |
||
439 | |||
440 | Assert.That(part.SitTargetAvatar, Is.EqualTo(npcId)); |
||
441 | Assert.That(npc.ParentID, Is.EqualTo(part.LocalId)); |
||
442 | // Assert.That( |
||
443 | // npc.AbsolutePosition, |
||
444 | // Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT)); |
||
445 | |||
446 | m_npcMod.Stand(npc.UUID, m_scene); |
||
447 | |||
448 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); |
||
449 | Assert.That(npc.ParentID, Is.EqualTo(0)); |
||
450 | } |
||
451 | |||
452 | [Test] |
||
453 | public void TestSitAndStandWithNoSitTarget() |
||
454 | { |
||
455 | TestHelpers.InMethod(); |
||
456 | // TestHelpers.EnableLogging(); |
||
457 | |||
458 | SetUpScene(); |
||
459 | |||
460 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); |
||
461 | |||
462 | // FIXME: To get this to work for now, we are going to place the npc right next to the target so that |
||
463 | // the autopilot doesn't trigger |
||
464 | Vector3 startPos = new Vector3(1, 1, 1); |
||
465 | |||
466 | UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance); |
||
467 | |||
468 | ScenePresence npc = m_scene.GetScenePresence(npcId); |
||
469 | SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart; |
||
470 | |||
471 | m_npcMod.Sit(npc.UUID, part.UUID, m_scene); |
||
472 | |||
473 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); |
||
474 | Assert.That(npc.ParentID, Is.EqualTo(part.LocalId)); |
||
475 | |||
476 | // We should really be using the NPC size but this would mean preserving the physics actor since it is |
||
477 | // removed on sit. |
||
478 | Assert.That( |
||
479 | npc.AbsolutePosition, |
||
480 | Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, sp.PhysicsActor.Size.Z / 2))); |
||
481 | |||
482 | m_npcMod.Stand(npc.UUID, m_scene); |
||
483 | |||
484 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); |
||
485 | Assert.That(npc.ParentID, Is.EqualTo(0)); |
||
486 | } |
||
487 | } |
||
488 | } |