2021-09-28 20:17:42 +01:00
|
|
|
|
using QuestValidator.Common.Helpers;
|
2021-09-14 19:52:11 +01:00
|
|
|
|
using QuestValidator.Models;
|
2021-09-07 17:45:49 +01:00
|
|
|
|
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
|
|
|
|
|
{
|
2021-09-15 09:15:52 +01:00
|
|
|
|
// Quest to lookup is key, previous quest is PreceedingQuest value
|
2021-09-14 19:52:11 +01:00
|
|
|
|
|
2022-09-07 08:51:30 +01:00
|
|
|
|
private static List<QuestRoot> _liveQuestData;
|
2021-09-28 20:17:42 +01:00
|
|
|
|
private static Dictionary<string, QuestValidator.Models.Quest> _questData;
|
2021-09-07 17:45:49 +01:00
|
|
|
|
private static List<AssortUnlocks> _assortUnlocks;
|
|
|
|
|
|
2021-09-28 20:17:42 +01:00
|
|
|
|
public static Dictionary<string, QuestValidator.Models.Quest> GetQuestData(string filename = "quests")
|
2021-09-07 17:45:49 +01:00
|
|
|
|
{
|
2022-01-09 20:35:43 +00:00
|
|
|
|
if (_questData is null)
|
2021-09-07 17:45:49 +01:00
|
|
|
|
{
|
|
|
|
|
var questFilePath = InputFileHelper.GetInputFilePaths().FirstOrDefault(x => x.Contains(filename));
|
2022-01-09 20:35:43 +00:00
|
|
|
|
if (questFilePath is null)
|
2021-09-10 13:25:26 +01:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-07 17:45:49 +01:00
|
|
|
|
var questDataJson = File.ReadAllText(questFilePath);
|
2021-09-28 20:17:42 +01:00
|
|
|
|
_questData = JsonSerializer.Deserialize<Dictionary<string, QuestValidator.Models.Quest>>(questDataJson);
|
2021-09-07 17:45:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _questData;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-07 08:51:30 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Merge all live quest dumps into one file
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="liveQuestDataFiles"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static QuestRoot MergeLiveQuestFiles(List<QuestRoot> liveQuestDataFiles)
|
|
|
|
|
{
|
|
|
|
|
QuestRoot mergedResult = null;
|
|
|
|
|
foreach (var liveQuestDataFile in liveQuestDataFiles)
|
|
|
|
|
{
|
|
|
|
|
if (mergedResult == null)
|
|
|
|
|
{
|
|
|
|
|
mergedResult = liveQuestDataFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var quest in liveQuestDataFile.data)
|
|
|
|
|
{
|
|
|
|
|
if (mergedResult.data.Any(x => x._id == quest._id))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-02 12:22:48 +00:00
|
|
|
|
LoggingHelpers.LogWarning($"missing quest {quest._id} {QuestNames.GetNameById(quest._id)} found in subsequent live quest dump");
|
2022-09-07 08:51:30 +01:00
|
|
|
|
mergedResult.data.Add(quest);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return mergedResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<QuestRoot> GetLiveQuestData(string filename = "resp.client.quest.list")
|
2021-09-07 17:45:49 +01:00
|
|
|
|
{
|
2022-01-09 20:35:43 +00:00
|
|
|
|
if (_liveQuestData is null)
|
2021-09-07 17:45:49 +01:00
|
|
|
|
{
|
2022-09-07 08:51:30 +01:00
|
|
|
|
_liveQuestData = new List<QuestRoot>();
|
|
|
|
|
var questFilePaths = InputFileHelper.GetInputFilePaths().Where(x => x.Contains(filename));
|
|
|
|
|
if (questFilePaths is null)
|
2021-09-10 13:25:26 +01:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-07 08:51:30 +01:00
|
|
|
|
foreach (var questFilepath in questFilePaths)
|
|
|
|
|
{
|
|
|
|
|
var questDataJson = File.ReadAllText(questFilepath);
|
|
|
|
|
_liveQuestData.Add(JsonSerializer.Deserialize<QuestRoot>(questDataJson));
|
|
|
|
|
}
|
2021-09-07 17:45:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _liveQuestData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetQuestNameById(string id)
|
|
|
|
|
{
|
2021-09-28 20:17:42 +01:00
|
|
|
|
return QuestNames.GetNameById(id);
|
2021-09-07 17:45:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<AssortUnlocks> GetAssortUnlocks()
|
|
|
|
|
{
|
2022-01-09 20:35:43 +00:00
|
|
|
|
if (_assortUnlocks is null)
|
2021-09-07 17:45:49 +01:00
|
|
|
|
{
|
|
|
|
|
_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;
|
|
|
|
|
}
|
2021-09-14 19:52:11 +01:00
|
|
|
|
|
2021-09-28 20:17:42 +01:00
|
|
|
|
public static bool DoesIconExist(string iconPath, string imageId)
|
|
|
|
|
{
|
|
|
|
|
var filesInPath = Directory.GetFiles(iconPath);
|
|
|
|
|
return filesInPath.Any(x => x.Contains(imageId));
|
2021-09-14 19:52:11 +01:00
|
|
|
|
}
|
2021-09-07 17:45:49 +01:00
|
|
|
|
}
|
|
|
|
|
}
|