2024-06-07 11:54:32 +01:00
|
|
|
|
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);
|
2024-09-08 00:06:40 +01:00
|
|
|
|
var uniqueFilteredOffers = FilterUniqueOffers(traderSpecificFleaData);
|
2024-06-07 11:54:32 +01:00
|
|
|
|
|
|
|
|
|
// 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>()
|
|
|
|
|
};
|
2024-09-08 00:06:40 +01:00
|
|
|
|
foreach (var fleaOffer in uniqueFilteredOffers)
|
2024-06-07 11:54:32 +01:00
|
|
|
|
{
|
|
|
|
|
// Has only one item
|
|
|
|
|
var singularItem = fleaOffer.items.Count == 1;
|
|
|
|
|
|
|
|
|
|
// First item in offer
|
|
|
|
|
var firstItem = fleaOffer.items[0];
|
|
|
|
|
|
|
|
|
|
// Add first item
|
2024-09-08 00:06:40 +01:00
|
|
|
|
var firstItemToAdd = new Item
|
2024-06-07 11:54:32 +01:00
|
|
|
|
{
|
|
|
|
|
_id = firstItem._id,
|
|
|
|
|
_tpl = firstItem._tpl,
|
|
|
|
|
parentId = "hideout",
|
|
|
|
|
slotId = "hideout",
|
2024-09-08 00:06:40 +01:00
|
|
|
|
upd = firstItem.upd
|
|
|
|
|
};
|
|
|
|
|
if (fleaOffer.buyRestrictionMax != null)
|
|
|
|
|
{
|
|
|
|
|
firstItemToAdd.upd.BuyRestrictionMax = fleaOffer.buyRestrictionMax;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
firstItemToAdd.upd.UnlimitedCount = fleaOffer.unlimitedCount;
|
|
|
|
|
firstItemToAdd.upd.BuyRestrictionCurrent = 0;
|
|
|
|
|
|
|
|
|
|
assortResult.items.Add(firstItemToAdd);
|
2024-06-07 11:54:32 +01:00
|
|
|
|
|
|
|
|
|
// Add child items
|
|
|
|
|
if (!singularItem)
|
|
|
|
|
{
|
2024-09-08 00:06:40 +01:00
|
|
|
|
// Exclude first item
|
2024-06-07 11:54:32 +01:00
|
|
|
|
var childItems = fleaOffer.items.Except([firstItem]);
|
2024-09-08 00:06:40 +01:00
|
|
|
|
var locationValue = 0;
|
2024-06-07 11:54:32 +01:00
|
|
|
|
foreach (var childItem in childItems)
|
|
|
|
|
{
|
2024-09-08 00:06:40 +01:00
|
|
|
|
var itemToAdd = new Item()
|
2024-06-07 11:54:32 +01:00
|
|
|
|
{
|
|
|
|
|
_id = childItem._id,
|
|
|
|
|
_tpl = childItem._tpl,
|
|
|
|
|
parentId = childItem.parentId,
|
2024-09-08 00:06:40 +01:00
|
|
|
|
slotId = childItem.slotId,
|
|
|
|
|
upd = childItem.upd
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (childItem.slotId == "cartridges")
|
|
|
|
|
{
|
|
|
|
|
itemToAdd.location = locationValue;
|
|
|
|
|
locationValue++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assortResult.items.Add(itemToAdd);
|
|
|
|
|
|
|
|
|
|
|
2024-06-07 11:54:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-08 00:06:40 +01:00
|
|
|
|
private static IEnumerable<FleaOffer> FilterUniqueOffers(IEnumerable<FleaOffer> traderSpecificFleaData)
|
|
|
|
|
{
|
|
|
|
|
var results = new List<FleaOffer>();
|
|
|
|
|
foreach (var offer in traderSpecificFleaData)
|
|
|
|
|
{
|
|
|
|
|
// Is a child, add it
|
|
|
|
|
if (offer.items[0].upd == null)
|
|
|
|
|
{
|
|
|
|
|
results.Add(offer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Has upd object, base item
|
|
|
|
|
// Get values to compare against
|
|
|
|
|
var itemCount = offer.items.Count;
|
|
|
|
|
var offerRootTpl = offer.items[0]._tpl;
|
|
|
|
|
var itemsCost = offer.itemsCost;
|
|
|
|
|
var requirementsCount = offer.requirements[0].count;
|
|
|
|
|
var loyaltyLevel = offer.loyaltyLevel;
|
|
|
|
|
var buyRestrictionMax = offer.buyRestrictionMax;
|
|
|
|
|
|
|
|
|
|
var existingItem = results.Exists((resultOffer => resultOffer.items.Count == itemCount
|
|
|
|
|
&& resultOffer.items[0]._tpl == offerRootTpl
|
|
|
|
|
&& resultOffer.itemsCost == itemsCost
|
|
|
|
|
&& resultOffer.requirements[0].count == requirementsCount
|
|
|
|
|
&& resultOffer.loyaltyLevel == loyaltyLevel
|
|
|
|
|
&& resultOffer.buyRestrictionMax.ToString() == buyRestrictionMax.ToString()));
|
|
|
|
|
|
|
|
|
|
if (!existingItem)
|
|
|
|
|
{
|
|
|
|
|
results.Add(offer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 11:54:32 +01:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|