refactor and cleanup
This commit is contained in:
parent
86e687e859
commit
702cbf4b8c
@ -51,6 +51,9 @@ namespace AssortUpdater
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn bsg format into a flat list of assorts that are easier to work with
|
||||
/// </summary>
|
||||
public static List<FlatAssort> FlattenLiveAssorts(Assort liveAssorts)
|
||||
{
|
||||
var results = new List<FlatAssort>();
|
||||
@ -95,6 +98,9 @@ namespace AssortUpdater
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn flattened assorts list into bsg format
|
||||
/// </summary>
|
||||
public static Assort UnFlatten(List<FlatAssort> flatAssorts)
|
||||
{
|
||||
var result = new Assort();
|
||||
|
@ -42,13 +42,13 @@ class Program
|
||||
Assort unflattenedAssorts = AssortFlattener.UnFlatten(flatAssorts);
|
||||
JsonWriter.WriteJson(unflattenedAssorts, traderId, Directory.GetCurrentDirectory(), "assort");
|
||||
|
||||
var questAssorts = QuestHelper.CreateQuestAssortsList(trader.Key, traderQuestAssortUnlocks, flatAssorts);
|
||||
var questAssorts = QuestAssortGenerator.CreateQuestAssorts(trader.Key, traderQuestAssortUnlocks, flatAssorts);
|
||||
LogQuestUnlocks(questAssorts, unflattenedAssorts);
|
||||
JsonWriter.WriteJson(questAssorts, traderId, Directory.GetCurrentDirectory(), "questassort");
|
||||
}
|
||||
}
|
||||
|
||||
private static void LogQuestUnlocks(QuestHelper.QuestAssorts questAssorts, Assort unflattenedAssorts)
|
||||
private static void LogQuestUnlocks(QuestAssorts questAssorts, Assort unflattenedAssorts)
|
||||
{
|
||||
foreach (var item in questAssorts.success)
|
||||
{
|
||||
|
99
AssortUpdater/QuestAssortGenerator.cs
Normal file
99
AssortUpdater/QuestAssortGenerator.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using AssortValidator.Common.Helpers;
|
||||
using AssortValidator.Common.Helpers.Models;
|
||||
using AssortValidator.Common.Models;
|
||||
|
||||
namespace AssortUpdater
|
||||
{
|
||||
public static class QuestAssortGenerator
|
||||
{
|
||||
public static QuestAssorts CreateQuestAssorts(Trader trader, IEnumerable<QuestAssortUnlock> questAssortData, List<FlatAssort> flatAssorts)
|
||||
{
|
||||
var result = new QuestAssorts();
|
||||
int count = 1;
|
||||
foreach (var questAssortUnlock in questAssortData)
|
||||
{
|
||||
// find assort by item tpl and level
|
||||
IEnumerable<FlatAssort> associatedAssort = flatAssorts.Where(x => x.ItemId == questAssortUnlock.AssortItems[0]._tpl
|
||||
&& x.Level == questAssortUnlock.LoyaltyLevel);
|
||||
|
||||
// no assort found
|
||||
if (associatedAssort?.Any() != true)
|
||||
{
|
||||
// Add a filler item
|
||||
result.success.Add($"MISSING{count}", questAssortUnlock.QuestId);
|
||||
count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// One match found, woo yeah
|
||||
if (associatedAssort.Count() == 1)
|
||||
{
|
||||
result.success.Add(associatedAssort.Single().AssortId, questAssortUnlock.QuestId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// multiple found, use hand-made data from QuestAssortMappingHelper
|
||||
if (associatedAssort.Count() > 1)
|
||||
{
|
||||
var matchingAssort = GetMatchingAssortUsingManualMapping(trader, associatedAssort, questAssortUnlock);
|
||||
if (matchingAssort.Count == 1)
|
||||
{
|
||||
result.success.Add(matchingAssort.Single().AssortId, questAssortUnlock.QuestId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (matchingAssort.Count == 0)
|
||||
{
|
||||
result.success.Add($"none found {count}", questAssortUnlock.QuestId);
|
||||
count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
result.success.Add($"too many {count}", questAssortUnlock.QuestId);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<FlatAssort> GetMatchingAssortUsingManualMapping(Trader trader, IEnumerable<FlatAssort> possibleAssorts, QuestAssortUnlock questToFindAssortFor)
|
||||
{
|
||||
var assorts = new List<FlatAssort>();
|
||||
|
||||
// Get manually made mappings to help us find the assort we want
|
||||
var manualAssortMappings = QuestAssortMappingHelper.GetQuestAssortMappingDetails(questToFindAssortFor.QuestId);
|
||||
manualAssortMappings = manualAssortMappings.Where(x => x.Trader == trader
|
||||
&& x.ItemTplId == questToFindAssortFor.AssortTemplateId
|
||||
&& x.Level == questToFindAssortFor.LoyaltyLevel).ToList();
|
||||
|
||||
// there may be multiple mappings for a quest, try and filter it down by subitem count
|
||||
QuestAssortMapping singleMapping;
|
||||
if (manualAssortMappings.Count != 1)
|
||||
{
|
||||
singleMapping = manualAssortMappings.Single(x => (x.SubItemCount ?? 0) == questToFindAssortFor.AssortItems.Count - 1); // remove base item from count
|
||||
}
|
||||
else
|
||||
{
|
||||
singleMapping = manualAssortMappings[0];
|
||||
}
|
||||
|
||||
// Find matching assort
|
||||
assorts = possibleAssorts.Where(x => x.IsMoney == singleMapping.IsMoneyBarter
|
||||
&& trader == singleMapping.Trader
|
||||
&& x.Level == singleMapping.Level
|
||||
&& x.RawItem._tpl == singleMapping.ItemTplId).ToList();
|
||||
|
||||
// Filter assort on subitem count
|
||||
if (assorts.Count > 1)
|
||||
{
|
||||
assorts = assorts.Where(x => x.SubItems.Count == singleMapping.SubItemCount).ToList();
|
||||
}
|
||||
|
||||
// Hopefully just one
|
||||
return assorts;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -261,14 +261,16 @@ namespace AssortValidator.Common.Helpers
|
||||
{ "6179afd0bca27a099552e040", "Lost Contact"},
|
||||
{ "613708a7f8333a5d15594368", "Action Test"}
|
||||
};
|
||||
private static Dictionary<string, Quest> _liveQuestData;
|
||||
|
||||
public static Quest GetQuestById(string questId)
|
||||
{
|
||||
return _liveQuestData[questId];
|
||||
}
|
||||
|
||||
private static Dictionary<string, Quest> _liveQuestData;
|
||||
|
||||
/// <summary>
|
||||
/// use when the quest data is in bsgs format
|
||||
/// </summary>
|
||||
public static Dictionary<string, Quest> GetQuestDataFromDump(string filename = "resp.client.quest.list")
|
||||
{
|
||||
if (_liveQuestData == null)
|
||||
@ -282,6 +284,9 @@ namespace AssortValidator.Common.Helpers
|
||||
return _liveQuestData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// use when the qeust data is in spt format
|
||||
/// </summary>
|
||||
public static Dictionary<string, Quest> GetQuestData(string filename = "quest")
|
||||
{
|
||||
if (_liveQuestData == null)
|
||||
@ -294,6 +299,9 @@ namespace AssortValidator.Common.Helpers
|
||||
return _liveQuestData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of quests and their associated assort item unlocks
|
||||
/// </summary>
|
||||
public static List<QuestAssortUnlock> GetQuestAssortUnlocks(IEnumerable<Quest> quests)
|
||||
{
|
||||
var results = new List<QuestAssortUnlock>();
|
||||
@ -310,7 +318,7 @@ namespace AssortValidator.Common.Helpers
|
||||
TraderType = TraderHelper.GetTraderTypeById(assortUnlockReward.traderId),
|
||||
AssortItems = assortUnlockReward.items,
|
||||
AssortTemplateId = assortUnlockReward.items[0]._tpl,
|
||||
LoyaltyLevel = assortUnlockReward.loyaltyLevel.GetValueOrDefault(1),
|
||||
LoyaltyLevel = assortUnlockReward.loyaltyLevel ?? 1,
|
||||
QuestState = "success"
|
||||
});
|
||||
}
|
||||
@ -319,109 +327,6 @@ namespace AssortValidator.Common.Helpers
|
||||
return results;
|
||||
}
|
||||
|
||||
public static QuestAssorts CreateQuestAssortsList(Trader trader, IEnumerable<QuestAssortUnlock> questAssortData, List<FlatAssort> flatAssorts)
|
||||
{
|
||||
var result = new QuestAssorts();
|
||||
int count = 1;
|
||||
foreach (var questAssortUnlock in questAssortData)
|
||||
{
|
||||
if (questAssortUnlock.QuestId == "5c0bbaa886f7746941031d82")
|
||||
{
|
||||
var x = 1;
|
||||
}
|
||||
|
||||
// find assort by item tpl and level
|
||||
IEnumerable<FlatAssort> associatedAssort = flatAssorts.Where(x => x.ItemId == questAssortUnlock.AssortItems[0]._tpl && x.Level == questAssortUnlock.LoyaltyLevel);
|
||||
|
||||
if (associatedAssort is null || !associatedAssort.Any())
|
||||
{
|
||||
result.success.Add($"MISSING{count}", questAssortUnlock.QuestId);
|
||||
count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// just one item found, woo yeah
|
||||
if (associatedAssort.Count() == 1)
|
||||
{
|
||||
result.success.Add(associatedAssort.Single().AssortId, questAssortUnlock.QuestId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// multiple found, use hand-made data from QuestAssortMappingHelper
|
||||
if (associatedAssort.Count() > 1)
|
||||
{
|
||||
var matchingAssort = GetMatchingAssortUsingManualMapping(trader, associatedAssort, questAssortUnlock);
|
||||
|
||||
if (matchingAssort.Count == 1)
|
||||
{
|
||||
result.success.Add(matchingAssort.Single().AssortId, questAssortUnlock.QuestId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (matchingAssort.Count == 0)
|
||||
{
|
||||
result.success.Add($"none found {Guid.NewGuid()}", questAssortUnlock.QuestId);
|
||||
continue;
|
||||
}
|
||||
|
||||
result.success.Add($"too many {Guid.NewGuid()}", questAssortUnlock.QuestId);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<FlatAssort> GetMatchingAssortUsingManualMapping(Trader trader, IEnumerable<FlatAssort> possibleAssorts, QuestAssortUnlock questToFindAssortFor)
|
||||
{
|
||||
var results = new List<FlatAssort>();
|
||||
|
||||
List<QuestAssortMapping> manualAssortMappings = QuestAssortMappingHelper.GetQuestAssortMappingDetails(questToFindAssortFor.QuestId);
|
||||
var mappings = manualAssortMappings.Where(x => x.Trader == trader
|
||||
&& x.ItemTplId == questToFindAssortFor.AssortTemplateId
|
||||
&& x.Level == questToFindAssortFor.LoyaltyLevel).ToList();
|
||||
QuestAssortMapping singleMapping;
|
||||
if (mappings.Count != 1)
|
||||
{
|
||||
// last resort, find by sub item count
|
||||
singleMapping = mappings.Single(x => (x.SubItemCount ?? 0) == questToFindAssortFor.AssortItems.Count - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
singleMapping = mappings[0];
|
||||
}
|
||||
|
||||
results = possibleAssorts.Where(x => x.IsMoney == singleMapping.IsMoneyBarter
|
||||
&& trader == singleMapping.Trader
|
||||
&& x.Level == singleMapping.Level
|
||||
&& x.RawItem._tpl == singleMapping.ItemTplId).ToList();
|
||||
|
||||
if (results.Any(x => x.AssortId == "61e0a291033bdc459438c2b7"))
|
||||
{
|
||||
var x = 2;
|
||||
}
|
||||
|
||||
if (results.Count > 1)
|
||||
{
|
||||
results = results.Where(x => x.SubItems.Count == singleMapping.SubItemCount).ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public class QuestAssorts
|
||||
{
|
||||
public QuestAssorts()
|
||||
{
|
||||
started = new Dictionary<string, string>();
|
||||
success = new Dictionary<string, string>();
|
||||
fail = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public Dictionary<string, string> started { get; set; }
|
||||
public Dictionary<string, string> success { get; set; }
|
||||
public Dictionary<string, string> fail { get; set; }
|
||||
}
|
||||
|
||||
private static string GetQuestNameById(string id)
|
||||
{
|
||||
if (questNames.ContainsKey(id))
|
||||
|
22
AssortValidator.Common/Models/QuestAssorts.cs
Normal file
22
AssortValidator.Common/Models/QuestAssorts.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AssortValidator.Common.Models
|
||||
{
|
||||
public class QuestAssorts
|
||||
{
|
||||
public QuestAssorts()
|
||||
{
|
||||
started = new Dictionary<string, string>();
|
||||
success = new Dictionary<string, string>();
|
||||
fail = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public Dictionary<string, string> started { get; set; }
|
||||
public Dictionary<string, string> success { get; set; }
|
||||
public Dictionary<string, string> fail { get; set; }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user