qstbak/QuestionableCompanion/QuestionableCompanion.Services/QuestTrackingService.cs
2025-12-04 04:39:08 +10:00

87 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game;
namespace QuestionableCompanion.Services;
public class QuestTrackingService : IDisposable
{
private readonly IPluginLog log;
private readonly Dictionary<string, HashSet<uint>> characterQuestCache = new Dictionary<string, HashSet<uint>>();
public QuestTrackingService(IPluginLog log)
{
this.log = log;
}
public HashSet<uint> GetCharacterCompletedQuests(string characterName)
{
if (string.IsNullOrEmpty(characterName))
{
return new HashSet<uint>();
}
if (characterQuestCache.TryGetValue(characterName, out HashSet<uint> quests))
{
return quests;
}
return new HashSet<uint>();
}
public void UpdateCurrentCharacterQuests(string characterName)
{
if (string.IsNullOrEmpty(characterName))
{
return;
}
try
{
HashSet<uint> completedQuests = new HashSet<uint>();
for (uint questId = 66000u; questId < 72000; questId++)
{
try
{
if (QuestManager.IsQuestComplete(questId))
{
completedQuests.Add(questId);
}
}
catch
{
}
}
characterQuestCache[characterName] = completedQuests;
}
catch (Exception ex)
{
log.Error("[QuestTracking] Failed to update quests for " + characterName + ": " + ex.Message);
}
}
public bool IsQuestCompleted(string characterName, uint questId)
{
return GetCharacterCompletedQuests(characterName).Contains(questId);
}
public void ClearCharacterCache(string characterName)
{
if (characterQuestCache.ContainsKey(characterName))
{
characterQuestCache.Remove(characterName);
log.Debug("[QuestTracking] Cleared cache for " + characterName);
}
}
public void ClearAllCache()
{
characterQuestCache.Clear();
log.Information("[QuestTracking] Cleared all cached quest data");
}
public void Dispose()
{
characterQuestCache.Clear();
log.Information("[QuestTracking] Service disposed");
}
}