122 lines
4.9 KiB
C#
Raw Normal View History

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;
using System.Text.Json;
namespace AssortGenerator.Common.Helpers
{
public static class QuestHelper
{
private static QuestRoot _questData;
private static List<AssortUnlocks> _assortUnlocks;
private static Dictionary<string, MissingAssortPrice> _missingTraderQuestPrices;
public static QuestRoot GetQuestData()
{
if (_questData == null)
{
var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains("resp.client.quest.list"));
var questDataJson = File.ReadAllText(questFilePath);
_questData = JsonSerializer.Deserialize<QuestRoot>(questDataJson);
}
return _questData;
}
public static Dictionary<string, Quest> GetFinalisedQuestData()
{
var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains("quests.json"));
var questDataJson = File.ReadAllText(questFilePath);
var finalisedQuestData = JsonSerializer.Deserialize<Dictionary<string, Quest>>(questDataJson);
var jsondoc = JsonDocument.Parse(questDataJson);
var root = jsondoc.RootElement;
return finalisedQuestData;
}
public static JsonDocument GetFinalisedQuestDataJsonDoc()
{
var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains("quests.json"));
var questDataJson = File.ReadAllText(questFilePath);
var jsondoc = JsonDocument.Parse(questDataJson);
return jsondoc;
}
public static List<AssortUnlocks> GetAssortUnlocks(Dictionary<string, Quest> questData)
{
if (_assortUnlocks == null)
{
_assortUnlocks = new List<AssortUnlocks>();
foreach (var quest in questData.Values)
{
foreach (var reward in quest.rewards.Success.Where(x => string.Equals(x.type, "assortmentunlock", System.StringComparison.OrdinalIgnoreCase)))
{
_assortUnlocks.Add(new AssortUnlocks
{
AssortUnlockId = reward.id,
ItemUnlockedId = reward.target,
ItemUnlockedTemplateId = reward.items[0]._tpl,
LoyaltyLevel = (int)reward.loyaltyLevel,
QuestId = quest._id,
QuestRewardId = reward.id,
TraderId = reward.traderId,
TraderType = TraderHelper.GetTraderTypeById(reward.traderId),
Criteria = "Success",
Items = reward.items
}
);
}
foreach (var reward in quest.rewards.Started.Where(x => string.Equals(x.type, "assortmentunlock", System.StringComparison.OrdinalIgnoreCase)))
{
_assortUnlocks.Add(new AssortUnlocks
{
AssortUnlockId = reward.id,
ItemUnlockedId = reward.target,
ItemUnlockedTemplateId = reward.items[0]._tpl,
LoyaltyLevel = (int)reward.loyaltyLevel,
QuestId = quest._id,
QuestRewardId = reward.id,
TraderId = reward.traderId,
TraderType = TraderHelper.GetTraderTypeById(reward.traderId),
Criteria = "Started",
Items = reward.items
}
);
}
}
}
return _assortUnlocks;
}
public static Dictionary<string, MissingAssortPrice> GetMissingTraderQuestPrices()
{
if (_missingTraderQuestPrices == null)
{
var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains("missingTraderAssortPrices"));
var questDataJson = File.ReadAllText(questFilePath);
_missingTraderQuestPrices = JsonSerializer.Deserialize<Dictionary<string, MissingAssortPrice>>(questDataJson);
}
return _missingTraderQuestPrices;
}
public class MissingAssortPrice
{
public string questId { get; set; }
public string itemTpl { get; set; }
2024-06-07 11:54:32 +01:00
public List<AssortGenerator.Models.Output.Item> items { get; set; }
public Upd itemUpd { get; set; }
public List<BarterObject> barterScheme { get; set; }
}
}
}