diff --git a/AssortGenerator/Program.cs b/AssortGenerator/Program.cs index 948d362..859c43d 100644 --- a/AssortGenerator/Program.cs +++ b/AssortGenerator/Program.cs @@ -127,7 +127,7 @@ namespace AssortGenerator // Find assortunlocks List assortUnlocks = QuestHelper.GetAssortUnlocks(); - + List assortItemsThatMatchBlackList = new List(); // store items already matched here // TODO: find out how the fuck the assort unlock is associated to the quest foreach (var assortUnlock in assortUnlocks.Where(x => x.TraderType == trader)) { @@ -142,7 +142,7 @@ namespace AssortGenerator if (assortUnlock.Criteria == "Success") { //Find assorts that match the quest unlocks item template - var assortItemsThatMatch = assortRoot.items.Where(x => x._tpl == assortUnlock.ItemUnlockedTemplateId).ToList(); + List assortItemsThatMatch = assortRoot.items.Where(x => x._tpl == assortUnlock.ItemUnlockedTemplateId).ToList(); // no assort found for this unlock, log and skip it if (assortItemsThatMatch == null || assortItemsThatMatch.Count == 0) @@ -151,38 +151,54 @@ namespace AssortGenerator continue; } - // Iterate over assorts that match. goal is to find which assort fits the best (traders assort has same loyalty level unlock as quest expects) + // Iterate over assorts that match. goal is to find assort that fits the best (traders assort has same loyalty level unlock as quest expects) string assortIdUnlockedByQuest = string.Empty; foreach (var match in assortItemsThatMatch) { // Look up item in Loyalty Level array - var associatedLoyaltyLevelItem = assortRoot.loyal_level_items.FirstOrDefault(x => x.Key == match._id); if (associatedLoyaltyLevelItem.Key == null) { - // end loop if no record found + // end loop if no record found in loyalty level array LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no loyalty record found. ({assortItemName})"); break; } if (associatedLoyaltyLevelItem.Value != assortUnlock.LoyaltyLevel) { - // loyalty level is different to what was expected, skip - LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no match found in LL array. LL{associatedLoyaltyLevelItem.Value}. questListLevel: {assortUnlock.LoyaltyLevel}. ({assortItemName})"); + // loyalty level is different to what was expected, skip and try next + LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no match found in LL array. expected LL{associatedLoyaltyLevelItem.Value}. found: LL{assortUnlock.LoyaltyLevel}. ({assortItemName})"); continue; } - //LoggingHelpers.LogInfo($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} {assortItemName}. MATCH FOUND. LL{assortUnlock.LoyaltyLevel}"); + // LoggingHelpers.LogInfo($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} {assortItemName}. MATCH FOUND. LL{assortUnlock.LoyaltyLevel}"); + if (assortItemsThatMatchBlackList.Contains(associatedLoyaltyLevelItem.Key)) + { + // Not the item we want, its already been matched + continue; + } + + // Add assort item id to blacklist so it wont be matched again + assortItemsThatMatchBlackList.Add(associatedLoyaltyLevelItem.Key); + + // assign id and break out of loop, We found the one we want assortIdUnlockedByQuest = associatedLoyaltyLevelItem.Key; + break; } - if (result.success.ContainsKey(assortUnlock.QuestId)) + if (result.success.ContainsKey(assortIdUnlockedByQuest)) { LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. ALREADY EXISTS. SKIPPING. ({assortItemName})"); continue; } + if (assortIdUnlockedByQuest == string.Empty) + { + LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no assortId found. ({assortItemName})"); + continue; + } + LoggingHelpers.LogSuccess($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. ADDING TO QUEST-ASSORT. ({assortItemName})"); - result.success.Add(assortUnlock.QuestId, assortIdUnlockedByQuest); + result.success.Add(assortIdUnlockedByQuest, assortUnlock.QuestId); } }