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> characterQuestCache = new Dictionary>(); public QuestTrackingService(IPluginLog log) { this.log = log; } public HashSet GetCharacterCompletedQuests(string characterName) { if (string.IsNullOrEmpty(characterName)) { return new HashSet(); } if (characterQuestCache.TryGetValue(characterName, out HashSet quests)) { return quests; } return new HashSet(); } public void UpdateCurrentCharacterQuests(string characterName) { if (string.IsNullOrEmpty(characterName)) { return; } try { HashSet completedQuests = new HashSet(); 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"); } }