From eac3804c7b95dc9976faa8e5e7f5e62da841860d Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 5 Dec 2019 23:04:24 -0800 Subject: [PATCH] Clean up dexlevel/evocriteria constructor usage DexLevel was the initial abstraction, which was expanded/reused for evolution details I should probably merge the two classes since everything is passed as EvoCriteria The encounter generators do some silly form fuzzy match which can now be more accurately checked since I've moved Form to DexLevel... maybe a future commit can clean that up. encounterarea2 was reusing this class, just use a throwaway readonly struct as our temp value storage --- PKHeX.Core/Legality/Areas/EncounterArea2.cs | 16 ++++++++++++++-- PKHeX.Core/Legality/Core.cs | 7 ++----- PKHeX.Core/Legality/Evolutions/DexLevel.cs | 10 +++++++++- PKHeX.Core/Legality/Evolutions/EvoCriteria.cs | 5 ++++- PKHeX.Core/Legality/Evolutions/EvolutionChain.cs | 6 +++--- .../Legality/Evolutions/EvolutionMethod.cs | 4 +--- PKHeX.Core/Legality/Evolutions/EvolutionTree.cs | 2 +- 7 files changed, 34 insertions(+), 16 deletions(-) diff --git a/PKHeX.Core/Legality/Areas/EncounterArea2.cs b/PKHeX.Core/Legality/Areas/EncounterArea2.cs index ce93daeeb..5a32fbaf1 100644 --- a/PKHeX.Core/Legality/Areas/EncounterArea2.cs +++ b/PKHeX.Core/Legality/Areas/EncounterArea2.cs @@ -196,9 +196,9 @@ private static List GetAreas2Fishing(byte[] data, ref int ofs) } // Read TimeFishGroups - var dl = new List(); + var dl = new List(); while (ofs < data.Length) - dl.Add(new DexLevel { Species = data[ofs++], Level = data[ofs++] }); + dl.Add(new SlotTemplate(data[ofs++], data[ofs++])); // Add TimeSlots foreach (var area in areas) @@ -228,6 +228,18 @@ private static List GetAreas2Fishing(byte[] data, ref int ofs) return areas; } + private readonly struct SlotTemplate + { + public readonly byte Species; + public readonly byte Level; + + public SlotTemplate(byte species, byte level) + { + Species = species; + Level = level; + } + } + private static IEnumerable GetAreas2Headbutt(byte[] data, ref int ofs) { // Read Location Table diff --git a/PKHeX.Core/Legality/Core.cs b/PKHeX.Core/Legality/Core.cs index bdc0c6675..6da4cbef9 100644 --- a/PKHeX.Core/Legality/Core.cs +++ b/PKHeX.Core/Legality/Core.cs @@ -686,19 +686,16 @@ internal static EvoCriteria GetBaseSpecies(PKM pkm, int skipOption = 0, int gene internal static EvoCriteria GetBaseSpecies(PKM pkm, IReadOnlyList evos, int skipOption = 0) => GetBaseSpecies(pkm.Species, evos, skipOption); - private static readonly EvoCriteria Nincada = new EvoCriteria + private static readonly EvoCriteria Nincada = new EvoCriteria(290, 0) { Method = (int)EvolutionType.LevelUp, MinLevel = 20, Level = 20, RequiresLvlUp = true, - Species = 290, Form = 0, }; - private static readonly EvoCriteria EvoEmpty = new EvoCriteria + private static readonly EvoCriteria EvoEmpty = new EvoCriteria(290, 0) { Method = (int)EvolutionType.None, - Species = 0, - Form = 0, }; internal static EvoCriteria GetBaseSpecies(int species, IReadOnlyList evos, int skipOption = 0) diff --git a/PKHeX.Core/Legality/Evolutions/DexLevel.cs b/PKHeX.Core/Legality/Evolutions/DexLevel.cs index 75679f43f..f050f2c57 100644 --- a/PKHeX.Core/Legality/Evolutions/DexLevel.cs +++ b/PKHeX.Core/Legality/Evolutions/DexLevel.cs @@ -5,7 +5,15 @@ /// public class DexLevel { - public int Species { get; set; } + public readonly int Species; + public readonly int Form; + public int Level { get; set; } + + protected DexLevel(int species, int form) + { + Species = species; + Form = form; + } } } \ No newline at end of file diff --git a/PKHeX.Core/Legality/Evolutions/EvoCriteria.cs b/PKHeX.Core/Legality/Evolutions/EvoCriteria.cs index 85059a683..af8985580 100644 --- a/PKHeX.Core/Legality/Evolutions/EvoCriteria.cs +++ b/PKHeX.Core/Legality/Evolutions/EvoCriteria.cs @@ -2,9 +2,12 @@ { public sealed class EvoCriteria : DexLevel { + public EvoCriteria(int species, int form) : base(species, form) + { + } + public int MinLevel { get; set; } public bool RequiresLvlUp { get; set; } - public int Form { get; set; } = -1; public int Method { get; set; } = -1; public bool IsTradeRequired => ((EvolutionType) Method).IsTrade(); diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionChain.cs b/PKHeX.Core/Legality/Evolutions/EvolutionChain.cs index f98667643..6714b53ca 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionChain.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionChain.cs @@ -239,7 +239,7 @@ internal static List GetValidPreEvolutions(PKM pkm, int maxspecieso { return new List(1) { - new EvoCriteria { Species = pkm.Species, Level = lvl, MinLevel = lvl }, + new EvoCriteria(pkm.Species, pkm.AltForm) { Level = lvl, MinLevel = lvl }, }; } @@ -248,8 +248,8 @@ internal static List GetValidPreEvolutions(PKM pkm, int maxspecieso { return new List(2) { - new EvoCriteria { Species = (int)Species.Shedinja, Level = lvl, MinLevel = 20, Form = 0 }, - new EvoCriteria { Species = (int)Species.Nincada, Level = lvl, MinLevel = 1, Form = 0 } + new EvoCriteria((int)Species.Shedinja, 0) { Level = lvl, MinLevel = 20 }, + new EvoCriteria((int)Species.Nincada, 0) { Level = lvl, MinLevel = 1 }, }; } diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionMethod.cs b/PKHeX.Core/Legality/Evolutions/EvolutionMethod.cs index a1d9382bc..be3754aee 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionMethod.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionMethod.cs @@ -105,11 +105,9 @@ private bool HasMetLevelIncreased(PKM pkm, int lvl) public EvoCriteria GetEvoCriteria(int species, int form, int lvl) { - return new EvoCriteria + return new EvoCriteria(species, form) { - Species = species, Level = lvl, - Form = form, Method = Method, }; } diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs index 4a90f3c5f..0d3b03b01 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs @@ -233,7 +233,7 @@ private IEnumerable GetEvolutions(int species, int form) private List GetExplicitLineage(PKM pkm, int maxLevel, bool skipChecks, int maxSpeciesOrigin, int minLevel) { int lvl = maxLevel; - var first = new EvoCriteria { Species = pkm.Species, Level = lvl, Form = pkm.AltForm }; + var first = new EvoCriteria(pkm.Species, pkm.AltForm) { Level = lvl, }; const int maxEvolutions = 3; var dl = new List(maxEvolutions) { first };