diff options
author | UbitUmarov | 2015-09-01 11:43:07 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 11:43:07 +0100 |
commit | fb78b182520fc9bb0f971afd0322029c70278ea6 (patch) | |
tree | b4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Framework/AvatarWearable.cs | |
parent | lixo (diff) | |
parent | Mantis #7713: fixed bug introduced by 1st MOSES patch. (diff) | |
download | opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2 opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz |
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Framework/AvatarWearable.cs')
-rw-r--r-- | OpenSim/Framework/AvatarWearable.cs | 253 |
1 files changed, 253 insertions, 0 deletions
diff --git a/OpenSim/Framework/AvatarWearable.cs b/OpenSim/Framework/AvatarWearable.cs new file mode 100644 index 0000000..8e27596 --- /dev/null +++ b/OpenSim/Framework/AvatarWearable.cs | |||
@@ -0,0 +1,253 @@ | |||
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 | public static readonly int ALPHA = 13; | ||
66 | public static readonly int TATTOO = 14; | ||
67 | |||
68 | public static readonly int MAX_WEARABLES = 15; | ||
69 | |||
70 | public static readonly UUID DEFAULT_BODY_ITEM = new UUID("66c41e39-38f9-f75a-024e-585989bfaba9"); | ||
71 | public static readonly UUID DEFAULT_BODY_ASSET = new UUID("66c41e39-38f9-f75a-024e-585989bfab73"); | ||
72 | |||
73 | public static readonly UUID DEFAULT_HAIR_ITEM = new UUID("d342e6c1-b9d2-11dc-95ff-0800200c9a66"); | ||
74 | public static readonly UUID DEFAULT_HAIR_ASSET = new UUID("d342e6c0-b9d2-11dc-95ff-0800200c9a66"); | ||
75 | |||
76 | public static readonly UUID DEFAULT_SKIN_ITEM = new UUID("77c41e39-38f9-f75a-024e-585989bfabc9"); | ||
77 | public static readonly UUID DEFAULT_SKIN_ASSET = new UUID("77c41e39-38f9-f75a-024e-585989bbabbb"); | ||
78 | |||
79 | public static readonly UUID DEFAULT_SHIRT_ITEM = new UUID("77c41e39-38f9-f75a-0000-585989bf0000"); | ||
80 | public static readonly UUID DEFAULT_SHIRT_ASSET = new UUID("00000000-38f9-1111-024e-222222111110"); | ||
81 | |||
82 | public static readonly UUID DEFAULT_PANTS_ITEM = new UUID("77c41e39-38f9-f75a-0000-5859892f1111"); | ||
83 | public static readonly UUID DEFAULT_PANTS_ASSET = new UUID("00000000-38f9-1111-024e-222222111120"); | ||
84 | |||
85 | // public static readonly UUID DEFAULT_ALPHA_ITEM = new UUID("bfb9923c-4838-4d2d-bf07-608c5b1165c8"); | ||
86 | // public static readonly UUID DEFAULT_ALPHA_ASSET = new UUID("1578a2b1-5179-4b53-b618-fe00ca5a5594"); | ||
87 | |||
88 | // public static readonly UUID DEFAULT_TATTOO_ITEM = new UUID("c47e22bd-3021-4ba4-82aa-2b5cb34d35e1"); | ||
89 | // public static readonly UUID DEFAULT_TATTOO_ASSET = new UUID("00000000-0000-2222-3333-100000001007"); | ||
90 | |||
91 | protected Dictionary<UUID, UUID> m_items = new Dictionary<UUID, UUID>(); | ||
92 | protected List<UUID> m_ids = new List<UUID>(); | ||
93 | |||
94 | public AvatarWearable() | ||
95 | { | ||
96 | } | ||
97 | |||
98 | public AvatarWearable(UUID itemID, UUID assetID) | ||
99 | { | ||
100 | Wear(itemID, assetID); | ||
101 | } | ||
102 | |||
103 | public AvatarWearable(OSDArray args) | ||
104 | { | ||
105 | Unpack(args); | ||
106 | } | ||
107 | |||
108 | public OSD Pack() | ||
109 | { | ||
110 | OSDArray wearlist = new OSDArray(); | ||
111 | |||
112 | foreach (UUID id in m_ids) | ||
113 | { | ||
114 | OSDMap weardata = new OSDMap(); | ||
115 | weardata["item"] = OSD.FromUUID(id); | ||
116 | weardata["asset"] = OSD.FromUUID(m_items[id]); | ||
117 | wearlist.Add(weardata); | ||
118 | } | ||
119 | |||
120 | return wearlist; | ||
121 | } | ||
122 | |||
123 | public void Unpack(OSDArray args) | ||
124 | { | ||
125 | Clear(); | ||
126 | |||
127 | foreach (OSDMap weardata in args) | ||
128 | { | ||
129 | Add(weardata["item"].AsUUID(), weardata["asset"].AsUUID()); | ||
130 | } | ||
131 | } | ||
132 | |||
133 | public int Count | ||
134 | { | ||
135 | get { return m_ids.Count; } | ||
136 | } | ||
137 | |||
138 | public void Add(UUID itemID, UUID assetID) | ||
139 | { | ||
140 | if (itemID == UUID.Zero) | ||
141 | return; | ||
142 | if (m_items.ContainsKey(itemID)) | ||
143 | { | ||
144 | m_items[itemID] = assetID; | ||
145 | return; | ||
146 | } | ||
147 | if (m_ids.Count >= 5) | ||
148 | return; | ||
149 | |||
150 | m_ids.Add(itemID); | ||
151 | m_items[itemID] = assetID; | ||
152 | } | ||
153 | |||
154 | public void Wear(WearableItem item) | ||
155 | { | ||
156 | Wear(item.ItemID, item.AssetID); | ||
157 | } | ||
158 | |||
159 | public void Wear(UUID itemID, UUID assetID) | ||
160 | { | ||
161 | Clear(); | ||
162 | Add(itemID, assetID); | ||
163 | } | ||
164 | |||
165 | public void Clear() | ||
166 | { | ||
167 | m_ids.Clear(); | ||
168 | m_items.Clear(); | ||
169 | } | ||
170 | |||
171 | public void RemoveItem(UUID itemID) | ||
172 | { | ||
173 | if (m_items.ContainsKey(itemID)) | ||
174 | { | ||
175 | m_ids.Remove(itemID); | ||
176 | m_items.Remove(itemID); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | public void RemoveAsset(UUID assetID) | ||
181 | { | ||
182 | UUID itemID = UUID.Zero; | ||
183 | |||
184 | foreach (KeyValuePair<UUID, UUID> kvp in m_items) | ||
185 | { | ||
186 | if (kvp.Value == assetID) | ||
187 | { | ||
188 | itemID = kvp.Key; | ||
189 | break; | ||
190 | } | ||
191 | } | ||
192 | |||
193 | if (itemID != UUID.Zero) | ||
194 | { | ||
195 | m_ids.Remove(itemID); | ||
196 | m_items.Remove(itemID); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | public WearableItem this [int idx] | ||
201 | { | ||
202 | get | ||
203 | { | ||
204 | if (idx >= m_ids.Count || idx < 0) | ||
205 | return new WearableItem(UUID.Zero, UUID.Zero); | ||
206 | |||
207 | return new WearableItem(m_ids[idx], m_items[m_ids[idx]]); | ||
208 | } | ||
209 | } | ||
210 | |||
211 | public UUID GetAsset(UUID itemID) | ||
212 | { | ||
213 | if (!m_items.ContainsKey(itemID)) | ||
214 | return UUID.Zero; | ||
215 | return m_items[itemID]; | ||
216 | } | ||
217 | |||
218 | public static AvatarWearable[] DefaultWearables | ||
219 | { | ||
220 | get | ||
221 | { | ||
222 | AvatarWearable[] defaultWearables = new AvatarWearable[MAX_WEARABLES]; //should be 15 of these | ||
223 | for (int i = 0; i < MAX_WEARABLES; i++) | ||
224 | { | ||
225 | defaultWearables[i] = new AvatarWearable(); | ||
226 | } | ||
227 | |||
228 | // Body | ||
229 | defaultWearables[BODY].Add(DEFAULT_BODY_ITEM, DEFAULT_BODY_ASSET); | ||
230 | |||
231 | // Hair | ||
232 | defaultWearables[HAIR].Add(DEFAULT_HAIR_ITEM, DEFAULT_HAIR_ASSET); | ||
233 | |||
234 | // Skin | ||
235 | defaultWearables[SKIN].Add(DEFAULT_SKIN_ITEM, DEFAULT_SKIN_ASSET); | ||
236 | |||
237 | // Shirt | ||
238 | defaultWearables[SHIRT].Add(DEFAULT_SHIRT_ITEM, DEFAULT_SHIRT_ASSET); | ||
239 | |||
240 | // Pants | ||
241 | defaultWearables[PANTS].Add(DEFAULT_PANTS_ITEM, DEFAULT_PANTS_ASSET); | ||
242 | |||
243 | // // Alpha | ||
244 | // defaultWearables[ALPHA].Add(DEFAULT_ALPHA_ITEM, DEFAULT_ALPHA_ASSET); | ||
245 | |||
246 | // // Tattoo | ||
247 | // defaultWearables[TATTOO].Add(DEFAULT_TATTOO_ITEM, DEFAULT_TATTOO_ASSET); | ||
248 | |||
249 | return defaultWearables; | ||
250 | } | ||
251 | } | ||
252 | } | ||
253 | } | ||