Add blacklist to fix bug with quests that unlock multiple items with the same template id (jaeger has quest that unlocks 4 remington 700 presets)

Fix bug; assort id is the key, not quest id
This commit is contained in:
Chomp 2021-09-05 21:35:28 +01:00
parent c5ad3efe42
commit 9931ff01ad

View File

@ -127,7 +127,7 @@ namespace AssortGenerator
// Find assortunlocks
List<AssortUnlocks> assortUnlocks = QuestHelper.GetAssortUnlocks();
List<string> assortItemsThatMatchBlackList = new List<string>(); // 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<Item> 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);
}
}