From f25b4fea9cf24e846859fa42a4ff160b3e3fb8a7 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 21 Nov 2017 18:31:24 -0800 Subject: [PATCH] Add forme range check method to personalinfo relocates logic to better location --- PKHeX.Core/Legality/Checks.cs | 2 +- PKHeX.Core/PersonalInfo/PersonalInfo.cs | 7 +++++++ PKHeX.WinForms/Util/SAVUtil.cs | 5 ++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/PKHeX.Core/Legality/Checks.cs b/PKHeX.Core/Legality/Checks.cs index 4b20a14ea..cef3f0fef 100644 --- a/PKHeX.Core/Legality/Checks.cs +++ b/PKHeX.Core/Legality/Checks.cs @@ -1857,7 +1857,7 @@ private void VerifyForm() if (count <= 1 && pkm.AltForm == 0) return; // no forms to check - if (pkm.AltForm >= count && !FormConverter.IsValidOutOfBoundsForme(pkm.Species, pkm.AltForm, Info.Generation)) + if (!PersonalInfo.IsFormeWithinRange(pkm.AltForm) && !FormConverter.IsValidOutOfBoundsForme(pkm.Species, pkm.AltForm, Info.Generation)) { AddLine(Severity.Invalid, string.Format(V304, count-1, pkm.AltForm), CheckIdentifier.Form); return; diff --git a/PKHeX.Core/PersonalInfo/PersonalInfo.cs b/PKHeX.Core/PersonalInfo/PersonalInfo.cs index 1a028613e..5e4c978ad 100644 --- a/PKHeX.Core/PersonalInfo/PersonalInfo.cs +++ b/PKHeX.Core/PersonalInfo/PersonalInfo.cs @@ -117,5 +117,12 @@ public int RandomGender } public bool HasFormes => FormeCount > 1; public int BST => HP + ATK + DEF + SPE + SPA + SPD; + + public bool IsFormeWithinRange(int forme) + { + if (forme == 0) + return true; + return forme < FormeCount; + } } } diff --git a/PKHeX.WinForms/Util/SAVUtil.cs b/PKHeX.WinForms/Util/SAVUtil.cs index c8efdc86b..77ba38276 100644 --- a/PKHeX.WinForms/Util/SAVUtil.cs +++ b/PKHeX.WinForms/Util/SAVUtil.cs @@ -170,9 +170,8 @@ public static string[] IsPKMCompatible(this SaveFile SAV, PKM pkm) else if (SAV.MaxSpeciesID < pkm.Species) errata.Add($"Game can't obtain species: {GameInfo.Strings.specieslist[pkm.Species]}"); - int count = SAV.Personal[pkm.Species].FormeCount; - if (pkm.AltForm >= SAV.Personal[pkm.Species].FormeCount && !FormConverter.IsValidOutOfBoundsForme(pkm.Species, pkm.AltForm, pkm.GenNumber)) - errata.Add(string.Format(LegalityCheckStrings.V304, count - 1, pkm.AltForm)); + if (!SAV.Personal[pkm.Species].IsFormeWithinRange(pkm.AltForm) && !FormConverter.IsValidOutOfBoundsForme(pkm.Species, pkm.AltForm, pkm.GenNumber)) + errata.Add(string.Format(LegalityCheckStrings.V304, Math.Max(0, SAV.Personal[pkm.Species].FormeCount - 1), pkm.AltForm)); if (pkm.Moves.Any(m => m > GameInfo.Strings.movelist.Length)) errata.Add($"Item Index beyond range: {string.Join(", ", pkm.Moves.Where(m => m > GameInfo.Strings.movelist.Length).Select(m => m.ToString()))}");