114 lines
4.2 KiB
C#
114 lines
4.2 KiB
C#
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;
|
|
}
|
|
}
|
|
} |