From 7518b075b76fea062971a9e5fb716118130ebe43 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 6 Jan 2012 22:35:06 +0000 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. --- .../Shared/Api/Implementation/OSSL_Api.cs | 25 ++++++++++++++++++---- .../Api/Implementation/Plugins/SensorRepeat.cs | 20 ++++++++++++++++- .../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 1 + .../Shared/Api/Runtime/LSL_Constants.cs | 1 + .../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 7 +++++- 5 files changed, 48 insertions(+), 6 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index bb0ba3d..c1a700a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2067,10 +2067,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return retVal; } + public LSL_Key osNpcCreateOwned(string firstname, string lastname, LSL_Vector position, string notecard) + { + CheckThreatLevel(ThreatLevel.High, "osNpcCreateOwned"); + return NpcCreate(firstname, lastname, position, notecard, true); + } + public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard) { - CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); + CheckThreatLevel(ThreatLevel.High, "osNpcCreated"); + return NpcCreate(firstname, lastname, position, notecard, false); + } + private LSL_Key NpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, bool owned) + { INPCModule module = World.RequestModuleInterface(); if (module != null) { @@ -2099,11 +2109,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (appearance == null) return new LSL_Key(UUID.Zero.ToString()); + UUID ownerID = UUID.Zero; + if (owned) + ownerID = m_host.OwnerID; UUID x = module.CreateNPC(firstname, lastname, new Vector3((float) position.x, (float) position.y, (float) position.z), - World, - appearance); + ownerID, + World,appearance); return new LSL_Key(x.ToString()); } @@ -2132,6 +2145,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) return new LSL_Key(UUID.Zero.ToString()); + UUID ownerID = npcModule.GetOwner(npcId); + if (ownerID != UUID.Zero && ownerID != m_host.OwnerID) + return new LSL_Key(UUID.Zero.ToString()); + return SaveAppearanceToNotecard(npcId, notecard); } @@ -2311,7 +2328,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule module = World.RequestModuleInterface(); if (module != null) { - module.DeleteNPC(new UUID(npc.m_string), World); + module.DeleteNPC(new UUID(npc.m_string), m_host.OwnerID, World); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index 3eeb23d..7d7813d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs @@ -26,10 +26,13 @@ */ using System; +using System.Reflection; using System.Collections.Generic; using OpenMetaverse; using OpenSim.Framework; +using log4net; +using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Region.ScriptEngine.Shared; using OpenSim.Region.ScriptEngine.Shared.Api; @@ -51,6 +54,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins private const int AGENT = 1; private const int AGENT_BY_USERNAME = 0x10; + private const int NPC = 0x20; private const int ACTIVE = 2; private const int PASSIVE = 4; private const int SCRIPTED = 8; @@ -203,7 +207,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins List sensedEntities = new List(); // Is the sensor type is AGENT and not SCRIPTED then include agents - if ((ts.type & (AGENT | AGENT_BY_USERNAME)) != 0 && (ts.type & SCRIPTED) == 0) + if ((ts.type & (AGENT | AGENT_BY_USERNAME | NPC)) != 0 && (ts.type & SCRIPTED) == 0) { sensedEntities.AddRange(doAgentSensor(ts)); } @@ -413,6 +417,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins private List doAgentSensor(SenseRepeatClass ts) { + INPCModule npcModule = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface(); + List sensedEntities = new List(); // If nobody about quit fast @@ -441,6 +447,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins Action senseEntity = new Action(delegate(ScenePresence presence) { + if ((ts.type & NPC) == 0 && presence.PresenceType == PresenceType.Npc) + return; + if ((ts.type & AGENT) == 0 && presence.PresenceType == PresenceType.User) + return; + if (presence.IsDeleted || presence.IsChildAgent || presence.GodLevel > 0.0) return; @@ -452,6 +463,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins toRegionPos = presence.AbsolutePosition; dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos)); + if (presence.PresenceType == PresenceType.Npc && npcModule != null) + { + UUID npcOwner = npcModule.GetOwner(presence.UUID); + if (npcOwner != UUID.Zero && npcOwner != SensePoint.OwnerID) + return; + } + // are they in range if (dis <= ts.range) { diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index f5ee733..1380ed4 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -172,6 +172,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules); key osNpcCreate(string user, string name, vector position, string notecard); + key osNpcCreateOwned(string user, string name, vector position, string notecard); LSL_Key osNpcSaveAppearance(key npc, string notecard); void osNpcLoadAppearance(key npc, string notecard); vector osNpcGetPos(key npc); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index fd08373..b58cf57 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs @@ -52,6 +52,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase public const int AGENT = 1; public const int AGENT_BY_LEGACY_NAME = 1; public const int AGENT_BY_USERNAME = 0x10; + public const int NPC = 0x20; public const int ACTIVE = 2; public const int PASSIVE = 4; public const int SCRIPTED = 8; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index 0d7d5ea..6572def 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -488,6 +488,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom); } + public key osNpcCreateOwned(string user, string name, vector position, key cloneFrom) + { + return m_OSSL_Functions.osNpcCreateOwned(user, name, position, cloneFrom); + } + public key osNpcSaveAppearance(key npc, string notecard) { return m_OSSL_Functions.osNpcSaveAppearance(npc, notecard); @@ -818,4 +823,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return m_OSSL_Functions.osUnixTimeToTimestamp(time); } } -} \ No newline at end of file +} -- cgit v1.1