2018-06-24 05:00:01 +00:00
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2018-07-02 02:17:37 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies the <see cref="PKM.Language"/>.
|
|
|
|
|
/// </summary>
|
2018-06-24 05:00:01 +00:00
|
|
|
|
public sealed class LanguageVerifier : Verifier
|
|
|
|
|
{
|
|
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Language;
|
|
|
|
|
|
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
|
|
|
|
int originalGeneration = data.Info.Generation;
|
|
|
|
|
int currentLanguage = pkm.Language;
|
|
|
|
|
int maxLanguageID = Legal.GetMaxLanguageID(originalGeneration);
|
|
|
|
|
|
|
|
|
|
if (!IsValidLanguageID(currentLanguage, maxLanguageID, pkm))
|
|
|
|
|
{
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(string.Format(LOTLanguage, $"<={(LanguageID)maxLanguageID}", (LanguageID)currentLanguage)));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Korean Gen4 games can not trade with other Gen4 languages, but can use Pal Park with any Gen3 game/language.
|
2018-08-23 05:36:56 +00:00
|
|
|
|
if (pkm.Format == 4 && pkm.Gen4 && !IsValidG4Korean(currentLanguage)
|
|
|
|
|
&& !(data.EncounterMatch is EncounterTrade x && (x.Species == 25 || x.Species == 129)) // ger magikarp / eng pikachu
|
|
|
|
|
)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
bool kor = currentLanguage == (int)LanguageID.Korean;
|
2018-09-01 21:11:12 +00:00
|
|
|
|
var msgpkm = kor ? L_XKorean : L_XKoreanNon;
|
|
|
|
|
var msgsav = kor ? L_XKoreanNon : L_XKorean;
|
|
|
|
|
data.AddLine(GetInvalid(string.Format(LTransferOriginFInvalid0_1, msgpkm, msgsav)));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Korean Crystal does not exist, neither do VC1
|
|
|
|
|
if (originalGeneration <= 2 && pkm.Korean && !GameVersion.GS.Contains((GameVersion)pkm.Version))
|
|
|
|
|
{
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(string.Format(LOTLanguage, $"!={(LanguageID)currentLanguage}", (LanguageID)currentLanguage)));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsValidLanguageID(int currentLanguage, int maxLanguageID, PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
if (currentLanguage == (int)LanguageID.UNUSED_6)
|
|
|
|
|
return false; // Language ID 6 is unused.
|
|
|
|
|
|
|
|
|
|
if (currentLanguage > maxLanguageID)
|
|
|
|
|
return false; // Language not available (yet)
|
|
|
|
|
|
|
|
|
|
if (currentLanguage <= (int) LanguageID.Hacked && !Legal.IsValidMissingLanguage(pkm))
|
|
|
|
|
return false; // Missing Language value is not obtainable
|
|
|
|
|
|
|
|
|
|
return true; // Language is possible
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Check if the <see cref="currentLanguage"/> can exist in the Generation 4 savefile.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="currentLanguage"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool IsValidG4Korean(int currentLanguage)
|
|
|
|
|
{
|
2018-10-06 02:58:30 +00:00
|
|
|
|
bool savKOR = ParseSettings.ActiveTrainer.Language == (int) LanguageID.Korean;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
bool pkmKOR = currentLanguage == (int) LanguageID.Korean;
|
|
|
|
|
if (savKOR == pkmKOR)
|
|
|
|
|
return true;
|
|
|
|
|
|
2018-10-06 02:58:30 +00:00
|
|
|
|
return ParseSettings.ActiveTrainer.Language < 0; // check not overriden by Legality settings
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|