From eac0ec5250a2329bb01001099ede6683629ec8de Mon Sep 17 00:00:00 2001 From: Archit Date Date: Tue, 3 Aug 2021 12:21:58 +0800 Subject: [PATCH] add vivillon edge cases sync with pkhex changes --- PKHeX.Core.AutoMod/AutoMod/APILegality.cs | 45 +++++++++++++++++-- .../AutoMod/Legalization/ShowdownEdits.cs | 3 +- .../AutoMod/Legalization/SimpleEdits.cs | 2 + .../AutoMod/Trainers/PokeTrainerDetails.cs | 6 +-- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/PKHeX.Core.AutoMod/AutoMod/APILegality.cs b/PKHeX.Core.AutoMod/AutoMod/APILegality.cs index 7cf96254..324c5a12 100644 --- a/PKHeX.Core.AutoMod/AutoMod/APILegality.cs +++ b/PKHeX.Core.AutoMod/AutoMod/APILegality.cs @@ -591,10 +591,10 @@ private static void SetIVsPID(this PKM pk, IBattleTemplate set, PIDType method, do PIDGenerator.SetRandomPokeSpotPID(pk, pk.Nature, pk.Gender, abil, es3ps.SlotNumber); while (pk.PID % 25 != pk.Nature); return; - case PGT { IsManaphyEgg:false } d: + case PCD d: { - if (d.PK.PID != 1) - pk.PID = d.PK.PID; + if (d.Gift.PK.PID != 1) + pk.PID = d.Gift.PK.PID; else if (pk.Nature != pk.PID % 25) pk.SetPIDNature(pk.Nature); return; @@ -1039,6 +1039,10 @@ private static void FixEdgeCases(this PKM pk, IEncounterable enc) // VC Games are locked to console region (modify based on language) if (pk is PK7 pk7 && pk7.Generation <= 2) pk7.FixVCRegion(); + + // Vivillon pattern fixes if necessary + if (pk is IGeoTrack && pk.Species is (int)Species.Vivillon or (int)Species.Spewpa or (int)Species.Scatterbug) + pk.FixVivillonRegion(); } /// @@ -1079,6 +1083,41 @@ public static void FixVCRegion(this PK7 pk7) } } + /// + /// Handle edge case vivillon legality if the trainerdata region is invalid + /// + /// pkm to fix + public static void FixVivillonRegion(this PKM pk) + { + if (pk is not IGeoTrack g) + return; + var valid = Vivillon3DS.IsPatternValid(pk.Form, g.ConsoleRegion); + if (valid) + return; + // 5: JP + // 7, 14: USA + // else: EUR + switch (pk.Form) + { + case 5: + g.ConsoleRegion = 0; + g.Region = 0; + g.Country = 1; + break; + case 7: + case 14: + g.ConsoleRegion = 1; + g.Region = 0; + g.Country = 49; + break; + default: + g.ConsoleRegion = 2; + g.Region = 0; + g.Country = 105; + break; + } + } + /// /// Wrapper function for GetLegalFromTemplate but with a Timeout /// diff --git a/PKHeX.Core.AutoMod/AutoMod/Legalization/ShowdownEdits.cs b/PKHeX.Core.AutoMod/AutoMod/Legalization/ShowdownEdits.cs index e629156d..d72be199 100644 --- a/PKHeX.Core.AutoMod/AutoMod/Legalization/ShowdownEdits.cs +++ b/PKHeX.Core.AutoMod/AutoMod/Legalization/ShowdownEdits.cs @@ -133,8 +133,6 @@ public static void SetSpeciesLevel(this PKM pk, IBattleTemplate set, int Form, I pk.CurrentLevel = set.Level; if (pk.Met_Level > pk.CurrentLevel) pk.Met_Level = pk.CurrentLevel; - if ((enc is EncounterSlot8 esl && esl.Weather is AreaWeather8.Heavy_Fog) || (enc is EncounterStatic8 est && est.Weather is AreaWeather8.Heavy_Fog)) - pk.Met_Level = EncounterArea8.BoostLevel; if (set.Level != 100 && set.Level == enc.LevelMin && (pk.Format == 3 || pk.Format == 4)) pk.EXP = Experience.GetEXP(enc.LevelMin + 1, PersonalTable.HGSS[enc.Species].EXPGrowth) - 1; @@ -239,6 +237,7 @@ public static void SetMovesEVs(this PKM pk, IBattleTemplate set, IEncounterable var la = new LegalityAnalysis(pk); if (la.Parsed && !pk.FatefulEncounter) { + // For dexnav. Certain encounters come with "random" relearn moves, and our requested moves might require one of them. var relearn = la.GetSuggestedRelearnMoves(enc); pk.ClearRelearnMoves(); pk.SetRelearnMoves(relearn); diff --git a/PKHeX.Core.AutoMod/AutoMod/Legalization/SimpleEdits.cs b/PKHeX.Core.AutoMod/AutoMod/Legalization/SimpleEdits.cs index d40a8c3f..355eb8ba 100644 --- a/PKHeX.Core.AutoMod/AutoMod/Legalization/SimpleEdits.cs +++ b/PKHeX.Core.AutoMod/AutoMod/Legalization/SimpleEdits.cs @@ -440,6 +440,8 @@ public static void SetAllTrainerData(this PKM pk, ITrainerInfo trainer) gt.Region = o.Region; if (pk is PK7 pk7 && pk.Generation <= 2) pk7.FixVCRegion(); + if (pk.Species is (int)Species.Vivillon or (int)Species.Spewpa or (int)Species.Scatterbug) + pk.FixVivillonRegion(); return; } diff --git a/PKHeX.Core.AutoMod/AutoMod/Trainers/PokeTrainerDetails.cs b/PKHeX.Core.AutoMod/AutoMod/Trainers/PokeTrainerDetails.cs index d2674426..45e7bb34 100644 --- a/PKHeX.Core.AutoMod/AutoMod/Trainers/PokeTrainerDetails.cs +++ b/PKHeX.Core.AutoMod/AutoMod/Trainers/PokeTrainerDetails.cs @@ -19,9 +19,9 @@ public class PokeTrainerDetails : ITrainerInfo, IRegionOrigin public int Game => pkm.Version; public int Language { get => pkm.Language; set => pkm.Language = value; } - public int Country { get => pkm is IGeoTrack gt ? gt.Country : 0; set { if (pkm is IGeoTrack gt) gt.Country = value; } } - public int Region { get => pkm is IGeoTrack gt ? gt.Region : 0; set { if (pkm is IGeoTrack gt) gt.Region = value; } } - public int ConsoleRegion { get => pkm is IGeoTrack gt ? gt.ConsoleRegion : 0; set { if (pkm is IGeoTrack gt) gt.ConsoleRegion = value; } } + public byte Country { get => pkm is IGeoTrack gt ? gt.Country : (byte)0; set { if (pkm is IGeoTrack gt) gt.Country = value; } } + public byte Region { get => pkm is IGeoTrack gt ? gt.Region : (byte)0; set { if (pkm is IGeoTrack gt) gt.Region = value; } } + public byte ConsoleRegion { get => pkm is IGeoTrack gt ? gt.ConsoleRegion : (byte)0; set { if (pkm is IGeoTrack gt) gt.ConsoleRegion = value; } } public int Generation => pkm.Generation; public static PokeTrainerDetails Clone(PokeTrainerDetails p) => new(p.pkm.Clone());