2020-11-30 02:17:15 +00:00
|
|
|
|
using static PKHeX.Core.Species;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
2020-07-18 20:36:30 +00:00
|
|
|
|
{
|
2021-09-16 01:13:17 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 2 Trade Encounter
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <inheritdoc cref="EncounterTradeGB"/>
|
2020-12-24 08:06:40 +00:00
|
|
|
|
public sealed record EncounterTrade2 : EncounterTradeGB
|
2020-07-18 20:36:30 +00:00
|
|
|
|
{
|
2020-08-30 22:35:59 +00:00
|
|
|
|
public override int Generation => 2;
|
2021-05-19 00:14:17 +00:00
|
|
|
|
public override int Location => Locations.LinkTrade2NPC;
|
2020-08-30 22:35:59 +00:00
|
|
|
|
|
2022-03-07 07:25:47 +00:00
|
|
|
|
public EncounterTrade2(ushort species, byte level, ushort tid) : base(species, level, GameVersion.GSC)
|
2020-07-18 20:36:30 +00:00
|
|
|
|
{
|
|
|
|
|
TID = tid;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-08 01:29:36 +00:00
|
|
|
|
public override bool IsMatchExact(PKM pkm, EvoCriteria evo)
|
2020-07-18 20:36:30 +00:00
|
|
|
|
{
|
|
|
|
|
if (Level > pkm.CurrentLevel) // minimum required level
|
|
|
|
|
return false;
|
|
|
|
|
if (TID != pkm.TID)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (pkm.Format <= 2)
|
|
|
|
|
{
|
|
|
|
|
if (Gender >= 0 && Gender != pkm.Gender)
|
|
|
|
|
return false;
|
2022-03-14 02:24:08 +00:00
|
|
|
|
if (IVs.Count != 0 && !Legal.GetIsFixedIVSequenceValidNoRand((int[])IVs, pkm))
|
2020-07-18 20:36:30 +00:00
|
|
|
|
return false;
|
2021-01-05 01:31:43 +00:00
|
|
|
|
if (pkm.Format == 2 && pkm.Met_Location is not (0 or 126))
|
2020-07-18 20:36:30 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!IsValidTradeOTGender(pkm))
|
|
|
|
|
return false;
|
|
|
|
|
return IsValidTradeOTName(pkm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IsValidTradeOTGender(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
if (OTGender == 1)
|
|
|
|
|
{
|
|
|
|
|
// Female, can be cleared if traded to RBY (clears met location)
|
|
|
|
|
if (pkm.Format <= 2)
|
|
|
|
|
return pkm.OT_Gender == (pkm.Met_Location != 0 ? 1 : 0);
|
|
|
|
|
return pkm.OT_Gender == 0 || !pkm.VC1; // require male except if transferred from GSC
|
|
|
|
|
}
|
|
|
|
|
return pkm.OT_Gender == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IsValidTradeOTName(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
var OT = pkm.OT_Name;
|
|
|
|
|
if (pkm.Japanese)
|
|
|
|
|
return GetOT((int)LanguageID.Japanese) == OT;
|
|
|
|
|
if (pkm.Korean)
|
|
|
|
|
return GetOT((int)LanguageID.Korean) == OT;
|
|
|
|
|
|
2020-11-30 02:17:15 +00:00
|
|
|
|
var lang = GetInternationalLanguageID(OT);
|
|
|
|
|
if (pkm.Format < 7)
|
|
|
|
|
return lang != -1;
|
|
|
|
|
|
|
|
|
|
switch (Species)
|
|
|
|
|
{
|
|
|
|
|
case (int)Voltorb when pkm.Language == (int)LanguageID.French:
|
|
|
|
|
if (lang == (int)LanguageID.Spanish)
|
|
|
|
|
return false;
|
|
|
|
|
if (lang != -1)
|
|
|
|
|
return true;
|
|
|
|
|
return OT == "FALCçN"; // FALCÁN
|
|
|
|
|
|
|
|
|
|
case (int)Shuckle when pkm.Language == (int)LanguageID.French:
|
|
|
|
|
if (lang == (int)LanguageID.Spanish)
|
|
|
|
|
return false;
|
|
|
|
|
if (lang != -1)
|
|
|
|
|
return true;
|
|
|
|
|
return OT == "MANôA"; // MANÍA
|
|
|
|
|
|
|
|
|
|
default: return lang != -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int GetInternationalLanguageID(string OT)
|
|
|
|
|
{
|
2020-07-18 20:36:30 +00:00
|
|
|
|
const int start = (int)LanguageID.English;
|
|
|
|
|
const int end = (int)LanguageID.Spanish;
|
|
|
|
|
|
2020-11-30 02:17:15 +00:00
|
|
|
|
var tr = TrainerNames;
|
2020-07-18 20:36:30 +00:00
|
|
|
|
for (int i = start; i <= end; i++)
|
|
|
|
|
{
|
2020-11-30 02:17:15 +00:00
|
|
|
|
if (tr[i] == OT)
|
|
|
|
|
return i;
|
2020-07-18 20:36:30 +00:00
|
|
|
|
}
|
2020-11-30 02:17:15 +00:00
|
|
|
|
return -1;
|
2020-07-18 20:36:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|