diff --git a/AssortUpdater/AssortFlattener.cs b/AssortUpdater/AssortFlattener.cs index 3900c20..6f3d3e2 100644 --- a/AssortUpdater/AssortFlattener.cs +++ b/AssortUpdater/AssortFlattener.cs @@ -1,11 +1,11 @@ using AssortValidator.Common; using AssortValidator.Common.Models; +using static AssortValidator.Common.Models.Assort; namespace AssortUpdater { public static class AssortFlattener { - public static List FlattenExistingAssorts(Assort existingAssorts) { var results = new List(); @@ -24,6 +24,7 @@ namespace AssortUpdater Level = level.Value, IsMoney = barterDetails.Value.Count == 1 && ItemTemplateHelper.IsMoney(firstBarterDetails._tpl), BarterDetails = barterDetails.Value.First(), + RawItem = assort }); } @@ -67,6 +68,7 @@ namespace AssortUpdater Level = level.Value, IsMoney = barterDetails.Value.Count == 1 && ItemTemplateHelper.IsMoney(firstBarterDetails._tpl), BarterDetails = barterDetails.Value.First(), + RawItem = assort }); } @@ -105,10 +107,53 @@ namespace AssortUpdater public string ItemId { get; set; } public string ItemName { get; set; } public List SubItems { get; set; } + public Assort.Item RawItem { get;set;} public int Level { get; set; } public bool IsMoney { get; set; } public List BarterDetails { get; set; } } + public static Assort UnFlatten(List flatAssorts) + { + var result = new Assort(); + foreach(var assort in flatAssorts) + { + // add loyalty level key/value + result.loyal_level_items.Add(assort.AssortId, assort.Level); + + // add barter scheme details + var barterItemsList = ConvertToOutputBarterItemsCollection(assort); + result.barter_scheme.Add(assort.AssortId, barterItemsList); + + // add base item + result.items.Add(assort.RawItem); + + // add sub items + foreach (var item in assort.SubItems) + { + result.items.Add(item); + } + } + + return result; + } + + private static List> ConvertToOutputBarterItemsCollection(FlatAssort assort) + { + var barterItems = new List(); + foreach (var item in assort.BarterDetails) + { + barterItems.Add(new BarterDetails + { + _tpl = item._tpl, + count = item.count + }); + } + + return new List> + { + barterItems + }; + } } } diff --git a/AssortUpdater/Program.cs b/AssortUpdater/Program.cs index e02140b..a984b3f 100644 --- a/AssortUpdater/Program.cs +++ b/AssortUpdater/Program.cs @@ -1,8 +1,9 @@ using AssortHelpers.Common.Helpers; using AssortHelpers.Helpers; using AssortUpdater; +using AssortValidator.Common; using AssortValidator.Common.Helpers; -using static AssortUpdater.AssortFlattener; +using AssortValidator.Common.Models; class Program { @@ -23,20 +24,20 @@ class Program var traderQuests = questData.Where(x=>x.Value.traderId == traderId); var traderAssortData = questAssortData.Where(x => x.TraderId == traderId); - var liveAssorts = trader.Value; - var existingAssorts = existingAssortData[trader.Key]; - var mergedAssortData = liveAssorts; + var liveAssortsForTrader = trader.Value; + var existingAssortsForTrader = existingAssortData[trader.Key]; - var flattenedLiveAssorts = AssortFlattener.FlattenLiveAssorts(liveAssorts); - var flattenedExistingAssorts = AssortFlattener.FlattenExistingAssorts(existingAssorts); + var flattenedLiveAssorts = AssortFlattener.FlattenLiveAssorts(liveAssortsForTrader); + var flattenedExistingAssorts = AssortFlattener.FlattenExistingAssorts(existingAssortsForTrader); //LogItemsMissingInLiveAssorts(trader.Key.ToString(), flattenedExistingAssorts, flattenedLiveAssorts); - //LogItemsMissingInExistingAssorts(trader.Key.ToString(), flattenedExistingAssorts, flattenedLiveAssorts); + var flatAssorts = AssortMerger.CreateMergedFlattenedAssorts(trader.Key.ToString(), flattenedLiveAssorts, flattenedExistingAssorts); - var result = CreateMergedFlattenedAssorts(trader.Key.ToString(), flattenedLiveAssorts, flattenedExistingAssorts); + Assort unflattenedAssorts = AssortFlattener.UnFlatten(flatAssorts); + JsonWriter.WriteJson(unflattenedAssorts, traderId, Directory.GetCurrentDirectory(), "assort"); // generate trader specific assort quest data, write out to file var questAssorts = QuestHelper.CreateQuestAssortsList(traderAssortData); @@ -44,78 +45,6 @@ class Program } } - private static List CreateMergedFlattenedAssorts(string trader, List flattenedLiveAssorts, List flattenedExistingAssorts) - { - var completeAssorts = new List(); - - // Add live assorts - foreach (var liveAssort in flattenedLiveAssorts) - { - completeAssorts.Add(liveAssort); - } - LoggingHelpers.LogSuccess($"{trader} Added {flattenedLiveAssorts.Count} items from live"); - - - // Check for missing existing assorts and add those - var ExistingItemCount = 0; - foreach (var existingAssort in flattenedExistingAssorts) - { - var matchInCompleteAssorts = GetMatchingAssortFromCompleteList(trader, existingAssort, completeAssorts); - if (matchInCompleteAssorts is null) - { - // no assort found, add - LoggingHelpers.LogWarning($"{trader} Adding Item found in existing assorts but not live: {existingAssort.ItemId} {existingAssort.ItemName} Level: {existingAssort.Level}"); - completeAssorts.Add(existingAssort); - ExistingItemCount++; - } - } - - LoggingHelpers.LogSuccess($"{trader} Added {ExistingItemCount} existing items"); - return completeAssorts; - } - - private static FlatAssort GetMatchingAssortFromCompleteList(string traderName, FlatAssort assortToFind, List completeAssorts) - { - var existingAssort = completeAssorts.Where(x => x.ItemId == assortToFind.ItemId - && x.Level == assortToFind.Level); - - // check only one item found - if (existingAssort?.Count() == 1) - { - //LoggingHelpers.LogSuccess($"{traderName} match found for item: {assortToFind.ItemId} {assortToFind.ItemName} Level: {assortToFind.Level}"); - return existingAssort.First(); - } - - if (existingAssort?.Count() > 1) - { - // try and get it by money - existingAssort = completeAssorts.Where( x=> x.ItemId == assortToFind.ItemId - && x.Level == assortToFind.Level - && x.IsMoney == assortToFind.IsMoney); - - if (existingAssort?.Count() == 1) - { - return existingAssort.First(); - } - if (existingAssort?.Count() > 1) - { - existingAssort = completeAssorts.Where(x => x.ItemId == assortToFind.ItemId - && x.Level == assortToFind.Level - && x.IsMoney == assortToFind.IsMoney - && x.SubItems.Count == assortToFind.SubItems.Count - && x.BarterDetails[0].count == assortToFind.BarterDetails[0].count); - - if ( existingAssort?.Count() == 1) - { - return existingAssort.First(); - } - } - } - - //LoggingHelpers.LogError($"{traderName} No match found for item: {assortToFind.ItemId} {assortToFind.ItemName} Level: {assortToFind.Level}"); - return null; - } - private static void LogItemsMissingInExistingAssorts(string traderName, List flattenedExistingAssorts, List flattenedLiveAssorts) { foreach (var liveAssort in flattenedLiveAssorts) diff --git a/AssortValidator.Common/Helpers/ItemTemplateHelper.cs b/AssortValidator.Common/Helpers/ItemTemplateHelper.cs index f96ed61..7bdd994 100644 --- a/AssortValidator.Common/Helpers/ItemTemplateHelper.cs +++ b/AssortValidator.Common/Helpers/ItemTemplateHelper.cs @@ -77,6 +77,8 @@ namespace AssortValidator.Common public static bool IsMoney(string tplId) { + return GetTemplateById(tplId)._parent == "543be5dd4bdc2deb348b4569"; // money type + if (tplId == "5449016a4bdc2d6f028b456f") { return true; diff --git a/AssortValidator.Common/Helpers/QuestHelper.cs b/AssortValidator.Common/Helpers/QuestHelper.cs index 8f0feb4..04d70d7 100644 --- a/AssortValidator.Common/Helpers/QuestHelper.cs +++ b/AssortValidator.Common/Helpers/QuestHelper.cs @@ -261,7 +261,20 @@ namespace AssortValidator.Common.Helpers }; private static Dictionary _liveQuestData; - public static Dictionary GetQuestData(string filename = "resp.client.quest.list") + public static Dictionary GetQuestDataFromDump(string filename = "resp.client.quest.list") + { + if (_liveQuestData == null) + { + var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains(filename)); + var questDataJson = File.ReadAllText(questFilePath); + var rawRootData = JsonSerializer.Deserialize(questDataJson).data; + _liveQuestData = rawRootData.ToDictionary(x => x._id, y => y); + } + + return _liveQuestData; + } + + public static Dictionary GetQuestData(string filename = "quest") { if (_liveQuestData == null) { @@ -294,7 +307,6 @@ namespace AssortValidator.Common.Helpers } } - return results; } diff --git a/AssortValidator.Common/Models/Assort.cs b/AssortValidator.Common/Models/Assort.cs index d085807..672cb8c 100644 --- a/AssortValidator.Common/Models/Assort.cs +++ b/AssortValidator.Common/Models/Assort.cs @@ -12,6 +12,13 @@ namespace AssortValidator.Common.Models public class Assort { + public Assort() + { + items = new List(); + barter_scheme = new Dictionary>>(); + loyal_level_items = new Dictionary(); + } + public int nextResupply { get; set; } public List items { get; set; } public Dictionary>> barter_scheme { get; set; } @@ -36,8 +43,9 @@ namespace AssortValidator.Common.Models public class Upd { public int? BuyRestrictionMax { get; set; } - public int BuyRestrictionCurrent { get; set; } - public int StackObjectsCount { get; set; } + public int? BuyRestrictionCurrent { get; set; } + public int? StackObjectsCount { get; set; } + public bool? UnlimitedCount { get; set; } } } } \ No newline at end of file