Fixed more multiple enumerations

This commit is contained in:
Stepan Goremykin 2023-01-29 02:20:46 +01:00
parent 4da0b6373d
commit 4fd52bc31f
3 changed files with 61 additions and 53 deletions

View File

@ -224,10 +224,11 @@ namespace DiIiS_NA.Core.Discord
{ {
var message = await guild.GetTextChannel(channelId).GetMessageAsync(param.First().Value); var message = await guild.GetTextChannel(channelId).GetMessageAsync(param.First().Value);
var reactedUsers = await (message as IUserMessage).GetReactionUsersAsync(Emote.Parse("<:wolfRNG:607868292979490816>"), 100).FlattenAsync(); var reactedUsers = await (message as IUserMessage).GetReactionUsersAsync(Emote.Parse("<:wolfRNG:607868292979490816>"), 100).FlattenAsync();
var contestants = reactedUsers.Where(u => !u.IsBot).ToList(); var contestants = reactedUsers.Where(u => !u.IsBot).ToArray();
if (contestants.Count() > 0)
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; 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!"); 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); var acc = AccountManager.GetAccountByDiscordId(winner.Id);

View File

@ -530,18 +530,23 @@ namespace DiIiS_NA.GameServer.GSSystem.ActorSystem.Implementations.Hirelings
#region EqupimentStats #region EqupimentStats
public List<Item> GetEquippedItems(Player player) public IEnumerable<Item> GetEquippedItems(Player player)
{ {
return _equipment[player].Values.ToList(); return _equipment[player].Values;
} }
public float GetItemBonus(GameAttributeF attributeF) 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) 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]); return stats.Sum(item => item.Attributes[attributeF]);
} }

View File

@ -171,11 +171,9 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
if (IsUnique) if (IsUnique)
{ {
var restrictedFamily = item.ItemDefinition.LegendaryAffixFamily.Where(af => af != -1); var restrictedFamily = item.ItemDefinition.LegendaryAffixFamily.Where(af => af != -1).ToHashSet();
filteredList = filteredList.Where( filteredList = filteredList
a => .Where(a => !(restrictedFamily.Contains(a.AffixFamily0) || restrictedFamily.Contains(a.AffixFamily1)));
!(restrictedFamily.Contains(a.AffixFamily0) || restrictedFamily.Contains(a.AffixFamily1))
);
if (restrictedFamily.Contains(1616088365) || if (restrictedFamily.Contains(1616088365) ||
restrictedFamily.Contains(-1461069734) || restrictedFamily.Contains(-1461069734) ||
@ -184,17 +182,17 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
restrictedFamily.Contains(-812845450) || restrictedFamily.Contains(-812845450) ||
restrictedFamily.Contains(1791554648) || restrictedFamily.Contains(1791554648) ||
restrictedFamily.Contains(125900958)) //MinMaxDam and ele damage restrictedFamily.Contains(125900958)) //MinMaxDam and ele damage
filteredList = filteredList.Where( {
a => filteredList = filteredList
!a.Name.Contains("FireD") && .Where(a => !a.Name.Contains("FireD") &&
!a.Name.Contains("PoisonD") && !a.Name.Contains("PoisonD") &&
!a.Name.Contains("HolyD") && !a.Name.Contains("HolyD") &&
!a.Name.Contains("ColdD") && !a.Name.Contains("ColdD") &&
!a.Name.Contains("LightningD") && !a.Name.Contains("LightningD") &&
!a.Name.Contains("ArcaneD") && !a.Name.Contains("ArcaneD") &&
!a.Name.Contains("MinMaxDam") && !a.Name.Contains("MinMaxDam") &&
isCrafting ? !a.Name.ToLower().Contains("socket") : !a.Name.Contains("ASDHUIOPASDHIOU") isCrafting ? !a.Name.ToLower().Contains("socket") : !a.Name.Contains("ASDHUIOPASDHIOU"));
); }
} }
if (affixesCount <= 1) 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) public static int FindSuitableAffix(Item item, int affixGroup, int affixLevel, bool extendedFilter)
{ {
if (affixGroup == -1) return -1; 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<int> itemTypes = ItemGroup.HierarchyToHashList(item.ItemType); List<int> 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; int suitableAffixLevel = suitable.MaxBy(a => a.AffixLevel).AffixLevel;
suitable = suitable.Where(a => a.AffixLevel == suitableAffixLevel); suitable = suitable.Where(a => a.AffixLevel == suitableAffixLevel).ToArray();
//if (i18 && !secondGroup) //if (i18 && !secondGroup)
// suitable = suitable.Where(a => a.MaxLevel <= (Program.MaxLevel + 4)); // suitable = suitable.Where(a => a.MaxLevel <= (Program.MaxLevel + 4));
@ -347,8 +349,8 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
//else //else
//suitable = suitable.Where(a => itemTypes.ContainsAtLeastOne(a.I10)); //suitable = suitable.Where(a => itemTypes.ContainsAtLeastOne(a.I10));
if (suitable.Count() == 0) if (!suitable.Any())
suitable = all_group.Where(a => a.AffixLevel == 1); suitable = allGroup.Where(a => a.AffixLevel == 1).ToArray();
/*int suitableMaxLevel = suitable.OrderByDescending(a => a.AffixLevel).First().MaxLevel; /*int suitableMaxLevel = suitable.OrderByDescending(a => a.AffixLevel).First().MaxLevel;
int suitableAffixLevel = suitable.OrderByDescending(a => a.AffixLevel).First().AffixLevel; 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) if (suitable.Count() > 1 && i18 && !secondGroup && suitable.Where(a => a.Name.Contains("Secondary")).Count() > 0)
suitable = suitable.Where(a => a.Name.Contains("Secondary"));*/ suitable = suitable.Where(a => a.Name.Contains("Secondary"));*/
if (suitable.Count() > 0) if (suitable.Any())
return suitable.ToList()[FastRandom.Instance.Next(0, suitable.Count())].Hash; return suitable[FastRandom.Instance.Next(0, suitable.Length)].Hash;
else
return -1; 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; AffixTable definition = null;
if (findFromTotal) if (findFromTotal)
{ {
definition = AllAffix.Where(def => def.Hash == AffixGbId).FirstOrDefault(); definition = AllAffix.FirstOrDefault(def => def.Hash == affixGbId);
var testc = AllAffix.Where(def => def.ItemGroup[0] == AffixGbId || def.ItemGroup[1] == AffixGbId).FirstOrDefault(); var testc = AllAffix.FirstOrDefault(def => def.ItemGroup[0] == affixGbId || def.ItemGroup[1] == affixGbId);
} }
else else
{ {
definition = AffixList.Where(def => def.Hash == AffixGbId).FirstOrDefault(); definition = AffixList.FirstOrDefault(def => def.Hash == affixGbId);
if (definition == null) if (definition == null)
{ {
definition = LegendaryAffixList.Where(def => def.Hash == AffixGbId).FirstOrDefault(); definition = LegendaryAffixList.FirstOrDefault(def => def.Hash == affixGbId);
} }
} }
if (definition == null) if (definition == null)
{ {
Logger.Warn("Affix {0} was not found!", AffixGbId); Logger.Warn("Affix {0} was not found!", affixGbId);
return; 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()); affix.Score = (Scores.Count == 0 ? 0 : Scores.Average());
item.AffixList.Add(affix); item.AffixList.Add(affix);
//item.Attributes[GameAttribute.Item_Quality_Level]++; //item.Attributes[GameAttribute.Item_Quality_Level]++;