2018-06-24 05:00:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using static PKHeX.Core.LegalityCheckStrings;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2018-07-02 02:17:37 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Verifies the <see cref="PKM.Nickname"/>.
|
|
|
|
|
/// </summary>
|
2018-06-24 05:00:01 +00:00
|
|
|
|
public sealed class NicknameVerifier : Verifier
|
|
|
|
|
{
|
|
|
|
|
protected override CheckIdentifier Identifier => CheckIdentifier.Nickname;
|
|
|
|
|
|
|
|
|
|
public override void Verify(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2018-08-02 03:39:20 +00:00
|
|
|
|
var EncounterMatch = data.EncounterOriginal;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
// If the Pokémon is not nicknamed, it should match one of the language strings.
|
|
|
|
|
if (pkm.Nickname.Length == 0)
|
|
|
|
|
{
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LNickLengthShort));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (pkm.Species > PKX.SpeciesLang[0].Length)
|
|
|
|
|
{
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(Get(LNickLengthShort, Severity.Indeterminate));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pkm.VC && pkm.IsNicknamed)
|
|
|
|
|
{
|
|
|
|
|
VerifyG1NicknameWithinBounds(data, pkm.Nickname);
|
|
|
|
|
}
|
|
|
|
|
else if (EncounterMatch is MysteryGift m)
|
|
|
|
|
{
|
|
|
|
|
if (pkm.IsNicknamed && !m.IsEgg)
|
2018-10-06 20:43:05 +00:00
|
|
|
|
data.AddLine(Get(LEncGiftNicknamed, ParseSettings.NicknamedMysteryGift));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
if (EncounterMatch is EncounterTrade t)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-10-27 20:37:03 +00:00
|
|
|
|
VerifyNicknameTrade(data, t);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pkm.IsEgg)
|
|
|
|
|
{
|
|
|
|
|
VerifyNicknameEgg(data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 05:40:20 +00:00
|
|
|
|
string nickname = pkm.Nickname.Replace('\'', '’');
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (VerifyUnNicknamedEncounter(data, pkm, nickname))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Non-nicknamed strings have already been checked.
|
2018-10-09 00:57:34 +00:00
|
|
|
|
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."));
|
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool VerifyUnNicknamedEncounter(LegalityAnalysis data, PKM pkm, string nickname)
|
|
|
|
|
{
|
|
|
|
|
if (pkm.IsNicknamed)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < PKX.SpeciesLang.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!PKX.SpeciesDict[i].TryGetValue(nickname, out int index))
|
|
|
|
|
continue;
|
2018-09-01 21:11:12 +00:00
|
|
|
|
var msg = index == pkm.Species && i != pkm.Language ? LNickMatchNoOthersFail : LNickMatchLanguageFlag;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
data.AddLine(Get(msg, Severity.Fishy));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-11-17 01:42:50 +00:00
|
|
|
|
if (StringConverter.HasEastAsianScriptCharacters(nickname) && !(pkm is PB7)) // East Asian Scripts
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LNickInvalidChar));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-10-27 23:06:06 +00:00
|
|
|
|
if (nickname.Length > Legal.GetMaxLengthNickname(data.Info.Generation, (LanguageID)pkm.Language))
|
2018-08-15 03:13:15 +00:00
|
|
|
|
{
|
2018-11-18 02:29:05 +00:00
|
|
|
|
var severe = data.EncounterOriginal.EggEncounter && pkm.WasTradedEgg && nickname.Length <= Legal.GetMaxLengthNickname(data.Info.Generation, LanguageID.English)
|
|
|
|
|
? Severity.Fishy
|
|
|
|
|
: Severity.Invalid;
|
|
|
|
|
data.AddLine(Get(LNickLengthLong, severe));
|
2018-08-15 03:13:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetValid(LNickMatchNoOthers));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
else if (pkm.Format < 3)
|
|
|
|
|
{
|
|
|
|
|
// pk1/pk2 IsNicknamed getter checks for match, logic should only reach here if matches.
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetValid(LNickMatchLanguage));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-08-02 03:39:20 +00:00
|
|
|
|
var EncounterMatch = data.EncounterOriginal;
|
2018-08-31 01:09:52 +00:00
|
|
|
|
bool valid = IsNicknameValid(pkm, EncounterMatch, nickname);
|
2018-09-01 21:11:12 +00:00
|
|
|
|
var result = valid ? GetValid(LNickMatchLanguage) : GetInvalid(LNickMatchLanguageFail);
|
2018-08-31 01:09:52 +00:00
|
|
|
|
data.AddLine(result);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2018-08-31 01:09:52 +00:00
|
|
|
|
private bool IsNicknameValid(PKM pkm, IEncounterable EncounterMatch, string nickname)
|
|
|
|
|
{
|
|
|
|
|
if (PKX.GetSpeciesNameGeneration(pkm.Species, pkm.Language, pkm.Format) == nickname)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// Can't have another language name if it hasn't evolved or wasn't a language-traded egg.
|
|
|
|
|
bool evolved = EncounterMatch.Species != pkm.Species;
|
|
|
|
|
if ((pkm.WasTradedEgg || evolved) && !PKX.IsNicknamedAnyLanguage(pkm.Species, nickname, pkm.Format))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
switch (EncounterMatch)
|
|
|
|
|
{
|
|
|
|
|
case WC7 wc7 when wc7.IsAshGreninjaWC7(pkm):
|
|
|
|
|
return true;
|
|
|
|
|
case ILangNick loc:
|
|
|
|
|
if (loc.Language != 0 && !loc.IsNicknamed && !PKX.IsNicknamedAnyLanguage(pkm.Species, nickname, pkm.Format))
|
|
|
|
|
return true; // fixed language without nickname, nice job event maker!
|
|
|
|
|
break;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-08-31 01:09:52 +00:00
|
|
|
|
|
|
|
|
|
if (pkm.Format == 5 && !pkm.IsNative) // transfer
|
|
|
|
|
{
|
|
|
|
|
if (evolved)
|
|
|
|
|
return !PKX.IsNicknamedAnyLanguage(pkm.Species, nickname, 4);
|
|
|
|
|
return PKX.GetSpeciesNameGeneration(pkm.Species, pkm.Language, 4) == nickname;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void VerifyNicknameEgg(LegalityAnalysis data)
|
|
|
|
|
{
|
|
|
|
|
var Info = data.Info;
|
|
|
|
|
var pkm = data.pkm;
|
|
|
|
|
var EncounterMatch = Info.EncounterMatch;
|
|
|
|
|
switch (pkm.Format)
|
|
|
|
|
{
|
|
|
|
|
case 4:
|
|
|
|
|
if (pkm.IsNicknamed) // gen4 doesn't use the nickname flag for eggs
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LNickFlagEggNo, CheckIdentifier.Egg));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
break;
|
|
|
|
|
case 7:
|
|
|
|
|
if (EncounterMatch is EncounterStatic ^ !pkm.IsNicknamed) // gen7 doesn't use for ingame gifts
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(pkm.IsNicknamed ? LNickFlagEggNo : LNickFlagEggYes, CheckIdentifier.Egg));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (!pkm.IsNicknamed)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LNickFlagEggYes, CheckIdentifier.Egg));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pkm.Format == 2 && pkm.IsEgg && !PKX.IsNicknamedAnyLanguage(0, pkm.Nickname, 2))
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetValid(LNickMatchLanguageEgg, CheckIdentifier.Egg));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
else if (PKX.GetSpeciesNameGeneration(0, pkm.Language, Info.Generation) != pkm.Nickname)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LNickMatchLanguageEggFail, CheckIdentifier.Egg));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
else
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetValid(LNickMatchLanguageEgg, CheckIdentifier.Egg));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
private void VerifyNicknameTrade(LegalityAnalysis data, EncounterTrade t)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
switch (data.Info.Generation)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
2018-10-27 20:37:03 +00:00
|
|
|
|
case 2: VerifyTrade12(data, t); return;
|
|
|
|
|
case 3: VerifyTrade3(data, t); return;
|
|
|
|
|
case 4: VerifyTrade4(data, t); return;
|
|
|
|
|
case 5: VerifyTrade5(data, t); return;
|
|
|
|
|
case 6:
|
|
|
|
|
case 7: VerifyTrade(data, t, data.pkm.Language); return;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void VerifyG1NicknameWithinBounds(LegalityAnalysis data, string str)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2019-03-21 04:50:44 +00:00
|
|
|
|
if (StringConverter12.GetIsG1English(str))
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (str.Length > 10)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LNickLengthLong));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2019-03-21 04:50:44 +00:00
|
|
|
|
else if (StringConverter12.GetIsG1Japanese(str))
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (str.Length > 5)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LNickLengthLong));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2019-03-21 04:50:44 +00:00
|
|
|
|
else if (pkm.Korean && StringConverter2KOR.GetIsG2Korean(str))
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (str.Length > 5)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LNickLengthLong));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LG1CharNick));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
private void VerifyTrade12(LegalityAnalysis data, EncounterTrade t)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-10-27 20:37:03 +00:00
|
|
|
|
if (t.TID != 0) // Gen2 Trade
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return; // already checked all relevant properties when fetching with getValidEncounterTradeVC2
|
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
if (!EncounterGenerator.IsEncounterTrade1Valid(data.pkm, t))
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LEncTradeChangedOT, CheckIdentifier.Trainer));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
private void VerifyTrade3(LegalityAnalysis data, EncounterTrade t)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2018-10-27 20:37:03 +00:00
|
|
|
|
int lang = pkm.Language;
|
|
|
|
|
if (t.Species == 124) // FRLG Jynx
|
|
|
|
|
lang = DetectTradeLanguageG3DANTAEJynx(pkm, lang);
|
|
|
|
|
VerifyTrade(data, t, lang);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
private void VerifyTrade4(LegalityAnalysis data, EncounterTrade t)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
|
|
|
|
if (pkm.TID == 1000)
|
|
|
|
|
{
|
2018-10-27 20:37:03 +00:00
|
|
|
|
VerifyTradeOTOnly(data, t);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-10-27 20:37:03 +00:00
|
|
|
|
int lang = pkm.Language;
|
|
|
|
|
switch (t.Species)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-10-27 20:37:03 +00:00
|
|
|
|
case 25: // HGSS Pikachu
|
|
|
|
|
lang = DetectTradeLanguageG4SurgePikachu(pkm, t, lang);
|
|
|
|
|
// flag korean on gen4 saves since the pkm.Language is German
|
|
|
|
|
FlagKoreanIncompatibleSameGenTrade(data, pkm, lang);
|
|
|
|
|
break;
|
|
|
|
|
case 129: // DPPt Magikarp
|
|
|
|
|
lang = DetectTradeLanguageG4MeisterMagikarp(pkm, t, lang);
|
|
|
|
|
// flag korean on gen4 saves since the pkm.Language is German
|
|
|
|
|
FlagKoreanIncompatibleSameGenTrade(data, pkm, lang);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (lang == 1 && (pkm.Version == (int)GameVersion.D || pkm.Version == (int)GameVersion.P))
|
|
|
|
|
{
|
|
|
|
|
// DP English origin are Japanese lang
|
|
|
|
|
if (pkm.OT_Name != t.TrainerNames[1]) // not japanese
|
|
|
|
|
lang = 2; // English
|
|
|
|
|
}
|
|
|
|
|
break;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-10-27 20:37:03 +00:00
|
|
|
|
VerifyTrade(data, t, lang);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void FlagKoreanIncompatibleSameGenTrade(LegalityAnalysis data, PKM pkm, int lang)
|
|
|
|
|
{
|
|
|
|
|
if (pkm.Format != 4 || lang != (int)LanguageID.Korean)
|
|
|
|
|
return; // transferred or not appropriate
|
|
|
|
|
if (ParseSettings.ActiveTrainer.Language != (int)LanguageID.Korean && ParseSettings.ActiveTrainer.Language >= 0)
|
|
|
|
|
data.AddLine(GetInvalid(string.Format(LTransferOriginFInvalid0_1, L_XKorean, L_XKoreanNon), CheckIdentifier.Language));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int DetectTradeLanguage(string OT, EncounterTrade t, int currentLanguageID)
|
|
|
|
|
{
|
|
|
|
|
var names = t.TrainerNames;
|
|
|
|
|
for (int lang = 1; lang < names.Length; lang++)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-10-27 20:37:03 +00:00
|
|
|
|
if (names[lang] != OT)
|
|
|
|
|
continue;
|
|
|
|
|
return lang;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-10-27 20:37:03 +00:00
|
|
|
|
return currentLanguageID;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
private static int DetectTradeLanguageG3DANTAEJynx(PKM pk, int currentLanguageID)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-10-27 20:37:03 +00:00
|
|
|
|
if (currentLanguageID != (int)LanguageID.Italian)
|
|
|
|
|
return currentLanguageID;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
if (pk.Version == (int)GameVersion.LG)
|
2018-10-27 20:37:03 +00:00
|
|
|
|
currentLanguageID = (int)LanguageID.English; // translation error; OT was not localized => same as English
|
|
|
|
|
return currentLanguageID;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
private static int DetectTradeLanguageG4MeisterMagikarp(PKM pkm, EncounterTrade t, int currentLanguageID)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-10-27 20:37:03 +00:00
|
|
|
|
if (currentLanguageID == (int)LanguageID.English)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return (int)LanguageID.German;
|
|
|
|
|
|
|
|
|
|
// All have German, regardless of origin version.
|
2018-10-27 20:37:03 +00:00
|
|
|
|
var lang = DetectTradeLanguage(pkm.OT_Name, t, currentLanguageID);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (lang == 2) // possible collision with FR/ES/DE. Check nickname
|
2018-10-27 20:37:03 +00:00
|
|
|
|
return pkm.Nickname == t.Nicknames[(int)LanguageID.French] ? (int)LanguageID.French : (int)LanguageID.Spanish; // Spanish is same as English
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
return lang;
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
private static int DetectTradeLanguageG4SurgePikachu(PKM pkm, EncounterTrade t, int currentLanguageID)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-10-27 20:37:03 +00:00
|
|
|
|
if (currentLanguageID == (int)LanguageID.French)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
return (int)LanguageID.English;
|
|
|
|
|
|
|
|
|
|
// All have English, regardless of origin version.
|
2018-10-27 20:37:03 +00:00
|
|
|
|
var lang = DetectTradeLanguage(pkm.OT_Name, t, currentLanguageID);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
if (lang == 2) // possible collision with ES/IT. Check nickname
|
2018-10-27 20:37:03 +00:00
|
|
|
|
return pkm.Nickname == t.Nicknames[(int)LanguageID.Italian] ? (int)LanguageID.Italian : (int)LanguageID.Spanish;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
return lang;
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
private void VerifyTrade5(LegalityAnalysis data, EncounterTrade t)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
2018-10-27 20:37:03 +00:00
|
|
|
|
int lang = pkm.Language;
|
2018-06-24 05:00:01 +00:00
|
|
|
|
// Trades for JPN games have language ID of 0, not 1.
|
|
|
|
|
if (pkm.BW)
|
|
|
|
|
{
|
|
|
|
|
if (pkm.Format == 5 && lang == (int)LanguageID.Japanese)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(string.Format(LOTLanguage, 0, LanguageID.Japanese), CheckIdentifier.Language));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
lang = Math.Max(lang, 1);
|
2018-10-27 20:37:03 +00:00
|
|
|
|
VerifyTrade(data, t, lang);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
else // B2W2
|
|
|
|
|
{
|
2018-10-27 20:37:03 +00:00
|
|
|
|
if (t.TID == Encounters5.YancyTID || t.TID == Encounters5.CurtisTID)
|
|
|
|
|
VerifyTradeOTOnly(data, t);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
else
|
2018-10-27 20:37:03 +00:00
|
|
|
|
VerifyTrade(data, t, lang);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
private static void VerifyTradeOTOnly(LegalityAnalysis data, EncounterTrade t)
|
2018-07-27 02:34:27 +00:00
|
|
|
|
{
|
2018-10-27 20:37:03 +00:00
|
|
|
|
var result = CheckTradeOTOnly(data, t.TrainerNames);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
data.AddLine(result);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
private static CheckResult CheckTradeOTOnly(LegalityAnalysis data, string[] validOT)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
|
|
|
|
var pkm = data.pkm;
|
|
|
|
|
if (pkm.IsNicknamed)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(LEncTradeChangedNickname, CheckIdentifier.Nickname);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
int lang = pkm.Language;
|
|
|
|
|
if (validOT.Length <= lang)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(LEncTradeIndexBad, CheckIdentifier.Trainer);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
if (validOT[lang] != pkm.OT_Name)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
return GetInvalid(LEncTradeChangedOT, CheckIdentifier.Trainer);
|
|
|
|
|
return GetValid(LEncTradeUnchanged, CheckIdentifier.Nickname);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
private static void VerifyTrade(LegalityAnalysis data, EncounterTrade t, int language)
|
2018-06-24 05:00:01 +00:00
|
|
|
|
{
|
2018-10-27 20:37:03 +00:00
|
|
|
|
var ot = t.GetOT(language);
|
|
|
|
|
var nick = t.GetNickname(language);
|
|
|
|
|
VerifyTradeOTNick(data, t, nick, ot);
|
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
private static void VerifyTradeOTNick(LegalityAnalysis data, EncounterTrade t, string nick, string OT)
|
|
|
|
|
{
|
2018-06-24 05:00:01 +00:00
|
|
|
|
var pkm = data.pkm;
|
2018-10-06 20:43:05 +00:00
|
|
|
|
// trades that are not nicknamed (but are present in a table with others being named)
|
2018-10-27 20:37:03 +00:00
|
|
|
|
var result = IsNicknameMatch(nick, pkm, t)
|
2018-10-06 20:43:05 +00:00
|
|
|
|
? GetValid(LEncTradeUnchanged, CheckIdentifier.Nickname)
|
|
|
|
|
: Get(LEncTradeChangedNickname, ParseSettings.NicknamedTrade, CheckIdentifier.Nickname);
|
|
|
|
|
data.AddLine(result);
|
2018-06-24 05:00:01 +00:00
|
|
|
|
|
|
|
|
|
if (OT != pkm.OT_Name)
|
2018-09-01 21:11:12 +00:00
|
|
|
|
data.AddLine(GetInvalid(LEncTradeChangedOT, CheckIdentifier.Trainer));
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-10-27 20:37:03 +00:00
|
|
|
|
private static bool IsNicknameMatch(string nick, ILangNick pkm, IEncounterable EncounterMatch)
|
2018-07-27 02:34:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (nick == "Quacklin’" && pkm.Nickname == "Quacklin'")
|
|
|
|
|
return true;
|
2018-08-27 01:32:39 +00:00
|
|
|
|
var trade = (EncounterTrade) EncounterMatch;
|
|
|
|
|
if (trade.IsNicknamed != pkm.IsNicknamed)
|
|
|
|
|
return false;
|
|
|
|
|
if (nick != pkm.Nickname) // if not match, must not be a nicknamed trade && not currently named
|
|
|
|
|
return !trade.IsNicknamed && !pkm.IsNicknamed;
|
|
|
|
|
return true;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
}
|
2018-06-24 05:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|