diff --git a/AssortGenerator.Common/Assets/missingTraderAssortPrices.json b/AssortGenerator.Common/Assets/missingTraderAssortPrices.json index b13787b..bcd60ea 100644 --- a/AssortGenerator.Common/Assets/missingTraderAssortPrices.json +++ b/AssortGenerator.Common/Assets/missingTraderAssortPrices.json @@ -152,5 +152,23 @@ "_tpl": "5449016a4bdc2d6f028b456f" } ] + }, + "64bd432d6de7c555ad051726": { + "questId": "64b907a85e9b86ab7a08cf0d", + "itemTpl": "5ac4cd105acfc40016339859", + "itemUpd": { + "BuyRestrictionMax": 2, + "StackObjectsCount": 40000 + }, + "barterScheme": [ + { + "count": 1, + "_tpl": "5d403f9186f7743cac3f229b" + }, + { + "count": 1, + "_tpl": "62a0a0bb621468534a797ad5" + } + ] } } \ No newline at end of file diff --git a/AssortGenerator.Common/Helpers/QuestHelper.cs b/AssortGenerator.Common/Helpers/QuestHelper.cs index 28610a0..e5ee6a9 100644 --- a/AssortGenerator.Common/Helpers/QuestHelper.cs +++ b/AssortGenerator.Common/Helpers/QuestHelper.cs @@ -1,6 +1,7 @@ using AssortGenerator.Models.Input; using AssortGenerator.Models.Other; using AssortGenerator.Models.Output; +using Common.Models; using System.Collections.Generic; using System.IO; using System.Linq; @@ -124,6 +125,7 @@ namespace AssortGenerator.Common.Helpers { public string questId { get; set; } public string itemTpl { get; set; } + public List items { get;set;} public Upd itemUpd { get; set; } public List barterScheme { get; set; } } diff --git a/AssortGenerator.Models/Output/AssortRoot.cs b/AssortGenerator.Models/Output/AssortRoot.cs index dacb358..d910b3d 100644 --- a/AssortGenerator.Models/Output/AssortRoot.cs +++ b/AssortGenerator.Models/Output/AssortRoot.cs @@ -27,6 +27,14 @@ namespace AssortGenerator.Models.Output public int? StackObjectsCount { get; set; } public object BuyRestrictionMax { get; set; } public int? BuyRestrictionCurrent { get; set; } + + public Repairable Repairable { get; set; } + } + + public class Repairable + { + public int Durability { get; set; } + public int MaxDurability { get; set; } } public class BarterObject diff --git a/AssortGenerator/Program.cs b/AssortGenerator/Program.cs index a864717..18b2416 100644 --- a/AssortGenerator/Program.cs +++ b/AssortGenerator/Program.cs @@ -169,28 +169,29 @@ namespace AssortGenerator } } - private static void AttemptToAddMissingQuestAssorts(AssortRoot outputAssortFile, QuestAssort questAssort, List missingQuestAssorts, Dictionary missingQuestAssortPrices) + private static void AttemptToAddMissingQuestAssorts( + AssortRoot outputAssortFile, + QuestAssort questAssort, + List missingQuestAssorts, + Dictionary missingQuestAssortPrices) { // iterate over each missing assort foreach (var missingQuestAssort in missingQuestAssorts) { // Single item, maybe we can add one in (skip complex items like guns/ammo boxes etc) - if (missingQuestAssort.Items.Count == 1) + var isSimpleItem = missingQuestAssort.Items.Count == 1; + + if (outputAssortFile.items.Any(x => x._id == missingQuestAssort.Items[0]._id)) { - // Check isn't a weapon - var itemTemplate = ItemTemplateHelper.GetTemplateById(missingQuestAssort.Items[0]._tpl); - if (itemTemplate._parent == "5447b5f14bdc2d61278b4567") - { - continue; - } - - if (outputAssortFile.items.Any(x => x._id == missingQuestAssort.Items[0]._id)) - { - LoggingHelpers.LogError("OH NO, DUPE ID FOUND"); - } + LoggingHelpers.LogError("OH NO, DUPE ID FOUND"); + } + // Find price data + var hasPriceData = missingQuestAssortPrices.TryGetValue(missingQuestAssort.AssortUnlockId, out var priceData); + if (isSimpleItem) + { // We can add it - var item = new Item + var itemToAdd = new Item { _tpl = missingQuestAssort.Items[0]._tpl, _id = missingQuestAssort.Items[0]._id, @@ -198,45 +199,98 @@ namespace AssortGenerator slotId = "hideout" }; - var questAssortPriceData = missingQuestAssortPrices.TryGetValue(missingQuestAssort.AssortUnlockId, out var value); - if (questAssortPriceData && value.itemTpl == missingQuestAssort.Items[0]._tpl) + // Set stack/buy max counts + if (hasPriceData && priceData.itemTpl == missingQuestAssort.Items[0]._tpl) { - item.upd = value.itemUpd; + itemToAdd.upd = priceData.itemUpd; } else { - item.upd = new Upd() { StackObjectsCount = 10 }; + itemToAdd.upd = new Upd() { StackObjectsCount = 10 }; } - outputAssortFile.items.Add(item); + outputAssortFile.items.Add(itemToAdd); + } + else + { + // multi-item assort! + var itemsToAdd = ConvertRewardToItems(missingQuestAssort.Items); - var barterItemListInner = new List(); - - if (questAssortPriceData && value.itemTpl == missingQuestAssort.Items[0]._tpl) + // Set stack/buy max counts + if (hasPriceData && priceData.itemTpl == missingQuestAssort.Items[0]._tpl) { - barterItemListInner.AddRange(value.barterScheme); + if (itemsToAdd.First().upd == null) + { + itemsToAdd.First().upd = new Upd(); + } + if (priceData.itemUpd.StackObjectsCount.HasValue) + { + itemsToAdd.First().upd.StackObjectsCount = priceData.itemUpd.StackObjectsCount.Value; + } + if (priceData.itemUpd.BuyRestrictionMax != null) + { + itemsToAdd.First().upd.BuyRestrictionMax = ((JsonElement)priceData.itemUpd.BuyRestrictionMax).GetInt32(); + itemsToAdd.First().upd.BuyRestrictionCurrent = 0; + } } else { - barterItemListInner.Add(new BarterObject() { _tpl = "5449016a4bdc2d6f028b456f", count = 25000 }); + // no value in json, set stack count to 10 + itemsToAdd.First().upd.StackObjectsCount = 10; } - var barterItemListOuter = new List> { barterItemListInner }; - outputAssortFile.barter_scheme.Add(missingQuestAssort.Items[0]._id, barterItemListOuter); + outputAssortFile.items.AddRange(itemsToAdd); + } - outputAssortFile.loyal_level_items[missingQuestAssort.Items[0]._id] = missingQuestAssort.LoyaltyLevel; + var barterItemListInner = new List(); + if (hasPriceData && priceData.itemTpl == missingQuestAssort.Items[0]._tpl) + { + barterItemListInner.AddRange(priceData.barterScheme); + } + else + { + barterItemListInner.Add(new BarterObject() { _tpl = "5449016a4bdc2d6f028b456f", count = 25000 }); + } - 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} assort with placeholder"); - questAssort.success.Remove(associatedQuestAssort.Key); - questAssort.success.Add(missingQuestAssort.Items[0]._id, missingQuestAssort.QuestId); - } + var barterItemListOuter = new List> { barterItemListInner }; + outputAssortFile.barter_scheme.Add(missingQuestAssort.Items[0]._id, barterItemListOuter); + + outputAssortFile.loyal_level_items[missingQuestAssort.Items[0]._id] = missingQuestAssort.LoyaltyLevel; + + 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} assort with placeholder"); + questAssort.success.Remove(associatedQuestAssort.Key); + questAssort.success.Add(missingQuestAssort.Items[0]._id, missingQuestAssort.QuestId); } } } + private static IEnumerable ConvertRewardToItems(List rewardToConvert) + { + var output = new List(); + foreach (var rewardItem in rewardToConvert) + { + var item = new Item() + { + _id = rewardItem._id, + _tpl = rewardItem._tpl, + parentId = rewardItem.parentId ?? "hideout", + slotId = rewardItem.slotId ?? "hideout" + }; + + if (rewardItem.upd != null) + { + item.upd = (Upd)((JsonElement)rewardItem.upd).Deserialize(typeof(Upd)); + } + + output.Add(item); + } + + return output; + } + private static void UpdateQuestAssortUnlockIds(string traderId, QuestAssort traderQuestAssort, Dictionary finalisedQuestData, AssortRoot traderAssortRoot) { var alreadyMatchedAssortIds = new List();