From 7bb070be55d0efe3a272f170055bdf02ee41aa65 Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Mon, 29 Jun 2009 18:07:30 +0000 Subject: [PATCH] Thank you kindly, Snowdrop/Snowcrash for a patch that: This patch makes the worn attachments accessible to MRM scripting --- .../Minimodule/Interfaces/IAvatar.cs | 20 +++++++++-- .../Scripting/Minimodule/SPAvatar.cs | 28 +++++++++++++++ .../Minimodule/SPAvatarAttachment.cs | 35 +++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatarAttachment.cs diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IAvatar.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IAvatar.cs index fef85dd9e5..51ba36cad0 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IAvatar.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IAvatar.cs @@ -32,8 +32,24 @@ using OpenMetaverse; namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { - public interface IAvatar : IEntity + public interface IAvatarAttachment { - + //// + /// Describes where on the avatar the attachment is located + /// + int Location { get ; } + + //// + /// Accessor to the rez'ed asset, representing the attachment + /// + IObject Asset { get; } + } + + public interface IAvatar : IEntity + { + //// + /// Array of worn attachments, empty but not null, if no attachments are worn + /// + IAvatarAttachment[] Attachments { get; } } } diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs index 8fed89c638..6fd36bf821 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs @@ -26,15 +26,22 @@ */ using System; +using System.Reflection; +using System.Collections; +using System.Collections.Generic; + using OpenMetaverse; using OpenSim.Region.Framework.Scenes; +using log4net; + namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { class SPAvatar : System.MarshalByRefObject, IAvatar { private readonly Scene m_rootScene; private readonly UUID m_ID; + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public SPAvatar(Scene scene, UUID ID) { @@ -63,5 +70,26 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule get { return GetSP().AbsolutePosition; } set { GetSP().TeleportWithMomentum(value); } } + + #region IAvatar implementation + public IAvatarAttachment[] Attachments + { + get { + List attachments = new List(); + + Hashtable internalAttachments = GetSP().Appearance.GetAttachments(); + if(internalAttachments != null) + { + foreach(DictionaryEntry element in internalAttachments) + { + Hashtable attachInfo = (Hashtable)element.Value; + attachments.Add(new SPAvatarAttachment(m_rootScene, this, (int)element.Key, new UUID((string)attachInfo["item"]), new UUID((string)attachInfo["asset"]))); + } + } + + return attachments.ToArray(); + } + } + #endregion } } diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatarAttachment.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatarAttachment.cs new file mode 100644 index 0000000000..5581fc34a5 --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatarAttachment.cs @@ -0,0 +1,35 @@ +using System; + +using OpenMetaverse; +using OpenSim.Region.Framework.Scenes; + +namespace OpenSim.Region.OptionalModules.Scripting.Minimodule +{ + public class SPAvatarAttachment : IAvatarAttachment + { + private readonly Scene m_rootScene; + private readonly IAvatar m_parent; + private readonly int m_location; + private readonly UUID m_itemId; + private readonly UUID m_assetId; + + public SPAvatarAttachment(Scene rootScene, IAvatar self, int location, UUID itemId, UUID assetId) + { + m_rootScene = rootScene; + m_parent = self; + m_location = location; + m_itemId = itemId; + m_assetId = assetId; + } + + public int Location { get { return m_location; } } + + public IObject Asset + { + get + { + return new SOPObject(m_rootScene, m_rootScene.GetSceneObjectPart(m_assetId).LocalId); + } + } + } +}