mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-05 21:17:14 -05:00
Split Country/Region/ConsoleRegion from ITrainerInfo
Only present in mainline gen6/7 game pairs, so it's not wise to have it for all games
This commit is contained in:
parent
36684ab867
commit
b7211000b0
|
|
@ -55,11 +55,11 @@ public static void TemplateFields(PKM pk, ITrainerInfo tr)
|
|||
pk.OT_Gender = tr.Gender;
|
||||
pk.TID = tr.TID;
|
||||
pk.SID = tr.SID;
|
||||
if (tr.ConsoleRegion >= 0 && pk is IGeoTrack gt)
|
||||
if (tr is IRegionOrigin o && pk is IRegionOrigin gt)
|
||||
{
|
||||
gt.ConsoleRegion = tr.ConsoleRegion;
|
||||
gt.Country = tr.Country;
|
||||
gt.Region = tr.SubRegion;
|
||||
gt.ConsoleRegion = o.ConsoleRegion;
|
||||
gt.Country = o.Country;
|
||||
gt.Region = o.Region;
|
||||
}
|
||||
|
||||
// Copy OT trash bytes for sensitive games (Gen1/2)
|
||||
|
|
|
|||
|
|
@ -82,7 +82,9 @@ private void SetAltForm(PKM pk, ITrainerInfo sav)
|
|||
case (int)Core.Species.Scatterbug:
|
||||
case (int)Core.Species.Spewpa:
|
||||
case (int)Core.Species.Vivillon:
|
||||
pk.AltForm = Legal.GetVivillonPattern((byte)sav.Country, (byte)sav.SubRegion);
|
||||
if (sav is IRegionOrigin o)
|
||||
pk.AltForm = Legal.GetVivillonPattern((byte)o.Country, (byte)o.Region);
|
||||
// else 0
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,8 +193,11 @@ private static int GetWildAltForm(PKM pk, int form, ITrainerInfo sav)
|
|||
return Util.Rand.Next(pk.PersonalInfo.FormeCount);
|
||||
|
||||
int spec = pk.Species;
|
||||
if (spec == (int)Core.Species.Scatterbug || spec == (int)Core.Species.Spewpa || spec == (int)Core.Species.Vivillon)
|
||||
return Legal.GetVivillonPattern((byte)sav.Country, (byte)sav.SubRegion);
|
||||
if ((int) Core.Species.Scatterbug <= spec && spec <= (int) Core.Species.Vivillon)
|
||||
{
|
||||
if (sav is IRegionOrigin o)
|
||||
return Legal.GetVivillonPattern((byte)o.Country, (byte)o.Region);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,10 +10,6 @@ public interface ITrainerInfo : ITrainerID
|
|||
int Game { get; }
|
||||
int Language { get; }
|
||||
|
||||
int Country { get; }
|
||||
int SubRegion { get; }
|
||||
int ConsoleRegion { get; }
|
||||
|
||||
int Generation { get; }
|
||||
}
|
||||
|
||||
|
|
@ -30,9 +26,12 @@ public static void ApplyTo(this ITrainerInfo info, PKM pk)
|
|||
|
||||
if (!(pk is IGeoTrack tr))
|
||||
return;
|
||||
tr.Country = info.Country;
|
||||
tr.Region = info.SubRegion;
|
||||
tr.ConsoleRegion = info.ConsoleRegion;
|
||||
|
||||
if (!(info is IRegionOrigin o))
|
||||
return;
|
||||
tr.Country = o.Country;
|
||||
tr.Region = o.Region;
|
||||
tr.ConsoleRegion = o.ConsoleRegion;
|
||||
}
|
||||
|
||||
public static void ApplyHandlingTrainerInfo(this ITrainerInfo sav, PKM pk, bool force = false)
|
||||
|
|
@ -45,11 +44,11 @@ public static void ApplyHandlingTrainerInfo(this ITrainerInfo sav, PKM pk, bool
|
|||
pk.HT_Friendship = pk.OT_Friendship;
|
||||
pk.CurrentHandler = 1;
|
||||
|
||||
if (pk.Format == 6)
|
||||
if (pk.Format == 6 && sav is IRegionOrigin o)
|
||||
{
|
||||
var g = (IGeoTrack) pk;
|
||||
g.Geo1_Country = sav.Country;
|
||||
g.Geo1_Region = sav.SubRegion;
|
||||
g.Geo1_Country = o.Country;
|
||||
g.Geo1_Region = o.Region;
|
||||
((PK6)pk).TradeMemory(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
namespace PKHeX.Core
|
||||
{
|
||||
public sealed class SimpleTrainerInfo : ITrainerInfo
|
||||
public sealed class SimpleTrainerInfo : ITrainerInfo, IRegionOrigin
|
||||
{
|
||||
public string OT { get; set; } = "PKHeX";
|
||||
public int TID { get; set; } = 12345;
|
||||
|
|
@ -9,7 +9,7 @@ public sealed class SimpleTrainerInfo : ITrainerInfo
|
|||
public int Language { get; set; } = (int)LanguageID.English;
|
||||
|
||||
public int ConsoleRegion { get; set; } = 1; // North America
|
||||
public int SubRegion { get; set; } = 7; // California
|
||||
public int Region { get; set; } = 7; // California
|
||||
public int Country { get; set; } = 49; // USA
|
||||
|
||||
public int Game { get; }
|
||||
|
|
@ -19,7 +19,7 @@ public SimpleTrainerInfo(GameVersion game = GameVersion.SW)
|
|||
{
|
||||
Game = (int) game;
|
||||
if (GameVersion.GG.Contains(game) || game.GetGeneration() >= 8)
|
||||
ConsoleRegion = SubRegion = Country = 0;
|
||||
ConsoleRegion = Region = Country = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -286,9 +286,6 @@ public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
|||
Version = OriginGame != 0 ? OriginGame : sav.Game,
|
||||
Language = Language != 0 ? Language : sav.Language,
|
||||
Ball = Ball,
|
||||
Country = sav.Country,
|
||||
Region = sav.SubRegion,
|
||||
ConsoleRegion = sav.ConsoleRegion,
|
||||
Move1 = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4,
|
||||
RelearnMove1 = RelearnMove1, RelearnMove2 = RelearnMove2,
|
||||
RelearnMove3 = RelearnMove3, RelearnMove4 = RelearnMove4,
|
||||
|
|
@ -337,6 +334,18 @@ public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
|||
|
||||
EVs = EVs,
|
||||
};
|
||||
|
||||
if (sav is IRegionOrigin o)
|
||||
{
|
||||
pk.Country = o.Country;
|
||||
pk.Region = o.Region;
|
||||
pk.ConsoleRegion = o.ConsoleRegion;
|
||||
}
|
||||
else
|
||||
{
|
||||
pk.SetDefaultRegionOrigins();
|
||||
}
|
||||
|
||||
pk.SetMaximumPPCurrent();
|
||||
|
||||
pk.MetDate = Date ?? DateTime.Now;
|
||||
|
|
|
|||
|
|
@ -330,9 +330,6 @@ public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
|||
Version = OriginGame != 0 ? OriginGame : sav.Game,
|
||||
Language = Language != 0 ? Language : sav.Language,
|
||||
Ball = Ball,
|
||||
Country = sav.Country,
|
||||
Region = sav.SubRegion,
|
||||
ConsoleRegion = sav.ConsoleRegion,
|
||||
Move1 = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4,
|
||||
RelearnMove1 = RelearnMove1, RelearnMove2 = RelearnMove2,
|
||||
RelearnMove3 = RelearnMove3, RelearnMove4 = RelearnMove4,
|
||||
|
|
@ -381,6 +378,18 @@ public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
|||
|
||||
EVs = EVs,
|
||||
};
|
||||
|
||||
if (sav is IRegionOrigin o)
|
||||
{
|
||||
pk.Country = o.Country;
|
||||
pk.Region = o.Region;
|
||||
pk.ConsoleRegion = o.ConsoleRegion;
|
||||
}
|
||||
else
|
||||
{
|
||||
pk.SetDefaultRegionOrigins();
|
||||
}
|
||||
|
||||
pk.SetMaximumPPCurrent();
|
||||
|
||||
if ((sav.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version))
|
||||
|
|
|
|||
|
|
@ -410,8 +410,11 @@ protected override bool TradeOT(ITrainerInfo tr)
|
|||
return false;
|
||||
|
||||
CurrentHandler = 0;
|
||||
if (!IsUntraded && (tr.Country != Geo1_Country || tr.SubRegion != Geo1_Region))
|
||||
this.TradeGeoLocation(tr.Country, tr.SubRegion);
|
||||
if (tr is IRegionOrigin o)
|
||||
{
|
||||
if (!IsUntraded && (o.Country != Geo1_Country || o.Region != Geo1_Region))
|
||||
this.TradeGeoLocation(o.Country, o.Region);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -419,7 +422,10 @@ protected override bool TradeOT(ITrainerInfo tr)
|
|||
protected override void TradeHT(ITrainerInfo tr)
|
||||
{
|
||||
if (tr.OT != HT_Name || tr.Gender != HT_Gender || (Geo1_Country == 0 && Geo1_Region == 0 && !IsUntradedEvent6))
|
||||
this.TradeGeoLocation(tr.Country, tr.SubRegion);
|
||||
{
|
||||
if (tr is IRegionOrigin o)
|
||||
this.TradeGeoLocation(o.Country, o.Region);
|
||||
}
|
||||
|
||||
if (tr.OT != HT_Name)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,12 +3,8 @@
|
|||
/// <summary>
|
||||
/// Tracks Geolocation history of a <see cref="PKM"/>
|
||||
/// </summary>
|
||||
public interface IGeoTrack
|
||||
public interface IGeoTrack : IRegionOrigin
|
||||
{
|
||||
int ConsoleRegion { get; set; }
|
||||
int Country { get; set; }
|
||||
int Region { get; set; }
|
||||
|
||||
int Geo1_Region { get; set; }
|
||||
int Geo2_Region { get; set; }
|
||||
int Geo3_Region { get; set; }
|
||||
|
|
|
|||
19
PKHeX.Core/PKM/Shared/IRegionOrigin.cs
Normal file
19
PKHeX.Core/PKM/Shared/IRegionOrigin.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
namespace PKHeX.Core
|
||||
{
|
||||
public interface IRegionOrigin
|
||||
{
|
||||
int ConsoleRegion { get; set; }
|
||||
int Country { get; set; }
|
||||
int Region { get; set; }
|
||||
}
|
||||
|
||||
public static partial class Extensions
|
||||
{
|
||||
public static void SetDefaultRegionOrigins(this IRegionOrigin o)
|
||||
{
|
||||
o.ConsoleRegion = 1; // North America
|
||||
o.Region = 7; // California
|
||||
o.Country = 49; // USA
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -15,12 +15,12 @@ public static class PKMConverter
|
|||
public static void SetPrimaryTrainer(ITrainerInfo t)
|
||||
{
|
||||
Trainer = t;
|
||||
if (t.ConsoleRegion != 0)
|
||||
Trainer67 = t;
|
||||
if (t is IRegionOrigin o)
|
||||
Trainer67 = o;
|
||||
}
|
||||
|
||||
private static ITrainerInfo Trainer { get; set; } = new SimpleTrainerInfo();
|
||||
private static ITrainerInfo Trainer67 { get; set; } = new SimpleTrainerInfo(GameVersion.SN);
|
||||
private static IRegionOrigin Trainer67 { get; set; } = new SimpleTrainerInfo(GameVersion.SN);
|
||||
public static string OT_Name => Trainer.OT;
|
||||
public static int OT_Gender => Trainer.Gender;
|
||||
public static int Language => Trainer.Language;
|
||||
|
|
@ -30,17 +30,17 @@ public static void SetPrimaryTrainer(ITrainerInfo t)
|
|||
|
||||
public static void SetConsoleRegionData3DS(IGeoTrack pkm)
|
||||
{
|
||||
var trainer = Trainer.ConsoleRegion != 0 ? Trainer : Trainer67;
|
||||
var trainer = Trainer is IRegionOrigin r ? r : Trainer67;
|
||||
pkm.ConsoleRegion = trainer.ConsoleRegion;
|
||||
pkm.Country = trainer.Country;
|
||||
pkm.Region = trainer.SubRegion;
|
||||
pkm.Region = trainer.Region;
|
||||
}
|
||||
|
||||
public static void SetFirstCountryRegion(IGeoTrack pkm)
|
||||
{
|
||||
var trainer = Trainer.ConsoleRegion != 0 ? Trainer : Trainer67;
|
||||
var trainer = Trainer is IRegionOrigin r ? r : Trainer67;
|
||||
pkm.Geo1_Country = trainer.Country;
|
||||
pkm.Geo1_Region = trainer.SubRegion;
|
||||
pkm.Geo1_Region = trainer.Region;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Generation 6 <see cref="SaveFile"/> object.
|
||||
/// </summary>
|
||||
public abstract class SAV6 : SAV_BEEF, ITrainerStatRecord, ISaveBlock6Core
|
||||
public abstract class SAV6 : SAV_BEEF, ITrainerStatRecord, ISaveBlock6Core, IRegionOrigin
|
||||
{
|
||||
// Save Data Attributes
|
||||
protected override string BAKText => $"{OT} ({Version}) - {Played.LastSavedTime}";
|
||||
|
|
@ -61,9 +61,9 @@ public abstract class SAV6 : SAV_BEEF, ITrainerStatRecord, ISaveBlock6Core
|
|||
public override int Gender { get => Status.Gender; set => Status.Gender = value; }
|
||||
public override int Language { get => Status.Language; set => Status.Language = value; }
|
||||
public override string OT { get => Status.OT; set => Status.OT = value; }
|
||||
public override int SubRegion { get => Status.SubRegion; set => Status.SubRegion = value; }
|
||||
public override int Country { get => Status.Country; set => Status.Country = value; }
|
||||
public override int ConsoleRegion { get => Status.ConsoleRegion; set => Status.ConsoleRegion = value; }
|
||||
public int Region { get => Status.SubRegion; set => Status.SubRegion = value; }
|
||||
public int Country { get => Status.Country; set => Status.Country = value; }
|
||||
public int ConsoleRegion { get => Status.ConsoleRegion; set => Status.ConsoleRegion = value; }
|
||||
public override int GameSyncIDSize => MyStatus6.GameSyncIDSize; // 64 bits
|
||||
public override string GameSyncID { get => Status.GameSyncID; set => Status.GameSyncID = value; }
|
||||
public override int PlayedHours { get => Played.PlayedHours; set => Played.PlayedHours = value; }
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Generation 7 <see cref="SaveFile"/> object.
|
||||
/// </summary>
|
||||
public abstract class SAV7 : SAV_BEEF, ITrainerStatRecord, ISaveBlock7Main
|
||||
public abstract class SAV7 : SAV_BEEF, ITrainerStatRecord, ISaveBlock7Main, IRegionOrigin
|
||||
{
|
||||
// Save Data Attributes
|
||||
protected override string BAKText => $"{OT} ({Version}) - {Played.LastSavedTime}";
|
||||
|
|
@ -140,9 +140,9 @@ public override byte[] SetString(string value, int maxLength, int PadToSize = 0,
|
|||
public override int Gender { get => MyStatus.Gender; set => MyStatus.Gender = value; }
|
||||
public override int GameSyncIDSize => MyStatus7.GameSyncIDSize; // 64 bits
|
||||
public override string GameSyncID { get => MyStatus.GameSyncID; set => MyStatus.GameSyncID = value; }
|
||||
public override int SubRegion { get => MyStatus.SubRegion; set => MyStatus.SubRegion = value; }
|
||||
public override int Country { get => MyStatus.Country; set => MyStatus.Country = value; }
|
||||
public override int ConsoleRegion { get => MyStatus.ConsoleRegion; set => MyStatus.ConsoleRegion = value; }
|
||||
public int Region { get => MyStatus.SubRegion; set => MyStatus.SubRegion = value; }
|
||||
public int Country { get => MyStatus.Country; set => MyStatus.Country = value; }
|
||||
public int ConsoleRegion { get => MyStatus.ConsoleRegion; set => MyStatus.ConsoleRegion = value; }
|
||||
public override int Language { get => MyStatus.Language; set => MyStatus.Language = value; }
|
||||
public override string OT { get => MyStatus.OT; set => MyStatus.OT = value; }
|
||||
public override int MultiplayerSpriteID { get => MyStatus.MultiplayerSpriteID; set => MyStatus.MultiplayerSpriteID = value; }
|
||||
|
|
|
|||
|
|
@ -250,9 +250,6 @@ public virtual MysteryGiftAlbum GiftAlbum
|
|||
public virtual int MultiplayerSpriteID { get => 0; set { } }
|
||||
public int TrainerID7 { get => (int)((uint)(TID | (SID << 16)) % 1000000); set => SetID7(TrainerSID7, value); }
|
||||
public int TrainerSID7 { get => (int)((uint)(TID | (SID << 16)) / 1000000); set => SetID7(value, TrainerID7); }
|
||||
public virtual int Country { get => -1; set { } }
|
||||
public virtual int ConsoleRegion { get => -1; set { } }
|
||||
public virtual int SubRegion { get => -1; set { } }
|
||||
public virtual int MaxMoney => 9999999;
|
||||
public virtual int MaxCoins => 9999;
|
||||
|
||||
|
|
|
|||
|
|
@ -570,12 +570,8 @@ public static SaveFile GetBlankSAV(GameVersion game, string trainerName)
|
|||
SAV.Language = (int)LanguageID.English; // English
|
||||
|
||||
// Only set geolocation data for 3DS titles
|
||||
if (6 <= SAV.Generation && SAV.Generation <= 7 && !(SAV is SAV7b))
|
||||
{
|
||||
SAV.Country = 49; // USA
|
||||
SAV.SubRegion = 7; // CA
|
||||
SAV.ConsoleRegion = 1; // Americas
|
||||
}
|
||||
if (SAV is IRegionOrigin o)
|
||||
o.SetDefaultRegionOrigins();
|
||||
|
||||
return SAV;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -394,11 +394,11 @@ private void SetDetailsOT(ITrainerInfo tr)
|
|||
if (lang <= 0)
|
||||
lang = (int)LanguageID.English;
|
||||
CB_Language.SelectedValue = lang;
|
||||
if (tr.ConsoleRegion != 0)
|
||||
if (tr is IRegionOrigin o)
|
||||
{
|
||||
CB_3DSReg.SelectedValue = tr.ConsoleRegion;
|
||||
CB_Country.SelectedValue = tr.Country;
|
||||
CB_SubRegion.SelectedValue = tr.SubRegion;
|
||||
CB_3DSReg.SelectedValue = o.ConsoleRegion;
|
||||
CB_Country.SelectedValue = o.Country;
|
||||
CB_SubRegion.SelectedValue = o.Region;
|
||||
}
|
||||
|
||||
// Copy OT trash bytes for sensitive games (Gen1/2)
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ private void GetTextBoxes()
|
|||
TB_Saying5.Text = status.Saying5;
|
||||
|
||||
CB_Country.SelectedValue = SAV.Country;
|
||||
CB_Region.SelectedValue = SAV.SubRegion;
|
||||
CB_Region.SelectedValue = SAV.Region;
|
||||
CB_3DSReg.SelectedValue = SAV.ConsoleRegion;
|
||||
CB_Language.SelectedValue = SAV.Language;
|
||||
|
||||
|
|
@ -200,7 +200,7 @@ private void Save()
|
|||
SAV.TID = (ushort)Util.ToUInt32(MT_TID.Text);
|
||||
SAV.SID = (ushort)Util.ToUInt32(MT_SID.Text);
|
||||
SAV.Money = Util.ToUInt32(MT_Money.Text);
|
||||
SAV.SubRegion = WinFormsUtil.GetIndex(CB_Region);
|
||||
SAV.Region = WinFormsUtil.GetIndex(CB_Region);
|
||||
SAV.Country = WinFormsUtil.GetIndex(CB_Country);
|
||||
SAV.ConsoleRegion = WinFormsUtil.GetIndex(CB_3DSReg);
|
||||
SAV.Language = WinFormsUtil.GetIndex(CB_Language);
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ private void GetTextBoxes()
|
|||
MT_Money.Text = SAV.Money.ToString();
|
||||
|
||||
CB_Country.SelectedValue = SAV.Country;
|
||||
CB_Region.SelectedValue = SAV.SubRegion;
|
||||
CB_Region.SelectedValue = SAV.Region;
|
||||
CB_3DSReg.SelectedValue = SAV.ConsoleRegion;
|
||||
CB_Language.SelectedValue = SAV.Language;
|
||||
var timeA = SAV.GameTime.AlolaTime;
|
||||
|
|
@ -325,7 +325,7 @@ private void SaveTrainerInfo()
|
|||
SAV.Gender = (byte)CB_Gender.SelectedIndex;
|
||||
|
||||
SAV.Money = Util.ToUInt32(MT_Money.Text);
|
||||
SAV.SubRegion = WinFormsUtil.GetIndex(CB_Region);
|
||||
SAV.Region = WinFormsUtil.GetIndex(CB_Region);
|
||||
SAV.Country = WinFormsUtil.GetIndex(CB_Country);
|
||||
SAV.ConsoleRegion = WinFormsUtil.GetIndex(CB_3DSReg);
|
||||
SAV.Language = WinFormsUtil.GetIndex(CB_Language);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user