From cb76d51e3818f1a7a09b44123211953256742e77 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 9 Jul 2017 08:47:17 -0700 Subject: [PATCH] Simplify vc transfer checks supply met level so the static encounter has a level to work with instead of 0 Closes #1316 in other areas: level 48 charizard VC1 transfer changed to mewtwo causes minlvl > maxlevel, handle instead of throwing exception. --- PKHeX.Core/Legality/Analysis.cs | 23 +++++++++++-------- PKHeX.Core/Legality/Checks.cs | 17 ++++---------- .../Legality/Encounters/EncounterGenerator.cs | 10 +++++--- PKHeX.Core/Legality/Structures/Learnset.cs | 2 ++ 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/PKHeX.Core/Legality/Analysis.cs b/PKHeX.Core/Legality/Analysis.cs index f8672f6b0..1d5e863f4 100644 --- a/PKHeX.Core/Legality/Analysis.cs +++ b/PKHeX.Core/Legality/Analysis.cs @@ -119,12 +119,6 @@ namespace PKHeX.Core UpdateInfo(); UpdateTypeInfo(); - if (pk.Format > 2) // transferred - { - EncounterOriginalGB = EncounterMatch; - foreach (var z in VerifyVCEncounter(pkm, EncounterMatch.Species, EncounterMatch as GBEncounterData)) - AddLine(z); - } VerifyNickname(); VerifyDVs(); VerifyEVs(); @@ -188,17 +182,28 @@ namespace PKHeX.Core { AddLine(Severity.Invalid, V187, CheckIdentifier.GameOrigin); return; } UpdateInfo(); + if (pkm.VC) + UpdateVCTransferInfo(); UpdateTypeInfo(); UpdateChecks(); } + private void UpdateVCTransferInfo() + { + EncounterOriginalGB = EncounterMatch; + if (pkm.VC1) + Info.EncounterMatch = EncounterGenerator.GetRBYStaticTransfer(pkm.Species, pkm.Met_Level); + else if (pkm.VC2) + Info.EncounterMatch = EncounterGenerator.GetGSStaticTransfer(pkm.Species, pkm.Met_Level); + foreach (var z in VerifyVCEncounter(pkm, EncounterOriginalGB.Species, EncounterOriginalGB as GBEncounterData, Info.EncounterMatch as EncounterStatic)) + AddLine(z); + } private void UpdateInfo() { Info = EncounterFinder.FindVerifiedEncounter(pkm); Encounter = Info.Parse[0]; Parse.AddRange(Info.Parse); } - private void UpdateTradebackG12() { if (pkm.Format == 1) @@ -260,9 +265,9 @@ namespace PKHeX.Core if (pkm.Format >= 7) { if (pkm.VC1) - Info.EncounterMatch = EncounterGenerator.GetRBYStaticTransfer(pkm.Species); + Info.EncounterMatch = EncounterGenerator.GetRBYStaticTransfer(pkm.Species, pkm.Met_Level); else if (pkm.VC2) - Info.EncounterMatch = EncounterGenerator.GetGSStaticTransfer(pkm.Species); + Info.EncounterMatch = EncounterGenerator.GetGSStaticTransfer(pkm.Species, pkm.Met_Level); } if (pkm.GenNumber <= 2 && pkm.TradebackStatus == TradebackType.Any && (EncounterMatch as GBEncounterData)?.Generation != pkm.GenNumber) diff --git a/PKHeX.Core/Legality/Checks.cs b/PKHeX.Core/Legality/Checks.cs index ed6dbfa75..f4172a79a 100644 --- a/PKHeX.Core/Legality/Checks.cs +++ b/PKHeX.Core/Legality/Checks.cs @@ -580,16 +580,10 @@ namespace PKHeX.Core } } } - private static IEnumerable VerifyVCEncounter(PKM pkm, int baseSpecies, GBEncounterData encounter) + private static IEnumerable VerifyVCEncounter(PKM pkm, int baseSpecies, GBEncounterData encounter, EncounterStatic transfer) { - // Sanitize Species to non-future species# - int species = pkm.Species; - if (pkm.VC1 && species > Legal.MaxSpeciesID_1 || - pkm.VC2 && species > Legal.MaxSpeciesID_2) - species = baseSpecies; - // Check existing EncounterMatch - if (encounter == null) + if (encounter == null || transfer == null) yield break; // Avoid duplicate invaild message if (encounter.Encounter is EncounterStatic v && (GameVersion.GBCartEraOnly.Contains(v.Version) || v.Version == GameVersion.VCEvents)) @@ -600,13 +594,12 @@ namespace PKHeX.Core yield return new CheckResult(Severity.Invalid, V79, CheckIdentifier.Encounter); } - var ematch = EncounterGenerator.GetRBYStaticTransfer(species); - if (pkm.Met_Location != ematch.Location) + if (pkm.Met_Location != transfer.Location) yield return new CheckResult(Severity.Invalid, V81, CheckIdentifier.Encounter); - if (pkm.Egg_Location != ematch.EggLocation) + if (pkm.Egg_Location != transfer.EggLocation) yield return new CheckResult(Severity.Invalid, V59, CheckIdentifier.Encounter); - if (species == 150 && pkm.Moves.Contains(6)) // pay day + if (baseSpecies == 150 && pkm.Moves.Contains(6)) // pay day yield return new CheckResult(Severity.Invalid, V82, CheckIdentifier.Encounter); } #endregion diff --git a/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs b/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs index 77b3d4952..c38585397 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterGenerator.cs @@ -1301,12 +1301,14 @@ namespace PKHeX.Core switch (pkm.GenNumber) { case 1: - return GetRBYStaticTransfer(species); + return GetRBYStaticTransfer(species, pkm.Met_Level); + case 2: + return GetGSStaticTransfer(species, pkm.Met_Level); default: return GetStaticEncounters(pkm, 100).OrderBy(s => s.Level).FirstOrDefault(); } } - internal static EncounterStatic GetRBYStaticTransfer(int species) + internal static EncounterStatic GetRBYStaticTransfer(int species, int pkmMetLevel) { return new EncounterStatic { @@ -1318,10 +1320,11 @@ namespace PKHeX.Core Location = 30013, EggLocation = 0, IV3 = true, + Level = pkmMetLevel, Version = GameVersion.RBY }; } - internal static EncounterStatic GetGSStaticTransfer(int species) + internal static EncounterStatic GetGSStaticTransfer(int species, int pkmMetLevel) { return new EncounterStatic { @@ -1333,6 +1336,7 @@ namespace PKHeX.Core Location = 30004, // todo EggLocation = 0, IV3 = true, + Level = pkmMetLevel, Version = GameVersion.GS }; } diff --git a/PKHeX.Core/Legality/Structures/Learnset.cs b/PKHeX.Core/Legality/Structures/Learnset.cs index dc4703886..8ffedb82c 100644 --- a/PKHeX.Core/Legality/Structures/Learnset.cs +++ b/PKHeX.Core/Legality/Structures/Learnset.cs @@ -20,6 +20,8 @@ namespace PKHeX.Core { if (minLevel <= 1 && maxLevel >= 100) return Moves; + if (minLevel > maxLevel) + return new int[0]; int start = Array.FindIndex(Levels, z => z >= minLevel); if (start < 0) return new int[0];