From f1846045a6663c0530524d7c91d1ed17bf449c07 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 6 Jan 2012 21:34:43 +0100 Subject: Add osNpcCreateOwned to create an owned NPC. Those can be sensed only by the owner, can be destroyed only by the owner and only the owner can save their appearance. Added "NPC" as a flag to llSensor to sense NPCs and exclude them from "AGENT" results. --- .../Region/OptionalModules/World/NPC/NPCAvatar.cs | 9 ++++++- .../Region/OptionalModules/World/NPC/NPCModule.cs | 28 ++++++++++++++++++---- .../World/NPC/Tests/NPCModuleTests.cs | 10 ++++---- 3 files changed, 36 insertions(+), 11 deletions(-) (limited to 'OpenSim/Region/OptionalModules') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index 6c7a683..b4181a4 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs @@ -42,13 +42,15 @@ namespace OpenSim.Region.OptionalModules.World.NPC private readonly Vector3 m_startPos; private readonly UUID m_uuid = UUID.Random(); private readonly Scene m_scene; + private readonly UUID m_ownerID; - public NPCAvatar(string firstname, string lastname, Vector3 position, Scene scene) + public NPCAvatar(string firstname, string lastname, Vector3 position, UUID ownerID, Scene scene) { m_firstname = firstname; m_lastname = lastname; m_startPos = position; m_scene = scene; + m_ownerID = ownerID; } public IScene Scene @@ -56,6 +58,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC get { return m_scene; } } + public UUID OwnerID + { + get { return m_ownerID; } + } + public ISceneAgent SceneAgent { get { throw new NotImplementedException(); } } public void Say(string message) diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 56ff367..e874417 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -91,9 +91,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC } public UUID CreateNPC( - string firstname, string lastname, Vector3 position, Scene scene, AvatarAppearance appearance) + string firstname, string lastname, Vector3 position, UUID owner, Scene scene, AvatarAppearance appearance) { - NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, scene); + NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, owner, scene); npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); m_log.DebugFormat( @@ -234,12 +234,30 @@ namespace OpenSim.Region.OptionalModules.World.NPC return false; } - public bool DeleteNPC(UUID agentID, Scene scene) + public UUID GetOwner(UUID agentID) { lock (m_avatars) { - if (m_avatars.ContainsKey(agentID)) + NPCAvatar av; + if (m_avatars.TryGetValue(agentID, out av)) { + return av.OwnerID; + } + } + + return UUID.Zero; + } + + public bool DeleteNPC(UUID agentID, UUID callerID, Scene scene) + { + lock (m_avatars) + { + NPCAvatar av; + if (m_avatars.TryGetValue(agentID, out av)) + { + if (av.OwnerID != UUID.Zero && callerID != UUID.Zero && av.OwnerID != callerID) + return false; + scene.RemoveClient(agentID, false); m_avatars.Remove(agentID); @@ -268,4 +286,4 @@ namespace OpenSim.Region.OptionalModules.World.NPC get { return true; } } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index 9c66b25..571d33d 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs @@ -109,7 +109,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests afm.SetAppearance(sp, originalTe, null); INPCModule npcModule = scene.RequestModuleInterface(); - UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, sp.Appearance); + UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, scene, sp.Appearance); ScenePresence npc = scene.GetScenePresence(npcId); @@ -137,7 +137,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests am.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest); INPCModule npcModule = scene.RequestModuleInterface(); - UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, sp.Appearance); + UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, scene, sp.Appearance); ScenePresence npc = scene.GetScenePresence(npcId); @@ -169,7 +169,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Vector3 startPos = new Vector3(128, 128, 30); INPCModule npcModule = scene.RequestModuleInterface(); - UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance); + UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, scene, sp.Appearance); ScenePresence npc = scene.GetScenePresence(npcId); Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); @@ -240,7 +240,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Vector3 startPos = new Vector3(128, 128, 30); INPCModule npcModule = scene.RequestModuleInterface(); - UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance); + UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, scene, sp.Appearance); ScenePresence npc = scene.GetScenePresence(npcId); SceneObjectPart part = SceneHelpers.AddSceneObject(scene); @@ -273,7 +273,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Vector3 startPos = new Vector3(1, 1, 1); INPCModule npcModule = scene.RequestModuleInterface(); - UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance); + UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, scene, sp.Appearance); ScenePresence npc = scene.GetScenePresence(npcId); SceneObjectPart part = SceneHelpers.AddSceneObject(scene); -- cgit v1.1