using System.Collections.Generic; using System.Linq; using Dalamud.Plugin.Services; using QuestionableCompanion.Models; namespace QuestionableCompanion.Services; public class AlliedSocietyQuestSelector { private readonly QuestionableIPC questionableIpc; private readonly IPluginLog log; public AlliedSocietyQuestSelector(QuestionableIPC questionableIpc, IPluginLog log) { this.questionableIpc = questionableIpc; this.log = log; } public List SelectQuestsForCharacter(string characterId, int remainingAllowances, List priorities, AlliedSocietyQuestMode mode) { List selectedQuests = new List(); int currentAllowances = remainingAllowances; List list = (from p in priorities where p.Enabled orderby p.Order select p).ToList(); log.Debug($"[AlliedSociety] Selecting quests for {characterId}. Allowances: {remainingAllowances}, Mode: {mode}"); foreach (AlliedSocietyPriority priority in list) { if (currentAllowances <= 0) { log.Debug("[AlliedSociety] No allowances left, stopping selection"); break; } byte societyId = priority.SocietyId; List optimalQuests = questionableIpc.GetAlliedSocietyOptimalQuests(societyId); if (optimalQuests.Count == 0) { continue; } List readyQuests = new List(); foreach (string questId in optimalQuests) { if (questionableIpc.IsReadyToAcceptQuest(questId)) { readyQuests.Add(questId); } } if (readyQuests.Count == 0) { continue; } if (mode == AlliedSocietyQuestMode.OnlyThreePerSociety) { List questsToTake = readyQuests; if (questsToTake.Count > 3) { questsToTake = questsToTake.Skip(questsToTake.Count - 3).Take(3).ToList(); } foreach (string questId2 in questsToTake) { if (currentAllowances > 0) { selectedQuests.Add(questId2); currentAllowances--; continue; } break; } continue; } foreach (string questId3 in readyQuests) { if (currentAllowances > 0) { selectedQuests.Add(questId3); currentAllowances--; continue; } break; } } log.Information($"[AlliedSociety] Selected {selectedQuests.Count} quests for {characterId}"); return selectedQuests; } }