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
|
2016-07-03 03:24:17 +00:00
|
|
|
|
internal static readonly PersonalInfo[] PersonalAO = PersonalInfo.getArray(Properties.Resources.personal_ao, GameVersion.ORAS);
|
|
|
|
|
internal static readonly PersonalInfo[] PersonalXY = PersonalInfo.getArray(Properties.Resources.personal_xy, GameVersion.XY);
|
|
|
|
|
internal static readonly PersonalInfo[] PersonalB2W2 = PersonalInfo.getArray(Properties.Resources.personal_b2w2, GameVersion.B2W2);
|
|
|
|
|
internal static readonly PersonalInfo[] PersonalBW = PersonalInfo.getArray(Properties.Resources.personal_bw, GameVersion.BW);
|
|
|
|
|
internal static readonly PersonalInfo[] PersonalHGSS = PersonalInfo.getArray(Properties.Resources.personal_hgss, GameVersion.HGSS);
|
|
|
|
|
internal static readonly PersonalInfo[] PersonalPt = PersonalInfo.getArray(Properties.Resources.personal_pt, GameVersion.Pt);
|
|
|
|
|
internal static readonly PersonalInfo[] PersonalDP = PersonalInfo.getArray(Properties.Resources.personal_dp, GameVersion.DP);
|
|
|
|
|
|
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-05-10 02:24:52 +00:00
|
|
|
|
{ return getValidMoves(pk6, -1, LVL: true, Relearn: false, Tutor: true, Machine: true); }
|
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;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Defer to EC/PID check
|
|
|
|
|
// if (e.Shiny != null && e.Shiny != pk6.IsShiny)
|
|
|
|
|
// continue;
|
2016-04-21 03:46:18 +00:00
|
|
|
|
|
|
|
|
|
// Defer ball check to later
|
|
|
|
|
// 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)
|
|
|
|
|
{
|
2016-05-10 03:58:12 +00:00
|
|
|
|
int species = pk6.Species;
|
|
|
|
|
List<int> res = new List<int>{species};
|
|
|
|
|
for (int i = 0; i < Evolves.Length; i++)
|
|
|
|
|
if (Evolves[i].Evos.Any(pk => pk.Species == species))
|
|
|
|
|
res.Add(i);
|
2016-03-28 05:05:51 +00:00
|
|
|
|
for (int i = -1; i < 2; i++)
|
|
|
|
|
res.Add(getBaseSpecies(pk6, i));
|
|
|
|
|
return res.Distinct();
|
|
|
|
|
}
|
2016-03-23 02:47:13 +00:00
|
|
|
|
|
2016-05-06 03:35:18 +00:00
|
|
|
|
internal static bool getCanBeCaptured(int species, int version = -1)
|
|
|
|
|
{
|
|
|
|
|
if (version < 0 || version == (int)GameVersion.X)
|
|
|
|
|
{
|
|
|
|
|
if (SlotsX.Any(loc => loc.Slots.Any(slot => slot.Species == species)))
|
|
|
|
|
return true;
|
|
|
|
|
if (FriendSafari.Contains(species))
|
|
|
|
|
return true;
|
|
|
|
|
if (StaticX.Any(enc => enc.Species == species && !enc.Gift))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (version < 0 || version == (int)GameVersion.Y)
|
|
|
|
|
{
|
|
|
|
|
if (SlotsY.Any(loc => loc.Slots.Any(slot => slot.Species == species)))
|
|
|
|
|
return true;
|
|
|
|
|
if (FriendSafari.Contains(species))
|
|
|
|
|
return true;
|
|
|
|
|
if (StaticY.Any(enc => enc.Species == species && !enc.Gift))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (version < 0 || version == (int)GameVersion.AS)
|
|
|
|
|
{
|
|
|
|
|
if (SlotsA.Any(loc => loc.Slots.Any(slot => slot.Species == species)))
|
|
|
|
|
return true;
|
|
|
|
|
if (StaticA.Any(enc => enc.Species == species && !enc.Gift))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (version < 0 || version == (int)GameVersion.OR)
|
|
|
|
|
{
|
|
|
|
|
if (SlotsO.Any(loc => loc.Slots.Any(slot => slot.Species == species)))
|
|
|
|
|
return true;
|
|
|
|
|
if (StaticO.Any(enc => enc.Species == species && !enc.Gift))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-05-10 02:24:52 +00:00
|
|
|
|
internal static bool getCanLearnMachineMove(PK6 pk6, int move, int version = -1)
|
2016-05-10 01:19:31 +00:00
|
|
|
|
{
|
2016-05-10 02:24:52 +00:00
|
|
|
|
return getValidMoves(pk6, version, Machine: true).Contains(move);
|
|
|
|
|
}
|
|
|
|
|
internal static bool getCanRelearnMove(PK6 pk6, int move, int version = -1)
|
|
|
|
|
{
|
|
|
|
|
return getValidMoves(pk6, version, LVL: true, Relearn: true).Contains(move);
|
|
|
|
|
}
|
|
|
|
|
internal static bool getCanLearnMove(PK6 pk6, int move, int version = -1)
|
|
|
|
|
{
|
|
|
|
|
return getValidMoves(pk6, version, Tutor: true, Machine: true).Contains(move);
|
|
|
|
|
}
|
|
|
|
|
internal static bool getCanKnowMove(PK6 pk6, int move, int version = -1)
|
|
|
|
|
{
|
2016-05-29 21:44:08 +00:00
|
|
|
|
if (pk6.Species == 235 && !InvalidSketch.Contains(move))
|
2016-05-10 16:03:51 +00:00
|
|
|
|
return true;
|
2016-05-10 02:24:52 +00:00
|
|
|
|
return getValidMoves(pk6, Version: version, LVL: true, Relearn: true, Tutor: true, Machine: true).Contains(move);
|
2016-05-10 01:19:31 +00:00
|
|
|
|
}
|
2016-05-06 03:35:18 +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-05-10 04:09:38 +00:00
|
|
|
|
if (pk6.Species == 242 && pk6.CurrentLevel < 3) // Never Cleffa
|
|
|
|
|
return 113;
|
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-23 19:31:12 +00:00
|
|
|
|
var encounterSlots = slots.Where(slot => slot.LevelMin - df <= lvl && lvl <= slot.LevelMax + (slot.AllowDexNav ? dn : df)).ToList();
|
2016-04-21 02:47:40 +00:00
|
|
|
|
|
|
|
|
|
// Pressure Slot
|
|
|
|
|
EncounterSlot slotMax = encounterSlots.OrderByDescending(slot => slot.LevelMax).FirstOrDefault();
|
2016-04-23 19:31:12 +00:00
|
|
|
|
if (slotMax != null)
|
|
|
|
|
slotMax = new EncounterSlot(slotMax) { Pressure = true, Form = pk6.AltForm };
|
2016-04-21 02:47:40 +00:00
|
|
|
|
|
|
|
|
|
if (!DexNav)
|
|
|
|
|
{
|
|
|
|
|
// Filter for Form Specific
|
|
|
|
|
slotdata.AddRange(WildForms.Contains(pk6.Species)
|
|
|
|
|
? encounterSlots.Where(slot => slot.Form == pk6.AltForm)
|
|
|
|
|
: encounterSlots);
|
|
|
|
|
if (slotMax != null)
|
2016-04-23 19:31:12 +00:00
|
|
|
|
slotdata.Add(slotMax);
|
2016-04-21 02:47:40 +00:00
|
|
|
|
return slotdata;
|
|
|
|
|
}
|
2016-04-23 19:31:12 +00:00
|
|
|
|
|
|
|
|
|
List<EncounterSlot> eslots = encounterSlots.Where(slot => !WildForms.Contains(pk6.Species) || slot.Form == pk6.AltForm).ToList();
|
2016-04-21 02:47:40 +00:00
|
|
|
|
if (slotMax != null)
|
2016-04-23 19:31:12 +00:00
|
|
|
|
eslots.Add(slotMax);
|
|
|
|
|
foreach (EncounterSlot s in eslots)
|
2016-04-21 02:47:40 +00:00
|
|
|
|
{
|
2016-04-23 19:31:12 +00:00
|
|
|
|
bool nav = s.AllowDexNav && (pk6.RelearnMove1 != 0 || pk6.AbilityNumber == 4);
|
|
|
|
|
EncounterSlot slot = new EncounterSlot(s) { DexNav = nav };
|
2016-04-21 02:47:40 +00:00
|
|
|
|
|
2016-04-23 19:31:12 +00:00
|
|
|
|
if (slot.LevelMin > lvl)
|
2016-04-21 02:47:40 +00:00
|
|
|
|
slot.WhiteFlute = true;
|
2016-04-23 19:31:12 +00:00
|
|
|
|
if (slot.LevelMax + 1 <= lvl && lvl <= slot.LevelMax + fluteBoost)
|
2016-04-21 02:47:40 +00:00
|
|
|
|
slot.BlackFlute = true;
|
2016-04-23 19:31:12 +00:00
|
|
|
|
if (slot.LevelMax != lvl && slot.AllowDexNav)
|
2016-04-21 02:47:40 +00:00
|
|
|
|
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-05-10 02:03:58 +00:00
|
|
|
|
private static IEnumerable<int> getValidMoves(PK6 pk6, int Version, bool LVL = false, bool Relearn = false, bool Tutor = false, bool Machine = false)
|
|
|
|
|
{
|
|
|
|
|
List<int> r = new List<int> { 0 };
|
|
|
|
|
int species = pk6.Species;
|
|
|
|
|
int lvl = pk6.CurrentLevel;
|
|
|
|
|
bool ORASTutors = Version == -1 || pk6.AO || !pk6.IsUntraded;
|
|
|
|
|
if (FormChangeMoves.Contains(species)) // Deoxys & Shaymin & Giratina (others don't have extra but whatever)
|
|
|
|
|
{
|
|
|
|
|
int formcount = PersonalAO[species].FormeCount;
|
|
|
|
|
for (int i = 0; i < formcount; i++)
|
|
|
|
|
r.AddRange(getMoves(species, lvl, i, ORASTutors, Version, LVL, Tutor, Machine));
|
|
|
|
|
if (Relearn) r.AddRange(pk6.RelearnMoves);
|
|
|
|
|
return r.Distinct().ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r.AddRange(getMoves(species, lvl, pk6.AltForm, ORASTutors, Version, LVL, Tutor, Machine));
|
|
|
|
|
IEnumerable<DexLevel> vs = getValidPreEvolutions(pk6);
|
|
|
|
|
|
|
|
|
|
foreach (DexLevel evo in vs)
|
|
|
|
|
r.AddRange(getMoves(evo.Species, evo.Level, pk6.AltForm, ORASTutors, Version, LVL, Tutor, Machine));
|
|
|
|
|
if (species == 479) // Rotom
|
|
|
|
|
r.Add(RotomMoves[pk6.AltForm]);
|
|
|
|
|
if (species == 25) // Pikachu
|
|
|
|
|
r.Add(PikachuMoves[pk6.AltForm]);
|
|
|
|
|
|
|
|
|
|
if (Relearn) r.AddRange(pk6.RelearnMoves);
|
|
|
|
|
return r.Distinct().ToArray();
|
|
|
|
|
}
|
|
|
|
|
private static IEnumerable<int> getMoves(int species, int lvl, int form, bool ORASTutors, int Version, bool LVL, bool Tutor, bool Machine)
|
|
|
|
|
{
|
|
|
|
|
List<int> r = new List<int> { 0 };
|
|
|
|
|
if (Version < 0 || Version == 0)
|
|
|
|
|
{
|
|
|
|
|
int index = PersonalXY[species].FormeIndex(species, form);
|
|
|
|
|
PersonalInfo pi = PersonalXY[index];
|
|
|
|
|
|
|
|
|
|
if (LVL) r.AddRange(LevelUpXY[index].getMoves(lvl));
|
|
|
|
|
if (Tutor) r.AddRange(getTutorMoves(species, form, ORASTutors));
|
|
|
|
|
if (Machine) r.AddRange(TMHM_XY.Where((t, m) => pi.TMHM[m]));
|
|
|
|
|
}
|
|
|
|
|
if (Version < 0 || Version == 1)
|
|
|
|
|
{
|
|
|
|
|
int index = PersonalAO[species].FormeIndex(species, form);
|
|
|
|
|
PersonalInfo pi = PersonalAO[index];
|
|
|
|
|
|
|
|
|
|
if (LVL) r.AddRange(LevelUpAO[index].getMoves(lvl));
|
|
|
|
|
if (Tutor) r.AddRange(getTutorMoves(species, form, ORASTutors));
|
|
|
|
|
if (Machine) r.AddRange(TMHM_AO.Where((t, m) => pi.TMHM[m]));
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
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-05-10 01:07:26 +00:00
|
|
|
|
private static IEnumerable<int> getTutorMoves(int species, int formnum, bool ORASTutors)
|
2016-02-23 06:52:48 +00:00
|
|
|
|
{
|
2016-07-03 03:24:17 +00:00
|
|
|
|
PersonalInfoORAS pkAO = (PersonalInfoORAS)PersonalAO[PersonalAO[species].FormeIndex(species, formnum)];
|
2016-02-23 06:52:48 +00:00
|
|
|
|
|
|
|
|
|
// Type Tutor
|
2016-07-03 03:24:17 +00:00
|
|
|
|
List<int> moves = TypeTutor.Where((t, i) => pkAO.TypeTutors[i]).ToList();
|
2016-02-23 06:52:48 +00:00
|
|
|
|
|
|
|
|
|
// Varied Tutors
|
2016-05-10 01:07:26 +00:00
|
|
|
|
if (ORASTutors)
|
2016-02-23 06:52:48 +00:00
|
|
|
|
for (int i = 0; i < Tutors_AO.Length; i++)
|
|
|
|
|
for (int b = 0; b < Tutors_AO[i].Length; b++)
|
2016-07-03 03:24:17 +00:00
|
|
|
|
if (pkAO.SpecialTutors[i][b])
|
2016-02-23 06:52:48 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|