2022-01-13 15:25:49 +00:00

113 lines
4.3 KiB
C#

using AssortHelpers.Common.Helpers;
using AssortHelpers.Helpers;
using AssortValidator.Common;
using AssortValidator.Common.Helpers;
using AssortValidator.Common.Helpers.Models;
using AssortValidator.Common.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace AssortValidator
{
class Program
{
static void Main(string[] args)
{
var inputPath = DiskHelpers.CreateWorkingFolder("input");
InputFileHelper.SetInputFiles(inputPath);
var assortData = AssortHelper.GetAssortData();
var liveAssortData = AssortHelper.GetLiveAssortData();
ListAssortFilesFound(assortData);
ListAssortsInLiveNotInOffline(assortData, liveAssortData);
AssortItemChecker.CheckAssortValues(assortData, liveAssortData);
}
private static void ListAssortFilesFound(Dictionary<Trader, Assort> assortData)
{
foreach (var trader in Enum.GetValues(typeof(Trader)).Cast<Trader>())
{
var traderFound = assortData.ContainsKey(trader);
if (traderFound)
{
LoggingHelpers.LogSuccess($"Trader: {trader} found");
}
else
{
LoggingHelpers.LogError($"Trader: {trader} NOT found");
}
}
}
private static void ListAssortsInLiveNotInOffline(Dictionary<Trader, Assort> assortData, Dictionary<Trader, Assort> liveAssortData)
{
foreach (var trader in liveAssortData)
{
LoggingHelpers.LogNewLine();
LoggingHelpers.LogInfo($"Checking Trader: {trader.Key}");
LoggingHelpers.LogInfo($"Live assort count: {trader.Value.items.Count}");
var missingAssortCount = 0;
var missingItems = new List<string>();
foreach (var liveAssort in trader.Value.items.Where(x => x.parentId == "hideout"))
{
var offlineAssort = assortData[trader.Key].items.FirstOrDefault(x=>x._tpl == liveAssort._tpl);
if (offlineAssort == null)
{
missingAssortCount++;
var data = ItemTemplateHelper.GetTemplateById(liveAssort._tpl);
if (data is null)
{
LoggingHelpers.LogInfo($"Assort not found skipping: {liveAssort._tpl}");
continue;
}
var itemName = data._name;
int assortLoyaltyLevel = GetAssortLoyaltyLevel(liveAssort._id, trader.Value);
var liveBarterData = trader.Value.barter_scheme.FirstOrDefault(x => x.Key == liveAssort._id).Value;
var firstItemIsMoney = ItemTemplateHelper.IsMoney(liveBarterData.First().First()._tpl);
var isMoneyMessage = firstItemIsMoney ? "money trade" : "barter trade";
missingItems.Add($"{liveAssort._tpl} - {itemName} - Level {assortLoyaltyLevel} - {isMoneyMessage}");
}
}
if (missingAssortCount > 0)
{
LoggingHelpers.LogWarning($"Missing assorts in live but not in existing: {missingAssortCount}");
foreach (var item in missingItems)
{
LoggingHelpers.LogError($"{item}");
}
}
else
{
LoggingHelpers.LogSuccess("Live and existing assorts match :)");
}
}
}
private static int GetAssortLoyaltyLevel(string assortId, Assort assort)
{
int assortLoyaltyLevel = 1;
if (!assort.loyal_level_items.ContainsKey(assortId))
{
LoggingHelpers.LogWarning($"No existing loyalty level record found for itemId: {assortId} assuming level 1");
LoggingHelpers.LogNewLine();
}
else
{
assortLoyaltyLevel = assort.loyal_level_items[assortId];
}
return assortLoyaltyLevel;
}
}
}