Refactor
This commit is contained in:
parent
75679d9974
commit
bee8f35955
@ -24,34 +24,27 @@ namespace AssortGenerator
|
|||||||
foreach (var trader in TraderHelper.GetTraders())
|
foreach (var trader in TraderHelper.GetTraders())
|
||||||
{
|
{
|
||||||
// Get relevant trader dump
|
// Get relevant trader dump
|
||||||
var assortDumpPath = traderAssortFilePaths.Find(x => x.Contains(trader.Value));
|
var assortDumpPath = traderAssortFilePaths.Find(x => x.Contains($"getTraderAssort.{trader.Value}"));
|
||||||
|
|
||||||
// convert input dump json into object
|
// Convert input dump json into object
|
||||||
var json = File.ReadAllText(assortDumpPath);
|
var json = File.ReadAllText(assortDumpPath);
|
||||||
var jsonObject = JsonDocument.Parse(json);
|
var jsonObject = JsonDocument.Parse(json);
|
||||||
|
|
||||||
// find root data node
|
// Find root data node
|
||||||
var data = jsonObject.RootElement.GetProperty("data");
|
var data = jsonObject.RootElement.GetProperty("data");
|
||||||
|
|
||||||
// find items node and parse into object
|
// Find assort items node and parse into list
|
||||||
string itemsJson = data.GetProperty("items").ToString();
|
string itemsJson = data.GetProperty("items").ToString();
|
||||||
List<Item> items = JsonSerializer.Deserialize<List<Item>>(itemsJson);
|
List<Item> items = JsonSerializer.Deserialize<List<Item>>(itemsJson);
|
||||||
|
|
||||||
// fix items that have ran out of stock in the dump and give it some default values
|
// Fix items that have ran out of stock in the dump and give stack size
|
||||||
foreach (var item in items)
|
FixZeroSizedStackAssorts(items, 100);
|
||||||
{
|
|
||||||
if (item.upd?.StackObjectsCount == 0 && item.slotId == "hideout")
|
|
||||||
{
|
|
||||||
LoggingHelpers.LogError($"item {item._tpl} found with stack count of 0, changing to 100");
|
|
||||||
item.upd.StackObjectsCount = 100;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find barter scheme node and parse into object
|
// Find barter scheme node and parse into dictionary
|
||||||
var barterSchemeJson = data.GetProperty("barter_scheme").ToString();
|
var barterSchemeJson = data.GetProperty("barter_scheme").ToString();
|
||||||
var barterSchemeItems = JsonSerializer.Deserialize<Dictionary<string, object>>(barterSchemeJson);
|
var barterSchemeItems = JsonSerializer.Deserialize<Dictionary<string, object>>(barterSchemeJson);
|
||||||
|
|
||||||
// Find loyalty level node and parse into object
|
// Find loyalty level node and parse into dictionary
|
||||||
var loyaltyLevelItemsJson = data.GetProperty("loyal_level_items").ToString();
|
var loyaltyLevelItemsJson = data.GetProperty("loyal_level_items").ToString();
|
||||||
var loyaltyLevelItems = JsonSerializer.Deserialize<Dictionary<string, int>>(loyaltyLevelItemsJson);
|
var loyaltyLevelItems = JsonSerializer.Deserialize<Dictionary<string, int>>(loyaltyLevelItemsJson);
|
||||||
|
|
||||||
@ -59,6 +52,19 @@ namespace AssortGenerator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void FixZeroSizedStackAssorts(List<Item> items, int defaultStackSize)
|
||||||
|
{
|
||||||
|
foreach (var item in items
|
||||||
|
.Where(item => item.upd?.StackObjectsCount == 0 && item.slotId == "hideout"))
|
||||||
|
{
|
||||||
|
LoggingHelpers.LogError($"item {item._tpl} found with stack count of 0, changing to {defaultStackSize}");
|
||||||
|
item.upd.StackObjectsCount = defaultStackSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create input/assorts/output/traders folders
|
||||||
|
/// </summary>
|
||||||
private static string CreateWorkingFolders()
|
private static string CreateWorkingFolders()
|
||||||
{
|
{
|
||||||
var workingPath = Directory.GetCurrentDirectory();
|
var workingPath = Directory.GetCurrentDirectory();
|
||||||
@ -81,6 +87,11 @@ namespace AssortGenerator
|
|||||||
return assortsPath;
|
return assortsPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parse raw tradersettings dump file into BaseRoot object
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filesInAssortsFolder">list of file paths</param>
|
||||||
|
/// <returns>BaseRoot</returns>
|
||||||
private static BaseRoot GetTraderData(IEnumerable<string> filesInAssortsFolder)
|
private static BaseRoot GetTraderData(IEnumerable<string> filesInAssortsFolder)
|
||||||
{
|
{
|
||||||
var traderDataPath = filesInAssortsFolder.FirstOrDefault(x => x.Contains("resp.client.trading.api.traderSettings"));
|
var traderDataPath = filesInAssortsFolder.FirstOrDefault(x => x.Contains("resp.client.trading.api.traderSettings"));
|
||||||
@ -88,7 +99,8 @@ namespace AssortGenerator
|
|||||||
return JsonSerializer.Deserialize<BaseRoot>(traderDataJson);
|
return JsonSerializer.Deserialize<BaseRoot>(traderDataJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteOutputFilesForTrader(KeyValuePair<Trader, string> trader,
|
private static void WriteOutputFilesForTrader(
|
||||||
|
KeyValuePair<Trader, string> trader,
|
||||||
List<Item> items,
|
List<Item> items,
|
||||||
Dictionary<string, object>
|
Dictionary<string, object>
|
||||||
barterSchemeItems,
|
barterSchemeItems,
|
||||||
@ -99,7 +111,7 @@ namespace AssortGenerator
|
|||||||
var traderData = GetTraderData(InputFileHelper.GetInputFilePaths());
|
var traderData = GetTraderData(InputFileHelper.GetInputFilePaths());
|
||||||
var traderFolderPath = $"traders\\{trader.Value}";
|
var traderFolderPath = $"traders\\{trader.Value}";
|
||||||
|
|
||||||
// create assort file, serialise into json and save into output folder
|
// Create assort file, serialise into json and save into output folder
|
||||||
var outputAssortFile = new AssortRoot
|
var outputAssortFile = new AssortRoot
|
||||||
{
|
{
|
||||||
items = items,
|
items = items,
|
||||||
@ -118,66 +130,106 @@ namespace AssortGenerator
|
|||||||
// create suits file for ragman
|
// create suits file for ragman
|
||||||
if (trader.Key == Trader.Ragman)
|
if (trader.Key == Trader.Ragman)
|
||||||
{
|
{
|
||||||
var customisationFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains("resp.client.trading.customization"));
|
CreateRagmanSuitsFile(workingPath, traderFolderPath);
|
||||||
var traderDataJson = File.ReadAllText(customisationFilePath);
|
|
||||||
var suitData = JsonSerializer.Deserialize<CustomisationRoot>(traderDataJson);
|
|
||||||
|
|
||||||
var outputSuitData = new List<Suit>();
|
|
||||||
outputSuitData.AddRange(suitData.data);
|
|
||||||
|
|
||||||
JsonWriter.WriteJson(outputSuitData, traderFolderPath, workingPath, "suits");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// merges bear and usec ragman clothing dumps into one file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="trader"></param>
|
||||||
|
/// <param name="workingPath"></param>
|
||||||
|
/// <param name="traderFolderPath"></param>
|
||||||
|
private static void CreateRagmanSuitsFile(string workingPath, string traderFolderPath)
|
||||||
|
{
|
||||||
|
var suitFileNames = new List<string>();
|
||||||
|
suitFileNames.Add("usec.resp.client.trading.customization.");
|
||||||
|
suitFileNames.Add("bear.resp.client.trading.customization.");
|
||||||
|
var outputSuitData = new List<Suit>();
|
||||||
|
foreach (var suitSideFilename in suitFileNames)
|
||||||
|
{
|
||||||
|
var customisationFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains(suitSideFilename));
|
||||||
|
if (string.IsNullOrEmpty(customisationFilePath))
|
||||||
|
{
|
||||||
|
LoggingHelpers.LogWarning($"no suit file found: {suitSideFilename}, skipped");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var traderDataJson = File.ReadAllText(customisationFilePath);
|
||||||
|
if (traderDataJson != null)
|
||||||
|
{
|
||||||
|
var suitData = JsonSerializer.Deserialize<CustomisationRoot>(traderDataJson);
|
||||||
|
outputSuitData.AddRange(suitData.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonWriter.WriteJson(outputSuitData, traderFolderPath, workingPath, "suits");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create quest assort file that links quest completions to trader assort unlocks
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="trader"></param>
|
||||||
|
/// <param name="assortRoot"></param>
|
||||||
|
/// <returns></returns>
|
||||||
private static QuestAssort GenerateQuestAssort(Trader trader, AssortRoot assortRoot)
|
private static QuestAssort GenerateQuestAssort(Trader trader, AssortRoot assortRoot)
|
||||||
{
|
{
|
||||||
var result = new QuestAssort();
|
var result = new QuestAssort();
|
||||||
var questData = QuestHelper.GetQuestData();
|
var questData = QuestHelper.GetQuestData();
|
||||||
|
|
||||||
// Find assortunlocks
|
// Find assort unlocks
|
||||||
List<AssortUnlocks> assortUnlocks = QuestHelper.GetAssortUnlocks();
|
List<AssortUnlocks> assortUnlocks = QuestHelper.GetAssortUnlocks();
|
||||||
List<string> assortItemsThatMatchBlackList = new List<string>(); // store items already matched here
|
var assortItemsThatMatchBlackList = new List<string>(); // store items already matched here
|
||||||
// TODO: find out how the fuck the assort unlock is associated to the quest
|
// TODO: find out how the fuck the assort unlock is associated to the quest
|
||||||
foreach (var assortUnlock in assortUnlocks.Where(x => x.TraderType == trader))
|
foreach (var assortUnlock in assortUnlocks.Where(x => x.TraderType == trader))
|
||||||
{
|
{
|
||||||
// Get unlock items name
|
if (assortUnlock.AssortUnlockId == "5ac653ed86f77405d4729344")
|
||||||
var assortItemName = ItemTemplateHelper.Items.FirstOrDefault(x=> x.Key == assortUnlock.ItemUnlockedTemplateId).Value._name;
|
{
|
||||||
|
var x = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get unlock items name
|
||||||
|
var assortItemName = ItemTemplateHelper.Items
|
||||||
|
.FirstOrDefault(x=> x.Key == assortUnlock.ItemUnlockedTemplateId).Value._name;
|
||||||
|
|
||||||
// TODO: handle started
|
// TODO: handle started
|
||||||
// TODO: handle fail
|
// TODO: handle fail
|
||||||
|
|
||||||
// handle quest success for now
|
// Handle quest success for now
|
||||||
if (assortUnlock.Criteria == "Success")
|
if (assortUnlock.Criteria.ToLower() == "success")
|
||||||
{
|
{
|
||||||
//Find assorts that match the quest unlocks item template
|
//Find assorts that match the quest unlocks item template
|
||||||
List<Item> assortItemsThatMatch = assortRoot.items.Where(x => x._tpl == assortUnlock.ItemUnlockedTemplateId).ToList();
|
List<Item> assortItemsThatMatch = assortRoot.items
|
||||||
|
.Where(x => x._tpl == assortUnlock.ItemUnlockedTemplateId && x.slotId == "hideout")
|
||||||
|
.ToList();
|
||||||
|
|
||||||
// no assort found for this unlock, log and skip it
|
// No assort found for this unlock, log and skip it
|
||||||
if (assortItemsThatMatch == null || assortItemsThatMatch.Count == 0)
|
if (assortItemsThatMatch == null || assortItemsThatMatch.Count == 0)
|
||||||
{
|
{
|
||||||
LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no assort item found. ({assortItemName})");
|
LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no assort item found. ({assortItemName})");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over assorts that match. goal is to find assort that fits the best (traders assort has same loyalty level unlock as quest expects)
|
// Iterate over assorts that match. goal is to find assort that fits the best
|
||||||
|
// (assort has same loyalty level unlock as quest expects)
|
||||||
string assortIdUnlockedByQuest = string.Empty;
|
string assortIdUnlockedByQuest = string.Empty;
|
||||||
foreach (var match in assortItemsThatMatch)
|
foreach (var match in assortItemsThatMatch)
|
||||||
{
|
{
|
||||||
// Look up item in Loyalty Level array
|
// Look up item in Loyalty Level array
|
||||||
var associatedLoyaltyLevelItem = assortRoot.loyal_level_items.FirstOrDefault(x => x.Key == match._id);
|
var associatedLoyaltyLevelItem = assortRoot.loyal_level_items
|
||||||
|
.FirstOrDefault(x => x.Key == match._id);
|
||||||
|
|
||||||
if (associatedLoyaltyLevelItem.Key == null)
|
if (associatedLoyaltyLevelItem.Key == null)
|
||||||
{
|
{
|
||||||
// end loop if no record found in loyalty level array
|
// Skip item if no record found in loyalty level array
|
||||||
LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no loyalty record found. ({assortItemName})");
|
LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. no loyalty record found. ");
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (associatedLoyaltyLevelItem.Value != assortUnlock.LoyaltyLevel)
|
if (associatedLoyaltyLevelItem.Value != assortUnlock.LoyaltyLevel)
|
||||||
{
|
{
|
||||||
// loyalty level is different to what was expected, skip and try next
|
// Loyalty level is different to what was expected, skip and try next
|
||||||
LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no match found in LL array. expected LL{associatedLoyaltyLevelItem.Value}. found: LL{assortUnlock.LoyaltyLevel}. ({assortItemName})");
|
LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. no match found in LL array. expected LL{associatedLoyaltyLevelItem.Value}. found: LL{assortUnlock.LoyaltyLevel}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,21 +247,32 @@ namespace AssortGenerator
|
|||||||
assortIdUnlockedByQuest = associatedLoyaltyLevelItem.Key;
|
assortIdUnlockedByQuest = associatedLoyaltyLevelItem.Key;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.success.ContainsKey(assortIdUnlockedByQuest))
|
if (result.success.ContainsKey(assortIdUnlockedByQuest))
|
||||||
{
|
{
|
||||||
LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. ALREADY EXISTS. SKIPPING. ({assortItemName})");
|
LoggingHelpers.LogWarning($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. ALREADY EXISTS. SKIPPING");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (assortIdUnlockedByQuest == string.Empty)
|
if (assortIdUnlockedByQuest.Length == 0)
|
||||||
{
|
{
|
||||||
LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. no assortId found. ({assortItemName})");
|
LoggingHelpers.LogError($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. no assortId found");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoggingHelpers.LogSuccess($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId}. questId: {assortUnlock.QuestId}. ADDING TO QUEST-ASSORT. ({assortItemName})");
|
LoggingHelpers.LogSuccess($"{trader} item templateId: {assortUnlock.ItemUnlockedTemplateId} ({assortItemName}). questId: {assortUnlock.QuestId}. ADDING TO QUEST-ASSORT");
|
||||||
result.success.Add(assortIdUnlockedByQuest, assortUnlock.QuestId);
|
result.success.Add(assortIdUnlockedByQuest, assortUnlock.QuestId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (assortUnlock.Criteria.ToLower() == "fail")
|
||||||
|
{
|
||||||
|
LoggingHelpers.LogError("Fail quest criteria not handled");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (assortUnlock.Criteria.ToLower() == "started")
|
||||||
|
{
|
||||||
|
LoggingHelpers.LogError("started quest criteria not handled");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user