aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs139
1 files changed, 37 insertions, 102 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index 48d236f..c1ddeee 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -47,31 +47,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC
47 47
48 // private const bool m_enabled = false; 48 // private const bool m_enabled = false;
49 49
50 private Mutex m_createMutex;
51 private Timer m_timer;
52
53 private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); 50 private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>();
54 private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>(); 51 private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>();
55 52
56 // Timer vars.
57 private bool p_inUse = false;
58 private readonly object p_lock = new object();
59 // Private Temporary Variables.
60 private string p_firstname;
61 private string p_lastname;
62 private Vector3 p_position;
63 private Scene p_scene;
64 private UUID p_cloneAppearanceFrom;
65 private UUID p_returnUuid;
66
67 public void Initialise(Scene scene, IConfigSource source) 53 public void Initialise(Scene scene, IConfigSource source)
68 { 54 {
69 m_createMutex = new Mutex(false);
70
71 m_timer = new Timer(500);
72 m_timer.Elapsed += m_timer_Elapsed;
73 m_timer.Start();
74
75 scene.RegisterModuleInterface<INPCModule>(this); 55 scene.RegisterModuleInterface<INPCModule>(this);
76 } 56 }
77 57
@@ -92,33 +72,51 @@ namespace OpenSim.Region.OptionalModules.World.NPC
92 72
93 public UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom) 73 public UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom)
94 { 74 {
75 NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, scene);
76 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue);
77
95 m_log.DebugFormat( 78 m_log.DebugFormat(
96 "[NPC MODULE]: Queueing request to create NPC {0} {1} at {2} in {3} cloning appearance of {4}", 79 "[NPC MODULE]: Creating NPC {0} {1} {2} at {3} in {4}",
97 firstname, lastname, position, scene.RegionInfo.RegionName, cloneAppearanceFrom); 80 firstname, lastname, npcAvatar.AgentId, position, scene.RegionInfo.RegionName);
81
82 AgentCircuitData acd = new AgentCircuitData();
83 acd.AgentID = npcAvatar.AgentId;
84 acd.firstname = firstname;
85 acd.lastname = lastname;
86 acd.ServiceURLs = new Dictionary<string, object>();
98 87
99 // Block. 88 AvatarAppearance originalAppearance = GetAppearance(cloneAppearanceFrom, scene);
100 m_createMutex.WaitOne(); 89 AvatarAppearance npcAppearance = new AvatarAppearance(originalAppearance, true);
90 acd.Appearance = npcAppearance;
101 91
102 // Copy Temp Variables for Timer to pick up. 92 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd);
103 lock (p_lock) 93 scene.AddNewClient(npcAvatar);
94
95 ScenePresence sp;
96 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
104 { 97 {
105 p_firstname = firstname; 98 m_log.DebugFormat(
106 p_lastname = lastname; 99 "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID);
107 p_position = position; 100
108 p_scene = scene; 101 // Shouldn't call this - temporary.
109 p_cloneAppearanceFrom = cloneAppearanceFrom; 102 sp.CompleteMovement(npcAvatar);
110 p_inUse = true;
111 p_returnUuid = UUID.Zero;
112 }
113 103
114 while (p_returnUuid == UUID.Zero) 104// sp.SendAppearanceToAllOtherAgents();
105//
106// // Send animations back to the avatar as well
107// sp.Animator.SendAnimPack();
108 }
109 else
115 { 110 {
116 Thread.Sleep(250); 111 m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID);
117 } 112 }
118 113
119 m_createMutex.ReleaseMutex(); 114 lock (m_avatars)
115 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
120 116
121 return p_returnUuid; 117 m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", npcAvatar.AgentId);
118
119 return npcAvatar.AgentId;
122 } 120 }
123 121
124 public void Autopilot(UUID agentID, Scene scene, Vector3 pos) 122 public void Autopilot(UUID agentID, Scene scene, Vector3 pos)
@@ -157,69 +155,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC
157 } 155 }
158 } 156 }
159 157
160 void m_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
161 {
162 try
163 {
164 lock (p_lock)
165 {
166 if (p_inUse)
167 {
168 p_inUse = false;
169
170 NPCAvatar npcAvatar = new NPCAvatar(p_firstname, p_lastname, p_position, p_scene);
171 npcAvatar.CircuitCode = (uint) Util.RandomClass.Next(0, int.MaxValue);
172
173 m_log.DebugFormat(
174 "[NPC MODULE]: Creating NPC {0} {1} {2} at {3} in {4}",
175 p_firstname, p_lastname, npcAvatar.AgentId, p_position, p_scene.RegionInfo.RegionName);
176
177 AgentCircuitData acd = new AgentCircuitData();
178 acd.AgentID = npcAvatar.AgentId;
179 acd.firstname = p_firstname;
180 acd.lastname = p_lastname;
181 acd.ServiceURLs = new Dictionary<string, object>();
182
183 AvatarAppearance originalAppearance = GetAppearance(p_cloneAppearanceFrom, p_scene);
184 AvatarAppearance npcAppearance = new AvatarAppearance(originalAppearance, true);
185 acd.Appearance = npcAppearance;
186
187 p_scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd);
188 p_scene.AddNewClient(npcAvatar);
189
190 ScenePresence sp;
191 if (p_scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
192 {
193 m_log.DebugFormat(
194 "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID);
195
196 // Shouldn't call this - temporary.
197 sp.CompleteMovement(npcAvatar);
198
199 // sp.SendAppearanceToAllOtherAgents();
200 //
201 // // Send animations back to the avatar as well
202 // sp.Animator.SendAnimPack();
203 }
204 else
205 {
206 m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID);
207 }
208
209 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
210
211 p_returnUuid = npcAvatar.AgentId;
212
213 m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", p_returnUuid);
214 }
215 }
216 }
217 catch (Exception ex)
218 {
219 m_log.ErrorFormat("[NPC MODULE]: NPC creation failed with exception {0} {1}", ex.Message, ex.StackTrace);
220 }
221 }
222
223 public void PostInitialise() 158 public void PostInitialise()
224 { 159 {
225 } 160 }
@@ -238,4 +173,4 @@ namespace OpenSim.Region.OptionalModules.World.NPC
238 get { return true; } 173 get { return true; }
239 } 174 }
240 } 175 }
241} 176} \ No newline at end of file