NPCModuleTests.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using log4net;
  31. using Nini.Config;
  32. using NUnit.Framework;
  33. using OpenMetaverse;
  34. using OpenSim.Framework;
  35. using OpenSim.Framework.Communications;
  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;
  45. namespace OpenSim.Region.OptionalModules.World.NPC.Tests
  46. {
  47. [TestFixture]
  48. public class NPCModuleTests : OpenSimTestCase
  49. {
  50. private TestScene m_scene;
  51. private AvatarFactoryModule m_afMod;
  52. private UserManagementModule m_umMod;
  53. private AttachmentsModule m_attMod;
  54. private NPCModule m_npcMod;
  55. [TestFixtureSetUp]
  56. public void FixtureInit()
  57. {
  58. // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
  59. Util.FireAndForgetMethod = FireAndForgetMethod.None;
  60. }
  61. [TestFixtureTearDown]
  62. public void TearDown()
  63. {
  64. // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
  65. // threads. Possibly, later tests should be rewritten not to worry about such things.
  66. Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
  67. }
  68. public void SetUpScene()
  69. {
  70. SetUpScene(256, 256);
  71. }
  72. public void SetUpScene(uint sizeX, uint sizeY)
  73. {
  74. IConfigSource config = new IniConfigSource();
  75. config.AddConfig("NPC");
  76. config.Configs["NPC"].Set("Enabled", "true");
  77. config.AddConfig("Modules");
  78. config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
  79. m_afMod = new AvatarFactoryModule();
  80. m_umMod = new UserManagementModule();
  81. m_attMod = new AttachmentsModule();
  82. m_npcMod = new NPCModule();
  83. m_scene = new SceneHelpers().SetupScene("test scene", UUID.Random(), 1000, 1000, sizeX, sizeY, config);
  84. SceneHelpers.SetupSceneModules(m_scene, config, m_afMod, m_umMod, m_attMod, m_npcMod, new BasicInventoryAccessModule());
  85. }
  86. [Test]
  87. public void TestCreate()
  88. {
  89. TestHelpers.InMethod();
  90. // log4net.Config.XmlConfigurator.Configure();
  91. SetUpScene();
  92. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
  93. // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
  94. // 8 is the index of the first baked texture in AvatarAppearance
  95. UUID originalFace8TextureId = TestHelpers.ParseTail(0x10);
  96. Primitive.TextureEntry originalTe = new Primitive.TextureEntry(UUID.Zero);
  97. Primitive.TextureEntryFace originalTef = originalTe.CreateFace(8);
  98. originalTef.TextureID = originalFace8TextureId;
  99. // We also need to add the texture to the asset service, otherwise the AvatarFactoryModule will tell
  100. // ScenePresence.SendInitialData() to reset our entire appearance.
  101. m_scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId));
  102. m_afMod.SetAppearance(sp, originalTe, null, null);
  103. UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance);
  104. ScenePresence npc = m_scene.GetScenePresence(npcId);
  105. Assert.That(npc, Is.Not.Null);
  106. Assert.That(npc.Appearance.Texture.FaceTextures[8].TextureID, Is.EqualTo(originalFace8TextureId));
  107. Assert.That(m_umMod.GetUserName(npc.UUID), Is.EqualTo(string.Format("{0} {1}", npc.Firstname, npc.Lastname)));
  108. IClientAPI client;
  109. Assert.That(m_scene.TryGetClient(npcId, out client), Is.True);
  110. // Have to account for both SP and NPC.
  111. Assert.That(m_scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(2));
  112. }
  113. [Test]
  114. public void TestRemove()
  115. {
  116. TestHelpers.InMethod();
  117. // log4net.Config.XmlConfigurator.Configure();
  118. SetUpScene();
  119. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
  120. // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
  121. Vector3 startPos = new Vector3(128, 128, 30);
  122. UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance);
  123. m_npcMod.DeleteNPC(npcId, m_scene);
  124. ScenePresence deletedNpc = m_scene.GetScenePresence(npcId);
  125. Assert.That(deletedNpc, Is.Null);
  126. IClientAPI client;
  127. Assert.That(m_scene.TryGetClient(npcId, out client), Is.False);
  128. // Have to account for SP still present.
  129. Assert.That(m_scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
  130. }
  131. [Test]
  132. public void TestCreateWithAttachments()
  133. {
  134. TestHelpers.InMethod();
  135. // TestHelpers.EnableLogging();
  136. SetUpScene();
  137. UUID userId = TestHelpers.ParseTail(0x1);
  138. UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
  139. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
  140. UUID attItemId = TestHelpers.ParseTail(0x2);
  141. UUID attAssetId = TestHelpers.ParseTail(0x3);
  142. string attName = "att";
  143. UserInventoryHelpers.CreateInventoryItem(m_scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object);
  144. m_attMod.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest);
  145. UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance);
  146. ScenePresence npc = m_scene.GetScenePresence(npcId);
  147. // Check scene presence status
  148. Assert.That(npc.HasAttachments(), Is.True);
  149. List<SceneObjectGroup> attachments = npc.GetAttachments();
  150. Assert.That(attachments.Count, Is.EqualTo(1));
  151. SceneObjectGroup attSo = attachments[0];
  152. // Just for now, we won't test the name since this is (wrongly) the asset part name rather than the item
  153. // name. TODO: Do need to fix ultimately since the item may be renamed before being passed on to an NPC.
  154. // Assert.That(attSo.Name, Is.EqualTo(attName));
  155. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
  156. Assert.That(attSo.IsAttachment);
  157. Assert.That(attSo.UsesPhysics, Is.False);
  158. Assert.That(attSo.IsTemporary, Is.False);
  159. Assert.That(attSo.OwnerID, Is.EqualTo(npc.UUID));
  160. }
  161. [Test]
  162. public void TestCreateWithMultiAttachments()
  163. {
  164. TestHelpers.InMethod();
  165. // TestHelpers.EnableLogging();
  166. SetUpScene();
  167. // m_attMod.DebugLevel = 1;
  168. UUID userId = TestHelpers.ParseTail(0x1);
  169. UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
  170. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
  171. InventoryItemBase att1Item
  172. = UserInventoryHelpers.CreateInventoryItem(
  173. m_scene, "att1", TestHelpers.ParseTail(0x2), TestHelpers.ParseTail(0x3), sp.UUID, InventoryType.Object);
  174. InventoryItemBase att2Item
  175. = UserInventoryHelpers.CreateInventoryItem(
  176. m_scene, "att2", TestHelpers.ParseTail(0x12), TestHelpers.ParseTail(0x13), sp.UUID, InventoryType.Object);
  177. m_attMod.RezSingleAttachmentFromInventory(sp, att1Item.ID, (uint)AttachmentPoint.Chest);
  178. m_attMod.RezSingleAttachmentFromInventory(sp, att2Item.ID, (uint)AttachmentPoint.Chest | 0x80);
  179. UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance);
  180. ScenePresence npc = m_scene.GetScenePresence(npcId);
  181. // Check scene presence status
  182. Assert.That(npc.HasAttachments(), Is.True);
  183. List<SceneObjectGroup> attachments = npc.GetAttachments();
  184. Assert.That(attachments.Count, Is.EqualTo(2));
  185. // Just for now, we won't test the name since this is (wrongly) the asset part name rather than the item
  186. // name. TODO: Do need to fix ultimately since the item may be renamed before being passed on to an NPC.
  187. // Assert.That(attSo.Name, Is.EqualTo(attName));
  188. TestAttachedObject(attachments[0], AttachmentPoint.Chest, npc.UUID);
  189. TestAttachedObject(attachments[1], AttachmentPoint.Chest, npc.UUID);
  190. // Attached objects on the same point must have different FromItemIDs to be shown to other avatars, at least
  191. // on Singularity 1.8.5. Otherwise, only one (the first ObjectUpdate sent) appears.
  192. Assert.AreNotEqual(attachments[0].FromItemID, attachments[1].FromItemID);
  193. }
  194. private void TestAttachedObject(SceneObjectGroup attSo, AttachmentPoint attPoint, UUID ownerId)
  195. {
  196. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)attPoint));
  197. Assert.That(attSo.IsAttachment);
  198. Assert.That(attSo.UsesPhysics, Is.False);
  199. Assert.That(attSo.IsTemporary, Is.False);
  200. Assert.That(attSo.OwnerID, Is.EqualTo(ownerId));
  201. }
  202. [Test]
  203. public void TestLoadAppearance()
  204. {
  205. TestHelpers.InMethod();
  206. // log4net.Config.XmlConfigurator.Configure();
  207. SetUpScene();
  208. UUID userId = TestHelpers.ParseTail(0x1);
  209. UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
  210. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
  211. UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance);
  212. // Now add the attachment to the original avatar and use that to load a new appearance
  213. // TODO: Could also run tests loading from a notecard though this isn't much different for our purposes here
  214. UUID attItemId = TestHelpers.ParseTail(0x2);
  215. UUID attAssetId = TestHelpers.ParseTail(0x3);
  216. string attName = "att";
  217. UserInventoryHelpers.CreateInventoryItem(m_scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object);
  218. m_attMod.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest);
  219. m_npcMod.SetNPCAppearance(npcId, sp.Appearance, m_scene);
  220. ScenePresence npc = m_scene.GetScenePresence(npcId);
  221. // Check scene presence status
  222. Assert.That(npc.HasAttachments(), Is.True);
  223. List<SceneObjectGroup> attachments = npc.GetAttachments();
  224. Assert.That(attachments.Count, Is.EqualTo(1));
  225. SceneObjectGroup attSo = attachments[0];
  226. // Just for now, we won't test the name since this is (wrongly) the asset part name rather than the item
  227. // name. TODO: Do need to fix ultimately since the item may be renamed before being passed on to an NPC.
  228. // Assert.That(attSo.Name, Is.EqualTo(attName));
  229. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
  230. Assert.That(attSo.IsAttachment);
  231. Assert.That(attSo.UsesPhysics, Is.False);
  232. Assert.That(attSo.IsTemporary, Is.False);
  233. Assert.That(attSo.OwnerID, Is.EqualTo(npc.UUID));
  234. }
  235. [Test]
  236. public void TestMove()
  237. {
  238. TestHelpers.InMethod();
  239. // TestHelpers.EnableLogging();
  240. SetUpScene();
  241. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
  242. // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
  243. Vector3 startPos = new Vector3(128, 128, 30);
  244. UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance);
  245. ScenePresence npc = m_scene.GetScenePresence(npcId);
  246. Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
  247. // For now, we'll make the scene presence fly to simplify this test, but this needs to change.
  248. npc.Flying = true;
  249. m_scene.Update(1);
  250. Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
  251. Vector3 targetPos = startPos + new Vector3(0, 10, 0);
  252. m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false);
  253. Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
  254. //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f)));
  255. Assert.That(
  256. npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001));
  257. m_scene.Update(1);
  258. // We should really check the exact figure.
  259. Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X));
  260. Assert.That(npc.AbsolutePosition.Y, Is.GreaterThan(startPos.Y));
  261. Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
  262. Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.X));
  263. m_scene.Update(10);
  264. double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
  265. Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move");
  266. Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
  267. Assert.That(npc.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE));
  268. // Try a second movement
  269. startPos = npc.AbsolutePosition;
  270. targetPos = startPos + new Vector3(10, 0, 0);
  271. m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false);
  272. Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
  273. // Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0, 1)));
  274. Assert.That(
  275. npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0, 1), 0.000001));
  276. m_scene.Update(1);
  277. // We should really check the exact figure.
  278. Assert.That(npc.AbsolutePosition.X, Is.GreaterThan(startPos.X));
  279. Assert.That(npc.AbsolutePosition.X, Is.LessThan(targetPos.X));
  280. Assert.That(npc.AbsolutePosition.Y, Is.EqualTo(startPos.Y));
  281. Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
  282. m_scene.Update(10);
  283. distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
  284. Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on second move");
  285. Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
  286. }
  287. [Test]
  288. public void TestMoveInVarRegion()
  289. {
  290. TestHelpers.InMethod();
  291. // TestHelpers.EnableLogging();
  292. SetUpScene(512, 512);
  293. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
  294. // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
  295. Vector3 startPos = new Vector3(128, 246, 30);
  296. UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance);
  297. ScenePresence npc = m_scene.GetScenePresence(npcId);
  298. Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
  299. // For now, we'll make the scene presence fly to simplify this test, but this needs to change.
  300. npc.Flying = true;
  301. m_scene.Update(1);
  302. Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
  303. Vector3 targetPos = startPos + new Vector3(0, 20, 0);
  304. m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false);
  305. Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
  306. //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f)));
  307. Assert.That(
  308. npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001));
  309. m_scene.Update(1);
  310. // We should really check the exact figure.
  311. Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X));
  312. Assert.That(npc.AbsolutePosition.Y, Is.GreaterThan(startPos.Y));
  313. Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
  314. Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.X));
  315. for (int i = 0; i < 20; i++)
  316. {
  317. m_scene.Update(1);
  318. // Console.WriteLine("pos: {0}", npc.AbsolutePosition);
  319. }
  320. double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
  321. Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move");
  322. Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
  323. Assert.That(npc.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE));
  324. }
  325. [Test]
  326. public void TestSitAndStandWithSitTarget()
  327. {
  328. TestHelpers.InMethod();
  329. // log4net.Config.XmlConfigurator.Configure();
  330. SetUpScene();
  331. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
  332. Vector3 startPos = new Vector3(128, 128, 30);
  333. UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance);
  334. ScenePresence npc = m_scene.GetScenePresence(npcId);
  335. SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
  336. part.SitTargetPosition = new Vector3(0, 0, 1);
  337. m_npcMod.Sit(npc.UUID, part.UUID, m_scene);
  338. Assert.That(part.SitTargetAvatar, Is.EqualTo(npcId));
  339. Assert.That(npc.ParentID, Is.EqualTo(part.LocalId));
  340. // Assert.That(
  341. // npc.AbsolutePosition,
  342. // Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT));
  343. m_npcMod.Stand(npc.UUID, m_scene);
  344. Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
  345. Assert.That(npc.ParentID, Is.EqualTo(0));
  346. }
  347. [Test]
  348. public void TestSitAndStandWithNoSitTarget()
  349. {
  350. TestHelpers.InMethod();
  351. // TestHelpers.EnableLogging();
  352. SetUpScene();
  353. ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
  354. // FIXME: To get this to work for now, we are going to place the npc right next to the target so that
  355. // the autopilot doesn't trigger
  356. Vector3 startPos = new Vector3(1, 1, 1);
  357. UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance);
  358. ScenePresence npc = m_scene.GetScenePresence(npcId);
  359. SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
  360. m_npcMod.Sit(npc.UUID, part.UUID, m_scene);
  361. Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
  362. Assert.That(npc.ParentID, Is.EqualTo(part.LocalId));
  363. // We should really be using the NPC size but this would mean preserving the physics actor since it is
  364. // removed on sit.
  365. Assert.That(
  366. npc.AbsolutePosition,
  367. Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, sp.PhysicsActor.Size.Z / 2)));
  368. m_npcMod.Stand(npc.UUID, m_scene);
  369. Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
  370. Assert.That(npc.ParentID, Is.EqualTo(0));
  371. }
  372. }
  373. }