2022-01-12 23:30:51 +00:00
|
|
|
|
using AssortValidator.Common;
|
|
|
|
|
using AssortValidator.Common.Models;
|
2022-01-13 15:21:55 +00:00
|
|
|
|
using static AssortValidator.Common.Models.Assort;
|
2022-01-12 23:30:51 +00:00
|
|
|
|
|
|
|
|
|
namespace AssortUpdater
|
|
|
|
|
{
|
|
|
|
|
public static class AssortFlattener
|
|
|
|
|
{
|
|
|
|
|
public static List<FlatAssort> FlattenExistingAssorts(Assort existingAssorts)
|
|
|
|
|
{
|
|
|
|
|
var results = new List<FlatAssort>();
|
|
|
|
|
|
|
|
|
|
foreach (var assort in existingAssorts.items.Where(x => x.slotId == "hideout"))
|
|
|
|
|
{
|
|
|
|
|
var level = existingAssorts.loyal_level_items.FirstOrDefault(x => x.Key == assort._id);
|
|
|
|
|
var barterDetails = existingAssorts.barter_scheme.FirstOrDefault(x => x.Key == assort._id);
|
|
|
|
|
var firstBarterDetails = barterDetails.Value[0].First();
|
|
|
|
|
|
|
|
|
|
results.Add(new FlatAssort
|
|
|
|
|
{
|
|
|
|
|
AssortId = assort._id,
|
|
|
|
|
ItemId = assort._tpl,
|
|
|
|
|
ItemName = ItemTemplateHelper.GetNameById(assort._tpl),
|
|
|
|
|
Level = level.Value,
|
|
|
|
|
IsMoney = barterDetails.Value.Count == 1 && ItemTemplateHelper.IsMoney(firstBarterDetails._tpl),
|
|
|
|
|
BarterDetails = barterDetails.Value.First(),
|
2022-01-13 15:21:55 +00:00
|
|
|
|
RawItem = assort
|
2022-01-12 23:30:51 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add in sub items
|
|
|
|
|
foreach (var subAssort in existingAssorts.items.Where(x => x.slotId != "hideout"))
|
|
|
|
|
{
|
|
|
|
|
// find parent item in assort list we created
|
|
|
|
|
var assortToAddTo = results.Find(x => x.AssortId == subAssort.parentId);
|
|
|
|
|
if (assortToAddTo is null)
|
|
|
|
|
{
|
|
|
|
|
// check items subitems as some have mods of their own
|
|
|
|
|
foreach (var result in results)
|
|
|
|
|
{
|
|
|
|
|
if (result.SubItems.Any(x => x._id == subAssort.parentId))
|
|
|
|
|
{
|
|
|
|
|
assortToAddTo = result;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-19 20:22:59 +00:00
|
|
|
|
assortToAddTo?.SubItems.Add(subAssort);
|
2022-01-12 23:30:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-23 11:51:27 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Turn bsg format into a flat list of assorts that are easier to work with
|
|
|
|
|
/// </summary>
|
2022-01-12 23:30:51 +00:00
|
|
|
|
public static List<FlatAssort> FlattenLiveAssorts(Assort liveAssorts)
|
|
|
|
|
{
|
|
|
|
|
var results = new List<FlatAssort>();
|
|
|
|
|
foreach (var assort in liveAssorts.items.Where(x => x.slotId == "hideout"))
|
|
|
|
|
{
|
|
|
|
|
var level = liveAssorts.loyal_level_items.FirstOrDefault(x => x.Key == assort._id);
|
|
|
|
|
var barterDetails = liveAssorts.barter_scheme.FirstOrDefault(x => x.Key == assort._id);
|
|
|
|
|
var firstBarterDetails = barterDetails.Value[0].First();
|
|
|
|
|
|
|
|
|
|
results.Add(new FlatAssort
|
|
|
|
|
{
|
|
|
|
|
AssortId = assort._id,
|
|
|
|
|
ItemId = assort._tpl,
|
|
|
|
|
ItemName = ItemTemplateHelper.GetNameById(assort._tpl),
|
|
|
|
|
Level = level.Value,
|
|
|
|
|
IsMoney = barterDetails.Value.Count == 1 && ItemTemplateHelper.IsMoney(firstBarterDetails._tpl),
|
|
|
|
|
BarterDetails = barterDetails.Value.First(),
|
2022-01-13 15:21:55 +00:00
|
|
|
|
RawItem = assort
|
2022-01-12 23:30:51 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add in sub items
|
|
|
|
|
foreach (var subAssort in liveAssorts.items.Where(x => x.slotId != "hideout"))
|
|
|
|
|
{
|
|
|
|
|
// find parent item in assort list we created
|
|
|
|
|
var assortToAddTo = results.Find(x => x.AssortId == subAssort.parentId);
|
|
|
|
|
if (assortToAddTo is null)
|
|
|
|
|
{
|
|
|
|
|
// check items subitems as some have mods of their own
|
|
|
|
|
foreach (var result in results)
|
|
|
|
|
{
|
|
|
|
|
if (result.SubItems.Any(x => x._id == subAssort.parentId))
|
|
|
|
|
{
|
|
|
|
|
assortToAddTo = result;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assortToAddTo.SubItems.Add(subAssort);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-23 11:51:27 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Turn flattened assorts list into bsg format
|
|
|
|
|
/// </summary>
|
2022-01-13 15:21:55 +00:00
|
|
|
|
public static Assort UnFlatten(List<FlatAssort> flatAssorts)
|
|
|
|
|
{
|
|
|
|
|
var result = new Assort();
|
|
|
|
|
foreach(var assort in flatAssorts)
|
|
|
|
|
{
|
|
|
|
|
// add loyalty level key/value
|
|
|
|
|
result.loyal_level_items.Add(assort.AssortId, assort.Level);
|
|
|
|
|
|
|
|
|
|
// add barter scheme details
|
|
|
|
|
var barterItemsList = ConvertToOutputBarterItemsCollection(assort);
|
|
|
|
|
result.barter_scheme.Add(assort.AssortId, barterItemsList);
|
|
|
|
|
|
|
|
|
|
// add base item
|
|
|
|
|
result.items.Add(assort.RawItem);
|
|
|
|
|
|
|
|
|
|
// add sub items
|
|
|
|
|
foreach (var item in assort.SubItems)
|
|
|
|
|
{
|
|
|
|
|
result.items.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<List<BarterDetails>> ConvertToOutputBarterItemsCollection(FlatAssort assort)
|
|
|
|
|
{
|
|
|
|
|
var barterItems = new List<BarterDetails>();
|
|
|
|
|
foreach (var item in assort.BarterDetails)
|
|
|
|
|
{
|
|
|
|
|
barterItems.Add(new BarterDetails
|
|
|
|
|
{
|
|
|
|
|
_tpl = item._tpl,
|
2022-01-15 17:20:38 +00:00
|
|
|
|
count = item.count,
|
|
|
|
|
level = item.level,
|
|
|
|
|
side = item.side,
|
2022-01-13 15:21:55 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new List<List<BarterDetails>>
|
|
|
|
|
{
|
|
|
|
|
barterItems
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-01-12 23:30:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|