From 8a4c40908b898dfc34bb12a7b79ad137db8d6c3b Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 12 Jun 2017 18:15:26 -0700 Subject: [PATCH] Enforce met location matching for crystal data Only while format == 2 improve detection for gen1/2 ingame trades --- PKHeX.Core/Legality/Checks.cs | 2 +- .../Legality/Encounters/EncounterGenerator.cs | 19 ++++++++++-------- PKHeX.Core/Legality/Tables2.cs | 20 +++++++++---------- PKHeX.WinForms/MainWindow/Main.cs | 2 ++ 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/PKHeX.Core/Legality/Checks.cs b/PKHeX.Core/Legality/Checks.cs index eca198e74..9e52aad18 100644 --- a/PKHeX.Core/Legality/Checks.cs +++ b/PKHeX.Core/Legality/Checks.cs @@ -285,7 +285,7 @@ private void verifyNicknameTrade() } else if (pkm.Format <= 2 || pkm.VC) { - var et = EncounterOriginalGB as EncounterTrade; + var et = (EncounterOriginalGB ?? EncounterMatch) as EncounterTrade; if (et?.TID == 0) // Gen1 Trade { if (!EncounterGenerator.getEncounterTrade1Valid(pkm)) diff --git a/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs b/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs index 72226e871..016df6fa7 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs @@ -143,14 +143,16 @@ private static IEnumerable GenerateRawEncounters12(PKM pkm, Gam private static IEnumerable GenerateFilteredEncounters(PKM pkm) { IEnumerable filter(IEnumerable data) => data - .OrderBy(z => z.Type == GBEncounterType.EggEncounter).ThenBy(z => z.Species).ThenBy(z => z.Level); + .OrderBy(z => !(z.Encounter is EncounterTrade && z.Generation == 2) || z.Type == GBEncounterType.EggEncounter) + .ThenBy(z => z.Species).ThenBy(z => z.Level); - if (!pkm.Gen2_NotTradeback) + bool crystal = pkm.Format == 2 && pkm.Met_Location != 0; + if (!pkm.Gen2_NotTradeback && !crystal) foreach (var z in filter(GenerateRawEncounters12(pkm, GameVersion.RBY))) yield return z; if (!pkm.Gen1_NotTradeback && AllowGen2VCTransfer) - foreach (var z in filter(GenerateRawEncounters12(pkm, GameVersion.GSC))) + foreach (var z in filter(GenerateRawEncounters12(pkm, crystal ? GameVersion.C : GameVersion.GSC))) yield return z; } private static IEnumerable GenerateRawEncounters(PKM pkm) @@ -582,8 +584,8 @@ private static IEnumerable getEncounterAreas(PKM pkm, GameVersion gameSource = (GameVersion)pkm.Version; var slots = getEncounterSlots(pkm, gameSource: gameSource); - bool noMet = !pkm.HasOriginalMetLocation; - return noMet || pkm.Format <= 2 ? slots : slots.Where(area => area.Location == pkm.Met_Location); + bool noMet = !pkm.HasOriginalMetLocation || pkm.Format == 2 && gameSource != GameVersion.C; + return noMet ? slots : slots.Where(area => area.Location == pkm.Met_Location); } private static IEnumerable getSlots(PKM pkm, IEnumerable tables, int lvl = -1) { @@ -638,6 +640,7 @@ private static IEnumerable getValidEncounterTradeVC(PKM pkm, Gam var table = !AllowGen1Tradeback ? TradeGift_RBY_NoTradeback : TradeGift_RBY_Tradeback; return getValidEncounterTradeVC1(pkm, p, table); case GameVersion.GSC: + case GameVersion.C: return getValidEncounterTradeVC2(pkm, p); default: return null; @@ -651,11 +654,11 @@ private static IEnumerable getValidEncounterTradeVC2(PKM pkm, De foreach (var z in possible) { // Filter Criteria - if (z?.Gender != pkm.Gender) - continue; if (z.TID != pkm.TID) continue; - if (!z.IVs.SequenceEqual(pkm.IVs)) + if (z.Gender != pkm.Gender && pkm.Format <= 2) + continue; + if (!z.IVs.SequenceEqual(pkm.IVs) && pkm.Format <= 2) continue; if (pkm.Met_Location != 0 && pkm.Format == 2 && pkm.Met_Location != z.Location) continue; diff --git a/PKHeX.Core/Legality/Tables2.cs b/PKHeX.Core/Legality/Tables2.cs index d041454ea..672f6cce6 100644 --- a/PKHeX.Core/Legality/Tables2.cs +++ b/PKHeX.Core/Legality/Tables2.cs @@ -122,16 +122,16 @@ public static partial class Legal internal static readonly EncounterTrade[] TradeGift_GSC = { - new EncounterTrade { Species = 095, Generation =2, Level = 03, Gender = 0, Location = 06, TID = 48926, IVs = new[] {08, 09, 06, 06, 06} }, // Onix @ Violet City for Bellsprout [wild] - new EncounterTrade { Species = 066, Generation =2, Level = 05, Gender = 1, Location = 16, TID = 37460, IVs = new[] {12, 03, 07, 06, 06} }, // Machop @ Goldenrod City for Drowzee [wild 9, hatched egg 5] - new EncounterTrade { Species = 100, Generation =2, Level = 05, Gender = 2, Location = 27, TID = 29189, IVs = new[] {08, 09, 08, 08, 08} }, // Voltorb @ Olivine City for Krabby [egg] - new EncounterTrade { Species = 112, Generation =2, Level = 30, Gender = 1, Location = 41, TID = 00283, IVs = new[] {12, 07, 07, 06, 06} }, // Rhydon @ Blackthorn City for Dragonair [blue jp game corner] - new EncounterTrade { Species = 142, Generation =2, Level = 05, Gender = 0, Location = 76, TID = 26491, IVs = new[] {08, 09, 06, 06, 06} }, // Aerodactyl @ Route 14 for Chansey [egg] - new EncounterTrade { Species = 078, Generation =2, Level = 14, Gender = 0, Location = 51, TID = 15616, IVs = new[] {08, 09, 06, 06, 06} }, // Rapidash @ Pewter City for Gloom [wild] - - new EncounterTrade { Species = 085, Generation =2, Level = 30, Gender = 1, Location = 41, TID = 00283, IVs = new[] {12, 07, 07, 06, 06} }, // Dodrio @ Blackthorn City for Dragonair [blue jp game corner] - new EncounterTrade { Species = 178, Generation =2, Level = 15, Gender = 0, Location = 51, TID = 15616, IVs = new[] {08, 09, 06, 08, 06} }, // Xatu @ Pewter City for Haunter [wild] - new EncounterTrade { Species = 082, Generation =2, Level = 16, Gender = 2, Location = 68, TID = 50082, IVs = new[] {08, 09, 06, 06, 06} }, // Magneton @ Power Plant for Dugtrio [wild] + new EncounterTrade { Species = 095, Generation = 2, Level = 03, Gender = 0, Location = 06, TID = 48926, IVs = new[] {08, 09, 06, 06, 06, 06} }, // Onix @ Violet City for Bellsprout [wild] + new EncounterTrade { Species = 066, Generation = 2, Level = 05, Gender = 1, Location = 16, TID = 37460, IVs = new[] {12, 03, 07, 06, 06, 06} }, // Machop @ Goldenrod City for Drowzee [wild 9, hatched egg 5] + new EncounterTrade { Species = 100, Generation = 2, Level = 05, Gender = 2, Location = 27, TID = 29189, IVs = new[] {08, 09, 08, 08, 08, 08} }, // Voltorb @ Olivine City for Krabby [egg] + new EncounterTrade { Species = 112, Generation = 2, Level = 30, Gender = 1, Location = 41, TID = 00283, IVs = new[] {12, 07, 07, 06, 06, 06} }, // Rhydon @ Blackthorn City for Dragonair [blue jp game corner] + new EncounterTrade { Species = 142, Generation = 2, Level = 05, Gender = 0, Location = 76, TID = 26491, IVs = new[] {08, 09, 06, 06, 06, 06} }, // Aerodactyl @ Route 14 for Chansey [egg] + new EncounterTrade { Species = 078, Generation = 2, Level = 14, Gender = 0, Location = 51, TID = 15616, IVs = new[] {08, 09, 06, 06, 06, 06} }, // Rapidash @ Pewter City for Gloom [wild] + + new EncounterTrade { Species = 085, Generation = 2, Level = 30, Gender = 1, Location = 41, TID = 00283, IVs = new[] {12, 07, 07, 06, 06, 06} }, // Dodrio @ Blackthorn City for Dragonair [blue jp game corner] + new EncounterTrade { Species = 178, Generation = 2, Level = 15, Gender = 0, Location = 51, TID = 15616, IVs = new[] {08, 09, 06, 08, 08, 06} }, // Xatu @ Pewter City for Haunter [wild] + new EncounterTrade { Species = 082, Generation = 2, Level = 16, Gender = 2, Location = 68, TID = 50082, IVs = new[] {08, 09, 06, 06, 06, 06} }, // Magneton @ Power Plant for Dugtrio [wild] }; internal static readonly string[][] TradeGift_GSC_OTs = { diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index ed487940a..c3e0d3c79 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -1092,6 +1092,8 @@ private void tabMain_DragEnter(object sender, DragEventArgs e) private void tabMain_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + if (files == null || files.Length == 0) + return; OpenQuick(files[0]); e.Effect = DragDropEffects.Copy;