Update generator to check if missing quest assort is a preset then read it from globals.json and add that instead

This commit is contained in:
Dev 2024-02-06 14:50:28 +00:00
parent a4a286bd33
commit 711f18fb57
2 changed files with 92 additions and 3 deletions

View File

@ -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<string, GlobalPreset> _presetData;
public static List<Item> GetDefaultPreset(string tpl)
{
if (_presetData == null)
{
var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains("globals"));
var questDataJson = File.ReadAllText(questFilePath);
_presetData = JsonSerializer.Deserialize<Globals>(questDataJson).ItemPresets;
}
return _presetData.FirstOrDefault(x => x.Value._encyclopedia == tpl).Value?._items;
}
}
}
public class Globals
{
public Dictionary<string, GlobalPreset> ItemPresets { get; set; }
}
public class GlobalPreset
{
public string _encyclopedia { get; set; }
public List<Item> _items { get; set; }
}

View File

@ -190,7 +190,7 @@ namespace AssortGenerator
List<AssortUnlocks> missingQuestAssorts,
Dictionary<string, MissingAssortPrice> missingQuestAssortPrices)
{
var missingAssortDataWithNoFix = new List<AssortUnlocks>();
var questData = QuestHelper.GetFinalisedQuestData();
// iterate over each missing assort
foreach (var missingQuestAssort in missingQuestAssorts)
@ -226,8 +226,38 @@ namespace AssortGenerator
itemToAdd.upd = new Upd() { StackObjectsCount = 10 };
}
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
{
// multi-item assort!
@ -281,13 +311,36 @@ 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<string, object>();
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<string> { },
});
}
JsonWriter.WriteJson(dict, "", Directory.GetCurrentDirectory(), "missingData");
}
private static IEnumerable<Item> ConvertRewardToItems(List<QuestRewardItem> rewardToConvert)
{
var output = new List<Item>();