From b481358e929a5fbf0f8debc3c320184f02570ac3 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 8 Oct 2018 17:57:34 -0700 Subject: [PATCH] Add number count check for OT/nick https://projectpokemon.org/home/forums/topic/47850-legality-issue-names-with-multiple-numbers/ let me know if there's any implications for transferred content (name reset on 1-3=>n?) --- .../Legality/Verifiers/NicknameVerifier.cs | 9 +++++-- .../Legality/Verifiers/TrainerNameVerifier.cs | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs b/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs index 32f235d37..6b8aebc9c 100644 --- a/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs @@ -54,8 +54,13 @@ namespace PKHeX.Core return; // Non-nicknamed strings have already been checked. - if (ParseSettings.CheckWordFilter && pkm.IsNicknamed && WordFilter.IsFiltered(nickname, out string bad)) - data.AddLine(GetInvalid($"Wordfilter: {bad}")); + if (ParseSettings.CheckWordFilter && pkm.IsNicknamed) + { + if (WordFilter.IsFiltered(nickname, out string bad)) + data.AddLine(GetInvalid($"Wordfilter: {bad}")); + if (TrainerNameVerifier.ContainsTooManyNumbers(nickname, data.Info.Generation)) + data.AddLine(GetInvalid("Wordfilter: Too many numbers.")); + } } private bool VerifyUnNicknamedEncounter(LegalityAnalysis data, PKM pkm, string nickname) diff --git a/PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs b/PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs index bcbc3c9b6..5962ad14d 100644 --- a/PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs @@ -72,6 +72,8 @@ namespace PKHeX.Core data.AddLine(GetInvalid($"Wordfilter: {bad}")); if (WordFilter.IsFiltered(pkm.HT_Name, out bad)) data.AddLine(GetInvalid($"Wordfilter: {bad}")); + if (ContainsTooManyNumbers(ot, data.Info.Generation)) + data.AddLine(GetInvalid($"Wordfilter: Too many numbers.")); } } @@ -132,5 +134,28 @@ namespace PKHeX.Core { return SuspiciousOTNames.Any(name.StartsWith); } + + public static bool ContainsTooManyNumbers(string str, int originalGeneration) + { + if (originalGeneration <= 3) + return false; // no limit from these generations + int max = originalGeneration < 6 ? 4 : 5; + if (str.Length < max) + return false; + int count = GetNumberCount(str); + return count > max; + } + + private static int GetNumberCount(string str) + { + bool IsNumber(char c) + { + if ('0' <= c) + return c <= '9'; + return c <= '9' && '0' <= c; + } + + return str.Count(IsNumber); + } } }