using AssortGenerator.Common.Helpers;
using QuestValidator.Common;
using QuestValidator.Common.Helpers;
using QuestValidator.Common.Models;
using QuestValidator.Helpers;
using QuestValidator.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Quest = QuestValidator.Models.Quest;
namespace GenerateQuestFile
{
class Program
{
///
/// Generate a quests.json file in /output/
/// Uses every quest from the live quest dump file
/// If any quests are missing, it will use the quests.json file to fill in the blanks
///
///
static void Main(string[] args)
{
var inputPath = DiskHelpers.CreateWorkingFolders();
InputFileHelper.SetInputFiles(inputPath);
// Read in quest files
var questBlacklist = QuestHelper.GetQuestBlacklist();
var existingQuestData = QuestHelper.GetQuestData();
var liveQuestData = QuestHelper.GetLiveQuestData();
var mergedLiveData = QuestHelper.MergeLiveQuestFiles(liveQuestData, questBlacklist);
OutputQuestRequirementsToConsole(mergedLiveData.data);
JsonWriter.WriteJson(mergedLiveData, "output", Directory.GetCurrentDirectory(), "mergedlivejson");
// Find the quests that are missing from the live file from existing quests.json
var missingQuests = GetMissingQuestsNotInLiveFile(existingQuestData, mergedLiveData, questBlacklist);
// Create a list of quests to output
// Use all quests in live file
// Use quests from quests.json to fill in missing quests
// Add live quests to collection to return later
var questsToOutputToFile = new Dictionary();
foreach (var liveQuest in mergedLiveData.data)
{
questsToOutputToFile.Add(liveQuest._id, liveQuest);
}
// Add missing quests from existing quest data to fill in blanks from live data
foreach (var missingQuest in missingQuests)
{
// 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);
}
// Now old + new quests have been merged, check quest list to see if any quests are missing
foreach (var missingQuest in QuestNames.GetQuests())
{
if (!questsToOutputToFile.Any(x => x.Key == missingQuest.Value))
{
LoggingHelpers.LogWarning($" quest not found in new or old data: {missingQuest.Key}");
}
}
if (!questsToOutputToFile.ContainsKey("5e383a6386f77465910ce1f3")) // TextileP1Bear
{
// add textileP1Bear
}
if (!questsToOutputToFile.ContainsKey("5e4d515e86f77438b2195244")) // TextileP2Bear
{
// add TextileP2Bear
}
foreach (var quest in questsToOutputToFile)
{
AddQuestName(quest);
var originalQuest = existingQuestData.FirstOrDefault(x => x.Key == quest.Key).Value;
if (originalQuest is null)
{
LoggingHelpers.LogWarning($"Cant check for original start conditions. Unable to find original quest {quest.Key} {QuestHelper.GetQuestNameById(quest.Key)}, skipping.");
continue;
}
AddMissingFields(quest);
// Quest has start conditions, check to ensure they're carried over
if (originalQuest.conditions.AvailableForStart.Count > 0)
{
AddMissingAvailableForStartConditions(originalQuest, quest);
}
if (originalQuest.rewards.Fail.Count > 0)
{
AddMissingFailRewards(originalQuest, quest);
}
// To make diffs more sane, copy the random IDs from the existing quests.json if possible
CopyExistingRandomIds(originalQuest, quest.Value);
}
// 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 = QuestRequirements.GetQuestRequirements(quest.Key);
if (questRequirements is null || questRequirements.Count == 0)
{
LoggingHelpers.LogWarning($"Quest requirement not found for : {quest.Value.QuestName}, skipping.");
continue;
}
foreach (var requirement in questRequirements)
{
if (requirement.PreReqType == PreRequisiteType.Quest)
{
// Does quest have requirement
if (!quest.Value.conditions.AvailableForStart.Any(x => x._parent == "Quest"
&& x._props.target.ToString() == requirement.Quest.Id))
{
LoggingHelpers.LogSuccess($"{quest.Value.QuestName} needs a prereq of quest {requirement.Quest.Name}, adding.");
string hashData = quest.Value._id + requirement.Quest.Id;
quest.Value.conditions.AvailableForStart.Add(new AvailableFor
{
_parent = "Quest",
_props = new AvailableForProps
{
id = Sha256(hashData),
index = GetNextIndex(quest.Value.conditions.AvailableForStart.LastOrDefault()?._props?.index),
parentId = "",
status = GetQuestStatus(requirement.QuestStatus),
target = requirement.Quest.Id,
visibilityConditions = new List