PKHeX/PKHeX.Core/Legality/Bulk/HandlerChecker.cs

49 lines
1.5 KiB
C#
Raw Normal View History

using System;
2023-02-09 01:24:47 +00:00
using static PKHeX.Core.CheckIdentifier;
namespace PKHeX.Core.Bulk;
public sealed class HandlerChecker : IBulkAnalyzer
{
public void Analyze(BulkAnalysis input)
{
if (input.Trainer.Generation < 6 || !input.Settings.CheckActiveHandler)
return; // no HT yet
CheckHandlerFlag(input);
}
private static void CheckHandlerFlag(BulkAnalysis input)
{
for (var i = 0; i < input.AllData.Count; i++)
{
if (!input.AllAnalysis[i].Valid)
continue;
var cs = input.AllData[i];
Verify(input, cs);
}
}
private static void Verify(BulkAnalysis input, SlotCache cs)
{
var pk = cs.Entity;
var tr = cs.SAV;
var withOT = tr.IsFromTrainer(pk);
var flag = pk.CurrentHandler;
var expect = withOT ? 0 : 1;
if (flag != expect)
input.AddLine(cs, LegalityCheckStrings.LTransferCurrentHandlerInvalid, Trainer);
if (flag != 1)
return;
Span<char> ht = stackalloc char[pk.TrashCharCountTrainer];
var len = pk.LoadString(pk.HandlingTrainerTrash, ht);
ht = ht[..len];
if (!ht.SequenceEqual(tr.OT))
2023-02-09 01:24:47 +00:00
input.AddLine(cs, LegalityCheckStrings.LTransferHTMismatchName, Trainer);
if (pk is IHandlerLanguage h && h.HandlingTrainerLanguage != tr.Language)
2023-02-09 01:24:47 +00:00
input.AddLine(cs, LegalityCheckStrings.LTransferHTMismatchLanguage, Trainer);
}
}