AvatarAppearance.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Runtime.Serialization;
  31. using System.Security.Permissions;
  32. using OpenMetaverse;
  33. namespace OpenSim.Framework
  34. {
  35. [Serializable]
  36. public class AvatarAppearance : ISerializable
  37. {
  38. // private static readonly ILog m_log
  39. // = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  40. // these are guessed at by the list here -
  41. // http://wiki.secondlife.com/wiki/Avatar_Appearance. We'll
  42. // correct them over time for when were are wrong.
  43. public readonly static int BODY = 0;
  44. public readonly static int SKIN = 1;
  45. public readonly static int HAIR = 2;
  46. public readonly static int EYES = 3;
  47. public readonly static int SHIRT = 4;
  48. public readonly static int PANTS = 5;
  49. public readonly static int SHOES = 6;
  50. public readonly static int SOCKS = 7;
  51. public readonly static int JACKET = 8;
  52. public readonly static int GLOVES = 9;
  53. public readonly static int UNDERSHIRT = 10;
  54. public readonly static int UNDERPANTS = 11;
  55. public readonly static int SKIRT = 12;
  56. private readonly static int MAX_WEARABLES = 13;
  57. private static UUID BODY_ASSET = new UUID("66c41e39-38f9-f75a-024e-585989bfab73");
  58. private static UUID BODY_ITEM = new UUID("66c41e39-38f9-f75a-024e-585989bfaba9");
  59. private static UUID SKIN_ASSET = new UUID("77c41e39-38f9-f75a-024e-585989bbabbb");
  60. private static UUID SKIN_ITEM = new UUID("77c41e39-38f9-f75a-024e-585989bfabc9");
  61. private static UUID SHIRT_ASSET = new UUID("00000000-38f9-1111-024e-222222111110");
  62. private static UUID SHIRT_ITEM = new UUID("77c41e39-38f9-f75a-0000-585989bf0000");
  63. private static UUID PANTS_ASSET = new UUID("00000000-38f9-1111-024e-222222111120");
  64. private static UUID PANTS_ITEM = new UUID("77c41e39-38f9-f75a-0000-5859892f1111");
  65. public readonly static int VISUALPARAM_COUNT = 218;
  66. protected UUID m_owner;
  67. public virtual UUID Owner
  68. {
  69. get { return m_owner; }
  70. set { m_owner = value; }
  71. }
  72. protected int m_serial = 1;
  73. public virtual int Serial
  74. {
  75. get { return m_serial; }
  76. set { m_serial = value; }
  77. }
  78. protected byte[] m_visualparams;
  79. public virtual byte[] VisualParams
  80. {
  81. get { return m_visualparams; }
  82. set { m_visualparams = value; }
  83. }
  84. protected AvatarWearable[] m_wearables;
  85. public virtual AvatarWearable[] Wearables
  86. {
  87. get { return m_wearables; }
  88. set { m_wearables = value; }
  89. }
  90. public virtual UUID BodyItem {
  91. get { return m_wearables[BODY].ItemID; }
  92. set { m_wearables[BODY].ItemID = value; }
  93. }
  94. public virtual UUID BodyAsset {
  95. get { return m_wearables[BODY].AssetID; }
  96. set { m_wearables[BODY].AssetID = value; }
  97. }
  98. public virtual UUID SkinItem {
  99. get { return m_wearables[SKIN].ItemID; }
  100. set { m_wearables[SKIN].ItemID = value; }
  101. }
  102. public virtual UUID SkinAsset {
  103. get { return m_wearables[SKIN].AssetID; }
  104. set { m_wearables[SKIN].AssetID = value; }
  105. }
  106. public virtual UUID HairItem {
  107. get { return m_wearables[HAIR].ItemID; }
  108. set { m_wearables[HAIR].ItemID = value; }
  109. }
  110. public virtual UUID HairAsset {
  111. get { return m_wearables[HAIR].AssetID; }
  112. set { m_wearables[HAIR].AssetID = value; }
  113. }
  114. public virtual UUID EyesItem {
  115. get { return m_wearables[EYES].ItemID; }
  116. set { m_wearables[EYES].ItemID = value; }
  117. }
  118. public virtual UUID EyesAsset {
  119. get { return m_wearables[EYES].AssetID; }
  120. set { m_wearables[EYES].AssetID = value; }
  121. }
  122. public virtual UUID ShirtItem {
  123. get { return m_wearables[SHIRT].ItemID; }
  124. set { m_wearables[SHIRT].ItemID = value; }
  125. }
  126. public virtual UUID ShirtAsset {
  127. get { return m_wearables[SHIRT].AssetID; }
  128. set { m_wearables[SHIRT].AssetID = value; }
  129. }
  130. public virtual UUID PantsItem {
  131. get { return m_wearables[PANTS].ItemID; }
  132. set { m_wearables[PANTS].ItemID = value; }
  133. }
  134. public virtual UUID PantsAsset {
  135. get { return m_wearables[PANTS].AssetID; }
  136. set { m_wearables[PANTS].AssetID = value; }
  137. }
  138. public virtual UUID ShoesItem {
  139. get { return m_wearables[SHOES].ItemID; }
  140. set { m_wearables[SHOES].ItemID = value; }
  141. }
  142. public virtual UUID ShoesAsset {
  143. get { return m_wearables[SHOES].AssetID; }
  144. set { m_wearables[SHOES].AssetID = value; }
  145. }
  146. public virtual UUID SocksItem {
  147. get { return m_wearables[SOCKS].ItemID; }
  148. set { m_wearables[SOCKS].ItemID = value; }
  149. }
  150. public virtual UUID SocksAsset {
  151. get { return m_wearables[SOCKS].AssetID; }
  152. set { m_wearables[SOCKS].AssetID = value; }
  153. }
  154. public virtual UUID JacketItem {
  155. get { return m_wearables[JACKET].ItemID; }
  156. set { m_wearables[JACKET].ItemID = value; }
  157. }
  158. public virtual UUID JacketAsset {
  159. get { return m_wearables[JACKET].AssetID; }
  160. set { m_wearables[JACKET].AssetID = value; }
  161. }
  162. public virtual UUID GlovesItem {
  163. get { return m_wearables[GLOVES].ItemID; }
  164. set { m_wearables[GLOVES].ItemID = value; }
  165. }
  166. public virtual UUID GlovesAsset {
  167. get { return m_wearables[GLOVES].AssetID; }
  168. set { m_wearables[GLOVES].AssetID = value; }
  169. }
  170. public virtual UUID UnderShirtItem {
  171. get { return m_wearables[UNDERSHIRT].ItemID; }
  172. set { m_wearables[UNDERSHIRT].ItemID = value; }
  173. }
  174. public virtual UUID UnderShirtAsset {
  175. get { return m_wearables[UNDERSHIRT].AssetID; }
  176. set { m_wearables[UNDERSHIRT].AssetID = value; }
  177. }
  178. public virtual UUID UnderPantsItem {
  179. get { return m_wearables[UNDERPANTS].ItemID; }
  180. set { m_wearables[UNDERPANTS].ItemID = value; }
  181. }
  182. public virtual UUID UnderPantsAsset {
  183. get { return m_wearables[UNDERPANTS].AssetID; }
  184. set { m_wearables[UNDERPANTS].AssetID = value; }
  185. }
  186. public virtual UUID SkirtItem {
  187. get { return m_wearables[SKIRT].ItemID; }
  188. set { m_wearables[SKIRT].ItemID = value; }
  189. }
  190. public virtual UUID SkirtAsset {
  191. get { return m_wearables[SKIRT].AssetID; }
  192. set { m_wearables[SKIRT].AssetID = value; }
  193. }
  194. public virtual void SetDefaultWearables()
  195. {
  196. m_wearables[BODY].AssetID = BODY_ASSET;
  197. m_wearables[BODY].ItemID = BODY_ITEM;
  198. m_wearables[SKIN].AssetID = SKIN_ASSET;
  199. m_wearables[SKIN].ItemID = SKIN_ITEM;
  200. m_wearables[SHIRT].AssetID = SHIRT_ASSET;
  201. m_wearables[SHIRT].ItemID = SHIRT_ITEM;
  202. m_wearables[PANTS].AssetID = PANTS_ASSET;
  203. m_wearables[PANTS].ItemID = PANTS_ITEM;
  204. }
  205. protected Primitive.TextureEntry m_texture;
  206. public virtual Primitive.TextureEntry Texture
  207. {
  208. get { return m_texture; }
  209. set { m_texture = value; }
  210. }
  211. protected float m_avatarHeight = 0;
  212. protected float m_hipOffset = 0;
  213. public virtual float AvatarHeight
  214. {
  215. get { return m_avatarHeight; }
  216. set { m_avatarHeight = value; }
  217. }
  218. public virtual float HipOffset
  219. {
  220. get { return m_hipOffset; }
  221. }
  222. public AvatarAppearance()
  223. {
  224. m_wearables = new AvatarWearable[MAX_WEARABLES];
  225. for (int i = 0; i < MAX_WEARABLES; i++)
  226. {
  227. // this makes them all null
  228. m_wearables[i] = new AvatarWearable();
  229. }
  230. m_serial = 0;
  231. m_owner = UUID.Zero;
  232. m_visualparams = new byte[VISUALPARAM_COUNT];
  233. SetDefaultWearables();
  234. m_texture = GetDefaultTexture();
  235. }
  236. public AvatarAppearance(UUID avatarID, AvatarWearable[] wearables, byte[] visualParams)
  237. {
  238. m_owner = avatarID;
  239. m_serial = 1;
  240. m_wearables = wearables;
  241. m_visualparams = visualParams;
  242. m_texture = GetDefaultTexture();
  243. }
  244. /// <summary>
  245. /// Set up appearance textures and avatar parameters, including a height calculation
  246. /// </summary>
  247. /// <param name="texture"></param>
  248. /// <param name="visualParam"></param>
  249. public virtual void SetAppearance(byte[] texture, List<byte> visualParam)
  250. {
  251. Primitive.TextureEntry textureEnt = new Primitive.TextureEntry(texture, 0, texture.Length);
  252. m_texture = textureEnt;
  253. m_visualparams = visualParam.ToArray();
  254. m_avatarHeight = 1.23077f // Shortest possible avatar height
  255. + 0.516945f * (float)m_visualparams[25] / 255.0f // Body height
  256. + 0.072514f * (float)m_visualparams[120] / 255.0f // Head size
  257. + 0.3836f * (float)m_visualparams[125] / 255.0f // Leg length
  258. + 0.08f * (float)m_visualparams[77] / 255.0f // Shoe heel height
  259. + 0.07f * (float)m_visualparams[78] / 255.0f // Shoe platform height
  260. + 0.076f * (float)m_visualparams[148] / 255.0f; // Neck length
  261. m_hipOffset = (0.615385f // Half of avatar
  262. + 0.08f * (float)m_visualparams[77] / 255.0f // Shoe heel height
  263. + 0.07f * (float)m_visualparams[78] / 255.0f // Shoe platform height
  264. + 0.3836f * (float)m_visualparams[125] / 255.0f // Leg length
  265. - m_avatarHeight / 2) * 0.3f - 0.04f;
  266. //System.Console.WriteLine("Height {0} Hip offset {1}", m_avatarHeight, m_hipOffset);
  267. }
  268. public virtual void SetWearable(int wearableId, AvatarWearable wearable)
  269. {
  270. m_wearables[wearableId] = wearable;
  271. }
  272. public static Primitive.TextureEntry GetDefaultTexture()
  273. {
  274. Primitive.TextureEntry textu = new Primitive.TextureEntry(new UUID("C228D1CF-4B5D-4BA8-84F4-899A0796AA97"));
  275. textu.CreateFace(0).TextureID = new UUID("00000000-0000-1111-9999-000000000012");
  276. textu.CreateFace(1).TextureID = new UUID("5748decc-f629-461c-9a36-a35a221fe21f");
  277. textu.CreateFace(2).TextureID = new UUID("5748decc-f629-461c-9a36-a35a221fe21f");
  278. textu.CreateFace(3).TextureID = new UUID("6522E74D-1660-4E7F-B601-6F48C1659A77");
  279. textu.CreateFace(4).TextureID = new UUID("7CA39B4C-BD19-4699-AFF7-F93FD03D3E7B");
  280. textu.CreateFace(5).TextureID = new UUID("00000000-0000-1111-9999-000000000010");
  281. textu.CreateFace(6).TextureID = new UUID("00000000-0000-1111-9999-000000000011");
  282. return textu;
  283. }
  284. public override String ToString()
  285. {
  286. String s = "[Wearables] =>";
  287. s += " Body Item: " + BodyItem.ToString() + ";";
  288. s += " Skin Item: " + SkinItem.ToString() + ";";
  289. s += " Shirt Item: " + ShirtItem.ToString() + ";";
  290. s += " Pants Item: " + PantsItem.ToString() + ";";
  291. return s;
  292. }
  293. protected AvatarAppearance(SerializationInfo info, StreamingContext context)
  294. {
  295. //System.Console.WriteLine("AvatarAppearance Deserialize BGN");
  296. if (info == null)
  297. {
  298. throw new ArgumentNullException("info");
  299. }
  300. m_owner = new UUID((Guid)info.GetValue("m_scenePresenceID", typeof(Guid)));
  301. m_serial = (int)info.GetValue("m_wearablesSerial", typeof(int));
  302. m_visualparams = (byte[])info.GetValue("m_visualParams", typeof(byte[]));
  303. m_wearables = (AvatarWearable[])info.GetValue("m_wearables", typeof(AvatarWearable[]));
  304. byte[] m_textureEntry_work = (byte[])info.GetValue("m_textureEntry", typeof(byte[]));
  305. m_texture = new Primitive.TextureEntry(m_textureEntry_work, 0, m_textureEntry_work.Length);
  306. m_avatarHeight = (float)info.GetValue("m_avatarHeight", typeof(float));
  307. //System.Console.WriteLine("AvatarAppearance Deserialize END");
  308. }
  309. // this is used for OGS1
  310. public virtual Hashtable ToHashTable()
  311. {
  312. Hashtable h = new Hashtable();
  313. h["owner"] = Owner.ToString();
  314. h["serial"] = Serial.ToString();
  315. h["visual_params"] = VisualParams;
  316. h["texture"] = Texture.ToBytes();
  317. h["avatar_height"] = AvatarHeight.ToString();
  318. h["body_item"] = BodyItem.ToString();
  319. h["body_asset"] = BodyAsset.ToString();
  320. h["skin_item"] = SkinItem.ToString();
  321. h["skin_asset"] = SkinAsset.ToString();
  322. h["hair_item"] = HairItem.ToString();
  323. h["hair_asset"] = HairAsset.ToString();
  324. h["eyes_item"] = EyesItem.ToString();
  325. h["eyes_asset"] = EyesAsset.ToString();
  326. h["shirt_item"] = ShirtItem.ToString();
  327. h["shirt_asset"] = ShirtAsset.ToString();
  328. h["pants_item"] = PantsItem.ToString();
  329. h["pants_asset"] = PantsAsset.ToString();
  330. h["shoes_item"] = ShoesItem.ToString();
  331. h["shoes_asset"] = ShoesAsset.ToString();
  332. h["socks_item"] = SocksItem.ToString();
  333. h["socks_asset"] = SocksAsset.ToString();
  334. h["jacket_item"] = JacketItem.ToString();
  335. h["jacket_asset"] = JacketAsset.ToString();
  336. h["gloves_item"] = GlovesItem.ToString();
  337. h["gloves_asset"] = GlovesAsset.ToString();
  338. h["undershirt_item"] = UnderShirtItem.ToString();
  339. h["undershirt_asset"] = UnderShirtAsset.ToString();
  340. h["underpants_item"] = UnderPantsItem.ToString();
  341. h["underpants_asset"] = UnderPantsAsset.ToString();
  342. h["skirt_item"] = SkirtItem.ToString();
  343. h["skirt_asset"] = SkirtAsset.ToString();
  344. string attachments = GetAttachmentsString();
  345. if (attachments != String.Empty)
  346. h["attachments"] = attachments;
  347. return h;
  348. }
  349. public AvatarAppearance(Hashtable h)
  350. {
  351. Owner = new UUID((string)h["owner"]);
  352. Serial = Convert.ToInt32((string)h["serial"]);
  353. VisualParams = (byte[])h["visual_params"];
  354. Texture = new Primitive.TextureEntry((byte[])h["texture"], 0, ((byte[])h["texture"]).Length);
  355. AvatarHeight = (float)Convert.ToDouble((string)h["avatar_height"]);
  356. m_wearables = new AvatarWearable[MAX_WEARABLES];
  357. for (int i = 0; i < MAX_WEARABLES; i++)
  358. {
  359. // this makes them all null
  360. m_wearables[i] = new AvatarWearable();
  361. }
  362. BodyItem = new UUID((string)h["body_item"]);
  363. BodyAsset = new UUID((string)h["body_asset"]);
  364. SkinItem = new UUID((string)h["skin_item"]);
  365. SkinAsset = new UUID((string)h["skin_asset"]);
  366. HairItem = new UUID((string)h["hair_item"]);
  367. HairAsset = new UUID((string)h["hair_asset"]);
  368. EyesItem = new UUID((string)h["eyes_item"]);
  369. EyesAsset = new UUID((string)h["eyes_asset"]);
  370. ShirtItem = new UUID((string)h["shirt_item"]);
  371. ShirtAsset = new UUID((string)h["shirt_asset"]);
  372. PantsItem = new UUID((string)h["pants_item"]);
  373. PantsAsset = new UUID((string)h["pants_asset"]);
  374. ShoesItem = new UUID((string)h["shoes_item"]);
  375. ShoesAsset = new UUID((string)h["shoes_asset"]);
  376. SocksItem = new UUID((string)h["socks_item"]);
  377. SocksAsset = new UUID((string)h["socks_asset"]);
  378. JacketItem = new UUID((string)h["jacket_item"]);
  379. JacketAsset = new UUID((string)h["jacket_asset"]);
  380. GlovesItem = new UUID((string)h["gloves_item"]);
  381. GlovesAsset = new UUID((string)h["gloves_asset"]);
  382. UnderShirtItem = new UUID((string)h["undershirt_item"]);
  383. UnderShirtAsset = new UUID((string)h["undershirt_asset"]);
  384. UnderPantsItem = new UUID((string)h["underpants_item"]);
  385. UnderPantsAsset = new UUID((string)h["underpants_asset"]);
  386. SkirtItem = new UUID((string)h["skirt_item"]);
  387. SkirtAsset = new UUID((string)h["skirt_asset"]);
  388. if (h.ContainsKey("attachments"))
  389. {
  390. SetAttachmentsString(h["attachments"].ToString());
  391. }
  392. }
  393. [SecurityPermission(SecurityAction.LinkDemand,
  394. Flags = SecurityPermissionFlag.SerializationFormatter)]
  395. public virtual void GetObjectData(
  396. SerializationInfo info, StreamingContext context)
  397. {
  398. if (info == null)
  399. {
  400. throw new ArgumentNullException("info");
  401. }
  402. info.AddValue("m_scenePresenceID", m_owner.Guid);
  403. info.AddValue("m_wearablesSerial", m_serial);
  404. info.AddValue("m_visualParams", m_visualparams);
  405. info.AddValue("m_wearables", m_wearables);
  406. info.AddValue("m_textureEntry", m_texture.ToBytes());
  407. info.AddValue("m_avatarHeight", m_avatarHeight);
  408. }
  409. private Dictionary<int, UUID[]> m_attachments = new Dictionary<int, UUID[]>();
  410. public void SetAttachments(Hashtable data)
  411. {
  412. m_attachments.Clear();
  413. if (data == null)
  414. return;
  415. foreach (DictionaryEntry e in data)
  416. {
  417. int attachpoint = Convert.ToInt32(e.Key);
  418. if (m_attachments.ContainsKey(attachpoint))
  419. continue;
  420. UUID item;
  421. UUID asset;
  422. Hashtable uuids = (Hashtable) e.Value;
  423. UUID.TryParse(uuids["item"].ToString(), out item);
  424. UUID.TryParse(uuids["asset"].ToString(), out asset);
  425. UUID[] attachment = new UUID[2];
  426. attachment[0] = item;
  427. attachment[1] = asset;
  428. m_attachments[attachpoint] = attachment;
  429. }
  430. }
  431. public Hashtable GetAttachments()
  432. {
  433. if (m_attachments.Count == 0)
  434. return null;
  435. Hashtable ret = new Hashtable();
  436. foreach (KeyValuePair<int, UUID[]> kvp in m_attachments)
  437. {
  438. int attachpoint = kvp.Key;
  439. UUID[] uuids = kvp.Value;
  440. Hashtable data = new Hashtable();
  441. data["item"] = uuids[0].ToString();
  442. data["asset"] = uuids[1].ToString();
  443. ret[attachpoint] = data;
  444. }
  445. return ret;
  446. }
  447. public List<int> GetAttachedPoints()
  448. {
  449. return new List<int>(m_attachments.Keys);
  450. }
  451. public UUID GetAttachedItem(int attachpoint)
  452. {
  453. if (!m_attachments.ContainsKey(attachpoint))
  454. return UUID.Zero;
  455. return m_attachments[attachpoint][0];
  456. }
  457. public UUID GetAttachedAsset(int attachpoint)
  458. {
  459. if (!m_attachments.ContainsKey(attachpoint))
  460. return UUID.Zero;
  461. return m_attachments[attachpoint][1];
  462. }
  463. public void SetAttachment(int attachpoint, UUID item, UUID asset)
  464. {
  465. if (attachpoint == 0)
  466. return;
  467. if (item == UUID.Zero)
  468. {
  469. if (m_attachments.ContainsKey(attachpoint))
  470. m_attachments.Remove(attachpoint);
  471. return;
  472. }
  473. if (!m_attachments.ContainsKey(attachpoint))
  474. m_attachments[attachpoint] = new UUID[2];
  475. m_attachments[attachpoint][0] = item;
  476. m_attachments[attachpoint][1] = asset;
  477. }
  478. public int GetAttachpoint(UUID itemID)
  479. {
  480. foreach (KeyValuePair<int, UUID[]> kvp in m_attachments)
  481. {
  482. if (kvp.Value[0] == itemID)
  483. {
  484. return kvp.Key;
  485. }
  486. }
  487. return 0;
  488. }
  489. public void DetachAttachment(UUID itemID)
  490. {
  491. int attachpoint = GetAttachpoint(itemID);
  492. if (attachpoint > 0)
  493. m_attachments.Remove(attachpoint);
  494. }
  495. string GetAttachmentsString()
  496. {
  497. List<string> strings = new List<string>();
  498. foreach (KeyValuePair<int, UUID[]> e in m_attachments)
  499. {
  500. strings.Add(e.Key.ToString());
  501. strings.Add(e.Value[0].ToString());
  502. strings.Add(e.Value[1].ToString());
  503. }
  504. return String.Join(",", strings.ToArray());
  505. }
  506. void SetAttachmentsString(string data)
  507. {
  508. string[] strings = data.Split(new char[] {','});
  509. int i = 0;
  510. m_attachments.Clear();
  511. while (strings.Length - i > 2)
  512. {
  513. int attachpoint = Int32.Parse(strings[i]);
  514. UUID item = new UUID(strings[i+1]);
  515. UUID asset = new UUID(strings[i+2]);
  516. i += 3;
  517. if (!m_attachments.ContainsKey(attachpoint))
  518. {
  519. m_attachments[attachpoint] = new UUID[2];
  520. m_attachments[attachpoint][0] = item;
  521. m_attachments[attachpoint][1] = asset;
  522. }
  523. }
  524. }
  525. }
  526. }