Code cleanup
This commit is contained in:
parent
fc92c73791
commit
d0579b645a
@ -2,6 +2,7 @@
|
||||
using QuestValidator.Common;
|
||||
using QuestValidator.Common.Helpers;
|
||||
using QuestValidator.Helpers;
|
||||
using QuestValidator.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@ -55,17 +56,17 @@ namespace QuestValidator
|
||||
}
|
||||
}
|
||||
|
||||
private static void LogQuestDetails(Models.Quest quest)
|
||||
private static void LogQuestDetails(Quest quest)
|
||||
{
|
||||
var questName = QuestHelper.GetQuestNameById(quest._id);
|
||||
LoggingHelpers.LogInfo($"### Quest name: {questName} ({quest._id})");
|
||||
LoggingHelpers.LogInfo($"Wiki: https://escapefromtarkov.fandom.com/wiki/{questName.Replace(' ', '_')}");
|
||||
}
|
||||
|
||||
private static void CheckRootItemValues(Models.Quest quest, Models.Quest relatedLiveQuest)
|
||||
private static void CheckRootItemValues(Quest quest, Quest relatedLiveQuest)
|
||||
{
|
||||
// Check image id matches
|
||||
CheckValuesMatch(quest.image.Substring(0, quest.image.Length - 3), relatedLiveQuest?.image.Substring(0, relatedLiveQuest.image.Length - 3), "item path mismatch");
|
||||
CheckValuesMatch(quest.image.Substring(0, quest.image.Length - 4), relatedLiveQuest?.image.Substring(0, relatedLiveQuest.image.Length - 4), "item path mismatch");
|
||||
|
||||
// Check started reward count matches
|
||||
CheckValuesMatch(quest.rewards.Started.Count, relatedLiveQuest.rewards.Started.Count, "Started item count mismatch");
|
||||
@ -89,27 +90,20 @@ namespace QuestValidator
|
||||
CheckValuesMatch(quest.type, relatedLiveQuest.type, "quest type value mismatch");
|
||||
}
|
||||
|
||||
private static void CheckSuccessRewardItems(Models.Quest quest, Models.Quest relatedLiveQuest)
|
||||
private static void CheckSuccessRewardItems(Quest quest, Quest relatedLiveQuest)
|
||||
{
|
||||
var liveQuestSuccessRewardItems = relatedLiveQuest.rewards.Success;
|
||||
|
||||
foreach (var questSuccessRewardItem in quest.rewards.Success.Where(x => x.type == "Item"))
|
||||
foreach (RewardStatus questSuccessRewardItem in quest.rewards.Success.Where(x => x.type == "Item"))
|
||||
{
|
||||
var errorMessage = string.Empty;
|
||||
// Get live reward item by index and type
|
||||
var relatedLiveRewardItem = liveQuestSuccessRewardItems.Find(x => x.index == questSuccessRewardItem.index && x.type == "Item");
|
||||
var relatedLiveRewardItem = GetLiveRewardItem(questSuccessRewardItem, liveQuestSuccessRewardItems);
|
||||
|
||||
LogUnableToFindSuccessItemInLiveData(questSuccessRewardItem, relatedLiveRewardItem);
|
||||
if (relatedLiveRewardItem == null)
|
||||
{
|
||||
// Get live reward item by templateId and type as we cant find it by index
|
||||
relatedLiveRewardItem = liveQuestSuccessRewardItems.Find(x => x.items != null && x.items[0]?._tpl == questSuccessRewardItem.items[0]?._tpl && x.type == "Item");
|
||||
if (relatedLiveRewardItem == null)
|
||||
{
|
||||
LoggingHelpers.LogError($"ERROR unable to find success reward item in live quest data by index: ({questSuccessRewardItem.index}) OR template id: {questSuccessRewardItem.items[0]._tpl}");
|
||||
LoggingHelpers.LogError($"ERROR Skipping quest success item: {questSuccessRewardItem.id}");
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
//LoggingHelpers.LogInfo($"INFO Found live success reward item: {relatedLiveRewardItem.id}");
|
||||
|
||||
// Ensure target matches the objects items[0].id value
|
||||
if (questSuccessRewardItem.items[0]?._id != questSuccessRewardItem.target)
|
||||
@ -130,20 +124,7 @@ namespace QuestValidator
|
||||
}
|
||||
|
||||
// check sub items match
|
||||
foreach (var subItem in questSuccessRewardItem.items.Where(x=> !string.IsNullOrEmpty(x.slotId)))
|
||||
{
|
||||
// find matching live counterpart
|
||||
var liveCounterpart = relatedLiveRewardItem.items.FirstOrDefault(x=> x.slotId == subItem.slotId);
|
||||
|
||||
if (liveCounterpart == null)
|
||||
{
|
||||
LoggingHelpers.LogWarning($"a live counterpart for the subItem {subItem.slotId} could not be found, skipping subItem check");
|
||||
continue;
|
||||
}
|
||||
|
||||
CheckValuesMatch(subItem._tpl, liveCounterpart._tpl, $"mismatch for success subItem({subItem.slotId}) reward templateId", subItem._id);
|
||||
|
||||
}
|
||||
CheckSubItemsMatch(questSuccessRewardItem, relatedLiveRewardItem);
|
||||
}
|
||||
|
||||
foreach (var questSuccessRewardItem in quest.rewards.Success.Where(x => x.type == "Experience"))
|
||||
@ -200,7 +181,66 @@ namespace QuestValidator
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckStartedRewardItems(Models.Quest quest, Models.Quest relatedLiveQuest)
|
||||
private static void CheckSubItemsMatch(RewardStatus questSuccessRewardItem, RewardStatus relatedLiveRewardItem)
|
||||
{
|
||||
foreach (var subItem in questSuccessRewardItem.items.Where(x => !string.IsNullOrEmpty(x.slotId)))
|
||||
{
|
||||
// find matching live counterpart by slotid
|
||||
var liveCounterpart = relatedLiveRewardItem.items.FirstOrDefault(x => x.slotId == subItem.slotId);
|
||||
if (liveCounterpart == null)
|
||||
{
|
||||
LoggingHelpers.LogWarning($"a live counterpart for the subItem {subItem.slotId} could not be found, skipping subItem check");
|
||||
continue;
|
||||
}
|
||||
|
||||
CheckValuesMatch(subItem._tpl, liveCounterpart._tpl, $"mismatch for success subItem({subItem.slotId}) reward templateId", subItem._id);
|
||||
}
|
||||
}
|
||||
|
||||
private static void LogUnableToFindSuccessItemInLiveData(RewardStatus questSuccessRewardItem, RewardStatus relatedLiveRewardItem)
|
||||
{
|
||||
if (relatedLiveRewardItem == null)
|
||||
{
|
||||
LoggingHelpers.LogError($"ERROR unable to find success reward item in live quest data by index: ({questSuccessRewardItem.index}) OR template id: {questSuccessRewardItem.items[0]._tpl} ({ItemTemplateHelper.GetTemplateById(questSuccessRewardItem.items[0]._tpl)._name})");
|
||||
|
||||
LoggingHelpers.LogError("Existing items:");
|
||||
LogSuccessItems(questSuccessRewardItem);
|
||||
|
||||
LoggingHelpers.LogError($"ERROR Skipping quest success item. id: {questSuccessRewardItem.id}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void LogSuccessItems(RewardStatus rewardItem)
|
||||
{
|
||||
foreach (var item in rewardItem.items)
|
||||
{
|
||||
LoggingHelpers.LogInfo($"{item._tpl} ({ItemTemplateHelper.GetTemplateById(item._tpl)._name})");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find live success item reward by index
|
||||
/// If item at index does not match templateId to desired item
|
||||
/// get live success item reward by template id
|
||||
/// </summary>
|
||||
/// <param name="questSuccessRewardItem"></param>
|
||||
/// <param name="liveQuestSuccessRewardItems"></param>
|
||||
/// <returns></returns>
|
||||
private static RewardStatus GetLiveRewardItem(RewardStatus questSuccessRewardItem, List<RewardStatus> liveQuestSuccessRewardItems)
|
||||
{
|
||||
var LiveItemRewards = liveQuestSuccessRewardItems.Where(x => x.type == "Item");
|
||||
var liveRewardItemByIndex = LiveItemRewards.FirstOrDefault(x => x.index == questSuccessRewardItem.index);
|
||||
|
||||
// item found by index but template id didnt match
|
||||
if (liveRewardItemByIndex != null && liveRewardItemByIndex.items[0]._tpl != questSuccessRewardItem.items[0]._tpl)
|
||||
{
|
||||
return LiveItemRewards.FirstOrDefault(x => x.items[0]._tpl == questSuccessRewardItem.items[0]._tpl);
|
||||
}
|
||||
|
||||
return liveRewardItemByIndex;
|
||||
}
|
||||
|
||||
private static void CheckStartedRewardItems(Quest quest, Quest relatedLiveQuest)
|
||||
{
|
||||
var liveQuestStartedRewardItems = relatedLiveQuest.rewards.Started;
|
||||
|
||||
@ -269,11 +309,11 @@ namespace QuestValidator
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckAvailableForFinishConditionItems(Models.Quest quest, Models.Quest relatedLiveQuest)
|
||||
private static void CheckAvailableForFinishConditionItems(Quest quest, Quest relatedLiveQuest)
|
||||
{
|
||||
foreach (var availableForFinishItem in quest.conditions.AvailableForFinish)
|
||||
{
|
||||
Models.AvailableFor liveFinishItem = relatedLiveQuest.conditions.AvailableForFinish.Find(x => x._props.id == availableForFinishItem._props.id);
|
||||
AvailableFor liveFinishItem = relatedLiveQuest.conditions.AvailableForFinish.Find(x => x._props.id == availableForFinishItem._props.id);
|
||||
if (!ItemExists(liveFinishItem, "AvailableForFinish item", availableForFinishItem._props.index.Value))
|
||||
{
|
||||
continue;
|
||||
@ -328,7 +368,22 @@ namespace QuestValidator
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckValuesMatch(string firstValue, string secondValue, string message, string associatedId = "", bool performTemplateIdLookup = false)
|
||||
private static void CheckValuesMatch<T>(T firstValue, T secondValue, string message, string associatedId = "") where T : struct
|
||||
{
|
||||
if (firstValue.Equals(secondValue))
|
||||
{
|
||||
if (associatedId == string.Empty)
|
||||
{
|
||||
LoggingHelpers.LogWarning($"WARNING {message}: '{firstValue}', expected '{secondValue}'");
|
||||
}
|
||||
else
|
||||
{
|
||||
LoggingHelpers.LogWarning($"WARNING {associatedId} {message}: '{firstValue}', expected '{secondValue}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckValuesMatch(string firstValue, string secondValue, string message, string associatedId = "", bool performTemplateIdLookup = false)
|
||||
{
|
||||
if (firstValue != secondValue)
|
||||
{
|
||||
@ -363,8 +418,9 @@ namespace QuestValidator
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckForMissingQuestsInAkiFile(Models.QuestRoot liveQuestData, Dictionary<string, Models.Quest> akiQuestData)
|
||||
private static void CheckForMissingQuestsInAkiFile(QuestRoot liveQuestData, Dictionary<string, Quest> akiQuestData)
|
||||
{
|
||||
// iterate over live quests and look for quests that exist in live but not in aki
|
||||
var missingQuests = new List<string>();
|
||||
foreach (var liveQuest in liveQuestData.data)
|
||||
{
|
||||
@ -373,6 +429,7 @@ namespace QuestValidator
|
||||
missingQuests.Add($"{liveQuest._id} {QuestHelper.GetQuestNameById(liveQuest._id)}");
|
||||
}
|
||||
}
|
||||
// Quests in live but not in aki were found, log it
|
||||
if (missingQuests.Count > 0)
|
||||
{
|
||||
LoggingHelpers.LogWarning($"WARNING aki quest list is missing quests:");
|
||||
|
Loading…
x
Reference in New Issue
Block a user