public AvatarAppearance FixCurrentOutFitFolder(UUID user, AvatarAppearance avappearance) { InventoryFolderBase CurrentOutFitFolder = m_InventoryService.GetFolderForType(user, 0, AssetType.CurrentOutfitFolder); if (CurrentOutFitFolder == null) return avappearance; List<InventoryItemBase> ic = m_InventoryService.GetFolderItems(user, CurrentOutFitFolder.ID); List<UUID> brokenLinks = new List<UUID>(); List<UUID> OtherStuff = new List<UUID>(); foreach (var i in ic) { InventoryItemBase linkedItem = null; if ((linkedItem = m_InventoryService.GetItem(new InventoryItemBase(i.AssetID))) == null) { brokenLinks.Add(i.ID); } else if (linkedItem.ID == AvatarWearable.DEFAULT_EYES_ITEM || linkedItem.ID == AvatarWearable.DEFAULT_BODY_ITEM || linkedItem.ID == AvatarWearable.DEFAULT_HAIR_ITEM || linkedItem.ID == AvatarWearable.DEFAULT_PANTS_ITEM || linkedItem.ID == AvatarWearable.DEFAULT_SHIRT_ITEM || linkedItem.ID == AvatarWearable.DEFAULT_SKIN_ITEM) brokenLinks.Add(i.ID); //Default item link, needs removed else if (!OtherStuff.Contains(i.AssetID)) OtherStuff.Add(i.AssetID); } for (int i = 0; i < avappearance.Wearables.Length; i++) { AvatarWearable wearable = avappearance.Wearables[i]; for (int ii = 0; ii < wearable.Count; ii++) { if (!OtherStuff.Contains(wearable[ii].ItemID)) { InventoryItemBase linkedItem2 = null; if ((linkedItem2 = m_InventoryService.GetItem(new InventoryItemBase(wearable[ii].ItemID))) != null) { InventoryItemBase linkedItem3 = (InventoryItemBase)linkedItem2.Clone(); linkedItem3.AssetID = linkedItem2.ID; linkedItem3.AssetType = 24; linkedItem3.ID = UUID.Random(); linkedItem3.CurrentPermissions = linkedItem2.NextPermissions; linkedItem3.EveryOnePermissions = linkedItem2.NextPermissions; linkedItem3.Folder = CurrentOutFitFolder.ID; m_InventoryService.AddItem(linkedItem3); } else { avappearance.Wearables[i] = AvatarWearable.DefaultWearables[i]; } } } } List<AvatarAttachment> attachments = avappearance.GetAttachments(); List<UUID> items2UnAttach = new List<UUID>(); foreach (KeyValuePair<int, List<AvatarAttachment>> attachmentSpot in avappearance.Attachments) { foreach (AvatarAttachment attachment in attachmentSpot.Value) { if (!OtherStuff.Contains(attachment.ItemID)) { InventoryItemBase linkedItem2 = null; if ((linkedItem2 = m_InventoryService.GetItem(new InventoryItemBase(attachment.ItemID))) != null) { InventoryItemBase linkedItem3 = (InventoryItemBase)linkedItem2.Clone(); linkedItem3.AssetID = linkedItem2.ID; linkedItem3.AssetType = 24; linkedItem3.ID = UUID.Random(); linkedItem3.CurrentPermissions = linkedItem2.NextPermissions; linkedItem3.EveryOnePermissions = linkedItem2.NextPermissions; linkedItem3.Folder = CurrentOutFitFolder.ID; m_InventoryService.AddItem(linkedItem3); } else items2UnAttach.Add(attachment.ItemID); } } } foreach (UUID uuid in items2UnAttach) { avappearance.DetachAttachment(uuid); } if (brokenLinks.Count != 0) m_InventoryService.DeleteItems(user, brokenLinks); return avappearance; }
public AvatarData(AvatarAppearance appearance) { AvatarType = 1; // SL avatars Data = new Dictionary<string, string>(); Data["Serial"] = appearance.Serial.ToString(); // Wearables Data["AvatarHeight"] = appearance.AvatarHeight.ToString(); Data["Textures"] = OSDParser.SerializeJsonString(appearance.Texture.GetOSD()); for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++) { for (int j = 0; j < appearance.Wearables[i].Count; j++) { string fieldName = String.Format("Wearable {0}:{1}", i, j); Data[fieldName] = String.Format("{0}:{1}", appearance.Wearables[i][j].ItemID.ToString(), appearance.Wearables[i][j].AssetID.ToString()); } } // Visual Params string[] vps = new string[AvatarAppearance.VISUALPARAM_COUNT]; byte[] binary = appearance.VisualParams; for (int i = 0; i < AvatarAppearance.VISUALPARAM_COUNT; i++) { vps[i] = binary[i].ToString(); } Data["VisualParams"] = String.Join(",", vps); // Attachments List<AvatarAttachment> attachments = appearance.GetAttachments(); foreach (AvatarAttachment attach in attachments) { Data["_ap_" + attach.AttachPoint] = attach.ItemID.ToString(); Data["_apa_" + attach.AttachPoint] = attach.AssetID.ToString(); } }
public AvatarAppearance WearFolder(AvatarAppearance avappearance, UUID user, UUID folderOwnerID) { InventoryFolderBase Folder2Wear = m_InventoryService.GetFolderByOwnerAndName(folderOwnerID, m_forceUserToWearFolderName); if (Folder2Wear != null) { List<InventoryItemBase> itemsInFolder = m_InventoryService.GetFolderItems(UUID.Zero, Folder2Wear.ID); InventoryFolderBase appearanceFolder = m_InventoryService.GetFolderForType(user, InventoryType.Wearable, AssetType.Clothing); InventoryFolderBase folderForAppearance = new InventoryFolderBase(UUID.Random(), "GridWear", user, -1, appearanceFolder.ID, 1); List<InventoryFolderBase> userFolders = m_InventoryService.GetFolderFolders(user, appearanceFolder.ID); bool alreadyThere = false; List<UUID> items2RemoveFromAppearence = new List<UUID>(); List<UUID> toDelete = new List<UUID>(); foreach (InventoryFolderBase folder in userFolders) { if (folder.Name == folderForAppearance.Name) { List<InventoryItemBase> itemsInCurrentFolder = m_InventoryService.GetFolderItems(UUID.Zero, folder.ID); foreach (InventoryItemBase itemBase in itemsInCurrentFolder) { items2RemoveFromAppearence.Add(itemBase.AssetID); items2RemoveFromAppearence.Add(itemBase.ID); toDelete.Add(itemBase.ID); } folderForAppearance = folder; alreadyThere = true; m_InventoryService.DeleteItems(user, toDelete); break; } } if (!alreadyThere) m_InventoryService.AddFolder(folderForAppearance); else { // we have to remove all the old items if they are currently wearing them for (int i = 0; i < avappearance.Wearables.Length; i++) { AvatarWearable wearable = avappearance.Wearables[i]; for (int ii = 0; ii < wearable.Count; ii++) { if (items2RemoveFromAppearence.Contains(wearable[ii].ItemID)) { avappearance.Wearables[i] = AvatarWearable.DefaultWearables[i]; break; } } } List<AvatarAttachment> attachments = avappearance.GetAttachments(); foreach (AvatarAttachment attachment in attachments) { if ((items2RemoveFromAppearence.Contains(attachment.AssetID)) || (items2RemoveFromAppearence.Contains(attachment.ItemID))) { avappearance.DetachAttachment(attachment.ItemID); } } } // ok, now we have a empty folder, lets add the items foreach (InventoryItemBase itemBase in itemsInFolder) { InventoryItemBase newcopy = (InventoryItemBase) itemBase.Clone(); newcopy.ID = UUID.Random(); newcopy.Folder = folderForAppearance.ID; newcopy.Owner = user; m_InventoryService.AddItem(newcopy); if (newcopy.InvType == (int) InventoryType.Object) { AssetBase attobj = m_AssetService.Get(newcopy.AssetID.ToString()); if (attobj != null) { string xmlData = Utils.BytesToString(attobj.Data); XmlDocument doc = new XmlDocument(); try { doc.LoadXml(xmlData); } catch { continue; } if (doc.FirstChild.OuterXml.StartsWith("<groups>") || (doc.FirstChild.NextSibling != null && doc.FirstChild.NextSibling.OuterXml.StartsWith("<groups>"))) continue; string xml = ""; if ((doc.FirstChild.NodeType == XmlNodeType.XmlDeclaration) && (doc.FirstChild.NextSibling != null)) xml = doc.FirstChild.NextSibling.OuterXml; else xml = doc.FirstChild.OuterXml; doc.LoadXml(xml); if (doc.DocumentElement == null) continue; XmlNodeList xmlNodeList = doc.DocumentElement.SelectNodes("//State"); int attchspot; if ((xmlNodeList != null) && (int.TryParse(xmlNodeList[0].InnerText, out attchspot))) { AvatarAttachment a = new AvatarAttachment(attchspot, newcopy.ID, newcopy.AssetID); Dictionary<int, List<AvatarAttachment>> ac = avappearance.Attachments; if (!ac.ContainsKey(attchspot)) ac[attchspot] = new List<AvatarAttachment>(); ac[attchspot].Add(a); avappearance.Attachments = ac; } } } } } return avappearance; }
/// <summary> /// This method is called by establishAppearance to do a copy all inventory items /// worn or attached to the Clothing inventory folder of the receiving avatar. /// In parallel the avatar wearables and attachments are updated. /// </summary> private void CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance) { IInventoryService inventoryService = manager.CurrentOrFirstScene.InventoryService; // Get Clothing folder of receiver InventoryFolderBase destinationFolder = inventoryService.GetFolderForType (destination, InventoryType.Wearable, AssetType.Clothing); if (destinationFolder == null) throw new Exception("Cannot locate folder(s)"); // Missing destination folder? This should *never* be the case if (destinationFolder.Type != (short)AssetType.Clothing) { destinationFolder = new InventoryFolderBase { ID = UUID.Random(), Name = "Clothing", Owner = destination, Type = (short) AssetType.Clothing, ParentID = inventoryService.GetRootFolder(destination).ID, Version = 1 }; inventoryService.AddFolder(destinationFolder); // store base record MainConsole.Instance.ErrorFormat("[RADMIN] Created folder for destination {0}", source); } // Wearables AvatarWearable[] wearables = avatarAppearance.Wearables; for (int i = 0; i < wearables.Length; i++) { AvatarWearable wearable = wearables[i]; if (wearable[0].ItemID != UUID.Zero) { // Get inventory item and copy it InventoryItemBase item = new InventoryItemBase(wearable[0].ItemID, source); item = inventoryService.GetItem(item); if (item != null) { InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination) { Name = item.Name, Description = item.Description, InvType = item.InvType, CreatorId = item.CreatorId, CreatorData = item.CreatorData, CreatorIdAsUuid = item.CreatorIdAsUuid, NextPermissions = item.NextPermissions, CurrentPermissions = item.CurrentPermissions, BasePermissions = item.BasePermissions, EveryOnePermissions = item.EveryOnePermissions, GroupPermissions = item.GroupPermissions, AssetType = item.AssetType, AssetID = item.AssetID, GroupID = item.GroupID, GroupOwned = item.GroupOwned, SalePrice = item.SalePrice, SaleType = item.SaleType, Flags = item.Flags, CreationDate = item.CreationDate, Folder = destinationFolder.ID }; ILLClientInventory inventoryModule = manager.CurrentOrFirstScene.RequestModuleInterface<ILLClientInventory>(); if (inventoryModule != null) inventoryModule.AddInventoryItem(destinationItem); MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); // Wear item AvatarWearable newWearable = new AvatarWearable(); newWearable.Wear(destinationItem.ID, wearable[0].AssetID); avatarAppearance.SetWearable(i, newWearable); } else { MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", wearable[0].ItemID, destinationFolder.ID); } } } // Attachments List<AvatarAttachment> attachments = avatarAppearance.GetAttachments(); foreach (AvatarAttachment attachment in attachments) { int attachpoint = attachment.AttachPoint; UUID itemID = attachment.ItemID; if (itemID != UUID.Zero) { // Get inventory item and copy it InventoryItemBase item = new InventoryItemBase(itemID, source); item = inventoryService.GetItem(item); if (item != null) { InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination) { Name = item.Name, Description = item.Description, InvType = item.InvType, CreatorId = item.CreatorId, CreatorData = item.CreatorData, CreatorIdAsUuid = item.CreatorIdAsUuid, NextPermissions = item.NextPermissions, CurrentPermissions = item.CurrentPermissions, BasePermissions = item.BasePermissions, EveryOnePermissions = item.EveryOnePermissions, GroupPermissions = item.GroupPermissions, AssetType = item.AssetType, AssetID = item.AssetID, GroupID = item.GroupID, GroupOwned = item.GroupOwned, SalePrice = item.SalePrice, SaleType = item.SaleType, Flags = item.Flags, CreationDate = item.CreationDate, Folder = destinationFolder.ID }; ILLClientInventory inventoryModule = manager.CurrentOrFirstScene.RequestModuleInterface<ILLClientInventory>(); if (inventoryModule != null) inventoryModule.AddInventoryItem(destinationItem); MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); // Attach item avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID); MainConsole.Instance.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID); } else { MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID); } } } }
public AvatarAppearance(AvatarAppearance appearance, bool copyWearables) { // MainConsole.Instance.WarnFormat("[AVATAR APPEARANCE] create from an existing appearance"); if (appearance == null) { m_serial = 1; m_owner = UUID.Zero; SetDefaultWearables(); SetDefaultTexture(); SetDefaultParams(); SetHeight(); m_attachments = new Dictionary<int, List<AvatarAttachment>>(); return; } m_serial = appearance.Serial; m_owner = appearance.Owner; m_wearables = new AvatarWearable[AvatarWearable.MAX_WEARABLES]; for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++) m_wearables[i] = new AvatarWearable(); if (copyWearables && (appearance.Wearables != null)) { for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++) SetWearable(i, appearance.Wearables[i]); } m_texture = null; if (appearance.Texture != null) { byte[] tbytes = appearance.Texture.GetBytes(); m_texture = new Primitive.TextureEntry(tbytes, 0, tbytes.Length); } m_visualparams = null; if (appearance.VisualParams != null) m_visualparams = (byte[]) appearance.VisualParams.Clone(); // Copy the attachment, force append mode since that ensures consistency m_attachments = new Dictionary<int, List<AvatarAttachment>>(); foreach (AvatarAttachment attachment in appearance.GetAttachments()) AppendAttachment(new AvatarAttachment(attachment)); }
private AvatarAppearance CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance, InventoryFolderBase destinationFolder) { if (destinationFolder == null) throw new Exception("Cannot locate folder(s)"); // Wearables AvatarWearable[] wearables = avatarAppearance.Wearables; for (int i = 0; i < wearables.Length; i++) { AvatarWearable wearable = wearables[i]; for (int ii = 0; ii < wearable.Count; ii++) { if (wearable[ii].ItemID != UUID.Zero) { // Get inventory item and copy it InventoryItemBase item = new InventoryItemBase(wearable[ii].ItemID); item = InventoryService.GetItem(item); if (item != null) { InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination) { Name = item.Name, Description = item.Description, InvType = item.InvType, CreatorId = item.CreatorId, CreatorData = item.CreatorData, CreatorIdAsUuid = item.CreatorIdAsUuid, NextPermissions = item.NextPermissions, CurrentPermissions = item.CurrentPermissions, BasePermissions = item.BasePermissions, EveryOnePermissions = item.EveryOnePermissions, GroupPermissions = item.GroupPermissions, AssetType = item.AssetType, AssetID = item.AssetID, GroupID = item.GroupID, GroupOwned = item.GroupOwned, SalePrice = item.SalePrice, SaleType = item.SaleType, Flags = item.Flags, CreationDate = item.CreationDate, Folder = destinationFolder.ID }; if (InventoryService != null) InventoryService.AddItem(destinationItem); MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); // Wear item AvatarWearable newWearable = new AvatarWearable(); newWearable.Wear(destinationItem.ID, wearable[ii].AssetID); avatarAppearance.SetWearable(i, newWearable); } else { MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", wearable[ii].ItemID, destinationFolder.ID); } } } } // Attachments List<AvatarAttachment> attachments = avatarAppearance.GetAttachments(); foreach (AvatarAttachment attachment in attachments) { int attachpoint = attachment.AttachPoint; UUID itemID = attachment.ItemID; if (itemID != UUID.Zero) { // Get inventory item and copy it InventoryItemBase item = new InventoryItemBase(itemID, source); item = InventoryService.GetItem(item); if (item != null) { InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination) { Name = item.Name, Description = item.Description, InvType = item.InvType, CreatorId = item.CreatorId, CreatorData = item.CreatorData, CreatorIdAsUuid = item.CreatorIdAsUuid, NextPermissions = item.NextPermissions, CurrentPermissions = item.CurrentPermissions, BasePermissions = item.BasePermissions, EveryOnePermissions = item.EveryOnePermissions, GroupPermissions = item.GroupPermissions, AssetType = item.AssetType, AssetID = item.AssetID, GroupID = item.GroupID, GroupOwned = item.GroupOwned, SalePrice = item.SalePrice, SaleType = item.SaleType, Flags = item.Flags, CreationDate = item.CreationDate, Folder = destinationFolder.ID }; if (InventoryService != null) InventoryService.AddItem(destinationItem); MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); // Attach item avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID); MainConsole.Instance.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID); } else { MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID); } } } return avatarAppearance; }
private AvatarAppearance CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance, InventoryFolderBase destinationFolder, UUID agentid, out List<InventoryItemBase> items) { if (destinationFolder == null) throw new Exception("Cannot locate folder(s)"); items = new List<InventoryItemBase>(); // Wearables AvatarWearable[] wearables = avatarAppearance.Wearables; for (int i = 0; i < wearables.Length; i++) { AvatarWearable wearable = wearables[i]; for (int ii = 0; ii < wearable.Count; ii++) { if (wearable[ii].ItemID != UUID.Zero) { // Get inventory item and copy it InventoryItemBase item = new InventoryItemBase(wearable[ii].ItemID); item = InventoryService.GetItem(item); if (item != null) { InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination, destination, item, destinationFolder.ID, false); items.Add(destinationItem); MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); // Wear item AvatarWearable newWearable = new AvatarWearable(); newWearable.Wear(destinationItem.ID, wearable[ii].AssetID); avatarAppearance.SetWearable(i, newWearable); } else { MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", wearable[ii].ItemID, destinationFolder.ID); } } } } // Attachments List<AvatarAttachment> attachments = avatarAppearance.GetAttachments(); foreach (AvatarAttachment attachment in attachments) { int attachpoint = attachment.AttachPoint; UUID itemID = attachment.ItemID; if (itemID != UUID.Zero) { // Get inventory item and copy it InventoryItemBase item = new InventoryItemBase(itemID, source); item = InventoryService.GetItem(item); if (item != null) { InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination, destination, item, destinationFolder.ID, false); items.Add(destinationItem); MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); // Attach item avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID); MainConsole.Instance.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID); } else { MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID); } } } return avatarAppearance; }