diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/OptionalModules/World/NPC | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC')
3 files changed, 254 insertions, 67 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index 5ea2bcd..fb644b7 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs | |||
@@ -44,10 +44,24 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
44 | { | 44 | { |
45 | public bool SenseAsAgent { get; set; } | 45 | public bool SenseAsAgent { get; set; } |
46 | 46 | ||
47 | public delegate void ChatToNPC( | ||
48 | string message, byte type, Vector3 fromPos, string fromName, | ||
49 | UUID fromAgentID, UUID ownerID, byte source, byte audible); | ||
50 | |||
51 | /// <summary> | ||
52 | /// Fired when the NPC receives a chat message. | ||
53 | /// </summary> | ||
54 | public event ChatToNPC OnChatToNPC; | ||
55 | |||
56 | /// <summary> | ||
57 | /// Fired when the NPC receives an instant message. | ||
58 | /// </summary> | ||
59 | public event Action<GridInstantMessage> OnInstantMessageToNPC; | ||
60 | |||
47 | private readonly string m_firstname; | 61 | private readonly string m_firstname; |
48 | private readonly string m_lastname; | 62 | private readonly string m_lastname; |
49 | private readonly Vector3 m_startPos; | 63 | private readonly Vector3 m_startPos; |
50 | private readonly UUID m_uuid = UUID.Random(); | 64 | private readonly UUID m_uuid; |
51 | private readonly Scene m_scene; | 65 | private readonly Scene m_scene; |
52 | private readonly UUID m_ownerID; | 66 | private readonly UUID m_ownerID; |
53 | 67 | ||
@@ -57,6 +71,19 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
57 | m_firstname = firstname; | 71 | m_firstname = firstname; |
58 | m_lastname = lastname; | 72 | m_lastname = lastname; |
59 | m_startPos = position; | 73 | m_startPos = position; |
74 | m_uuid = UUID.Random(); | ||
75 | m_scene = scene; | ||
76 | m_ownerID = ownerID; | ||
77 | SenseAsAgent = senseAsAgent; | ||
78 | } | ||
79 | |||
80 | public NPCAvatar( | ||
81 | string firstname, string lastname, UUID agentID, Vector3 position, UUID ownerID, bool senseAsAgent, Scene scene) | ||
82 | { | ||
83 | m_firstname = firstname; | ||
84 | m_lastname = lastname; | ||
85 | m_startPos = position; | ||
86 | m_uuid = agentID; | ||
60 | m_scene = scene; | 87 | m_scene = scene; |
61 | m_ownerID = ownerID; | 88 | m_ownerID = ownerID; |
62 | SenseAsAgent = senseAsAgent; | 89 | SenseAsAgent = senseAsAgent; |
@@ -258,6 +285,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
258 | public event Action<IClientAPI, bool> OnCompleteMovementToRegion; | 285 | public event Action<IClientAPI, bool> OnCompleteMovementToRegion; |
259 | public event UpdateAgent OnPreAgentUpdate; | 286 | public event UpdateAgent OnPreAgentUpdate; |
260 | public event UpdateAgent OnAgentUpdate; | 287 | public event UpdateAgent OnAgentUpdate; |
288 | public event UpdateAgent OnAgentCameraUpdate; | ||
261 | public event AgentRequestSit OnAgentRequestSit; | 289 | public event AgentRequestSit OnAgentRequestSit; |
262 | public event AgentSit OnAgentSit; | 290 | public event AgentSit OnAgentSit; |
263 | public event AvatarPickerRequest OnAvatarPickerRequest; | 291 | public event AvatarPickerRequest OnAvatarPickerRequest; |
@@ -391,6 +419,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
391 | public event EstateTeleportAllUsersHomeRequest OnEstateTeleportAllUsersHomeRequest; | 419 | public event EstateTeleportAllUsersHomeRequest OnEstateTeleportAllUsersHomeRequest; |
392 | public event EstateChangeInfo OnEstateChangeInfo; | 420 | public event EstateChangeInfo OnEstateChangeInfo; |
393 | public event EstateManageTelehub OnEstateManageTelehub; | 421 | public event EstateManageTelehub OnEstateManageTelehub; |
422 | public event CachedTextureRequest OnCachedTextureRequest; | ||
394 | public event ScriptReset OnScriptReset; | 423 | public event ScriptReset OnScriptReset; |
395 | public event GetScriptRunning OnGetScriptRunning; | 424 | public event GetScriptRunning OnGetScriptRunning; |
396 | public event SetScriptRunning OnSetScriptRunning; | 425 | public event SetScriptRunning OnSetScriptRunning; |
@@ -569,6 +598,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
569 | { | 598 | { |
570 | } | 599 | } |
571 | 600 | ||
601 | public void SendCachedTextureResponse(ISceneEntity avatar, int serial, List<CachedTextureResponseArg> cachedTextures) | ||
602 | { | ||
603 | |||
604 | } | ||
605 | |||
572 | public virtual void Kick(string message) | 606 | public virtual void Kick(string message) |
573 | { | 607 | { |
574 | } | 608 | } |
@@ -586,7 +620,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
586 | 620 | ||
587 | } | 621 | } |
588 | 622 | ||
589 | public virtual void SendKillObject(ulong regionHandle, List<uint> localID) | 623 | public virtual void SendKillObject(List<uint> localID) |
590 | { | 624 | { |
591 | } | 625 | } |
592 | 626 | ||
@@ -607,25 +641,26 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
607 | string message, byte type, Vector3 fromPos, string fromName, | 641 | string message, byte type, Vector3 fromPos, string fromName, |
608 | UUID fromAgentID, UUID ownerID, byte source, byte audible) | 642 | UUID fromAgentID, UUID ownerID, byte source, byte audible) |
609 | { | 643 | { |
610 | } | 644 | ChatToNPC ctn = OnChatToNPC; |
611 | 645 | ||
612 | public virtual void SendChatMessage( | 646 | if (ctn != null) |
613 | byte[] message, byte type, Vector3 fromPos, string fromName, | 647 | ctn(message, type, fromPos, fromName, fromAgentID, ownerID, source, audible); |
614 | UUID fromAgentID, UUID ownerID, byte source, byte audible) | ||
615 | { | ||
616 | } | 648 | } |
617 | 649 | ||
618 | public void SendInstantMessage(GridInstantMessage im) | 650 | public void SendInstantMessage(GridInstantMessage im) |
619 | { | 651 | { |
620 | 652 | Action<GridInstantMessage> oimtn = OnInstantMessageToNPC; | |
653 | |||
654 | if (oimtn != null) | ||
655 | oimtn(im); | ||
621 | } | 656 | } |
622 | 657 | ||
623 | public void SendGenericMessage(string method, List<string> message) | 658 | public void SendGenericMessage(string method, UUID invoice, List<string> message) |
624 | { | 659 | { |
625 | 660 | ||
626 | } | 661 | } |
627 | 662 | ||
628 | public void SendGenericMessage(string method, List<byte[]> message) | 663 | public void SendGenericMessage(string method, UUID invoice, List<byte[]> message) |
629 | { | 664 | { |
630 | 665 | ||
631 | } | 666 | } |
@@ -688,7 +723,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
688 | { | 723 | { |
689 | } | 724 | } |
690 | 725 | ||
691 | public virtual void SendMoneyBalance(UUID transaction, bool success, byte[] description, int balance) | 726 | public virtual void SendMoneyBalance(UUID transaction, bool success, byte[] description, int balance, int transactionType, UUID sourceID, bool sourceIsGroup, UUID destID, bool destIsGroup, int amount, string item) |
692 | { | 727 | { |
693 | } | 728 | } |
694 | 729 | ||
@@ -860,11 +895,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
860 | { | 895 | { |
861 | } | 896 | } |
862 | 897 | ||
863 | public bool AddMoney(int debit) | ||
864 | { | ||
865 | return false; | ||
866 | } | ||
867 | |||
868 | public void SendSunPos(Vector3 sunPos, Vector3 sunVel, ulong time, uint dlen, uint ylen, float phase) | 898 | public void SendSunPos(Vector3 sunPos, Vector3 sunVel, ulong time, uint dlen, uint ylen, float phase) |
869 | { | 899 | { |
870 | } | 900 | } |
@@ -1227,12 +1257,17 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
1227 | { | 1257 | { |
1228 | } | 1258 | } |
1229 | 1259 | ||
1230 | public void StopFlying(ISceneEntity presence) | 1260 | public void SendAgentTerseUpdate(ISceneEntity presence) |
1231 | { | 1261 | { |
1232 | } | 1262 | } |
1233 | 1263 | ||
1234 | public void SendPlacesReply(UUID queryID, UUID transactionID, PlacesReplyData[] data) | 1264 | public void SendPlacesReply(UUID queryID, UUID transactionID, PlacesReplyData[] data) |
1235 | { | 1265 | { |
1236 | } | 1266 | } |
1267 | |||
1268 | public void SendPartPhysicsProprieties(ISceneEntity entity) | ||
1269 | { | ||
1270 | } | ||
1271 | |||
1237 | } | 1272 | } |
1238 | } | 1273 | } |
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index d6cf1ab..9232db9 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | |||
@@ -116,7 +116,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
116 | return false; | 116 | return false; |
117 | 117 | ||
118 | // Delete existing npc attachments | 118 | // Delete existing npc attachments |
119 | scene.AttachmentsModule.DeleteAttachmentsFromScene(npc, false); | 119 | if(scene.AttachmentsModule != null) |
120 | scene.AttachmentsModule.DeleteAttachmentsFromScene(npc, false); | ||
120 | 121 | ||
121 | // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet | 122 | // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet |
122 | // since it doesn't transfer attachments | 123 | // since it doesn't transfer attachments |
@@ -125,7 +126,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
125 | npc.Appearance = npcAppearance; | 126 | npc.Appearance = npcAppearance; |
126 | 127 | ||
127 | // Rez needed npc attachments | 128 | // Rez needed npc attachments |
128 | scene.AttachmentsModule.RezAttachments(npc); | 129 | if (scene.AttachmentsModule != null) |
130 | scene.AttachmentsModule.RezAttachments(npc); | ||
129 | 131 | ||
130 | IAvatarFactoryModule module = | 132 | IAvatarFactoryModule module = |
131 | scene.RequestModuleInterface<IAvatarFactoryModule>(); | 133 | scene.RequestModuleInterface<IAvatarFactoryModule>(); |
@@ -138,15 +140,37 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
138 | Vector3 position, UUID owner, bool senseAsAgent, Scene scene, | 140 | Vector3 position, UUID owner, bool senseAsAgent, Scene scene, |
139 | AvatarAppearance appearance) | 141 | AvatarAppearance appearance) |
140 | { | 142 | { |
141 | NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, | 143 | return CreateNPC(firstname, lastname, position, UUID.Zero, owner, senseAsAgent, scene, appearance); |
142 | owner, senseAsAgent, scene); | 144 | } |
145 | |||
146 | public UUID CreateNPC(string firstname, string lastname, | ||
147 | Vector3 position, UUID agentID, UUID owner, bool senseAsAgent, Scene scene, | ||
148 | AvatarAppearance appearance) | ||
149 | { | ||
150 | NPCAvatar npcAvatar = null; | ||
151 | |||
152 | try | ||
153 | { | ||
154 | if (agentID == UUID.Zero) | ||
155 | npcAvatar = new NPCAvatar(firstname, lastname, position, | ||
156 | owner, senseAsAgent, scene); | ||
157 | else | ||
158 | npcAvatar = new NPCAvatar(firstname, lastname, agentID, position, | ||
159 | owner, senseAsAgent, scene); | ||
160 | } | ||
161 | catch (Exception e) | ||
162 | { | ||
163 | m_log.Info("[NPC MODULE]: exception creating NPC avatar: " + e.ToString()); | ||
164 | return UUID.Zero; | ||
165 | } | ||
166 | |||
143 | npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, | 167 | npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, |
144 | int.MaxValue); | 168 | int.MaxValue); |
145 | 169 | ||
146 | m_log.DebugFormat( | 170 | m_log.DebugFormat( |
147 | "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}", | 171 | "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}", |
148 | firstname, lastname, npcAvatar.AgentId, owner, | 172 | firstname, lastname, npcAvatar.AgentId, owner, |
149 | senseAsAgent, position, scene.RegionInfo.RegionName); | 173 | senseAsAgent, position, scene.RegionInfo.RegionName); |
150 | 174 | ||
151 | AgentCircuitData acd = new AgentCircuitData(); | 175 | AgentCircuitData acd = new AgentCircuitData(); |
152 | acd.AgentID = npcAvatar.AgentId; | 176 | acd.AgentID = npcAvatar.AgentId; |
@@ -154,8 +178,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
154 | acd.lastname = lastname; | 178 | acd.lastname = lastname; |
155 | acd.ServiceURLs = new Dictionary<string, object>(); | 179 | acd.ServiceURLs = new Dictionary<string, object>(); |
156 | 180 | ||
157 | AvatarAppearance npcAppearance = new AvatarAppearance(appearance, | 181 | AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); |
158 | true); | ||
159 | acd.Appearance = npcAppearance; | 182 | acd.Appearance = npcAppearance; |
160 | 183 | ||
161 | /* | 184 | /* |
@@ -173,7 +196,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
173 | { | 196 | { |
174 | scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, | 197 | scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, |
175 | acd); | 198 | acd); |
176 | scene.AddNewClient(npcAvatar, PresenceType.Npc); | 199 | scene.AddNewAgent(npcAvatar, PresenceType.Npc); |
177 | 200 | ||
178 | ScenePresence sp; | 201 | ScenePresence sp; |
179 | if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) | 202 | if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) |
@@ -186,16 +209,16 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
186 | 209 | ||
187 | sp.CompleteMovement(npcAvatar, false); | 210 | sp.CompleteMovement(npcAvatar, false); |
188 | m_avatars.Add(npcAvatar.AgentId, npcAvatar); | 211 | m_avatars.Add(npcAvatar.AgentId, npcAvatar); |
189 | m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", | 212 | m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name); |
190 | npcAvatar.AgentId, sp.Name); | ||
191 | 213 | ||
192 | return npcAvatar.AgentId; | 214 | return npcAvatar.AgentId; |
193 | } | 215 | } |
194 | else | 216 | else |
195 | { | 217 | { |
196 | m_log.WarnFormat( | 218 | m_log.WarnFormat( |
197 | "[NPC MODULE]: Could not find scene presence for NPC {0} {1}", | 219 | "[NPC MODULE]: Could not find scene presence for NPC {0} {1}", |
198 | sp.Name, sp.UUID); | 220 | sp.Name, sp.UUID); |
221 | |||
199 | return UUID.Zero; | 222 | return UUID.Zero; |
200 | } | 223 | } |
201 | } | 224 | } |
@@ -211,12 +234,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
211 | ScenePresence sp; | 234 | ScenePresence sp; |
212 | if (scene.TryGetScenePresence(agentID, out sp)) | 235 | if (scene.TryGetScenePresence(agentID, out sp)) |
213 | { | 236 | { |
214 | /* | 237 | if (sp.IsSatOnObject || sp.SitGround) |
215 | m_log.DebugFormat( | 238 | return false; |
216 | "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", | 239 | |
217 | sp.Name, pos, scene.RegionInfo.RegionName, | 240 | // m_log.DebugFormat( |
218 | noFly, landAtTarget); | 241 | // "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", |
219 | */ | 242 | // sp.Name, pos, scene.RegionInfo.RegionName, |
243 | // noFly, landAtTarget); | ||
220 | 244 | ||
221 | sp.MoveToTarget(pos, noFly, landAtTarget); | 245 | sp.MoveToTarget(pos, noFly, landAtTarget); |
222 | sp.SetAlwaysRun = running; | 246 | sp.SetAlwaysRun = running; |
@@ -293,9 +317,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
293 | ScenePresence sp; | 317 | ScenePresence sp; |
294 | if (scene.TryGetScenePresence(agentID, out sp)) | 318 | if (scene.TryGetScenePresence(agentID, out sp)) |
295 | { | 319 | { |
296 | sp.HandleAgentRequestSit(m_avatars[agentID], agentID, | 320 | sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero); |
297 | partID, Vector3.Zero); | ||
298 | //sp.HandleAgentSit(m_avatars[agentID], agentID); | ||
299 | 321 | ||
300 | return true; | 322 | return true; |
301 | } | 323 | } |
@@ -376,23 +398,30 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
376 | 398 | ||
377 | public bool DeleteNPC(UUID agentID, Scene scene) | 399 | public bool DeleteNPC(UUID agentID, Scene scene) |
378 | { | 400 | { |
401 | bool doRemove = false; | ||
402 | NPCAvatar av; | ||
379 | lock (m_avatars) | 403 | lock (m_avatars) |
380 | { | 404 | { |
381 | NPCAvatar av; | ||
382 | if (m_avatars.TryGetValue(agentID, out av)) | 405 | if (m_avatars.TryGetValue(agentID, out av)) |
383 | { | 406 | { |
384 | /* | 407 | /* |
385 | m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", | 408 | m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", |
386 | agentID, av.Name); | 409 | agentID, av.Name); |
387 | */ | 410 | */ |
388 | scene.RemoveClient(agentID, false); | 411 | doRemove = true; |
412 | } | ||
413 | } | ||
414 | |||
415 | if (doRemove) | ||
416 | { | ||
417 | scene.CloseAgent(agentID, false); | ||
418 | lock (m_avatars) | ||
419 | { | ||
389 | m_avatars.Remove(agentID); | 420 | m_avatars.Remove(agentID); |
390 | /* | ||
391 | m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", | ||
392 | agentID, av.Name); | ||
393 | */ | ||
394 | return true; | ||
395 | } | 421 | } |
422 | m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", | ||
423 | agentID, av.Name); | ||
424 | return true; | ||
396 | } | 425 | } |
397 | /* | 426 | /* |
398 | m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove", | 427 | m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove", |
@@ -416,13 +445,20 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
416 | /// <summary> | 445 | /// <summary> |
417 | /// Check if the caller has permission to manipulate the given NPC. | 446 | /// Check if the caller has permission to manipulate the given NPC. |
418 | /// </summary> | 447 | /// </summary> |
448 | /// <remarks> | ||
449 | /// A caller has permission if | ||
450 | /// * The caller UUID given is UUID.Zero. | ||
451 | /// * The avatar is unowned (owner is UUID.Zero). | ||
452 | /// * The avatar is owned and the owner and callerID match. | ||
453 | /// * The avatar is owned and the callerID matches its agentID. | ||
454 | /// </remarks> | ||
419 | /// <param name="av"></param> | 455 | /// <param name="av"></param> |
420 | /// <param name="callerID"></param> | 456 | /// <param name="callerID"></param> |
421 | /// <returns>true if they do, false if they don't.</returns> | 457 | /// <returns>true if they do, false if they don't.</returns> |
422 | private bool CheckPermissions(NPCAvatar av, UUID callerID) | 458 | private bool CheckPermissions(NPCAvatar av, UUID callerID) |
423 | { | 459 | { |
424 | return callerID == UUID.Zero || av.OwnerID == UUID.Zero || | 460 | return callerID == UUID.Zero || av.OwnerID == UUID.Zero || |
425 | av.OwnerID == callerID; | 461 | av.OwnerID == callerID || av.AgentId == callerID; |
426 | } | 462 | } |
427 | } | 463 | } |
428 | } | 464 | } |
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index bf23040..77dfd40 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs | |||
@@ -33,7 +33,6 @@ using Nini.Config; | |||
33 | using NUnit.Framework; | 33 | using NUnit.Framework; |
34 | using OpenMetaverse; | 34 | using OpenMetaverse; |
35 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
36 | using OpenSim.Framework.Communications; | ||
37 | using OpenSim.Region.CoreModules.Avatar.Attachments; | 36 | using OpenSim.Region.CoreModules.Avatar.Attachments; |
38 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; | 37 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; |
39 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | 38 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; |
@@ -43,7 +42,6 @@ using OpenSim.Region.Framework.Interfaces; | |||
43 | using OpenSim.Region.Framework.Scenes; | 42 | using OpenSim.Region.Framework.Scenes; |
44 | using OpenSim.Services.AvatarService; | 43 | using OpenSim.Services.AvatarService; |
45 | using OpenSim.Tests.Common; | 44 | using OpenSim.Tests.Common; |
46 | using OpenSim.Tests.Common.Mock; | ||
47 | 45 | ||
48 | namespace OpenSim.Region.OptionalModules.World.NPC.Tests | 46 | namespace OpenSim.Region.OptionalModules.World.NPC.Tests |
49 | { | 47 | { |
@@ -71,11 +69,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
71 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | 69 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; |
72 | } | 70 | } |
73 | 71 | ||
74 | [SetUp] | 72 | public void SetUpScene() |
75 | public void Init() | ||
76 | { | 73 | { |
77 | base.SetUp(); | 74 | SetUpScene(256, 256); |
75 | } | ||
78 | 76 | ||
77 | public void SetUpScene(uint sizeX, uint sizeY) | ||
78 | { | ||
79 | IConfigSource config = new IniConfigSource(); | 79 | IConfigSource config = new IniConfigSource(); |
80 | config.AddConfig("NPC"); | 80 | config.AddConfig("NPC"); |
81 | config.Configs["NPC"].Set("Enabled", "true"); | 81 | config.Configs["NPC"].Set("Enabled", "true"); |
@@ -87,7 +87,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
87 | m_attMod = new AttachmentsModule(); | 87 | m_attMod = new AttachmentsModule(); |
88 | m_npcMod = new NPCModule(); | 88 | m_npcMod = new NPCModule(); |
89 | 89 | ||
90 | m_scene = new SceneHelpers().SetupScene(); | 90 | m_scene = new SceneHelpers().SetupScene("test scene", UUID.Random(), 1000, 1000, sizeX, sizeY, config); |
91 | SceneHelpers.SetupSceneModules(m_scene, config, m_afMod, m_umMod, m_attMod, m_npcMod, new BasicInventoryAccessModule()); | 91 | SceneHelpers.SetupSceneModules(m_scene, config, m_afMod, m_umMod, m_attMod, m_npcMod, new BasicInventoryAccessModule()); |
92 | } | 92 | } |
93 | 93 | ||
@@ -97,6 +97,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
97 | TestHelpers.InMethod(); | 97 | TestHelpers.InMethod(); |
98 | // log4net.Config.XmlConfigurator.Configure(); | 98 | // log4net.Config.XmlConfigurator.Configure(); |
99 | 99 | ||
100 | SetUpScene(); | ||
101 | |||
100 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); | 102 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); |
101 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); | 103 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); |
102 | 104 | ||
@@ -110,7 +112,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
110 | // ScenePresence.SendInitialData() to reset our entire appearance. | 112 | // ScenePresence.SendInitialData() to reset our entire appearance. |
111 | m_scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId)); | 113 | m_scene.AssetService.Store(AssetHelpers.CreateNotecardAsset(originalFace8TextureId)); |
112 | 114 | ||
113 | m_afMod.SetAppearance(sp, originalTe, null); | 115 | m_afMod.SetAppearance(sp, originalTe, null, null); |
114 | 116 | ||
115 | UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance); | 117 | UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance); |
116 | 118 | ||
@@ -133,6 +135,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
133 | TestHelpers.InMethod(); | 135 | TestHelpers.InMethod(); |
134 | // log4net.Config.XmlConfigurator.Configure(); | 136 | // log4net.Config.XmlConfigurator.Configure(); |
135 | 137 | ||
138 | SetUpScene(); | ||
139 | |||
136 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); | 140 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); |
137 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); | 141 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); |
138 | 142 | ||
@@ -155,7 +159,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
155 | public void TestCreateWithAttachments() | 159 | public void TestCreateWithAttachments() |
156 | { | 160 | { |
157 | TestHelpers.InMethod(); | 161 | TestHelpers.InMethod(); |
158 | // log4net.Config.XmlConfigurator.Configure(); | 162 | // TestHelpers.EnableLogging(); |
163 | |||
164 | SetUpScene(); | ||
159 | 165 | ||
160 | UUID userId = TestHelpers.ParseTail(0x1); | 166 | UUID userId = TestHelpers.ParseTail(0x1); |
161 | UserAccountHelpers.CreateUserWithInventory(m_scene, userId); | 167 | UserAccountHelpers.CreateUserWithInventory(m_scene, userId); |
@@ -191,11 +197,66 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
191 | } | 197 | } |
192 | 198 | ||
193 | [Test] | 199 | [Test] |
200 | public void TestCreateWithMultiAttachments() | ||
201 | { | ||
202 | TestHelpers.InMethod(); | ||
203 | // TestHelpers.EnableLogging(); | ||
204 | |||
205 | SetUpScene(); | ||
206 | // m_attMod.DebugLevel = 1; | ||
207 | |||
208 | UUID userId = TestHelpers.ParseTail(0x1); | ||
209 | UserAccountHelpers.CreateUserWithInventory(m_scene, userId); | ||
210 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
211 | |||
212 | InventoryItemBase att1Item | ||
213 | = UserInventoryHelpers.CreateInventoryItem( | ||
214 | m_scene, "att1", TestHelpers.ParseTail(0x2), TestHelpers.ParseTail(0x3), sp.UUID, InventoryType.Object); | ||
215 | InventoryItemBase att2Item | ||
216 | = UserInventoryHelpers.CreateInventoryItem( | ||
217 | m_scene, "att2", TestHelpers.ParseTail(0x12), TestHelpers.ParseTail(0x13), sp.UUID, InventoryType.Object); | ||
218 | |||
219 | m_attMod.RezSingleAttachmentFromInventory(sp, att1Item.ID, (uint)AttachmentPoint.Chest); | ||
220 | m_attMod.RezSingleAttachmentFromInventory(sp, att2Item.ID, (uint)AttachmentPoint.Chest | 0x80); | ||
221 | |||
222 | UUID npcId = m_npcMod.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, sp.Appearance); | ||
223 | |||
224 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
225 | |||
226 | // Check scene presence status | ||
227 | Assert.That(npc.HasAttachments(), Is.True); | ||
228 | List<SceneObjectGroup> attachments = npc.GetAttachments(); | ||
229 | Assert.That(attachments.Count, Is.EqualTo(2)); | ||
230 | |||
231 | // Just for now, we won't test the name since this is (wrongly) the asset part name rather than the item | ||
232 | // name. TODO: Do need to fix ultimately since the item may be renamed before being passed on to an NPC. | ||
233 | // Assert.That(attSo.Name, Is.EqualTo(attName)); | ||
234 | |||
235 | TestAttachedObject(attachments[0], AttachmentPoint.Chest, npc.UUID); | ||
236 | TestAttachedObject(attachments[1], AttachmentPoint.Chest, npc.UUID); | ||
237 | |||
238 | // Attached objects on the same point must have different FromItemIDs to be shown to other avatars, at least | ||
239 | // on Singularity 1.8.5. Otherwise, only one (the first ObjectUpdate sent) appears. | ||
240 | Assert.AreNotEqual(attachments[0].FromItemID, attachments[1].FromItemID); | ||
241 | } | ||
242 | |||
243 | private void TestAttachedObject(SceneObjectGroup attSo, AttachmentPoint attPoint, UUID ownerId) | ||
244 | { | ||
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)); | ||
250 | } | ||
251 | |||
252 | [Test] | ||
194 | public void TestLoadAppearance() | 253 | public void TestLoadAppearance() |
195 | { | 254 | { |
196 | TestHelpers.InMethod(); | 255 | TestHelpers.InMethod(); |
197 | // log4net.Config.XmlConfigurator.Configure(); | 256 | // log4net.Config.XmlConfigurator.Configure(); |
198 | 257 | ||
258 | SetUpScene(); | ||
259 | |||
199 | UUID userId = TestHelpers.ParseTail(0x1); | 260 | UUID userId = TestHelpers.ParseTail(0x1); |
200 | UserAccountHelpers.CreateUserWithInventory(m_scene, userId); | 261 | UserAccountHelpers.CreateUserWithInventory(m_scene, userId); |
201 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | 262 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); |
@@ -237,7 +298,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
237 | public void TestMove() | 298 | public void TestMove() |
238 | { | 299 | { |
239 | TestHelpers.InMethod(); | 300 | TestHelpers.InMethod(); |
240 | // log4net.Config.XmlConfigurator.Configure(); | 301 | // TestHelpers.EnableLogging(); |
302 | |||
303 | SetUpScene(); | ||
241 | 304 | ||
242 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); | 305 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); |
243 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); | 306 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); |
@@ -303,11 +366,64 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
303 | } | 366 | } |
304 | 367 | ||
305 | [Test] | 368 | [Test] |
369 | public void TestMoveInVarRegion() | ||
370 | { | ||
371 | TestHelpers.InMethod(); | ||
372 | // TestHelpers.EnableLogging(); | ||
373 | |||
374 | SetUpScene(512, 512); | ||
375 | |||
376 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); | ||
377 | // ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); | ||
378 | |||
379 | Vector3 startPos = new Vector3(128, 246, 30); | ||
380 | UUID npcId = m_npcMod.CreateNPC("John", "Smith", startPos, UUID.Zero, true, m_scene, sp.Appearance); | ||
381 | |||
382 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
383 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); | ||
384 | |||
385 | // For now, we'll make the scene presence fly to simplify this test, but this needs to change. | ||
386 | npc.Flying = true; | ||
387 | |||
388 | m_scene.Update(1); | ||
389 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); | ||
390 | |||
391 | Vector3 targetPos = startPos + new Vector3(0, 20, 0); | ||
392 | m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false); | ||
393 | |||
394 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); | ||
395 | //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f))); | ||
396 | Assert.That( | ||
397 | npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001)); | ||
398 | |||
399 | m_scene.Update(1); | ||
400 | |||
401 | // We should really check the exact figure. | ||
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)); | ||
406 | |||
407 | for (int i = 0; i < 20; i++) | ||
408 | { | ||
409 | m_scene.Update(1); | ||
410 | // Console.WriteLine("pos: {0}", npc.AbsolutePosition); | ||
411 | } | ||
412 | |||
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)); | ||
417 | } | ||
418 | |||
419 | [Test] | ||
306 | public void TestSitAndStandWithSitTarget() | 420 | public void TestSitAndStandWithSitTarget() |
307 | { | 421 | { |
308 | TestHelpers.InMethod(); | 422 | TestHelpers.InMethod(); |
309 | // log4net.Config.XmlConfigurator.Configure(); | 423 | // log4net.Config.XmlConfigurator.Configure(); |
310 | 424 | ||
425 | SetUpScene(); | ||
426 | |||
311 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); | 427 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); |
312 | 428 | ||
313 | Vector3 startPos = new Vector3(128, 128, 30); | 429 | Vector3 startPos = new Vector3(128, 128, 30); |
@@ -321,9 +437,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
321 | 437 | ||
322 | Assert.That(part.SitTargetAvatar, Is.EqualTo(npcId)); | 438 | Assert.That(part.SitTargetAvatar, Is.EqualTo(npcId)); |
323 | Assert.That(npc.ParentID, Is.EqualTo(part.LocalId)); | 439 | Assert.That(npc.ParentID, Is.EqualTo(part.LocalId)); |
324 | Assert.That( | 440 | // Assert.That( |
325 | npc.AbsolutePosition, | 441 | // npc.AbsolutePosition, |
326 | Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT)); | 442 | // Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT)); |
327 | 443 | ||
328 | m_npcMod.Stand(npc.UUID, m_scene); | 444 | m_npcMod.Stand(npc.UUID, m_scene); |
329 | 445 | ||
@@ -335,7 +451,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
335 | public void TestSitAndStandWithNoSitTarget() | 451 | public void TestSitAndStandWithNoSitTarget() |
336 | { | 452 | { |
337 | TestHelpers.InMethod(); | 453 | TestHelpers.InMethod(); |
338 | // log4net.Config.XmlConfigurator.Configure(); | 454 | // TestHelpers.EnableLogging(); |
455 | |||
456 | SetUpScene(); | ||
339 | 457 | ||
340 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); | 458 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); |
341 | 459 | ||
@@ -353,13 +471,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
353 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); | 471 | Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); |
354 | Assert.That(npc.ParentID, Is.EqualTo(part.LocalId)); | 472 | Assert.That(npc.ParentID, Is.EqualTo(part.LocalId)); |
355 | 473 | ||
356 | // FIXME: This is different for live avatars - z position is adjusted. This is half the height of the | 474 | // We should really be using the NPC size but this would mean preserving the physics actor since it is |
357 | // default avatar. | 475 | // removed on sit. |
358 | // Curiously, Vector3.ToString() will not display the last two places of the float. For example, | ||
359 | // printing out npc.AbsolutePosition will give <0, 0, 0.8454993> not <0, 0, 0.845499337> | ||
360 | Assert.That( | 476 | Assert.That( |
361 | npc.AbsolutePosition, | 477 | npc.AbsolutePosition, |
362 | Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, 0.845499337f))); | 478 | Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, sp.PhysicsActor.Size.Z / 2))); |
363 | 479 | ||
364 | m_npcMod.Stand(npc.UUID, m_scene); | 480 | m_npcMod.Stand(npc.UUID, m_scene); |
365 | 481 | ||
@@ -367,4 +483,4 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
367 | Assert.That(npc.ParentID, Is.EqualTo(0)); | 483 | Assert.That(npc.ParentID, Is.EqualTo(0)); |
368 | } | 484 | } |
369 | } | 485 | } |
370 | } | 486 | } \ No newline at end of file |