Improve missing quest assort code to add complex items + add terragroup p6 quest assort item

This commit is contained in:
Dev 2023-08-09 18:56:10 +01:00
parent 4cb12456b4
commit 7348b8d336
4 changed files with 116 additions and 34 deletions

View File

@ -152,5 +152,23 @@
"_tpl": "5449016a4bdc2d6f028b456f" "_tpl": "5449016a4bdc2d6f028b456f"
} }
] ]
},
"64bd432d6de7c555ad051726": {
"questId": "64b907a85e9b86ab7a08cf0d",
"itemTpl": "5ac4cd105acfc40016339859",
"itemUpd": {
"BuyRestrictionMax": 2,
"StackObjectsCount": 40000
},
"barterScheme": [
{
"count": 1,
"_tpl": "5d403f9186f7743cac3f229b"
},
{
"count": 1,
"_tpl": "62a0a0bb621468534a797ad5"
}
]
} }
} }

View File

@ -1,6 +1,7 @@
using AssortGenerator.Models.Input; using AssortGenerator.Models.Input;
using AssortGenerator.Models.Other; using AssortGenerator.Models.Other;
using AssortGenerator.Models.Output; using AssortGenerator.Models.Output;
using Common.Models;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -124,6 +125,7 @@ namespace AssortGenerator.Common.Helpers
{ {
public string questId { get; set; } public string questId { get; set; }
public string itemTpl { get; set; } public string itemTpl { get; set; }
public List<Models.Output.Item> items { get;set;}
public Upd itemUpd { get; set; } public Upd itemUpd { get; set; }
public List<BarterObject> barterScheme { get; set; } public List<BarterObject> barterScheme { get; set; }
} }

View File

@ -27,6 +27,14 @@ namespace AssortGenerator.Models.Output
public int? StackObjectsCount { get; set; } public int? StackObjectsCount { get; set; }
public object BuyRestrictionMax { get; set; } public object BuyRestrictionMax { get; set; }
public int? BuyRestrictionCurrent { 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 public class BarterObject

View File

@ -169,28 +169,29 @@ namespace AssortGenerator
} }
} }
private static void AttemptToAddMissingQuestAssorts(AssortRoot outputAssortFile, QuestAssort questAssort, List<AssortUnlocks> missingQuestAssorts, Dictionary<string, MissingAssortPrice> missingQuestAssortPrices) private static void AttemptToAddMissingQuestAssorts(
AssortRoot outputAssortFile,
QuestAssort questAssort,
List<AssortUnlocks> missingQuestAssorts,
Dictionary<string, MissingAssortPrice> missingQuestAssortPrices)
{ {
// iterate over each missing assort // iterate over each missing assort
foreach (var missingQuestAssort in missingQuestAssorts) foreach (var missingQuestAssort in missingQuestAssorts)
{ {
// Single item, maybe we can add one in (skip complex items like guns/ammo boxes etc) // 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;
{
// 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)) 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 // We can add it
var item = new Item var itemToAdd = new Item
{ {
_tpl = missingQuestAssort.Items[0]._tpl, _tpl = missingQuestAssort.Items[0]._tpl,
_id = missingQuestAssort.Items[0]._id, _id = missingQuestAssort.Items[0]._id,
@ -198,23 +199,53 @@ namespace AssortGenerator
slotId = "hideout" slotId = "hideout"
}; };
var questAssortPriceData = missingQuestAssortPrices.TryGetValue(missingQuestAssort.AssortUnlockId, out var value); // Set stack/buy max counts
if (questAssortPriceData && value.itemTpl == missingQuestAssort.Items[0]._tpl) if (hasPriceData && priceData.itemTpl == missingQuestAssort.Items[0]._tpl)
{ {
item.upd = value.itemUpd; itemToAdd.upd = priceData.itemUpd;
} }
else 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);
// Set stack/buy max counts
if (hasPriceData && priceData.itemTpl == missingQuestAssort.Items[0]._tpl)
{
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
{
// no value in json, set stack count to 10
itemsToAdd.First().upd.StackObjectsCount = 10;
}
outputAssortFile.items.AddRange(itemsToAdd);
}
var barterItemListInner = new List<BarterObject>(); var barterItemListInner = new List<BarterObject>();
if (hasPriceData && priceData.itemTpl == missingQuestAssort.Items[0]._tpl)
if (questAssortPriceData && value.itemTpl == missingQuestAssort.Items[0]._tpl)
{ {
barterItemListInner.AddRange(value.barterScheme); barterItemListInner.AddRange(priceData.barterScheme);
} }
else else
{ {
@ -235,6 +266,29 @@ namespace AssortGenerator
} }
} }
} }
private static IEnumerable<Item> ConvertRewardToItems(List<QuestRewardItem> rewardToConvert)
{
var output = new List<Item>();
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<string, Quest> finalisedQuestData, AssortRoot traderAssortRoot) private static void UpdateQuestAssortUnlockIds(string traderId, QuestAssort traderQuestAssort, Dictionary<string, Quest> finalisedQuestData, AssortRoot traderAssortRoot)