mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00:00
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:
parent
47f20b8c0e
commit
b481358e92
2 changed files with 32 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue