using QuestValidator.Common.Helpers; using QuestValidator.Common.Models; using QuestValidator.Models; using QuestValidator.Models.Other; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.Json; namespace AssortGenerator.Common.Helpers { public static class QuestHelper { // Quest to lookup is key, previous quest is PreceedingQuest value private static QuestRoot _liveQuestData; private static Dictionary _questData; private static List _assortUnlocks; public static Dictionary GetQuestData(string filename = "quests") { if (_questData == null) { var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains(filename)); if (questFilePath == null) { return null; } var questDataJson = File.ReadAllText(questFilePath); _questData = JsonSerializer.Deserialize>(questDataJson); } return _questData; } public static QuestRoot GetLiveQuestData(string filename = "resp.client.quest.list") { if (_liveQuestData == null) { var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains(filename)); if (questFilePath == null) { return null; } var questDataJson = File.ReadAllText(questFilePath); _liveQuestData = JsonSerializer.Deserialize(questDataJson); } return _liveQuestData; } public static string GetQuestNameById(string id) { return QuestNames.GetNameById(id); } public static List GetAssortUnlocks() { if (_assortUnlocks == null) { _assortUnlocks = new List(); foreach (var quest in GetQuestData()) { foreach (var reward in quest.Value.rewards.Success) { if (string.Equals(reward.type, "assortmentunlock", System.StringComparison.OrdinalIgnoreCase)) { _assortUnlocks.Add(new AssortUnlocks { AssortUnlockId = reward.id, ItemUnlockedId = reward.target, ItemUnlockedTemplateId = reward.items[0]._tpl, LoyaltyLevel = (int)reward.loyaltyLevel, QuestId = quest.Key, QuestRewardId = reward.id, TraderId = reward.traderId, TraderType = TraderHelper.GetTraderTypeById(reward.traderId), Criteria = "Success" } ); } } } } return _assortUnlocks; } public static List GetQuestDependancy(string questId) { return QuestRequirements.GetQuestRequirements(questId); } public static bool DoesIconExist(string iconPath, string imageId) { var filesInPath = Directory.GetFiles(iconPath); return filesInPath.Any(x => x.Contains(imageId)); } } }