aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/World/NPC
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs44
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs37
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs18
3 files changed, 66 insertions, 33 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
index 4674489..fa1d38a 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
@@ -44,6 +44,20 @@ 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;
@@ -67,6 +81,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
67 get { return m_scene; } 81 get { return m_scene; }
68 } 82 }
69 83
84 public int PingTimeMS { get { return 0; } }
85
70 public UUID OwnerID 86 public UUID OwnerID
71 { 87 {
72 get { return m_ownerID; } 88 get { return m_ownerID; }
@@ -259,6 +275,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
259 public event Action<IClientAPI, bool> OnCompleteMovementToRegion; 275 public event Action<IClientAPI, bool> OnCompleteMovementToRegion;
260 public event UpdateAgent OnPreAgentUpdate; 276 public event UpdateAgent OnPreAgentUpdate;
261 public event UpdateAgent OnAgentUpdate; 277 public event UpdateAgent OnAgentUpdate;
278 public event UpdateAgent OnAgentCameraUpdate;
262 public event AgentRequestSit OnAgentRequestSit; 279 public event AgentRequestSit OnAgentRequestSit;
263 public event AgentSit OnAgentSit; 280 public event AgentSit OnAgentSit;
264 public event AvatarPickerRequest OnAvatarPickerRequest; 281 public event AvatarPickerRequest OnAvatarPickerRequest;
@@ -393,6 +410,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
393 public event EstateTeleportAllUsersHomeRequest OnEstateTeleportAllUsersHomeRequest; 410 public event EstateTeleportAllUsersHomeRequest OnEstateTeleportAllUsersHomeRequest;
394 public event EstateChangeInfo OnEstateChangeInfo; 411 public event EstateChangeInfo OnEstateChangeInfo;
395 public event EstateManageTelehub OnEstateManageTelehub; 412 public event EstateManageTelehub OnEstateManageTelehub;
413 public event CachedTextureRequest OnCachedTextureRequest;
396 public event ScriptReset OnScriptReset; 414 public event ScriptReset OnScriptReset;
397 public event GetScriptRunning OnGetScriptRunning; 415 public event GetScriptRunning OnGetScriptRunning;
398 public event SetScriptRunning OnSetScriptRunning; 416 public event SetScriptRunning OnSetScriptRunning;
@@ -573,6 +591,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC
573 { 591 {
574 } 592 }
575 593
594 public void SendCachedTextureResponse(ISceneEntity avatar, int serial, List<CachedTextureResponseArg> cachedTextures)
595 {
596
597 }
598
576 public virtual void Kick(string message) 599 public virtual void Kick(string message)
577 { 600 {
578 } 601 }
@@ -590,7 +613,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
590 613
591 } 614 }
592 615
593 public virtual void SendKillObject(ulong regionHandle, List<uint> localID) 616 public virtual void SendKillObject(List<uint> localID)
594 { 617 {
595 } 618 }
596 619
@@ -617,17 +640,18 @@ namespace OpenSim.Region.OptionalModules.World.NPC
617 string message, byte type, Vector3 fromPos, string fromName, 640 string message, byte type, Vector3 fromPos, string fromName,
618 UUID fromAgentID, UUID ownerID, byte source, byte audible) 641 UUID fromAgentID, UUID ownerID, byte source, byte audible)
619 { 642 {
620 } 643 ChatToNPC ctn = OnChatToNPC;
621 644
622 public virtual void SendChatMessage( 645 if (ctn != null)
623 byte[] message, byte type, Vector3 fromPos, string fromName, 646 ctn(message, type, fromPos, fromName, fromAgentID, ownerID, source, audible);
624 UUID fromAgentID, UUID ownerID, byte source, byte audible)
625 {
626 } 647 }
627 648
628 public void SendInstantMessage(GridInstantMessage im) 649 public void SendInstantMessage(GridInstantMessage im)
629 { 650 {
630 651 Action<GridInstantMessage> oimtn = OnInstantMessageToNPC;
652
653 if (oimtn != null)
654 oimtn(im);
631 } 655 }
632 656
633 public void SendGenericMessage(string method, UUID invoice, List<string> message) 657 public void SendGenericMessage(string method, UUID invoice, List<string> message)
@@ -1236,7 +1260,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
1236 { 1260 {
1237 } 1261 }
1238 1262
1239 public void StopFlying(ISceneEntity presence) 1263 public void SendAgentTerseUpdate(ISceneEntity presence)
1240 { 1264 {
1241 } 1265 }
1242 1266
@@ -1248,5 +1272,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC
1248 { 1272 {
1249 } 1273 }
1250 1274
1275 public void SendPartFullUpdate(ISceneEntity ent, uint? parentID)
1276 {
1277 }
1278
1251 } 1279 }
1252} 1280}
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index 8c9c006..226608a 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>();
@@ -168,26 +170,27 @@ namespace OpenSim.Region.OptionalModules.World.NPC
168 } 170 }
169 */ 171 */
170 172
171 ManualResetEvent ev = new ManualResetEvent(false); 173// ManualResetEvent ev = new ManualResetEvent(false);
172 174
173 Util.FireAndForget(delegate(object x) { 175// Util.FireAndForget(delegate(object x) {
174 lock (m_avatars) 176 lock (m_avatars)
175 { 177 {
176 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); 178 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd);
177 scene.AddNewClient(npcAvatar, PresenceType.Npc); 179 scene.AddNewAgent(npcAvatar, PresenceType.Npc);
178 180
179 ScenePresence sp; 181 ScenePresence sp;
180 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) 182 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
181 { 183 {
184
182 sp.CompleteMovement(npcAvatar, false); 185 sp.CompleteMovement(npcAvatar, false);
183 m_avatars.Add(npcAvatar.AgentId, npcAvatar); 186 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
184// m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name); 187// m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name);
185 } 188 }
186 } 189 }
187 ev.Set(); 190// ev.Set();
188 }); 191// });
189 192
190 ev.WaitOne(); 193// ev.WaitOne();
191 194
192// m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", npcAvatar.AgentId); 195// m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", npcAvatar.AgentId);
193 196
@@ -205,8 +208,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC
205 if (scene.TryGetScenePresence(agentID, out sp)) 208 if (scene.TryGetScenePresence(agentID, out sp))
206 { 209 {
207// m_log.DebugFormat( 210// m_log.DebugFormat(
208// "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", 211// "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}",
209// sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); 212// sp.Name, pos, scene.RegionInfo.RegionName,
213// noFly, landAtTarget);
210 214
211 sp.MoveToTarget(pos, noFly, landAtTarget); 215 sp.MoveToTarget(pos, noFly, landAtTarget);
212 sp.SetAlwaysRun = running; 216 sp.SetAlwaysRun = running;
@@ -283,9 +287,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
283 ScenePresence sp; 287 ScenePresence sp;
284 if (scene.TryGetScenePresence(agentID, out sp)) 288 if (scene.TryGetScenePresence(agentID, out sp))
285 { 289 {
286 sp.HandleAgentRequestSit(m_avatars[agentID], agentID, 290 sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero);
287 partID, Vector3.Zero);
288 //sp.HandleAgentSit(m_avatars[agentID], agentID);
289 291
290 return true; 292 return true;
291 } 293 }
@@ -375,10 +377,15 @@ namespace OpenSim.Region.OptionalModules.World.NPC
375 m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", 377 m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove",
376 agentID, av.Name); 378 agentID, av.Name);
377 */ 379 */
378 scene.RemoveClient(agentID, false); 380
381 scene.CloseAgent(agentID, false);
382
379 m_avatars.Remove(agentID); 383 m_avatars.Remove(agentID);
380 384
381// m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", agentID, av.Name); 385 /*
386 m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}",
387 agentID, av.Name);
388 */
382 return true; 389 return true;
383 } 390 }
384 } 391 }
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
index 34362af..14eb25b 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
@@ -155,7 +155,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
155 public void TestCreateWithAttachments() 155 public void TestCreateWithAttachments()
156 { 156 {
157 TestHelpers.InMethod(); 157 TestHelpers.InMethod();
158// log4net.Config.XmlConfigurator.Configure(); 158// TestHelpers.EnableLogging();
159 159
160 UUID userId = TestHelpers.ParseTail(0x1); 160 UUID userId = TestHelpers.ParseTail(0x1);
161 UserAccountHelpers.CreateUserWithInventory(m_scene, userId); 161 UserAccountHelpers.CreateUserWithInventory(m_scene, userId);
@@ -321,9 +321,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
321 321
322 Assert.That(part.SitTargetAvatar, Is.EqualTo(npcId)); 322 Assert.That(part.SitTargetAvatar, Is.EqualTo(npcId));
323 Assert.That(npc.ParentID, Is.EqualTo(part.LocalId)); 323 Assert.That(npc.ParentID, Is.EqualTo(part.LocalId));
324 Assert.That( 324// Assert.That(
325 npc.AbsolutePosition, 325// npc.AbsolutePosition,
326 Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT)); 326// Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT));
327 327
328 m_npcMod.Stand(npc.UUID, m_scene); 328 m_npcMod.Stand(npc.UUID, m_scene);
329 329
@@ -335,7 +335,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
335 public void TestSitAndStandWithNoSitTarget() 335 public void TestSitAndStandWithNoSitTarget()
336 { 336 {
337 TestHelpers.InMethod(); 337 TestHelpers.InMethod();
338// log4net.Config.XmlConfigurator.Configure(); 338// TestHelpers.EnableLogging();
339 339
340 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); 340 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
341 341
@@ -353,13 +353,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
353 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); 353 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
354 Assert.That(npc.ParentID, Is.EqualTo(part.LocalId)); 354 Assert.That(npc.ParentID, Is.EqualTo(part.LocalId));
355 355
356 // FIXME: This is different for live avatars - z position is adjusted. This is half the height of the 356 // We should really be using the NPC size but this would mean preserving the physics actor since it is
357 // default avatar. 357 // 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( 358 Assert.That(
361 npc.AbsolutePosition, 359 npc.AbsolutePosition,
362 Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, 0.845499337f))); 360 Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, sp.PhysicsActor.Size.Z / 2)));
363 361
364 m_npcMod.Stand(npc.UUID, m_scene); 362 m_npcMod.Stand(npc.UUID, m_scene);
365 363