Further work on creating an assort for each trader
This commit is contained in:
parent
593f68f812
commit
82e78f80eb
@ -1,11 +1,11 @@
|
||||
using AssortValidator.Common;
|
||||
using AssortValidator.Common.Models;
|
||||
using static AssortValidator.Common.Models.Assort;
|
||||
|
||||
namespace AssortUpdater
|
||||
{
|
||||
public static class AssortFlattener
|
||||
{
|
||||
|
||||
public static List<FlatAssort> FlattenExistingAssorts(Assort existingAssorts)
|
||||
{
|
||||
var results = new List<FlatAssort>();
|
||||
@ -24,6 +24,7 @@ namespace AssortUpdater
|
||||
Level = level.Value,
|
||||
IsMoney = barterDetails.Value.Count == 1 && ItemTemplateHelper.IsMoney(firstBarterDetails._tpl),
|
||||
BarterDetails = barterDetails.Value.First(),
|
||||
RawItem = assort
|
||||
});
|
||||
}
|
||||
|
||||
@ -67,6 +68,7 @@ namespace AssortUpdater
|
||||
Level = level.Value,
|
||||
IsMoney = barterDetails.Value.Count == 1 && ItemTemplateHelper.IsMoney(firstBarterDetails._tpl),
|
||||
BarterDetails = barterDetails.Value.First(),
|
||||
RawItem = assort
|
||||
});
|
||||
}
|
||||
|
||||
@ -105,10 +107,53 @@ namespace AssortUpdater
|
||||
public string ItemId { get; set; }
|
||||
public string ItemName { get; set; }
|
||||
public List<Assort.Item> SubItems { get; set; }
|
||||
public Assort.Item RawItem { get;set;}
|
||||
public int Level { get; set; }
|
||||
public bool IsMoney { get; set; }
|
||||
public List<Assort.BarterDetails> BarterDetails { get; set; }
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
using AssortHelpers.Common.Helpers;
|
||||
using AssortHelpers.Helpers;
|
||||
using AssortUpdater;
|
||||
using AssortValidator.Common;
|
||||
using AssortValidator.Common.Helpers;
|
||||
using static AssortUpdater.AssortFlattener;
|
||||
using AssortValidator.Common.Models;
|
||||
|
||||
class Program
|
||||
{
|
||||
@ -23,20 +24,20 @@ class Program
|
||||
var traderQuests = questData.Where(x=>x.Value.traderId == traderId);
|
||||
var traderAssortData = questAssortData.Where(x => x.TraderId == traderId);
|
||||
|
||||
var liveAssorts = trader.Value;
|
||||
var existingAssorts = existingAssortData[trader.Key];
|
||||
var mergedAssortData = liveAssorts;
|
||||
var liveAssortsForTrader = trader.Value;
|
||||
var existingAssortsForTrader = existingAssortData[trader.Key];
|
||||
|
||||
var flattenedLiveAssorts = AssortFlattener.FlattenLiveAssorts(liveAssorts);
|
||||
var flattenedExistingAssorts = AssortFlattener.FlattenExistingAssorts(existingAssorts);
|
||||
var flattenedLiveAssorts = AssortFlattener.FlattenLiveAssorts(liveAssortsForTrader);
|
||||
var flattenedExistingAssorts = AssortFlattener.FlattenExistingAssorts(existingAssortsForTrader);
|
||||
|
||||
//LogItemsMissingInLiveAssorts(trader.Key.ToString(), flattenedExistingAssorts, flattenedLiveAssorts);
|
||||
|
||||
//LogItemsMissingInExistingAssorts(trader.Key.ToString(), flattenedExistingAssorts, flattenedLiveAssorts);
|
||||
|
||||
var flatAssorts = AssortMerger.CreateMergedFlattenedAssorts(trader.Key.ToString(), flattenedLiveAssorts, flattenedExistingAssorts);
|
||||
|
||||
var result = CreateMergedFlattenedAssorts(trader.Key.ToString(), flattenedLiveAssorts, flattenedExistingAssorts);
|
||||
|
||||
Assort unflattenedAssorts = AssortFlattener.UnFlatten(flatAssorts);
|
||||
JsonWriter.WriteJson(unflattenedAssorts, traderId, Directory.GetCurrentDirectory(), "assort");
|
||||
|
||||
// generate trader specific assort quest data, write out to file
|
||||
var questAssorts = QuestHelper.CreateQuestAssortsList(traderAssortData);
|
||||
@ -44,78 +45,6 @@ class Program
|
||||
}
|
||||
}
|
||||
|
||||
private static List<FlatAssort> CreateMergedFlattenedAssorts(string trader, List<FlatAssort> flattenedLiveAssorts, List<FlatAssort> flattenedExistingAssorts)
|
||||
{
|
||||
var completeAssorts = new List<FlatAssort>();
|
||||
|
||||
// Add live assorts
|
||||
foreach (var liveAssort in flattenedLiveAssorts)
|
||||
{
|
||||
completeAssorts.Add(liveAssort);
|
||||
}
|
||||
LoggingHelpers.LogSuccess($"{trader} Added {flattenedLiveAssorts.Count} items from live");
|
||||
|
||||
|
||||
// Check for missing existing assorts and add those
|
||||
var ExistingItemCount = 0;
|
||||
foreach (var existingAssort in flattenedExistingAssorts)
|
||||
{
|
||||
var matchInCompleteAssorts = GetMatchingAssortFromCompleteList(trader, existingAssort, completeAssorts);
|
||||
if (matchInCompleteAssorts is null)
|
||||
{
|
||||
// no assort found, add
|
||||
LoggingHelpers.LogWarning($"{trader} Adding Item found in existing assorts but not live: {existingAssort.ItemId} {existingAssort.ItemName} Level: {existingAssort.Level}");
|
||||
completeAssorts.Add(existingAssort);
|
||||
ExistingItemCount++;
|
||||
}
|
||||
}
|
||||
|
||||
LoggingHelpers.LogSuccess($"{trader} Added {ExistingItemCount} existing items");
|
||||
return completeAssorts;
|
||||
}
|
||||
|
||||
private static FlatAssort GetMatchingAssortFromCompleteList(string traderName, FlatAssort assortToFind, List<FlatAssort> completeAssorts)
|
||||
{
|
||||
var existingAssort = completeAssorts.Where(x => x.ItemId == assortToFind.ItemId
|
||||
&& x.Level == assortToFind.Level);
|
||||
|
||||
// check only one item found
|
||||
if (existingAssort?.Count() == 1)
|
||||
{
|
||||
//LoggingHelpers.LogSuccess($"{traderName} match found for item: {assortToFind.ItemId} {assortToFind.ItemName} Level: {assortToFind.Level}");
|
||||
return existingAssort.First();
|
||||
}
|
||||
|
||||
if (existingAssort?.Count() > 1)
|
||||
{
|
||||
// try and get it by money
|
||||
existingAssort = completeAssorts.Where( x=> x.ItemId == assortToFind.ItemId
|
||||
&& x.Level == assortToFind.Level
|
||||
&& x.IsMoney == assortToFind.IsMoney);
|
||||
|
||||
if (existingAssort?.Count() == 1)
|
||||
{
|
||||
return existingAssort.First();
|
||||
}
|
||||
if (existingAssort?.Count() > 1)
|
||||
{
|
||||
existingAssort = completeAssorts.Where(x => x.ItemId == assortToFind.ItemId
|
||||
&& x.Level == assortToFind.Level
|
||||
&& x.IsMoney == assortToFind.IsMoney
|
||||
&& x.SubItems.Count == assortToFind.SubItems.Count
|
||||
&& x.BarterDetails[0].count == assortToFind.BarterDetails[0].count);
|
||||
|
||||
if ( existingAssort?.Count() == 1)
|
||||
{
|
||||
return existingAssort.First();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//LoggingHelpers.LogError($"{traderName} No match found for item: {assortToFind.ItemId} {assortToFind.ItemName} Level: {assortToFind.Level}");
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void LogItemsMissingInExistingAssorts(string traderName, List<AssortFlattener.FlatAssort> flattenedExistingAssorts, List<AssortFlattener.FlatAssort> flattenedLiveAssorts)
|
||||
{
|
||||
foreach (var liveAssort in flattenedLiveAssorts)
|
||||
|
@ -77,6 +77,8 @@ namespace AssortValidator.Common
|
||||
|
||||
public static bool IsMoney(string tplId)
|
||||
{
|
||||
return GetTemplateById(tplId)._parent == "543be5dd4bdc2deb348b4569"; // money type
|
||||
|
||||
if (tplId == "5449016a4bdc2d6f028b456f")
|
||||
{
|
||||
return true;
|
||||
|
@ -261,7 +261,20 @@ namespace AssortValidator.Common.Helpers
|
||||
};
|
||||
private static Dictionary<string, Quest> _liveQuestData;
|
||||
|
||||
public static Dictionary<string, Quest> GetQuestData(string filename = "resp.client.quest.list")
|
||||
public static Dictionary<string, Quest> GetQuestDataFromDump(string filename = "resp.client.quest.list")
|
||||
{
|
||||
if (_liveQuestData == null)
|
||||
{
|
||||
var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains(filename));
|
||||
var questDataJson = File.ReadAllText(questFilePath);
|
||||
var rawRootData = JsonSerializer.Deserialize<QuestRoot>(questDataJson).data;
|
||||
_liveQuestData = rawRootData.ToDictionary(x => x._id, y => y);
|
||||
}
|
||||
|
||||
return _liveQuestData;
|
||||
}
|
||||
|
||||
public static Dictionary<string, Quest> GetQuestData(string filename = "quest")
|
||||
{
|
||||
if (_liveQuestData == null)
|
||||
{
|
||||
@ -294,7 +307,6 @@ namespace AssortValidator.Common.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,13 @@ namespace AssortValidator.Common.Models
|
||||
|
||||
public class Assort
|
||||
{
|
||||
public Assort()
|
||||
{
|
||||
items = new List<Item>();
|
||||
barter_scheme = new Dictionary<string, List<List<BarterDetails>>>();
|
||||
loyal_level_items = new Dictionary<string, int>();
|
||||
}
|
||||
|
||||
public int nextResupply { get; set; }
|
||||
public List<Item> items { get; set; }
|
||||
public Dictionary<string, List<List<BarterDetails>>> barter_scheme { get; set; }
|
||||
@ -36,8 +43,9 @@ namespace AssortValidator.Common.Models
|
||||
public class Upd
|
||||
{
|
||||
public int? BuyRestrictionMax { get; set; }
|
||||
public int BuyRestrictionCurrent { get; set; }
|
||||
public int StackObjectsCount { get; set; }
|
||||
public int? BuyRestrictionCurrent { get; set; }
|
||||
public int? StackObjectsCount { get; set; }
|
||||
public bool? UnlimitedCount { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user