document & 80-character width terminal formatting

Signed-off-by: Diva Canto <diva@metaverseink.com>
integration
SignpostMarv 2012-11-11 20:42:55 +00:00 committed by Diva Canto
parent 23605cf93d
commit f560d581bb
2 changed files with 158 additions and 85 deletions

View File

@ -32,14 +32,16 @@ using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.Framework.Interfaces
{
/// <summary>
/// Temporary interface. More methods to come at some point to make NPCs more object oriented rather than
/// controlling purely through module level interface calls (e.g. sit/stand).
/// Temporary interface. More methods to come at some point to make NPCs
/// more object oriented rather than controlling purely through module
/// level interface calls (e.g. sit/stand).
/// </summary>
public interface INPC
{
/// <summary>
/// Should this NPC be sensed by LSL sensors as an 'agent' (interpreted here to mean a normal user)
/// rather than an OpenSim specific NPC extension?
/// Should this NPC be sensed by LSL sensors as an 'agent'
/// (interpreted here to mean a normal user) rather than an OpenSim
/// specific NPC extension?
/// </summary>
bool SenseAsAgent { get; }
}
@ -53,35 +55,42 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="lastname"></param>
/// <param name="position"></param>
/// <param name="senseAsAgent">
/// Make the NPC show up as an agent on LSL sensors. The default is that they
/// show up as the NPC type instead, but this is currently an OpenSim-only extension.
/// Make the NPC show up as an agent on LSL sensors. The default is
/// that they show up as the NPC type instead, but this is currently
/// an OpenSim-only extension.
/// </param>
/// <param name="scene"></param>
/// <param name="appearance">The avatar appearance to use for the new NPC.</param>
/// <returns>The UUID of the ScenePresence created. UUID.Zero if there was a failure.</returns>
UUID CreateNPC(
string firstname,
string lastname,
Vector3 position,
UUID owner,
bool senseAsAgent,
Scene scene,
AvatarAppearance appearance);
/// <param name="appearance">
/// The avatar appearance to use for the new NPC.
/// </param>
/// <returns>
/// The UUID of the ScenePresence created. UUID.Zero if there was a
/// failure.
/// </returns>
UUID CreateNPC(string firstname, string lastname, Vector3 position,
UUID owner, bool senseAsAgent, Scene scene,
AvatarAppearance appearance);
/// <summary>
/// Check if the agent is an NPC.
/// </summary>
/// <param name="agentID"></param>
/// <param name="scene"></param>
/// <returns>True if the agent is an NPC in the given scene. False otherwise.</returns>
/// <returns>
/// True if the agent is an NPC in the given scene. False otherwise.
/// </returns>
bool IsNPC(UUID agentID, Scene scene);
/// <summary>
/// Get the NPC. This is not currently complete - manipulation of NPCs still occurs through the region interface
/// Get the NPC.
/// </summary>
/// <remarks>
/// This is not currently complete - manipulation of NPCs still occurs
/// through the region interface.
/// </remarks>
/// <param name="agentID"></param>
/// <param name="scene"></param>
/// <returns>The NPC. null if it does not exist.</returns>
/// <returns>The NPC. null if it does not exist.</returns>
INPC GetNPC(UUID agentID, Scene scene);
/// <summary>
@ -89,7 +98,10 @@ namespace OpenSim.Region.Framework.Interfaces
/// </summary>
/// <param name="npcID"></param>
/// <param name="callerID"></param>
/// <returns>true if they do, false if they don't or if there's no NPC with the given ID.</returns>
/// <returns>
/// true if they do, false if they don't or if there's no NPC with the
/// given ID.
/// </returns>
bool CheckPermissions(UUID npcID, UUID callerID);
/// <summary>
@ -98,8 +110,12 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="agentID"></param>
/// <param name="appearance"></param>
/// <param name="scene"></param>
/// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
bool SetNPCAppearance(UUID agentID, AvatarAppearance appearance, Scene scene);
/// <returns>
/// True if the operation succeeded, false if there was no such agent
/// or the agent was not an NPC.
/// </returns>
bool SetNPCAppearance(UUID agentID, AvatarAppearance appearance,
Scene scene);
/// <summary>
/// Move an NPC to a target over time.
@ -108,23 +124,29 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="scene"></param>
/// <param name="pos"></param>
/// <param name="noFly">
/// If true, then the avatar will attempt to walk to the location even if it's up in the air.
/// This is to allow walking on prims.
/// If true, then the avatar will attempt to walk to the location even
/// if it's up in the air. This is to allow walking on prims.
/// </param>
/// <param name="landAtTarget">
/// If true and the avatar is flying when it reaches the target, land.
/// </param> name="running">
/// If true, NPC moves with running speed.
/// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
///
bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget, bool running);
/// <returns>
/// True if the operation succeeded, false if there was no such agent
/// or the agent was not an NPC.
/// </returns>
bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly,
bool landAtTarget, bool running);
/// <summary>
/// Stop the NPC's current movement.
/// </summary>
/// <param name="agentID">The UUID of the NPC</param>
/// <param name="scene"></param>
/// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
/// <returns>
/// True if the operation succeeded, false if there was no such agent
/// or the agent was not an NPC.
/// </returns>
bool StopMoveToTarget(UUID agentID, Scene scene);
/// <summary>
@ -133,7 +155,10 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="agentID">The UUID of the NPC</param>
/// <param name="scene"></param>
/// <param name="text"></param>
/// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
/// <returns>
/// True if the operation succeeded, false if there was no such agent
/// or the agent was not an NPC.
/// </returns>
bool Say(UUID agentID, Scene scene, string text);
/// <summary>
@ -143,7 +168,10 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="scene"></param>
/// <param name="text"></param>
/// <param name="channel"></param>
/// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
/// <returns>
/// True if the operation succeeded, false if there was no such agent
/// or the agent was not an NPC.
/// </returns>
bool Say(UUID agentID, Scene scene, string text, int channel);
/// <summary>
@ -153,7 +181,10 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="scene"></param>
/// <param name="text"></param>
/// <param name="channel"></param>
/// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
/// <returns>
/// True if the operation succeeded, false if there was no such agent
/// or the agent was not an NPC.
/// </returns>
bool Shout(UUID agentID, Scene scene, string text, int channel);
/// <summary>
@ -163,7 +194,10 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="scene"></param>
/// <param name="text"></param>
/// <param name="channel"></param>
/// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
/// <returns>
/// True if the operation succeeded, false if there was no such agent
/// or the agent was not an NPC.
/// </returns>
bool Whisper(UUID agentID, Scene scene, string text, int channel);
/// <summary>
@ -188,7 +222,9 @@ namespace OpenSim.Region.Framework.Interfaces
/// </summary>
/// <param name="agentID"></param>
/// <param name="partID"></param>
/// <returns>true if the touch is actually attempted, false if not</returns>
/// <returns>
/// true if the touch is actually attempted, false if not.
/// </returns>
bool Touch(UUID agentID, UUID partID);
/// <summary>
@ -196,14 +232,20 @@ namespace OpenSim.Region.Framework.Interfaces
/// </summary>
/// <param name="agentID">The UUID of the NPC</param>
/// <param name="scene"></param>
/// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
/// <returns>
/// True if the operation succeeded, false if there was no such agent
/// or the agent was not an NPC.
/// </returns>
bool DeleteNPC(UUID agentID, Scene scene);
/// <summary>
/// Get the owner of a NPC
/// </summary>
/// <param name="agentID">The UUID of the NPC</param>
/// <returns>UUID of owner if the NPC exists, UUID.Zero if there was no such agent, the agent is unowned or the agent was not an NPC</returns>
/// <returns>
/// UUID of owner if the NPC exists, UUID.Zero if there was no such
/// agent, the agent is unowned or the agent was not an NPC.
/// </returns>
UUID GetOwner(UUID agentID);
}
}
}

