diff --git a/AssortGenerator.Common/Helpers/QuestHelper.cs b/AssortGenerator.Common/Helpers/QuestHelper.cs index 4bb0283..724a652 100644 --- a/AssortGenerator.Common/Helpers/QuestHelper.cs +++ b/AssortGenerator.Common/Helpers/QuestHelper.cs @@ -44,7 +44,8 @@ namespace AssortGenerator.Common.Helpers QuestRewardId = reward.id, TraderId = reward.traderId, TraderType = TraderHelper.GetTraderTypeById(reward.traderId), - Criteria = "Success" + Criteria = "Success", + Items = reward.items } ); } @@ -63,7 +64,8 @@ namespace AssortGenerator.Common.Helpers QuestRewardId = reward.id, TraderId = reward.traderId, TraderType = TraderHelper.GetTraderTypeById(reward.traderId), - Criteria = "Started" + Criteria = "Started", + Items = reward.items } ); } diff --git a/AssortGenerator.Models/Other/Assortunlocks.cs b/AssortGenerator.Models/Other/Assortunlocks.cs index 027688b..bbe0432 100644 --- a/AssortGenerator.Models/Other/Assortunlocks.cs +++ b/AssortGenerator.Models/Other/Assortunlocks.cs @@ -1,4 +1,7 @@ -namespace AssortGenerator.Models.Other +using AssortGenerator.Models.Input; +using System.Collections.Generic; + +namespace AssortGenerator.Models.Other { public class AssortUnlocks { @@ -11,5 +14,6 @@ public Trader TraderType { get; set; } public int LoyaltyLevel { get; set; } public string Criteria { get; set; } + public List Items { get; set; } } } diff --git a/AssortGenerator/Program.cs b/AssortGenerator/Program.cs index 5900698..77deb28 100644 --- a/AssortGenerator/Program.cs +++ b/AssortGenerator/Program.cs @@ -206,24 +206,21 @@ namespace AssortGenerator // Find assort unlocks List assortUnlocks = QuestHelper.GetAssortUnlocks(); - var assortItemsThatMatchBlackList = new List(); // store items already matched here + + // Store already matched items + var assortItemsThatMatchBlackList = new List(); foreach (var assortUnlock in assortUnlocks.Where(x => x.TraderType == trader)) { - if (assortUnlock.ItemUnlockedTemplateId == "62a0a043cf4a99369e2624a5") + if (assortUnlock.ItemUnlockedTemplateId == "58948c8e86f77409493f7266") { var x = 2; } - // Get unlock items name - var assortItemName = ItemTemplateHelper.Items - .FirstOrDefault(x => x.Key == assortUnlock.ItemUnlockedTemplateId).Value._name; + // Get unlock item details + var assortItemDetailsDB = ItemTemplateHelper.Items.FirstOrDefault(x => x.Key == assortUnlock.ItemUnlockedTemplateId); + var ItemName = assortItemDetailsDB.Value._name; + var assortItemMods = assortUnlock.Items.Where(x => x.parentId == assortUnlock.ItemUnlockedId); - // TODO: handle started - // TODO: handle fail - - // Handle quest success for now - //if (assortUnlock.Criteria.ToLower() == "success") - //{ //Find assorts that match the quest unlocks item template List assortItemsThatMatch = assortRoot.items .Where(x => x._tpl == assortUnlock.ItemUnlockedTemplateId && x.slotId == "hideout") @@ -232,7 +229,7 @@ namespace AssortGenerator // No assort found for this unlock, log and skip it if (assortItemsThatMatch == null || assortItemsThatMatch.Count == 0) { - LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no assort item found. ({assortItemName})"); + LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no assort item found. ({ItemName})"); continue; } @@ -248,14 +245,14 @@ namespace AssortGenerator if (associatedLoyaltyLevelItem.Key == null) { // Skip item if no record found in loyalty level array - LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. no loyalty record found. "); + LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({ItemName}). questId: {assortUnlock.QuestId}. no loyalty record found. "); continue; } if (associatedLoyaltyLevelItem.Value != assortUnlock.LoyaltyLevel) { // Loyalty level is different to what was expected, skip and try next - LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. no match found in LL array. expected LL{associatedLoyaltyLevelItem.Value}. found: LL{assortUnlock.LoyaltyLevel}"); + LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({ItemName}). questId: {assortUnlock.QuestId}. no match found in LL array. expected LL{associatedLoyaltyLevelItem.Value}. found: LL{assortUnlock.LoyaltyLevel}"); continue; } @@ -266,6 +263,33 @@ namespace AssortGenerator continue; } + // Try matching by mods on item if they exist + if (assortItemMods.Any()) + { + var matchedItemMods = assortRoot.items.Where(x => x.parentId == match._id).ToList(); + if (assortItemMods.Count() != matchedItemMods.Count) + { + LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({ItemName}). questId: {assortUnlock.QuestId}. mismatch of mod count, skipping"); + continue; + } + var badMatch = false; + foreach (var desiredMod in assortItemMods) + { + var matchingModInCurrentMatch = matchedItemMods.FirstOrDefault(x => x._tpl == desiredMod._tpl); + if (matchingModInCurrentMatch == null) + { + badMatch = true; + LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({ItemName}). questId: {assortUnlock.QuestId}. mismatch of mods, skipping"); + break; + } + } + + if (badMatch) + { + continue; + } + } + // Add assort item id to blacklist so it wont be matched again assortItemsThatMatchBlackList.Add(associatedLoyaltyLevelItem.Key); @@ -276,17 +300,17 @@ namespace AssortGenerator if (result.success.ContainsKey(assortIdUnlockedByQuest)) { - LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. ALREADY EXISTS. SKIPPING"); + LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({ItemName}). questId: {assortUnlock.QuestId}. ALREADY EXISTS. SKIPPING"); continue; } if (assortIdUnlockedByQuest.Length == 0) { - LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. no assortId found"); + LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({ItemName}). questId: {assortUnlock.QuestId}. no assortId found"); continue; } - LoggingHelpers.LogSuccess($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. ADDING TO QUEST-ASSORT"); + LoggingHelpers.LogSuccess($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({ItemName}). questId: {assortUnlock.QuestId}. ADDING TO QUEST-ASSORT"); if (assortUnlock.Criteria == "Success") {