OpenSim.Framework.AvatarAppearance.SetAttachment C# (CSharp) Method

SetAttachment() public method

Add an attachment, if the attachpoint has the 0x80 bit set then we assume this is an append operation otherwise we replace whatever is currently attached at the attachpoint
public SetAttachment ( int attachpoint, UUID item, UUID asset ) : void
attachpoint int
item UUID
asset UUID
return void
        public void SetAttachment(int attachpoint, UUID item, UUID asset)
        {
            if (attachpoint == 0)
                return;

            if (item == UUID.Zero)
            {
                if (m_attachments.ContainsKey(attachpoint))
                    m_attachments.Remove(attachpoint);
                return;
            }

            // check if this is an append or a replace, 0x80 marks it as an append
            if ((attachpoint & 0x80) > 0)
            {
                // strip the append bit
                int point = attachpoint & 0x7F;
                AppendAttachment(new AvatarAttachment(point, item, asset));
            }
            else
            {
                ReplaceAttachment(new AvatarAttachment(attachpoint,item,asset));
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// This method is called by establishAppearance to copy inventory folders to make
        /// copies of Clothing and Bodyparts inventory folders and attaches worn attachments
        /// </summary>

        private void CopyInventoryFolders(UUID destination, UUID source, AssetType assetType, Dictionary<UUID,UUID> inventoryMap,
                                          AvatarAppearance avatarAppearance)
        {
            IInventoryService inventoryService = m_application.SceneManager.CurrentOrFirstScene.InventoryService;

            InventoryFolderBase sourceFolder = inventoryService.GetFolderForType(source, assetType);
            InventoryFolderBase destinationFolder = inventoryService.GetFolderForType(destination, assetType);

            if (sourceFolder == null || destinationFolder == null)
                throw new Exception("Cannot locate folder(s)");

            // Missing source folder? This should *never* be the case
            if (sourceFolder.Type != (short)assetType)
            {
                sourceFolder = new InventoryFolderBase();
                sourceFolder.ID       = UUID.Random();
                if (assetType == AssetType.Clothing) {
                    sourceFolder.Name     = "Clothing";
                } else {
                    sourceFolder.Name     = "Body Parts";
                }
                sourceFolder.Owner    = source;
                sourceFolder.Type     = (short)assetType;
                sourceFolder.ParentID = inventoryService.GetRootFolder(source).ID;
                sourceFolder.Version  = 1;
                inventoryService.AddFolder(sourceFolder);     // store base record
                m_log.ErrorFormat("[RADMIN] Created folder for source {0}", source);
            }

            // Missing destination folder? This should *never* be the case
            if (destinationFolder.Type != (short)assetType)
            {
                destinationFolder = new InventoryFolderBase();
                destinationFolder.ID       = UUID.Random();
                if (assetType == AssetType.Clothing) {
                    destinationFolder.Name  = "Clothing";
                } else {
                    destinationFolder.Name  = "Body Parts";
                }
                destinationFolder.Owner    = destination;
                destinationFolder.Type     = (short)assetType;
                destinationFolder.ParentID = inventoryService.GetRootFolder(destination).ID;
                destinationFolder.Version  = 1;
                inventoryService.AddFolder(destinationFolder);     // store base record
                m_log.ErrorFormat("[RADMIN]: Created folder for destination {0}", source);
            }

            InventoryFolderBase extraFolder;
            List<InventoryFolderBase> folders = inventoryService.GetFolderContent(source, sourceFolder.ID).Folders;

            foreach (InventoryFolderBase folder in folders)
            {

                extraFolder = new InventoryFolderBase();
                extraFolder.ID = UUID.Random();
                extraFolder.Name = folder.Name;
                extraFolder.Owner = destination;
                extraFolder.Type = folder.Type;
                extraFolder.Version = folder.Version;
                extraFolder.ParentID = destinationFolder.ID;
                inventoryService.AddFolder(extraFolder);

                m_log.DebugFormat("[RADMIN]: Added folder {0} to folder {1}", extraFolder.ID, sourceFolder.ID);

                List<InventoryItemBase> items = inventoryService.GetFolderContent(source, folder.ID).Items;

                foreach (InventoryItemBase item in items)
                {
                    InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
                    destinationItem.Name = item.Name;
                    destinationItem.Owner = destination;
                    destinationItem.Description = item.Description;
                    destinationItem.InvType = item.InvType;
                    destinationItem.CreatorId = item.CreatorId;
                    destinationItem.CreatorIdAsUuid = item.CreatorIdAsUuid;
                    destinationItem.CreatorData = item.CreatorData;
                    destinationItem.NextPermissions = item.NextPermissions;
                    destinationItem.CurrentPermissions = item.CurrentPermissions;
                    destinationItem.BasePermissions = item.BasePermissions;
                    destinationItem.EveryOnePermissions = item.EveryOnePermissions;
                    destinationItem.GroupPermissions = item.GroupPermissions;
                    destinationItem.AssetType = item.AssetType;
                    destinationItem.AssetID = item.AssetID;
                    destinationItem.GroupID = item.GroupID;
                    destinationItem.GroupOwned = item.GroupOwned;
                    destinationItem.SalePrice = item.SalePrice;
                    destinationItem.SaleType = item.SaleType;
                    destinationItem.Flags = item.Flags;
                    destinationItem.CreationDate = item.CreationDate;
                    destinationItem.Folder = extraFolder.ID;
                    ApplyNextOwnerPermissions(destinationItem);

                    m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem);
                    inventoryMap.Add(item.ID, destinationItem.ID);
                    m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, extraFolder.ID);

                    // Attach item, if original is attached
                    int attachpoint = avatarAppearance.GetAttachpoint(item.ID);
                    if (attachpoint != 0)
                    {
                        avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
                        m_log.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
                    }
                }
            }
        }
All Usage Examples Of OpenSim.Framework.AvatarAppearance::SetAttachment