2018-03-28 22:55:19 +00:00
|
|
|
namespace PKHeX.Core
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Minimal Trainer Information necessary for generating a <see cref="PKM"/>.
|
|
|
|
/// </summary>
|
2018-04-28 18:06:58 +00:00
|
|
|
public interface ITrainerInfo : ITrainerID
|
2018-03-28 22:55:19 +00:00
|
|
|
{
|
|
|
|
string OT { get; }
|
|
|
|
int Gender { get; }
|
|
|
|
int Game { get; }
|
|
|
|
int Language { get; }
|
|
|
|
|
|
|
|
int Generation { get; }
|
|
|
|
}
|
2018-03-29 03:34:58 +00:00
|
|
|
|
|
|
|
public static partial class Extensions
|
|
|
|
{
|
2020-06-17 02:46:22 +00:00
|
|
|
public static void ApplyTo(this ITrainerInfo info, PKM pk)
|
2018-03-29 03:34:58 +00:00
|
|
|
{
|
|
|
|
pk.OT_Name = info.OT;
|
|
|
|
pk.TID = info.TID;
|
2018-04-01 03:37:36 +00:00
|
|
|
pk.SID = pk.Format < 3 || pk.VC ? 0 : info.SID;
|
2018-03-29 03:34:58 +00:00
|
|
|
pk.OT_Gender = info.Gender;
|
|
|
|
pk.Language = info.Language;
|
|
|
|
pk.Version = info.Game;
|
|
|
|
|
2020-12-22 01:12:39 +00:00
|
|
|
if (pk is not IRegionOrigin tr)
|
2019-11-26 18:46:32 +00:00
|
|
|
return;
|
2020-07-31 20:53:42 +00:00
|
|
|
|
2020-12-22 01:12:39 +00:00
|
|
|
if (info is not IRegionOrigin o)
|
2020-07-31 20:53:42 +00:00
|
|
|
return;
|
|
|
|
tr.Country = o.Country;
|
|
|
|
tr.Region = o.Region;
|
|
|
|
tr.ConsoleRegion = o.ConsoleRegion;
|
2018-03-29 03:34:58 +00:00
|
|
|
}
|
2018-03-30 04:00:38 +00:00
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
public static void ApplyHandlingTrainerInfo(this ITrainerInfo sav, PKM pk, bool force = false)
|
2018-03-30 04:00:38 +00:00
|
|
|
{
|
2020-06-17 02:46:22 +00:00
|
|
|
if (pk.Format == sav.Generation && !force)
|
2018-03-30 04:00:38 +00:00
|
|
|
return;
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
pk.HT_Name = sav.OT;
|
|
|
|
pk.HT_Gender = sav.Gender;
|
2018-03-30 04:00:38 +00:00
|
|
|
pk.HT_Friendship = pk.OT_Friendship;
|
|
|
|
pk.CurrentHandler = 1;
|
|
|
|
|
2020-08-01 00:25:14 +00:00
|
|
|
if (pk is PK6 pk6 && sav is IRegionOrigin o)
|
2018-03-30 04:00:38 +00:00
|
|
|
{
|
2020-08-01 00:25:14 +00:00
|
|
|
pk6.Geo1_Country = o.Country;
|
|
|
|
pk6.Geo1_Region = o.Region;
|
2021-08-29 20:15:45 +00:00
|
|
|
pk6.SetTradeMemoryHT6(true);
|
|
|
|
}
|
|
|
|
else if (pk is PK8 pk8)
|
|
|
|
{
|
|
|
|
pk8.SetTradeMemoryHT8();
|
2018-03-30 04:00:38 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-26 03:40:57 +00:00
|
|
|
|
|
|
|
public static bool IsFromTrainer(this ITrainerInfo tr, PKM pk)
|
|
|
|
{
|
|
|
|
if (tr.Game == (int)GameVersion.Any)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (tr.TID != pk.TID)
|
|
|
|
return false;
|
|
|
|
if (tr.OT != pk.OT_Name)
|
|
|
|
return false;
|
|
|
|
if (pk.Format <= 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (tr.SID != pk.SID)
|
|
|
|
return false;
|
|
|
|
if (pk.Format == 3)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (tr.Gender != pk.OT_Gender)
|
|
|
|
return false;
|
|
|
|
if (tr.Game != pk.Version)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-29 03:34:58 +00:00
|
|
|
}
|
2018-03-28 22:55:19 +00:00
|
|
|
}
|