PKHeX/PKHeX.Core/Legality/Bulk/StandardCloneChecker.cs
Kurt 95fbf66a6e
Refactor: Gen3/4 Lead Encounters, property fixing (#4193)
In addition to the Method 1 (and other sibling PIDIV types) correlation, an encounter can only be triggered if the calls prior land on the Method {1} seed. The RNG community has dubbed these patterns as "Method J" (D/P/Pt), "Method K" (HG/SS), and "Method H" (Gen3, coined by yours truly). The basic gist of these is that they are pre-requisites, like the Shadow locks of Colosseum/XD. 

Rename/re-type a bunch of properties to get the codebase more in line with correct property names & more obvious underlying types.
2024-02-22 21:20:54 -06:00

62 lines
2.1 KiB
C#

using System.Collections.Generic;
using System.Diagnostics;
using PKHeX.Core.Searching;
using static PKHeX.Core.CheckIdentifier;
namespace PKHeX.Core.Bulk;
public sealed class StandardCloneChecker : IBulkAnalyzer
{
public void Analyze(BulkAnalysis input) => CheckClones(input);
private static void CheckClones(BulkAnalysis input)
{
var dict = new Dictionary<string, SlotCache>();
for (int i = 0; i < input.AllData.Count; i++)
{
var cs = input.AllData[i];
var ca = input.AllAnalysis[i];
Debug.Assert(cs.Entity.Format == input.Trainer.Generation);
// Check the upload tracker to see if there's any duplication.
if (cs.Entity is IHomeTrack home)
CheckClonedTrackerHOME(input, home, cs, ca);
// Hash Details like EC/IV to see if there's any duplication.
var identity = SearchUtil.HashByDetails(cs.Entity);
if (!dict.TryGetValue(identity, out var ps))
{
dict.Add(identity, cs);
continue;
}
input.SetIsClone(i, true);
input.AddLine(ps, cs, "Clone detected (Details).", Encounter);
}
}
private const ulong DefaultUnsetTrackerHOME = 0ul;
private static void CheckClonedTrackerHOME(BulkAnalysis input, IHomeTrack home, SlotCache cs, LegalityAnalysis ca)
{
var tracker = home.Tracker;
if (tracker == DefaultUnsetTrackerHOME)
CheckTrackerMissing(input, cs, ca);
else
CheckTrackerPresent(input, cs, tracker);
}
private static void CheckTrackerMissing(BulkAnalysis input, SlotCache cs, LegalityAnalysis ca)
{
if (ca.Info.Generation is (< 8 and not 0))
input.AddLine(cs, "Missing tracker.", Encounter);
}
private static void CheckTrackerPresent(BulkAnalysis input, SlotCache cs, ulong tracker)
{
if (input.Trackers.TryGetValue(tracker, out var clone))
input.AddLine(cs, clone, "Clone detected (Duplicate Tracker).", Encounter);
else
input.Trackers.Add(tracker, cs);
}
}