aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs142
1 files changed, 38 insertions, 104 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index 48d236f..3cdd06d 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -34,7 +34,6 @@ using Nini.Config;
34using OpenMetaverse; 34using OpenMetaverse;
35using OpenSim.Region.Framework.Interfaces; 35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes; 36using OpenSim.Region.Framework.Scenes;
37using OpenSim.Region.CoreModules.Avatar.NPC;
38using OpenSim.Framework; 37using OpenSim.Framework;
39using Timer=System.Timers.Timer; 38using Timer=System.Timers.Timer;
40using OpenSim.Services.Interfaces; 39using OpenSim.Services.Interfaces;
@@ -47,31 +46,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC
47 46
48 // private const bool m_enabled = false; 47 // private const bool m_enabled = false;
49 48
50 private Mutex m_createMutex;
51 private Timer m_timer;
52
53 private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); 49 private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>();
54 private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>(); 50 private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>();
55 51
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) 52 public void Initialise(Scene scene, IConfigSource source)
68 { 53 {
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); 54 scene.RegisterModuleInterface<INPCModule>(this);
76 } 55 }
77 56
@@ -90,35 +69,53 @@ namespace OpenSim.Region.OptionalModules.World.NPC
90 return new AvatarAppearance(); 69 return new AvatarAppearance();
91 } 70 }
92 71
93 public UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom) 72 public UUID CreateNPC(string firstname, string lastname, Vector3 position, Scene scene, UUID cloneAppearanceFrom)
94 { 73 {
74 NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, scene);
75 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue);
76
95 m_log.DebugFormat( 77 m_log.DebugFormat(
96 "[NPC MODULE]: Queueing request to create NPC {0} {1} at {2} in {3} cloning appearance of {4}", 78 "[NPC MODULE]: Creating NPC {0} {1} {2} at {3} in {4}",
97 firstname, lastname, position, scene.RegionInfo.RegionName, cloneAppearanceFrom); 79 firstname, lastname, npcAvatar.AgentId, position, scene.RegionInfo.RegionName);
80
81 AgentCircuitData acd = new AgentCircuitData();
82 acd.AgentID = npcAvatar.AgentId;
83 acd.firstname = firstname;
84 acd.lastname = lastname;
85 acd.ServiceURLs = new Dictionary<string, object>();
98 86
99 // Block. 87 AvatarAppearance originalAppearance = GetAppearance(cloneAppearanceFrom, scene);
100 m_createMutex.WaitOne(); 88 AvatarAppearance npcAppearance = new AvatarAppearance(originalAppearance, true);
89 acd.Appearance = npcAppearance;
101 90
102 // Copy Temp Variables for Timer to pick up. 91 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd);
103 lock (p_lock) 92 scene.AddNewClient(npcAvatar);
93
94 ScenePresence sp;
95 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
104 { 96 {
105 p_firstname = firstname; 97 m_log.DebugFormat(
106 p_lastname = lastname; 98 "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID);
107 p_position = position; 99
108 p_scene = scene; 100 // Shouldn't call this - temporary.
109 p_cloneAppearanceFrom = cloneAppearanceFrom; 101 sp.CompleteMovement(npcAvatar);
110 p_inUse = true;
111 p_returnUuid = UUID.Zero;
112 }
113 102
114 while (p_returnUuid == UUID.Zero) 103// sp.SendAppearanceToAllOtherAgents();
104//
105// // Send animations back to the avatar as well
106// sp.Animator.SendAnimPack();
107 }
108 else
115 { 109 {
116 Thread.Sleep(250); 110 m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID);
117 } 111 }
118 112
119 m_createMutex.ReleaseMutex(); 113 lock (m_avatars)
114 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
120 115
121 return p_returnUuid; 116 m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", npcAvatar.AgentId);
117
118 return npcAvatar.AgentId;
122 } 119 }
123 120
124 public void Autopilot(UUID agentID, Scene scene, Vector3 pos) 121 public void Autopilot(UUID agentID, Scene scene, Vector3 pos)
@@ -157,69 +154,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC
157 } 154 }
158 } 155 }
159 156
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() 157 public void PostInitialise()
224 { 158 {
225 } 159 }
@@ -238,4 +172,4 @@ namespace OpenSim.Region.OptionalModules.World.NPC
238 get { return true; } 172 get { return true; }
239 } 173 }
240 } 174 }
241} 175} \ No newline at end of file