public Object Convert(Object[] values, Type targetType, Object parameter, CultureInfo culture) { if (values != null && values.Length == 3 && values[0] is PartyMemberPowerSet && values[1] is Dictionary<String, Int32> && values[2] is GiftSortOrder) { var powerSet = values[0] as PartyMemberPowerSet; var requiredExperienceByType = values[1] as Dictionary<String, Int32>; var sortOrder = (GiftSortOrder)values[2]; var availableGifts = new Power[] { powerSet.Power1, powerSet.Power2, powerSet.Power3 } .Where(x => x.IsUnlocked) .SelectMany(x => x.Gifts) .Where(x => x.GiftType.IsUnlocked) .Where(x => requiredExperienceByType.ContainsKey(x.GiftType.Id) && requiredExperienceByType[x.GiftType.Id] >= x.RequiredAbilityExperience) .OrderBy(x => { switch (sortOrder) { case GiftSortOrder.OffenseSupportDefense: return x.GiftSubtype.Name == GiftSubtype.Offensive.Name ? 1 : x.GiftSubtype.Name == GiftSubtype.Support.Name ? 2 : 3; case GiftSortOrder.OffenseDefenseSupport: return x.GiftSubtype.Name == GiftSubtype.Offensive.Name ? 1 : x.GiftSubtype.Name == GiftSubtype.Defensive.Name ? 2 : 3; case GiftSortOrder.DefenseOffenseSupport: return x.GiftSubtype.Name == GiftSubtype.Defensive.Name ? 1 : x.GiftSubtype.Name == GiftSubtype.Offensive.Name ? 2 : 3; case GiftSortOrder.DefenseSupportOffense: return x.GiftSubtype.Name == GiftSubtype.Defensive.Name ? 1 : x.GiftSubtype.Name == GiftSubtype.Support.Name ? 2 : 3; case GiftSortOrder.SupportOffenseDefense: return x.GiftSubtype.Name == GiftSubtype.Support.Name ? 1 : x.GiftSubtype.Name == GiftSubtype.Offensive.Name ? 2 : 3; case GiftSortOrder.SupportDefenseOffense: return x.GiftSubtype.Name == GiftSubtype.Support.Name ? 1 : x.GiftSubtype.Name == GiftSubtype.Defensive.Name ? 2 : 3; } return 0; }) .ThenBy(x => x.Ability.Name); return availableGifts.ToArray(); } return new Gift[0]; }