110 lines
4.3 KiB
C#

using AssortGenerator.Models.Input;
using AssortGenerator.Models.Other;
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;
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()
{
if (_assortUnlocks == null)
{
_assortUnlocks = new List<AssortUnlocks>();
foreach (var quest in GetQuestData().data)
{
// debut
if (quest._id == "5936d90786f7742b1420ba5b")
{
var x = 2;
}
foreach (var reward in quest.rewards.Success)
{
if (string.Equals(reward.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)
{
if (string.Equals(reward.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;
}
}
}