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.
This commit is contained in:
Kaphotics 2016-03-09 21:32:42 -08:00
parent 9729e5a30e
commit 9604589a4a
2 changed files with 34 additions and 1 deletions

View file

@ -96,6 +96,21 @@ namespace PKHeX
vs.Any(dl => dl.Species == wc6.Species) &&
wc6.OT == pk6.OT_Name);
}
internal static IEnumerable<EncounterArea> 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<EncounterArea>();
}
}
private static int getBaseSpecies(PK6 pk6, int skipOption)
{
@ -124,6 +139,23 @@ namespace PKHeX
slots = slots.Where(slot => slot.Form == pk6.AltForm);
return slots;
}
private static IEnumerable<EncounterArea> getSlots(PK6 pk6, IEnumerable<EncounterArea> tables)
{
int species = pk6.Species;
IEnumerable<DexLevel> vs = getValidPreEvolutions(pk6);
List<EncounterArea> slotLocations = new List<EncounterArea>();
foreach (var loc in tables)
{
IEnumerable<EncounterSlot> 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<DexLevel> getValidPreEvolutions(PK6 pk6)
{
var evos = Evolves[pk6.Species].Evos;

View file

@ -100,8 +100,9 @@ namespace PKHeX
public class EncounterArea
{
public readonly int Location;
public int Location;
public EncounterSlot[] Slots;
public EncounterArea() { }
public EncounterArea(byte[] data)
{
Location = BitConverter.ToUInt16(data, 0);