public void CreateMatchingSetFrom(IEnumerable <IArmorGetter> others, bool addAll = false) { ConcurrentDictionary <string, ConcurrentDictionary <string, TArmor> > matchedArmors1 = new(); IEnumerable <TArmor> armorParts = others .Where(x => (ArmorUtils.GetMaterial(x).Equals(Material) || x.HasKeyword(Skyrim.Keyword.ArmorJewelry)) && Type.Equals(ArmorUtils.GetArmorType(x))) .Select(x => new TArmor(x)); if (!addAll) { var block = new ActionBlock <TArmor>( armor => { var armorName = armor.Name; if (HelperUtils.GetMatchingWordCount(Body.Name, armorName) > 0) { armor.BodySlots.Select(x => x.ToString()).ForEach(flag => { if (!matchedArmors1.ContainsKey(flag)) { matchedArmors1.TryAdd(flag, new ConcurrentDictionary <string, TArmor>()); } matchedArmors1.GetValueOrDefault(flag) .TryAdd(HelperUtils.GetMatchingWordCount(Body.Name, armorName).ToString(), armor); }); } }, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 30 }); foreach (var armor in armorParts) { block.Post(armor); } block.Complete(); block.Completion.Wait(); var armors = matchedArmors1.Values.Select(x => x.OrderBy(k => k.Key).Last().Value); this.AddArmors(armors); Logger.DebugFormat("Created Armors Set: {0}=> [{1}]", Body.FormKey.ModKey.FileName, string.Join(", ", Armors.Select(x => x.Name))); } else { this.AddArmors(armorParts); } }
public void CreateMatchingSetFrom(IEnumerable <IWeaponGetter> weapons, int bodyCounts, bool addAll = false) { ConcurrentDictionary <string, SortedSet <IWeaponGetter> > map = new(); ConcurrentDictionary <string, ConcurrentDictionary <string, IWeaponGetter> > matchedMap = new(); bool matched = false; if (!addAll) { var block = new ActionBlock <IWeaponGetter>( weapon => { var weaponName = ArmorUtils.ResolveItemName(weapon); if (HelperUtils.GetMatchingWordCount(Body.Name, weaponName) > 0) { matched = true; var type = weapon.Data.AnimationType.ToString(); if (!matchedMap.ContainsKey(type)) { matchedMap.TryAdd(type, new ConcurrentDictionary <string, IWeaponGetter>()); } matchedMap.GetValueOrDefault(type) .TryAdd(HelperUtils.GetMatchingWordCount(Body.Name, weaponName).ToString(), weapon); } }, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 10 }); foreach (var weapon in weapons) { block.Post(weapon); } block.Complete(); block.Completion.Wait(); var weaps = matchedMap.Values.Select(x => x.OrderBy(k => k.Key).Last().Value); this.AddWeapons(weaps); } else if (addAll || (!matched && bodyCounts < 5)) { this.AddWeapons(weapons); } }