29 using System.Collections.Generic;
30 using System.Reflection;
31 using System.Threading;
39 using OpenSim.Region.Framework.Interfaces;
40 using OpenSim.Region.Framework.Scenes;
41 using OpenSim.Framework;
42 using OpenSim.Services.Interfaces;
46 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"NPCModule")]
49 private static readonly ILog m_log = LogManager.GetLogger(
50 MethodBase.GetCurrentMethod().DeclaringType);
52 private Dictionary<UUID, NPCAvatar> m_avatars =
53 new Dictionary<UUID, NPCAvatar>();
60 public bool Enabled {
get;
private set; }
64 IConfig config = source.Configs[
"NPC"];
66 Enabled = (config != null && config.GetBoolean(
"Enabled",
false));
67 m_NPCOptionFlags = NPCOptionsFlags.None;
70 if(config.GetBoolean(
"AllowNotOwned",
true))
73 if(config.GetBoolean(
"AllowSenseAsAvatar",
true))
76 if(config.GetBoolean(
"AllowCloneOtherAvatars",
true))
79 if(config.GetBoolean(
"NoNPCGroup",
true))
87 scene.RegisterModuleInterface<
INPCModule>(
this);
100 scene.UnregisterModuleInterface<
INPCModule>(
this);
109 get {
return "NPCModule"; }
112 public Type ReplaceableInterface {
get {
return null; } }
124 return m_avatars.ContainsKey(agentId);
135 if (!m_avatars.ContainsKey(agentId))
140 scene.AttachmentsModule.DeleteAttachmentsFromScene(npc,
false);
146 npc.Appearance = npcAppearance;
150 scene.AttachmentsModule.RezAttachments(npc);
154 module.SendAppearance(npc.UUID);
160 Vector3 position, UUID owner,
bool senseAsAgent,
Scene scene,
163 return CreateNPC(firstname, lastname, position,
UUID.Zero, owner, senseAsAgent, scene, appearance);
167 Vector3 position, UUID agentID, UUID owner,
bool senseAsAgent,
Scene scene,
174 if (agentID ==
UUID.Zero)
175 npcAvatar =
new NPCAvatar(firstname, lastname, position,
176 owner, senseAsAgent, scene);
178 npcAvatar =
new NPCAvatar(firstname, lastname, agentID, position,
179 owner, senseAsAgent, scene);
183 m_log.Info(
"[NPC MODULE]: exception creating NPC avatar: " + e.ToString());
187 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
195 acd.AgentID = npcAvatar.AgentId;
196 acd.firstname = firstname;
197 acd.lastname = lastname;
198 acd.ServiceURLs =
new Dictionary<string, object>();
201 acd.Appearance = npcAppearance;
219 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd);
220 scene.AddNewAgent(npcAvatar, PresenceType.Npc);
226 sp.CompleteMovement(npcAvatar,
false);
227 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
238 return npcAvatar.AgentId;
242 bool noFly,
bool landAtTarget,
bool running)
246 if (m_avatars.ContainsKey(agentID))
251 if (sp.IsSatOnObject || sp.SitGround)
259 sp.MoveToTarget(pos, noFly, landAtTarget);
260 sp.SetAlwaysRun = running;
274 if (m_avatars.ContainsKey(agentID))
279 sp.Velocity = Vector3.Zero;
280 sp.ResetMoveToTarget();
290 public bool Say(UUID agentID,
Scene scene,
string text)
292 return Say(agentID, scene, text, 0);
295 public bool Say(UUID agentID,
Scene scene,
string text,
int channel)
299 if (m_avatars.ContainsKey(agentID))
301 m_avatars[agentID].Say(channel, text);
310 public bool Shout(UUID agentID,
Scene scene,
string text,
int channel)
314 if (m_avatars.ContainsKey(agentID))
316 m_avatars[agentID].Shout(channel, text);
325 public bool Sit(UUID agentID, UUID partID,
Scene scene)
329 if (m_avatars.ContainsKey(agentID))
334 sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero);
349 if (m_avatars.ContainsKey(agentID))
351 m_avatars[agentID].Whisper(channel, text);
364 if (m_avatars.ContainsKey(agentID))
379 public bool Touch(UUID agentID, UUID objectID)
383 if (m_avatars.ContainsKey(agentID))
384 return m_avatars[agentID].Touch(objectID);
395 if (m_avatars.TryGetValue(agentID, out av))
406 if (m_avatars.ContainsKey(agentID))
407 return m_avatars[agentID];
415 bool doRemove =
false;
419 if (m_avatars.TryGetValue(agentID, out av))
431 scene.CloseAgent(agentID,
false);
434 m_avatars.Remove(agentID);
436 m_log.DebugFormat(
"[NPC MODULE]: Removed NPC {0} {1}",
452 if (m_avatars.TryGetValue(npcID, out av))
454 if (npcID == callerID)
456 return CheckPermissions(av, callerID);
478 private bool CheckPermissions(
NPCAvatar av, UUID callerID)
480 return callerID == UUID.Zero || av.OwnerID == UUID.Zero ||
481 av.OwnerID == callerID || av.AgentId == callerID;
bool DeleteNPC(UUID agentID, Scene scene)
Delete an NPC.
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
INPC GetNPC(UUID agentID, Scene scene)
Get the NPC.
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
bool Stand(UUID agentID, Scene scene)
Stand a sitting NPC.
bool Say(UUID agentID, Scene scene, string text, int channel)
Get the NPC to say something.
bool CheckPermissions(UUID npcID, UUID callerID)
Check if the caller has permission to manipulate the given NPC.
Contains the Avatar's Appearance and methods to manipulate the appearance.
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
Temporary interface. More methods to come at some point to make NPCs more object oriented rather than...
System.Timers.Timer Timer
bool StopMoveToTarget(UUID agentID, Scene scene)
Stop the NPC's current movement.
bool IsNPC(UUID agentId, Scene scene)
Check if the agent is an NPC.
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
IAttachmentsModule AttachmentsModule
bool Touch(UUID agentID, UUID objectID)
Get the NPC to touch an object.
bool SetNPCAppearance(UUID agentId, AvatarAppearance appearance, Scene scene)
Set the appearance for an NPC.
override bool TryGetScenePresence(UUID agentID, out ScenePresence sp)
Try to get a scene presence from the scene
bool Whisper(UUID agentID, Scene scene, string text, int channel)
Get the NPC to whisper something.
System.Timers.Timer Timer
UUID CreateNPC(string firstname, string lastname, Vector3 position, UUID owner, bool senseAsAgent, Scene scene, AvatarAppearance appearance)
Create an NPC
bool Say(UUID agentID, Scene scene, string text)
Get the NPC to say something.
bool Sit(UUID agentID, UUID partID, Scene scene)
Sit the NPC.
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
UUID GetOwner(UUID agentID)
Get the owner of a NPC
UUID CreateNPC(string firstname, string lastname, Vector3 position, UUID agentID, UUID owner, bool senseAsAgent, Scene scene, AvatarAppearance appearance)
Create an NPC with a user-supplied agentID
bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget, bool running)
Move an NPC to a target over time.
bool Shout(UUID agentID, Scene scene, string text, int channel)
Get the NPC to shout something.