using AssortGenerator.Models.Input; using AssortGenerator.Models.Other; using AssortGenerator.Models.Output; using Common.Models; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.Json; namespace AssortGenerator.Common.Helpers { public static class QuestHelper { private static QuestRoot _questData; private static List _assortUnlocks; private static Dictionary _missingTraderQuestPrices; public static QuestRoot GetQuestData() { if (_questData == null) { var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains("resp.client.quest.list")); var questDataJson = File.ReadAllText(questFilePath); _questData = JsonSerializer.Deserialize(questDataJson); } return _questData; } public static Dictionary GetFinalisedQuestData() { var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains("quests.json")); var questDataJson = File.ReadAllText(questFilePath); var finalisedQuestData = JsonSerializer.Deserialize>(questDataJson); var jsondoc = JsonDocument.Parse(questDataJson); var root = jsondoc.RootElement; return finalisedQuestData; } public static JsonDocument GetFinalisedQuestDataJsonDoc() { var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains("quests.json")); var questDataJson = File.ReadAllText(questFilePath); var jsondoc = JsonDocument.Parse(questDataJson); return jsondoc; } public static List GetAssortUnlocks(Dictionary questData) { if (_assortUnlocks == null) { _assortUnlocks = new List(); foreach (var quest in questData.Values) { foreach (var reward in quest.rewards.Success.Where(x => string.Equals(x.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._id, QuestRewardId = reward.id, TraderId = reward.traderId, TraderType = TraderHelper.GetTraderTypeById(reward.traderId), Criteria = "Success", Items = reward.items } ); } foreach (var reward in quest.rewards.Started.Where(x => string.Equals(x.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._id, QuestRewardId = reward.id, TraderId = reward.traderId, TraderType = TraderHelper.GetTraderTypeById(reward.traderId), Criteria = "Started", Items = reward.items } ); } } } return _assortUnlocks; } public static Dictionary GetMissingTraderQuestPrices() { if (_missingTraderQuestPrices == null) { var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains("missingTraderAssortPrices")); var questDataJson = File.ReadAllText(questFilePath); _missingTraderQuestPrices = JsonSerializer.Deserialize>(questDataJson); } return _missingTraderQuestPrices; } public class MissingAssortPrice { public string questId { get; set; } public string itemTpl { get; set; } public List items { get; set; } public Upd itemUpd { get; set; } public List barterScheme { get; set; } } } }