From 016497bece1491974b6cc3d9dfd963c15ceea97d Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 22 Apr 2017 21:00:06 -0700 Subject: [PATCH] Refactoring r2 Don't calculate suggested moves until prompted Don't check EncounterType for gen7 pkm (no field to check) --- PKHeX/Legality/Analysis.cs | 38 +++++++++++++++++++++++++++----------- PKHeX/Legality/Checks.cs | 18 ++++++++++-------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/PKHeX/Legality/Analysis.cs b/PKHeX/Legality/Analysis.cs index 7b1f91cf0..1e2fb0eae 100644 --- a/PKHeX/Legality/Analysis.cs +++ b/PKHeX/Legality/Analysis.cs @@ -26,14 +26,36 @@ public partial class LegalityAnalysis public readonly bool Parsed; public readonly bool Valid; + public readonly bool Error; public bool ParsedValid => Parsed && Valid; public bool ParsedInvalid => Parsed && !Valid; public CheckResult[] vMoves = new CheckResult[4]; public CheckResult[] vRelearn = new CheckResult[4]; - public string Report(bool verbose = false) => verbose ? getVerboseLegalityReport() : getLegalityReport(); - public readonly int[] AllSuggestedMoves; - public readonly int[] AllSuggestedRelearnMoves; - public readonly int[] AllSuggestedMovesAndRelearn; + public string Report(bool verbose = false) => verbose ? getVerboseLegalityReport() : getLegalityReport(); + private IEnumerable AllSuggestedMoves + { + get + { + if (Error) + return new int[4]; + if (_allSuggestedMoves == null) + return _allSuggestedMoves = !pkm.IsOriginValid ? new int[4] : getSuggestedMoves(true, true, true); + return _allSuggestedMoves; + } + } + private IEnumerable AllSuggestedRelearnMoves + { + get + { + if (Error) + return new int[4]; + if (_allSuggestedRelearnMoves == null) + return _allSuggestedRelearnMoves = !pkm.IsOriginValid ? new int[4] : Legal.getValidRelearn(pkm, -1).ToArray(); + return _allSuggestedRelearnMoves; + } + } + private int[] _allSuggestedMoves, _allSuggestedRelearnMoves; + public int[] AllSuggestedMovesAndRelearn => AllSuggestedMoves.Concat(AllSuggestedRelearnMoves).ToArray(); public LegalityAnalysis(PKM pk) { @@ -76,8 +98,6 @@ public LegalityAnalysis(PKM pk) if (pkm.FatefulEncounter && vRelearn.Any(chk => !chk.Valid) && EncounterMatch == null) AddLine(Severity.Indeterminate, V188, CheckIdentifier.Fateful); } - else - return; } catch (Exception e) { @@ -85,12 +105,8 @@ public LegalityAnalysis(PKM pk) Valid = false; Parsed = true; AddLine(Severity.Invalid, V190, CheckIdentifier.Misc); - AllSuggestedMoves = AllSuggestedRelearnMoves = AllSuggestedMovesAndRelearn = new int[0]; - return; + Error = true; } - AllSuggestedMoves = !pkm.IsOriginValid ? new int[4] : getSuggestedMoves(true, true, true); - AllSuggestedRelearnMoves = !pkm.IsOriginValid ? new int[4] : Legal.getValidRelearn(pkm, -1).ToArray(); - AllSuggestedMovesAndRelearn = AllSuggestedMoves.Concat(AllSuggestedRelearnMoves).ToArray(); } private void AddLine(Severity s, string c, CheckIdentifier i) diff --git a/PKHeX/Legality/Checks.cs b/PKHeX/Legality/Checks.cs index ea434d9b4..bda8d1f8c 100644 --- a/PKHeX/Legality/Checks.cs +++ b/PKHeX/Legality/Checks.cs @@ -701,9 +701,9 @@ private CheckResult verifyEncounterWild() switch (pkm.GenNumber) { case 4: - if(pkm.HasOriginalMetLocation && pkm.Met_Location == 193 && enc.All( t => t.Type == SlotType.Surf)) + if (pkm.HasOriginalMetLocation && pkm.Met_Location == 193 && enc.All(t => t.Type == SlotType.Surf)) { - // Pokemon surfing in Jhoto Route 45 + // Pokemon surfing in Johto Route 45 return new CheckResult(Severity.Invalid, V384, CheckIdentifier.Encounter); } break; @@ -749,7 +749,7 @@ private CheckResult verifyEncounterStatic() return new CheckResult(Severity.Invalid, V383, CheckIdentifier.Encounter); if (pkm.Species == 492 && s.Location == 063 && !pkm.Pt) // DP Shaymin return new CheckResult(Severity.Invalid, V354, CheckIdentifier.Encounter); - if (s.Location == 193 && (s as EncounterStaticTyped)?.TypeEncounter == EncounterType.Surfing_Fishing) // Roaming pokemon surfin in Jhoto Route 45 + if (s.Location == 193 && (s as EncounterStaticTyped)?.TypeEncounter == EncounterType.Surfing_Fishing) // Roaming pokemon surfin in Johto Route 45 return new CheckResult(Severity.Invalid, V384, CheckIdentifier.Encounter); break; case 7: @@ -813,11 +813,14 @@ private CheckResult verifyEncounterVC() } private void verifyEncounterType() { + if (pkm.Format >= 7) + return; + EncounterType type = EncounterType.None; // Encounter type data is only stored for gen 4 encounters // Gen 6 -> 7 transfer delete encounter type data // All eggs have encounter type none, even if they are from static encounters - if (pkm.Format < 7 && pkm.Gen4 && !pkm.WasEgg) + if (pkm.Gen4 && !pkm.WasEgg) { if (EncounterMatch is EncounterSlot[]) // If there is more than one slot, the get wild encounter have filter for the pkm type encounter like safari/sports ball @@ -831,12 +834,11 @@ private void verifyEncounterType() AddLine(Severity.NotImplemented, V382, CheckIdentifier.Encounter); return; } + if (type != (EncounterType)pkm.EncounterType) - { AddLine(Severity.Invalid, V381, CheckIdentifier.Encounter); - return; - } - AddLine(Severity.Valid, V380, CheckIdentifier.Encounter); + else + AddLine(Severity.Valid, V380, CheckIdentifier.Encounter); } private CheckResult verifyEncounter()