PKHeX/PKHeX.Core/Editing/PKM/EntityTemplates.cs
Kurt 88830e0d00
Update from .NET Framework 4.6 to .NET 7 (#3729)
Updates from net46->net7, dropping support for mono in favor of using the latest runtime (along with the performance/API improvements). Releases will be posted as 64bit only for now.

Refactors a good amount of internal API methods to be more performant and more customizable for future updates & fixes.

Adds functionality for Batch Editor commands to `>`, `<` and <=/>=

TID/SID properties renamed to TID16/SID16 for clarity; other properties exposed for Gen7 / display variants.

Main window has a new layout to account for DPI scaling (8 point grid)

Fixed: Tatsugiri and Paldean Tauros now output Showdown form names as Showdown expects
Changed: Gen9 species now interact based on the confirmed National Dex IDs (closes #3724)
Fixed: Pokedex set all no longer clears species with unavailable non-base forms (closes #3720)
Changed: Hyper Training suggestions now apply for level 50 in SV. (closes #3714)
Fixed: B2/W2 hatched egg met locations exclusive to specific versions are now explicitly checked (closes #3691)
Added: Properties for ribbon/mark count (closes #3659)
Fixed: Traded SV eggs are now checked correctly (closes #3692)
2023-01-21 20:02:33 -08:00

76 lines
2.1 KiB
C#

using System;
namespace PKHeX.Core;
/// <summary>
/// Logic for filling in template data for <see cref="PKM"/> objects.
/// </summary>
public static class EntityTemplates
{
/// <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)
{
pk.Move1 = (int)Move.Pound;
pk.HealPP();
pk.Ball = 4;
pk.MetDate = DateOnly.FromDateTime(DateTime.Today);
if (tr.Game >= 0)
pk.Version = tr.Game;
pk.Species = GetTemplateSpecies(pk, tr);
pk.Language = GetTemplateLanguage(tr);
pk.Gender = pk.GetSaneGender();
pk.ClearNickname();
pk.OT_Name = tr.OT;
pk.OT_Gender = tr.Gender;
pk.ID32 = tr.ID32;
if (tr is IRegionOrigin o && pk is IRegionOrigin gt)
{
gt.ConsoleRegion = o.ConsoleRegion;
gt.Country = o.Country;
gt.Region = o.Region;
}
ApplyTrashBytes(pk, tr);
pk.RefreshChecksum();
}
private static void ApplyTrashBytes(PKM pk, ITrainerInfo tr)
{
// Copy OT trash bytes for sensitive games (Gen1/2)
if (pk is not GBPKM pk12)
return;
switch (tr)
{
case SAV1 s1:
s1.OT_Trash.CopyTo(pk12.OT_Trash);
break;
case SAV2 s2:
s2.OT_Trash.CopyTo(pk12.OT_Trash);
break;
}
}
private static ushort GetTemplateSpecies(PKM pk, ITrainerInfo tr)
{
ushort 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;
}
}