aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/World
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/World')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs129
1 files changed, 80 insertions, 49 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index b372c88..41e7097 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -29,14 +29,16 @@ using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Reflection; 30using System.Reflection;
31using System.Threading; 31using System.Threading;
32using Timer = System.Timers.Timer;
33
32using log4net; 34using log4net;
33using Nini.Config; 35using Nini.Config;
34using Mono.Addins; 36using Mono.Addins;
35using OpenMetaverse; 37using OpenMetaverse;
38
36using OpenSim.Region.Framework.Interfaces; 39using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes; 40using OpenSim.Region.Framework.Scenes;
38using OpenSim.Framework; 41using OpenSim.Framework;
39using Timer=System.Timers.Timer;
40using OpenSim.Services.Interfaces; 42using OpenSim.Services.Interfaces;
41 43
42namespace OpenSim.Region.OptionalModules.World.NPC 44namespace OpenSim.Region.OptionalModules.World.NPC
@@ -44,9 +46,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC
44 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] 46 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
45 public class NPCModule : INPCModule, ISharedRegionModule 47 public class NPCModule : INPCModule, ISharedRegionModule
46 { 48 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 49 private static readonly ILog m_log = LogManager.GetLogger(
50 MethodBase.GetCurrentMethod().DeclaringType);
48 51
49 private Dictionary<UUID, NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); 52 private Dictionary<UUID, NPCAvatar> m_avatars =
53 new Dictionary<UUID, NPCAvatar>();
50 54
51 public bool Enabled { get; private set; } 55 public bool Enabled { get; private set; }
52 56
@@ -89,8 +93,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC
89 93
90 public bool IsNPC(UUID agentId, Scene scene) 94 public bool IsNPC(UUID agentId, Scene scene)
91 { 95 {
92 // FIXME: This implementation could not just use the ScenePresence.PresenceType (and callers could inspect 96 // FIXME: This implementation could not just use the
93 // that directly). 97 // ScenePresence.PresenceType (and callers could inspect that
98 // directly).
94 ScenePresence sp = scene.GetScenePresence(agentId); 99 ScenePresence sp = scene.GetScenePresence(agentId);
95 if (sp == null || sp.IsChildAgent) 100 if (sp == null || sp.IsChildAgent)
96 return false; 101 return false;
@@ -99,7 +104,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
99 return m_avatars.ContainsKey(agentId); 104 return m_avatars.ContainsKey(agentId);
100 } 105 }
101 106
102 public bool SetNPCAppearance(UUID agentId, AvatarAppearance appearance, Scene scene) 107 public bool SetNPCAppearance(UUID agentId,
108 AvatarAppearance appearance, Scene scene)
103 { 109 {
104 ScenePresence npc = scene.GetScenePresence(agentId); 110 ScenePresence npc = scene.GetScenePresence(agentId);
105 if (npc == null || npc.IsChildAgent) 111 if (npc == null || npc.IsChildAgent)
@@ -112,34 +118,35 @@ namespace OpenSim.Region.OptionalModules.World.NPC
112 // Delete existing npc attachments 118 // Delete existing npc attachments
113 scene.AttachmentsModule.DeleteAttachmentsFromScene(npc, false); 119 scene.AttachmentsModule.DeleteAttachmentsFromScene(npc, false);
114 120
115 // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet since it doesn't transfer attachments 121 // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet
116 AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); 122 // since it doesn't transfer attachments
123 AvatarAppearance npcAppearance = new AvatarAppearance(appearance,
124 true);
117 npc.Appearance = npcAppearance; 125 npc.Appearance = npcAppearance;
118 126
119 // Rez needed npc attachments 127 // Rez needed npc attachments
120 scene.AttachmentsModule.RezAttachments(npc); 128 scene.AttachmentsModule.RezAttachments(npc);
121 129
122 IAvatarFactoryModule module = scene.RequestModuleInterface<IAvatarFactoryModule>(); 130 IAvatarFactoryModule module =
131 scene.RequestModuleInterface<IAvatarFactoryModule>();
123 module.SendAppearance(npc.UUID); 132 module.SendAppearance(npc.UUID);
124 133
125 return true; 134 return true;
126 } 135 }
127 136
128 public UUID CreateNPC( 137 public UUID CreateNPC(string firstname, string lastname,
129 string firstname, 138 Vector3 position, UUID owner, bool senseAsAgent, Scene scene,
130 string lastname, 139 AvatarAppearance appearance)
131 Vector3 position,
132 UUID owner,
133 bool senseAsAgent,
134 Scene scene,
135 AvatarAppearance appearance)
136 { 140 {
137 NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, owner, senseAsAgent, scene); 141 NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position,
138 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); 142 owner, senseAsAgent, scene);
143 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
144 int.MaxValue);
139 145
140 m_log.DebugFormat( 146 m_log.DebugFormat(
141 "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}", 147 "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}",
142 firstname, lastname, npcAvatar.AgentId, owner, senseAsAgent, position, scene.RegionInfo.RegionName); 148 firstname, lastname, npcAvatar.AgentId, owner,
149 senseAsAgent, position, scene.RegionInfo.RegionName);
143 150
144 AgentCircuitData acd = new AgentCircuitData(); 151 AgentCircuitData acd = new AgentCircuitData();
145 acd.AgentID = npcAvatar.AgentId; 152 acd.AgentID = npcAvatar.AgentId;
@@ -147,42 +154,55 @@ namespace OpenSim.Region.OptionalModules.World.NPC
147 acd.lastname = lastname; 154 acd.lastname = lastname;
148 acd.ServiceURLs = new Dictionary<string, object>(); 155 acd.ServiceURLs = new Dictionary<string, object>();
149 156
150 AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); 157 AvatarAppearance npcAppearance = new AvatarAppearance(appearance,
158 true);
151 acd.Appearance = npcAppearance; 159 acd.Appearance = npcAppearance;
152 160
153// for (int i = 0; i < acd.Appearance.Texture.FaceTextures.Length; i++) 161 /*
154// { 162 for (int i = 0;
155// m_log.DebugFormat( 163 i < acd.Appearance.Texture.FaceTextures.Length; i++)
156// "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}", 164 {
157// acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]); 165 m_log.DebugFormat(
158// } 166 "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}",
167 acd.AgentID, i,
168 acd.Appearance.Texture.FaceTextures[i]);
169 }
170 */
159 171
160 lock (m_avatars) 172 lock (m_avatars)
161 { 173 {
162 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); 174 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode,
175 acd);
163 scene.AddNewClient(npcAvatar, PresenceType.Npc); 176 scene.AddNewClient(npcAvatar, PresenceType.Npc);
164 177
165 ScenePresence sp; 178 ScenePresence sp;
166 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) 179 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
167 { 180 {
168// m_log.DebugFormat( 181 /*
169// "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID); 182 m_log.DebugFormat(
183 "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}",
184 sp.Name, sp.UUID);
185 */
170 186
171 sp.CompleteMovement(npcAvatar, false); 187 sp.CompleteMovement(npcAvatar, false);
172 m_avatars.Add(npcAvatar.AgentId, npcAvatar); 188 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
173 m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name); 189 m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}",
190 npcAvatar.AgentId, sp.Name);
174 191
175 return npcAvatar.AgentId; 192 return npcAvatar.AgentId;
176 } 193 }
177 else 194 else
178 { 195 {
179 m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID); 196 m_log.WarnFormat(
197 "[NPC MODULE]: Could not find scene presence for NPC {0} {1}",
198 sp.Name, sp.UUID);
180 return UUID.Zero; 199 return UUID.Zero;
181 } 200 }
182 } 201 }
183 } 202 }
184 203
185 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget, bool running) 204 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos,
205 bool noFly, bool landAtTarget, bool running)
186 { 206 {
187 lock (m_avatars) 207 lock (m_avatars)
188 { 208 {
@@ -192,12 +212,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC
192 if (scene.TryGetScenePresence(agentID, out sp)) 212 if (scene.TryGetScenePresence(agentID, out sp))
193 { 213 {
194 m_log.DebugFormat( 214 m_log.DebugFormat(
195 "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", 215 "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}",
196 sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); 216 sp.Name, pos, scene.RegionInfo.RegionName,
217 noFly, landAtTarget);
197 218
198 sp.MoveToTarget(pos, noFly, landAtTarget); 219 sp.MoveToTarget(pos, noFly, landAtTarget);
199 sp.SetAlwaysRun = running; 220 sp.SetAlwaysRun = running;
200 221
201 return true; 222 return true;
202 } 223 }
203 } 224 }
@@ -270,9 +291,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
270 ScenePresence sp; 291 ScenePresence sp;
271 if (scene.TryGetScenePresence(agentID, out sp)) 292 if (scene.TryGetScenePresence(agentID, out sp))
272 { 293 {
273 sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero); 294 sp.HandleAgentRequestSit(m_avatars[agentID], agentID,
274 // sp.HandleAgentSit(m_avatars[agentID], agentID); 295 partID, Vector3.Zero);
275 296 //sp.HandleAgentSit(m_avatars[agentID], agentID);
297
276 return true; 298 return true;
277 } 299 }
278 } 300 }
@@ -281,7 +303,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
281 return false; 303 return false;
282 } 304 }
283 305
284 public bool Whisper(UUID agentID, Scene scene, string text, int channel) 306 public bool Whisper(UUID agentID, Scene scene, string text,
307 int channel)
285 { 308 {
286 lock (m_avatars) 309 lock (m_avatars)
287 { 310 {
@@ -356,16 +379,23 @@ namespace OpenSim.Region.OptionalModules.World.NPC
356 NPCAvatar av; 379 NPCAvatar av;
357 if (m_avatars.TryGetValue(agentID, out av)) 380 if (m_avatars.TryGetValue(agentID, out av))
358 { 381 {
359// m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", agentID, av.Name); 382 /*
383 m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove",
384 agentID, av.Name);
385 */
360 scene.RemoveClient(agentID, false); 386 scene.RemoveClient(agentID, false);
361 m_avatars.Remove(agentID); 387 m_avatars.Remove(agentID);
362 388 /*
363 m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", agentID, av.Name); 389 m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}",
390 agentID, av.Name);
391 */
364 return true; 392 return true;
365 } 393 }
366 } 394 }
367 395 /*
368// m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove", agentID); 396 m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove",
397 agentID);
398 */
369 return false; 399 return false;
370 } 400 }
371 401
@@ -389,7 +419,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
389 /// <returns>true if they do, false if they don't.</returns> 419 /// <returns>true if they do, false if they don't.</returns>
390 private bool CheckPermissions(NPCAvatar av, UUID callerID) 420 private bool CheckPermissions(NPCAvatar av, UUID callerID)
391 { 421 {
392 return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID; 422 return callerID == UUID.Zero || av.OwnerID == UUID.Zero ||
423 av.OwnerID == callerID;
393 } 424 }
394 } 425 }
395} 426}