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