From 799e4852cf8cdd83f8a720f5f559bd5c1ad61ad8 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 20 Mar 2020 13:33:15 -0700 Subject: [PATCH] Minor clean --- PKHeX.Core/Legality/BulkGenerator.cs | 56 ++++++++++++------- .../Encounters/EncounterSlot/EncounterSlot.cs | 13 ++--- PKHeX.Core/Legality/Verifiers/MiscVerifier.cs | 2 +- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/PKHeX.Core/Legality/BulkGenerator.cs b/PKHeX.Core/Legality/BulkGenerator.cs index abd31551b..e049ba64f 100644 --- a/PKHeX.Core/Legality/BulkGenerator.cs +++ b/PKHeX.Core/Legality/BulkGenerator.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; namespace PKHeX.Core @@ -8,13 +9,18 @@ namespace PKHeX.Core /// public static class BulkGenerator { - public static IList GetLivingDex(SaveFile sav) + public static List GetLivingDex(this SaveFile sav) { var speciesToGenerate = Enumerable.Range(1, sav.MaxSpeciesID); - return GetLivingDex(sav, speciesToGenerate, sav.BlankPKM); + return GetLivingDex(sav, speciesToGenerate); } - public static List GetLivingDex(ITrainerInfo tr, IEnumerable speciesToGenerate, PKM blank) + private static List GetLivingDex(SaveFile sav, IEnumerable speciesToGenerate) + { + return sav.GetLivingDex(speciesToGenerate, sav.BlankPKM); + } + + public static List GetLivingDex(this ITrainerInfo tr, IEnumerable speciesToGenerate, PKM blank) { var result = new List(); var destType = blank.GetType(); @@ -25,28 +31,38 @@ public static List GetLivingDex(ITrainerInfo tr, IEnumerable speciesTo pk.Gender = pk.GetSaneGender(); var pi = pk.PersonalInfo; - for (int i = 0; i < pi.FormeCount; i++) + for (int f = 0; f < pi.FormeCount; f++) { - pk.AltForm = i; - if (s == (int) Species.Indeedee || s == (int) Species.Meowstic) - pk.Gender = i; - - var f = EncounterMovesetGenerator.GeneratePKMs(pk, tr).FirstOrDefault(); - if (f == null) + var entry = tr.GetLivingEntry(pk, s, f, destType); + if (entry == null) continue; - var converted = PKMConverter.ConvertToType(f, destType, out _); - if (converted == null) - continue; - - converted.CurrentLevel = 100; - converted.Species = s; - converted.AltForm = i; - - result.Add(converted); + result.Add(entry); } } return result; } + + public static PKM? GetLivingEntry(this ITrainerInfo tr, PKM template, int species, int form, Type destType) + { + template.Species = species; + template.AltForm = form; + template.Gender = template.GetSaneGender(); + + var f = EncounterMovesetGenerator.GeneratePKMs(template, tr).FirstOrDefault(); + if (f == null) + return null; + + var result = PKMConverter.ConvertToType(f, destType, out _); + if (result == null) + return null; + + result.CurrentLevel = 100; + result.Species = species; + result.AltForm = form; + + result.Heal(); + return result; + } } } diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot.cs index 8caf85622..b60ca00e1 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot.cs @@ -11,6 +11,12 @@ public class EncounterSlot : IEncounterable, IGeneration, ILocation, IVersion public int Form { get; set; } public int LevelMin { get; set; } public int LevelMax { get; set; } + public GameVersion Version { get; set; } + public int Generation { get; set; } = -1; + internal EncounterArea? Area { private get; set; } + public int Location { get => Area?.Location ?? 0; set { } } + public bool EggEncounter => false; + public int EggLocation { get => 0; set { } } /// /// Gets if the specified level inputs are within range of the and @@ -49,15 +55,8 @@ public class EncounterSlot : IEncounterable, IGeneration, ILocation, IVersion public SlotType Type { get; set; } = SlotType.Any; public EncounterType TypeEncounter { get; set; } = EncounterType.None; public int SlotNumber { get; set; } - public int Generation { get; set; } = -1; private EncounterSlotPermissions? _perm; public EncounterSlotPermissions Permissions => _perm ??= new EncounterSlotPermissions(); - public GameVersion Version { get; set; } - - internal EncounterArea? Area { private get; set; } - public int Location { get => Area?.Location ?? 0; set { } } - public bool EggEncounter => false; - public int EggLocation { get => 0; set { } } public EncounterSlot Clone() { diff --git a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs index f5ebc79d6..b2f649105 100644 --- a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs @@ -279,7 +279,7 @@ private static void VerifyFatefulIngameActive(LegalityAnalysis data) data.AddLine(result); } - public void VerifyVersionEvolution(LegalityAnalysis data) + public static void VerifyVersionEvolution(LegalityAnalysis data) { var pkm = data.pkm; if (pkm.Format < 7 || data.EncounterMatch.Species == pkm.Species)