First pass at filtering assort generation
This commit is contained in:
parent
5fa432ee32
commit
ce251b1e2b
@ -33,6 +33,7 @@ namespace CreateAssortFromFleaJsons
|
||||
// Limit flea offers to just this trader
|
||||
var traderIdToProcess = "6617beeaa9cfa777ca915b7c"; // REF
|
||||
var traderSpecificFleaData = _findResults.Where(find => find.user.id == traderIdToProcess);
|
||||
var uniqueFilteredOffers = FilterUniqueOffers(traderSpecificFleaData);
|
||||
|
||||
// Prep assort output file
|
||||
var assortResult = new AssortRoot()
|
||||
@ -41,7 +42,7 @@ namespace CreateAssortFromFleaJsons
|
||||
barter_scheme = new Dictionary<string, List<List<BarterObject>>>(),
|
||||
loyal_level_items = new Dictionary<string, int>()
|
||||
};
|
||||
foreach (var fleaOffer in traderSpecificFleaData)
|
||||
foreach (var fleaOffer in uniqueFilteredOffers)
|
||||
{
|
||||
// Has only one item
|
||||
var singularItem = fleaOffer.items.Count == 1;
|
||||
@ -50,34 +51,50 @@ namespace CreateAssortFromFleaJsons
|
||||
var firstItem = fleaOffer.items[0];
|
||||
|
||||
// Add first item
|
||||
assortResult.items.Add(new Item()
|
||||
var firstItemToAdd = 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
|
||||
}
|
||||
});
|
||||
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);
|
||||
|
||||
// Add child items
|
||||
if (!singularItem)
|
||||
{
|
||||
// Exclude first item
|
||||
var childItems = fleaOffer.items.Except([firstItem]);
|
||||
var locationValue = 0;
|
||||
foreach (var childItem in childItems)
|
||||
{
|
||||
assortResult.items.Add(new Item()
|
||||
var itemToAdd = new Item()
|
||||
{
|
||||
_id = childItem._id,
|
||||
_tpl = childItem._tpl,
|
||||
parentId = childItem.parentId,
|
||||
slotId = childItem.slotId
|
||||
});
|
||||
slotId = childItem.slotId,
|
||||
upd = childItem.upd
|
||||
};
|
||||
|
||||
if (childItem.slotId == "cartridges")
|
||||
{
|
||||
itemToAdd.location = locationValue;
|
||||
locationValue++;
|
||||
}
|
||||
|
||||
assortResult.items.Add(itemToAdd);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,6 +114,42 @@ namespace CreateAssortFromFleaJsons
|
||||
JsonWriter.WriteJson(assortResult, "", Directory.GetCurrentDirectory(), "assort");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private static string CreateWorkingFolders()
|
||||
{
|
||||
var workingPath = Directory.GetCurrentDirectory();
|
||||
|
Loading…
x
Reference in New Issue
Block a user