Implement osNpcSit(). This is still in development so don't trust it

Format is osNpcSit(<npc-uuid>, <target-uuid>, OS_NPC_SIT_IMMEDIATE)
e.g. osNpcSit(npc, llGetKey(), OS_NPC_SIT_IMMEDIATE);
At the moment, sit only succeeds if the part has a sit target set.
NPC immediately sits on the target even if miles away - they do not walk up to it.
This method is in development - it may change so please don't trust it yet.
Standing will follow shortly since that's kind of important once you're sitting :)
0.7.2-post-fixes
Justin Clark-Casey (justincc) 2011-10-17 01:42:31 +01:00
parent af564291f2
commit 1c66e08964
10 changed files with 75 additions and 5 deletions

View File

@ -94,6 +94,15 @@ namespace OpenSim.Region.Framework.Interfaces
/// <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); bool Say(UUID agentID, Scene scene, string text);
/// <summary>
/// Sit the NPC.
/// </summary>
/// <param name="agentID"></param>
/// <param name="partID"></param>
/// <param name="scene"></param>
/// <returns>true if the sit succeeded, false if not</returns>
bool Sit(UUID agentID, UUID partID, Scene scene);
/// <summary> /// <summary>
/// Delete an NPC. /// Delete an NPC.
/// </summary> /// </summary>

View File

@ -1220,14 +1220,12 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
public UUID SitTargetAvatar public UUID SitTargetAvatar
{ {
get { return m_sitTargetAvatar; } get { return m_sitTargetAvatar; }
set { m_sitTargetAvatar = value; } set { m_sitTargetAvatar = value; }
} }
public virtual UUID RegionID public virtual UUID RegionID
{ {
get get

View File

@ -609,13 +609,13 @@ namespace OpenSim.Region.Framework.Scenes
set { m_isChildAgent = value; } set { m_isChildAgent = value; }
} }
private uint m_parentID;
public uint ParentID public uint ParentID
{ {
get { return m_parentID; } get { return m_parentID; }
set { m_parentID = value; } set { m_parentID = value; }
} }
private uint m_parentID;
public float Health public float Health
{ {
get { return m_health; } get { return m_health; }
@ -1936,6 +1936,8 @@ namespace OpenSim.Region.Framework.Scenes
) )
)); ));
// m_log.DebugFormat("[SCENE PRESENCE]: {0} {1}", SitTargetisSet, SitTargetUnOccupied);
if (SitTargetisSet && SitTargetUnOccupied) if (SitTargetisSet && SitTargetUnOccupied)
{ {
part.SitTargetAvatar = UUID; part.SitTargetAvatar = UUID;
@ -2230,7 +2232,6 @@ namespace OpenSim.Region.Framework.Scenes
} }
*/ */
public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) public void HandleAgentSit(IClientAPI remoteClient, UUID agentID)
{ {
if (!String.IsNullOrEmpty(m_nextSitAnimation)) if (!String.IsNullOrEmpty(m_nextSitAnimation))

View File

@ -199,6 +199,24 @@ namespace OpenSim.Region.OptionalModules.World.NPC
return false; return false;
} }
public bool Sit(UUID agentID, UUID partID, Scene scene)
{
lock (m_avatars)
{
if (m_avatars.ContainsKey(agentID))
{
ScenePresence sp;
scene.TryGetScenePresence(agentID, out sp);
sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero);
sp.HandleAgentSit(m_avatars[agentID], agentID);
return true;
}
}
return false;
}
public bool DeleteNPC(UUID agentID, Scene scene) public bool DeleteNPC(UUID agentID, Scene scene)
{ {
lock (m_avatars) lock (m_avatars)

View File

@ -231,5 +231,29 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on second move"); Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on second move");
Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos)); Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
} }
[Test]
public void TestSit()
{
TestHelpers.InMethod();
// log4net.Config.XmlConfigurator.Configure();
ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
Vector3 startPos = new Vector3(128, 128, 30);
INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance);
ScenePresence npc = scene.GetScenePresence(npcId);
SceneObjectPart part = SceneHelpers.AddSceneObject(scene);
// We must have a non Vector3.Zero sit target position otherwise part.SitTargetAvatar doesn't get set!
part.SitTargetPosition = new Vector3(0, 0, 1);
npcModule.Sit(npc.UUID, part.UUID, scene);
// Assertions?
Assert.That(part.SitTargetAvatar, Is.EqualTo(npcId));
Assert.That(npc.ParentID, Is.EqualTo(part.LocalId));
}
} }
} }

View File

@ -687,6 +687,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// <param name="g2">another geometry or space</param> /// <param name="g2">another geometry or space</param>
private void near(IntPtr space, IntPtr g1, IntPtr g2) private void near(IntPtr space, IntPtr g1, IntPtr g2)
{ {
// m_log.DebugFormat("[PHYSICS]: Colliding {0} and {1} in {2}", g1, g2, space);
// no lock here! It's invoked from within Simulate(), which is thread-locked // no lock here! It's invoked from within Simulate(), which is thread-locked
// Test if we're colliding a geom with a space. // Test if we're colliding a geom with a space.

View File

@ -2344,6 +2344,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
} }
} }
public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
{
CheckThreatLevel(ThreatLevel.High, "osNpcSit");
INPCModule module = World.RequestModuleInterface<INPCModule>();
if (module != null)
{
module.Sit(new UUID(npc.m_string), new UUID(target.m_string), World);
}
}
public void osNpcRemove(LSL_Key npc) public void osNpcRemove(LSL_Key npc)
{ {
CheckThreatLevel(ThreatLevel.High, "osNpcRemove"); CheckThreatLevel(ThreatLevel.High, "osNpcRemove");

View File

@ -178,6 +178,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
void osNpcSetRot(LSL_Key npc, rotation rot); void osNpcSetRot(LSL_Key npc, rotation rot);
void osNpcStopMoveToTarget(LSL_Key npc); void osNpcStopMoveToTarget(LSL_Key npc);
void osNpcSay(key npc, string message); void osNpcSay(key npc, string message);
void osNpcSit(key npc, key target, int options);
void osNpcRemove(key npc); void osNpcRemove(key npc);
LSL_Key osOwnerSaveAppearance(string notecard); LSL_Key osOwnerSaveAppearance(string notecard);

View File

@ -596,6 +596,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
public const int OS_NPC_NO_FLY = 1; public const int OS_NPC_NO_FLY = 1;
public const int OS_NPC_LAND_AT_TARGET = 2; public const int OS_NPC_LAND_AT_TARGET = 2;
public const int OS_NPC_SIT_IMMEDIATE = 0;
public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED"; public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED";
public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED"; public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED";

View File

@ -528,6 +528,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
m_OSSL_Functions.osNpcSay(npc, message); m_OSSL_Functions.osNpcSay(npc, message);
} }
public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
{
m_OSSL_Functions.osNpcSit(npc, target, options);
}
public void osNpcRemove(key npc) public void osNpcRemove(key npc)
{ {
m_OSSL_Functions.osNpcRemove(npc); m_OSSL_Functions.osNpcRemove(npc);