From 8f73c9b0ac033c9b71f1801fa8b36126c368c3d9 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 26 Nov 2016 23:23:45 -0800 Subject: [PATCH] Add suggested met location fetch Closes #450 --- PKHeX/Legality/Analysis.cs | 51 +++++++++++++++++++++++++++++++ PKHeX/Legality/Core.cs | 14 +++++++++ PKHeX/MainWindow/Main.Designer.cs | 1 + PKHeX/MainWindow/Main.cs | 30 ++++++++++++++++++ 4 files changed, 96 insertions(+) diff --git a/PKHeX/Legality/Analysis.cs b/PKHeX/Legality/Analysis.cs index 0822455d9..b65e9c37b 100644 --- a/PKHeX/Legality/Analysis.cs +++ b/PKHeX/Legality/Analysis.cs @@ -232,5 +232,56 @@ public int[] getSuggestedMoves(bool tm, bool tutor, bool reminder) return null; return Legal.getValidMoves(pkm, Tutor: tutor, Machine: tm, MoveReminder: reminder).Skip(1).ToArray(); // skip move 0 } + + public EncounterStatic getSuggestedMetInfo() + { + if (pkm.WasEgg) + return new EncounterStatic + { + Location = getSuggestedEggMetLocation(pkm), + Level = 1, + }; + + var capture = Legal.getCaptureLocation(pkm); + if (capture != null) + return new EncounterStatic + { + Location = capture.Location, + Level = capture.Slots.First().LevelMin, + }; + + var encounter = Legal.getStaticLocation(pkm); + return encounter; + } + private static int getSuggestedEggMetLocation(PKM pkm) + { + // Return one of legal hatch locations for game + switch ((GameVersion)pkm.Version) + { + case GameVersion.D: + case GameVersion.P: + case GameVersion.Pt: + return pkm.Format > 4 ? 30001 /* Transporter */ : 4; // Solaceon Town + case GameVersion.HG: + case GameVersion.SS: + return pkm.Format > 4 ? 30001 /* Transporter */ : 182; // Route 34 + + case GameVersion.B: + case GameVersion.W: + return 16; // Route 3 + + case GameVersion.X: + case GameVersion.Y: + return 38; // Route 7 + case GameVersion.AS: + case GameVersion.OR: + return 318; // Battle Resort + + case GameVersion.SN: + case GameVersion.MN: + break; + } + return -1; + } } } diff --git a/PKHeX/Legality/Core.cs b/PKHeX/Legality/Core.cs index 0b661eac1..adbbb85ff 100644 --- a/PKHeX/Legality/Core.cs +++ b/PKHeX/Legality/Core.cs @@ -541,6 +541,20 @@ internal static bool getEvolutionValid(PKM pkm) return curr.Count() >= poss.Count(); } + internal static EncounterArea getCaptureLocation(PKM pkm) + { + return (from area in getEncounterSlots(pkm) + let slots = getValidEncounterSlots(pkm, area, pkm.AO).ToArray() + where slots.Any() + select new EncounterArea + { + Location = area.Location, Slots = slots, + }).FirstOrDefault(); + } + internal static EncounterStatic getStaticLocation(PKM pkm) + { + return getStaticEncounters(pkm).FirstOrDefault(); + } internal static bool getCanBeCaptured(int species, int gen, GameVersion version = GameVersion.Any) { switch (gen) diff --git a/PKHeX/MainWindow/Main.Designer.cs b/PKHeX/MainWindow/Main.Designer.cs index 1d46df9ac..4ff571da9 100644 --- a/PKHeX/MainWindow/Main.Designer.cs +++ b/PKHeX/MainWindow/Main.Designer.cs @@ -1759,6 +1759,7 @@ public void InitializeComponent() this.Label_MetLocation.TabIndex = 1; this.Label_MetLocation.Text = "Met Location:"; this.Label_MetLocation.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.Label_MetLocation.Click += new System.EventHandler(this.clickMetLocation); // // CB_MetLocation // diff --git a/PKHeX/MainWindow/Main.cs b/PKHeX/MainWindow/Main.cs index 6ddb09a2b..52ef28af3 100644 --- a/PKHeX/MainWindow/Main.cs +++ b/PKHeX/MainWindow/Main.cs @@ -1841,6 +1841,36 @@ private void clickMoves(object sender, EventArgs e) updateLegality(); } + private void clickMetLocation(object sender, EventArgs e) + { + if (HaX) + return; + + var encounter = Legality.getSuggestedMetInfo(); + if (encounter == null || encounter.Location < 0) + { + Util.Alert("Unable to provide a suggestion."); + return; + } + + int level = encounter.Level; + int location = encounter.Location; + + if (pkm.Met_Level == level && pkm.Met_Location == location) + return; + + var met_list = GameInfo.getLocationList((GameVersion)pkm.Version, SAV.Generation, egg: false); + var locstr = met_list.FirstOrDefault(loc => loc.Value == location)?.Text; + string suggestion = $"Set Met Location to {locstr} @ level {level}?"; + + if (Util.Prompt(MessageBoxButtons.YesNo, suggestion) != DialogResult.Yes) + return; + + TB_MetLevel.Text = level.ToString(); + if (pkm.CurrentLevel < level) + TB_Level.Text = level.ToString(); + CB_MetLocation.SelectedValue = location; + } // Prompted Updates of PKX Functions // private bool changingFields; private void updateBall(object sender, EventArgs e)