From 89b078caecb533975ff2635ce671c5f87fc16fce Mon Sep 17 00:00:00 2001 From: Luca Date: Wed, 16 Jun 2021 17:42:10 +0200 Subject: [PATCH 1/2] fix for `The given key 'x' was not present in dictionary.` --- HalgarisRPGLoot/ArmorAnalyzer.cs | 3 ++- HalgarisRPGLoot/WeaponAnalyer.cs | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/HalgarisRPGLoot/ArmorAnalyzer.cs b/HalgarisRPGLoot/ArmorAnalyzer.cs index 8f1f5ab..7bf9022 100644 --- a/HalgarisRPGLoot/ArmorAnalyzer.cs +++ b/HalgarisRPGLoot/ArmorAnalyzer.cs @@ -95,13 +95,14 @@ public void Analyze() AllLevels = AllEnchantments.Select(e => e.Level).Distinct().ToHashSet(); + short maxLvl = AllListItems.Select(i => i.Entry.Data.Level).Distinct().ToHashSet().Max(); ByLevel = AllEnchantments.GroupBy(e => e.Level) .OrderBy(e => e.Key) .Select(e => (e.Key, e.ToArray())) .ToArray(); - ByLevelIndexed = Enumerable.Range(0, 100) + ByLevelIndexed = Enumerable.Range(0, maxLvl+1) .Select(lvl => (lvl, ByLevel.Where(bl => bl.Key <= lvl).SelectMany(e => e.Item2).ToArray())) .ToDictionary(kv => kv.lvl, kv => kv.Item2); } diff --git a/HalgarisRPGLoot/WeaponAnalyer.cs b/HalgarisRPGLoot/WeaponAnalyer.cs index 38798c2..82bfe82 100644 --- a/HalgarisRPGLoot/WeaponAnalyer.cs +++ b/HalgarisRPGLoot/WeaponAnalyer.cs @@ -95,12 +95,14 @@ public void Analyze() AllLevels = AllEnchantments.Select(e => e.Level).Distinct().ToHashSet(); + short maxLvl = AllListItems.Select(i => i.Entry.Data.Level).Distinct().ToHashSet().Max(); + ByLevel = AllEnchantments.GroupBy(e => e.Level) .OrderBy(e => e.Key) .Select(e => (e.Key, e.ToArray())) .ToArray(); - ByLevelIndexed = Enumerable.Range(0, 100) + ByLevelIndexed = Enumerable.Range(0, maxLvl+1) .Select(lvl => (lvl, ByLevel.Where(bl => bl.Key <= lvl).SelectMany(e => e.Item2).ToArray())) .ToDictionary(kv => kv.lvl, kv => kv.Item2); } From 430cc4253c78901e772585ce14cd293af35fe63a Mon Sep 17 00:00:00 2001 From: Luca Date: Wed, 16 Jun 2021 19:05:29 +0200 Subject: [PATCH 2/2] index out of bounds fix --- HalgarisRPGLoot/Extensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HalgarisRPGLoot/Extensions.cs b/HalgarisRPGLoot/Extensions.cs index cbb9a98..1866312 100644 --- a/HalgarisRPGLoot/Extensions.cs +++ b/HalgarisRPGLoot/Extensions.cs @@ -13,7 +13,7 @@ public static class Extensions public static T RandomItem(this T[] itms) { - return itms[Random.Next(0, itms.Length)]; + return itms[Random.Next(0, (itms.Length-1 <= 0 )? 1 : itms.Length-1)]; } public static IEnumerable Repeatedly(Func f)