118 lines
3.7 KiB
C#
Raw Normal View History

2021-09-10 17:57:24 +01:00
using AssortHelpers.Common.Helpers;
using AssortValidator.Common.Models;
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<Trader, Assort> _assortDataCache;
2022-01-12 15:06:00 +00:00
private static Dictionary<Trader, Assort> _assortLiveDataCache;
2021-09-10 17:57:24 +01:00
public static Dictionary<Trader, Assort> GetAssortData()
{
if (_assortDataCache == null)
{
_assortDataCache = new Dictionary<Trader, Assort>();
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<Assort>(json);
if (traderType != Trader.Unknown)
{
_assortDataCache.Add(traderType, parsedAssorts);
}
}
}
return _assortDataCache;
}
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;
}
2022-01-12 15:06:00 +00:00
public static Dictionary<Trader, Assort> GetLiveAssortData()
2021-09-10 17:57:24 +01:00
{
if (_assortLiveDataCache == null)
{
2022-01-12 15:06:00 +00:00
_assortLiveDataCache = new Dictionary<Trader, Assort>();
2021-09-10 17:57:24 +01:00
foreach (var filePath in InputFileHelper.GetInputFilePaths().Where(x => x.Contains("resp.client.trading.api.getTraderAssort")))
{
var traderType = GetTraderType(filePath);
var json = File.ReadAllText(filePath);
2022-01-12 15:06:00 +00:00
var parsedAssorts = JsonSerializer.Deserialize<AssortRoot>(json);
2021-09-10 17:57:24 +01:00
if (traderType != Trader.Unknown)
{
_assortLiveDataCache.Add(traderType, parsedAssorts.data);
}
}
}
return _assortLiveDataCache;
}
/// <summary>
/// Assume level 1 if it doesnt exist
/// </summary>
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;
}
}
}