2021-10-16 18:55:50 +01:00

102 lines
3.6 KiB
C#

using QuestValidator.Common.Helpers;
using QuestValidator.Models;
using QuestValidator.Models.Other;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
namespace AssortGenerator.Common.Helpers
{
public static class QuestHelper
{
// Quest to lookup is key, previous quest is PreceedingQuest value
private static QuestRoot _liveQuestData;
private static Dictionary<string, QuestValidator.Models.Quest> _questData;
private static List<AssortUnlocks> _assortUnlocks;
public static Dictionary<string, QuestValidator.Models.Quest> GetQuestData(string filename = "quests")
{
if (_questData == null)
{
var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains(filename));
if (questFilePath == null)
{
return null;
}
var questDataJson = File.ReadAllText(questFilePath);
_questData = JsonSerializer.Deserialize<Dictionary<string, QuestValidator.Models.Quest>>(questDataJson);
}
return _questData;
}
public static QuestRoot GetLiveQuestData(string filename = "resp.client.quest.list")
{
if (_liveQuestData == null)
{
var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains(filename));
if (questFilePath == null)
{
return null;
}
var questDataJson = File.ReadAllText(questFilePath);
_liveQuestData = JsonSerializer.Deserialize<QuestRoot>(questDataJson);
}
return _liveQuestData;
}
public static string GetQuestNameById(string id)
{
return QuestNames.GetNameById(id);
}
public static List<AssortUnlocks> GetAssortUnlocks()
{
if (_assortUnlocks == null)
{
_assortUnlocks = new List<AssortUnlocks>();
foreach (var quest in GetQuestData())
{
foreach (var reward in quest.Value.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.Key,
QuestRewardId = reward.id,
TraderId = reward.traderId,
TraderType = TraderHelper.GetTraderTypeById(reward.traderId),
Criteria = "Success"
}
);
}
}
}
}
return _assortUnlocks;
}
public static List<QuestRequirements.PreRequisite> GetQuestDependancy(string questId)
{
return QuestRequirements.GetQuestRequirements(questId);
}
public static bool DoesIconExist(string iconPath, string imageId)
{
var filesInPath = Directory.GetFiles(iconPath);
return filesInPath.Any(x => x.Contains(imageId));
}
}
}