diff --git a/AssortGenerator.Common/Helpers/QuestHelper.cs b/AssortGenerator.Common/Helpers/QuestHelper.cs index 6169396..c141b76 100644 --- a/AssortGenerator.Common/Helpers/QuestHelper.cs +++ b/AssortGenerator.Common/Helpers/QuestHelper.cs @@ -113,7 +113,7 @@ namespace AssortGenerator.Common.Helpers { public string questId { get; set; } public string itemTpl { get; set; } - public List items { get; set; } + public List items { get; set; } public Upd itemUpd { get; set; } public List barterScheme { get; set; } } diff --git a/AssortGenerator.Common/Models/FleaFindResult.cs b/AssortGenerator.Common/Models/FleaFindResult.cs new file mode 100644 index 0000000..f58ac03 --- /dev/null +++ b/AssortGenerator.Common/Models/FleaFindResult.cs @@ -0,0 +1,50 @@ +using AssortGenerator.Models.Output; +using System.Collections.Generic; + +namespace AssortGenerator.Common.Models +{ + public class FleaFindResult + { + public int err { get; set; } + public object errmsg { get; set; } + public FindFleaData data { get; set; } + } + + public class FindFleaData + { + public List offers { get; set; } + public int offersCount { get; set; } + public string selectedCategory { get; set; } + } + + public class FleaOffer + { + public string _id { get; set; } + public int intId { get; set; } + public User user { get; set; } + public string root { get; set; } + public List items { get; set; } + public int itemsCost { get; set; } + public List requirements { get; set; } + public int requirementsCost { get; set; } + public int summaryCost { get; set; } + public bool sellInOnePiece { get; set; } + public int startTime { get; set; } + public int endTime { get; set; } + public bool unlimitedCount { get; set; } + public object buyRestrictionMax { get; set; } + public int loyaltyLevel { get; set; } + } + + public class User + { + public string id { get; set; } + public int memberType { get; set; } + } + + public class Requirement + { + public decimal count { get; set; } + public string _tpl { get; set; } + } +} diff --git a/AssortGenerator.sln b/AssortGenerator.sln index bbb3727..3c321e1 100644 --- a/AssortGenerator.sln +++ b/AssortGenerator.sln @@ -1,13 +1,15 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31624.102 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34902.65 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssortGenerator", "AssortGenerator\AssortGenerator.csproj", "{747ED3CB-DED2-47CB-9BD6-493FB05B6C2B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssortGenerator", "AssortGenerator\AssortGenerator.csproj", "{747ED3CB-DED2-47CB-9BD6-493FB05B6C2B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssortGenerator.Models", "AssortGenerator.Models\AssortGenerator.Models.csproj", "{BC63C9C4-A796-4C25-AC3E-8C9565F041DC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssortGenerator.Models", "AssortGenerator.Models\AssortGenerator.Models.csproj", "{BC63C9C4-A796-4C25-AC3E-8C9565F041DC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssortGenerator.Common", "AssortGenerator.Common\AssortGenerator.Common.csproj", "{FED37D1A-85E4-45C6-9D55-EFD05065251B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssortGenerator.Common", "AssortGenerator.Common\AssortGenerator.Common.csproj", "{FED37D1A-85E4-45C6-9D55-EFD05065251B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreateAssortFromFleaJsons", "CreateAssortFromFleaJsons\CreateAssortFromFleaJsons.csproj", "{F37E2B63-EA8E-4907-A0C5-697B4B80912B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,6 +29,10 @@ Global {FED37D1A-85E4-45C6-9D55-EFD05065251B}.Debug|Any CPU.Build.0 = Debug|Any CPU {FED37D1A-85E4-45C6-9D55-EFD05065251B}.Release|Any CPU.ActiveCfg = Release|Any CPU {FED37D1A-85E4-45C6-9D55-EFD05065251B}.Release|Any CPU.Build.0 = Release|Any CPU + {F37E2B63-EA8E-4907-A0C5-697B4B80912B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F37E2B63-EA8E-4907-A0C5-697B4B80912B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F37E2B63-EA8E-4907-A0C5-697B4B80912B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F37E2B63-EA8E-4907-A0C5-697B4B80912B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CreateAssortFromFleaJsons/CreateAssortFromFleaJsons.csproj b/CreateAssortFromFleaJsons/CreateAssortFromFleaJsons.csproj new file mode 100644 index 0000000..3b5d202 --- /dev/null +++ b/CreateAssortFromFleaJsons/CreateAssortFromFleaJsons.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/CreateAssortFromFleaJsons/Program.cs b/CreateAssortFromFleaJsons/Program.cs new file mode 100644 index 0000000..259094a --- /dev/null +++ b/CreateAssortFromFleaJsons/Program.cs @@ -0,0 +1,114 @@ +using AssortGenerator.Common; +using AssortGenerator.Common.Helpers; +using AssortGenerator.Common.Models; +using AssortGenerator.Models.Output; +using Common; +using System.Linq; +using System.Text.Json; + +namespace CreateAssortFromFleaJsons +{ + public class Program + { + private static readonly List _findResults = []; + + static void Main(string[] args) + { + // Create input and ouput folders + var inputPath = CreateWorkingFolders(); + + // Read in all files inside input folder + InputFileHelper.SetInputFiles(inputPath); + + // Read paths, get file and convert file contents into an object, + // Store object inside _findResults + var fleaFilePaths = InputFileHelper.GetInputFilePaths().ToList(); + foreach (var path in fleaFilePaths) + { + var json = File.ReadAllText(path); + var findResult = JsonSerializer.Deserialize(json); + _findResults.AddRange(findResult.data.offers); + } + + // Limit flea offers to just this trader + var traderIdToProcess = "6617beeaa9cfa777ca915b7c"; // REF + var traderSpecificFleaData = _findResults.Where(find => find.user.id == traderIdToProcess); + + // Prep assort output file + var assortResult = new AssortRoot() + { + items = new List(), + barter_scheme = new Dictionary>>(), + loyal_level_items = new Dictionary() + }; + foreach (var fleaOffer in traderSpecificFleaData) + { + // Has only one item + var singularItem = fleaOffer.items.Count == 1; + + // First item in offer + var firstItem = fleaOffer.items[0]; + + // Add first item + assortResult.items.Add(new Item() + { + _id = firstItem._id, + _tpl = firstItem._tpl, + parentId = "hideout", + slotId = "hideout", + upd = new Upd + { + UnlimitedCount = fleaOffer.unlimitedCount, + StackObjectsCount = firstItem.upd.StackObjectsCount, + BuyRestrictionMax = fleaOffer.buyRestrictionMax, + BuyRestrictionCurrent = 0 + } + }); + + // Add child items + if (!singularItem) + { + var childItems = fleaOffer.items.Except([firstItem]); + foreach (var childItem in childItems) + { + assortResult.items.Add(new Item() + { + _id = childItem._id, + _tpl = childItem._tpl, + parentId = childItem.parentId, + slotId = childItem.slotId + }); + } + } + + // Add barter_scheme + var barterItemListInner = new List + { + // Assumes only one item for bartering + new() { _tpl = fleaOffer.requirements[0]._tpl, count = fleaOffer.requirements[0].count } + }; + var barterItemListOuter = new List> { barterItemListInner }; + assortResult.barter_scheme.Add(firstItem._id, barterItemListOuter); + + // Add loyal_level + assortResult.loyal_level_items.Add(firstItem._id, fleaOffer.loyaltyLevel); + } + + JsonWriter.WriteJson(assortResult, "", Directory.GetCurrentDirectory(), "assort"); + } + + private static string CreateWorkingFolders() + { + var workingPath = Directory.GetCurrentDirectory(); + // create input folder + var inputPath = $"{workingPath}//input"; + DiskHelpers.CreateDirIfDoesntExist(inputPath); + + // create output folder + var outputPath = $"{workingPath}//output"; + DiskHelpers.CreateDirIfDoesntExist(outputPath); + + return inputPath; + } + } +} \ No newline at end of file