From 6b86c6c29ab34dd42340277c9e97a6ee62df8b41 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sat, 15 Jan 2022 15:00:21 +0000 Subject: [PATCH] Check for single item with same itemId prior to inserting item from existing assort file into merged file --- AssortUpdater/AssortMerger.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/AssortUpdater/AssortMerger.cs b/AssortUpdater/AssortMerger.cs index ff1faef..1e5cfbb 100644 --- a/AssortUpdater/AssortMerger.cs +++ b/AssortUpdater/AssortMerger.cs @@ -9,7 +9,7 @@ namespace AssortUpdater { var completeAssorts = new List(); - // Add live assorts + // Add live assorts to merged list foreach (var liveAssort in flattenedLiveAssorts) { completeAssorts.Add(liveAssort); @@ -41,7 +41,14 @@ namespace AssortUpdater private static FlatAssort? GetMatchingAssortFromCompleteList(string traderName, FlatAssort assortToFind, List completeAssorts) { - IEnumerable? existingAssort = GetAssortByItemIdAndLevel(assortToFind, completeAssorts); + IEnumerable? existingAssort = GetAssortByItemId(assortToFind, completeAssorts); + if (existingAssort.Any() && existingAssort.Count() == 1) + { + // one match found by id, dont add + return existingAssort.First(); + } + + existingAssort = GetAssortByItemIdAndLevel(assortToFind, completeAssorts); if (SingleAssortFound(existingAssort)) { @@ -101,6 +108,11 @@ namespace AssortUpdater && x.BarterDetails[0].count == assortToFind.BarterDetails[0].count); } + private static IEnumerable GetAssortByItemId(FlatAssort assortToFind, List completeAssorts) + { + return completeAssorts.Where(x => x.ItemId == assortToFind.ItemId); + } + private static IEnumerable GetAssortByItemIdAndLevel(FlatAssort assortToFind, List completeAssorts) { return completeAssorts.Where(x => x.ItemId == assortToFind.ItemId