mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-10 14:44:24 +00:00
88830e0d00
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)
154 lines
5 KiB
C#
154 lines
5 KiB
C#
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Tracks Geolocation history of a <see cref="PKM"/>
|
|
/// </summary>
|
|
public interface IGeoTrack : IRegionOrigin
|
|
{
|
|
byte Geo1_Region { get; set; }
|
|
byte Geo2_Region { get; set; }
|
|
byte Geo3_Region { get; set; }
|
|
byte Geo4_Region { get; set; }
|
|
byte Geo5_Region { get; set; }
|
|
byte Geo1_Country { get; set; }
|
|
byte Geo2_Country { get; set; }
|
|
byte Geo3_Country { get; set; }
|
|
byte Geo4_Country { get; set; }
|
|
byte Geo5_Country { get; set; }
|
|
}
|
|
|
|
public static partial class Extensions
|
|
{
|
|
/// <summary>
|
|
/// Clears all Geolocation history.
|
|
/// </summary>
|
|
public static void ClearGeoLocationData(this IGeoTrack g)
|
|
{
|
|
g.Geo1_Country = g.Geo2_Country = g.Geo3_Country = g.Geo4_Country = g.Geo5_Country = 0;
|
|
g.Geo1_Region = g.Geo2_Region = g.Geo3_Region = g.Geo4_Region = g.Geo5_Region = 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserts a new Geolocation tuple to the <see cref="IGeoTrack"/> values.
|
|
/// </summary>
|
|
/// <param name="g">Object tracking the geolocation history</param>
|
|
/// <param name="GeoCountry">Newly arrived country</param>
|
|
/// <param name="GeoRegion">Newly arrived region</param>
|
|
public static void TradeGeoLocation(this IGeoTrack g, byte GeoCountry, byte GeoRegion)
|
|
{
|
|
// Trickle existing values up one slot
|
|
g.Geo5_Country = g.Geo4_Country;
|
|
g.Geo5_Region = g.Geo4_Region;
|
|
|
|
g.Geo4_Country = g.Geo3_Country;
|
|
g.Geo4_Region = g.Geo3_Region;
|
|
|
|
g.Geo3_Country = g.Geo2_Country;
|
|
g.Geo3_Region = g.Geo2_Region;
|
|
|
|
g.Geo2_Country = g.Geo1_Country;
|
|
g.Geo2_Region = g.Geo1_Region;
|
|
|
|
g.Geo1_Country = GeoCountry;
|
|
g.Geo1_Region = GeoRegion;
|
|
}
|
|
|
|
public static void SanitizeGeoLocationData(this IGeoTrack g)
|
|
{
|
|
if (g.Geo1_Country == 0) g.Geo1_Region = 0;
|
|
if (g.Geo2_Country == 0) g.Geo2_Region = 0;
|
|
if (g.Geo3_Country == 0) g.Geo3_Region = 0;
|
|
if (g.Geo4_Country == 0) g.Geo4_Region = 0;
|
|
if (g.Geo5_Country == 0) g.Geo5_Region = 0;
|
|
|
|
// trickle down empty slots
|
|
while (true)
|
|
{
|
|
if (g.Geo5_Country != 0 && g.Geo4_Country == 0)
|
|
{
|
|
g.Geo4_Country = g.Geo5_Country;
|
|
g.Geo4_Region = g.Geo5_Region;
|
|
g.Geo5_Country = g.Geo5_Region = 0;
|
|
}
|
|
if (g.Geo4_Country != 0 && g.Geo3_Country == 0)
|
|
{
|
|
g.Geo3_Country = g.Geo4_Country;
|
|
g.Geo3_Region = g.Geo4_Region;
|
|
g.Geo4_Country = g.Geo4_Region = 0;
|
|
continue;
|
|
}
|
|
if (g.Geo3_Country != 0 && g.Geo2_Country == 0)
|
|
{
|
|
g.Geo2_Country = g.Geo3_Country;
|
|
g.Geo2_Region = g.Geo3_Region;
|
|
g.Geo3_Country = g.Geo3_Region = 0;
|
|
continue;
|
|
}
|
|
if (g.Geo2_Country != 0 && g.Geo1_Country == 0)
|
|
{
|
|
g.Geo1_Country = g.Geo2_Country;
|
|
g.Geo1_Region = g.Geo2_Region;
|
|
g.Geo2_Country = g.Geo2_Region = 0;
|
|
continue;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if all Geolocation tuples are valid.
|
|
/// </summary>
|
|
/// <param name="g"></param>
|
|
/// <returns></returns>
|
|
public static bool GetIsValid(this IGeoTrack g) => g.GetValidity() == GeoValid.Valid;
|
|
|
|
/// <summary>
|
|
/// Checks if all Geolocation tuples are valid.
|
|
/// </summary>
|
|
internal static GeoValid GetValidity(this IGeoTrack g)
|
|
{
|
|
bool end = false;
|
|
GeoValid result;
|
|
if ((result = UpdateCheck(g.Geo1_Country, g.Geo1_Region, ref end)) != GeoValid.Valid)
|
|
return result;
|
|
if ((result = UpdateCheck(g.Geo2_Country, g.Geo2_Region, ref end)) != GeoValid.Valid)
|
|
return result;
|
|
if ((result = UpdateCheck(g.Geo3_Country, g.Geo3_Region, ref end)) != GeoValid.Valid)
|
|
return result;
|
|
if ((result = UpdateCheck(g.Geo4_Country, g.Geo4_Region, ref end)) != GeoValid.Valid)
|
|
return result;
|
|
if ((result = UpdateCheck(g.Geo5_Country, g.Geo5_Region, ref end)) != GeoValid.Valid)
|
|
return result;
|
|
|
|
return result;
|
|
|
|
static GeoValid UpdateCheck(byte country, byte region, ref bool end)
|
|
{
|
|
if (country != 0)
|
|
return end ? GeoValid.CountryAfterPreviousEmpty : GeoValid.Valid;
|
|
if (region != 0) // c == 0
|
|
return GeoValid.RegionWithoutCountry;
|
|
end = true;
|
|
return GeoValid.Valid;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Geolocation Country-Region tuple validity tagging.
|
|
/// </summary>
|
|
internal enum GeoValid
|
|
{
|
|
/// <summary> Tuple is valid. </summary>
|
|
Valid,
|
|
|
|
/// <summary>
|
|
/// Lower-index country is empty, but higher has data (invalid).
|
|
/// </summary>
|
|
CountryAfterPreviousEmpty,
|
|
|
|
/// <summary>
|
|
/// Zero-value country (None) with a non-zero Region (invalid).
|
|
/// </summary>
|
|
RegionWithoutCountry,
|
|
}
|