View File

@ -29,14 +29,16 @@ using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using Timer = System.Timers.Timer;
using log4net;
using Nini.Config;
using Mono.Addins;
using OpenMetaverse;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Framework;
using Timer=System.Timers.Timer;
using OpenSim.Services.Interfaces;
namespace OpenSim.Region.OptionalModules.World.NPC
@ -44,9 +46,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
public class NPCModule : INPCModule, ISharedRegionModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ILog m_log = LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private Dictionary<UUID, NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>();
private Dictionary<UUID, NPCAvatar> m_avatars =
new Dictionary<UUID, NPCAvatar>();
public bool Enabled { get; private set; }
@ -89,8 +93,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC
public bool IsNPC(UUID agentId, Scene scene)
{
// FIXME: This implementation could not just use the ScenePresence.PresenceType (and callers could inspect
// that directly).
// FIXME: This implementation could not just use the
// ScenePresence.PresenceType (and callers could inspect that
// directly).
ScenePresence sp = scene.GetScenePresence(agentId);
if (sp == null || sp.IsChildAgent)
return false;
@ -99,7 +104,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
return m_avatars.ContainsKey(agentId);
}
public bool SetNPCAppearance(UUID agentId, AvatarAppearance appearance, Scene scene)
public bool SetNPCAppearance(UUID agentId,
AvatarAppearance appearance, Scene scene)
{
ScenePresence npc = scene.GetScenePresence(agentId);
if (npc == null || npc.IsChildAgent)
@ -112,34 +118,35 @@ namespace OpenSim.Region.OptionalModules.World.NPC
// Delete existing npc attachments
scene.AttachmentsModule.DeleteAttachmentsFromScene(npc, false);
// XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet since it doesn't transfer attachments
AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true);
// XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet
// since it doesn't transfer attachments
AvatarAppearance npcAppearance = new AvatarAppearance(appearance,
true);
npc.Appearance = npcAppearance;
// Rez needed npc attachments
scene.AttachmentsModule.RezAttachments(npc);
IAvatarFactoryModule module = scene.RequestModuleInterface<IAvatarFactoryModule>();
IAvatarFactoryModule module =
scene.RequestModuleInterface<IAvatarFactoryModule>();
module.SendAppearance(npc.UUID);
return true;
}
public UUID CreateNPC(
string firstname,
string lastname,
Vector3 position,
UUID owner,
bool senseAsAgent,
Scene scene,
AvatarAppearance appearance)
public UUID CreateNPC(string firstname, string lastname,
Vector3 position, UUID owner, bool senseAsAgent, Scene scene,
AvatarAppearance appearance)
{
NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, owner, senseAsAgent, scene);
npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue);
NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position,
owner, senseAsAgent, scene);
npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
int.MaxValue);
m_log.DebugFormat(
"[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}",
firstname, lastname, npcAvatar.AgentId, owner, senseAsAgent, position, scene.RegionInfo.RegionName);
"[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}",
firstname, lastname, npcAvatar.AgentId, owner,
senseAsAgent, position, scene.RegionInfo.RegionName);
AgentCircuitData acd = new AgentCircuitData();
acd.AgentID = npcAvatar.AgentId;
@ -147,42 +154,55 @@ namespace OpenSim.Region.OptionalModules.World.NPC
acd.lastname = lastname;
acd.ServiceURLs = new Dictionary<string, object>();
AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true);
AvatarAppearance npcAppearance = new AvatarAppearance(appearance,
true);
acd.Appearance = npcAppearance;
// for (int i = 0; i < acd.Appearance.Texture.FaceTextures.Length; i++)
// {
// m_log.DebugFormat(
// "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}",
// acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]);
// }
/*
for (int i = 0;
i < acd.Appearance.Texture.FaceTextures.Length; i++)
{
m_log.DebugFormat(
"[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}",
acd.AgentID, i,
acd.Appearance.Texture.FaceTextures[i]);
}
*/
lock (m_avatars)
{
scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd);
scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode,
acd);
scene.AddNewClient(npcAvatar, PresenceType.Npc);
ScenePresence sp;
if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
{
// m_log.DebugFormat(
// "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID);
/*
m_log.DebugFormat(
"[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}",
sp.Name, sp.UUID);
*/
sp.CompleteMovement(npcAvatar, false);
m_avatars.Add(npcAvatar.AgentId, npcAvatar);
m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name);
m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}",
npcAvatar.AgentId, sp.Name);
return npcAvatar.AgentId;
}
else
{
m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID);
m_log.WarnFormat(
"[NPC MODULE]: Could not find scene presence for NPC {0} {1}",
sp.Name, sp.UUID);
return UUID.Zero;
}
}
}
public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget, bool running)
public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos,
bool noFly, bool landAtTarget, bool running)
{
lock (m_avatars)
{
@ -192,12 +212,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC
if (scene.TryGetScenePresence(agentID, out sp))
{
m_log.DebugFormat(
"[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}",
sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget);
"[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}",
sp.Name, pos, scene.RegionInfo.RegionName,
noFly, landAtTarget);
sp.MoveToTarget(pos, noFly, landAtTarget);
sp.SetAlwaysRun = running;
return true;
}
}
@ -270,9 +291,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
ScenePresence sp;
if (scene.TryGetScenePresence(agentID, out sp))
{
sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero);
// sp.HandleAgentSit(m_avatars[agentID], agentID);
sp.HandleAgentRequestSit(m_avatars[agentID], agentID,
partID, Vector3.Zero);
//sp.HandleAgentSit(m_avatars[agentID], agentID);
return true;
}
}
@ -281,7 +303,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
return false;
}
public bool Whisper(UUID agentID, Scene scene, string text, int channel)
public bool Whisper(UUID agentID, Scene scene, string text,
int channel)
{
lock (m_avatars)
{
@ -356,16 +379,23 @@ namespace OpenSim.Region.OptionalModules.World.NPC
NPCAvatar av;
if (m_avatars.TryGetValue(agentID, out av))
{
// m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", agentID, av.Name);
/*
m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove",
agentID, av.Name);
*/
scene.RemoveClient(agentID, false);
m_avatars.Remove(agentID);
m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", agentID, av.Name);
/*
m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}",
agentID, av.Name);
*/
return true;
}
}
// m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove", agentID);
/*
m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove",
agentID);
*/
return false;
}
@ -389,7 +419,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
/// <returns>true if they do, false if they don't.</returns>
private bool CheckPermissions(NPCAvatar av, UUID callerID)
{
return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID;
return callerID == UUID.Zero || av.OwnerID == UUID.Zero ||
av.OwnerID == callerID;
}
}
}