Add initial marking checks

This commit is contained in:
Kurt 2020-04-06 16:32:23 -07:00
parent 0b48034f4d
commit 4d061c561a
5 changed files with 88 additions and 1 deletions

View file

@ -332,6 +332,11 @@ namespace PKHeX.Core
HyperTraining.Verify(this);
Misc.VerifyVersionEvolution(this);
if (pkm.Format < 8)
return;
Mark.Verify(this);
}
private string GetLegalityReport()

View file

@ -30,6 +30,7 @@ namespace PKHeX.Core
private static readonly LevelVerifier Level = new LevelVerifier();
private static readonly MiscVerifier Misc = new MiscVerifier();
private static readonly TransferVerifier Transfer = new TransferVerifier();
private static readonly MarkVerifier Mark = new MarkVerifier();
public static string[] MoveStrings { internal get; set; } = Util.GetMovesList(GameLanguage.DefaultLanguage);
public static string[] SpeciesStrings { internal get; set; } = Util.GetSpeciesList(GameLanguage.DefaultLanguage);

View file

@ -137,6 +137,11 @@
/// <summary>
/// The CheckResult pertains to the <see cref="PKM.HeldItem"/>.
/// </summary>
HeldItem
HeldItem,
/// <summary>
/// The <see cref="CheckResult"/> pertains to the <see cref="PKM"/> <see cref="IRibbonSetMark8"/>.
/// </summary>
RibbonMark,
}
}

View file

@ -402,6 +402,7 @@ namespace PKHeX.Core
public static string LRibbonEgg { get; set; } = "Can't receive Ribbon(s) as an Egg.";
public static string LRibbonFInvalid_0 { get; set; } = "Invalid Ribbons: {0}";
public static string LRibbonFMissing_0 { get; set; } = "Missing Ribbons: {0}";
public static string LRibbonMarkingFInvalid_0 { get; set; } = "Invalid Marking: {0}";
public static string LStatDynamaxInvalid { get; set; } = "Dynamax Level is not within the expected range.";
public static string LStatIncorrectHeight { get; set; } = "Calculated Height does not match stored value.";

View file

@ -0,0 +1,75 @@
using static PKHeX.Core.LegalityCheckStrings;
namespace PKHeX.Core
{
/// <summary>
/// Verifies the <see cref="RibbonIndex"/> values for markings.
/// </summary>
public sealed class MarkVerifier : Verifier
{
protected override CheckIdentifier Identifier => CheckIdentifier.RibbonMark;
public override void Verify(LegalityAnalysis data)
{
var pkm = data.pkm;
if (!(pkm is IRibbonIndex m))
return;
if (data.Info.Generation != 8)
VerifyNoMarksPresent(data, m);
else
VerifyMarksPresent(data, m);
}
private void VerifyNoMarksPresent(LegalityAnalysis data, IRibbonIndex m)
{
for (var x = RibbonIndex.MarkLunchtime; x <= RibbonIndex.MarkSlump; x++)
{
if (m.GetRibbon((int)x))
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, x)));
}
}
private void VerifyMarksPresent(LegalityAnalysis data, IRibbonIndex m)
{
bool hasOne = false;
for (var mark = RibbonIndex.MarkLunchtime; mark <= RibbonIndex.MarkSlump; mark++)
{
bool has = m.GetRibbon((int) mark);
if (!has)
continue;
if (hasOne)
{
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, mark)));
return;
}
bool result = VerifyMarking(data, mark);
if (!result)
{
data.AddLine(GetInvalid(string.Format(LRibbonMarkingFInvalid_0, mark)));
return;
}
hasOne = true;
}
}
private static bool VerifyMarking(LegalityAnalysis data, RibbonIndex mark)
{
var pkm = data.pkm;
switch (mark)
{
case RibbonIndex.MarkCurry:
{
var ball = pkm.Ball;
if (!(2 <= ball && ball <= 4)) // Poke,Great,Ultra only
return false;
break;
}
}
return true;
}
}
}