From 4fd52bc31f232bce57450d1c0df7d4ee7b4e5852 Mon Sep 17 00:00:00 2001 From: Stepan Goremykin Date: Sun, 29 Jan 2023 02:20:46 +0100 Subject: [PATCH] Fixed more multiple enumerations --- src/DiIiS-NA/Core/Discord/Bot.cs | 7 +- .../Implementations/Hirelings/Hireling.cs | 15 ++- .../GSSystem/ItemsSystem/AffixGenerator.cs | 92 ++++++++++--------- 3 files changed, 61 insertions(+), 53 deletions(-) diff --git a/src/DiIiS-NA/Core/Discord/Bot.cs b/src/DiIiS-NA/Core/Discord/Bot.cs index 00f421d..c713b82 100644 --- a/src/DiIiS-NA/Core/Discord/Bot.cs +++ b/src/DiIiS-NA/Core/Discord/Bot.cs @@ -224,10 +224,11 @@ namespace DiIiS_NA.Core.Discord { var message = await guild.GetTextChannel(channelId).GetMessageAsync(param.First().Value); var reactedUsers = await (message as IUserMessage).GetReactionUsersAsync(Emote.Parse("<:wolfRNG:607868292979490816>"), 100).FlattenAsync(); - var contestants = reactedUsers.Where(u => !u.IsBot).ToList(); - if (contestants.Count() > 0) + var contestants = reactedUsers.Where(u => !u.IsBot).ToArray(); + + if (contestants.Length > 0) { - var winner = reactedUsers.Where(u => !u.IsBot).ToList()[DiIiS_NA.Core.Helpers.Math.FastRandom.Instance.Next(0, reactedUsers.Count() - 1)]; + var winner = contestants[Helpers.Math.FastRandom.Instance.Next(0, contestants.Length - 1)]; winnerName = guild.GetUser(winner.Id).Nickname; await winner.SendMessageAsync("Congratulations! You have won **7 days of D3 Reflection Premium**!.\nYour account has already had its Premium prolonged. Have a nice game!"); var acc = AccountManager.GetAccountByDiscordId(winner.Id); diff --git a/src/DiIiS-NA/D3-GameServer/GSSystem/ActorSystem/Implementations/Hirelings/Hireling.cs b/src/DiIiS-NA/D3-GameServer/GSSystem/ActorSystem/Implementations/Hirelings/Hireling.cs index 9b5803b..34afbd0 100644 --- a/src/DiIiS-NA/D3-GameServer/GSSystem/ActorSystem/Implementations/Hirelings/Hireling.cs +++ b/src/DiIiS-NA/D3-GameServer/GSSystem/ActorSystem/Implementations/Hirelings/Hireling.cs @@ -530,18 +530,23 @@ namespace DiIiS_NA.GameServer.GSSystem.ActorSystem.Implementations.Hirelings #region EqupimentStats - public List GetEquippedItems(Player player) + public IEnumerable GetEquippedItems(Player player) { - return _equipment[player].Values.ToList(); + return _equipment[player].Values; } public float GetItemBonus(GameAttributeF attributeF) { - var stats = GetEquippedItems(owner).Where(item => item.Attributes[GameAttribute.Durability_Cur] > 0 || item.Attributes[GameAttribute.Durability_Max] == 0); + var stats = GetEquippedItems(owner) + .Where(item => item.Attributes[GameAttribute.Durability_Cur] > 0 || + item.Attributes[GameAttribute.Durability_Max] == 0); if (attributeF == GameAttribute.Attacks_Per_Second_Item) - return stats.Count() > 0 ? stats.Select(item => item.Attributes[attributeF]).Where(a => a > 0f).Aggregate(1f, (x, y) => x * y) : 0f; - + { + return stats.Any() + ? stats.Select(item => item.Attributes[attributeF]).Where(a => a > 0f).Aggregate(1f, (x, y) => x * y) + : 0f; + } return stats.Sum(item => item.Attributes[attributeF]); } diff --git a/src/DiIiS-NA/D3-GameServer/GSSystem/ItemsSystem/AffixGenerator.cs b/src/DiIiS-NA/D3-GameServer/GSSystem/ItemsSystem/AffixGenerator.cs index cc1b8a1..951378b 100644 --- a/src/DiIiS-NA/D3-GameServer/GSSystem/ItemsSystem/AffixGenerator.cs +++ b/src/DiIiS-NA/D3-GameServer/GSSystem/ItemsSystem/AffixGenerator.cs @@ -171,30 +171,28 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem if (IsUnique) { - var restrictedFamily = item.ItemDefinition.LegendaryAffixFamily.Where(af => af != -1); - filteredList = filteredList.Where( - a => - !(restrictedFamily.Contains(a.AffixFamily0) || restrictedFamily.Contains(a.AffixFamily1)) - ); + var restrictedFamily = item.ItemDefinition.LegendaryAffixFamily.Where(af => af != -1).ToHashSet(); + filteredList = filteredList + .Where(a => !(restrictedFamily.Contains(a.AffixFamily0) || restrictedFamily.Contains(a.AffixFamily1))); if (restrictedFamily.Contains(1616088365) || - restrictedFamily.Contains(-1461069734) || - restrictedFamily.Contains(234326220) || - restrictedFamily.Contains(1350281776) || - restrictedFamily.Contains(-812845450) || - restrictedFamily.Contains(1791554648) || - restrictedFamily.Contains(125900958)) //MinMaxDam and ele damage - filteredList = filteredList.Where( - a => - !a.Name.Contains("FireD") && - !a.Name.Contains("PoisonD") && - !a.Name.Contains("HolyD") && - !a.Name.Contains("ColdD") && - !a.Name.Contains("LightningD") && - !a.Name.Contains("ArcaneD") && - !a.Name.Contains("MinMaxDam") && - isCrafting ? !a.Name.ToLower().Contains("socket") : !a.Name.Contains("ASDHUIOPASDHIOU") - ); + restrictedFamily.Contains(-1461069734) || + restrictedFamily.Contains(234326220) || + restrictedFamily.Contains(1350281776) || + restrictedFamily.Contains(-812845450) || + restrictedFamily.Contains(1791554648) || + restrictedFamily.Contains(125900958)) //MinMaxDam and ele damage + { + filteredList = filteredList + .Where(a => !a.Name.Contains("FireD") && + !a.Name.Contains("PoisonD") && + !a.Name.Contains("HolyD") && + !a.Name.Contains("ColdD") && + !a.Name.Contains("LightningD") && + !a.Name.Contains("ArcaneD") && + !a.Name.Contains("MinMaxDam") && + isCrafting ? !a.Name.ToLower().Contains("socket") : !a.Name.Contains("ASDHUIOPASDHIOU")); + } } if (affixesCount <= 1) @@ -321,24 +319,28 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem public static int FindSuitableAffix(Item item, int affixGroup, int affixLevel, bool extendedFilter) { if (affixGroup == -1) return -1; - var all_group = LegendaryAffixList.Where(a => (a.AffixFamily0 == affixGroup || a.AffixFamily1 == affixGroup) && (Item.Is2H(item.ItemType) ? !a.Name.EndsWith("1h") : (!a.Name.Contains("Two-Handed") && !a.Name.EndsWith("2h")))); + var allGroup = LegendaryAffixList + .Where(a => (a.AffixFamily0 == affixGroup || a.AffixFamily1 == affixGroup) && (Item.Is2H(item.ItemType) ? !a.Name.EndsWith("1h") : (!a.Name.Contains("Two-Handed") && !a.Name.EndsWith("2h")))) + .ToArray(); - if (all_group.Count() == 0) return -1; + if (!allGroup.Any()) return -1; - bool secondGroup = (all_group.First().AffixFamily1 == affixGroup); + bool secondGroup = allGroup.First().AffixFamily1 == affixGroup; - var suitable = all_group.Where(a => a.AffixLevel <= affixLevel || affixLevel <= 0); + var suitable = allGroup.Where(a => a.AffixLevel <= affixLevel || affixLevel <= 0).ToArray(); - if (suitable.Count() == 0) return -1; + if (!suitable.Any()) return -1; List itemTypes = ItemGroup.HierarchyToHashList(item.ItemType); - suitable = suitable.Where(a => itemTypes.ContainsAtLeastOne(a.ItemGroup) || (extendedFilter ? itemTypes.ContainsAtLeastOne(a.LegendaryAllowedTypes) : false)); + suitable = suitable.Where(a => + itemTypes.ContainsAtLeastOne(a.ItemGroup) || + (extendedFilter && itemTypes.ContainsAtLeastOne(a.LegendaryAllowedTypes))).ToArray(); - if (suitable.Count() == 0) return -1; + if (!suitable.Any()) return -1; - int suitableAffixLevel = suitable.OrderByDescending(a => a.AffixLevel).First().AffixLevel; - suitable = suitable.Where(a => a.AffixLevel == suitableAffixLevel); + int suitableAffixLevel = suitable.MaxBy(a => a.AffixLevel).AffixLevel; + suitable = suitable.Where(a => a.AffixLevel == suitableAffixLevel).ToArray(); //if (i18 && !secondGroup) // suitable = suitable.Where(a => a.MaxLevel <= (Program.MaxLevel + 4)); @@ -347,8 +349,8 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem //else //suitable = suitable.Where(a => itemTypes.ContainsAtLeastOne(a.I10)); - if (suitable.Count() == 0) - suitable = all_group.Where(a => a.AffixLevel == 1); + if (!suitable.Any()) + suitable = allGroup.Where(a => a.AffixLevel == 1).ToArray(); /*int suitableMaxLevel = suitable.OrderByDescending(a => a.AffixLevel).First().MaxLevel; int suitableAffixLevel = suitable.OrderByDescending(a => a.AffixLevel).First().AffixLevel; @@ -361,36 +363,36 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem if (suitable.Count() > 1 && i18 && !secondGroup && suitable.Where(a => a.Name.Contains("Secondary")).Count() > 0) suitable = suitable.Where(a => a.Name.Contains("Secondary"));*/ - if (suitable.Count() > 0) - return suitable.ToList()[FastRandom.Instance.Next(0, suitable.Count())].Hash; - else - return -1; + if (suitable.Any()) + return suitable[FastRandom.Instance.Next(0, suitable.Length)].Hash; + + return -1; } - public static void AddAffix(Item item, int AffixGbId, bool findFromTotal = false) + public static void AddAffix(Item item, int affixGbId, bool findFromTotal = false) { - if (AffixGbId == -1) return; + if (affixGbId == -1) return; AffixTable definition = null; if (findFromTotal) { - definition = AllAffix.Where(def => def.Hash == AffixGbId).FirstOrDefault(); - var testc = AllAffix.Where(def => def.ItemGroup[0] == AffixGbId || def.ItemGroup[1] == AffixGbId).FirstOrDefault(); + definition = AllAffix.FirstOrDefault(def => def.Hash == affixGbId); + var testc = AllAffix.FirstOrDefault(def => def.ItemGroup[0] == affixGbId || def.ItemGroup[1] == affixGbId); } else { - definition = AffixList.Where(def => def.Hash == AffixGbId).FirstOrDefault(); + definition = AffixList.FirstOrDefault(def => def.Hash == affixGbId); if (definition == null) { - definition = LegendaryAffixList.Where(def => def.Hash == AffixGbId).FirstOrDefault(); + definition = LegendaryAffixList.FirstOrDefault(def => def.Hash == affixGbId); } } if (definition == null) { - Logger.Warn("Affix {0} was not found!", AffixGbId); + Logger.Warn("Affix {0} was not found!", affixGbId); return; } @@ -444,7 +446,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem } } } - var affix = new Affix(AffixGbId); + var affix = new Affix(affixGbId); affix.Score = (Scores.Count == 0 ? 0 : Scores.Average()); item.AffixList.Add(affix); //item.Attributes[GameAttribute.Item_Quality_Level]++;