2022-06-18 18:04:24 +00:00
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
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.Language"/>.
|
|
|
|
/// </summary>
|
|
|
|
public sealed class LanguageVerifier : Verifier
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Language;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override void Verify(LegalityAnalysis data)
|
|
|
|
{
|
|
|
|
var pk = data.Entity;
|
|
|
|
int originalGeneration = data.Info.Generation;
|
|
|
|
int currentLanguage = pk.Language;
|
|
|
|
int maxLanguageID = Legal.GetMaxLanguageID(originalGeneration);
|
|
|
|
var enc = data.EncounterMatch;
|
|
|
|
if (!IsValidLanguageID(currentLanguage, maxLanguageID, pk, enc))
|
2018-06-24 05:00:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
data.AddLine(GetInvalid(string.Format(LOTLanguage, $"<={(LanguageID)maxLanguageID}", (LanguageID)currentLanguage)));
|
|
|
|
return;
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Korean Gen4 games can not trade with other Gen4 languages, but can use Pal Park with any Gen3 game/language.
|
|
|
|
if (pk.Format == 4 && enc.Generation == 4 && !IsValidG4Korean(currentLanguage)
|
|
|
|
&& enc is not EncounterTrade4PID {Species: (int)Species.Pikachu or (int)Species.Magikarp} // ger magikarp / eng pikachu
|
|
|
|
)
|
|
|
|
{
|
|
|
|
bool kor = currentLanguage == (int)LanguageID.Korean;
|
|
|
|
var msgpkm = kor ? L_XKorean : L_XKoreanNon;
|
|
|
|
var msgsav = kor ? L_XKoreanNon : L_XKorean;
|
|
|
|
data.AddLine(GetInvalid(string.Format(LTransferOriginFInvalid0_1, msgpkm, msgsav)));
|
|
|
|
return;
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (originalGeneration <= 2)
|
|
|
|
{
|
|
|
|
// Korean Crystal does not exist, neither do Korean VC1
|
|
|
|
if (pk.Korean && !GameVersion.GS.Contains((GameVersion)pk.Version))
|
|
|
|
data.AddLine(GetInvalid(string.Format(LOTLanguage, $"!={(LanguageID)currentLanguage}", (LanguageID)currentLanguage)));
|
2020-12-02 00:55:10 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Japanese VC is language locked; cannot obtain Japanese-Blue version as other languages.
|
|
|
|
if (pk.Version == (int)GameVersion.BU && !pk.Japanese)
|
|
|
|
data.AddLine(GetInvalid(string.Format(LOTLanguage, nameof(LanguageID.Japanese), (LanguageID)currentLanguage)));
|
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
|
|
|
public static bool IsValidLanguageID(int currentLanguage, int maxLanguageID, PKM pk, IEncounterTemplate enc)
|
|
|
|
{
|
|
|
|
if (currentLanguage == (int)LanguageID.UNUSED_6)
|
|
|
|
return false; // Language ID 6 is unused.
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (currentLanguage > maxLanguageID)
|
|
|
|
return false; // Language not available (yet)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (currentLanguage <= (int)LanguageID.Hacked && !(enc is EncounterTrade5PID && EncounterTrade5PID.IsValidMissingLanguage(pk)))
|
|
|
|
return false; // Missing Language value is not obtainable
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return true; // Language is possible
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Check if the <see cref="currentLanguage"/> can exist in the Generation 4 savefile.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="currentLanguage"></param>
|
|
|
|
public static bool IsValidG4Korean(int currentLanguage)
|
|
|
|
{
|
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
|
|
|
var activeTr = ParseSettings.ActiveTrainer;
|
|
|
|
var activeLang = activeTr.Language;
|
|
|
|
bool savKOR = activeLang == (int) LanguageID.Korean;
|
2022-06-18 18:04:24 +00:00
|
|
|
bool pkmKOR = currentLanguage == (int) LanguageID.Korean;
|
|
|
|
if (savKOR == pkmKOR)
|
|
|
|
return true;
|
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
|
|
|
return activeLang < 0; // check not overriden by Legality settings
|
2018-06-24 05:00:01 +00:00
|
|
|
}
|
|
|
|
}
|