29 using System.Collections.Generic;
30 using System.Reflection;
33 using NUnit.Framework;
35 using OpenSim.Framework;
36 using OpenSim.Region.CoreModules.Avatar.Attachments;
37 using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
38 using OpenSim.Region.CoreModules.Framework.InventoryAccess;
39 using OpenSim.Region.CoreModules.Framework.UserManagement;
40 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar;
41 using OpenSim.Region.Framework.Interfaces;
42 using OpenSim.Region.Framework.Scenes;
43 using OpenSim.Services.AvatarService;
44 using OpenSim.Tests.Common;
61 Util.FireAndForgetMethod = FireAndForgetMethod.None;
69 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
79 IConfigSource config =
new IniConfigSource();
80 config.AddConfig(
"NPC");
81 config.Configs[
"NPC"].Set(
"Enabled",
"true");
82 config.AddConfig(
"Modules");
83 config.Configs[
"Modules"].Set(
"InventoryAccessModule",
"BasicInventoryAccessModule");
90 m_scene =
new SceneHelpers().SetupScene(
"test scene", UUID.Random(), 1000, 1000, sizeX, sizeY, config);
97 TestHelpers.InMethod();
102 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
106 UUID originalFace8TextureId = TestHelpers.ParseTail(0x10);
107 Primitive.TextureEntry originalTe =
new Primitive.TextureEntry(UUID.Zero);
108 Primitive.TextureEntryFace originalTef = originalTe.CreateFace(8);
109 originalTef.TextureID = originalFace8TextureId;
113 m_scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId));
117 UUID npcId = m_npcMod.CreateNPC(
"John",
"Smith",
new Vector3(128, 128, 30), UUID.Zero,
true, m_scene, sp.Appearance);
121 Assert.That(npc, Is.Not.Null);
122 Assert.That(npc.Appearance.Texture.FaceTextures[8].TextureID, Is.EqualTo(originalFace8TextureId));
123 Assert.That(m_umMod.GetUserName(npc.UUID), Is.EqualTo(
string.Format(
"{0} {1}", npc.Firstname, npc.Lastname)));
126 Assert.That(m_scene.TryGetClient(npcId, out client), Is.True);
129 Assert.That(m_scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(2));
135 TestHelpers.InMethod();
140 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
143 Vector3 startPos =
new Vector3(128, 128, 30);
144 UUID npcId = m_npcMod.CreateNPC(
"John",
"Smith", startPos, UUID.Zero,
true, m_scene, sp.Appearance);
146 m_npcMod.DeleteNPC(npcId, m_scene);
150 Assert.That(deletedNpc, Is.Null);
152 Assert.That(m_scene.TryGetClient(npcId, out client), Is.False);
155 Assert.That(m_scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
161 TestHelpers.InMethod();
166 UUID userId = TestHelpers.ParseTail(0x1);
167 UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
168 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
170 UUID attItemId = TestHelpers.ParseTail(0x2);
171 UUID attAssetId = TestHelpers.ParseTail(0x3);
172 string attName =
"att";
174 UserInventoryHelpers.CreateInventoryItem(m_scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object);
176 m_attMod.RezSingleAttachmentFromInventory(sp, attItemId, (uint)
AttachmentPoint.Chest);
178 UUID npcId = m_npcMod.CreateNPC(
"John",
"Smith",
new Vector3(128, 128, 30), UUID.Zero,
true, m_scene, sp.Appearance);
183 Assert.That(npc.HasAttachments(), Is.True);
184 List<SceneObjectGroup> attachments = npc.GetAttachments();
185 Assert.That(attachments.Count, Is.EqualTo(1));
192 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)
AttachmentPoint.Chest));
193 Assert.That(attSo.IsAttachment);
194 Assert.That(attSo.UsesPhysics, Is.False);
195 Assert.That(attSo.IsTemporary, Is.False);
196 Assert.That(attSo.OwnerID, Is.EqualTo(npc.UUID));
202 TestHelpers.InMethod();
208 UUID userId = TestHelpers.ParseTail(0x1);
209 UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
210 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
213 = UserInventoryHelpers.CreateInventoryItem(
214 m_scene,
"att1", TestHelpers.ParseTail(0x2),
TestHelpers.
ParseTail(0x3), sp.UUID, InventoryType.Object);
216 = UserInventoryHelpers.CreateInventoryItem(
217 m_scene,
"att2", TestHelpers.ParseTail(0x12),
TestHelpers.
ParseTail(0x13), sp.UUID, InventoryType.Object);
219 m_attMod.RezSingleAttachmentFromInventory(sp, att1Item.ID, (uint)
AttachmentPoint.Chest);
220 m_attMod.RezSingleAttachmentFromInventory(sp, att2Item.ID, (uint)
AttachmentPoint.Chest | 0x80);
222 UUID npcId = m_npcMod.CreateNPC(
"John",
"Smith",
new Vector3(128, 128, 30), UUID.Zero,
true, m_scene, sp.Appearance);
227 Assert.That(npc.HasAttachments(), Is.True);
228 List<SceneObjectGroup> attachments = npc.GetAttachments();
229 Assert.That(attachments.Count, Is.EqualTo(2));
240 Assert.AreNotEqual(attachments[0].FromItemID, attachments[1].FromItemID);
243 private void TestAttachedObject(
SceneObjectGroup attSo, AttachmentPoint attPoint, UUID ownerId)
245 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)attPoint));
246 Assert.That(attSo.IsAttachment);
247 Assert.That(attSo.UsesPhysics, Is.False);
248 Assert.That(attSo.IsTemporary, Is.False);
249 Assert.That(attSo.OwnerID, Is.EqualTo(ownerId));
255 TestHelpers.InMethod();
260 UUID userId = TestHelpers.ParseTail(0x1);
261 UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
262 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
264 UUID npcId = m_npcMod.CreateNPC(
"John",
"Smith",
new Vector3(128, 128, 30), UUID.Zero,
true, m_scene, sp.Appearance);
268 UUID attItemId = TestHelpers.ParseTail(0x2);
269 UUID attAssetId = TestHelpers.ParseTail(0x3);
270 string attName =
"att";
272 UserInventoryHelpers.CreateInventoryItem(m_scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object);
274 m_attMod.RezSingleAttachmentFromInventory(sp, attItemId, (uint)
AttachmentPoint.Chest);
276 m_npcMod.SetNPCAppearance(npcId, sp.Appearance, m_scene);
281 Assert.That(npc.HasAttachments(), Is.True);
282 List<SceneObjectGroup> attachments = npc.GetAttachments();
283 Assert.That(attachments.Count, Is.EqualTo(1));
290 Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)
AttachmentPoint.Chest));
291 Assert.That(attSo.IsAttachment);
292 Assert.That(attSo.UsesPhysics, Is.False);
293 Assert.That(attSo.IsTemporary, Is.False);
294 Assert.That(attSo.OwnerID, Is.EqualTo(npc.UUID));
300 TestHelpers.InMethod();
305 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
308 Vector3 startPos =
new Vector3(128, 128, 30);
309 UUID npcId = m_npcMod.CreateNPC(
"John",
"Smith", startPos, UUID.Zero,
true, m_scene, sp.Appearance);
312 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
318 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
320 Vector3 targetPos = startPos +
new Vector3(0, 10, 0);
321 m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos,
false,
false,
false);
323 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
331 Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X));
332 Assert.That(npc.AbsolutePosition.Y, Is.GreaterThan(startPos.Y));
333 Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
334 Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.X));
338 double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
339 Assert.That(distanceToTarget, Is.LessThan(1),
"NPC not within 1 unit of target position on first move");
340 Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
341 Assert.That(npc.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE));
344 startPos = npc.AbsolutePosition;
345 targetPos = startPos +
new Vector3(10, 0, 0);
346 m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos,
false,
false,
false);
348 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
356 Assert.That(npc.AbsolutePosition.X, Is.GreaterThan(startPos.X));
357 Assert.That(npc.AbsolutePosition.X, Is.LessThan(targetPos.X));
358 Assert.That(npc.AbsolutePosition.Y, Is.EqualTo(startPos.Y));
359 Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
363 distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
364 Assert.That(distanceToTarget, Is.LessThan(1),
"NPC not within 1 unit of target position on second move");
365 Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
371 TestHelpers.InMethod();
374 SetUpScene(512, 512);
376 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
379 Vector3 startPos =
new Vector3(128, 246, 30);
380 UUID npcId = m_npcMod.CreateNPC(
"John",
"Smith", startPos, UUID.Zero,
true, m_scene, sp.Appearance);
383 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
389 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
391 Vector3 targetPos = startPos +
new Vector3(0, 20, 0);
392 m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos,
false,
false,
false);
394 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
402 Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X));
403 Assert.That(npc.AbsolutePosition.Y, Is.GreaterThan(startPos.Y));
404 Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
405 Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.X));
407 for (
int i = 0; i < 20; i++)
413 double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
414 Assert.That(distanceToTarget, Is.LessThan(1),
"NPC not within 1 unit of target position on first move");
415 Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
416 Assert.That(npc.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE));
422 TestHelpers.InMethod();
427 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
429 Vector3 startPos =
new Vector3(128, 128, 30);
430 UUID npcId = m_npcMod.CreateNPC(
"John",
"Smith", startPos, UUID.Zero,
true, m_scene, sp.Appearance);
435 part.SitTargetPosition =
new Vector3(0, 0, 1);
436 m_npcMod.Sit(npc.UUID, part.UUID, m_scene);
438 Assert.That(part.SitTargetAvatar, Is.EqualTo(npcId));
439 Assert.That(npc.ParentID, Is.EqualTo(part.LocalId));
444 m_npcMod.Stand(npc.UUID, m_scene);
446 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
447 Assert.That(npc.ParentID, Is.EqualTo(0));
453 TestHelpers.InMethod();
458 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
462 Vector3 startPos =
new Vector3(1, 1, 1);
464 UUID npcId = m_npcMod.CreateNPC(
"John",
"Smith", startPos, UUID.Zero,
true, m_scene, sp.Appearance);
469 m_npcMod.Sit(npc.UUID, part.UUID, m_scene);
471 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
472 Assert.That(npc.ParentID, Is.EqualTo(part.LocalId));
477 npc.AbsolutePosition,
478 Is.EqualTo(part.AbsolutePosition +
new Vector3(0, 0, sp.
PhysicsActor.Size.Z / 2)));
480 m_npcMod.Stand(npc.UUID, m_scene);
482 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
483 Assert.That(npc.ParentID, Is.EqualTo(0));
void TestSitAndStandWithSitTarget()
PhysicsActor PhysicsActor
Physical scene representation of this Avatar.
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
void TestLoadAppearance()
void TestCreateWithAttachments()
static UUID ParseTail(int tail)
Parse tail section into full UUID.
void SetUpScene(uint sizeX, uint sizeY)
void TestSitAndStandWithNoSitTarget()
Inventory Item - contains all the properties associated with an individual inventory piece...
Helpers for setting up scenes.
Interactive OpenSim region server
void TestMoveInVarRegion()
void TestCreateWithMultiAttachments()