Update questassort code to include assort unlocks by starting a quest

This commit is contained in:
Chomp 2023-01-28 13:42:56 +00:00
parent 34fe602c9c
commit 89f1b6e998
2 changed files with 76 additions and 63 deletions

View File

@ -63,7 +63,7 @@ namespace AssortGenerator.Common.Helpers
QuestRewardId = reward.id, QuestRewardId = reward.id,
TraderId = reward.traderId, TraderId = reward.traderId,
TraderType = TraderHelper.GetTraderTypeById(reward.traderId), TraderType = TraderHelper.GetTraderTypeById(reward.traderId),
Criteria = "Success" Criteria = "Started"
} }
); );
} }

View File

@ -26,7 +26,7 @@ namespace AssortGenerator
{ {
// Get relevant trader dump // Get relevant trader dump
var assortDumpPath = traderAssortFilePaths.Find(x => x.Contains($"getTraderAssort.{trader.Value}")); var assortDumpPath = traderAssortFilePaths.Find(x => x.Contains($"getTraderAssort.{trader.Value}"));
if (assortDumpPath == null) if (assortDumpPath == null)
{ {
assortDumpPath = traderAssortFilePaths.Find(x => x.Contains($"{trader.Value}") && x.Contains("getTraderAssort")); assortDumpPath = traderAssortFilePaths.Find(x => x.Contains($"{trader.Value}") && x.Contains("getTraderAssort"));
} }
@ -207,99 +207,112 @@ namespace AssortGenerator
// Find assort unlocks // Find assort unlocks
List<AssortUnlocks> assortUnlocks = QuestHelper.GetAssortUnlocks(); List<AssortUnlocks> assortUnlocks = QuestHelper.GetAssortUnlocks();
var assortItemsThatMatchBlackList = new List<string>(); // store items already matched here var 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)) foreach (var assortUnlock in assortUnlocks.Where(x => x.TraderType == trader))
{ {
if (assortUnlock.AssortUnlockId == "5ac653ed86f77405d4729344") if (assortUnlock.ItemUnlockedTemplateId == "62a0a043cf4a99369e2624a5")
{ {
var x = 2; var x = 2;
} }
// Get unlock items name // Get unlock items name
var assortItemName = ItemTemplateHelper.Items var assortItemName = ItemTemplateHelper.Items
.FirstOrDefault(x=> x.Key == assortUnlock.ItemUnlockedTemplateId).Value._name; .FirstOrDefault(x => x.Key == assortUnlock.ItemUnlockedTemplateId).Value._name;
// TODO: handle started // TODO: handle started
// TODO: handle fail // TODO: handle fail
// Handle quest success for now // Handle quest success for now
if (assortUnlock.Criteria.ToLower() == "success") //if (assortUnlock.Criteria.ToLower() == "success")
//{
//Find assorts that match the quest unlocks item template
List<Item> assortItemsThatMatch = assortRoot.items
.Where(x => x._tpl == assortUnlock.ItemUnlockedTemplateId && x.slotId == "hideout")
.ToList();
// No assort found for this unlock, log and skip it
if (assortItemsThatMatch == null || assortItemsThatMatch.Count == 0)
{ {
//Find assorts that match the quest unlocks item template LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no assort item found. ({assortItemName})");
List<Item> assortItemsThatMatch = assortRoot.items continue;
.Where(x => x._tpl == assortUnlock.ItemUnlockedTemplateId && x.slotId == "hideout") }
.ToList();
// No assort found for this unlock, log and skip it // Iterate over assorts that match. goal is to find assort that fits the best
if (assortItemsThatMatch == null || assortItemsThatMatch.Count == 0) // (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)
{ {
LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no assort item found. ({assortItemName})"); // 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. ");
continue; continue;
} }
// Iterate over assorts that match. goal is to find assort that fits the best if (associatedLoyaltyLevelItem.Value != assortUnlock.LoyaltyLevel)
// (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 // Loyalty level is different to what was expected, skip and try next
var associatedLoyaltyLevelItem = assortRoot.loyal_level_items 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}");
.FirstOrDefault(x => x.Key == match._id);
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. ");
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}");
continue;
}
// 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(assortIdUnlockedByQuest))
{
LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. ALREADY EXISTS. SKIPPING");
continue; continue;
} }
if (assortIdUnlockedByQuest.Length == 0) // LoggingHelpers.LogInfo($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} {assortItemName}. MATCH FOUND. LL{assortUnlock.LoyaltyLevel}");
if (assortItemsThatMatchBlackList.Contains(associatedLoyaltyLevelItem.Key))
{ {
LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. no assortId found"); // Not the item we want, its already been matched
continue; continue;
} }
LoggingHelpers.LogSuccess($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. ADDING TO QUEST-ASSORT"); // 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(assortIdUnlockedByQuest))
{
LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). 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");
continue;
}
LoggingHelpers.LogSuccess($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. ADDING TO QUEST-ASSORT");
if (assortUnlock.Criteria == "Success")
{
result.success.Add(assortIdUnlockedByQuest, assortUnlock.QuestId); result.success.Add(assortIdUnlockedByQuest, assortUnlock.QuestId);
} }
else if (assortUnlock.Criteria == "Started")
if (assortUnlock.Criteria.ToLower() == "fail")
{ {
LoggingHelpers.LogError("Fail quest criteria not handled"); result.started.Add(assortIdUnlockedByQuest, assortUnlock.QuestId);
}
else
{
LoggingHelpers.LogError($"{assortUnlock.Criteria} quest criteria not handled");
} }
if (assortUnlock.Criteria.ToLower() == "started")
{ //}
LoggingHelpers.LogError("started quest criteria not handled");
} //if (assortUnlock.Criteria.ToLower() == "fail")
//{
// LoggingHelpers.LogError("Fail quest criteria not handled");
//}
//if (assortUnlock.Criteria.ToLower() == "started")
//{
// LoggingHelpers.LogError("started quest criteria not handled");
//}
} }
return result; return result;