From 1c29f3378dd13e8c95eca944e3240e2a874b61fa Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 16 Feb 2021 03:16:54 +0000 Subject: [PATCH] mantis 8865: add experimental osNpcLookAt --- .../Shared/Api/Implementation/OSSL_Api.cs | 58 +++++++++++++++++++ .../Shared/Api/Interface/IOSSL_Api.cs | 2 + .../Shared/Api/Runtime/OSSL_Stub.cs | 5 ++ 3 files changed, 65 insertions(+) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 3f4bbed945..a1905d504e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -6068,5 +6068,63 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } + public LSL_Integer osNpcLookAt(LSL_Key npckey, LSL_Integer ltype, LSL_Key objkey, LSL_Vector offset) + { + if (World.GetNumberOfClients() == 0) + return 0; + + if (ltype < 0 || ltype > 11) + return -1; + + if (!UUID.TryParse(npckey, out UUID npc)) + return -2; + + ScenePresence npcSP = World.GetScenePresence(npc); + if(npc == null) + return -3; + + if (!UUID.TryParse(objkey, out UUID obj)) + return -4; + + if(obj != UUID.Zero) + { + ScenePresence objSP = World.GetScenePresence(obj); + if(objSP == null) + { + SceneObjectPart objSOP = World.GetSceneObjectPart(obj); + if(objSOP == null) + return -5; + } + } + + byte[] data = new byte[57]; + npc.ToBytes(data, 0); + obj.ToBytes(data, 16); + Vector3d vd = new Vector3d(offset.x, offset.y, offset.z); + vd.ToBytes(data, 32); + data[56] = (byte)(int)ltype; + + OpenMetaverse.Packets.ViewerEffectPacket.EffectBlock effect = new OpenMetaverse.Packets.ViewerEffectPacket.EffectBlock(); + effect.AgentID = npc; + effect.Color = new byte[4]; + effect.Duration = 0; + effect.ID = UUID.Random(); + effect.Type = 14; + effect.TypeData = data; + + OpenMetaverse.Packets.ViewerEffectPacket.EffectBlock[] effectblock = new OpenMetaverse.Packets.ViewerEffectPacket.EffectBlock[1]; + effectblock[0] = effect; + + World.ForEachScenePresence( + sp => + { + if(!sp.IsNPC && !sp.IsDeleted) + { + sp.ControllingClient.SendViewerEffect(effectblock); + } + }); + + return 0; + } } } \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 3e079dbc12..105789f4aa 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -589,5 +589,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces void osParticleSystem(LSL_List rules); void osLinkParticleSystem(LSL_Integer linknumber, LSL_List rules); + + LSL_Integer osNpcLookAt(LSL_Key npckey, LSL_Integer type, LSL_Key objkey, vector offset); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index 5edbca66cc..26ff160310 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -1543,5 +1543,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase { m_OSSL_Functions.osLinkParticleSystem(linknumber, rules); } + + public LSL_Integer osNpcLookAt(LSL_Key npckey, LSL_Integer type, LSL_Key objkey, vector offset) + { + return m_OSSL_Functions.osNpcLookAt(npckey, type, objkey, offset); + } } }