From 08e293dadcb0a2c40bcd576c14245aca53a8fc90 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 26 Nov 2019 16:55:28 -0800 Subject: [PATCH] Add SimpleTrainerInfo constructor zeroes out console region data if not present in game --- PKHeX.Core/Legality/Structures/SimpleTrainerInfo.cs | 9 ++++++++- PKHeX.Core/Legality/Verifiers/ParseSettings.cs | 2 +- Tests/PKHeX.Core.Tests/Simulator/GeneratorTests.cs | 4 ++-- Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs | 12 ++++++------ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/PKHeX.Core/Legality/Structures/SimpleTrainerInfo.cs b/PKHeX.Core/Legality/Structures/SimpleTrainerInfo.cs index a8ab0e17d..07b7ae9ba 100644 --- a/PKHeX.Core/Legality/Structures/SimpleTrainerInfo.cs +++ b/PKHeX.Core/Legality/Structures/SimpleTrainerInfo.cs @@ -12,7 +12,14 @@ public sealed class SimpleTrainerInfo : ITrainerInfo public int SubRegion { get; set; } = 7; // California public int Country { get; set; } = 49; // USA - public int Game { get; set; } = (int)GameVersion.UM; + public int Game { get; } public int Generation { get; set; } = PKX.Generation; + + public SimpleTrainerInfo(GameVersion game = GameVersion.SW) + { + Game = (int) game; + if (GameVersion.GG.Contains(game) || game.GetGeneration() >= 8) + ConsoleRegion = SubRegion = Country = 0; + } } } diff --git a/PKHeX.Core/Legality/Verifiers/ParseSettings.cs b/PKHeX.Core/Legality/Verifiers/ParseSettings.cs index c7ae9dad4..973127616 100644 --- a/PKHeX.Core/Legality/Verifiers/ParseSettings.cs +++ b/PKHeX.Core/Legality/Verifiers/ParseSettings.cs @@ -2,7 +2,7 @@ { public static class ParseSettings { - internal static ITrainerInfo ActiveTrainer { get; set; } = new SimpleTrainerInfo { OT = string.Empty, Game = (int)GameVersion.Any, Language = -1 }; + internal static ITrainerInfo ActiveTrainer { get; set; } = new SimpleTrainerInfo(GameVersion.Any) { OT = string.Empty, Language = -1 }; /// /// Toggles whether or not the word filter should be used when checking the data. diff --git a/Tests/PKHeX.Core.Tests/Simulator/GeneratorTests.cs b/Tests/PKHeX.Core.Tests/Simulator/GeneratorTests.cs index f87c6698c..8e506bcf0 100644 --- a/Tests/PKHeX.Core.Tests/Simulator/GeneratorTests.cs +++ b/Tests/PKHeX.Core.Tests/Simulator/GeneratorTests.cs @@ -27,7 +27,7 @@ public static IEnumerable PokemonGenerationTestData() public void PokemonGenerationReturnsLegalPokemon(int species) { int count = 0; - var tr = new SimpleTrainerInfo(); + var tr = new SimpleTrainerInfo(GameVersion.SN); var pk = new PK7 { Species = species }; pk.Gender = pk.GetSaneGender(); @@ -50,7 +50,7 @@ public void CanGenerateMG5Case() ez.Should().NotBeNull("Shiny Haxorus stationary encounter exists for B2/W2"); var criteria = new EncounterCriteria(); - var tr = new SimpleTrainerInfo + var tr = new SimpleTrainerInfo(GameVersion.B2) { TID = 57600, SID = 62446, diff --git a/Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs b/Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs index 0795d2e23..e610fcf0c 100644 --- a/Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs +++ b/Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs @@ -37,7 +37,7 @@ public void SimulatorGetEncounters() Assert.NotNull(first); var egg = (EncounterEgg)first; - var info = new SimpleTrainerInfo(); + var info = new SimpleTrainerInfo(GameVersion.SN); var pk = egg.ConvertToPKM(info); Assert.True(pk.Species != set.Species); @@ -64,7 +64,7 @@ public void SimulatorGetWC3() Assert.NotNull(first); var wc3 = (WC3)first; - var info = new SimpleTrainerInfo(); + var info = new SimpleTrainerInfo(GameVersion.R); var pk = wc3.ConvertToPKM(info); var la = new LegalityAnalysis(pk); @@ -83,7 +83,7 @@ public void SimulatorGetCelebi() Assert.NotNull(first); var enc = first; - var info = new SimpleTrainerInfo(); + var info = new SimpleTrainerInfo(GameVersion.SN); var pk = enc.ConvertToPKM(info); var la = new LegalityAnalysis(pk); @@ -99,7 +99,7 @@ public void SimulatorGetSplitBreed() Assert.True(encs.Count > 0); Assert.True(encs.All(z => z.Species > 150)); - var info = new SimpleTrainerInfo(); + var info = new SimpleTrainerInfo(GameVersion.SN); var enc = encs[0]; var pk = enc.ConvertToPKM(info); @@ -115,7 +115,7 @@ public void SimulatorGetVCEgg1() var encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.GD).ToList(); Assert.True(encs.Count > 0); - var info = new SimpleTrainerInfo(); + var info = new SimpleTrainerInfo(GameVersion.SN); var enc = encs[0]; var pk = enc.ConvertToPKM(info); @@ -135,7 +135,7 @@ public void SimulatorGetSmeargle() Assert.NotNull(first); var enc = first; - var info = new SimpleTrainerInfo(); + var info = new SimpleTrainerInfo(GameVersion.SN); var pk = enc.ConvertToPKM(info); var la = new LegalityAnalysis(pk);