using AssortHelpers.Common.Helpers; using AssortValidator.Common.Models; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.Json; namespace AssortValidator.Common.Helpers { public static class AssortHelper { private static Dictionary _assortDataCache; private static Dictionary _assortLiveDataCache; public static Dictionary GetAssortData() { if (_assortDataCache == null) { _assortDataCache = new Dictionary(); foreach (var filePath in InputFileHelper.GetInputFilePaths().Where(x => x.EndsWith("\\assort.json"))) { var traderType = GetTraderType(filePath); var json = File.ReadAllText(filePath); var parsedAssorts = JsonSerializer.Deserialize(json); if (traderType != Trader.Unknown) { _assortDataCache.Add(traderType, parsedAssorts); } } } return _assortDataCache; } /// /// Log to console if each trader was found in the supplied dictionary /// /// public static void ListAssortFilesFound(Dictionary assortData) { foreach (var trader in Enum.GetValues(typeof(Trader)).Cast()) { var traderFound = assortData.ContainsKey(trader); if (traderFound) { LoggingHelpers.LogSuccess($"Trader: {trader} found"); } else { LoggingHelpers.LogError($"Trader: {trader} NOT found"); } } } private static Trader GetTraderType(string filePath) { if (filePath.Contains("54cb50c76803fa8b248b4571")) { return Trader.Prapor; } if (filePath.Contains("54cb57776803fa99248b456e")) { return Trader.Therapist; } if (filePath.Contains("58330581ace78e27b8b10cee")) { return Trader.Skier; } if (filePath.Contains("5935c25fb3acc3127c3d8cd9")) { return Trader.Peacekeeper; } if (filePath.Contains("5a7c2eca46aef81a7ca2145d")) { return Trader.Mechanic; } if (filePath.Contains("5ac3b934156ae10c4430e83c")) { return Trader.Ragman; } if (filePath.Contains("5c0647fdd443bc2504c2d371")) { return Trader.Jaeger; } return Trader.Unknown; } public static Dictionary GetLiveAssortData() { if (_assortLiveDataCache == null) { _assortLiveDataCache = new Dictionary(); foreach (var filePath in InputFileHelper.GetInputFilePaths().Where(x => x.Contains("resp.client.trading.api.getTraderAssort"))) { var traderType = GetTraderType(filePath); var json = File.ReadAllText(filePath); var parsedAssorts = JsonSerializer.Deserialize(json); if (traderType != Trader.Unknown) { _assortLiveDataCache.Add(traderType, parsedAssorts.data); } } } return _assortLiveDataCache; } /// /// Assume level 1 if it doesnt exist /// public static int GetAssortLoyaltyLevel(string assortId, Assort assort) { int assortLoyaltyLevel = 1; if (!assort.loyal_level_items.ContainsKey(assortId)) { LoggingHelpers.LogWarning($"No offline loyalty level record found for itemId: {assortId} assuming level 1"); LoggingHelpers.LogInfo(""); } else { assortLoyaltyLevel = assort.loyal_level_items[assortId]; } return assortLoyaltyLevel; } } }