From d3f6d5935f1b9227005b1d8d04fbcfd775d89635 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 10 Jan 2020 16:33:40 -0800 Subject: [PATCH] Add form argument legality checks Closes #2611 (Alcremie) Closes #2604 (Runerigus) --- PKHeX.Core/Legality/LegalityCheckStrings.cs | 4 ++ PKHeX.Core/Legality/Verifiers/FormVerifier.cs | 70 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/PKHeX.Core/Legality/LegalityCheckStrings.cs b/PKHeX.Core/Legality/LegalityCheckStrings.cs index 5fb9170be..7ce2a44aa 100644 --- a/PKHeX.Core/Legality/LegalityCheckStrings.cs +++ b/PKHeX.Core/Legality/LegalityCheckStrings.cs @@ -188,6 +188,10 @@ namespace PKHeX.Core public static string LFavoriteMarkingUnavailable { get; set; } = "Favorite Marking is not available."; + public static string LFormArgumentHigh { get; set; } = "Form argument is too high for current form."; + public static string LFormArgumentLow { get; set; } = "Form argument is too low for current form."; + public static string LFormArgumentNotAllowed { get; set; } = "Form argument is not allowed for this encounter."; + public static string LFormArgumentValid { get; set; } = "Form argument is valid."; public static string LFormBattle { get; set; } = "Form cannot exist outside of a battle."; public static string LFormEternal { get; set; } = "Valid Eternal Flower encounter."; public static string LFormEternalInvalid { get; set; } = "Invalid Eternal Flower encounter."; diff --git a/PKHeX.Core/Legality/Verifiers/FormVerifier.cs b/PKHeX.Core/Legality/Verifiers/FormVerifier.cs index 131956f8c..ec524dfed 100644 --- a/PKHeX.Core/Legality/Verifiers/FormVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/FormVerifier.cs @@ -18,6 +18,9 @@ namespace PKHeX.Core return; // no forms exist var result = VerifyForm(data); data.AddLine(result); + + if (pkm is IFormArgument f) + data.AddLine(VerifyFormArgument(data, f)); } private CheckResult VALID => GetValid(LFormValid); @@ -250,5 +253,72 @@ namespace PKHeX.Core break; } } + + private CheckResult VerifyFormArgument(LegalityAnalysis data, IFormArgument f) + { + var pkm = data.pkm; + switch (data.pkm.Species) + { + default: + { + if (f.FormArgument != 0) + return GetInvalid(LFormArgumentNotAllowed); + break; + } + case (int)Species.Furfrou: + { + if (f.FormArgument > 5) + return GetInvalid(LFormArgumentHigh); + if (f.FormArgument == 0 && pkm.AltForm != 0) + return GetInvalid(LFormArgumentNotAllowed); + if (f.FormArgument != 0 && pkm.AltForm == 0) + return GetInvalid(LFormArgumentNotAllowed); + break; + } + case (int)Species.Hoopa: + { + if (f.FormArgument > 3) + return GetInvalid(LFormArgumentHigh); + if (f.FormArgument == 0 && pkm.AltForm != 0) + return GetInvalid(LFormArgumentNotAllowed); + if (f.FormArgument != 0 && pkm.AltForm == 0) + return GetInvalid(LFormArgumentNotAllowed); + break; + } + case (int)Species.Runerigus: + { + if (data.EncounterMatch.Species == (int)Species.Runerigus) + { + if (f.FormArgument != 0) + return GetInvalid(LFormArgumentNotAllowed); + } + else + { + if (f.FormArgument < 49) + return GetInvalid(LFormArgumentLow); + if (f.FormArgument > 320) // calculate Yamask HP maximum? Arbitrary bound check. + return GetInvalid(LFormArgumentHigh); + } + break; + } + + case (int)Species.Alcremie: + { + if (data.EncounterMatch.Species == (int)Species.Alcremie) + { + if (f.FormArgument != 0) + return GetInvalid(LFormArgumentNotAllowed); + } + else + { + if (f.FormArgument > (uint)AlcremieDecoration.Ribbon) + return GetInvalid(LFormArgumentHigh); + } + break; + } + } + + return GetValid(LFormArgumentValid); + } } }