2019-05-30 05:40:39 +00:00
|
|
|
|
using System;
|
2019-05-30 04:35:52 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2019-07-14 22:06:45 +00:00
|
|
|
|
/// <summary>
|
2021-06-08 03:02:57 +00:00
|
|
|
|
/// Logic for filling in template data for <see cref="PKM"/> objects.
|
2019-07-14 22:06:45 +00:00
|
|
|
|
/// </summary>
|
2021-06-08 03:02:57 +00:00
|
|
|
|
public static class EntityTemplates
|
2019-05-30 04:35:52 +00:00
|
|
|
|
{
|
2019-05-30 05:40:39 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Applies junk data to a <see cref="SaveFile.BlankPKM"/>, which is preferable to a completely empty entity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pk">Blank data</param>
|
|
|
|
|
/// <param name="tr">Trainer info to apply</param>
|
|
|
|
|
public static void TemplateFields(PKM pk, ITrainerInfo tr)
|
|
|
|
|
{
|
2021-01-27 16:40:37 +00:00
|
|
|
|
pk.Move1 = (int)Move.Pound;
|
|
|
|
|
pk.HealPP();
|
2019-05-30 05:40:39 +00:00
|
|
|
|
pk.Ball = 4;
|
|
|
|
|
pk.MetDate = DateTime.Today;
|
|
|
|
|
|
|
|
|
|
if (tr.Game >= 0)
|
|
|
|
|
pk.Version = tr.Game;
|
2021-06-08 03:02:57 +00:00
|
|
|
|
|
|
|
|
|
pk.Species = GetTemplateSpecies(pk, tr);
|
|
|
|
|
pk.Language = GetTemplateLanguage(tr);
|
2019-12-01 07:44:37 +00:00
|
|
|
|
pk.Gender = pk.GetSaneGender();
|
2019-05-30 05:40:39 +00:00
|
|
|
|
|
|
|
|
|
pk.ClearNickname();
|
|
|
|
|
|
|
|
|
|
pk.OT_Name = tr.OT;
|
|
|
|
|
pk.OT_Gender = tr.Gender;
|
|
|
|
|
pk.TID = tr.TID;
|
|
|
|
|
pk.SID = tr.SID;
|
2020-07-31 20:53:42 +00:00
|
|
|
|
if (tr is IRegionOrigin o && pk is IRegionOrigin gt)
|
2019-05-30 05:40:39 +00:00
|
|
|
|
{
|
2020-07-31 20:53:42 +00:00
|
|
|
|
gt.ConsoleRegion = o.ConsoleRegion;
|
|
|
|
|
gt.Country = o.Country;
|
|
|
|
|
gt.Region = o.Region;
|
2019-05-30 05:40:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 03:02:57 +00:00
|
|
|
|
ApplyTrashBytes(pk, tr);
|
|
|
|
|
pk.RefreshChecksum();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ApplyTrashBytes(PKM pk, ITrainerInfo tr)
|
|
|
|
|
{
|
2019-05-30 05:40:39 +00:00
|
|
|
|
// Copy OT trash bytes for sensitive games (Gen1/2)
|
2021-06-08 03:02:57 +00:00
|
|
|
|
if (pk is not GBPKM pk12)
|
|
|
|
|
return;
|
|
|
|
|
switch (tr)
|
2019-07-14 22:06:45 +00:00
|
|
|
|
{
|
2021-06-08 03:02:57 +00:00
|
|
|
|
case SAV1 s1:
|
|
|
|
|
pk12.OT_Trash = s1.OT_Trash;
|
|
|
|
|
break;
|
|
|
|
|
case SAV2 s2:
|
|
|
|
|
pk12.OT_Trash = s2.OT_Trash;
|
|
|
|
|
break;
|
2019-07-14 22:06:45 +00:00
|
|
|
|
}
|
2021-06-08 03:02:57 +00:00
|
|
|
|
}
|
2019-05-30 05:50:34 +00:00
|
|
|
|
|
2021-06-08 03:02:57 +00:00
|
|
|
|
private static int GetTemplateSpecies(PKM pk, ITrainerInfo tr)
|
|
|
|
|
{
|
|
|
|
|
int species = tr is IGameValueLimit s ? s.MaxSpeciesID : ((GameVersion)pk.Version).GetMaxSpeciesID();
|
|
|
|
|
if (species <= 0)
|
|
|
|
|
species = pk.MaxSpeciesID;
|
|
|
|
|
return species;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int GetTemplateLanguage(ITrainerInfo tr)
|
|
|
|
|
{
|
|
|
|
|
var lang = tr.Language;
|
|
|
|
|
if (lang <= 0)
|
|
|
|
|
lang = (int)LanguageID.English;
|
|
|
|
|
return lang;
|
2019-05-30 05:40:39 +00:00
|
|
|
|
}
|
2019-05-30 04:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|