Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
using System;
|
2018-06-24 05:00:01 +00:00
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
using static PKHeX.Core.LanguageID;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Verifies the <see cref="PKM.Nickname"/>.
|
|
|
|
/// </summary>
|
|
|
|
public sealed class NicknameVerifier : Verifier
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Nickname;
|
|
|
|
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var pk = data.Entity;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// If the Pokémon is not nicknamed, it should match one of the language strings.
|
|
|
|
var nickname = pk.Nickname;
|
|
|
|
if (nickname.Length == 0)
|
|
|
|
{
|
|
|
|
data.AddLine(GetInvalid(LNickLengthShort));
|
|
|
|
return;
|
|
|
|
}
|
2023-08-28 06:05:50 +00:00
|
|
|
if (pk.Species > SpeciesName.MaxSpeciesID)
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
data.AddLine(Get(LNickLengthShort, Severity.Invalid));
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var enc = data.EncounterOriginal;
|
|
|
|
if (enc is ILangNicknamedTemplate n)
|
|
|
|
{
|
|
|
|
VerifyFixedNicknameEncounter(data, n, enc, pk, nickname);
|
|
|
|
if (pk.IsEgg)
|
|
|
|
VerifyNicknameEgg(data);
|
2023-12-05 02:38:05 +00:00
|
|
|
if (pk.IsNicknamed)
|
|
|
|
return;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
if (pk is { Format: <= 7, IsNicknamed: true }) // can nickname afterward
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (pk.VC)
|
2023-01-22 04:02:33 +00:00
|
|
|
VerifyG1NicknameWithinBounds(data, nickname);
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (enc is MysteryGift {IsEgg: false})
|
|
|
|
data.AddLine(Get(LEncGiftNicknamed, ParseSettings.NicknamedMysteryGift));
|
|
|
|
}
|
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
if (enc is IFixedTrainer t)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-08-12 23:01:16 +00:00
|
|
|
VerifyNicknameTrade(data, enc);
|
|
|
|
if (t is IFixedNickname { IsFixedNickname: true })
|
2021-02-02 02:35:37 +00:00
|
|
|
return;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2021-02-02 02:35:37 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.IsEgg)
|
|
|
|
{
|
|
|
|
VerifyNicknameEgg(data);
|
|
|
|
return;
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (VerifyUnNicknamedEncounter(data, pk, nickname))
|
|
|
|
return;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Non-nicknamed strings have already been checked.
|
|
|
|
if (ParseSettings.CheckWordFilter && pk.IsNicknamed)
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
if (WordFilter.IsFiltered(nickname, out var badPattern))
|
|
|
|
data.AddLine(GetInvalid($"Word Filter: {badPattern}"));
|
2022-06-18 18:04:24 +00:00
|
|
|
if (TrainerNameVerifier.ContainsTooManyNumbers(nickname, data.Info.Generation))
|
|
|
|
data.AddLine(GetInvalid("Word Filter: Too many numbers."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private void VerifyFixedNicknameEncounter(LegalityAnalysis data, ILangNicknamedTemplate n, IEncounterTemplate enc, PKM pk, ReadOnlySpan<char> nickname)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var encounterNickname = n.GetNickname(pk.Language);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(encounterNickname))
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (n is WC8 {IsHOMEGift: true})
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
VerifyHomeGiftNickname(data, enc, pk, nickname);
|
2018-06-24 05:00:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (n.CanHandleOT(pk.Language))
|
2018-06-24 05:00:01 +00:00
|
|
|
return;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (n is WC3 && pk.Format != 3)
|
2018-10-09 00:57:34 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Gen3 gifts transferred to Generation 4 from another language can set the nickname flag.
|
|
|
|
var evos = data.Info.EvoChainsAllGens.Gen3;
|
2022-08-18 06:48:37 +00:00
|
|
|
foreach (var evo in evos)
|
|
|
|
{
|
|
|
|
if (!SpeciesName.IsNicknamedAnyLanguage(evo.Species, nickname, 3))
|
|
|
|
return;
|
|
|
|
}
|
2018-10-09 00:57:34 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
if (pk.IsNicknamed)
|
|
|
|
data.AddLine(Get(LEncGiftNicknamed, Severity.Invalid));
|
|
|
|
return;
|
2018-06-24 05:00:01 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!pk.IsNicknamed)
|
2021-02-02 02:35:37 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Check if it had a nickname at all
|
|
|
|
var orig = SpeciesName.GetSpeciesNameGeneration(enc.Species, pk.Language, enc.Generation);
|
2023-01-22 04:02:33 +00:00
|
|
|
if (orig == encounterNickname)
|
2021-02-02 02:35:37 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Didn't have a nickname. Ensure that the language matches the current nickname string.
|
|
|
|
if (!SpeciesName.IsNicknamed(pk.Species, nickname, pk.Language, pk.Format))
|
2021-02-03 03:14:38 +00:00
|
|
|
return;
|
2021-02-02 02:35:37 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Should have a nickname present.
|
|
|
|
data.AddLine(GetInvalid(LNickMatchLanguageFail));
|
|
|
|
return;
|
2021-02-02 02:35:37 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Encounter has a nickname, and PKM should have it.
|
2023-01-22 04:02:33 +00:00
|
|
|
bool matches = nickname.SequenceEqual(encounterNickname);
|
|
|
|
var severity = !matches || !pk.IsNicknamed ? Severity.Invalid : Severity.Valid;
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(Get(LEncGiftNicknamed, severity));
|
|
|
|
}
|
2021-02-03 03:21:17 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private void VerifyHomeGiftNickname(LegalityAnalysis data, IEncounterTemplate enc, ILangNick pk, ReadOnlySpan<char> nickname)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
// can nickname on redemption
|
|
|
|
if (!pk.IsNicknamed)
|
|
|
|
return;
|
2021-02-03 03:21:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Can't nickname everything.
|
|
|
|
if (enc.Species == (int) Species.Melmetal)
|
|
|
|
{
|
|
|
|
data.AddLine(GetInvalid(LEncGiftNicknamed));
|
|
|
|
return;
|
2021-02-03 03:14:38 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Ensure the nickname does not match species name
|
|
|
|
var orig = SpeciesName.GetSpeciesNameGeneration(enc.Species, pk.Language, enc.Generation);
|
2023-01-22 04:02:33 +00:00
|
|
|
if (nickname.SequenceEqual(orig))
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(GetInvalid(LNickMatchLanguageFlag));
|
|
|
|
}
|
|
|
|
|
2023-08-28 06:05:50 +00:00
|
|
|
private bool VerifyUnNicknamedEncounter(LegalityAnalysis data, PKM pk, ReadOnlySpan<char> nickname)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (pk.IsNicknamed)
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
if (data.Info.Generation >= 8 && CanNicknameForeign8Plus(data, pk))
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Can only nickname if it matches your language.
|
|
|
|
// Setting the nickname to the same as the species name does not set the Nickname flag (equals unmodified, no flag)
|
|
|
|
if (!SpeciesName.IsNicknamed(pk.Species, nickname, pk.Language, pk.Format))
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(Get(LNickMatchLanguageFlag, Severity.Invalid));
|
2018-06-24 05:00:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2023-08-28 06:05:50 +00:00
|
|
|
foreach (var language in Language.GetAvailableGameLanguages(pk.Format))
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2023-08-28 06:05:50 +00:00
|
|
|
if (!SpeciesName.TryGetSpecies(nickname, language, out var species))
|
2022-06-18 18:04:24 +00:00
|
|
|
continue;
|
2023-08-28 06:05:50 +00:00
|
|
|
var msg = species == pk.Species && language != pk.Language ? LNickMatchNoOthersFail : LNickMatchLanguageFlag;
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(Get(msg, ParseSettings.NicknamedAnotherSpecies));
|
|
|
|
return true;
|
2018-06-24 05:00:01 +00:00
|
|
|
}
|
2023-01-22 04:02:33 +00:00
|
|
|
if (pk.Format <= 7 && StringConverter.HasEastAsianScriptCharacters(nickname) && pk is not PB7) // East Asian Scripts
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(GetInvalid(LNickInvalidChar));
|
|
|
|
return true;
|
2018-08-31 01:09:52 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (nickname.Length > Legal.GetMaxLengthNickname(data.Info.Generation, (LanguageID)pk.Language))
|
|
|
|
{
|
|
|
|
int length = GetForeignNicknameLength(pk, data.Info.EncounterOriginal, data.Info.Generation);
|
|
|
|
var severe = (length != 0 && nickname.Length <= length) ? Severity.Fishy : Severity.Invalid;
|
|
|
|
data.AddLine(Get(LNickLengthLong, severe));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
data.AddLine(GetValid(LNickMatchNoOthers));
|
2018-08-31 01:09:52 +00:00
|
|
|
}
|
2023-01-22 04:02:33 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
VerifyUnNicknamed(data, pk, nickname);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void VerifyUnNicknamed(LegalityAnalysis data, PKM pk, ReadOnlySpan<char> nickname)
|
|
|
|
{
|
|
|
|
if (pk.Format < 3)
|
2022-01-08 18:33:02 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// pk1/pk2 IsNicknamed getter checks for match, logic should only reach here if matches.
|
|
|
|
data.AddLine(GetValid(LNickMatchLanguage));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var enc = data.EncounterOriginal;
|
|
|
|
bool valid = IsNicknameValid(pk, enc, nickname);
|
|
|
|
var result = valid ? GetValid(LNickMatchLanguage) : GetInvalid(LNickMatchLanguageFail);
|
|
|
|
data.AddLine(result);
|
|
|
|
}
|
2023-01-22 04:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static bool CanNicknameForeign8Plus(LegalityAnalysis data, PKM pk)
|
|
|
|
{
|
|
|
|
if (data.Info.EvoChainsAllGens.HasVisitedSWSH)
|
|
|
|
return true;
|
|
|
|
if (pk.Format >= 9)
|
|
|
|
return !pk.FatefulEncounter;
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
private static int GetForeignNicknameLength(PKM pk, IEncounterTemplate match, byte origin)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
// HOME gifts already verified prior to reaching here.
|
|
|
|
System.Diagnostics.Debug.Assert(match is not WC8 {IsHOMEGift:true});
|
2022-01-08 18:33:02 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int length = 0;
|
2024-03-25 05:39:30 +00:00
|
|
|
if (origin is (4 or 5 or 6 or 7) && match.IsEgg && pk.WasTradedEgg)
|
2022-06-18 18:04:24 +00:00
|
|
|
length = Legal.GetMaxLengthNickname(origin, English);
|
2022-01-08 18:33:02 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.FatefulEncounter)
|
|
|
|
return length;
|
2022-01-08 18:33:02 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.Format < 8 || pk.BDSP)
|
|
|
|
return length;
|
2022-01-08 18:33:02 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Can only nickname if the language matches.
|
|
|
|
var future = Legal.GetMaxLengthNickname(pk.Format, (LanguageID)pk.Language);
|
|
|
|
return Math.Max(length, future);
|
|
|
|
}
|
2022-01-08 18:33:02 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private static bool IsNicknameValid(PKM pk, IEncounterTemplate enc, ReadOnlySpan<char> nickname)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
ushort species = pk.Species;
|
2024-02-23 03:20:54 +00:00
|
|
|
byte format = pk.Format;
|
2022-06-18 18:04:24 +00:00
|
|
|
int language = pk.Language;
|
2023-01-22 04:02:33 +00:00
|
|
|
var expect = SpeciesName.GetSpeciesNameGeneration(species, language, format);
|
|
|
|
if (nickname.SequenceEqual(expect))
|
2022-06-18 18:04:24 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Can't have another language name if it hasn't evolved or wasn't a language-traded egg.
|
|
|
|
// Starting in Generation 8, hatched language-traded eggs will take the Language from the trainer that hatched it.
|
|
|
|
// Also in Generation 8, evolving in a foreign language game will retain the original language as the source for the newly evolved species name.
|
|
|
|
// Transferring from Gen7->Gen8 realigns the Nickname string to the Language, if not nicknamed.
|
|
|
|
bool canHaveAnyLanguage = format <= 7 && (enc.Species != species || pk.WasTradedEgg) && !pk.GG;
|
|
|
|
if (canHaveAnyLanguage && !SpeciesName.IsNicknamedAnyLanguage(species, nickname, format))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
switch (enc)
|
2018-08-31 01:09:52 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
case WC7 wc7 when wc7.IsAshGreninjaWC7(pk):
|
2018-08-31 01:09:52 +00:00
|
|
|
return true;
|
2022-06-18 18:04:24 +00:00
|
|
|
case ILangNick loc:
|
|
|
|
if (loc.Language != 0 && !loc.IsNicknamed && !SpeciesName.IsNicknamedAnyLanguage(species, nickname, format))
|
|
|
|
return true; // fixed language without nickname, nice job event maker!
|
|
|
|
break;
|
|
|
|
}
|
2018-08-31 01:09:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (format == 5 && !pk.IsNative) // transfer
|
|
|
|
{
|
|
|
|
if (canHaveAnyLanguage)
|
|
|
|
return !SpeciesName.IsNicknamedAnyLanguage(species, nickname, 4);
|
2023-01-22 04:02:33 +00:00
|
|
|
expect = SpeciesName.GetSpeciesNameGeneration(species, language, 4);
|
|
|
|
return nickname.SequenceEqual(expect);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-08-31 01:09:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-08-31 01:09:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static void VerifyNicknameEgg(LegalityAnalysis data)
|
|
|
|
{
|
|
|
|
var Info = data.Info;
|
|
|
|
var pk = data.Entity;
|
|
|
|
|
|
|
|
bool flagState = EggStateLegality.IsNicknameFlagSet(Info.EncounterMatch, pk);
|
|
|
|
if (pk.IsNicknamed != flagState)
|
|
|
|
data.AddLine(GetInvalid(flagState ? LNickFlagEggYes : LNickFlagEggNo, CheckIdentifier.Egg));
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
ReadOnlySpan<char> nickname = pk.Nickname;
|
|
|
|
if (pk.Format == 2 && !SpeciesName.IsNicknamedAnyLanguage(0, nickname, 2))
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(GetValid(LNickMatchLanguageEgg, CheckIdentifier.Egg));
|
2023-01-22 04:02:33 +00:00
|
|
|
else if (!nickname.SequenceEqual(SpeciesName.GetEggName(pk.Language, Info.Generation)))
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(GetInvalid(LNickMatchLanguageEggFail, CheckIdentifier.Egg));
|
|
|
|
else
|
|
|
|
data.AddLine(GetValid(LNickMatchLanguageEgg, CheckIdentifier.Egg));
|
|
|
|
}
|
2018-08-31 01:09:52 +00:00
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
private static void VerifyNicknameTrade(LegalityAnalysis data, IEncounterTemplate t)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-08-12 23:01:16 +00:00
|
|
|
switch (t)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-08-12 23:01:16 +00:00
|
|
|
case EncounterTrade8b b: VerifyTrade8b(data, b); return;
|
|
|
|
case EncounterTrade4PID t4: VerifyTrade4(data, t4); return;
|
|
|
|
case EncounterTrade5BW t5:
|
|
|
|
VerifyEncounterTrade5(data, t5); return;
|
2022-11-25 01:42:17 +00:00
|
|
|
default:
|
2022-06-18 18:04:24 +00:00
|
|
|
VerifyTrade(data, t, data.Entity.Language); return;
|
2018-06-24 05:00:01 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void VerifyG1NicknameWithinBounds(LegalityAnalysis data, ReadOnlySpan<char> str)
|
|
|
|
{
|
|
|
|
var pk = data.Entity;
|
|
|
|
if (StringConverter12.GetIsG1English(str))
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (str.Length > 10)
|
|
|
|
data.AddLine(GetInvalid(LNickLengthLong));
|
2018-06-24 05:00:01 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (StringConverter12.GetIsG1Japanese(str))
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (str.Length > 5)
|
|
|
|
data.AddLine(GetInvalid(LNickLengthLong));
|
2018-06-24 05:00:01 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else if (pk.Korean && StringConverter2KOR.GetIsG2Korean(str))
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (str.Length > 5)
|
|
|
|
data.AddLine(GetInvalid(LNickLengthLong));
|
2018-06-24 05:00:01 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(GetInvalid(LG1CharNick));
|
2018-06-24 05:00:01 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
private static void VerifyTrade4(LegalityAnalysis data, EncounterTrade4PID t)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var pk = data.Entity;
|
2023-08-12 23:01:16 +00:00
|
|
|
if (t.IsIncorrectEnglish(pk))
|
|
|
|
data.AddLine(GetInvalid(string.Format(LOTLanguage, Japanese, English), CheckIdentifier.Language));
|
|
|
|
var lang = t.DetectOriginalLanguage(pk);
|
2022-06-18 18:04:24 +00:00
|
|
|
VerifyTrade(data, t, lang);
|
|
|
|
}
|
2021-11-20 02:23:49 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static void VerifyTrade8b(LegalityAnalysis data, EncounterTrade8b t)
|
|
|
|
{
|
|
|
|
var pk = data.Entity;
|
|
|
|
int lang = pk.Language;
|
|
|
|
if (t.Species == (int)Species.Magikarp)
|
2021-12-12 06:23:05 +00:00
|
|
|
{
|
2023-08-12 23:01:16 +00:00
|
|
|
if (t.IsMagikarpJapaneseTradedBDSP(pk))
|
2021-12-25 20:57:05 +00:00
|
|
|
{
|
2023-08-12 23:01:16 +00:00
|
|
|
// Traded replaces the OT Name. Verify only the Nickname now.
|
|
|
|
VerifyNickname(data, t, (int)German);
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2021-12-25 20:57:05 +00:00
|
|
|
}
|
2021-12-12 06:23:05 +00:00
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
lang = t.DetectMeisterMagikarpLanguage(pk.Nickname, pk.OriginalTrainerName, lang);
|
2023-08-12 23:01:16 +00:00
|
|
|
if (lang == -1) // err
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(GetInvalid(string.Format(LOTLanguage, $"{Japanese}/{German}", $"{(LanguageID)pk.Language}"), CheckIdentifier.Language));
|
2018-10-27 20:37:03 +00:00
|
|
|
}
|
2023-07-10 02:59:37 +00:00
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
if (t.IsPijako(pk))
|
2023-07-10 02:59:37 +00:00
|
|
|
{
|
|
|
|
// Let it be anything (Nicknamed or not) and just verify the OT.
|
|
|
|
VerifyTradeOTOnly(data, t);
|
|
|
|
return;
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
VerifyTrade(data, t, lang);
|
|
|
|
}
|
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
private static void VerifyEncounterTrade5(LegalityAnalysis data, EncounterTrade5BW t)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var pk = data.Entity;
|
2023-08-12 23:01:16 +00:00
|
|
|
var lang = pk.Language;
|
|
|
|
if (pk.Format == 5 && lang == (int)Japanese)
|
|
|
|
data.AddLine(GetInvalid(string.Format(LOTLanguage, 0, Japanese), CheckIdentifier.Language));
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
lang = Math.Max(lang, 1);
|
|
|
|
VerifyTrade(data, t, lang);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
private static void VerifyTradeOTOnly(LegalityAnalysis data, IFixedTrainer t)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-08-12 23:01:16 +00:00
|
|
|
var result = CheckTradeOTOnly(data, t);
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(result);
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
private static CheckResult CheckTradeOTOnly(LegalityAnalysis data, IFixedTrainer t)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var pk = data.Entity;
|
|
|
|
if (pk.IsNicknamed && (pk.Format < 8 || pk.FatefulEncounter))
|
|
|
|
return GetInvalid(LEncTradeChangedNickname, CheckIdentifier.Nickname);
|
|
|
|
int lang = pk.Language;
|
2024-02-23 03:20:54 +00:00
|
|
|
if (!t.IsTrainerMatch(pk, pk.OriginalTrainerName, lang))
|
2022-06-18 18:04:24 +00:00
|
|
|
return GetInvalid(LEncTradeIndexBad, CheckIdentifier.Trainer);
|
|
|
|
return GetValid(LEncTradeUnchanged, CheckIdentifier.Nickname);
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
private static void VerifyTrade(LegalityAnalysis data, IEncounterTemplate t, int language)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-08-12 23:01:16 +00:00
|
|
|
if (t is IFixedTrainer { IsFixedTrainer: true } ft)
|
|
|
|
VerifyTrainerName(data, ft, language);
|
|
|
|
if (t is IFixedNickname { IsFixedNickname: true } fn)
|
|
|
|
VerifyNickname(data, fn, language);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2022-01-08 17:59:35 +00:00
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
private static void VerifyNickname(LegalityAnalysis data, IFixedNickname fn, int language)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var pk = data.Entity;
|
2023-08-12 23:01:16 +00:00
|
|
|
var result = fn.IsNicknameMatch(pk, pk.Nickname, language)
|
2022-06-18 18:04:24 +00:00
|
|
|
? GetValid(LEncTradeUnchanged, CheckIdentifier.Nickname)
|
|
|
|
: Get(LEncTradeChangedNickname, ParseSettings.NicknamedTrade, CheckIdentifier.Nickname);
|
|
|
|
data.AddLine(result);
|
|
|
|
}
|
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
private static void VerifyTrainerName(LegalityAnalysis data, IFixedTrainer ft, int language)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-08-12 23:01:16 +00:00
|
|
|
var pk = data.Entity;
|
2024-02-23 03:20:54 +00:00
|
|
|
if (!ft.IsTrainerMatch(pk, pk.OriginalTrainerName, language))
|
2023-08-12 23:01:16 +00:00
|
|
|
data.AddLine(GetInvalid(LEncTradeChangedOT, CheckIdentifier.Trainer));
|
2018-06-24 05:00:01 +00:00
|
|
|
}
|
|
|
|
}
|