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

87 lines
2.3 KiB
C#

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<string> SelectQuestsForCharacter(string characterId, int remainingAllowances, List<AlliedSocietyPriority> priorities, AlliedSocietyQuestMode mode)
{
List<string> selectedQuests = new List<string>();
int currentAllowances = remainingAllowances;
List<AlliedSocietyPriority> 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<string> optimalQuests = questionableIpc.GetAlliedSocietyOptimalQuests(societyId);
if (optimalQuests.Count == 0)
{
continue;
}
List<string> readyQuests = new List<string>();
foreach (string questId in optimalQuests)
{
if (questionableIpc.IsReadyToAcceptQuest(questId))
{
readyQuests.Add(questId);
}
}
if (readyQuests.Count == 0)
{
continue;
}
if (mode == AlliedSocietyQuestMode.OnlyThreePerSociety)
{
List<string> 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;
}
}