From f0c6bda9dcc3acb85aa19b0aaeb070a1609f52bd Mon Sep 17 00:00:00 2001 From: Chomp Date: Sun, 9 Jan 2022 20:35:43 +0000 Subject: [PATCH] use "is null" instead of "==" --- GenerateQuestFile/Program.cs | 78 ++++++++----------- .../Helpers/ItemTemplateHelper.cs | 2 +- .../Helpers/LiveQuestHelper.cs | 2 +- QuestValidator.Common/Helpers/QuestHelper.cs | 10 +-- QuestValidator.Common/Helpers/TraderHelper.cs | 2 +- QuestValidator/Program.cs | 29 ++++--- 6 files changed, 52 insertions(+), 71 deletions(-) diff --git a/GenerateQuestFile/Program.cs b/GenerateQuestFile/Program.cs index bb0a711..622bca7 100644 --- a/GenerateQuestFile/Program.cs +++ b/GenerateQuestFile/Program.cs @@ -23,77 +23,61 @@ namespace GenerateQuestFile var inputPath = DiskHelpers.CreateWorkingFolders(); InputFileHelper.SetInputFiles(inputPath); - //read in quest files - var questData = QuestHelper.GetQuestData(); + // Read in quest files + var existingQuestData = QuestHelper.GetQuestData(); var liveQuestData = QuestHelper.GetLiveQuestData(); - //var oldQuestData = QuestHelper.GetQuestData("oldQuests"); - - // Find the quests that are missing from the live file - var missingQuests = new List(); - foreach (var quest in questData.Values) - { - var liveQuest = liveQuestData.data.Find(x => x._id == quest._id); - if (liveQuest == null) - { - missingQuests.Add(quest); - LoggingHelpers.LogError($"ERROR Quest {quest._id} {QuestHelper.GetQuestNameById(quest._id)} missing in live file. Will use fallback quests.json"); - } - else - { - LoggingHelpers.LogSuccess($"SUCCESS Quest {quest._id} {QuestHelper.GetQuestNameById(quest._id)} found in live file."); - } - } + // Find the quests that are missing from the live file from existing quest data + var missingQuests = GetMissingQuestsNotInLiveFile(existingQuestData, liveQuestData); + // Create a list of quests to output - // use all quests in live file + // Use all quests in live file // Use quests from quests.json to fill in missing quests var questsToOutputToFile = new Dictionary(); - //create live version of quests.json - foreach (var quest in liveQuestData.data) + + // Add live quests to collection to return later + foreach (var liveQuest in liveQuestData.data) { - var questName = QuestHelper.GetQuestNameById(quest._id); // special characters like ", brake the client when it parses it - var rgx = new Regex("[^a-zA-Z0-9 -]"); - quest.QuestName = rgx.Replace(questName, ""); - questsToOutputToFile.Add(quest._id, quest); + questsToOutputToFile.Add(liveQuest._id, liveQuest); } + + // Add missing quests from existing quest data to fill in blanks from live data foreach (var missingQuest in missingQuests) { - missingQuest.QuestName = QuestHelper.GetQuestNameById(missingQuest._id); + // Going from a pre-12.7.x version has problems, it doesnt have the new quest data format + CheckAndFixMissingProperties(missingQuest); + questsToOutputToFile.Add(missingQuest._id, missingQuest); } - + if (!questsToOutputToFile.ContainsKey("5e383a6386f77465910ce1f3")) // TextileP1Bear + { + // add textileP1Bear + } + + if (!questsToOutputToFile.ContainsKey("5e4d515e86f77438b2195244")) // TextileP2Bear + { + // add TextileP2Bear + } foreach (var quest in questsToOutputToFile) { - if (quest.Key == "597a160786f77477531d39d2") - { - - } + AddQuestName(quest); - var originalQuest = questData.FirstOrDefault(x => x.Key == quest.Key).Value; + var originalQuest = existingQuestData.FirstOrDefault(x => x.Key == quest.Key).Value; + + // quest has start conditions, check to ensure they're carried over if (originalQuest.conditions.AvailableForStart.Count > 0) { - // Iterate over quest requirements in existing qeust file - foreach (var questRequirementToAdd in originalQuest.conditions.AvailableForStart.ToList()) - { - //Exists already - if (quest.Value.conditions.AvailableForStart.Any(x => x._parent == questRequirementToAdd._parent - && x._props.target?.ToString() == questRequirementToAdd._props.target?.ToString())) - { - continue; - } - - quest.Value.conditions.AvailableForStart.Add(questRequirementToAdd); - } + AddMissingAvailableForStartConditions(originalQuest, quest); } } - // iterate over quest objects a final time and add hard coded quest requirements if they dont already exist + // Iterate over quest objects a final time and add hard coded quest requirements if they dont already exist foreach (var quest in questsToOutputToFile) { var questRequirements = QuestHelper.GetQuestDependancy(quest.Key); - if (questRequirements == null || questRequirements.Count == 0) + if (questRequirements is null || questRequirements.Count == 0) { continue; } diff --git a/QuestValidator.Common/Helpers/ItemTemplateHelper.cs b/QuestValidator.Common/Helpers/ItemTemplateHelper.cs index 904aeea..02502b6 100644 --- a/QuestValidator.Common/Helpers/ItemTemplateHelper.cs +++ b/QuestValidator.Common/Helpers/ItemTemplateHelper.cs @@ -15,7 +15,7 @@ namespace QuestValidator.Common { get { - if (_itemCache == null) + if (_itemCache is null) { var itemsFilePath = $"{Directory.GetCurrentDirectory()}\\Assets\\items.json"; if (!File.Exists(itemsFilePath)) diff --git a/QuestValidator.Common/Helpers/LiveQuestHelper.cs b/QuestValidator.Common/Helpers/LiveQuestHelper.cs index a1399c0..e01a55b 100644 --- a/QuestValidator.Common/Helpers/LiveQuestHelper.cs +++ b/QuestValidator.Common/Helpers/LiveQuestHelper.cs @@ -15,7 +15,7 @@ namespace QuestValidator.Common { get { - if (_itemCache == null) + if (_itemCache is null) { var itemsFilePath = $"{Directory.GetCurrentDirectory()}\\Assets\\items.json"; if (!File.Exists(itemsFilePath)) diff --git a/QuestValidator.Common/Helpers/QuestHelper.cs b/QuestValidator.Common/Helpers/QuestHelper.cs index dc96a44..acef58f 100644 --- a/QuestValidator.Common/Helpers/QuestHelper.cs +++ b/QuestValidator.Common/Helpers/QuestHelper.cs @@ -18,10 +18,10 @@ namespace AssortGenerator.Common.Helpers public static Dictionary GetQuestData(string filename = "quests") { - if (_questData == null) + if (_questData is null) { var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains(filename)); - if (questFilePath == null) + if (questFilePath is null) { return null; } @@ -35,10 +35,10 @@ namespace AssortGenerator.Common.Helpers public static QuestRoot GetLiveQuestData(string filename = "resp.client.quest.list") { - if (_liveQuestData == null) + if (_liveQuestData is null) { var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains(filename)); - if (questFilePath == null) + if (questFilePath is null) { return null; } @@ -57,7 +57,7 @@ namespace AssortGenerator.Common.Helpers public static List GetAssortUnlocks() { - if (_assortUnlocks == null) + if (_assortUnlocks is null) { _assortUnlocks = new List(); foreach (var quest in GetQuestData()) diff --git a/QuestValidator.Common/Helpers/TraderHelper.cs b/QuestValidator.Common/Helpers/TraderHelper.cs index c40ecc1..4ef34f6 100644 --- a/QuestValidator.Common/Helpers/TraderHelper.cs +++ b/QuestValidator.Common/Helpers/TraderHelper.cs @@ -9,7 +9,7 @@ namespace AssortGenerator.Common.Helpers public static Dictionary GetTraders() { - if (_traders == null) + if (_traders is null) { _traders = new Dictionary { diff --git a/QuestValidator/Program.cs b/QuestValidator/Program.cs index f0f92a0..954ef1c 100644 --- a/QuestValidator/Program.cs +++ b/QuestValidator/Program.cs @@ -20,7 +20,7 @@ namespace QuestValidator var questData = QuestHelper.GetQuestData(); var liveQuestData = QuestHelper.GetLiveQuestData(); - if (questData == null || liveQuestData == null) + if (questData is null || liveQuestData is null) { LoggingHelpers.LogError("Unable to read quest data. Are you sure the both quest files are in 'QuestValidator//bin//Debug//netcoreapp3.1//input'"); return; @@ -86,7 +86,7 @@ namespace QuestValidator { var liveQuest = liveQuestData.data.FirstOrDefault(x=>x._id == quest._id); - if (liveQuest == null) + if (liveQuest is null) { missingQuests.Add(quest); LoggingHelpers.LogError($"ERROR Quest {quest._id} {QuestHelper.GetQuestNameById(quest._id)} missing in live"); @@ -162,9 +162,6 @@ namespace QuestValidator // Check Fail reward count matches CheckValuesMatch(quest.rewards.Fail.Count, relatedLiveQuest.rewards.Fail.Count, "fail item count mismatch"); - // Check min level matches - CheckValuesMatch(quest.min_level, relatedLiveQuest.min_level, "min level value mismatch"); - // Check location matches CheckValuesMatch(quest.location, relatedLiveQuest.location, "location value mismatch"); @@ -184,7 +181,7 @@ namespace QuestValidator // Get live reward item by index and type var relatedLiveRewardItem = GetLiveRewardItem(questSuccessRewardItem, liveQuestSuccessRewardItems); - if (relatedLiveRewardItem == null) + if (relatedLiveRewardItem is null) { LogUnableToFindSuccessItemInLiveData(questSuccessRewardItem, relatedLiveRewardItem); continue; @@ -258,13 +255,13 @@ namespace QuestValidator relatedLiveRewardItem = possibleLiveRewardItems.FirstOrDefault(x=>x.index == questSuccessRewardItem.index); // nothing found by index, try by - if (relatedLiveRewardItem == null) + if (relatedLiveRewardItem is null) { relatedLiveRewardItem = possibleLiveRewardItems.FirstOrDefault(x => x.traderId == questSuccessRewardItem.traderId); } } - if (relatedLiveRewardItem == null) + if (relatedLiveRewardItem is null) { relatedLiveRewardItem = liveQuestSuccessRewardItems.Find(x => x.traderId == questSuccessRewardItem.traderId && x.index == questSuccessRewardItem.index @@ -294,11 +291,11 @@ namespace QuestValidator { // find live item by slotid var liveCounterpart = relatedLiveRewardItem.items.Where(x => x.slotId == subItem.slotId); - if (liveCounterpart == null || liveCounterpart.Count() == 0) + if (liveCounterpart is null || liveCounterpart.Count() == 0) { // Look for live item by template id liveCounterpart = relatedLiveRewardItem.items.Where(x => x._tpl == subItem._tpl); - if (liveCounterpart == null || liveCounterpart.Count() == 0) + if (liveCounterpart is null || liveCounterpart.Count() == 0) { LoggingHelpers.LogWarning($"a live counterpart for the subItem {subItem.slotId} could not be found by slotid or tpId, skipping subItem check"); continue; @@ -317,7 +314,7 @@ namespace QuestValidator private static void LogUnableToFindSuccessItemInLiveData(RewardStatus questSuccessRewardItem, RewardStatus relatedLiveRewardItem) { - if (relatedLiveRewardItem == null) + if (relatedLiveRewardItem is 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})"); @@ -350,7 +347,7 @@ namespace QuestValidator var liveRewardItemByIndex = LiveItemRewards.FirstOrDefault(x => x.index == questSuccessRewardItem.index); // no item found by index, find by template id - if (liveRewardItemByIndex == null) + if (liveRewardItemByIndex is null) { foreach (var liveItem in LiveItemRewards .SelectMany(liveItem => liveItem.items @@ -379,11 +376,11 @@ namespace QuestValidator var errorMessage = string.Empty; // Get live reward item by index and type var relatedLiveRewardItem = liveQuestStartedRewardItems.Find(x => x.index == questStartedRewardItem.index && x.type == "Item"); - if (relatedLiveRewardItem == null) + if (relatedLiveRewardItem is null) { // Get live reward item by templateId and type as we cant find it by index relatedLiveRewardItem = liveQuestStartedRewardItems.Find(x => x.items != null && x.items[0]?._tpl == questStartedRewardItem.items[0]?._tpl && x.type == "Item"); - if (relatedLiveRewardItem == null) + if (relatedLiveRewardItem is null) { LoggingHelpers.LogError($"ERROR unable to find started reward item in live quest data by index: ({questStartedRewardItem.index}) OR template id: {questStartedRewardItem.items[0]._tpl}"); LoggingHelpers.LogError($"ERROR Skipping quest started item: {questStartedRewardItem.id}"); @@ -414,7 +411,7 @@ namespace QuestValidator { // Get live reward item by id var relatedLiveRewardItem = liveQuestStartedRewardItems.FirstOrDefault(x => x.id == questStartedRewardItem.id && x.type == "AssortmentUnlock"); - if (relatedLiveRewardItem == null) + if (relatedLiveRewardItem is null) { // Cant find live reward item by id, get my template id inside items[0] relatedLiveRewardItem = liveQuestStartedRewardItems.Find(x => x.traderId == questStartedRewardItem.traderId @@ -472,7 +469,7 @@ namespace QuestValidator private static bool ItemExists(object itemToCheck, string message, int index = -1) { - if (itemToCheck == null) + if (itemToCheck is null) { if (index == -1) {