Add AssortFromFleaJSON program
This commit is contained in:
parent
711f18fb57
commit
5fa432ee32
@ -113,7 +113,7 @@ namespace AssortGenerator.Common.Helpers
|
|||||||
{
|
{
|
||||||
public string questId { get; set; }
|
public string questId { get; set; }
|
||||||
public string itemTpl { get; set; }
|
public string itemTpl { get; set; }
|
||||||
public List<Models.Output.Item> items { get; set; }
|
public List<AssortGenerator.Models.Output.Item> items { get; set; }
|
||||||
public Upd itemUpd { get; set; }
|
public Upd itemUpd { get; set; }
|
||||||
public List<BarterObject> barterScheme { get; set; }
|
public List<BarterObject> barterScheme { get; set; }
|
||||||
}
|
}
|
||||||
|
50
AssortGenerator.Common/Models/FleaFindResult.cs
Normal file
50
AssortGenerator.Common/Models/FleaFindResult.cs
Normal file
@ -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<FleaOffer> 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<Item> items { get; set; }
|
||||||
|
public int itemsCost { get; set; }
|
||||||
|
public List<Requirement> 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,15 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 16.0.31624.102
|
VisualStudioVersion = 17.9.34902.65
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
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
|
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
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{FED37D1A-85E4-45C6-9D55-EFD05065251B}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
14
CreateAssortFromFleaJsons/CreateAssortFromFleaJsons.csproj
Normal file
14
CreateAssortFromFleaJsons/CreateAssortFromFleaJsons.csproj
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AssortGenerator.Common\AssortGenerator.Common.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
114
CreateAssortFromFleaJsons/Program.cs
Normal file
114
CreateAssortFromFleaJsons/Program.cs
Normal file
@ -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<FleaOffer> _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<FleaFindResult>(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<Item>(),
|
||||||
|
barter_scheme = new Dictionary<string, List<List<BarterObject>>>(),
|
||||||
|
loyal_level_items = new Dictionary<string, int>()
|
||||||
|
};
|
||||||
|
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<BarterObject>
|
||||||
|
{
|
||||||
|
// Assumes only one item for bartering
|
||||||
|
new() { _tpl = fleaOffer.requirements[0]._tpl, count = fleaOffer.requirements[0].count }
|
||||||
|
};
|
||||||
|
var barterItemListOuter = new List<List<BarterObject>> { 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user