diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | 99 |
1 files changed, 74 insertions, 25 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 3b94dff..ced82e6 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | |||
@@ -52,6 +52,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
52 | private Dictionary<UUID, NPCAvatar> m_avatars = | 52 | private Dictionary<UUID, NPCAvatar> m_avatars = |
53 | new Dictionary<UUID, NPCAvatar>(); | 53 | new Dictionary<UUID, NPCAvatar>(); |
54 | 54 | ||
55 | |||
56 | |||
57 | private NPCOptionsFlags m_NPCOptionFlags; | ||
58 | public NPCOptionsFlags NPCOptionFlags {get {return m_NPCOptionFlags;}} | ||
59 | |||
55 | public bool Enabled { get; private set; } | 60 | public bool Enabled { get; private set; } |
56 | 61 | ||
57 | public void Initialise(IConfigSource source) | 62 | public void Initialise(IConfigSource source) |
@@ -59,6 +64,21 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
59 | IConfig config = source.Configs["NPC"]; | 64 | IConfig config = source.Configs["NPC"]; |
60 | 65 | ||
61 | Enabled = (config != null && config.GetBoolean("Enabled", false)); | 66 | Enabled = (config != null && config.GetBoolean("Enabled", false)); |
67 | m_NPCOptionFlags = NPCOptionsFlags.None; | ||
68 | if(Enabled) | ||
69 | { | ||
70 | if(config.GetBoolean("AllowNotOwned", true)) | ||
71 | m_NPCOptionFlags |= NPCOptionsFlags.AllowNotOwned; | ||
72 | |||
73 | if(config.GetBoolean("AllowSenseAsAvatar", true)) | ||
74 | m_NPCOptionFlags |= NPCOptionsFlags.AllowSenseAsAvatar; | ||
75 | |||
76 | if(config.GetBoolean("AllowCloneOtherAvatars", true)) | ||
77 | m_NPCOptionFlags |= NPCOptionsFlags.AllowCloneOtherAvatars; | ||
78 | |||
79 | if(config.GetBoolean("NoNPCGroup", true)) | ||
80 | m_NPCOptionFlags |= NPCOptionsFlags.NoNPCGroup; | ||
81 | } | ||
62 | } | 82 | } |
63 | 83 | ||
64 | public void AddRegion(Scene scene) | 84 | public void AddRegion(Scene scene) |
@@ -137,17 +157,18 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
137 | } | 157 | } |
138 | 158 | ||
139 | public UUID CreateNPC(string firstname, string lastname, | 159 | public UUID CreateNPC(string firstname, string lastname, |
140 | Vector3 position, UUID owner, bool senseAsAgent, Scene scene, | 160 | Vector3 position, UUID owner, bool senseAsAgent, Scene scene, |
141 | AvatarAppearance appearance) | 161 | AvatarAppearance appearance) |
142 | { | 162 | { |
143 | return CreateNPC(firstname, lastname, position, UUID.Zero, owner, senseAsAgent, scene, appearance); | 163 | return CreateNPC(firstname, lastname, position, UUID.Zero, owner, "", UUID.Zero, senseAsAgent, scene, appearance); |
144 | } | 164 | } |
145 | 165 | ||
146 | public UUID CreateNPC(string firstname, string lastname, | 166 | public UUID CreateNPC(string firstname, string lastname, |
147 | Vector3 position, UUID agentID, UUID owner, bool senseAsAgent, Scene scene, | 167 | Vector3 position, UUID agentID, UUID owner, string groupTitle, UUID groupID, bool senseAsAgent, Scene scene, |
148 | AvatarAppearance appearance) | 168 | AvatarAppearance appearance) |
149 | { | 169 | { |
150 | NPCAvatar npcAvatar = null; | 170 | NPCAvatar npcAvatar = null; |
171 | string born = DateTime.UtcNow.ToString(); | ||
151 | 172 | ||
152 | try | 173 | try |
153 | { | 174 | { |
@@ -167,10 +188,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
167 | npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, | 188 | npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, |
168 | int.MaxValue); | 189 | int.MaxValue); |
169 | 190 | ||
170 | m_log.DebugFormat( | 191 | // m_log.DebugFormat( |
171 | "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}", | 192 | // "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}", |
172 | firstname, lastname, npcAvatar.AgentId, owner, | 193 | // firstname, lastname, npcAvatar.AgentId, owner, senseAsAgent, position, scene.RegionInfo.RegionName); |
173 | senseAsAgent, position, scene.RegionInfo.RegionName); | ||
174 | 194 | ||
175 | AgentCircuitData acd = new AgentCircuitData(); | 195 | AgentCircuitData acd = new AgentCircuitData(); |
176 | acd.AgentID = npcAvatar.AgentId; | 196 | acd.AgentID = npcAvatar.AgentId; |
@@ -181,30 +201,44 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
181 | AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); | 201 | AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); |
182 | acd.Appearance = npcAppearance; | 202 | acd.Appearance = npcAppearance; |
183 | 203 | ||
184 | lock (m_avatars) | 204 | /* |
205 | for (int i = 0; | ||
206 | i < acd.Appearance.Texture.FaceTextures.Length; i++) | ||
185 | { | 207 | { |
186 | scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, | 208 | m_log.DebugFormat( |
187 | acd); | 209 | "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}", |
188 | scene.AddNewAgent(npcAvatar, PresenceType.Npc); | 210 | acd.AgentID, i, |
211 | acd.Appearance.Texture.FaceTextures[i]); | ||
212 | } | ||
213 | */ | ||
189 | 214 | ||
190 | ScenePresence sp; | 215 | // ManualResetEvent ev = new ManualResetEvent(false); |
191 | if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) | ||
192 | { | ||
193 | sp.CompleteMovement(npcAvatar, false); | ||
194 | m_avatars.Add(npcAvatar.AgentId, npcAvatar); | ||
195 | m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name); | ||
196 | 216 | ||
197 | return npcAvatar.AgentId; | 217 | // Util.FireAndForget(delegate(object x) { |
198 | } | 218 | lock (m_avatars) |
199 | else | ||
200 | { | 219 | { |
201 | m_log.WarnFormat( | 220 | scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); |
202 | "[NPC MODULE]: Could not find scene presence for NPC {0} {1}", | 221 | scene.AddNewAgent(npcAvatar, PresenceType.Npc); |
203 | sp.Name, sp.UUID); | ||
204 | 222 | ||
205 | return UUID.Zero; | 223 | ScenePresence sp; |
224 | if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) | ||
225 | { | ||
226 | npcAvatar.Born = born; | ||
227 | npcAvatar.ActiveGroupId = groupID; | ||
228 | sp.CompleteMovement(npcAvatar, false); | ||
229 | sp.Grouptitle = groupTitle; | ||
230 | m_avatars.Add(npcAvatar.AgentId, npcAvatar); | ||
231 | // m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name); | ||
232 | } | ||
206 | } | 233 | } |
207 | } | 234 | // ev.Set(); |
235 | // }); | ||
236 | |||
237 | // ev.WaitOne(); | ||
238 | |||
239 | // m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", npcAvatar.AgentId); | ||
240 | |||
241 | return npcAvatar.AgentId; | ||
208 | } | 242 | } |
209 | 243 | ||
210 | public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, | 244 | public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, |
@@ -220,6 +254,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
220 | if (sp.IsSatOnObject || sp.SitGround) | 254 | if (sp.IsSatOnObject || sp.SitGround) |
221 | return false; | 255 | return false; |
222 | 256 | ||
257 | // m_log.DebugFormat( | ||
258 | // "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", | ||
259 | // sp.Name, pos, scene.RegionInfo.RegionName, | ||
260 | // noFly, landAtTarget); | ||
261 | |||
223 | sp.MoveToTarget(pos, noFly, landAtTarget); | 262 | sp.MoveToTarget(pos, noFly, landAtTarget); |
224 | sp.SetAlwaysRun = running; | 263 | sp.SetAlwaysRun = running; |
225 | 264 | ||
@@ -382,6 +421,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
382 | { | 421 | { |
383 | if (m_avatars.TryGetValue(agentID, out av)) | 422 | if (m_avatars.TryGetValue(agentID, out av)) |
384 | { | 423 | { |
424 | /* | ||
425 | m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", | ||
426 | agentID, av.Name); | ||
427 | */ | ||
385 | doRemove = true; | 428 | doRemove = true; |
386 | } | 429 | } |
387 | } | 430 | } |
@@ -410,9 +453,15 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
410 | { | 453 | { |
411 | NPCAvatar av; | 454 | NPCAvatar av; |
412 | if (m_avatars.TryGetValue(npcID, out av)) | 455 | if (m_avatars.TryGetValue(npcID, out av)) |
456 | { | ||
457 | if (npcID == callerID) | ||
458 | return true; | ||
413 | return CheckPermissions(av, callerID); | 459 | return CheckPermissions(av, callerID); |
460 | } | ||
414 | else | 461 | else |
462 | { | ||
415 | return false; | 463 | return false; |
464 | } | ||
416 | } | 465 | } |
417 | } | 466 | } |
418 | 467 | ||