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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assortToAddTo.SubItems.Add(subAssort);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class FlatAssort
|
|
|
|
|
{
|
|
|
|
|
public FlatAssort()
|
|
|
|
|
{
|
|
|
|
|
SubItems = new List<Assort.Item>();
|
|
|
|
|
BarterDetails = new List<Assort.BarterDetails>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string AssortId { get; set; }
|
|
|
|
|
public string ItemId { get; set; }
|
|
|
|
|
public string ItemName { get; set; }
|
|
|
|
|
public List<Assort.Item> SubItems { get; set; }
|
2022-01-13 15:21:55 +00:00
|
|
|
|
public Assort.Item RawItem { get;set;}
|
2022-01-12 23:30:51 +00:00
|
|
|
|
public int Level { get; set; }
|
|
|
|
|
public bool IsMoney { get; set; }
|
|
|
|
|
public List<Assort.BarterDetails> BarterDetails { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
|
|
|
|
count = item.count
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new List<List<BarterDetails>>
|
|
|
|
|
{
|
|
|
|
|
barterItems
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-01-12 23:30:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|