* Fleshes more of NPCModule out.

* Implements some OSSL commands:
        key osNpcCreate(string user, string name, vector position, key cloneFrom);
        void osNpcMoveTo(key npc, vector position);
        void osNpcSay(key npc, string message);
        void osNpcRemove(key npc);
* Untested. Requires ThreatLevel.High.
arthursv
Adam Frisby 2009-08-21 11:14:55 +10:00
parent e83b00a3df
commit 01f394d203
4 changed files with 90 additions and 13 deletions

View File

@ -0,0 +1,13 @@
using OpenMetaverse;
using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.CoreModules.Avatar.NPC
{
public interface INPCModule
{
UUID CreateNPC(string firstname, string lastname, Vector3 position, Scene scene, UUID cloneAppearanceFrom);
void Autopilot(UUID agentID, Scene scene, Vector3 pos);
void Say(UUID agentID, Scene scene, string text);
void DeleteNPC(UUID agentID, Scene scene);
}
}

View File

@ -30,18 +30,11 @@ using OpenMetaverse;
using Nini.Config; using Nini.Config;
using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.CoreModules.Avatar.NPC;
using OpenSim.Framework; using OpenSim.Framework;
namespace OpenSim.Region.OptionalModules.World.NPC namespace OpenSim.Region.OptionalModules.World.NPC
{ {
public interface INPCModule
{
UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom);
void Autopilot(UUID agentID, Scene scene, Vector3 pos);
void Say(UUID agentID, Scene scene, string text);
void DeleteNPC(UUID agentID, Scene scene);
}
public class NPCModule : IRegionModule, INPCModule public class NPCModule : IRegionModule, INPCModule
{ {
// private const bool m_enabled = false; // private const bool m_enabled = false;
@ -73,20 +66,33 @@ namespace OpenSim.Region.OptionalModules.World.NPC
} }
public void Autopilot(UUID agentID, Scene scene, Vector3 pos) public void Autopilot(UUID agentID, Scene scene, Vector3 pos)
{
lock (m_avatars)
if (m_avatars.ContainsKey(agentID))
{ {
ScenePresence sp; ScenePresence sp;
scene.TryGetAvatar(agentID, out sp); scene.TryGetAvatar(agentID, out sp);
sp.DoAutoPilot(0, pos, m_avatars[agentID]); sp.DoAutoPilot(0, pos, m_avatars[agentID]);
} }
}
public void Say(UUID agentID, Scene scene, string text) public void Say(UUID agentID, Scene scene, string text)
{
lock (m_avatars)
if (m_avatars.ContainsKey(agentID))
{ {
m_avatars[agentID].Say(text); m_avatars[agentID].Say(text);
} }
}
public void DeleteNPC(UUID agentID, Scene scene) public void DeleteNPC(UUID agentID, Scene scene)
{
lock(m_avatars)
if (m_avatars.ContainsKey(agentID))
{ {
scene.RemoveClient(agentID); scene.RemoveClient(agentID);
m_avatars.Remove(agentID);
}
} }

View File

@ -37,6 +37,7 @@ using OpenSim;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
using OpenSim.Region.CoreModules.Avatar.NPC;
using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.Framework.Scenes.Hypergrid; using OpenSim.Region.Framework.Scenes.Hypergrid;
@ -1762,5 +1763,56 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return retVal; return retVal;
} }
public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom)
{
CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
INPCModule module = World.RequestModuleInterface<INPCModule>();
if (module != null)
{
UUID x = module.CreateNPC(firstname,
lastname,
new Vector3((float) position.x, (float) position.y, (float) position.z),
World,
new UUID(cloneFrom));
return new LSL_Key(x.ToString());
}
return new LSL_Key(UUID.Zero.ToString());
}
public void osNpcMoveTo(LSL_Key npc, LSL_Vector position)
{
CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");
INPCModule module = World.RequestModuleInterface<INPCModule>();
if (module != null)
{
Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
module.Autopilot(new UUID(npc.m_string), World, pos);
}
}
public void osNpcSay(LSL_Key npc, string message)
{
CheckThreatLevel(ThreatLevel.High, "osNpcSay");
INPCModule module = World.RequestModuleInterface<INPCModule>();
if (module != null)
{
module.Say(new UUID(npc.m_string), World, message);
}
}
public void osNpcRemove(LSL_Key npc)
{
CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
INPCModule module = World.RequestModuleInterface<INPCModule>();
if (module != null)
{
module.DeleteNPC(new UUID(npc.m_string), World);
}
}
} }
} }

View File

@ -149,5 +149,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules); LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules);
key osNpcCreate(string user, string name, vector position, key cloneFrom);
void osNpcMoveTo(key npc, vector position);
void osNpcSay(key npc, string message);
void osNpcRemove(key npc);
} }
} }