public void ReplaceOutfit(List<InventoryItem> wearableItems)
{
List<InventoryWearable> wearables = new List<InventoryWearable>();
List<InventoryItem> attachments = new List<InventoryItem>();
for (int i = 0; i < wearableItems.Count; i++)
{
InventoryItem item = wearableItems[i];
if (item is InventoryWearable)
wearables.Add((InventoryWearable)item);
else if (item is InventoryAttachment || item is InventoryObject)
attachments.Add(item);
}
// If we don't already have a the current agent wearables downloaded, updating to a
// new set of wearables that doesn't have all of the bodyparts can leave the avatar
// in an inconsistent state. If any bodypart entries are empty, we need to fetch the
// current wearables first
bool needsCurrentWearables = false;
lock (Wearables)
{
for (int i = 0; i < WEARABLE_COUNT; i++)
{
WearableType wearableType = (WearableType)i;
if (WearableTypeToAssetType(wearableType) == AssetType.Bodypart && !Wearables.ContainsKey(wearableType))
{
needsCurrentWearables = true;
break;
}
}
}
if (needsCurrentWearables && !GetAgentWearables())
{
Logger.Log("Failed to fetch the current agent wearables, cannot safely replace outfit",
Helpers.LogLevel.Error);
return;
}
// Replace our local Wearables collection, send the packet(s) to update our
// attachments, tell sim what we are wearing now, and start the baking process
ReplaceOutfit(wearables);
AddAttachments(attachments, true);
SendAgentIsNowWearing();
DelayedRequestSetAppearance();
}