From 9604589a4ada1dd7aeddb4535d86498c92ff0f76 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Wed, 9 Mar 2016 21:32:42 -0800 Subject: [PATCH] Add slot legality fetch for pk6 calling getEncounterSlots(pk6) yields a list of locations and valid slots for given input pk6. For later use in suggestion of legal values. Flexible enough for future fetch of past gen, but I doubt I'd ever be motivated enough to implement past gen checks. --- Legality/Core.cs | 32 ++++++++++++++++++++++++++++++++ Legality/Data.cs | 3 ++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Legality/Core.cs b/Legality/Core.cs index 69012314b..fffbf2c30 100644 --- a/Legality/Core.cs +++ b/Legality/Core.cs @@ -96,6 +96,21 @@ internal static IEnumerable getValidWC6s(PK6 pk6) vs.Any(dl => dl.Species == wc6.Species) && wc6.OT == pk6.OT_Name); } + internal static IEnumerable getEncounterSlots(PK6 pk6) + { + switch (pk6.Version) + { + case 24: // X + return getSlots(pk6, SlotsX); + case 25: // Y + return getSlots(pk6, SlotsY); + case 26: // AS + return getSlots(pk6, SlotsA); + case 27: // OR + return getSlots(pk6, SlotsO); + default: return new List(); + } + } private static int getBaseSpecies(PK6 pk6, int skipOption) { @@ -124,6 +139,23 @@ private static IEnumerable getValidEncounterSlots(PK6 pk6, Encoun slots = slots.Where(slot => slot.Form == pk6.AltForm); return slots; } + private static IEnumerable getSlots(PK6 pk6, IEnumerable tables) + { + int species = pk6.Species; + IEnumerable vs = getValidPreEvolutions(pk6); + List slotLocations = new List(); + foreach (var loc in tables) + { + IEnumerable slots = loc.Slots.Where(slot => vs.Any(evo => evo.Species == slot.Species && evo.Level >= slot.LevelMin)); + if (WildForms.Contains(species)) + slots = slots.Where(slot => slot.Form == pk6.AltForm); + + EncounterSlot[] es = slots.ToArray(); + if (es.Length > 0) + slotLocations.Add(new EncounterArea { Location = loc.Location, Slots = es }); + } + return slotLocations; + } private static IEnumerable getValidPreEvolutions(PK6 pk6) { var evos = Evolves[pk6.Species].Evos; diff --git a/Legality/Data.cs b/Legality/Data.cs index 490f86c14..d1569efd2 100644 --- a/Legality/Data.cs +++ b/Legality/Data.cs @@ -100,8 +100,9 @@ public class DexLevel public class EncounterArea { - public readonly int Location; + public int Location; public EncounterSlot[] Slots; + public EncounterArea() { } public EncounterArea(byte[] data) { Location = BitConverter.ToUInt16(data, 0);