118 lines
3.7 KiB
C#
118 lines
3.7 KiB
C#
|
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;
|
|||
|
private static Dictionary<Trader, LiveAssort> _assortLiveDataCache;
|
|||
|
|
|||
|
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;
|
|||
|
}
|
|||
|
|
|||
|
public static Dictionary<Trader, LiveAssort> GetLiveAssortData()
|
|||
|
{
|
|||
|
if (_assortLiveDataCache == null)
|
|||
|
{
|
|||
|
_assortLiveDataCache = new Dictionary<Trader, LiveAssort>();
|
|||
|
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<LiveAssortRoot>(json);
|
|||
|
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|