152 lines
7.0 KiB
C#
Raw Normal View History

using AssortHelpers.Common.Helpers;
using AssortHelpers.Helpers;
using AssortUpdater;
using AssortValidator.Common;
using AssortValidator.Common.Helpers;
using AssortValidator.Common.Models;
2022-01-15 15:01:24 +00:00
using QuestValidator.Common.Helpers;
class Program
{
static void Main(string[] args)
{
2022-01-13 15:25:49 +00:00
var inputPath = DiskHelpers.CreateWorkingFolder("input");
InputFileHelper.SetInputFiles(inputPath);
var existingAssortData = AssortHelper.GetAssortData();
var liveAssortData = AssortHelper.GetLiveAssortData();
var questData = QuestHelper.GetQuestData("quests");
var questAssortData = QuestHelper.GetQuestAssortUnlocks(questData.Values.ToList());
foreach (var trader in liveAssortData)
{
var traderId = TraderHelper.GetTraderIdByName(trader.Key);
var traderQuests = questData.Where(x=>x.Value.traderId == traderId);
2022-01-15 15:01:24 +00:00
var traderQuestAssortUnlocks = questAssortData.Where(x => x.TraderId == traderId);
var liveAssortsForTrader = trader.Value;
var existingAssortsForTrader = existingAssortData[trader.Key];
var flattenedLiveAssorts = AssortFlattener.FlattenLiveAssorts(liveAssortsForTrader);
var flattenedExistingAssorts = AssortFlattener.FlattenExistingAssorts(existingAssortsForTrader);
//LogItemsMissingInLiveAssorts(trader.Key.ToString(), flattenedExistingAssorts, flattenedLiveAssorts);
//LogItemsMissingInExistingAssorts(trader.Key.ToString(), flattenedExistingAssorts, flattenedLiveAssorts);
List<FlatAssort>? flatAssorts = AssortMerger.CreateMergedFlattenedAssorts(trader.Key.ToString(), flattenedLiveAssorts, flattenedExistingAssorts);
2022-01-15 15:01:24 +00:00
LoggingHelpers.LogInfo($"trader: {TraderHelper.GetTraderIdByName(trader.Key)}");
2022-01-15 15:02:37 +00:00
AssortMerger.ListDuplicatesInMergedAssorts(flatAssorts);
List<FlatAssort> roundedFlattenedAssorts = RoundFlatAssortStackCounts(flatAssorts);
Assort unflattenedAssorts = AssortFlattener.UnFlatten(roundedFlattenedAssorts);
2022-01-23 11:36:43 +00:00
JsonWriter.WriteJson(unflattenedAssorts, traderId, Directory.GetCurrentDirectory(), "assort");
2022-01-23 11:51:27 +00:00
var questAssorts = QuestAssortGenerator.CreateQuestAssorts(trader.Key, traderQuestAssortUnlocks, flatAssorts);
2022-01-15 15:01:24 +00:00
LogQuestUnlocks(questAssorts, unflattenedAssorts);
JsonWriter.WriteJson(questAssorts, traderId, Directory.GetCurrentDirectory(), "questassort");
}
}
private static List<FlatAssort> RoundFlatAssortStackCounts(List<FlatAssort> flatAssorts)
{
foreach (var flatAssort in flatAssorts)
{
if (flatAssort.RawItem.upd.StackObjectsCount.HasValue)
{
var stackCount = flatAssort.RawItem.upd.StackObjectsCount;
if (stackCount > 49 && stackCount != 999999)
{
var numberSize = stackCount.Value.NumberSize();
flatAssort.RawItem.upd.StackObjectsCount = stackCount.Value.Round(numberSize);
}
}
}
return flatAssorts;
}
2022-01-23 11:51:27 +00:00
private static void LogQuestUnlocks(QuestAssorts questAssorts, Assort unflattenedAssorts)
2022-01-15 15:01:24 +00:00
{
foreach (var item in questAssorts.success)
{
var assortId = item.Key;
var questId = item.Value;
var assortData = unflattenedAssorts.items.Find(x => x._id == assortId);
LoggingHelpers.LogToConsole($"Assort: {assortId} Item: {assortData?.ItemName} is unlocked by quest {QuestNames.GetNameById(questId)}");
2022-01-15 15:01:24 +00:00
}
}
private static void LogItemsMissingInExistingAssorts(string traderName, List<FlatAssort> flattenedExistingAssorts, List<FlatAssort> flattenedLiveAssorts)
{
foreach (var liveAssort in flattenedLiveAssorts)
{
// get live assort, match by level and item tpl
var existingAssort = flattenedExistingAssorts.Where(x => x.ItemId == liveAssort.ItemId && x.Level == liveAssort.Level);
if (existingAssort.Count() > 1)
{
// we have multiple matches, lets compare by number of rewards
existingAssort = flattenedExistingAssorts.Where(x => x.ItemId == liveAssort.ItemId
&& x.Level == liveAssort.Level
&& x.BarterDetails.Count == liveAssort.BarterDetails.Count
&& x.SubItems.Count == liveAssort.SubItems.Count
&& x.IsMoney == liveAssort.IsMoney);
if (existingAssort is null)
{
LoggingHelpers.LogError($"{traderName} multiple matches found for item: {liveAssort.ItemId} {liveAssort.ItemName} Level: {liveAssort.Level}");
continue;
}
}
if (liveAssort is null)
{
LoggingHelpers.LogError($"{traderName} unable to find matching live assort for item: {liveAssort.ItemId} {liveAssort.ItemName} Level: {liveAssort.Level}");
}
else
{
LoggingHelpers.LogSuccess($"{traderName} found matching live assort for item: {liveAssort.ItemId} {liveAssort.ItemName} Level: {liveAssort.Level}");
}
}
}
private static void LogItemsMissingInLiveAssorts(string traderName, List<FlatAssort> flattenedExistingAssorts, List<FlatAssort> flattenedLiveAssorts)
{
foreach (var existingAssort in flattenedExistingAssorts)
{
// get live assort, match by level and item tpl
var liveAssort = flattenedLiveAssorts.Where(x => x.ItemId == existingAssort.ItemId && x.Level == existingAssort.Level);
if (liveAssort.Count() > 1)
{
// we have multiple matches, lets compare by number of rewards
liveAssort = flattenedLiveAssorts.Where(x => x.ItemId == existingAssort.ItemId
&& x.Level == existingAssort.Level
&& x.BarterDetails.Count == existingAssort.BarterDetails.Count
&& x.SubItems.Count == existingAssort.SubItems.Count
&& x.IsMoney == existingAssort.IsMoney);
if (liveAssort.Count() > 1)
{
LoggingHelpers.LogError($"{traderName} multiple matches found for item: {existingAssort.ItemId} {existingAssort.ItemName} Level: {existingAssort.Level}");
continue;
}
}
if (liveAssort is null)
{
LoggingHelpers.LogError($"{traderName} unable to find matching existing assort for item: {existingAssort.ItemId} {existingAssort.ItemName} Level: {existingAssort.Level}");
}
else
{
LoggingHelpers.LogSuccess($"{traderName} found matching existing assort for item: {existingAssort.ItemId} {existingAssort.ItemName} Level: {existingAssort.Level}");
}
}
}
}