2016-03-13 21:56:23 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-02-23 06:52:48 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX
|
|
|
|
|
{
|
|
|
|
|
public static partial class Legal
|
|
|
|
|
{
|
2016-03-23 02:47:13 +00:00
|
|
|
|
// PKHeX master Wonder Card Database
|
2016-02-29 01:05:38 +00:00
|
|
|
|
internal static WC6[] WC6DB;
|
2016-02-23 06:52:48 +00:00
|
|
|
|
// PKHeX master personal.dat
|
|
|
|
|
internal static readonly PersonalInfo[] PersonalAO = PersonalInfo.getPersonalArray(Properties.Resources.personal_ao, PersonalInfo.SizeAO);
|
|
|
|
|
private static readonly PersonalInfo[] PersonalXY = PersonalInfo.getPersonalArray(Properties.Resources.personal_xy, PersonalInfo.SizeXY);
|
2016-04-19 01:21:50 +00:00
|
|
|
|
private static readonly EggMoves[] EggMoveXY = EggMoves.getArray(Data.unpackMini(Properties.Resources.eggmove_xy, "xy"));
|
|
|
|
|
private static readonly Learnset[] LevelUpXY = Learnset.getArray(Data.unpackMini(Properties.Resources.lvlmove_xy, "xy"));
|
|
|
|
|
private static readonly EggMoves[] EggMoveAO = EggMoves.getArray(Data.unpackMini(Properties.Resources.eggmove_ao, "ao"));
|
|
|
|
|
private static readonly Learnset[] LevelUpAO = Learnset.getArray(Data.unpackMini(Properties.Resources.lvlmove_ao, "ao"));
|
|
|
|
|
private static readonly Evolutions[] Evolves = Evolutions.getArray(Data.unpackMini(Properties.Resources.evos_ao, "ao"));
|
2016-03-23 02:47:13 +00:00
|
|
|
|
private static readonly EncounterArea[] SlotsA;
|
|
|
|
|
private static readonly EncounterArea[] SlotsO;
|
|
|
|
|
private static readonly EncounterArea[] SlotsX;
|
|
|
|
|
private static readonly EncounterArea[] SlotsY;
|
|
|
|
|
private static readonly EncounterStatic[] StaticX;
|
|
|
|
|
private static readonly EncounterStatic[] StaticY;
|
|
|
|
|
private static readonly EncounterStatic[] StaticA;
|
|
|
|
|
private static readonly EncounterStatic[] StaticO;
|
|
|
|
|
private static EncounterStatic[] getSpecial(GameVersion Game)
|
2016-03-18 03:20:34 +00:00
|
|
|
|
{
|
2016-03-23 02:47:13 +00:00
|
|
|
|
if (Game == GameVersion.X || Game == GameVersion.Y)
|
|
|
|
|
return Encounter_XY.Where(s => s.Version == GameVersion.Any || s.Version == Game).ToArray();
|
|
|
|
|
// else if (Game == GameVersion.AS || Game == GameVersion.OR)
|
|
|
|
|
return Encounter_AO.Where(s => s.Version == GameVersion.Any || s.Version == Game).ToArray();
|
|
|
|
|
}
|
2016-03-18 03:20:34 +00:00
|
|
|
|
private static EncounterArea[] addXYAltTiles(EncounterArea[] GameSlots, EncounterArea[] SpecialSlots)
|
|
|
|
|
{
|
|
|
|
|
foreach (EncounterArea g in GameSlots)
|
|
|
|
|
{
|
|
|
|
|
EncounterArea slots = SpecialSlots.FirstOrDefault(l => l.Location == g.Location);
|
|
|
|
|
if (slots != null)
|
|
|
|
|
g.Slots = g.Slots.Concat(slots.Slots).ToArray();
|
|
|
|
|
}
|
|
|
|
|
return GameSlots;
|
|
|
|
|
}
|
2016-02-25 00:36:26 +00:00
|
|
|
|
|
2016-03-23 02:47:13 +00:00
|
|
|
|
static Legal() // Setup
|
2016-02-25 00:36:26 +00:00
|
|
|
|
{
|
2016-03-23 02:47:13 +00:00
|
|
|
|
StaticX = getSpecial(GameVersion.X);
|
|
|
|
|
StaticY = getSpecial(GameVersion.Y);
|
|
|
|
|
StaticA = getSpecial(GameVersion.AS);
|
|
|
|
|
StaticO = getSpecial(GameVersion.OR);
|
|
|
|
|
|
2016-04-19 01:21:50 +00:00
|
|
|
|
var XSlots = EncounterArea.getArray(Data.unpackMini(Properties.Resources.encounter_x, "xy"));
|
|
|
|
|
var YSlots = EncounterArea.getArray(Data.unpackMini(Properties.Resources.encounter_y, "xy"));
|
2016-03-23 02:47:13 +00:00
|
|
|
|
|
|
|
|
|
// Mark Horde Encounters
|
|
|
|
|
foreach (var area in XSlots)
|
|
|
|
|
{
|
|
|
|
|
int slotct = area.Slots.Length;
|
|
|
|
|
for (int i = slotct - 15; i < slotct; i++)
|
|
|
|
|
area.Slots[i].Type = SlotType.Horde;
|
|
|
|
|
}
|
|
|
|
|
foreach (var area in YSlots)
|
|
|
|
|
{
|
|
|
|
|
int slotct = area.Slots.Length;
|
|
|
|
|
for (int i = slotct - 15; i < slotct; i++)
|
|
|
|
|
area.Slots[i].Type = SlotType.Horde;
|
|
|
|
|
}
|
|
|
|
|
SlotsX = addXYAltTiles(XSlots, SlotsXYAlt);
|
|
|
|
|
SlotsY = addXYAltTiles(YSlots, SlotsXYAlt);
|
|
|
|
|
|
2016-04-19 01:21:50 +00:00
|
|
|
|
SlotsA = EncounterArea.getArray(Data.unpackMini(Properties.Resources.encounter_a, "ao"));
|
|
|
|
|
SlotsO = EncounterArea.getArray(Data.unpackMini(Properties.Resources.encounter_o, "ao"));
|
2016-03-23 02:47:13 +00:00
|
|
|
|
|
2016-04-21 02:47:40 +00:00
|
|
|
|
// Mark Encounters
|
2016-03-23 02:47:13 +00:00
|
|
|
|
foreach (var area in SlotsA)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 32; i < 37; i++)
|
|
|
|
|
area.Slots[i].Type = SlotType.Rock_Smash;
|
|
|
|
|
int slotct = area.Slots.Length;
|
|
|
|
|
for (int i = slotct - 15; i < slotct; i++)
|
|
|
|
|
area.Slots[i].Type = SlotType.Horde;
|
2016-04-21 02:47:40 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < slotct; i++)
|
|
|
|
|
area.Slots[i].AllowDexNav = area.Slots[i].Type != SlotType.Rock_Smash;
|
2016-03-23 02:47:13 +00:00
|
|
|
|
}
|
|
|
|
|
foreach (var area in SlotsO)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 32; i < 37; i++)
|
|
|
|
|
area.Slots[i].Type = SlotType.Rock_Smash;
|
|
|
|
|
int slotct = area.Slots.Length;
|
|
|
|
|
for (int i = slotct - 15; i < slotct; i++)
|
|
|
|
|
area.Slots[i].Type = SlotType.Horde;
|
|
|
|
|
|
2016-04-21 02:47:40 +00:00
|
|
|
|
for (int i = 0; i < slotct; i++)
|
|
|
|
|
area.Slots[i].AllowDexNav = area.Slots[i].Type != SlotType.Rock_Smash;
|
|
|
|
|
}
|
2016-02-26 15:52:08 +00:00
|
|
|
|
}
|
2016-03-23 02:47:13 +00:00
|
|
|
|
|
2016-03-12 17:16:41 +00:00
|
|
|
|
internal static IEnumerable<int> getValidMoves(PK6 pk6)
|
2016-02-26 15:52:08 +00:00
|
|
|
|
{
|
2016-03-04 06:12:22 +00:00
|
|
|
|
List<int> r = new List<int> {0};
|
2016-03-15 06:46:18 +00:00
|
|
|
|
int species = pk6.Species;
|
2016-03-22 06:43:03 +00:00
|
|
|
|
if (FormChangeMoves.Contains(species)) // Deoxys & Shaymin & Giratina (others don't have extra but whatever)
|
2016-03-15 06:46:18 +00:00
|
|
|
|
{
|
|
|
|
|
int formcount = PersonalAO[species].FormeCount;
|
|
|
|
|
for (int i = 0; i < formcount; i++)
|
|
|
|
|
{
|
|
|
|
|
// Check all Forms
|
|
|
|
|
r.AddRange(getLVLMoves(species, pk6.CurrentLevel, i));
|
|
|
|
|
r.AddRange(getTutorMoves(species, i));
|
|
|
|
|
r.AddRange(getMachineMoves(species, i));
|
|
|
|
|
}
|
|
|
|
|
return r.Distinct().ToArray();
|
|
|
|
|
}
|
|
|
|
|
r.AddRange(getLVLMoves(species, pk6.CurrentLevel, pk6.AltForm));
|
|
|
|
|
r.AddRange(getTutorMoves(species, pk6.AltForm));
|
|
|
|
|
r.AddRange(getMachineMoves(species, pk6.AltForm));
|
2016-03-04 06:12:22 +00:00
|
|
|
|
IEnumerable<DexLevel> vs = getValidPreEvolutions(pk6);
|
|
|
|
|
foreach (DexLevel evo in vs)
|
2016-02-26 15:52:08 +00:00
|
|
|
|
{
|
2016-03-15 06:46:18 +00:00
|
|
|
|
r.AddRange(getLVLMoves(evo.Species, evo.Level, pk6.AltForm));
|
|
|
|
|
r.AddRange(getTutorMoves(evo.Species, pk6.AltForm));
|
|
|
|
|
r.AddRange(getMachineMoves(evo.Species, pk6.AltForm));
|
2016-02-26 15:52:08 +00:00
|
|
|
|
}
|
2016-03-15 06:46:18 +00:00
|
|
|
|
if (species == 479) // Rotom
|
|
|
|
|
r.Add(RotomMoves[pk6.AltForm]);
|
|
|
|
|
if (species == 25) // Pikachu
|
|
|
|
|
r.Add(PikachuMoves[pk6.AltForm]);
|
|
|
|
|
|
2016-03-04 06:12:22 +00:00
|
|
|
|
return r.Distinct().ToArray();
|
2016-02-25 00:36:26 +00:00
|
|
|
|
}
|
2016-03-12 17:16:41 +00:00
|
|
|
|
internal static IEnumerable<int> getValidRelearn(PK6 pk6, int skipOption)
|
2016-02-23 06:52:48 +00:00
|
|
|
|
{
|
2016-03-04 06:12:22 +00:00
|
|
|
|
List<int> r = new List<int> { 0 };
|
|
|
|
|
int species = getBaseSpecies(pk6, skipOption);
|
2016-03-15 06:46:18 +00:00
|
|
|
|
r.AddRange(getLVLMoves(species, 1, pk6.AltForm));
|
|
|
|
|
r.AddRange(getEggMoves(species, pk6.Species == 678 ? pk6.AltForm : 0));
|
|
|
|
|
r.AddRange(getLVLMoves(species, 100, pk6.AltForm));
|
2016-03-12 17:16:41 +00:00
|
|
|
|
return r.Distinct();
|
2016-02-23 06:52:48 +00:00
|
|
|
|
}
|
2016-03-23 05:50:54 +00:00
|
|
|
|
internal static IEnumerable<int> getBaseEggMoves(PK6 pk6, int skipOption, int gameSource)
|
2016-03-06 19:19:09 +00:00
|
|
|
|
{
|
2016-03-23 05:50:54 +00:00
|
|
|
|
int species = getBaseSpecies(pk6, skipOption);
|
|
|
|
|
if (gameSource == -1)
|
|
|
|
|
{
|
|
|
|
|
if (pk6.XY)
|
|
|
|
|
return LevelUpXY[species].getMoves(1);
|
|
|
|
|
// if (pk6.Version == 26 || pk6.Version == 27)
|
|
|
|
|
return LevelUpAO[species].getMoves(1);
|
|
|
|
|
}
|
|
|
|
|
if (gameSource == 0) // XY
|
|
|
|
|
return LevelUpXY[species].getMoves(1);
|
|
|
|
|
// if (gameSource == 1) // ORAS
|
|
|
|
|
return LevelUpAO[species].getMoves(1);
|
2016-03-06 19:19:09 +00:00
|
|
|
|
}
|
2016-03-23 05:50:54 +00:00
|
|
|
|
|
2016-03-05 04:43:00 +00:00
|
|
|
|
internal static IEnumerable<WC6> getValidWC6s(PK6 pk6)
|
|
|
|
|
{
|
2016-03-22 02:53:02 +00:00
|
|
|
|
var vs = getValidPreEvolutions(pk6).ToArray();
|
|
|
|
|
List<WC6> validWC6 = new List<WC6>();
|
|
|
|
|
|
|
|
|
|
foreach (WC6 wc in WC6DB.Where(wc => vs.Any(dl => dl.Species == wc.Species)))
|
|
|
|
|
{
|
|
|
|
|
if (pk6.Egg_Location == 0) // Not Egg
|
|
|
|
|
{
|
|
|
|
|
if (wc.CardID != pk6.SID) continue;
|
|
|
|
|
if (wc.TID != pk6.TID) continue;
|
|
|
|
|
if (wc.OT != pk6.OT_Name) continue;
|
|
|
|
|
if (wc.OTGender != pk6.OT_Gender) continue;
|
|
|
|
|
if (wc.PIDType == 0 && pk6.PID != wc.PID) continue;
|
|
|
|
|
if (wc.PIDType == 2 && !pk6.IsShiny) continue;
|
|
|
|
|
if (wc.PIDType == 3 && pk6.IsShiny) continue;
|
|
|
|
|
if (wc.OriginGame != 0 && wc.OriginGame != pk6.Version) continue;
|
|
|
|
|
if (wc.EncryptionConstant != 0 && wc.EncryptionConstant != pk6.EncryptionConstant) continue;
|
|
|
|
|
if (wc.Language != 0 && wc.Language != pk6.Language) continue;
|
|
|
|
|
}
|
|
|
|
|
if (wc.Form != pk6.AltForm && vs.All(dl => !FormChange.Contains(dl.Species))) continue;
|
|
|
|
|
if (wc.MetLocation != pk6.Met_Location) continue;
|
|
|
|
|
if (wc.EggLocation != pk6.Egg_Location) continue;
|
|
|
|
|
if (wc.Level != pk6.Met_Level) continue;
|
|
|
|
|
if (wc.Pokéball != pk6.Ball) continue;
|
|
|
|
|
if (wc.OTGender < 3 && wc.OTGender != pk6.OT_Gender) continue;
|
|
|
|
|
if (wc.Nature != 0xFF && wc.Nature != pk6.Nature) continue;
|
|
|
|
|
if (wc.Gender != 3 && wc.Gender != pk6.Gender) continue;
|
|
|
|
|
|
|
|
|
|
if (wc.CNT_Cool > pk6.CNT_Cool) continue;
|
|
|
|
|
if (wc.CNT_Beauty > pk6.CNT_Beauty) continue;
|
|
|
|
|
if (wc.CNT_Cute > pk6.CNT_Cute) continue;
|
|
|
|
|
if (wc.CNT_Smart > pk6.CNT_Smart) continue;
|
|
|
|
|
if (wc.CNT_Tough > pk6.CNT_Tough) continue;
|
|
|
|
|
if (wc.CNT_Sheen > pk6.CNT_Sheen) continue;
|
2016-03-05 04:43:00 +00:00
|
|
|
|
|
2016-03-22 02:53:02 +00:00
|
|
|
|
// Some checks are best performed separately as they are caused by users screwing up valid data.
|
|
|
|
|
// if (!wc.RelearnMoves.SequenceEqual(pk6.RelearnMoves)) continue; // Defer to relearn legality
|
|
|
|
|
// if (wc.OT.Length > 0 && pk6.CurrentHandler != 1) continue; // Defer to ownership legality
|
|
|
|
|
// if (wc.OT.Length > 0 && pk6.OT_Friendship != PKX.getBaseFriendship(pk6.Species)) continue; // Friendship
|
|
|
|
|
// if (wc.Level > pk6.CurrentLevel) continue; // Defer to level legality
|
|
|
|
|
// RIBBONS: Defer to ribbon legality
|
|
|
|
|
|
|
|
|
|
validWC6.Add(wc);
|
|
|
|
|
}
|
|
|
|
|
return validWC6;
|
2016-03-05 04:43:00 +00:00
|
|
|
|
}
|
2016-03-23 05:50:54 +00:00
|
|
|
|
internal static EncounterLink getValidLinkGifts(PK6 pk6)
|
|
|
|
|
{
|
|
|
|
|
return LinkGifts.FirstOrDefault(g => g.Species == pk6.Species && g.Level == pk6.Met_Level);
|
|
|
|
|
}
|
2016-03-23 02:47:13 +00:00
|
|
|
|
internal static EncounterSlot[] getValidWildEncounters(PK6 pk6)
|
2016-03-10 05:32:42 +00:00
|
|
|
|
{
|
2016-03-23 02:47:13 +00:00
|
|
|
|
List<EncounterSlot> s = new List<EncounterSlot>();
|
2016-03-19 00:18:01 +00:00
|
|
|
|
|
2016-03-23 02:47:13 +00:00
|
|
|
|
foreach (var area in getEncounterAreas(pk6))
|
2016-04-21 02:47:40 +00:00
|
|
|
|
s.AddRange(getValidEncounterSlots(pk6, area, DexNav: pk6.AO));
|
2016-03-23 02:47:13 +00:00
|
|
|
|
return s.Any() ? s.ToArray() : null;
|
2016-03-10 05:32:42 +00:00
|
|
|
|
}
|
2016-03-23 02:47:13 +00:00
|
|
|
|
internal static EncounterStatic getValidStaticEncounter(PK6 pk6)
|
2016-03-13 21:56:23 +00:00
|
|
|
|
{
|
|
|
|
|
// Get possible encounters
|
|
|
|
|
IEnumerable<EncounterStatic> poss = getStaticEncounters(pk6);
|
|
|
|
|
// Back Check against pk6
|
|
|
|
|
foreach (EncounterStatic e in poss)
|
|
|
|
|
{
|
|
|
|
|
if (e.Nature != Nature.Random && pk6.Nature != (int)e.Nature)
|
|
|
|
|
continue;
|
|
|
|
|
if (e.EggLocation != pk6.Egg_Location)
|
|
|
|
|
continue;
|
|
|
|
|
if (e.Location != 0 && e.Location != pk6.Met_Location)
|
|
|
|
|
continue;
|
|
|
|
|
if (e.Gender != -1 && e.Gender != pk6.Gender)
|
|
|
|
|
continue;
|
|
|
|
|
if (e.Level != pk6.Met_Level)
|
|
|
|
|
continue;
|
|
|
|
|
if (e.Shiny != null && e.Shiny != pk6.IsShiny)
|
|
|
|
|
continue;
|
2016-03-14 02:40:47 +00:00
|
|
|
|
if (e.Gift && pk6.Ball != 4) // PokéBall
|
|
|
|
|
continue;
|
2016-03-13 21:56:23 +00:00
|
|
|
|
|
|
|
|
|
// Passes all checks, valid encounter
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2016-03-23 02:47:13 +00:00
|
|
|
|
internal static EncounterTrade getValidIngameTrade(PK6 pk6)
|
2016-03-17 06:29:28 +00:00
|
|
|
|
{
|
2016-03-26 23:40:12 +00:00
|
|
|
|
if (!pk6.WasIngameTrade)
|
|
|
|
|
return null;
|
2016-03-17 06:29:28 +00:00
|
|
|
|
int lang = pk6.Language;
|
|
|
|
|
if (lang == 0)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
// Get valid pre-evolutions
|
|
|
|
|
IEnumerable<DexLevel> p = getValidPreEvolutions(pk6);
|
2016-03-22 04:51:36 +00:00
|
|
|
|
EncounterTrade z = null;
|
2016-03-17 06:29:28 +00:00
|
|
|
|
if (pk6.XY)
|
2016-03-22 04:51:36 +00:00
|
|
|
|
z = lang == 6 ? null : TradeGift_XY.FirstOrDefault(f => p.Any(r => r.Species == f.Species));
|
2016-03-17 06:29:28 +00:00
|
|
|
|
if (pk6.AO)
|
2016-03-22 04:51:36 +00:00
|
|
|
|
z = lang == 6 ? null : TradeGift_AO.FirstOrDefault(f => p.Any(r => r.Species == f.Species));
|
2016-03-17 06:29:28 +00:00
|
|
|
|
|
2016-03-22 04:51:36 +00:00
|
|
|
|
if (z == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
if (z.IVs[i] != -1 && z.IVs[i] != pk6.IVs[i])
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
if (z.Shiny ^ pk6.IsShiny) // Are PIDs static?
|
|
|
|
|
return null;
|
|
|
|
|
if (z.TID != pk6.TID)
|
|
|
|
|
return null;
|
|
|
|
|
if (z.SID != pk6.SID)
|
|
|
|
|
return null;
|
|
|
|
|
if (z.Location != pk6.Met_Location)
|
|
|
|
|
return null;
|
|
|
|
|
if (z.Level != pk6.Met_Level)
|
|
|
|
|
return null;
|
2016-03-26 23:40:12 +00:00
|
|
|
|
if (z.Nature != Nature.Random && (int)z.Nature != pk6.Nature)
|
2016-03-22 04:51:36 +00:00
|
|
|
|
return null;
|
|
|
|
|
if (z.Gender != pk6.Gender)
|
|
|
|
|
return null;
|
|
|
|
|
// if (z.Ability == 4 ^ pk6.AbilityNumber == 4) // defer to Ability
|
|
|
|
|
// return null;
|
|
|
|
|
|
|
|
|
|
return z;
|
2016-03-17 06:29:28 +00:00
|
|
|
|
}
|
2016-03-23 05:31:30 +00:00
|
|
|
|
internal static EncounterSlot[] getValidFriendSafari(PK6 pk6)
|
2016-03-23 02:47:13 +00:00
|
|
|
|
{
|
|
|
|
|
if (!pk6.XY)
|
2016-03-23 05:31:30 +00:00
|
|
|
|
return null;
|
|
|
|
|
if (pk6.Met_Location != 148) // Friend Safari
|
|
|
|
|
return null;
|
|
|
|
|
if (pk6.Met_Level != 30)
|
|
|
|
|
return null;
|
|
|
|
|
|
2016-03-23 02:47:13 +00:00
|
|
|
|
IEnumerable<DexLevel> vs = getValidPreEvolutions(pk6);
|
2016-03-23 05:31:30 +00:00
|
|
|
|
List<EncounterSlot> slots = new List<EncounterSlot>();
|
2016-03-23 02:47:13 +00:00
|
|
|
|
foreach (DexLevel d in vs.Where(d => FriendSafari.Contains(d.Species) && d.Level >= 30))
|
2016-03-23 05:31:30 +00:00
|
|
|
|
{
|
|
|
|
|
var slot = new EncounterSlot
|
|
|
|
|
{
|
|
|
|
|
Species = d.Species,
|
|
|
|
|
LevelMin = 30,
|
|
|
|
|
LevelMax = 30,
|
|
|
|
|
Form = 0,
|
|
|
|
|
Type = SlotType.FriendSafari,
|
|
|
|
|
};
|
|
|
|
|
slots.Add(slot);
|
|
|
|
|
}
|
2016-03-23 02:47:13 +00:00
|
|
|
|
|
2016-03-23 05:31:30 +00:00
|
|
|
|
return slots.Any() ? slots.ToArray() : null;
|
2016-03-23 02:47:13 +00:00
|
|
|
|
}
|
2016-03-23 05:50:54 +00:00
|
|
|
|
|
|
|
|
|
internal static bool getDexNavValid(PK6 pk6)
|
2016-03-23 02:47:13 +00:00
|
|
|
|
{
|
2016-03-23 05:50:54 +00:00
|
|
|
|
IEnumerable<EncounterArea> locs = getDexNavAreas(pk6);
|
2016-04-21 02:47:40 +00:00
|
|
|
|
return locs.Select(loc => getValidEncounterSlots(pk6, loc, DexNav: true)).Any(slots => slots.Any(slot => slot.AllowDexNav && slot.DexNav));
|
2016-03-23 05:50:54 +00:00
|
|
|
|
}
|
|
|
|
|
internal static bool getHasEvolved(PK6 pk6)
|
|
|
|
|
{
|
|
|
|
|
return getValidPreEvolutions(pk6).Count() > 1;
|
|
|
|
|
}
|
|
|
|
|
internal static bool getHasTradeEvolved(PK6 pk6)
|
|
|
|
|
{
|
|
|
|
|
return Evolves[pk6.Species].Evos.Any(evo => evo.Level == 1); // 1: Trade, 0: Item, >=2: Levelup
|
|
|
|
|
}
|
|
|
|
|
internal static bool getIsFossil(PK6 pk6)
|
|
|
|
|
{
|
|
|
|
|
if (pk6.Met_Level != 20)
|
|
|
|
|
return false;
|
|
|
|
|
if (pk6.Egg_Location != 0)
|
|
|
|
|
return false;
|
|
|
|
|
if (pk6.XY && pk6.Met_Location == 44)
|
|
|
|
|
return Fossils.Contains(getBaseSpecies(pk6));
|
|
|
|
|
if (pk6.AO && pk6.Met_Location == 190)
|
|
|
|
|
return Fossils.Contains(getBaseSpecies(pk6));
|
|
|
|
|
|
|
|
|
|
return false;
|
2016-03-23 02:47:13 +00:00
|
|
|
|
}
|
2016-04-08 01:19:21 +00:00
|
|
|
|
internal static bool getEvolutionValid(PK6 pk6)
|
|
|
|
|
{
|
|
|
|
|
var curr = getValidPreEvolutions(pk6);
|
|
|
|
|
var poss = getValidPreEvolutions(pk6, 100);
|
|
|
|
|
|
|
|
|
|
if (SplitBreed.Contains(getBaseSpecies(pk6, 1)))
|
|
|
|
|
return curr.Count() >= poss.Count() - 1;
|
|
|
|
|
return curr.Count() >= poss.Count();
|
|
|
|
|
}
|
2016-03-28 05:05:51 +00:00
|
|
|
|
internal static IEnumerable<int> getLineage(PK6 pk6)
|
|
|
|
|
{
|
|
|
|
|
List<int> res = new List<int>();
|
|
|
|
|
for (int i = -1; i < 2; i++)
|
|
|
|
|
res.Add(getBaseSpecies(pk6, i));
|
|
|
|
|
return res.Distinct();
|
|
|
|
|
}
|
2016-03-23 02:47:13 +00:00
|
|
|
|
|
2016-03-17 02:15:49 +00:00
|
|
|
|
private static int getBaseSpecies(PK6 pk6, int skipOption = 0)
|
2016-02-23 06:52:48 +00:00
|
|
|
|
{
|
2016-03-18 02:37:06 +00:00
|
|
|
|
if (pk6.Species == 292)
|
|
|
|
|
return 290;
|
2016-02-26 15:52:08 +00:00
|
|
|
|
DexLevel[] evos = Evolves[pk6.Species].Evos;
|
|
|
|
|
switch (skipOption)
|
2016-02-23 06:52:48 +00:00
|
|
|
|
{
|
2016-02-26 15:52:08 +00:00
|
|
|
|
case -1: return pk6.Species;
|
2016-03-12 23:05:01 +00:00
|
|
|
|
case 1: return evos.Length <= 1 ? pk6.Species : evos[evos.Length - 2].Species;
|
2016-02-26 15:52:08 +00:00
|
|
|
|
default: return evos.Length <= 0 ? pk6.Species : evos.Last().Species;
|
2016-02-23 06:52:48 +00:00
|
|
|
|
}
|
2016-02-26 15:52:08 +00:00
|
|
|
|
}
|
2016-03-23 02:47:13 +00:00
|
|
|
|
private static IEnumerable<EncounterArea> getDexNavAreas(PK6 pk6)
|
|
|
|
|
{
|
|
|
|
|
bool alpha = pk6.Version == 26;
|
|
|
|
|
if (!alpha && pk6.Version != 27)
|
|
|
|
|
return new EncounterArea[0];
|
2016-04-21 02:47:40 +00:00
|
|
|
|
return (alpha ? SlotsA : SlotsO).Where(l => l.Location == pk6.Met_Location);
|
2016-03-23 02:47:13 +00:00
|
|
|
|
}
|
2016-03-15 06:46:18 +00:00
|
|
|
|
private static IEnumerable<int> getLVLMoves(int species, int lvl, int formnum)
|
2016-03-12 03:43:40 +00:00
|
|
|
|
{
|
2016-03-15 06:46:18 +00:00
|
|
|
|
int ind_XY = PersonalXY[species].FormeIndex(species, formnum);
|
|
|
|
|
int ind_AO = PersonalAO[species].FormeIndex(species, formnum);
|
|
|
|
|
return LevelUpXY[ind_XY].getMoves(lvl).Concat(LevelUpAO[ind_AO].getMoves(lvl));
|
2016-03-12 03:43:40 +00:00
|
|
|
|
}
|
2016-03-12 17:16:41 +00:00
|
|
|
|
private 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>();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-13 21:56:23 +00:00
|
|
|
|
private static IEnumerable<EncounterStatic> getStaticEncounters(PK6 pk6)
|
|
|
|
|
{
|
|
|
|
|
switch (pk6.Version)
|
|
|
|
|
{
|
|
|
|
|
case 24: // X
|
|
|
|
|
return getStatic(pk6, StaticX);
|
|
|
|
|
case 25: // Y
|
|
|
|
|
return getStatic(pk6, StaticY);
|
|
|
|
|
case 26: // AS
|
|
|
|
|
return getStatic(pk6, StaticA);
|
|
|
|
|
case 27: // OR
|
|
|
|
|
return getStatic(pk6, StaticO);
|
|
|
|
|
default: return new List<EncounterStatic>();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-12 17:16:41 +00:00
|
|
|
|
private static IEnumerable<EncounterArea> getEncounterAreas(PK6 pk6)
|
2016-03-12 03:43:40 +00:00
|
|
|
|
{
|
|
|
|
|
return getEncounterSlots(pk6).Where(l => l.Location == pk6.Met_Location);
|
|
|
|
|
}
|
2016-03-12 17:16:41 +00:00
|
|
|
|
private static IEnumerable<EncounterSlot> getValidEncounterSlots(PK6 pk6, EncounterArea loc, bool DexNav)
|
2016-02-26 15:52:08 +00:00
|
|
|
|
{
|
2016-04-21 02:47:40 +00:00
|
|
|
|
const int fluteBoost = 4;
|
|
|
|
|
const int dexnavBoost = 30;
|
|
|
|
|
int df = DexNav ? fluteBoost : 0;
|
|
|
|
|
int dn = DexNav ? fluteBoost + dexnavBoost : 0;
|
|
|
|
|
List<EncounterSlot> slotdata = new List<EncounterSlot>();
|
|
|
|
|
|
2016-03-04 06:12:22 +00:00
|
|
|
|
// Get Valid levels
|
|
|
|
|
IEnumerable<DexLevel> vs = getValidPreEvolutions(pk6);
|
|
|
|
|
// Get slots where pokemon can exist
|
2016-04-21 02:47:40 +00:00
|
|
|
|
IEnumerable<EncounterSlot> slots = loc.Slots.Where(slot => vs.Any(evo => evo.Species == slot.Species && evo.Level >= slot.LevelMin - df));
|
2016-03-07 01:08:04 +00:00
|
|
|
|
|
|
|
|
|
// Filter for Met Level
|
2016-03-19 00:18:01 +00:00
|
|
|
|
int lvl = pk6.Met_Level;
|
2016-04-21 02:47:40 +00:00
|
|
|
|
EncounterSlot[] encounterSlots = slots.Where(slot => slot.LevelMin - df <= lvl && lvl <= slot.LevelMax + (slot.AllowDexNav ? dn : df)).ToArray();
|
|
|
|
|
|
|
|
|
|
// Pressure Slot
|
|
|
|
|
EncounterSlot slotMax = encounterSlots.OrderByDescending(slot => slot.LevelMax).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (!DexNav)
|
|
|
|
|
{
|
|
|
|
|
// Filter for Form Specific
|
|
|
|
|
slotdata.AddRange(WildForms.Contains(pk6.Species)
|
|
|
|
|
? encounterSlots.Where(slot => slot.Form == pk6.AltForm)
|
|
|
|
|
: encounterSlots);
|
|
|
|
|
if (slotMax != null)
|
|
|
|
|
slotdata.Add(new EncounterSlot(slotMax) { Pressure = true, Form = pk6.AltForm });
|
|
|
|
|
return slotdata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (EncounterSlot slot in encounterSlots.Where(slot => !WildForms.Contains(pk6.Species) || slot.Form == pk6.AltForm))
|
|
|
|
|
{
|
|
|
|
|
if (slot.LevelMin >= lvl)
|
|
|
|
|
slotdata.Add(new EncounterSlot(slot) { WhiteFlute = true });
|
|
|
|
|
else if (slot.LevelMax + 1 <= lvl && lvl <= slot.LevelMax + fluteBoost)
|
|
|
|
|
slotdata.Add(new EncounterSlot(slot) { BlackFlute = true });
|
|
|
|
|
else if (slot.LevelMax != lvl && slot.AllowDexNav)
|
|
|
|
|
slotdata.Add(new EncounterSlot(slot) { DexNav = true });
|
|
|
|
|
else
|
|
|
|
|
slotdata.Add(new EncounterSlot(slot));
|
|
|
|
|
}
|
|
|
|
|
if (slotMax != null)
|
|
|
|
|
{
|
|
|
|
|
EncounterSlot slot = new EncounterSlot(slotMax) {Pressure = true, Form = pk6.AltForm};
|
|
|
|
|
|
|
|
|
|
if (slot.LevelMin >= lvl)
|
|
|
|
|
slot.WhiteFlute = true;
|
|
|
|
|
else if (slot.LevelMax + 1 <= lvl && lvl <= slot.LevelMax + fluteBoost)
|
|
|
|
|
slot.BlackFlute = true;
|
|
|
|
|
else if (slot.LevelMax != lvl && slot.AllowDexNav)
|
|
|
|
|
slot.DexNav = true;
|
|
|
|
|
slotdata.Add(slot);
|
|
|
|
|
}
|
|
|
|
|
return slotdata;
|
2016-02-26 15:52:08 +00:00
|
|
|
|
}
|
2016-03-10 05:32:42 +00:00
|
|
|
|
private static IEnumerable<EncounterArea> getSlots(PK6 pk6, IEnumerable<EncounterArea> tables)
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<DexLevel> vs = getValidPreEvolutions(pk6);
|
|
|
|
|
List<EncounterArea> slotLocations = new List<EncounterArea>();
|
|
|
|
|
foreach (var loc in tables)
|
|
|
|
|
{
|
2016-04-21 02:47:40 +00:00
|
|
|
|
IEnumerable<EncounterSlot> slots = loc.Slots.Where(slot => vs.Any(evo => evo.Species == slot.Species));
|
2016-03-10 05:32:42 +00:00
|
|
|
|
|
|
|
|
|
EncounterSlot[] es = slots.ToArray();
|
|
|
|
|
if (es.Length > 0)
|
|
|
|
|
slotLocations.Add(new EncounterArea { Location = loc.Location, Slots = es });
|
|
|
|
|
}
|
|
|
|
|
return slotLocations;
|
|
|
|
|
}
|
2016-04-08 01:19:21 +00:00
|
|
|
|
private static IEnumerable<DexLevel> getValidPreEvolutions(PK6 pk6, int lvl = -1)
|
2016-02-26 15:52:08 +00:00
|
|
|
|
{
|
2016-04-08 01:19:21 +00:00
|
|
|
|
if (lvl < 0)
|
|
|
|
|
lvl = pk6.CurrentLevel;
|
2016-03-18 02:37:06 +00:00
|
|
|
|
if (pk6.Species == 292 && pk6.Met_Level + 1 <= lvl && lvl >= 20)
|
|
|
|
|
return new List<DexLevel>
|
|
|
|
|
{
|
|
|
|
|
new DexLevel { Species = 292, Level = lvl },
|
|
|
|
|
new DexLevel { Species = 290, Level = lvl-1 }
|
|
|
|
|
};
|
|
|
|
|
var evos = Evolves[pk6.Species].Evos;
|
|
|
|
|
List<DexLevel> dl = new List<DexLevel> { new DexLevel { Species = pk6.Species, Level = lvl } };
|
2016-03-04 06:12:22 +00:00
|
|
|
|
foreach (DexLevel evo in evos)
|
|
|
|
|
{
|
2016-03-14 03:43:29 +00:00
|
|
|
|
if (lvl >= pk6.Met_Level && lvl >= evo.Level)
|
2016-03-20 01:06:02 +00:00
|
|
|
|
dl.Add(new DexLevel {Species = evo.Species, Level = lvl});
|
|
|
|
|
else break;
|
2016-03-16 04:46:49 +00:00
|
|
|
|
if (evo.Level > 1) // Level Up (from previous level)
|
2016-03-14 02:58:23 +00:00
|
|
|
|
lvl--;
|
2016-03-04 06:12:22 +00:00
|
|
|
|
}
|
|
|
|
|
return dl;
|
2016-02-23 06:52:48 +00:00
|
|
|
|
}
|
2016-03-13 21:56:23 +00:00
|
|
|
|
private static IEnumerable<EncounterStatic> getStatic(PK6 pk6, IEnumerable<EncounterStatic> table)
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<DexLevel> dl = getValidPreEvolutions(pk6);
|
|
|
|
|
return table.Where(e => dl.Any(d => d.Species == e.Species));
|
|
|
|
|
}
|
2016-03-15 06:46:18 +00:00
|
|
|
|
private static IEnumerable<int> getEggMoves(int species, int formnum)
|
2016-02-23 06:52:48 +00:00
|
|
|
|
{
|
2016-03-15 06:46:18 +00:00
|
|
|
|
int ind_XY = PersonalXY[species].FormeIndex(species, formnum);
|
|
|
|
|
int ind_AO = PersonalAO[species].FormeIndex(species, formnum);
|
|
|
|
|
return EggMoveAO[ind_AO].Moves.Concat(EggMoveXY[ind_XY].Moves);
|
2016-02-23 06:52:48 +00:00
|
|
|
|
}
|
2016-03-15 06:46:18 +00:00
|
|
|
|
private static IEnumerable<int> getTutorMoves(int species, int formnum)
|
2016-02-23 06:52:48 +00:00
|
|
|
|
{
|
2016-03-15 06:46:18 +00:00
|
|
|
|
PersonalInfo pkAO = PersonalAO[PersonalAO[species].FormeIndex(species, formnum)];
|
2016-02-23 06:52:48 +00:00
|
|
|
|
|
|
|
|
|
// Type Tutor
|
|
|
|
|
List<int> moves = TypeTutor.Where((t, i) => pkAO.Tutors[i]).ToList();
|
|
|
|
|
|
|
|
|
|
// Varied Tutors
|
|
|
|
|
for (int i = 0; i < Tutors_AO.Length; i++)
|
|
|
|
|
for (int b = 0; b < Tutors_AO[i].Length; b++)
|
|
|
|
|
if (pkAO.ORASTutors[i][b])
|
|
|
|
|
moves.Add(Tutors_AO[i][b]);
|
|
|
|
|
|
2016-03-19 14:53:55 +00:00
|
|
|
|
// Keldeo - Secret Sword
|
|
|
|
|
if (species == 647)
|
|
|
|
|
moves.Add(548);
|
2016-03-04 06:12:22 +00:00
|
|
|
|
return moves;
|
2016-02-23 06:52:48 +00:00
|
|
|
|
}
|
2016-03-15 06:46:18 +00:00
|
|
|
|
private static IEnumerable<int> getMachineMoves(int species, int formnum)
|
2016-02-23 06:52:48 +00:00
|
|
|
|
{
|
2016-03-15 06:46:18 +00:00
|
|
|
|
PersonalInfo pkXY = PersonalXY[PersonalXY[species].FormeIndex(species, formnum)];
|
|
|
|
|
PersonalInfo pkAO = PersonalAO[PersonalAO[species].FormeIndex(species, formnum)];
|
2016-02-23 06:52:48 +00:00
|
|
|
|
List<int> moves = new List<int>();
|
|
|
|
|
moves.AddRange(TMHM_XY.Where((t, i) => pkXY.TMHM[i]));
|
|
|
|
|
moves.AddRange(TMHM_AO.Where((t, i) => pkAO.TMHM[i]));
|
2016-03-04 06:12:22 +00:00
|
|
|
|
return moves;
|
2016-02-23 06:52:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|