use "is null" instead of "=="

This commit is contained in:
Chomp 2022-01-09 20:35:43 +00:00
parent dd458f80ab
commit f0c6bda9dc
6 changed files with 52 additions and 71 deletions

View File

@ -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<Quest>();
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<string, Quest>();
//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 = existingQuestData.FirstOrDefault(x => x.Key == quest.Key).Value;
var originalQuest = questData.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;
}

View File

@ -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))

View File

@ -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))

View File

@ -18,10 +18,10 @@ namespace AssortGenerator.Common.Helpers
public static Dictionary<string, QuestValidator.Models.Quest> 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<AssortUnlocks> GetAssortUnlocks()
{
if (_assortUnlocks == null)
if (_assortUnlocks is null)
{
_assortUnlocks = new List<AssortUnlocks>();
foreach (var quest in GetQuestData())

View File

@ -9,7 +9,7 @@ namespace AssortGenerator.Common.Helpers
public static Dictionary<Trader, string> GetTraders()
{
if (_traders == null)
if (_traders is null)
{
_traders = new Dictionary<Trader, string>
{

View File

@ -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)
{