private void RemapWornItems(UUID botID, AvatarAppearance appearance) { // save before Clear calls List <AvatarWearable> wearables = appearance.GetWearables(); List <AvatarAttachment> attachments = appearance.GetAttachments(); appearance.ClearWearables(); appearance.ClearAttachments(); // Remap bot outfit with new item IDs foreach (AvatarWearable w in wearables) { AvatarWearable newWearable = new AvatarWearable(w); // store a reversible back-link to the original inventory item ID. newWearable.ItemID = w.ItemID ^ botID; appearance.SetWearable(newWearable); } foreach (AvatarAttachment a in attachments) { // store a reversible back-link to the original inventory item ID. UUID itemID = a.ItemID ^ botID; appearance.SetAttachment(a.AttachPoint, true, itemID, a.AssetID); } }
public bool SetAvatarAppearance(UUID botID, AvatarAppearance avatarApp, IScene scene) { Bot bot; //Find the bot if (!m_bots.TryGetValue(botID, out bot)) { return(false); } var origOwner = avatarApp.Owner; avatarApp.Owner = botID; List <AvatarAttachment> attachments = avatarApp.GetAttachments(); avatarApp.ClearAttachments(); // get original attachments foreach (AvatarAttachment t in attachments) { InventoryItemBase item = scene.InventoryService.GetItem(origOwner, t.ItemID); if (item != null) { item.ID = UUID.Random(); item.Owner = botID; item.Folder = UUID.Zero; scene.InventoryService.AddCacheItemAsync(item); //Now fix the ItemID avatarApp.SetAttachment(t.AttachPoint, item.ID, t.AssetID); } } IScenePresence SP = scene.GetScenePresence(botID); if (SP == null) { return(false); // Failed! bot not found?? } IAvatarAppearanceModule appearance = SP.RequestModuleInterface <IAvatarAppearanceModule>(); appearance.Appearance = avatarApp; appearance.InitialHasWearablesBeenSent = true; return(true); }
public AvatarAppearance ToAvatarAppearance(UUID owner) { AvatarAppearance appearance = new AvatarAppearance(owner); if (Data.Count == 0) return appearance; appearance.ClearWearables(); try { if (Data.ContainsKey("Serial")) appearance.Serial = Int32.Parse(Data["Serial"]); if (Data.ContainsKey("AvatarHeight")) appearance.AvatarHeight = float.Parse(Data["AvatarHeight"]); // Legacy Wearables if (Data.ContainsKey("BodyItem")) appearance.Wearables[AvatarWearable.BODY].Wear( UUID.Parse(Data["BodyItem"]), UUID.Parse(Data["BodyAsset"])); if (Data.ContainsKey("SkinItem")) appearance.Wearables[AvatarWearable.SKIN].Wear( UUID.Parse(Data["SkinItem"]), UUID.Parse(Data["SkinAsset"])); if (Data.ContainsKey("HairItem")) appearance.Wearables[AvatarWearable.HAIR].Wear( UUID.Parse(Data["HairItem"]), UUID.Parse(Data["HairAsset"])); if (Data.ContainsKey("EyesItem")) appearance.Wearables[AvatarWearable.EYES].Wear( UUID.Parse(Data["EyesItem"]), UUID.Parse(Data["EyesAsset"])); if (Data.ContainsKey("ShirtItem")) appearance.Wearables[AvatarWearable.SHIRT].Wear( UUID.Parse(Data["ShirtItem"]), UUID.Parse(Data["ShirtAsset"])); if (Data.ContainsKey("PantsItem")) appearance.Wearables[AvatarWearable.PANTS].Wear( UUID.Parse(Data["PantsItem"]), UUID.Parse(Data["PantsAsset"])); if (Data.ContainsKey("ShoesItem")) appearance.Wearables[AvatarWearable.SHOES].Wear( UUID.Parse(Data["ShoesItem"]), UUID.Parse(Data["ShoesAsset"])); if (Data.ContainsKey("SocksItem")) appearance.Wearables[AvatarWearable.SOCKS].Wear( UUID.Parse(Data["SocksItem"]), UUID.Parse(Data["SocksAsset"])); if (Data.ContainsKey("JacketItem")) appearance.Wearables[AvatarWearable.JACKET].Wear( UUID.Parse(Data["JacketItem"]), UUID.Parse(Data["JacketAsset"])); if (Data.ContainsKey("GlovesItem")) appearance.Wearables[AvatarWearable.GLOVES].Wear( UUID.Parse(Data["GlovesItem"]), UUID.Parse(Data["GlovesAsset"])); if (Data.ContainsKey("UnderShirtItem")) appearance.Wearables[AvatarWearable.UNDERSHIRT].Wear( UUID.Parse(Data["UnderShirtItem"]), UUID.Parse(Data["UnderShirtAsset"])); if (Data.ContainsKey("UnderPantsItem")) appearance.Wearables[AvatarWearable.UNDERPANTS].Wear( UUID.Parse(Data["UnderPantsItem"]), UUID.Parse(Data["UnderPantsAsset"])); if (Data.ContainsKey("SkirtItem")) appearance.Wearables[AvatarWearable.SKIRT].Wear( UUID.Parse(Data["SkirtItem"]), UUID.Parse(Data["SkirtAsset"])); if (Data.ContainsKey("VisualParams")) { string[] vps = Data["VisualParams"].Split(new char[] { ',' }); byte[] binary = new byte[AvatarAppearance.VISUALPARAM_COUNT]; for (int i = 0; i < vps.Length && i < binary.Length; i++) binary[i] = (byte)Convert.ToInt32(vps[i]); appearance.VisualParams = binary; } if (Data.ContainsKey("Textures")) { string t = Data["Textures"]; OSD tex = OSDParser.DeserializeJson(t); appearance.Texture = Primitive.TextureEntry.FromOSD(tex); } // New style wearables foreach (KeyValuePair<string, string> _kvp in Data) { if (_kvp.Key.StartsWith("Wearable ")) { string wearIndex = _kvp.Key.Substring(9); string[] wearIndices = wearIndex.Split(new char[] { ':' }); int index = Convert.ToInt32(wearIndices[0]); string[] ids = _kvp.Value.Split(new char[] { ':' }); UUID itemID = new UUID(ids[0]); UUID assetID = new UUID(ids[1]); appearance.Wearables[index].Add(itemID, assetID); } } // Attachments Dictionary<string, string> attchs = new Dictionary<string, string>(); foreach (KeyValuePair<string, string> _kvp in Data) if (_kvp.Key.StartsWith("_ap_")) attchs[_kvp.Key] = _kvp.Value; foreach (KeyValuePair<string, string> _kvp in attchs) { string pointStr = _kvp.Key.Substring(4); int point = 0; if (!Int32.TryParse(pointStr, out point)) continue; UUID uuid = UUID.Zero; UUID.TryParse(_kvp.Value, out uuid); appearance.SetAttachment(point, uuid, UUID.Zero); } if (appearance.Wearables[AvatarWearable.BODY].Count == 0) appearance.Wearables[AvatarWearable.BODY].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.BODY][0]); if (appearance.Wearables[AvatarWearable.SKIN].Count == 0) appearance.Wearables[AvatarWearable.SKIN].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.SKIN][0]); if (appearance.Wearables[AvatarWearable.HAIR].Count == 0) appearance.Wearables[AvatarWearable.HAIR].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.HAIR][0]); if (appearance.Wearables[AvatarWearable.EYES].Count == 0) appearance.Wearables[AvatarWearable.EYES].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.EYES][0]); } catch { // We really should report something here, returning null // will at least break the wrapper return null; } return appearance; }
private AvatarAppearance ConvertXMLToAvatarAppearance(List<string> file, out List<UUID> AttachmentIDs, out List<string> AttachmentPoints, out List<string> AttachmentAsset, out string FolderNameToPlaceAppearanceIn) { AvatarAppearance appearance = new AvatarAppearance(); List<string> newFile = new List<string>(); foreach (string line in file) { string newLine = line.TrimStart('<'); newFile.Add(newLine.TrimEnd('>')); } appearance.AvatarHeight = Convert.ToInt32(newFile[1]); appearance.BodyAsset = new UUID(newFile[2]); appearance.BodyItem = new UUID(newFile[3]); appearance.EyesAsset = new UUID(newFile[4]); appearance.EyesItem = new UUID(newFile[5]); appearance.GlovesAsset = new UUID(newFile[6]); appearance.GlovesItem = new UUID(newFile[7]); appearance.HairAsset = new UUID(newFile[8]); appearance.HairItem = new UUID(newFile[9]); //Skip Hip Offset appearance.JacketAsset = new UUID(newFile[11]); appearance.JacketItem = new UUID(newFile[12]); appearance.Owner = new UUID(newFile[13]); appearance.PantsAsset = new UUID(newFile[14]); appearance.PantsItem = new UUID(newFile[15]); appearance.Serial = Convert.ToInt32(newFile[16]); appearance.ShirtAsset = new UUID(newFile[17]); appearance.ShirtItem = new UUID(newFile[18]); appearance.ShoesAsset = new UUID(newFile[19]); appearance.ShoesItem = new UUID(newFile[20]); appearance.SkinAsset = new UUID(newFile[21]); appearance.SkinItem = new UUID(newFile[22]); appearance.SkirtAsset = new UUID(newFile[23]); appearance.SkirtItem = new UUID(newFile[24]); appearance.SocksAsset = new UUID(newFile[25]); appearance.SocksItem = new UUID(newFile[26]); //appearance.Texture = new Primitive.TextureEntry(newFile[27],); appearance.UnderPantsAsset = new UUID(newFile[27]); appearance.UnderPantsItem = new UUID(newFile[28]); appearance.UnderShirtAsset = new UUID(newFile[29]); appearance.UnderShirtItem = new UUID(newFile[30]); FolderNameToPlaceAppearanceIn = newFile[31]; Byte[] bytes = new byte[218]; int i = 0; while (i <= 31) { newFile.RemoveAt(0); //Clear out the already processed parts i++; } i = 0; if (newFile[0] == "VisualParams") { foreach (string partLine in newFile) { if (partLine.StartsWith("/VP")) { string newpartLine = ""; newpartLine = partLine.Replace("/VP", ""); bytes[i] = Convert.ToByte(newpartLine); i++; } } } appearance.VisualParams = bytes; List<string> WearableAsset = new List<string>(); List<string> WearableItem = new List<string>(); string texture = ""; AttachmentIDs = new List<UUID>(); AttachmentPoints = new List<string>(); AttachmentAsset = new List<string>(); foreach (string partLine in newFile) { if (partLine.StartsWith("WA")) { string newpartLine = ""; newpartLine = partLine.Replace("WA", ""); WearableAsset.Add(newpartLine); } if (partLine.StartsWith("WI")) { string newpartLine = ""; newpartLine = partLine.Replace("WI", ""); WearableItem.Add(newpartLine); } if (partLine.StartsWith("TEXTURE")) { string newpartLine = ""; newpartLine = partLine.Replace("TEXTURE", ""); texture = newpartLine; } if (partLine.StartsWith("AI")) { string newpartLine = ""; newpartLine = partLine.Replace("AI", ""); AttachmentIDs.Add(new UUID(newpartLine)); } if (partLine.StartsWith("AA")) { string newpartLine = ""; newpartLine = partLine.Replace("AA", ""); AttachmentAsset.Add(newpartLine); } if (partLine.StartsWith("AP")) { string newpartLine = ""; newpartLine = partLine.Replace("AP", ""); AttachmentPoints.Add(newpartLine); } } //byte[] textureBytes = Utils.StringToBytes(texture); //appearance.Texture = new Primitive.TextureEntry(textureBytes, 0, textureBytes.Length); AvatarWearable[] wearables = new AvatarWearable[13]; i = 0; foreach (string asset in WearableAsset) { AvatarWearable wearable = new AvatarWearable(new UUID(asset), new UUID(WearableItem[i])); wearables[i] = wearable; i++; } i = 0; foreach (string asset in AttachmentAsset) { appearance.SetAttachment(Convert.ToInt32(AttachmentPoints[i]), AttachmentIDs[i], new UUID(asset)); i++; } return appearance; }
private AvatarAppearance CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance, InventoryFolderBase destinationFolder, UUID agentid, OSDMap itemsMap, out List<InventoryItemBase> items) { if (destinationFolder == null) throw new Exception("Cannot locate folder(s)"); items = new List<InventoryItemBase>(); List<InventoryItemBase> litems = new List<InventoryItemBase>(); foreach (KeyValuePair<string, OSD> kvp in itemsMap) { InventoryItemBase item = new InventoryItemBase(); item.FromOSD((OSDMap)kvp.Value); MainConsole.Instance.Info("[AvatarArchive]: Loading item " + item.ID.ToString()); litems.Add(item); } // 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 = InventoryService.GetItem(UUID.Zero, wearable[ii].ItemID); if (item == null) { //Attempt to get from the map if it doesn't already exist on the grid item = litems.First((itm) => itm.ID == wearable[ii].ItemID); } if (item != null) { InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination, destination, item, destinationFolder .ID, false, 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, destinationItem.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 = InventoryService.GetItem(UUID.Zero, itemID); if (item != null) { InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination, destination, item, destinationFolder.ID, false, 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; }
public AvatarAppearance ToAvatarAppearance() { AvatarAppearance appearance = new AvatarAppearance(); if (Data.Count == 0) { return(appearance); } appearance.ClearWearables(); try { if (Data.ContainsKey("Serial")) { appearance.Serial = Int32.Parse(Data["Serial"]); } if (Data.ContainsKey("AvatarHeight")) { appearance.AvatarHeight = float.Parse(Data["AvatarHeight"]); } // Legacy Wearables if (Data.ContainsKey("BodyItem")) { appearance.Wearables[AvatarWearable.BODY].Wear( UUID.Parse(Data["BodyItem"]), UUID.Parse(Data["BodyAsset"])); } if (Data.ContainsKey("SkinItem")) { appearance.Wearables[AvatarWearable.SKIN].Wear( UUID.Parse(Data["SkinItem"]), UUID.Parse(Data["SkinAsset"])); } if (Data.ContainsKey("HairItem")) { appearance.Wearables[AvatarWearable.HAIR].Wear( UUID.Parse(Data["HairItem"]), UUID.Parse(Data["HairAsset"])); } if (Data.ContainsKey("EyesItem")) { appearance.Wearables[AvatarWearable.EYES].Wear( UUID.Parse(Data["EyesItem"]), UUID.Parse(Data["EyesAsset"])); } if (Data.ContainsKey("ShirtItem")) { appearance.Wearables[AvatarWearable.SHIRT].Wear( UUID.Parse(Data["ShirtItem"]), UUID.Parse(Data["ShirtAsset"])); } if (Data.ContainsKey("PantsItem")) { appearance.Wearables[AvatarWearable.PANTS].Wear( UUID.Parse(Data["PantsItem"]), UUID.Parse(Data["PantsAsset"])); } if (Data.ContainsKey("ShoesItem")) { appearance.Wearables[AvatarWearable.SHOES].Wear( UUID.Parse(Data["ShoesItem"]), UUID.Parse(Data["ShoesAsset"])); } if (Data.ContainsKey("SocksItem")) { appearance.Wearables[AvatarWearable.SOCKS].Wear( UUID.Parse(Data["SocksItem"]), UUID.Parse(Data["SocksAsset"])); } if (Data.ContainsKey("JacketItem")) { appearance.Wearables[AvatarWearable.JACKET].Wear( UUID.Parse(Data["JacketItem"]), UUID.Parse(Data["JacketAsset"])); } if (Data.ContainsKey("GlovesItem")) { appearance.Wearables[AvatarWearable.GLOVES].Wear( UUID.Parse(Data["GlovesItem"]), UUID.Parse(Data["GlovesAsset"])); } if (Data.ContainsKey("UnderShirtItem")) { appearance.Wearables[AvatarWearable.UNDERSHIRT].Wear( UUID.Parse(Data["UnderShirtItem"]), UUID.Parse(Data["UnderShirtAsset"])); } if (Data.ContainsKey("UnderPantsItem")) { appearance.Wearables[AvatarWearable.UNDERPANTS].Wear( UUID.Parse(Data["UnderPantsItem"]), UUID.Parse(Data["UnderPantsAsset"])); } if (Data.ContainsKey("SkirtItem")) { appearance.Wearables[AvatarWearable.SKIRT].Wear( UUID.Parse(Data["SkirtItem"]), UUID.Parse(Data["SkirtAsset"])); } if (Data.ContainsKey("VisualParams")) { string[] vps = Data["VisualParams"].Split(new char[] { ',' }); byte[] binary = new byte[AvatarAppearance.VISUALPARAM_COUNT]; for (int i = 0; i < vps.Length && i < binary.Length; i++) { binary[i] = (byte)Convert.ToInt32(vps[i]); } appearance.VisualParams = binary; } // New style wearables foreach (KeyValuePair <string, string> _kvp in Data) { if (_kvp.Key.StartsWith("Wearable ")) { string wearIndex = _kvp.Key.Substring(9); string[] wearIndices = wearIndex.Split(new char[] { ':' }); int index = Convert.ToInt32(wearIndices[0]); string[] ids = _kvp.Value.Split(new char[] { ':' }); UUID itemID = new UUID(ids[0]); UUID assetID = new UUID(ids[1]); appearance.Wearables[index].Add(itemID, assetID); } } // Attachments Dictionary <string, string> attchs = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> _kvp in Data) { if (_kvp.Key.StartsWith("_ap_")) { attchs[_kvp.Key] = _kvp.Value; } } foreach (KeyValuePair <string, string> _kvp in attchs) { string pointStr = _kvp.Key.Substring(4); int point = 0; if (!Int32.TryParse(pointStr, out point)) { continue; } UUID uuid = UUID.Zero; UUID.TryParse(_kvp.Value, out uuid); appearance.SetAttachment(point, uuid, UUID.Zero); } if (appearance.Wearables[AvatarWearable.BODY].Count == 0) { appearance.Wearables[AvatarWearable.BODY].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.BODY][0]); } if (appearance.Wearables[AvatarWearable.SKIN].Count == 0) { appearance.Wearables[AvatarWearable.SKIN].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.SKIN][0]); } if (appearance.Wearables[AvatarWearable.HAIR].Count == 0) { appearance.Wearables[AvatarWearable.HAIR].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.HAIR][0]); } if (appearance.Wearables[AvatarWearable.EYES].Count == 0) { appearance.Wearables[AvatarWearable.EYES].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.EYES][0]); } } catch { // We really should report something here, returning null // will at least break the wrapper return(null); } return(appearance); }
public UUID CreateAvatar(string firstName, string lastName, IScene scene, AvatarAppearance avatarApp, UUID creatorID, Vector3 startPos) { //Add the circuit data so they can login AgentCircuitData m_aCircuitData = new AgentCircuitData { IsChildAgent = false, CircuitCode = (uint)Util.RandomClass.Next() }; //Create the new bot data BotClientAPI m_character = new BotClientAPI(scene, m_aCircuitData); m_character.Name = firstName + " " + lastName; m_aCircuitData.AgentID = m_character.AgentId; //Set up appearance var origOwner = avatarApp.Owner; avatarApp.Owner = m_character.AgentId; List <AvatarAttachment> attachments = avatarApp.GetAttachments(); avatarApp.ClearAttachments(); // get original attachments foreach (AvatarAttachment t in attachments) { InventoryItemBase item = scene.InventoryService.GetItem(origOwner, t.ItemID); if (item != null) { item.ID = UUID.Random(); item.Owner = m_character.AgentId; item.Folder = UUID.Zero; scene.InventoryService.AddCacheItemAsync(item); //Now fix the ItemID avatarApp.SetAttachment(t.AttachPoint, item.ID, t.AssetID); } } scene.AuthenticateHandler.AgentCircuits.Add(m_character.CircuitCode, m_aCircuitData); //This adds them to the scene and sets them in world AddAndWaitUntilAgentIsAdded(scene, m_character); IScenePresence SP = scene.GetScenePresence(m_character.AgentId); if (SP == null) { return(UUID.Zero); //Failed! } // set this as a NPC character SP.IsNpcAgent = true; IAvatarAppearanceModule appearance = SP.RequestModuleInterface <IAvatarAppearanceModule>(); appearance.Appearance = avatarApp; appearance.InitialHasWearablesBeenSent = true; Bot bot = new Bot(); bot.Initialize(SP, creatorID); try { SP.MakeRootAgent(startPos, false, true); } catch { MainConsole.Instance.ErrorFormat("[BotManager]: Error creating bot {0} as root agent!", m_character.AgentId); } //Move them SP.Teleport(startPos); foreach (var presence in scene.GetScenePresences()) { presence.SceneViewer.QueuePresenceForUpdate(SP, PrimUpdateFlags.ForcedFullUpdate); } IAttachmentsModule attModule = SP.Scene.RequestModuleInterface <IAttachmentsModule>(); if (attModule != null) { foreach (AvatarAttachment att in attachments) { attModule.RezSingleAttachmentFromInventory(SP.ControllingClient, att.ItemID, att.AssetID, 0, true); } } //Save them in the bots list m_bots.Add(m_character.AgentId, bot); AddTagToBot(m_character.AgentId, "AllBots", bot.AvatarCreatorID); MainConsole.Instance.InfoFormat("[BotManager]: Added bot {0} to region {1}", m_character.Name, scene.RegionInfo.RegionName); //Return their UUID return(m_character.AgentId); }
private AvatarAppearance CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance, InventoryFolderBase destinationFolder, UUID agentid, OSDMap itemsMap, out List <InventoryItemBase> items) { if (destinationFolder == null) { throw new Exception("Cannot locate folder(s)"); } items = new List <InventoryItemBase>(); List <InventoryItemBase> litems = new List <InventoryItemBase>(); foreach (KeyValuePair <string, OSD> kvp in itemsMap) { InventoryItemBase item = new InventoryItemBase(); item.FromOSD((OSDMap)kvp.Value); MainConsole.Instance.Info("[AvatarArchive]: Loading item " + item.ID.ToString()); litems.Add(item); } // 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 = InventoryService.GetItem(UUID.Zero, wearable[ii].ItemID); if (item == null) { //Attempt to get from the map if it doesn't already exist on the grid item = litems.First((itm) => itm.ID == wearable[ii].ItemID); } if (item != null) { InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination, destination, item, destinationFolder .ID, false, 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, destinationItem.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 = InventoryService.GetItem(UUID.Zero, itemID); if (item != null) { InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination, destination, item, destinationFolder.ID, false, 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); }
public AvatarAppearance ToAvatarAppearance() { AvatarAppearance appearance = new AvatarAppearance(); if (Data.Count == 0) { return(appearance); } appearance.ClearWearables(); try { if (Data.ContainsKey("Serial")) { appearance.Serial = Int32.Parse(Data["Serial"]); } if (Data.ContainsKey("AvatarHeight")) { float h = float.Parse(Data["AvatarHeight"]); if (h == 0f) { h = 1.9f; } appearance.SetSize(new Vector3(0.45f, 0.6f, h)); } // Legacy Wearables if (Data.ContainsKey("BodyItem")) { appearance.Wearables[AvatarWearable.BODY].Wear( UUID.Parse(Data["BodyItem"]), UUID.Parse(Data["BodyAsset"])); } if (Data.ContainsKey("SkinItem")) { appearance.Wearables[AvatarWearable.SKIN].Wear( UUID.Parse(Data["SkinItem"]), UUID.Parse(Data["SkinAsset"])); } if (Data.ContainsKey("HairItem")) { appearance.Wearables[AvatarWearable.HAIR].Wear( UUID.Parse(Data["HairItem"]), UUID.Parse(Data["HairAsset"])); } if (Data.ContainsKey("EyesItem")) { appearance.Wearables[AvatarWearable.EYES].Wear( UUID.Parse(Data["EyesItem"]), UUID.Parse(Data["EyesAsset"])); } if (Data.ContainsKey("ShirtItem")) { appearance.Wearables[AvatarWearable.SHIRT].Wear( UUID.Parse(Data["ShirtItem"]), UUID.Parse(Data["ShirtAsset"])); } if (Data.ContainsKey("PantsItem")) { appearance.Wearables[AvatarWearable.PANTS].Wear( UUID.Parse(Data["PantsItem"]), UUID.Parse(Data["PantsAsset"])); } if (Data.ContainsKey("ShoesItem")) { appearance.Wearables[AvatarWearable.SHOES].Wear( UUID.Parse(Data["ShoesItem"]), UUID.Parse(Data["ShoesAsset"])); } if (Data.ContainsKey("SocksItem")) { appearance.Wearables[AvatarWearable.SOCKS].Wear( UUID.Parse(Data["SocksItem"]), UUID.Parse(Data["SocksAsset"])); } if (Data.ContainsKey("JacketItem")) { appearance.Wearables[AvatarWearable.JACKET].Wear( UUID.Parse(Data["JacketItem"]), UUID.Parse(Data["JacketAsset"])); } if (Data.ContainsKey("GlovesItem")) { appearance.Wearables[AvatarWearable.GLOVES].Wear( UUID.Parse(Data["GlovesItem"]), UUID.Parse(Data["GlovesAsset"])); } if (Data.ContainsKey("UnderShirtItem")) { appearance.Wearables[AvatarWearable.UNDERSHIRT].Wear( UUID.Parse(Data["UnderShirtItem"]), UUID.Parse(Data["UnderShirtAsset"])); } if (Data.ContainsKey("UnderPantsItem")) { appearance.Wearables[AvatarWearable.UNDERPANTS].Wear( UUID.Parse(Data["UnderPantsItem"]), UUID.Parse(Data["UnderPantsAsset"])); } if (Data.ContainsKey("SkirtItem")) { appearance.Wearables[AvatarWearable.SKIRT].Wear( UUID.Parse(Data["SkirtItem"]), UUID.Parse(Data["SkirtAsset"])); } if (Data.ContainsKey("VisualParams")) { string[] vps = Data["VisualParams"].Split(new char[] { ',' }); byte[] binary = new byte[vps.Length]; for (int i = 0; i < vps.Length; i++) { binary[i] = (byte)Convert.ToInt32(vps[i]); } appearance.VisualParams = binary; } AvatarWearable[] wearables = appearance.Wearables; int currentLength = wearables.Length; foreach (KeyValuePair <string, string> _kvp in Data) { // New style wearables if (_kvp.Key.StartsWith("Wearable ") && _kvp.Key.Length > 9) { string wearIndex = _kvp.Key.Substring(9); string[] wearIndices = wearIndex.Split(new char[] { ':' }); int index = Convert.ToInt32(wearIndices[0]); string[] ids = _kvp.Value.Split(new char[] { ':' }); UUID itemID = new UUID(ids[0]); UUID assetID = new UUID(ids[1]); if (index >= currentLength) { Array.Resize(ref wearables, index + 1); for (int i = currentLength; i < wearables.Length; i++) { wearables[i] = new AvatarWearable(); } currentLength = wearables.Length; } wearables[index].Add(itemID, assetID); continue; } // Attachments if (_kvp.Key.StartsWith("_ap_") && _kvp.Key.Length > 4) { string pointStr = _kvp.Key.Substring(4); int point = 0; if (Int32.TryParse(pointStr, out point)) { List <string> idList = new List <string>(_kvp.Value.Split(new char[] { ',' })); appearance.SetAttachment(point, UUID.Zero, UUID.Zero); foreach (string id in idList) { UUID uuid = UUID.Zero; if (UUID.TryParse(id, out uuid)) { appearance.SetAttachment(point | 0x80, uuid, UUID.Zero); } } } } } if (appearance.Wearables[AvatarWearable.BODY].Count == 0) { appearance.Wearables[AvatarWearable.BODY].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.BODY][0]); } if (appearance.Wearables[AvatarWearable.SKIN].Count == 0) { appearance.Wearables[AvatarWearable.SKIN].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.SKIN][0]); } if (appearance.Wearables[AvatarWearable.HAIR].Count == 0) { appearance.Wearables[AvatarWearable.HAIR].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.HAIR][0]); } if (appearance.Wearables[AvatarWearable.EYES].Count == 0) { appearance.Wearables[AvatarWearable.EYES].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.EYES][0]); } } catch { // We really should report something here, returning null // will at least break the wrapper return(null); } return(appearance); }
private AvatarAppearance ConvertXMLToAvatarAppearance(OSDMap map, out string FolderNameToPlaceAppearanceIn) { AvatarAppearance appearance = new AvatarAppearance(); appearance.AvatarHeight = (float)map["AvatarHeight"].AsReal(); appearance.BodyAsset = map["BodyAsset"].AsUUID(); appearance.BodyItem = map["BodyItem"].AsUUID(); appearance.EyesAsset = map["EyesAsset"].AsUUID(); appearance.EyesItem = map["EyesItem"].AsUUID(); appearance.GlovesAsset = map["GlovesAsset"].AsUUID(); appearance.GlovesItem = map["GlovesItem"].AsUUID(); appearance.HairAsset = map["HairAsset"].AsUUID(); appearance.HairItem = map["HairItem"].AsUUID(); //Skip Hip Offset appearance.JacketAsset = map["JacketAsset"].AsUUID(); appearance.JacketItem = map["JacketItem"].AsUUID(); appearance.Owner = map["Owner"].AsUUID(); appearance.PantsAsset = map["PantsAsset"].AsUUID(); appearance.PantsItem = map["PantsItem"].AsUUID(); appearance.Serial = map["Serial"].AsInteger(); appearance.ShirtAsset = map["ShirtAsset"].AsUUID(); appearance.ShirtItem = map["ShirtItem"].AsUUID(); appearance.ShoesAsset = map["ShoesAsset"].AsUUID(); appearance.ShoesItem = map["ShoesItem"].AsUUID(); appearance.SkinAsset = map["SkinAsset"].AsUUID(); appearance.SkinItem = map["SkinItem"].AsUUID(); appearance.SkirtAsset = map["SkirtAsset"].AsUUID(); appearance.SkirtItem = map["SkirtItem"].AsUUID(); appearance.SocksAsset = map["SocksAsset"].AsUUID(); appearance.SocksItem = map["SocksItem"].AsUUID(); appearance.UnderPantsAsset = map["UnderPantsAsset"].AsUUID(); appearance.UnderPantsItem = map["UnderPantsItem"].AsUUID(); appearance.UnderShirtAsset = map["UnderShirtAsset"].AsUUID(); appearance.UnderShirtItem = map["UnderShirtItem"].AsUUID(); appearance.TattooAsset = map["TattooAsset"].AsUUID(); appearance.TattooItem = map["TattooItem"].AsUUID(); appearance.AlphaAsset = map["AlphaAsset"].AsUUID(); appearance.AlphaItem = map["AlphaItem"].AsUUID(); FolderNameToPlaceAppearanceIn = map["FolderName"].AsString(); appearance.VisualParams = map["VisualParams"].AsBinary(); OSDArray wearables = (OSDArray)map["AvatarWearables"]; List<AvatarWearable> AvatarWearables = new List<AvatarWearable>(); foreach (OSD o in wearables) { OSDMap wearable = (OSDMap)o; AvatarWearable wear = new AvatarWearable(); wear.AssetID = wearable["Asset"].AsUUID(); wear.ItemID = wearable["Item"].AsUUID(); AvatarWearables.Add(wear); } appearance.Wearables = AvatarWearables.ToArray(); appearance.Texture = Primitive.TextureEntry.FromOSD(map["Texture"]); OSDArray attachmentsArray = (OSDArray)map["Attachments"]; foreach (OSD o in wearables) { OSDMap attachment = (OSDMap)o; UUID Asset = attachment["Asset"].AsUUID(); UUID Item = attachment["Item"].AsUUID(); int AttachmentPoint = attachment["Point"].AsInteger(); appearance.SetAttachment(AttachmentPoint, Item, Asset); } return appearance; }
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 = InventoryService.GetItem(agentid, wearable[ii].ItemID); 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, destinationItem.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 = InventoryService.GetItem(source, itemID); 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; }
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); }
private bool CloneFolder(List <InventoryFolderBase> avatarInventory, UUID avID, UUID parentFolder, AvatarAppearance appearance, InventoryFolderBase templateFolder, List <InventoryFolderBase> templateFolders, bool modifyPermissions) { bool success = false; UUID templateFolderId = templateFolder.ID; if (templateFolderId != UUID.Zero) { InventoryFolderBase toFolder = FindFolder(templateFolder.Name, parentFolder.Guid, avatarInventory); if (toFolder == null) { //create new folder toFolder = new InventoryFolderBase(); toFolder.ID = UUID.Random(); toFolder.Name = templateFolder.Name; toFolder.Owner = avID; toFolder.Type = templateFolder.Type; toFolder.Version = 1; toFolder.ParentID = parentFolder; if (!SynchronousRestObjectRequester.MakeRequest <InventoryFolderBase, bool>( "POST", m_inventoryServerUrl + "CreateFolder/", toFolder)) { m_log.InfoFormat("[AvatarApperance] Couldn't make new folder {0} in users inventory", toFolder.Name); return(false); } else { // m_log.InfoFormat("made new folder {0} in users inventory", toFolder.Name); } } List <InventoryItemBase> templateItems = SynchronousRestObjectRequester.MakeRequest <Guid, List <InventoryItemBase> >( "POST", m_inventoryServerUrl + "GetItems/", templateFolderId.Guid); if ((templateItems != null) && (templateItems.Count > 0)) { List <ClothesAttachment> wornClothes = new List <ClothesAttachment>(); List <ClothesAttachment> attachedItems = new List <ClothesAttachment>(); foreach (InventoryItemBase item in templateItems) { UUID clonedItemId = CloneInventoryItem(avID, toFolder.ID, item, modifyPermissions); if (clonedItemId != UUID.Zero) { int appearanceType = ItemIsPartOfAppearance(item, appearance); if (appearanceType >= 0) { // UpdateAvatarAppearance(avID, appearanceType, clonedItemId, item.AssetID); wornClothes.Add(new ClothesAttachment(appearanceType, clonedItemId, item.AssetID)); } if (appearance != null) { int attachment = appearance.GetAttachpoint(item.ID); if (attachment > 0) { //UpdateAvatarAttachment(avID, attachment, clonedItemId, item.AssetID); attachedItems.Add(new ClothesAttachment(attachment, clonedItemId, item.AssetID)); } } success = true; } } if ((wornClothes.Count > 0) || (attachedItems.Count > 0)) { //Update the worn clothes and attachments AvatarAppearance targetAppearance = GetAppearance(avID); if (targetAppearance != null) { foreach (ClothesAttachment wornItem in wornClothes) { targetAppearance.Wearables[wornItem.Type].AssetID = wornItem.AssetID; targetAppearance.Wearables[wornItem.Type].ItemID = wornItem.ItemID; } foreach (ClothesAttachment wornItem in attachedItems) { targetAppearance.SetAttachment(wornItem.Type, wornItem.ItemID, wornItem.AssetID); } m_userDataBaseService.UpdateUserAppearance(avID, targetAppearance); wornClothes.Clear(); attachedItems.Clear(); } } } List <InventoryFolderBase> subFolders = FindSubFolders(templateFolder.ID.Guid, templateFolders); foreach (InventoryFolderBase subFolder in subFolders) { if (subFolder.Name.ToLower() != "trash") { success = CloneFolder(avatarInventory, avID, toFolder.ID, appearance, subFolder, templateFolders, modifyPermissions); } } } else { m_log.Info("[AvatarAppearance] Failed to find the template folder"); } return(success); }
public AvatarAppearance ToAvatarAppearance(UUID owner) { AvatarAppearance appearance = new AvatarAppearance(owner); if (Data.Count == 0) { return(appearance); } appearance.ClearWearables(); try { if (Data.ContainsKey("Serial")) { appearance.Serial = Int32.Parse(Data["Serial"]); } if (Data.ContainsKey("AvatarHeight")) { appearance.AvatarHeight = float.Parse(Data["AvatarHeight"]); } // Legacy Wearables if (Data.ContainsKey("BodyItem")) { appearance.Wearables[AvatarWearable.BODY].Wear( UUID.Parse(Data["BodyItem"]), UUID.Parse(Data["BodyAsset"])); } if (Data.ContainsKey("SkinItem")) { appearance.Wearables[AvatarWearable.SKIN].Wear( UUID.Parse(Data["SkinItem"]), UUID.Parse(Data["SkinAsset"])); } if (Data.ContainsKey("HairItem")) { appearance.Wearables[AvatarWearable.HAIR].Wear( UUID.Parse(Data["HairItem"]), UUID.Parse(Data["HairAsset"])); } if (Data.ContainsKey("EyesItem")) { appearance.Wearables[AvatarWearable.EYES].Wear( UUID.Parse(Data["EyesItem"]), UUID.Parse(Data["EyesAsset"])); } if (Data.ContainsKey("ShirtItem")) { appearance.Wearables[AvatarWearable.SHIRT].Wear( UUID.Parse(Data["ShirtItem"]), UUID.Parse(Data["ShirtAsset"])); } if (Data.ContainsKey("PantsItem")) { appearance.Wearables[AvatarWearable.PANTS].Wear( UUID.Parse(Data["PantsItem"]), UUID.Parse(Data["PantsAsset"])); } if (Data.ContainsKey("ShoesItem")) { appearance.Wearables[AvatarWearable.SHOES].Wear( UUID.Parse(Data["ShoesItem"]), UUID.Parse(Data["ShoesAsset"])); } if (Data.ContainsKey("SocksItem")) { appearance.Wearables[AvatarWearable.SOCKS].Wear( UUID.Parse(Data["SocksItem"]), UUID.Parse(Data["SocksAsset"])); } if (Data.ContainsKey("JacketItem")) { appearance.Wearables[AvatarWearable.JACKET].Wear( UUID.Parse(Data["JacketItem"]), UUID.Parse(Data["JacketAsset"])); } if (Data.ContainsKey("GlovesItem")) { appearance.Wearables[AvatarWearable.GLOVES].Wear( UUID.Parse(Data["GlovesItem"]), UUID.Parse(Data["GlovesAsset"])); } if (Data.ContainsKey("UnderShirtItem")) { appearance.Wearables[AvatarWearable.UNDERSHIRT].Wear( UUID.Parse(Data["UnderShirtItem"]), UUID.Parse(Data["UnderShirtAsset"])); } if (Data.ContainsKey("UnderPantsItem")) { appearance.Wearables[AvatarWearable.UNDERPANTS].Wear( UUID.Parse(Data["UnderPantsItem"]), UUID.Parse(Data["UnderPantsAsset"])); } if (Data.ContainsKey("SkirtItem")) { appearance.Wearables[AvatarWearable.SKIRT].Wear( UUID.Parse(Data["SkirtItem"]), UUID.Parse(Data["SkirtAsset"])); } if (Data.ContainsKey("VisualParams")) { string[] vps = Data["VisualParams"].Split(new[] { ',' }); byte[] binary = new byte[AvatarAppearance.VISUALPARAM_COUNT]; for (int i = 0; i < vps.Length && i < binary.Length; i++) { binary[i] = (byte)Convert.ToInt32(vps[i]); } appearance.VisualParams = binary; } if (Data.ContainsKey("Textures")) { string t = Data["Textures"]; OSD tex = OSDParser.DeserializeJson(t); appearance.Texture = Primitive.TextureEntry.FromOSD(tex); } // New style wearables foreach (KeyValuePair <string, string> _kvp in Data) { if (_kvp.Key.StartsWith("Wearable ")) { string wearIndex = _kvp.Key.Substring(9); string[] wearIndices = wearIndex.Split(new[] { ':' }); if (wearIndices.Length == 2 && wearIndices[1].Length == 1) { int index = Convert.ToInt32(wearIndices[0]); string[] ids = _kvp.Value.Split(new[] { ':' }); UUID itemID = new UUID(ids[0]); UUID assetID = new UUID(ids[1]); appearance.Wearables[index].Add(itemID, assetID); } else { //For when we get stuff like 0020_0_x003A_0 var index2 = wearIndices[1].Split('_'); int index = Convert.ToInt32(index2[1]); string[] ids = _kvp.Value.Split(new[] { ':' }); UUID itemID = new UUID(ids[0]); UUID assetID = new UUID(ids[1]); appearance.Wearables[index].Add(itemID, assetID); } } } // Attachments Dictionary <string, string> attchs = new Dictionary <string, string>(); Dictionary <string, string> attchsAssets = new Dictionary <string, string>(); #if (!ISWIN) foreach (KeyValuePair <string, string> _kvp in Data) { if (_kvp.Key.StartsWith("_ap_")) { attchs[_kvp.Key] = _kvp.Value; } if (_kvp.Key.StartsWith("_apa_")) { attchsAssets[_kvp.Key] = _kvp.Value; } } #else foreach (KeyValuePair <string, string> _kvp in Data.Where(_kvp => _kvp.Key.StartsWith("_ap_"))) { attchs[_kvp.Key] = _kvp.Value; } #endif foreach (KeyValuePair <string, string> _kvp in attchs) { string pointStr = _kvp.Key.Substring(4, 1); int point = 0; if (!Int32.TryParse(pointStr, out point)) { continue; } UUID uuid = UUID.Zero; UUID.TryParse(_kvp.Value, out uuid); UUID assetuuid = UUID.Zero; if (attchsAssets.ContainsKey(_kvp.Key)) { UUID.TryParse(attchsAssets[_kvp.Key], out uuid); } appearance.SetAttachment(point, uuid, assetuuid); } if (appearance.Wearables[AvatarWearable.BODY].Count == 0) { appearance.Wearables[AvatarWearable.BODY].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.BODY][0]); } if (appearance.Wearables[AvatarWearable.SKIN].Count == 0) { appearance.Wearables[AvatarWearable.SKIN].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.SKIN][0]); } if (appearance.Wearables[AvatarWearable.HAIR].Count == 0) { appearance.Wearables[AvatarWearable.HAIR].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.HAIR][0]); } if (appearance.Wearables[AvatarWearable.EYES].Count == 0) { appearance.Wearables[AvatarWearable.EYES].Wear( AvatarWearable.DefaultWearables[ AvatarWearable.EYES][0]); } } catch { // We really should report something here, returning null // will at least break the wrapper return(null); } return(appearance); }
/// <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) { // Get Clothing folder of receiver InventoryFolderBase destinationFolder = m_InventoryService.GetFolderForType(destination, FolderType.Clothing); if (destinationFolder == null) { throw new Exception("Cannot locate folder(s)"); } // Missing destination folder? This should *never* be the case if (destinationFolder.Type != (short)FolderType.Clothing) { destinationFolder = new InventoryFolderBase(); destinationFolder.ID = UUID.Random(); destinationFolder.Name = "Clothing"; destinationFolder.Owner = destination; destinationFolder.Type = (short)AssetType.Clothing; destinationFolder.ParentID = m_InventoryService.GetRootFolder(destination).ID; destinationFolder.Version = 1; m_InventoryService.AddFolder(destinationFolder); // store base record m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Created folder for destination {0}", source); } // Wearables AvatarWearable[] wearables = avatarAppearance.Wearables; AvatarWearable wearable; for (int i = 0; i < wearables.Length; i++) { wearable = wearables[i]; if (wearable[0].ItemID != UUID.Zero) { // Get inventory item and copy it InventoryItemBase item = m_InventoryService.GetItem(source, wearable[0].ItemID); if (item != null) { 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.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 = destinationFolder.ID; ApplyNextOwnerPermissions(destinationItem); m_InventoryService.AddItem(destinationItem); m_log.DebugFormat("[USER ACCOUNT SERVICE]: 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 { m_log.WarnFormat("[USER ACCOUNT SERVICE]: 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 = m_InventoryService.GetItem(source, itemID); if (item != null) { 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.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 = destinationFolder.ID; ApplyNextOwnerPermissions(destinationItem); m_InventoryService.AddItem(destinationItem); m_log.DebugFormat("[USER ACCOUNT SERVICE]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); // Attach item avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID); m_log.DebugFormat("[USER ACCOUNT SERVICE]: Attached {0}", destinationItem.ID); } else { m_log.WarnFormat("[USER ACCOUNT SERVICE]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID); } } } }