diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs | 99 |
1 files changed, 83 insertions, 16 deletions
diff --git a/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs b/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs index 820a26b..b6c373c 100644 --- a/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs +++ b/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs | |||
@@ -1,5 +1,6 @@ | |||
1 | using System; | 1 | using System; |
2 | using libsecondlife; | 2 | using libsecondlife; |
3 | using System.Collections.Generic; | ||
3 | using Nini.Config; | 4 | using Nini.Config; |
4 | using OpenSim.Framework; | 5 | using OpenSim.Framework; |
5 | using OpenSim.Framework.Communications.Cache; | 6 | using OpenSim.Framework.Communications.Cache; |
@@ -11,18 +12,30 @@ namespace OpenSim.Region.Environment.Modules | |||
11 | public class AvatarFactoryModule : IAvatarFactory | 12 | public class AvatarFactoryModule : IAvatarFactory |
12 | { | 13 | { |
13 | private Scene m_scene = null; | 14 | private Scene m_scene = null; |
15 | private Dictionary<LLUUID, AvatarWearing> m_avatarsClothes = new Dictionary<LLUUID, AvatarWearing>(); | ||
14 | 16 | ||
15 | public bool TryGetIntialAvatarAppearance(LLUUID avatarId, out AvatarWearable[] wearables, | 17 | public bool TryGetIntialAvatarAppearance(LLUUID avatarId, out AvatarWearable[] wearables, |
16 | out byte[] visualParams) | 18 | out byte[] visualParams) |
17 | { | 19 | { |
18 | GetDefaultAvatarAppearance(out wearables, out visualParams); | 20 | if (!m_avatarsClothes.ContainsKey(avatarId)) |
19 | return true; | 21 | { |
22 | GetDefaultAvatarAppearance(out wearables, out visualParams); | ||
23 | AvatarWearing wearing = new AvatarWearing(wearables); | ||
24 | m_avatarsClothes[avatarId] = wearing; | ||
25 | return true; | ||
26 | } | ||
27 | else | ||
28 | { | ||
29 | visualParams = SetDefaultVisualParams(); | ||
30 | wearables = m_avatarsClothes[avatarId].IsWearing; | ||
31 | return true; | ||
32 | } | ||
20 | } | 33 | } |
21 | 34 | ||
22 | public void Initialise(Scene scene, IConfigSource source) | 35 | public void Initialise(Scene scene, IConfigSource source) |
23 | { | 36 | { |
24 | scene.RegisterModuleInterface<IAvatarFactory>(this); | 37 | scene.RegisterModuleInterface<IAvatarFactory>(this); |
25 | // scene.EventManager.OnNewClient += NewClient; | 38 | scene.EventManager.OnNewClient += NewClient; |
26 | 39 | ||
27 | if (m_scene == null) | 40 | if (m_scene == null) |
28 | { | 41 | { |
@@ -50,43 +63,97 @@ namespace OpenSim.Region.Environment.Modules | |||
50 | 63 | ||
51 | public void NewClient(IClientAPI client) | 64 | public void NewClient(IClientAPI client) |
52 | { | 65 | { |
53 | // client.OnAvatarNowWearing += AvatarIsWearing; | 66 | client.OnAvatarNowWearing += AvatarIsWearing; |
54 | } | 67 | } |
55 | 68 | ||
56 | public void RemoveClient(IClientAPI client) | 69 | public void RemoveClient(IClientAPI client) |
57 | { | 70 | { |
58 | // client.OnAvatarNowWearing -= AvatarIsWearing; | 71 | // client.OnAvatarNowWearing -= AvatarIsWearing; |
59 | } | 72 | } |
60 | 73 | ||
61 | public void AvatarIsWearing(Object sender, AvatarWearingArgs e) | 74 | public void AvatarIsWearing(Object sender, AvatarWearingArgs e) |
62 | { | 75 | { |
63 | IClientAPI clientView = (IClientAPI) sender; | 76 | IClientAPI clientView = (IClientAPI)sender; |
64 | //Todo look up the assetid from the inventory cache (or something) for each itemId that is in AvatarWearingArgs | 77 | //Todo look up the assetid from the inventory cache (or something) for each itemId that is in AvatarWearingArgs |
65 | // then store assetid and itemId and wearable type in a database | 78 | // then store assetid and itemId and wearable type in a database |
66 | foreach (AvatarWearingArgs.Wearable wear in e.NowWearing) | 79 | foreach (AvatarWearingArgs.Wearable wear in e.NowWearing) |
67 | { | ||
68 | LLUUID assetId; | ||
69 | CachedUserInfo profile = m_scene.CommsManager.UserProfileCache.GetUserDetails(clientView.AgentId); | ||
70 | if (profile != null) | ||
71 | { | 80 | { |
72 | InventoryItemBase baseItem = profile.RootFolder.HasItem(wear.ItemID); | 81 | if (wear.Type < 13) |
73 | if (baseItem != null) | ||
74 | { | 82 | { |
75 | assetId = baseItem.assetID; | 83 | LLUUID assetId; |
84 | CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(clientView.AgentId); | ||
85 | if (profile != null) | ||
86 | { | ||
87 | InventoryItemBase baseItem = profile.RootFolder.HasItem(wear.ItemID); | ||
88 | if (baseItem != null) | ||
89 | { | ||
90 | assetId = baseItem.assetID; | ||
91 | //Tempoaray dictionary storage. This is be storing to a database | ||
92 | if (m_avatarsClothes.ContainsKey(clientView.AgentId)) | ||
93 | { | ||
94 | AvatarWearing avWearing = m_avatarsClothes[clientView.AgentId]; | ||
95 | avWearing.IsWearing[wear.Type].AssetID = assetId; | ||
96 | avWearing.IsWearing[wear.Type].ItemID = wear.ItemID; | ||
97 | } | ||
98 | } | ||
99 | } | ||
76 | } | 100 | } |
77 | } | 101 | } |
78 | } | ||
79 | } | 102 | } |
80 | 103 | ||
81 | public static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams) | 104 | public static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams) |
82 | { | 105 | { |
106 | visualParams = SetDefaultVisualParams(); | ||
107 | |||
108 | wearables = AvatarWearable.DefaultWearables; | ||
109 | } | ||
110 | |||
111 | private static byte[] SetDefaultVisualParams() | ||
112 | { | ||
113 | byte[] visualParams; | ||
83 | visualParams = new byte[218]; | 114 | visualParams = new byte[218]; |
84 | for (int i = 0; i < 218; i++) | 115 | for (int i = 0; i < 218; i++) |
85 | { | 116 | { |
86 | visualParams[i] = 100; | 117 | visualParams[i] = 100; |
87 | } | 118 | } |
119 | return visualParams; | ||
120 | } | ||
88 | 121 | ||
89 | wearables = AvatarWearable.DefaultWearables; | 122 | public class AvatarWearing |
123 | { | ||
124 | public AvatarWearable[] IsWearing; | ||
125 | |||
126 | public AvatarWearing() | ||
127 | { | ||
128 | IsWearing = new AvatarWearable[13]; | ||
129 | for (int i = 0; i < 13; i++) | ||
130 | { | ||
131 | IsWearing[i] = new AvatarWearable(); | ||
132 | } | ||
133 | } | ||
134 | |||
135 | public AvatarWearing(AvatarWearable[] wearing) | ||
136 | { | ||
137 | if (wearing.Length == 13) | ||
138 | { | ||
139 | IsWearing = new AvatarWearable[13]; | ||
140 | for (int i = 0; i < 13; i++) | ||
141 | { | ||
142 | IsWearing[i] = new AvatarWearable(); | ||
143 | IsWearing[i].AssetID = wearing[i].AssetID; | ||
144 | IsWearing[i].ItemID = wearing[i].ItemID; | ||
145 | } | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | IsWearing = new AvatarWearable[13]; | ||
150 | for (int i = 0; i < 13; i++) | ||
151 | { | ||
152 | IsWearing[i] = new AvatarWearable(); | ||
153 | } | ||
154 | } | ||
155 | } | ||
90 | } | 156 | } |
91 | } | 157 | } |
158 | |||
92 | } \ No newline at end of file | 159 | } \ No newline at end of file |