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?)
This commit is contained in:
Kurt 2018-10-08 17:57:34 -07:00
parent 47f20b8c0e
commit b481358e92
2 changed files with 32 additions and 2 deletions

View file

@ -54,8 +54,13 @@ namespace PKHeX.Core
return; return;
// Non-nicknamed strings have already been checked. // Non-nicknamed strings have already been checked.
if (ParseSettings.CheckWordFilter && pkm.IsNicknamed && WordFilter.IsFiltered(nickname, out string bad)) if (ParseSettings.CheckWordFilter && pkm.IsNicknamed)
{
if (WordFilter.IsFiltered(nickname, out string bad))
data.AddLine(GetInvalid($"Wordfilter: {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) private bool VerifyUnNicknamedEncounter(LegalityAnalysis data, PKM pkm, string nickname)

View file

@ -72,6 +72,8 @@ namespace PKHeX.Core
data.AddLine(GetInvalid($"Wordfilter: {bad}")); data.AddLine(GetInvalid($"Wordfilter: {bad}"));
if (WordFilter.IsFiltered(pkm.HT_Name, out bad)) if (WordFilter.IsFiltered(pkm.HT_Name, out bad))
data.AddLine(GetInvalid($"Wordfilter: {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); 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 ('' <= c)
return c <= '';
return c <= '9' && '0' <= c;
}
return str.Count(IsNumber);
}
} }
} }