AvatarWearable.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 OpenSimulator 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.Generic;
  29. using OpenMetaverse;
  30. using OpenMetaverse.StructuredData;
  31. namespace OpenSim.Framework
  32. {
  33. public struct WearableItem
  34. {
  35. public UUID ItemID;
  36. public UUID AssetID;
  37. public WearableItem(UUID itemID, UUID assetID)
  38. {
  39. ItemID = itemID;
  40. AssetID = assetID;
  41. }
  42. }
  43. public class AvatarWearable
  44. {
  45. // these are guessed at by the list here -
  46. // http://wiki.secondlife.com/wiki/Avatar_Appearance. We'll
  47. // correct them over time for when were are wrong.
  48. public static readonly int BODY = 0;
  49. public static readonly int SKIN = 1;
  50. public static readonly int HAIR = 2;
  51. public static readonly int EYES = 3;
  52. public static readonly int SHIRT = 4;
  53. public static readonly int PANTS = 5;
  54. public static readonly int SHOES = 6;
  55. public static readonly int SOCKS = 7;
  56. public static readonly int JACKET = 8;
  57. public static readonly int GLOVES = 9;
  58. public static readonly int UNDERSHIRT = 10;
  59. public static readonly int UNDERPANTS = 11;
  60. public static readonly int SKIRT = 12;
  61. public static readonly int MAX_BASICWEARABLES = 13;
  62. public static readonly int ALPHA = 13;
  63. public static readonly int TATTOO = 14;
  64. public static readonly int LEGACY_VERSION_MAX_WEARABLES = 15;
  65. public static readonly int PHYSICS = 15;
  66. public static int MAX_WEARABLES_PV7 = 16;
  67. public static readonly int UNIVERSAL = 16;
  68. public static int MAX_WEARABLES = 17;
  69. public static readonly UUID DEFAULT_BODY_ITEM = new UUID("66c41e39-38f9-f75a-024e-585989bfaba9");
  70. public static readonly UUID DEFAULT_BODY_ASSET = new UUID("66c41e39-38f9-f75a-024e-585989bfab73");
  71. public static readonly UUID DEFAULT_HAIR_ITEM = new UUID("d342e6c1-b9d2-11dc-95ff-0800200c9a66");
  72. public static readonly UUID DEFAULT_HAIR_ASSET = new UUID("d342e6c0-b9d2-11dc-95ff-0800200c9a66");
  73. public static readonly UUID DEFAULT_SKIN_ITEM = new UUID("77c41e39-38f9-f75a-024e-585989bfabc9");
  74. public static readonly UUID DEFAULT_SKIN_ASSET = new UUID("77c41e39-38f9-f75a-024e-585989bbabbb");
  75. public static readonly UUID DEFAULT_EYES_ITEM = new UUID("cdc31054-eed8-4021-994f-4e0c6e861b50");
  76. public static readonly UUID DEFAULT_EYES_ASSET = new UUID("4bb6fa4d-1cd2-498a-a84c-95c1a0e745a7");
  77. public static readonly UUID DEFAULT_SHIRT_ITEM = new UUID("77c41e39-38f9-f75a-0000-585989bf0000");
  78. public static readonly UUID DEFAULT_SHIRT_ASSET = new UUID("00000000-38f9-1111-024e-222222111110");
  79. public static readonly UUID DEFAULT_PANTS_ITEM = new UUID("77c41e39-38f9-f75a-0000-5859892f1111");
  80. public static readonly UUID DEFAULT_PANTS_ASSET = new UUID("00000000-38f9-1111-024e-222222111120");
  81. public static readonly UUID DEFAULT_ALPHA_ITEM = new UUID("bfb9923c-4838-4d2d-bf07-608c5b1165c8");
  82. public static readonly UUID DEFAULT_ALPHA_ASSET = new UUID("1578a2b1-5179-4b53-b618-fe00ca5a5594");
  83. public static readonly UUID DEFAULT_TATTOO_ITEM = new UUID("c47e22bd-3021-4ba4-82aa-2b5cb34d35e1");
  84. public static readonly UUID DEFAULT_TATTOO_ASSET = new UUID("00000000-0000-2222-3333-100000001007");
  85. protected Dictionary<UUID, UUID> m_items = new Dictionary<UUID, UUID>();
  86. protected List<UUID> m_ids = new List<UUID>();
  87. public AvatarWearable()
  88. {
  89. }
  90. public AvatarWearable(UUID itemID, UUID assetID)
  91. {
  92. Wear(itemID, assetID);
  93. }
  94. public AvatarWearable(OSDArray args)
  95. {
  96. Unpack(args);
  97. }
  98. public OSD Pack()
  99. {
  100. OSDArray wearlist = new OSDArray();
  101. foreach (UUID id in m_ids)
  102. {
  103. OSDMap weardata = new OSDMap();
  104. weardata["item"] = OSD.FromUUID(id);
  105. weardata["asset"] = OSD.FromUUID(m_items[id]);
  106. wearlist.Add(weardata);
  107. }
  108. return wearlist;
  109. }
  110. public void Unpack(OSDArray args)
  111. {
  112. Clear();
  113. OSD tmpOSDA, tmpOSDB;
  114. foreach (OSDMap weardata in args)
  115. {
  116. tmpOSDA = weardata["item"];
  117. tmpOSDB = weardata["asset"];
  118. Add(tmpOSDA.AsUUID(), tmpOSDB.AsUUID());
  119. }
  120. }
  121. public int Count
  122. {
  123. get { return m_ids.Count; }
  124. }
  125. public void Add(UUID itemID, UUID assetID)
  126. {
  127. if (itemID == UUID.Zero)
  128. return;
  129. if (m_items.ContainsKey(itemID))
  130. {
  131. m_items[itemID] = assetID;
  132. return;
  133. }
  134. if (m_ids.Count >= 5)
  135. return;
  136. m_ids.Add(itemID);
  137. m_items[itemID] = assetID;
  138. }
  139. public void Wear(WearableItem item)
  140. {
  141. Wear(item.ItemID, item.AssetID);
  142. }
  143. public void Wear(UUID itemID, UUID assetID)
  144. {
  145. Clear();
  146. Add(itemID, assetID);
  147. }
  148. public void Clear()
  149. {
  150. m_ids.Clear();
  151. m_items.Clear();
  152. }
  153. public void RemoveItem(UUID itemID)
  154. {
  155. if (m_items.ContainsKey(itemID))
  156. {
  157. m_ids.Remove(itemID);
  158. m_items.Remove(itemID);
  159. }
  160. }
  161. public void RemoveAsset(UUID assetID)
  162. {
  163. UUID itemID = UUID.Zero;
  164. foreach (KeyValuePair<UUID, UUID> kvp in m_items)
  165. {
  166. if (kvp.Value == assetID)
  167. {
  168. itemID = kvp.Key;
  169. break;
  170. }
  171. }
  172. if (itemID != UUID.Zero)
  173. {
  174. m_ids.Remove(itemID);
  175. m_items.Remove(itemID);
  176. }
  177. }
  178. public WearableItem this [int idx]
  179. {
  180. get
  181. {
  182. if (idx >= m_ids.Count || idx < 0)
  183. return new WearableItem(UUID.Zero, UUID.Zero);
  184. return new WearableItem(m_ids[idx], m_items[m_ids[idx]]);
  185. }
  186. }
  187. public UUID GetAsset(UUID itemID)
  188. {
  189. if (!m_items.ContainsKey(itemID))
  190. return UUID.Zero;
  191. return m_items[itemID];
  192. }
  193. public static AvatarWearable[] DefaultWearables
  194. {
  195. get
  196. {
  197. // We use the legacy count here because this is just a fallback anyway
  198. AvatarWearable[] defaultWearables = new AvatarWearable[LEGACY_VERSION_MAX_WEARABLES];
  199. for (int i = 0; i < LEGACY_VERSION_MAX_WEARABLES; i++)
  200. {
  201. defaultWearables[i] = new AvatarWearable();
  202. }
  203. // Body
  204. defaultWearables[BODY].Add(DEFAULT_BODY_ITEM, DEFAULT_BODY_ASSET);
  205. // Hair
  206. defaultWearables[HAIR].Add(DEFAULT_HAIR_ITEM, DEFAULT_HAIR_ASSET);
  207. // Skin
  208. defaultWearables[SKIN].Add(DEFAULT_SKIN_ITEM, DEFAULT_SKIN_ASSET);
  209. // Eyes
  210. defaultWearables[EYES].Add(DEFAULT_EYES_ITEM, DEFAULT_EYES_ASSET);
  211. // Shirt
  212. defaultWearables[SHIRT].Add(DEFAULT_SHIRT_ITEM, DEFAULT_SHIRT_ASSET);
  213. // Pants
  214. defaultWearables[PANTS].Add(DEFAULT_PANTS_ITEM, DEFAULT_PANTS_ASSET);
  215. // // Alpha
  216. // defaultWearables[ALPHA].Add(DEFAULT_ALPHA_ITEM, DEFAULT_ALPHA_ASSET);
  217. // // Tattoo
  218. // defaultWearables[TATTOO].Add(DEFAULT_TATTOO_ITEM, DEFAULT_TATTOO_ASSET);
  219. // // Physics
  220. // defaultWearables[PHYSICS].Add(DEFAULT_TATTOO_ITEM, DEFAULT_TATTOO_ASSET);
  221. return defaultWearables;
  222. }
  223. }
  224. }
  225. }