From 0c041ce12f393367e2754e88d9b8dad5e45f88c4 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 17 Oct 2011 01:42:31 +0100 Subject: Implement osNpcSit(). This is still in development so don't trust it Format is osNpcSit(, , 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 :) --- OpenSim/Region/Framework/Interfaces/INPCModule.cs | 9 ++++++++ OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 2 -- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 7 ++++--- .../Region/OptionalModules/World/NPC/NPCModule.cs | 18 ++++++++++++++++ .../World/NPC/Tests/NPCModuleTests.cs | 24 ++++++++++++++++++++++ OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 1 + .../Shared/Api/Implementation/OSSL_Api.cs | 11 ++++++++++ .../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 1 + .../Shared/Api/Runtime/LSL_Constants.cs | 2 ++ .../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 +++++ 10 files changed, 75 insertions(+), 5 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Interfaces/INPCModule.cs b/OpenSim/Region/Framework/Interfaces/INPCModule.cs index 5e5c4a1..9dd8c79 100644 --- a/OpenSim/Region/Framework/Interfaces/INPCModule.cs +++ b/OpenSim/Region/Framework/Interfaces/INPCModule.cs @@ -95,6 +95,15 @@ namespace OpenSim.Region.Framework.Interfaces bool Say(UUID agentID, Scene scene, string text); /// + /// Sit the NPC. + /// + /// + /// + /// + /// true if the sit succeeded, false if not + bool Sit(UUID agentID, UUID partID, Scene scene); + + /// /// Delete an NPC. /// /// The UUID of the NPC diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 42cc1ce..703b986 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -1220,14 +1220,12 @@ namespace OpenSim.Region.Framework.Scenes } } - public UUID SitTargetAvatar { get { return m_sitTargetAvatar; } set { m_sitTargetAvatar = value; } } - public virtual UUID RegionID { get diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 972e7fc..dd1a29d 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -615,13 +615,13 @@ namespace OpenSim.Region.Framework.Scenes set { m_isChildAgent = value; } } - private uint m_parentID; - public uint ParentID { get { return m_parentID; } set { m_parentID = value; } } + private uint m_parentID; + public float Health { get { return m_health; } @@ -1962,6 +1962,8 @@ namespace OpenSim.Region.Framework.Scenes ) )); +// m_log.DebugFormat("[SCENE PRESENCE]: {0} {1}", SitTargetisSet, SitTargetUnOccupied); + if (SitTargetisSet && SitTargetUnOccupied) { part.SitTargetAvatar = UUID; @@ -2256,7 +2258,6 @@ namespace OpenSim.Region.Framework.Scenes } */ - public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) { if (!String.IsNullOrEmpty(m_nextSitAnimation)) diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index bcd9e94..be73639 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -199,6 +199,24 @@ namespace OpenSim.Region.OptionalModules.World.NPC 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) { lock (m_avatars) diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index 49c06bc..c5be0b6 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs @@ -229,5 +229,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(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(); + 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)); + } } } \ No newline at end of file diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index fc45b82..ffcb004 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -687,6 +687,7 @@ namespace OpenSim.Region.Physics.OdePlugin /// another geometry or space 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 // Test if we're colliding a geom with a space. diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 268a599..7cf6642 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2351,6 +2351,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(); + if (module != null) + { + module.Sit(new UUID(npc.m_string), new UUID(target.m_string), World); + } + } + public void osNpcRemove(LSL_Key npc) { CheckThreatLevel(ThreatLevel.High, "osNpcRemove"); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 87cfe1a..bb0a870 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -178,6 +178,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces void osNpcSetRot(LSL_Key npc, rotation rot); void osNpcStopMoveToTarget(LSL_Key npc); void osNpcSay(key npc, string message); + void osNpcSit(key npc, key target, int options); void osNpcRemove(key npc); LSL_Key osOwnerSaveAppearance(string notecard); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index 36c5f90..d36b550 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs @@ -600,6 +600,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase public const int OS_NPC_NO_FLY = 1; 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_DENIED = "URL_REQUEST_DENIED"; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index bbc8cc6..38391df 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -528,6 +528,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase 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) { m_OSSL_Functions.osNpcRemove(npc); -- cgit v1.1