From 3255f7df9343a3dbd19e8c3026756bbca8f3bd11 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sun, 12 Sep 2021 15:41:15 +0100 Subject: [PATCH] Improve handling of finding assort unlock reward items --- QuestValidator/Program.cs | 55 +++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/QuestValidator/Program.cs b/QuestValidator/Program.cs index ee5ae04..0a377df 100644 --- a/QuestValidator/Program.cs +++ b/QuestValidator/Program.cs @@ -68,6 +68,12 @@ namespace QuestValidator // Check image id matches CheckValuesMatch(quest.image.Substring(0, quest.image.Length - 4), relatedLiveQuest?.image.Substring(0, relatedLiveQuest.image.Length - 4), "item path mismatch"); + //Check image id contains quest id + if (!quest.image.Contains(quest._id)) + { + LoggingHelpers.LogWarning($"WARNING Quest image path does not contain quest id"); + } + // Check started reward count matches CheckValuesMatch(quest.rewards.Started.Count, relatedLiveQuest.rewards.Started.Count, "Started item count mismatch"); @@ -99,9 +105,9 @@ namespace QuestValidator // Get live reward item by index and type var relatedLiveRewardItem = GetLiveRewardItem(questSuccessRewardItem, liveQuestSuccessRewardItems); - LogUnableToFindSuccessItemInLiveData(questSuccessRewardItem, relatedLiveRewardItem); if (relatedLiveRewardItem == null) { + LogUnableToFindSuccessItemInLiveData(questSuccessRewardItem, relatedLiveRewardItem); continue; } @@ -156,7 +162,29 @@ namespace QuestValidator foreach (var questSuccessRewardItem in quest.rewards.Success.Where(x => x.type == "AssortmentUnlock")) { - var relatedLiveRewardItem = liveQuestSuccessRewardItems.Find(x => x.id == questSuccessRewardItem.id && x.type == "AssortmentUnlock"); + // Find the assort unlock item in the list of success rewards + var possibleLiveRewardItems = liveQuestSuccessRewardItems.Where(x => x.id == questSuccessRewardItem.id && x.type == "AssortmentUnlock"); + RewardStatus relatedLiveRewardItem = null; + + // we found the one we want + if (possibleLiveRewardItems?.Count() == 1) + { + relatedLiveRewardItem = possibleLiveRewardItems.First(); + } + + // multiple found + if (possibleLiveRewardItems?.Count() > 1) + { + // be more specific, get my index + relatedLiveRewardItem = possibleLiveRewardItems.FirstOrDefault(x=>x.index == questSuccessRewardItem.index); + + // nothing found by index, try by + if (relatedLiveRewardItem == null) + { + relatedLiveRewardItem = possibleLiveRewardItems.FirstOrDefault(x => x.traderId == questSuccessRewardItem.traderId); + } + } + if (relatedLiveRewardItem == null) { relatedLiveRewardItem = liveQuestSuccessRewardItems.Find(x => x.traderId == questSuccessRewardItem.traderId @@ -185,12 +213,17 @@ namespace QuestValidator { foreach (var subItem in questSuccessRewardItem.items.Where(x => !string.IsNullOrEmpty(x.slotId))) { - // find matching live counterpart by slotid + // find live item by slotid var liveCounterpart = relatedLiveRewardItem.items.Where(x => x.slotId == subItem.slotId); if (liveCounterpart == null || liveCounterpart.Count() == 0) { - LoggingHelpers.LogWarning($"a live counterpart for the subItem {subItem.slotId} could not be found, skipping subItem check"); - continue; + // Look for live item by template id + liveCounterpart = relatedLiveRewardItem.items.Where(x => x._tpl == subItem._tpl); + if (liveCounterpart == null || liveCounterpart.Count() == 0) + { + LoggingHelpers.LogWarning($"a live counterpart for the subItem {subItem.slotId} could not be found by slotid or tpId, skipping subItem check"); + continue; + } } if (liveCounterpart.Count() > 1) { @@ -237,6 +270,18 @@ namespace QuestValidator var LiveItemRewards = liveQuestSuccessRewardItems.Where(x => x.type == "Item"); var liveRewardItemByIndex = LiveItemRewards.FirstOrDefault(x => x.index == questSuccessRewardItem.index); + // no item found by index, find by template id + if (liveRewardItemByIndex == null) + { + foreach (var liveItem in LiveItemRewards + .SelectMany(liveItem => liveItem.items + .Where(subItem => subItem._tpl == questSuccessRewardItem.items[0]._tpl) + .Select(subItem => liveItem))) + { + return liveItem; + } + } + // item found by index but template id didnt match if (liveRewardItemByIndex != null && liveRewardItemByIndex.items[0]._tpl != questSuccessRewardItem.items[0]._tpl) {