41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Questionable.Data;
|
|
using Questionable.Model;
|
|
using Questionable.Model.Questing;
|
|
|
|
namespace Questionable.Validation.Validators;
|
|
|
|
internal sealed class SinglePlayerInstanceValidator : IQuestValidator
|
|
{
|
|
private readonly Dictionary<ElementId, List<byte>> _questIdToDutyIndexes;
|
|
|
|
public SinglePlayerInstanceValidator(TerritoryData territoryData)
|
|
{
|
|
_questIdToDutyIndexes = (from x in territoryData.GetAllQuestsWithQuestBattles()
|
|
group x by x.QuestId).ToDictionary((IGrouping<ElementId, (ElementId QuestId, byte Index, TerritoryData.ContentFinderConditionData Data)> x) => x.Key, (IGrouping<ElementId, (ElementId QuestId, byte Index, TerritoryData.ContentFinderConditionData Data)> x) => x.Select(((ElementId QuestId, byte Index, TerritoryData.ContentFinderConditionData Data) y) => y.Index).ToList());
|
|
}
|
|
|
|
public IEnumerable<ValidationIssue> Validate(Quest quest)
|
|
{
|
|
if (!_questIdToDutyIndexes.TryGetValue(quest.Id, out List<byte> value))
|
|
{
|
|
yield break;
|
|
}
|
|
foreach (byte index in value)
|
|
{
|
|
if (!quest.AllSteps().Any<(QuestSequence, int, QuestStep)>(((QuestSequence Sequence, int StepId, QuestStep Step) x) => x.Step.InteractionType == EInteractionType.SinglePlayerDuty && x.Step.SinglePlayerDutyIndex == index))
|
|
{
|
|
yield return new ValidationIssue
|
|
{
|
|
ElementId = quest.Id,
|
|
Sequence = null,
|
|
Step = null,
|
|
Type = EIssueType.UnusedSinglePlayerInstance,
|
|
Severity = EIssueSeverity.Error,
|
|
Description = $"Single player instance {index} not used"
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|