From 711f18fb5716be356019716f534b646a03b7a4ea Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 6 Feb 2024 14:50:28 +0000 Subject: [PATCH] Update generator to check if missing quest assort is a preset then read it from globals.json and add that instead --- .../Helpers/PresetHelper.cs | 36 +++++++++++ AssortGenerator/Program.cs | 59 ++++++++++++++++++- 2 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 AssortGenerator.Common/Helpers/PresetHelper.cs diff --git a/AssortGenerator.Common/Helpers/PresetHelper.cs b/AssortGenerator.Common/Helpers/PresetHelper.cs new file mode 100644 index 0000000..65fb2e6 --- /dev/null +++ b/AssortGenerator.Common/Helpers/PresetHelper.cs @@ -0,0 +1,36 @@ +using AssortGenerator.Models.Input; +using AssortGenerator.Models.Other; +using AssortGenerator.Models.Output;using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.Json; + +namespace AssortGenerator.Common.Helpers +{ + public static class PresetHelper + { + private static Dictionary _presetData; + public static List GetDefaultPreset(string tpl) + { + if (_presetData == null) + { + var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains("globals")); + var questDataJson = File.ReadAllText(questFilePath); + _presetData = JsonSerializer.Deserialize(questDataJson).ItemPresets; + } + + return _presetData.FirstOrDefault(x => x.Value._encyclopedia == tpl).Value?._items; + } + } +} + +public class Globals +{ + public Dictionary ItemPresets { get; set; } +} + +public class GlobalPreset +{ + public string _encyclopedia { get; set; } + public List _items { get; set; } +} diff --git a/AssortGenerator/Program.cs b/AssortGenerator/Program.cs index ebc55d8..b686835 100644 --- a/AssortGenerator/Program.cs +++ b/AssortGenerator/Program.cs @@ -190,7 +190,7 @@ namespace AssortGenerator List missingQuestAssorts, Dictionary missingQuestAssortPrices) { - + var missingAssortDataWithNoFix = new List(); var questData = QuestHelper.GetFinalisedQuestData(); // iterate over each missing assort foreach (var missingQuestAssort in missingQuestAssorts) @@ -226,7 +226,37 @@ namespace AssortGenerator itemToAdd.upd = new Upd() { StackObjectsCount = 10 }; } - outputAssortFile.items.Add(itemToAdd); + var itemDefaultPreset = PresetHelper.GetDefaultPreset(missingQuestAssort.Items[0]._tpl); + if (itemDefaultPreset != null) + { + // Add upd data to preset before we add to assort data + itemDefaultPreset[0].upd = itemToAdd.upd; + itemDefaultPreset[0].parentId = itemToAdd.parentId; + itemDefaultPreset[0].slotId = itemToAdd.slotId; + + // Make ID match original data + var badIdWeNeedToChange = itemDefaultPreset[0]._id; + var goodId = missingQuestAssort.Items[0]._id; + foreach (var presetItem in itemDefaultPreset) + { + if (presetItem._id == badIdWeNeedToChange) + { + // Update root id + presetItem._id = goodId; + continue; + } + + if (presetItem.parentId == badIdWeNeedToChange) + { + presetItem.parentId = goodId; + } + } + outputAssortFile.items.AddRange(itemDefaultPreset); + } + else + { + outputAssortFile.items.Add(itemToAdd); + } } else { @@ -281,11 +311,34 @@ namespace AssortGenerator var associatedQuestAssort = questAssort.success.FirstOrDefault(x => x.Value == missingQuestAssort.QuestId && x.Key.StartsWith("UnknownAssortId")); if (associatedQuestAssort.Key != null) { - LoggingHelpers.LogWarning($"Able to replace missing quest: {missingQuestAssort.QuestId} {questData.FirstOrDefault(x => x.Key == missingQuestAssort.QuestId).Value.QuestName} assort with placeholder"); + LoggingHelpers.LogWarning($"Able to replace missing quest: ({missingQuestAssort.QuestId} {questData.FirstOrDefault(x => x.Key == missingQuestAssort.QuestId).Value.QuestName}) assort with placeholder"); questAssort.success.Remove(associatedQuestAssort.Key); questAssort.success.Add(missingQuestAssort.Items[0]._id, missingQuestAssort.QuestId); } + + if (!hasPriceData) + { + missingAssortDataWithNoFix.Add(missingQuestAssort); + } } + + var dict = new Dictionary(); + foreach (var item in missingAssortDataWithNoFix) + { + dict.Add(item.AssortUnlockId, new + { + questName = questData.FirstOrDefault(x => x.Key == item.QuestId).Value.QuestName, + questid = item.QuestId, + itemTpl = item.ItemUnlockedTemplateId, + itemUpd = new { + BuyRestrictionMax = 0, + StackObjectsCount = 100 + }, + barterScheme = new List { }, + }); + } + + JsonWriter.WriteJson(dict, "", Directory.GetCurrentDirectory(), "missingData"); } private static IEnumerable ConvertRewardToItems(List rewardToConvert)