2017-05-28 04:17:53 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using static PKHeX.Core.Legal;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2017-09-20 06:19:22 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates matching <see cref="IEncounterable"/> data and relevant <see cref="LegalInfo"/> for a <see cref="PKM"/>.
|
|
|
|
|
/// Logic for generating possible in-game encounter data.
|
|
|
|
|
/// </summary>
|
2017-05-28 04:17:53 +00:00
|
|
|
|
public static class EncounterGenerator
|
|
|
|
|
{
|
2017-09-20 06:19:22 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates possible <see cref="IEncounterable"/> data according to the input PKM data and legality info.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pkm">PKM data</param>
|
|
|
|
|
/// <param name="info">Legality information</param>
|
|
|
|
|
/// <returns>Possible encounters</returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// The iterator lazily finds possible encounters. If no encounters are possible, the enumerable will be empty.
|
|
|
|
|
/// </remarks>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static IEnumerable<IEncounterable> GetEncounters(PKM pkm, LegalInfo info)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-06-02 23:56:38 +00:00
|
|
|
|
switch (info.Generation)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
case 2:
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var enc in GetEncounters12(pkm, info))
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield return enc;
|
|
|
|
|
yield break;
|
|
|
|
|
case 3:
|
2017-06-02 23:56:38 +00:00
|
|
|
|
// info.PIDIV = MethodFinder.Analyze(pkm);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var enc in GetEncounters3(pkm, info))
|
2017-06-02 23:56:38 +00:00
|
|
|
|
yield return enc;
|
|
|
|
|
yield break;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
case 4:
|
|
|
|
|
// info.PIDIV = MethodFinder.Analyze(pkm);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var enc in GetEncounters4(pkm, info))
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield return enc;
|
|
|
|
|
yield break;
|
|
|
|
|
default:
|
|
|
|
|
foreach (var enc in GenerateRawEncounters(pkm))
|
|
|
|
|
yield return enc;
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<IEncounterable> GetEncounters12(PKM pkm, LegalInfo info)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int baseSpecies = GetBaseSpecies(pkm);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
bool g1 = pkm.VC1 || pkm.Format == 1;
|
|
|
|
|
|
|
|
|
|
if (g1 && baseSpecies > MaxSpeciesID_1 || baseSpecies > MaxSpeciesID_2)
|
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
|
|
foreach (var z in GenerateFilteredEncounters(pkm))
|
2017-05-28 23:56:51 +00:00
|
|
|
|
{
|
|
|
|
|
info.Generation = z.Generation;
|
|
|
|
|
info.Game = z.Game;
|
|
|
|
|
yield return z.Encounter;
|
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<IEncounterable> GetEncounters3(PKM pkm, LegalInfo info)
|
2017-06-02 23:56:38 +00:00
|
|
|
|
{
|
2017-06-03 07:12:05 +00:00
|
|
|
|
info.PIDIV = MethodFinder.Analyze(pkm);
|
|
|
|
|
var deferred = new List<IEncounterable>();
|
2017-11-25 21:53:39 +00:00
|
|
|
|
foreach (var z in GenerateRawEncounters3(pkm, info))
|
2017-06-02 23:56:38 +00:00
|
|
|
|
{
|
2017-06-03 22:16:24 +00:00
|
|
|
|
if (z is EncounterSlot w && pkm.Version == 15)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
info.PIDIV = MethodFinder.GetPokeSpotSeeds(pkm, w.SlotNumber).FirstOrDefault() ?? info.PIDIV;
|
2017-06-03 07:12:05 +00:00
|
|
|
|
if (info.PIDIV.Type.IsCompatible3(z, pkm))
|
|
|
|
|
yield return z;
|
|
|
|
|
else
|
|
|
|
|
deferred.Add(z);
|
2017-06-02 23:56:38 +00:00
|
|
|
|
}
|
2017-09-10 02:27:28 +00:00
|
|
|
|
if (deferred.Count == 0)
|
|
|
|
|
yield break;
|
|
|
|
|
|
2017-06-03 07:12:05 +00:00
|
|
|
|
info.PIDIVMatches = false;
|
|
|
|
|
foreach (var z in deferred)
|
|
|
|
|
yield return z;
|
2017-06-02 23:56:38 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<IEncounterable> GetEncounters4(PKM pkm, LegalInfo info)
|
2017-06-02 23:56:38 +00:00
|
|
|
|
{
|
2017-06-03 07:12:05 +00:00
|
|
|
|
info.PIDIV = MethodFinder.Analyze(pkm);
|
2017-10-22 17:41:27 +00:00
|
|
|
|
var deferredPIDIV = new List<IEncounterable>();
|
2017-10-22 16:42:15 +00:00
|
|
|
|
var deferredEType = new List<IEncounterable>();
|
|
|
|
|
|
2017-11-25 21:53:39 +00:00
|
|
|
|
foreach (var z in GenerateRawEncounters4(pkm, info))
|
2017-06-02 23:56:38 +00:00
|
|
|
|
{
|
2017-10-22 16:42:15 +00:00
|
|
|
|
if (!info.PIDIV.Type.IsCompatible4(z, pkm))
|
2017-10-22 17:41:27 +00:00
|
|
|
|
deferredPIDIV.Add(z);
|
2017-11-25 17:48:49 +00:00
|
|
|
|
else if (pkm.Format <= 6 && !IsEncounterTypeMatch(z, pkm.EncounterType))
|
2017-10-22 16:42:15 +00:00
|
|
|
|
deferredEType.Add(z);
|
2017-06-03 07:12:05 +00:00
|
|
|
|
else
|
2017-10-22 16:42:15 +00:00
|
|
|
|
yield return z;
|
2017-06-02 23:56:38 +00:00
|
|
|
|
}
|
2017-10-22 16:42:15 +00:00
|
|
|
|
|
|
|
|
|
foreach (var z in deferredEType)
|
|
|
|
|
yield return z;
|
|
|
|
|
|
2017-10-22 17:41:27 +00:00
|
|
|
|
if (deferredPIDIV.Count == 0)
|
2017-08-27 18:04:31 +00:00
|
|
|
|
yield break;
|
|
|
|
|
|
2017-06-03 07:12:05 +00:00
|
|
|
|
info.PIDIVMatches = false;
|
2017-10-22 17:41:27 +00:00
|
|
|
|
foreach (var z in deferredPIDIV)
|
2017-06-03 07:12:05 +00:00
|
|
|
|
yield return z;
|
2017-06-02 23:56:38 +00:00
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
private static IEnumerable<GBEncounterData> GenerateRawEncounters12(PKM pkm, GameVersion game)
|
|
|
|
|
{
|
2018-01-01 21:53:28 +00:00
|
|
|
|
bool gsc = GameVersion.GSC.Contains(game);
|
|
|
|
|
var gen = gsc ? 2 : 1;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
|
|
|
|
// Since encounter matching is super weak due to limited stored data in the structure
|
|
|
|
|
// Calculate all 3 at the same time and pick the best result (by species).
|
|
|
|
|
// Favor special event move gifts as Static Encounters when applicable
|
2018-01-01 21:53:28 +00:00
|
|
|
|
var maxspeciesorigin = gsc ? MaxSpeciesID_2 : MaxSpeciesID_1;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
DexLevel[] vs = GetValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin).ToArray();
|
2017-05-28 04:17:53 +00:00
|
|
|
|
HashSet<int> species = new HashSet<int>(vs.Select(p => p.Species).ToList());
|
|
|
|
|
|
|
|
|
|
var deferred = new List<IEncounterable>();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var t in GetValidEncounterTrades(pkm, game))
|
2017-06-13 04:05:04 +00:00
|
|
|
|
{
|
2017-08-11 06:23:02 +00:00
|
|
|
|
if (pkm.Format >= 7)
|
|
|
|
|
{
|
|
|
|
|
deferred.Add(t);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-08-25 14:25:59 +00:00
|
|
|
|
yield return new GBEncounterData(pkm, gen, t, t.Version);
|
2017-06-13 04:05:04 +00:00
|
|
|
|
}
|
2017-08-11 06:20:03 +00:00
|
|
|
|
foreach (var s in GetValidStaticEncounter(pkm, game).Where(z => species.Contains(z.Species)))
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
// Valid stadium and non-stadium encounters, return only non-stadium encounters, they are less restrictive
|
2017-08-11 06:20:03 +00:00
|
|
|
|
if (s.Version == GameVersion.Stadium || s.Version == GameVersion.Stadium2)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
deferred.Add(s);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-08-06 03:25:20 +00:00
|
|
|
|
if (s.Version == GameVersion.EventsGBGen2 && s.Species != 251)
|
|
|
|
|
{
|
|
|
|
|
// no Gen2 events outside of Japan besides Celebi
|
2017-10-25 01:27:40 +00:00
|
|
|
|
if (pkm.Japanese)
|
2017-08-11 06:20:03 +00:00
|
|
|
|
deferred.Add(s);
|
|
|
|
|
continue;
|
2017-08-06 03:25:20 +00:00
|
|
|
|
}
|
2018-01-01 21:53:28 +00:00
|
|
|
|
if (gsc && !s.EggEncounter && s.Version == GameVersion.C && !pkm.HasOriginalMetLocation)
|
2017-06-18 23:40:23 +00:00
|
|
|
|
continue;
|
2017-08-25 14:25:59 +00:00
|
|
|
|
yield return new GBEncounterData(pkm, gen, s, s.Version);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-08-25 14:25:59 +00:00
|
|
|
|
foreach (var e in GetValidWildEncounters(pkm, game).OfType<EncounterSlot1>())
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (!species.Contains(e.Species))
|
|
|
|
|
continue;
|
2017-08-25 14:25:59 +00:00
|
|
|
|
yield return new GBEncounterData(pkm, gen, e, e.Version);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-01 21:53:28 +00:00
|
|
|
|
if (gsc)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
bool WasEgg = !pkm.Gen1_NotTradeback && GetWasEgg23(pkm) && !NoHatchFromEgg.Contains(pkm.Species);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
if (WasEgg)
|
|
|
|
|
{
|
|
|
|
|
// Further Filtering
|
|
|
|
|
if (pkm.Format < 3)
|
|
|
|
|
{
|
|
|
|
|
WasEgg &= pkm.Met_Location == 0 || pkm.Met_Level == 1; // 2->1->2 clears met info
|
|
|
|
|
WasEgg &= pkm.CurrentLevel >= 5;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (WasEgg)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int eggspec = GetBaseEggSpecies(pkm);
|
2017-09-23 18:46:10 +00:00
|
|
|
|
if (AllowGen2Crystal(pkm))
|
2017-06-07 04:59:29 +00:00
|
|
|
|
yield return new GBEncounterData(eggspec, GameVersion.C); // gen2 egg
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield return new GBEncounterData(eggspec, GameVersion.GS); // gen2 egg
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var d in deferred)
|
2017-05-28 23:56:51 +00:00
|
|
|
|
yield return new GBEncounterData(pkm, gen, d, game);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-05-28 23:56:51 +00:00
|
|
|
|
private static IEnumerable<GBEncounterData> GenerateFilteredEncounters(PKM pkm)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-11-24 18:13:42 +00:00
|
|
|
|
bool crystal = pkm.Format == 2 && pkm.Met_Location != 0 || pkm.Format >= 7 && pkm.OT_Gender == 1;
|
2017-06-13 04:05:04 +00:00
|
|
|
|
var g1i = new PeekEnumerator<GBEncounterData>(get1().GetEnumerator());
|
|
|
|
|
var g2i = new PeekEnumerator<GBEncounterData>(get2().GetEnumerator());
|
|
|
|
|
var deferred = new List<GBEncounterData>();
|
|
|
|
|
while (g2i.PeekIsNext() || g1i.PeekIsNext())
|
|
|
|
|
{
|
2017-10-23 06:26:37 +00:00
|
|
|
|
var move = GetPreferredGBIterator(g1i, g2i);
|
2017-06-13 04:05:04 +00:00
|
|
|
|
var obj = move.Peek();
|
2017-10-23 06:26:37 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (obj.Generation == 1 && obj.Encounter is EncounterTrade && !IsEncounterTrade1Valid(pkm))
|
2017-06-13 04:05:04 +00:00
|
|
|
|
deferred.Add(obj);
|
|
|
|
|
else
|
|
|
|
|
yield return obj;
|
|
|
|
|
|
|
|
|
|
move.MoveNext();
|
|
|
|
|
}
|
|
|
|
|
foreach (var z in deferred)
|
|
|
|
|
yield return z;
|
|
|
|
|
|
|
|
|
|
IEnumerable<GBEncounterData> get1()
|
|
|
|
|
{
|
|
|
|
|
if (!pkm.Gen2_NotTradeback && !crystal)
|
|
|
|
|
foreach (var z in GenerateRawEncounters12(pkm, GameVersion.RBY))
|
|
|
|
|
yield return z;
|
|
|
|
|
}
|
|
|
|
|
IEnumerable<GBEncounterData> get2()
|
|
|
|
|
{
|
2017-11-24 18:13:42 +00:00
|
|
|
|
if (!pkm.Gen1_NotTradeback)
|
2017-06-13 04:05:04 +00:00
|
|
|
|
foreach (var z in GenerateRawEncounters12(pkm, crystal ? GameVersion.C : GameVersion.GSC))
|
|
|
|
|
yield return z;
|
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-10-23 06:26:37 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the preferred iterator from a pair of <see cref="GBEncounterData"/> iterators based on the highest value <see cref="GBEncounterData.Type"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g1i">Generation 1 Iterator</param>
|
|
|
|
|
/// <param name="g2i">Generation 2 Iterator</param>
|
|
|
|
|
/// <returns>Preferred iterator </returns>
|
|
|
|
|
private static PeekEnumerator<GBEncounterData> GetPreferredGBIterator(PeekEnumerator<GBEncounterData> g1i, PeekEnumerator<GBEncounterData> g2i)
|
|
|
|
|
{
|
|
|
|
|
if (!g1i.PeekIsNext())
|
|
|
|
|
return g2i;
|
|
|
|
|
if (!g2i.PeekIsNext())
|
|
|
|
|
return g1i;
|
|
|
|
|
return g1i.Peek().Type > g2i.Peek().Type ? g1i : g2i;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-28 04:17:53 +00:00
|
|
|
|
private static IEnumerable<IEncounterable> GenerateRawEncounters(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
int ctr = 0;
|
|
|
|
|
if (pkm.WasLink)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidLinkGifts(pkm))
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{ yield return z; ++ctr; }
|
|
|
|
|
if (ctr != 0) yield break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-02 23:56:38 +00:00
|
|
|
|
if (pkm.WasEvent || pkm.WasEventEgg)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidGifts(pkm))
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{ yield return z; ++ctr; }
|
|
|
|
|
if (ctr != 0) yield break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-02 23:56:38 +00:00
|
|
|
|
if (pkm.WasEgg)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GenerateEggs(pkm))
|
2017-06-18 02:08:40 +00:00
|
|
|
|
{ yield return z; ++ctr; }
|
2018-01-07 05:51:58 +00:00
|
|
|
|
if (ctr == 0) yield break;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidStaticEncounter(pkm))
|
2017-05-31 01:42:50 +00:00
|
|
|
|
{ yield return z; ++ctr; }
|
2017-06-02 23:56:38 +00:00
|
|
|
|
if (ctr != 0) yield break;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidFriendSafari(pkm))
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{ yield return z; ++ctr; }
|
2017-06-02 23:56:38 +00:00
|
|
|
|
if (ctr != 0) yield break;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidWildEncounters(pkm))
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{ yield return z; ++ctr; }
|
2017-06-02 23:56:38 +00:00
|
|
|
|
if (ctr != 0) yield break;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidEncounterTrades(pkm))
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{ yield return z; ++ctr; }
|
|
|
|
|
// if (ctr != 0) yield break;
|
2017-06-02 23:56:38 +00:00
|
|
|
|
}
|
2017-11-25 21:53:39 +00:00
|
|
|
|
private static IEnumerable<IEncounterable> GenerateRawEncounters4(PKM pkm, LegalInfo info)
|
2017-06-02 23:56:38 +00:00
|
|
|
|
{
|
|
|
|
|
bool wasEvent = pkm.WasEvent || pkm.WasEventEgg; // egg events?
|
|
|
|
|
if (wasEvent)
|
|
|
|
|
{
|
2017-10-25 05:25:52 +00:00
|
|
|
|
int ctr = 0;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidGifts(pkm))
|
2017-06-02 23:56:38 +00:00
|
|
|
|
{ yield return z; ++ctr; }
|
|
|
|
|
if (ctr != 0) yield break;
|
|
|
|
|
}
|
|
|
|
|
if (pkm.WasEgg)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GenerateEggs(pkm))
|
2017-10-25 05:25:52 +00:00
|
|
|
|
yield return z;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-11-25 21:53:39 +00:00
|
|
|
|
foreach (var z in GetValidEncounterTrades(pkm))
|
|
|
|
|
yield return z;
|
2017-06-02 23:56:38 +00:00
|
|
|
|
|
2017-12-14 00:17:02 +00:00
|
|
|
|
var deferred = new LinkedList<IEncounterable>();
|
|
|
|
|
bool sport = pkm.Ball == 0x18; // never static encounters (conflict with non bcc / bcc)
|
|
|
|
|
bool safari = pkm.Ball == 0x05; // never static encounters
|
|
|
|
|
bool safariSport = safari || sport;
|
2017-06-02 23:56:38 +00:00
|
|
|
|
if (!safariSport)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidStaticEncounter(pkm))
|
2017-08-11 03:51:21 +00:00
|
|
|
|
{
|
|
|
|
|
if (z.Gift && pkm.Ball != 4)
|
2017-12-14 00:17:02 +00:00
|
|
|
|
deferred.AddLast(z);
|
2017-08-11 03:51:21 +00:00
|
|
|
|
else
|
2017-10-25 05:25:52 +00:00
|
|
|
|
yield return z;
|
2017-08-11 03:51:21 +00:00
|
|
|
|
}
|
2017-11-25 21:53:39 +00:00
|
|
|
|
|
|
|
|
|
var slots = FrameFinder.GetFrames(info.PIDIV, pkm).ToList();
|
2017-10-25 05:25:52 +00:00
|
|
|
|
foreach (var z in GetValidWildEncounters(pkm))
|
2017-11-25 21:53:39 +00:00
|
|
|
|
{
|
2017-12-14 00:17:02 +00:00
|
|
|
|
if (sport != z.Type.HasFlag(SlotType.BugContest))
|
|
|
|
|
{
|
|
|
|
|
deferred.AddLast(z);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-30 05:31:52 +00:00
|
|
|
|
var frame = slots.FirstOrDefault(s => s.IsSlotCompatibile(z, pkm));
|
2017-12-03 03:54:50 +00:00
|
|
|
|
if (frame != null || pkm.Species == 201) // Unown -- don't really care to figure this out
|
2017-11-25 21:53:39 +00:00
|
|
|
|
yield return z;
|
2017-11-29 05:30:53 +00:00
|
|
|
|
else
|
2017-12-14 00:17:02 +00:00
|
|
|
|
deferred.AddFirst(z);
|
2017-11-25 21:53:39 +00:00
|
|
|
|
}
|
2017-11-29 05:30:53 +00:00
|
|
|
|
info.FrameMatches = false;
|
2017-06-02 23:56:38 +00:00
|
|
|
|
|
2017-12-14 00:17:02 +00:00
|
|
|
|
foreach (var z in deferred)
|
|
|
|
|
yield return z;
|
|
|
|
|
|
2017-06-02 23:56:38 +00:00
|
|
|
|
// do static encounters if they were deferred to end, spit out any possible encounters for invalid pkm
|
|
|
|
|
if (safariSport)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidStaticEncounter(pkm))
|
2017-06-02 23:56:38 +00:00
|
|
|
|
yield return z;
|
|
|
|
|
}
|
2017-11-25 21:53:39 +00:00
|
|
|
|
private static IEnumerable<IEncounterable> GenerateRawEncounters3(PKM pkm, LegalInfo info)
|
2017-06-02 23:56:38 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidGifts(pkm))
|
2017-06-03 07:12:05 +00:00
|
|
|
|
yield return z;
|
2017-11-25 21:53:39 +00:00
|
|
|
|
foreach (var z in GetValidEncounterTrades(pkm))
|
|
|
|
|
yield return z;
|
2017-06-02 23:56:38 +00:00
|
|
|
|
|
2017-12-14 00:17:02 +00:00
|
|
|
|
var deferred = new Queue<IEncounterable>();
|
2017-06-02 23:56:38 +00:00
|
|
|
|
bool safari = pkm.Ball == 0x05; // never static encounters
|
|
|
|
|
if (!safari)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidStaticEncounter(pkm))
|
2017-08-29 01:12:57 +00:00
|
|
|
|
{
|
|
|
|
|
if (z.Gift && pkm.Ball != 4)
|
2017-12-14 00:17:02 +00:00
|
|
|
|
deferred.Enqueue(z);
|
2017-08-29 01:12:57 +00:00
|
|
|
|
else
|
|
|
|
|
yield return z;
|
|
|
|
|
}
|
2017-11-25 21:53:39 +00:00
|
|
|
|
var slots = FrameFinder.GetFrames(info.PIDIV, pkm).ToList();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidWildEncounters(pkm))
|
2017-11-25 21:53:39 +00:00
|
|
|
|
{
|
2017-11-30 05:31:52 +00:00
|
|
|
|
var frame = slots.FirstOrDefault(s => s.IsSlotCompatibile(z, pkm));
|
|
|
|
|
if (frame != null)
|
2017-11-25 21:53:39 +00:00
|
|
|
|
yield return z;
|
2017-11-29 05:30:53 +00:00
|
|
|
|
else
|
2017-12-14 00:17:02 +00:00
|
|
|
|
deferred.Enqueue(z);
|
2017-11-25 21:53:39 +00:00
|
|
|
|
}
|
2017-11-29 05:30:53 +00:00
|
|
|
|
info.FrameMatches = false;
|
2017-06-02 23:56:38 +00:00
|
|
|
|
|
2017-10-25 05:25:52 +00:00
|
|
|
|
if (pkm.Version != 15) // no eggs in C/XD
|
|
|
|
|
foreach (var z in GenerateEggs(pkm))
|
|
|
|
|
yield return z;
|
|
|
|
|
|
2017-12-14 00:17:02 +00:00
|
|
|
|
foreach (var z in deferred)
|
|
|
|
|
yield return z;
|
2017-06-02 23:56:38 +00:00
|
|
|
|
// do static encounters if they were deferred to end, spit out any possible encounters for invalid pkm
|
|
|
|
|
if (safari)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidStaticEncounter(pkm))
|
2017-06-02 23:56:38 +00:00
|
|
|
|
yield return z;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EncounterStatic
|
2017-08-31 04:30:07 +00:00
|
|
|
|
private static bool IsValidCatchRatePK1(EncounterStatic e, PK1 pk1)
|
|
|
|
|
{
|
|
|
|
|
var catch_rate = pk1.Catch_Rate;
|
|
|
|
|
// Pure gen 1, trades can be filter by catch rate
|
2017-09-20 05:55:05 +00:00
|
|
|
|
if (pk1.Species == 25 || pk1.Species == 26)
|
|
|
|
|
{
|
|
|
|
|
if (catch_rate == 190) // Red Blue Pikachu, is not a static encounter
|
|
|
|
|
return false;
|
|
|
|
|
if (catch_rate == 163 && e.Level == 5) // Light Ball (Yellow) starter
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-08-31 04:30:07 +00:00
|
|
|
|
|
|
|
|
|
if (e.Version == GameVersion.Stadium)
|
|
|
|
|
{
|
|
|
|
|
switch (e.Species)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
return Stadium_CatchRate.Contains(catch_rate);
|
|
|
|
|
case 054: // Psyduck
|
|
|
|
|
// Amnesia Psyduck has different catch rates depending on language
|
|
|
|
|
return catch_rate == (pk1.Japanese ? 167 : 168);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Encounters can have different Catch Rates (RBG vs Y)
|
|
|
|
|
var rate = e.Version == GameVersion.Y
|
|
|
|
|
? PersonalTable.Y[e.Species].CatchRate
|
|
|
|
|
: PersonalTable.RB[e.Species].CatchRate;
|
|
|
|
|
return catch_rate == rate;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<EncounterStatic> GetValidStaticEncounter(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (gameSource == GameVersion.Any)
|
|
|
|
|
gameSource = (GameVersion)pkm.Version;
|
|
|
|
|
|
|
|
|
|
// Get possible encounters
|
2017-06-18 01:37:19 +00:00
|
|
|
|
IEnumerable<EncounterStatic> poss = GetStaticEncounters(pkm, gameSource: gameSource);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int lvl = GetMinLevelEncounter(pkm);
|
2017-07-12 16:02:54 +00:00
|
|
|
|
if (lvl < 0)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
|
|
// Back Check against pkm
|
2017-10-22 16:42:15 +00:00
|
|
|
|
var enc = GetMatchingStaticEncounters(pkm, poss, lvl);
|
|
|
|
|
foreach (var z in enc)
|
|
|
|
|
yield return z;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<EncounterStatic> GetMatchingStaticEncounters(PKM pkm, IEnumerable<EncounterStatic> poss, int lvl)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-07-14 06:12:30 +00:00
|
|
|
|
// check for petty rejection scenarios that will be flagged by other legality checks
|
|
|
|
|
var deferred = new List<EncounterStatic>();
|
2017-05-28 04:17:53 +00:00
|
|
|
|
foreach (EncounterStatic e in poss)
|
|
|
|
|
{
|
2017-12-17 02:24:03 +00:00
|
|
|
|
if (!GetIsMatchStatic(pkm, e, lvl))
|
2017-05-28 04:17:53 +00:00
|
|
|
|
continue;
|
2017-12-17 02:24:03 +00:00
|
|
|
|
|
|
|
|
|
if (pkm.FatefulEncounter != e.Fateful)
|
|
|
|
|
deferred.Add(e);
|
|
|
|
|
else
|
|
|
|
|
yield return e;
|
|
|
|
|
}
|
|
|
|
|
foreach (var e in deferred)
|
|
|
|
|
yield return e;
|
|
|
|
|
}
|
|
|
|
|
private static bool GetIsMatchStatic(PKM pkm, EncounterStatic e, int lvl)
|
|
|
|
|
{
|
|
|
|
|
if (e.Nature != Nature.Random && pkm.Nature != (int) e.Nature)
|
|
|
|
|
return false;
|
|
|
|
|
if (pkm.WasEgg != e.EggEncounter && pkm.Egg_Location == 0 && pkm.Format > 3 && pkm.GenNumber > 3 && !pkm.IsEgg)
|
|
|
|
|
return false;
|
2017-12-18 23:25:40 +00:00
|
|
|
|
if (e is EncounterStaticPID p && p.PID != pkm.PID)
|
|
|
|
|
return false;
|
2017-12-17 02:24:03 +00:00
|
|
|
|
|
|
|
|
|
if (pkm.Gen3 && e.EggLocation != 0) // Gen3 Egg
|
|
|
|
|
{
|
|
|
|
|
if (pkm.Format == 3 && pkm.IsEgg && e.EggLocation != pkm.Met_Location)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (pkm.VC || pkm.GenNumber <= 2 && e.EggLocation != 0) // Gen2 Egg
|
|
|
|
|
{
|
|
|
|
|
if (pkm.Format <= 2)
|
2017-06-13 05:16:20 +00:00
|
|
|
|
{
|
2017-12-17 02:24:03 +00:00
|
|
|
|
if (pkm.IsEgg)
|
2017-06-13 05:16:20 +00:00
|
|
|
|
{
|
2017-12-17 02:24:03 +00:00
|
|
|
|
if (pkm.Met_Location != 0 && pkm.Met_Level != 0)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
switch (pkm.Met_Level)
|
2017-06-13 05:16:20 +00:00
|
|
|
|
{
|
2017-12-17 02:24:03 +00:00
|
|
|
|
case 0 when pkm.Met_Location != 0:
|
|
|
|
|
return false;
|
|
|
|
|
case 1 when pkm.Met_Location == 0:
|
|
|
|
|
return false;
|
|
|
|
|
default: if (pkm.Met_Location == 0)
|
|
|
|
|
return false;
|
|
|
|
|
break;
|
2017-06-13 05:16:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-02 05:51:36 +00:00
|
|
|
|
if (pkm.Met_Level == 1)
|
|
|
|
|
lvl = 5; // met @ 1, hatch @ 5.
|
2017-06-13 05:16:20 +00:00
|
|
|
|
}
|
2017-12-17 02:24:03 +00:00
|
|
|
|
}
|
|
|
|
|
else if (e.EggLocation != pkm.Egg_Location)
|
|
|
|
|
{
|
2017-12-18 23:25:40 +00:00
|
|
|
|
if (pkm.IsEgg) // unhatched
|
|
|
|
|
{
|
|
|
|
|
if (e.EggLocation != pkm.Met_Location)
|
|
|
|
|
return false;
|
|
|
|
|
if (pkm.Egg_Location != 0)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-01-21 19:57:34 +00:00
|
|
|
|
else if (pkm.Gen4)
|
2017-06-12 01:39:19 +00:00
|
|
|
|
{
|
2018-01-21 19:57:34 +00:00
|
|
|
|
if (pkm.Egg_Location != 2002) // Link Trade
|
|
|
|
|
{
|
|
|
|
|
// check Pt/HGSS data
|
|
|
|
|
if (pkm.Format <= 4)
|
|
|
|
|
return false; // must match
|
|
|
|
|
if (e.EggLocation >= 3000 || e.EggLocation <= 2010) // non-Pt/HGSS egg gift
|
2017-12-17 02:24:03 +00:00
|
|
|
|
return false;
|
2018-01-21 19:57:34 +00:00
|
|
|
|
|
|
|
|
|
// transferring 4->5 clears pt/hgss location value and keeps Faraway Place
|
|
|
|
|
if (pkm.Egg_Location != 3002) // Faraway Place
|
2017-12-17 02:24:03 +00:00
|
|
|
|
return false;
|
2018-01-21 19:57:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (pkm.Egg_Location != 30002) // Link Trade
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (e.EggLocation != 0 && pkm.Gen4)
|
|
|
|
|
{
|
|
|
|
|
// Check the inverse scenario for 4->5 eggs
|
|
|
|
|
if (e.EggLocation < 3000 && e.EggLocation > 2010) // Pt/HGSS egg gift
|
|
|
|
|
{
|
|
|
|
|
if (pkm.Format > 4)
|
|
|
|
|
return false; // locations match when it shouldn't
|
2017-06-12 01:39:19 +00:00
|
|
|
|
}
|
2017-12-17 02:24:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pkm.HasOriginalMetLocation)
|
|
|
|
|
{
|
|
|
|
|
if (!e.EggEncounter && e.Location != 0 && e.Location != pkm.Met_Location)
|
|
|
|
|
return false;
|
|
|
|
|
if (e.Level != lvl)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-12-17 02:24:03 +00:00
|
|
|
|
if (!(pkm.Format == 3 && e.EggEncounter && lvl == 0))
|
|
|
|
|
return false;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-17 02:24:03 +00:00
|
|
|
|
else if (e.Level > lvl)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (e.Gender != -1 && e.Gender != pkm.Gender)
|
|
|
|
|
return false;
|
2018-01-13 20:10:17 +00:00
|
|
|
|
if (e.Form != pkm.AltForm && !e.SkipFormCheck && !IsFormChangeable(pkm, e.Species, e.Form))
|
2017-12-17 02:24:03 +00:00
|
|
|
|
return false;
|
|
|
|
|
if (e.EggLocation == 60002 && e.Relearn[0] == 0 && pkm.RelearnMoves.Any(z => z != 0)) // gen7 eevee edge case
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Defer to EC/PID check
|
|
|
|
|
// if (e.Shiny != null && e.Shiny != pkm.IsShiny)
|
|
|
|
|
// continue;
|
|
|
|
|
|
|
|
|
|
// Defer ball check to later
|
|
|
|
|
// if (e.Gift && pkm.Ball != 4) // PokéBall
|
|
|
|
|
// continue;
|
|
|
|
|
|
|
|
|
|
if (pkm is PK1 pk1 && pk1.Gen1_NotTradeback)
|
|
|
|
|
if (!IsValidCatchRatePK1(e, pk1))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!AllowGBCartEra && GameVersion.GBCartEraOnly.Contains(e.Version))
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-08-29 01:12:57 +00:00
|
|
|
|
private static IEnumerable<EncounterStatic> GetStaticEncounters(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (gameSource == GameVersion.Any)
|
|
|
|
|
gameSource = (GameVersion)pkm.Version;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var table = GetEncounterStaticTable(pkm, gameSource);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
switch (pkm.GenNumber)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
2017-08-29 01:12:57 +00:00
|
|
|
|
return GetStatic(pkm, table, maxspeciesorigin: MaxSpeciesID_1);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
case 2:
|
2017-08-29 01:12:57 +00:00
|
|
|
|
return GetStatic(pkm, table, maxspeciesorigin: MaxSpeciesID_2);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
default:
|
2017-08-29 01:12:57 +00:00
|
|
|
|
return GetStatic(pkm, table);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-29 01:12:57 +00:00
|
|
|
|
private static IEnumerable<EncounterStatic> GetStatic(PKM pkm, IEnumerable<EncounterStatic> table, int maxspeciesorigin = -1, int lvl = -1, bool skip = false)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-08-29 01:12:57 +00:00
|
|
|
|
IEnumerable<DexLevel> dl = GetValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin, lvl: lvl, skipChecks: skip);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
return table.Where(e => dl.Any(d => d.Species == e.Species));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EncounterSlot
|
2017-06-30 07:37:17 +00:00
|
|
|
|
private static IEnumerable<EncounterSlot> GetRawEncounterSlots(PKM pkm, int lvl, GameVersion gameSource = GameVersion.Any)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-11-19 20:41:23 +00:00
|
|
|
|
int maxspeciesorigin = -1;
|
|
|
|
|
if (gameSource == GameVersion.RBY) maxspeciesorigin = MaxSpeciesID_1;
|
|
|
|
|
else if (GameVersion.GSC.Contains(gameSource)) maxspeciesorigin = MaxSpeciesID_2;
|
|
|
|
|
|
2017-11-19 23:26:41 +00:00
|
|
|
|
var vs = GetValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin);
|
|
|
|
|
return GetEncounterAreas(pkm, gameSource).SelectMany(area => GetValidEncounterSlots(pkm, area, vs, DexNav: pkm.AO, lvl: lvl));
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<EncounterSlot> GetValidWildEncounters(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (gameSource == GameVersion.Any)
|
|
|
|
|
gameSource = (GameVersion)pkm.Version;
|
|
|
|
|
|
2017-06-30 07:37:17 +00:00
|
|
|
|
int lvl = GetMinLevelEncounter(pkm);
|
|
|
|
|
if (lvl <= 0)
|
|
|
|
|
yield break;
|
|
|
|
|
var s = GetRawEncounterSlots(pkm, lvl, gameSource);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
bool IsSafariBall = pkm.Ball == 5;
|
|
|
|
|
bool IsSportsBall = pkm.Ball == 0x18;
|
2017-05-28 18:10:01 +00:00
|
|
|
|
bool IsHidden = pkm.AbilityNumber == 4; // hidden Ability
|
|
|
|
|
int species = pkm.Species;
|
|
|
|
|
|
|
|
|
|
var deferred = new List<EncounterSlot>();
|
|
|
|
|
foreach (EncounterSlot slot in s)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-06-30 06:50:24 +00:00
|
|
|
|
// check for petty rejection scenarios that will be flagged by other legality checks
|
|
|
|
|
// defer these edge case scenarios in the event that a later encounter ends up passing
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (slot.Species == 265 && species != 265 && !IsWurmpleEvoValid(pkm)) { } // bad wurmple evolution
|
2017-05-28 18:10:01 +00:00
|
|
|
|
else if (IsHidden ^ IsHiddenAbilitySlot(slot)) { } // ability mismatch
|
|
|
|
|
else if (IsSafariBall ^ IsSafariSlot(slot.Type)) { } // Safari Zone only ball
|
|
|
|
|
else if (IsSportsBall ^ slot.Type == SlotType.BugContest) { } // BCC only ball
|
|
|
|
|
else
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
yield return slot;
|
2017-05-28 18:10:01 +00:00
|
|
|
|
continue;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-05-28 18:10:01 +00:00
|
|
|
|
deferred.Add(slot);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-05-28 18:10:01 +00:00
|
|
|
|
foreach (var d in deferred)
|
|
|
|
|
yield return d;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<EncounterSlot> GetValidFriendSafari(PKM pkm)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (!pkm.XY)
|
|
|
|
|
yield break;
|
|
|
|
|
if (pkm.Met_Location != 148) // Friend Safari
|
|
|
|
|
yield break;
|
|
|
|
|
if (pkm.Met_Level != 30)
|
|
|
|
|
yield break;
|
|
|
|
|
|
2017-12-23 19:49:20 +00:00
|
|
|
|
var vs = GetValidPreEvolutions(pkm).Where(d => d.Level >= 30);
|
|
|
|
|
foreach (var slot in vs.SelectMany(z => Encounters6.FriendSafari[z.Species]))
|
|
|
|
|
yield return slot;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-11-19 23:26:41 +00:00
|
|
|
|
private static IEnumerable<EncounterSlot> GetValidEncounterSlots(PKM pkm, EncounterArea loc, IEnumerable<DexLevel> vs, bool DexNav = false, int lvl = -1, bool ignoreLevel = false)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2018-01-07 05:51:58 +00:00
|
|
|
|
if (pkm.WasEgg)
|
|
|
|
|
return Enumerable.Empty<EncounterSlot>();
|
2017-06-30 07:37:17 +00:00
|
|
|
|
if (lvl < 0)
|
|
|
|
|
lvl = GetMinLevelEncounter(pkm);
|
|
|
|
|
if (lvl <= 0)
|
2017-11-11 17:35:07 +00:00
|
|
|
|
return Enumerable.Empty<EncounterSlot>();
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2017-11-11 17:35:07 +00:00
|
|
|
|
int gen = pkm.GenNumber;
|
2017-11-19 23:26:41 +00:00
|
|
|
|
if (gen < 3)
|
|
|
|
|
return GetValidEncounterSlots12(pkm, loc, vs, lvl, ignoreLevel);
|
|
|
|
|
|
|
|
|
|
const int fluteBoost = 4;
|
2017-11-11 17:35:07 +00:00
|
|
|
|
const int dexnavBoost = 30;
|
|
|
|
|
int df = DexNav ? fluteBoost : 0;
|
|
|
|
|
int dn = DexNav ? fluteBoost + dexnavBoost : 0;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2017-11-19 23:26:41 +00:00
|
|
|
|
// Get Valid levels
|
2017-11-19 20:41:23 +00:00
|
|
|
|
var encounterSlots = GetValidEncounterSlotsByEvoLevel(pkm, loc.Slots, lvl, ignoreLevel, vs, df, dn);
|
2017-06-30 06:50:24 +00:00
|
|
|
|
|
2017-11-11 17:35:07 +00:00
|
|
|
|
// Return enumerable of slots pkm might have originated from
|
|
|
|
|
if (gen <= 5)
|
|
|
|
|
return GetFilteredSlotsByForm(pkm, encounterSlots);
|
|
|
|
|
if (DexNav && gen == 6)
|
|
|
|
|
return GetFilteredSlots6DexNav(pkm, lvl, encounterSlots, fluteBoost);
|
|
|
|
|
return GetFilteredSlots67(pkm, encounterSlots);
|
|
|
|
|
}
|
2017-11-19 23:26:41 +00:00
|
|
|
|
private static IEnumerable<EncounterSlot> GetValidEncounterSlots12(PKM pkm, EncounterArea loc, IEnumerable<DexLevel> vs, int lvl = -1, bool ignoreLevel = false)
|
|
|
|
|
{
|
|
|
|
|
if (lvl < 0)
|
|
|
|
|
lvl = GetMinLevelEncounter(pkm);
|
|
|
|
|
if (lvl <= 0)
|
|
|
|
|
return Enumerable.Empty<EncounterSlot>();
|
|
|
|
|
|
|
|
|
|
var Gen1Version = GameVersion.RBY;
|
|
|
|
|
bool RBDragonair = false;
|
|
|
|
|
if (!ignoreLevel && !FilterGBSlotsCatchRate(pkm, ref vs, ref Gen1Version, ref RBDragonair))
|
|
|
|
|
return Enumerable.Empty<EncounterSlot>();
|
|
|
|
|
|
|
|
|
|
var encounterSlots = GetValidEncounterSlotsByEvoLevel(pkm, loc.Slots, lvl, ignoreLevel, vs);
|
|
|
|
|
return GetFilteredSlots12(pkm, pkm.GenNumber, Gen1Version, encounterSlots, RBDragonair).OrderBy(slot => slot.LevelMin); // prefer lowest levels
|
|
|
|
|
}
|
2017-12-23 19:49:20 +00:00
|
|
|
|
private static IEnumerable<EncounterSlot> GetValidEncounterSlotsByEvoLevel(PKM pkm, IEnumerable<EncounterSlot> slots, int lvl, bool ignoreLevel, IEnumerable<DexLevel> vs, int df = 0, int dn = 0)
|
2017-11-11 17:35:07 +00:00
|
|
|
|
{
|
2017-11-19 20:41:23 +00:00
|
|
|
|
// Get slots where pokemon can exist with respect to the evolution chain
|
2017-05-28 04:17:53 +00:00
|
|
|
|
if (ignoreLevel)
|
2017-11-19 20:41:23 +00:00
|
|
|
|
return slots.Where(slot => vs.Any(evo => evo.Species == slot.Species)).ToList();
|
|
|
|
|
|
|
|
|
|
slots = slots.Where(slot => vs.Any(evo => evo.Species == slot.Species && evo.Level >= slot.LevelMin - df));
|
|
|
|
|
// Get slots where pokemon can exist with respect to level constraints
|
2017-11-11 17:35:07 +00:00
|
|
|
|
if (pkm.HasOriginalMetLocation)
|
|
|
|
|
return slots.Where(slot => slot.LevelMin - df <= lvl && lvl <= slot.LevelMax + (slot.Permissions.AllowDexNav ? dn : df)).ToList();
|
|
|
|
|
// check for any less than current level
|
|
|
|
|
return slots.Where(slot => slot.LevelMin <= lvl).ToList();
|
|
|
|
|
}
|
|
|
|
|
private static IEnumerable<EncounterSlot> GetFilteredSlotsByForm(PKM pkm, IEnumerable<EncounterSlot> encounterSlots)
|
|
|
|
|
{
|
|
|
|
|
return WildForms.Contains(pkm.Species)
|
|
|
|
|
? encounterSlots.Where(slot => slot.Form == pkm.AltForm)
|
|
|
|
|
: encounterSlots;
|
|
|
|
|
}
|
2017-12-23 19:49:20 +00:00
|
|
|
|
private static IEnumerable<EncounterSlot> GetFilteredSlots67(PKM pkm, IEnumerable<EncounterSlot> encounterSlots)
|
2017-11-11 17:35:07 +00:00
|
|
|
|
{
|
|
|
|
|
int species = pkm.Species;
|
|
|
|
|
int form = pkm.AltForm;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2017-11-18 04:02:01 +00:00
|
|
|
|
// Edge Case Handling
|
|
|
|
|
switch (species)
|
|
|
|
|
{
|
|
|
|
|
case 744 when form == 1:
|
|
|
|
|
case 745 when form == 2:
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-23 19:49:20 +00:00
|
|
|
|
var slots = new List<EncounterSlot>();
|
2017-11-11 17:35:07 +00:00
|
|
|
|
if (AlolanVariantEvolutions12.Contains(species)) // match form if same species, else form 0.
|
2017-12-23 19:49:20 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var slot in encounterSlots)
|
|
|
|
|
{
|
|
|
|
|
if (species == slot.Species ? slot.Form == form : slot.Form == 0)
|
|
|
|
|
yield return slot;
|
|
|
|
|
slots.Add(slot);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-14 16:43:04 +00:00
|
|
|
|
else if (ShouldMatchSlotForm()) // match slot form
|
2017-12-23 19:49:20 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var slot in encounterSlots)
|
|
|
|
|
{
|
|
|
|
|
if (slot.Form == form)
|
|
|
|
|
yield return slot;
|
|
|
|
|
slots.Add(slot);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-11 17:35:07 +00:00
|
|
|
|
else
|
2017-12-23 19:49:20 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var slot in encounterSlots)
|
|
|
|
|
{
|
|
|
|
|
yield return slot; // no form checking
|
|
|
|
|
slots.Add(slot);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-11 17:35:07 +00:00
|
|
|
|
|
|
|
|
|
// Filter for Form Specific
|
2017-05-28 04:17:53 +00:00
|
|
|
|
// Pressure Slot
|
2017-12-23 19:49:20 +00:00
|
|
|
|
EncounterSlot slotMax = slots.OrderByDescending(slot => slot.LevelMax).FirstOrDefault();
|
2017-11-11 17:35:07 +00:00
|
|
|
|
if (slotMax == null)
|
|
|
|
|
yield break; // yield break;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2017-11-11 17:35:07 +00:00
|
|
|
|
if (AlolanVariantEvolutions12.Contains(species)) // match form if same species, else form 0.
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-11-11 17:35:07 +00:00
|
|
|
|
if (species == slotMax.Species ? slotMax.Form == form : slotMax.Form == 0)
|
|
|
|
|
yield return GetPressureSlot(slotMax, pkm);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-11-14 16:43:04 +00:00
|
|
|
|
else if (ShouldMatchSlotForm()) // match slot form
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-11-11 17:35:07 +00:00
|
|
|
|
if (slotMax.Form == form)
|
|
|
|
|
yield return GetPressureSlot(slotMax, pkm);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-11-11 17:35:07 +00:00
|
|
|
|
else
|
|
|
|
|
yield return GetPressureSlot(slotMax, pkm);
|
2017-11-14 16:43:04 +00:00
|
|
|
|
|
|
|
|
|
bool ShouldMatchSlotForm() => WildForms.Contains(species) || AlolanOriginForms.Contains(species) || FormConverter.IsTotemForm(species, form);
|
2017-11-11 17:35:07 +00:00
|
|
|
|
}
|
2017-12-23 19:49:20 +00:00
|
|
|
|
private static IEnumerable<EncounterSlot> GetFilteredSlots6DexNav(PKM pkm, int lvl, IEnumerable<EncounterSlot> encounterSlots, int fluteBoost)
|
2017-11-11 17:35:07 +00:00
|
|
|
|
{
|
2017-12-23 19:49:20 +00:00
|
|
|
|
var slots = new List<EncounterSlot>();
|
|
|
|
|
foreach (EncounterSlot s in encounterSlots)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-12-23 19:49:20 +00:00
|
|
|
|
if (WildForms.Contains(pkm.Species) && s.Form != pkm.AltForm)
|
|
|
|
|
{
|
|
|
|
|
slots.Add(s);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
bool nav = s.Permissions.AllowDexNav && (pkm.RelearnMove1 != 0 || pkm.AbilityNumber == 4);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
EncounterSlot slot = s.Clone();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
slot.Permissions.DexNav = nav;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
|
|
|
|
if (slot.LevelMin > lvl)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
slot.Permissions.WhiteFlute = true;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
if (slot.LevelMax + 1 <= lvl && lvl <= slot.LevelMax + fluteBoost)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
slot.Permissions.BlackFlute = true;
|
|
|
|
|
if (slot.LevelMax != lvl && slot.Permissions.AllowDexNav)
|
|
|
|
|
slot.Permissions.DexNav = true;
|
2017-06-30 07:37:17 +00:00
|
|
|
|
yield return slot;
|
2017-12-23 19:49:20 +00:00
|
|
|
|
slots.Add(s);
|
2017-06-30 07:37:17 +00:00
|
|
|
|
}
|
2017-11-11 17:35:07 +00:00
|
|
|
|
// Pressure Slot
|
2017-12-23 19:49:20 +00:00
|
|
|
|
EncounterSlot slotMax = slots.OrderByDescending(slot => slot.LevelMax).FirstOrDefault();
|
2017-06-30 07:37:17 +00:00
|
|
|
|
if (slotMax != null)
|
2017-11-11 17:35:07 +00:00
|
|
|
|
yield return GetPressureSlot(slotMax, pkm);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-11-11 17:35:07 +00:00
|
|
|
|
private static EncounterSlot GetPressureSlot(EncounterSlot s, PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
var max = s.Clone();
|
|
|
|
|
max.Permissions.Pressure = true;
|
|
|
|
|
max.Form = pkm.AltForm;
|
|
|
|
|
return max;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-19 23:26:41 +00:00
|
|
|
|
private static bool FilterGBSlotsCatchRate(PKM pkm, ref IEnumerable<DexLevel> vs, ref GameVersion Gen1Version, ref bool RBDragonair)
|
2017-07-07 00:01:29 +00:00
|
|
|
|
{
|
|
|
|
|
if (!(pkm is PK1 pk1) || !pkm.Gen1_NotTradeback)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// Pure gen 1, slots can be filter by catch rate
|
2017-08-31 04:30:07 +00:00
|
|
|
|
var rate = pk1.Catch_Rate;
|
2017-07-07 00:01:29 +00:00
|
|
|
|
switch (pkm.Species)
|
|
|
|
|
{
|
|
|
|
|
// Pikachu
|
2017-08-31 04:30:07 +00:00
|
|
|
|
case 25 when rate == 163:
|
|
|
|
|
case 26 when rate == 163:
|
2017-07-07 00:01:29 +00:00
|
|
|
|
return false; // Yellow Pikachu is not a wild encounter
|
|
|
|
|
|
|
|
|
|
// Kadabra (YW)
|
2017-08-31 04:30:07 +00:00
|
|
|
|
case 64 when rate == 96:
|
|
|
|
|
case 65 when rate == 96:
|
2017-07-07 00:01:29 +00:00
|
|
|
|
vs = vs.Where(s => s.Species == 64);
|
|
|
|
|
Gen1Version = GameVersion.YW;
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// Kadabra (RB)
|
2017-08-31 04:30:07 +00:00
|
|
|
|
case 64 when rate == 100:
|
|
|
|
|
case 65 when rate == 100:
|
2017-07-07 00:01:29 +00:00
|
|
|
|
vs = vs.Where(s => s.Species == 64);
|
|
|
|
|
Gen1Version = GameVersion.RB;
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// Dragonair (YW)
|
2017-08-31 04:30:07 +00:00
|
|
|
|
case 148 when rate == 27:
|
|
|
|
|
case 149 when rate == 27:
|
2017-07-07 00:01:29 +00:00
|
|
|
|
vs = vs.Where(s => s.Species == 148); // Yellow Dragonair, ignore Dratini encounters
|
|
|
|
|
Gen1Version = GameVersion.YW;
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// Dragonair (RB)
|
|
|
|
|
case 148:
|
|
|
|
|
case 149:
|
|
|
|
|
// Red blue dragonair have the same catch rate as dratini, it could also be a dratini from any game
|
2017-08-31 04:30:07 +00:00
|
|
|
|
vs = vs.Where(s => rate == PersonalTable.RB[s.Species].CatchRate);
|
2017-07-07 00:01:29 +00:00
|
|
|
|
RBDragonair = true;
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
default:
|
2017-08-31 04:30:07 +00:00
|
|
|
|
vs = vs.Where(s => rate == PersonalTable.RB[s.Species].CatchRate);
|
2017-07-07 00:01:29 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-11 17:35:07 +00:00
|
|
|
|
private static IEnumerable<EncounterSlot> GetFilteredSlots12(PKM pkm, int gen, GameVersion Gen1Version, IEnumerable<EncounterSlot> slots, bool RBDragonair)
|
2017-07-07 00:01:29 +00:00
|
|
|
|
{
|
|
|
|
|
switch (gen)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
if (Gen1Version != GameVersion.RBY)
|
|
|
|
|
slots = slots.Where(slot => Gen1Version.Contains(((EncounterSlot1)slot).Version));
|
|
|
|
|
|
|
|
|
|
// Red Blue dragonair or dratini from any gen 1 games
|
|
|
|
|
if (RBDragonair)
|
|
|
|
|
return slots.Where(slot => GameVersion.RB.Contains(((EncounterSlot1)slot).Version) || slot.Species == 147);
|
|
|
|
|
|
|
|
|
|
return slots;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
if (pkm is PK2 pk2 && pk2.Met_Day != 0)
|
2017-12-23 19:49:20 +00:00
|
|
|
|
return slots.Where(slot => ((EncounterSlot1)slot).Time.Contains(pk2.Met_Day));
|
2017-07-07 00:01:29 +00:00
|
|
|
|
return slots;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2017-07-07 00:01:29 +00:00
|
|
|
|
default:
|
|
|
|
|
return slots;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-19 20:41:23 +00:00
|
|
|
|
private static IEnumerable<EncounterArea> GetEncounterSlots(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (gameSource == GameVersion.Any)
|
|
|
|
|
gameSource = (GameVersion)pkm.Version;
|
|
|
|
|
|
2017-11-19 20:41:23 +00:00
|
|
|
|
return GetEncounterTable(pkm, gameSource);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<EncounterArea> GetEncounterAreas(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (gameSource == GameVersion.Any)
|
|
|
|
|
gameSource = (GameVersion)pkm.Version;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var slots = GetEncounterSlots(pkm, gameSource: gameSource);
|
2017-06-13 01:15:26 +00:00
|
|
|
|
bool noMet = !pkm.HasOriginalMetLocation || pkm.Format == 2 && gameSource != GameVersion.C;
|
|
|
|
|
return noMet ? slots : slots.Where(area => area.Location == pkm.Met_Location);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EncounterLink
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<EncounterLink> GetValidLinkGifts(PKM pkm)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
switch (pkm.GenNumber)
|
|
|
|
|
{
|
|
|
|
|
case 6:
|
2017-07-25 07:28:43 +00:00
|
|
|
|
return Encounters6.LinkGifts6.Where(g => g.Species == pkm.Species && g.Level == pkm.Met_Level);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
default:
|
2017-10-23 22:44:01 +00:00
|
|
|
|
return Enumerable.Empty<EncounterLink>();
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EncounterTrade
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static EncounterTrade[] GetEncounterTradeTable(PKM pkm)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
switch (pkm.GenNumber)
|
|
|
|
|
{
|
|
|
|
|
case 3:
|
2017-07-25 07:28:43 +00:00
|
|
|
|
return pkm.FRLG ? Encounters3.TradeGift_FRLG : Encounters3.TradeGift_RSE;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
case 4:
|
2017-07-25 07:28:43 +00:00
|
|
|
|
return pkm.HGSS ? Encounters4.TradeGift_HGSS : Encounters4.TradeGift_DPPt;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
case 5:
|
2017-07-25 07:28:43 +00:00
|
|
|
|
return pkm.B2W2 ? Encounters5.TradeGift_B2W2 : Encounters5.TradeGift_BW;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
case 6:
|
2017-07-25 07:28:43 +00:00
|
|
|
|
return pkm.XY ? Encounters6.TradeGift_XY : Encounters6.TradeGift_AO;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
case 7:
|
2017-09-01 05:37:28 +00:00
|
|
|
|
return pkm.SM ? Encounters7.TradeGift_SM : Encounters7.TradeGift_USUM;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<EncounterTrade> GetValidEncounterTradesVC(PKM pkm, GameVersion gameSource)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var p = GetValidPreEvolutions(pkm).ToArray();
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
|
|
|
|
switch (gameSource)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.RBY:
|
2017-07-25 07:28:43 +00:00
|
|
|
|
var table = !AllowGen1Tradeback ? Encounters1.TradeGift_RBY_NoTradeback : Encounters1.TradeGift_RBY_Tradeback;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetValidEncounterTradesVC1(pkm, p, table);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
case GameVersion.GSC:
|
2017-06-13 01:15:26 +00:00
|
|
|
|
case GameVersion.C:
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetValidEncounterTradesVC2(pkm, p);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<EncounterTrade> GetValidEncounterTradesVC2(PKM pkm, DexLevel[] p)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
// Check GSC trades. Reuse generic table fetch-match
|
2017-07-25 07:28:43 +00:00
|
|
|
|
var possible = GetValidEncounterTradesVC1(pkm, p, Encounters2.TradeGift_GSC);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
|
|
|
|
foreach (var z in possible)
|
|
|
|
|
{
|
|
|
|
|
// Filter Criteria
|
|
|
|
|
if (z.TID != pkm.TID)
|
|
|
|
|
continue;
|
2017-06-18 05:44:05 +00:00
|
|
|
|
if (z.Gender >= 0 && z.Gender != pkm.Gender && pkm.Format <= 2)
|
2017-06-13 01:15:26 +00:00
|
|
|
|
continue;
|
2017-06-18 05:44:05 +00:00
|
|
|
|
if (z.IVs[0] >= 0 && !z.IVs.SequenceEqual(pkm.IVs) && pkm.Format <= 2)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
continue;
|
2017-06-17 06:14:22 +00:00
|
|
|
|
if (pkm.Met_Location != 0 && pkm.Format == 2 && pkm.Met_Location != 126)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2017-07-25 07:28:43 +00:00
|
|
|
|
int index = Array.IndexOf(Encounters2.TradeGift_GSC, z);
|
|
|
|
|
if (Encounters2.TradeGift_GSC_OTs[index].All(ot => ot != pkm.OT_Name))
|
2017-05-28 04:17:53 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
yield return z;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<EncounterTrade> GetValidEncounterTradesVC1(PKM pkm, DexLevel[] p, IEnumerable<EncounterTrade> table)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
var possible = table.Where(f => p.Any(r => r.Species == f.Species));
|
|
|
|
|
foreach (var z in possible)
|
|
|
|
|
{
|
|
|
|
|
if (z == null)
|
|
|
|
|
continue;
|
|
|
|
|
if (z.Level > pkm.CurrentLevel) // minimum required level
|
|
|
|
|
continue;
|
|
|
|
|
if (pkm.Format != 1 || !pkm.Gen1_NotTradeback)
|
|
|
|
|
yield return z;
|
|
|
|
|
|
|
|
|
|
// Even if the in game trade uses the tables with source pokemon allowing generation 2 games, the traded pokemon could be a non-tradeback pokemon
|
|
|
|
|
var rate = (pkm as PK1)?.Catch_Rate;
|
2017-09-20 06:19:22 +00:00
|
|
|
|
if (z is EncounterTradeCatchRate r)
|
2017-07-06 23:03:41 +00:00
|
|
|
|
{
|
|
|
|
|
if (rate != r.Catch_Rate)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (z.Version == GameVersion.YW && rate != PersonalTable.Y[z.Species].CatchRate)
|
|
|
|
|
continue;
|
|
|
|
|
if (z.Version != GameVersion.YW && rate != PersonalTable.RB[z.Species].CatchRate)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
|
|
|
|
yield return z;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<EncounterTrade> GetValidEncounterTrades(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (gameSource == GameVersion.Any)
|
|
|
|
|
gameSource = (GameVersion)pkm.Version;
|
|
|
|
|
|
|
|
|
|
if (pkm.VC || pkm.Format <= 2)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
foreach (var z in GetValidEncounterTradesVC(pkm, gameSource))
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield return z;
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int lang = pkm.Language;
|
2017-10-23 04:01:08 +00:00
|
|
|
|
if (lang == (int)LanguageID.UNUSED_6) // invalid language
|
2017-09-16 00:43:31 +00:00
|
|
|
|
yield break;
|
2017-10-23 04:01:08 +00:00
|
|
|
|
if (lang == (int)LanguageID.Hacked && (pkm.Format != 5 || !pkm.BW)) // Japanese trades in BW have no language ID
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield break;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int lvl = GetMinLevelEncounter(pkm);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
if (lvl <= 0)
|
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
|
|
// Get valid pre-evolutions
|
2017-06-18 01:37:19 +00:00
|
|
|
|
IEnumerable<DexLevel> p = GetValidPreEvolutions(pkm);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
EncounterTrade[] table = GetEncounterTradeTable(pkm);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
if (table == null)
|
|
|
|
|
yield break;
|
|
|
|
|
var poss = table.Where(f => p.Any(r => r.Species == f.Species) && f.Version.Contains((GameVersion)pkm.Version));
|
|
|
|
|
|
|
|
|
|
foreach (var z in poss)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (IsEncounterTradeValid(pkm, z, lvl))
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield return z;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool IsEncounterTradeValid(PKM pkm, EncounterTrade z, int lvl)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
if (z.IVs[i] != -1 && z.IVs[i] != pkm.IVs[i])
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-09-21 04:28:29 +00:00
|
|
|
|
if (z is EncounterTradePID p)
|
|
|
|
|
{
|
|
|
|
|
if (p.PID != pkm.EncryptionConstant)
|
|
|
|
|
return false;
|
2017-12-16 22:09:03 +00:00
|
|
|
|
if (z.Nature != Nature.Random && (int)z.Nature != pkm.Nature) // gen5 BW only
|
|
|
|
|
return false;
|
2017-09-21 04:28:29 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (z.Shiny ^ pkm.IsShiny)
|
|
|
|
|
return false;
|
|
|
|
|
if (z.Nature != Nature.Random && (int)z.Nature != pkm.Nature)
|
|
|
|
|
return false;
|
|
|
|
|
if (z.Gender != -1 && z.Gender != pkm.Gender)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
if (z.TID != pkm.TID)
|
|
|
|
|
return false;
|
|
|
|
|
if (z.SID != pkm.SID)
|
|
|
|
|
return false;
|
|
|
|
|
if (pkm.HasOriginalMetLocation)
|
|
|
|
|
{
|
2017-06-17 06:14:22 +00:00
|
|
|
|
var loc = z.Location > 0 ? z.Location : EncounterTrade.DefaultMetLocation[pkm.GenNumber - 1];
|
|
|
|
|
if (loc != pkm.Met_Location)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
return false;
|
|
|
|
|
if (pkm.Format < 5)
|
|
|
|
|
{
|
|
|
|
|
if (z.Level > lvl)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (z.Level != lvl)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (z.Level > lvl)
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-09-21 04:28:29 +00:00
|
|
|
|
if (z.CurrentLevel != -1 && z.CurrentLevel > pkm.CurrentLevel)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
return false;
|
2017-09-21 04:28:29 +00:00
|
|
|
|
|
2018-01-13 20:10:17 +00:00
|
|
|
|
if (z.Form != pkm.AltForm && !IsFormChangeable(pkm, pkm.Species, z.Form))
|
2017-12-16 22:09:03 +00:00
|
|
|
|
return false;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
if (z.OTGender != -1 && z.OTGender != pkm.OT_Gender)
|
|
|
|
|
return false;
|
2018-01-02 20:00:41 +00:00
|
|
|
|
if (z.EggLocation != pkm.Egg_Location)
|
2017-09-21 04:28:29 +00:00
|
|
|
|
return false;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
// if (z.Ability == 4 ^ pkm.AbilityNumber == 4) // defer to Ability
|
|
|
|
|
// countinue;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MysteryGift
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<MysteryGift> GetValidGifts(PKM pkm)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
switch (pkm.GenNumber)
|
|
|
|
|
{
|
2017-05-29 07:48:25 +00:00
|
|
|
|
case 3:
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetMatchingWC3(pkm, MGDB_G3);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
case 4:
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetMatchingPCD(pkm, MGDB_G4);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
case 5:
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetMatchingPGF(pkm, MGDB_G5);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
case 6:
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetMatchingWC6(pkm, MGDB_G6);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
case 7:
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetMatchingWC7(pkm, MGDB_G7);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
default:
|
2017-10-23 22:44:01 +00:00
|
|
|
|
return Enumerable.Empty<MysteryGift>();
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<MysteryGift> GetMatchingWC3(PKM pkm, IEnumerable<MysteryGift> DB)
|
2017-05-29 07:48:25 +00:00
|
|
|
|
{
|
|
|
|
|
if (DB == null)
|
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
|
|
var validWC3 = new List<MysteryGift>();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var vs = GetValidPreEvolutions(pkm, MaxSpeciesID_3).ToArray();
|
2017-08-24 17:09:34 +00:00
|
|
|
|
var enumerable = DB.OfType<WC3>().Where(wc => vs.Any(dl => dl.Species == wc.Species));
|
|
|
|
|
foreach (WC3 wc in enumerable)
|
2017-05-29 07:48:25 +00:00
|
|
|
|
{
|
2017-08-24 17:09:34 +00:00
|
|
|
|
if (!GetIsMatchWC3(pkm, wc))
|
2017-05-29 07:48:25 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (wc.Species == pkm.Species) // best match
|
|
|
|
|
yield return wc;
|
|
|
|
|
else
|
|
|
|
|
validWC3.Add(wc);
|
|
|
|
|
}
|
|
|
|
|
foreach (var z in validWC3)
|
|
|
|
|
yield return z;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<MysteryGift> GetMatchingPCD(PKM pkm, IEnumerable<MysteryGift> DB)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-07-06 06:05:49 +00:00
|
|
|
|
if (DB == null || pkm.IsEgg && pkm.Format != 4) // transferred
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield break;
|
|
|
|
|
|
2017-07-05 19:31:41 +00:00
|
|
|
|
if (IsRangerManaphy(pkm))
|
2017-07-06 06:05:49 +00:00
|
|
|
|
{
|
2017-10-23 04:01:08 +00:00
|
|
|
|
if (pkm.Language != (int)LanguageID.Korean) // never korean
|
2017-08-31 04:30:07 +00:00
|
|
|
|
yield return new PGT { Data = { [0] = 7, [8] = 1 } };
|
2017-07-06 06:05:49 +00:00
|
|
|
|
yield break;
|
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2017-08-31 04:30:07 +00:00
|
|
|
|
var deferred = new List<MysteryGift>();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var vs = GetValidPreEvolutions(pkm).ToArray();
|
2017-08-24 17:09:34 +00:00
|
|
|
|
var enumerable = DB.OfType<PCD>().Where(wc => vs.Any(dl => dl.Species == wc.Species));
|
|
|
|
|
foreach (PCD mg in enumerable)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
var wc = mg.Gift.PK;
|
2017-08-24 17:09:34 +00:00
|
|
|
|
if (!GetIsMatchPCD(pkm, wc, vs))
|
|
|
|
|
continue;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2017-06-18 06:09:00 +00:00
|
|
|
|
bool receivable = mg.CanBeReceivedBy(pkm.Version);
|
|
|
|
|
if (wc.Species == pkm.Species && receivable) // best match
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield return mg;
|
|
|
|
|
else
|
2017-08-31 04:30:07 +00:00
|
|
|
|
deferred.Add(mg);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-08-31 04:30:07 +00:00
|
|
|
|
foreach (var z in deferred)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield return z;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<MysteryGift> GetMatchingPGF(PKM pkm, IEnumerable<MysteryGift> DB)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (DB == null)
|
|
|
|
|
yield break;
|
|
|
|
|
|
2017-08-31 04:30:07 +00:00
|
|
|
|
var deferred = new List<MysteryGift>();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var vs = GetValidPreEvolutions(pkm).ToArray();
|
2017-08-24 17:09:34 +00:00
|
|
|
|
var enumerable = DB.OfType<PGF>().Where(wc => vs.Any(dl => dl.Species == wc.Species));
|
|
|
|
|
foreach (PGF wc in enumerable)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-08-24 17:09:34 +00:00
|
|
|
|
if (!GetIsMatchPGF(pkm, wc, vs))
|
|
|
|
|
continue;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
|
|
|
|
if (wc.Species == pkm.Species) // best match
|
|
|
|
|
yield return wc;
|
|
|
|
|
else
|
2017-08-31 04:30:07 +00:00
|
|
|
|
deferred.Add(wc);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-08-31 04:30:07 +00:00
|
|
|
|
foreach (var z in deferred)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield return z;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<MysteryGift> GetMatchingWC6(PKM pkm, IEnumerable<MysteryGift> DB)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (DB == null)
|
|
|
|
|
yield break;
|
2017-08-31 04:30:07 +00:00
|
|
|
|
var deferred = new List<MysteryGift>();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var vs = GetValidPreEvolutions(pkm).ToArray();
|
2017-08-24 17:09:34 +00:00
|
|
|
|
var enumerable = DB.OfType<WC6>().Where(wc => vs.Any(dl => dl.Species == wc.Species));
|
|
|
|
|
foreach (WC6 wc in enumerable)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-08-24 17:09:34 +00:00
|
|
|
|
if (!GetIsMatchWC6(pkm, wc, vs))
|
|
|
|
|
continue;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2017-10-19 01:28:17 +00:00
|
|
|
|
switch (wc.CardID)
|
|
|
|
|
{
|
|
|
|
|
case 0525 when wc.IV_HP == 0xFE: // Diancie was distributed with no IV enforcement & 3IVs
|
|
|
|
|
case 0504 when wc.RibbonClassic != ((IRibbonSetEvent4)pkm).RibbonClassic: // magmar with/without classic
|
|
|
|
|
deferred.Add(wc);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (wc.Species == pkm.Species) // best match
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield return wc;
|
|
|
|
|
else
|
2017-08-31 04:30:07 +00:00
|
|
|
|
deferred.Add(wc);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-08-31 04:30:07 +00:00
|
|
|
|
foreach (var z in deferred)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield return z;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<MysteryGift> GetMatchingWC7(PKM pkm, IEnumerable<MysteryGift> DB)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (DB == null)
|
|
|
|
|
yield break;
|
2017-08-31 04:30:07 +00:00
|
|
|
|
var deferred = new List<MysteryGift>();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var vs = GetValidPreEvolutions(pkm).ToArray();
|
2017-08-24 17:09:34 +00:00
|
|
|
|
var enumerable = DB.OfType<WC7>().Where(wc => vs.Any(dl => dl.Species == wc.Species));
|
|
|
|
|
foreach (WC7 wc in enumerable)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-08-24 17:09:34 +00:00
|
|
|
|
if (!GetIsMatchWC7(pkm, wc, vs))
|
|
|
|
|
continue;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
|
|
|
|
if ((pkm.SID << 16 | pkm.TID) == 0x79F57B49) // Greninja WC has variant PID and can arrive @ 36 or 37
|
|
|
|
|
{
|
|
|
|
|
if (!pkm.IsShiny)
|
2017-08-31 04:30:07 +00:00
|
|
|
|
deferred.Add(wc);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-08-31 04:30:07 +00:00
|
|
|
|
if (wc.PIDType == 0 && pkm.PID != wc.PID)
|
|
|
|
|
continue;
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
|
|
|
|
if (wc.Species == pkm.Species) // best match
|
|
|
|
|
yield return wc;
|
|
|
|
|
else
|
2017-08-31 04:30:07 +00:00
|
|
|
|
deferred.Add(wc);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-08-31 04:30:07 +00:00
|
|
|
|
foreach (var z in deferred)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
yield return z;
|
|
|
|
|
}
|
2017-08-24 17:09:34 +00:00
|
|
|
|
private static bool GetIsMatchWC3(PKM pkm, WC3 wc)
|
|
|
|
|
{
|
|
|
|
|
// Gen3 Version MUST match.
|
|
|
|
|
if (wc.Version != 0 && !((GameVersion)wc.Version).Contains((GameVersion)pkm.Version))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool hatchedEgg = wc.IsEgg && !pkm.IsEgg;
|
|
|
|
|
if (!hatchedEgg)
|
|
|
|
|
{
|
|
|
|
|
if (wc.SID != -1 && wc.SID != pkm.SID) return false;
|
|
|
|
|
if (wc.TID != -1 && wc.TID != pkm.TID) return false;
|
|
|
|
|
if (wc.OT_Name != null && wc.OT_Name != pkm.OT_Name) return false;
|
|
|
|
|
if (wc.OT_Gender < 3 && wc.OT_Gender != pkm.OT_Gender) return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (wc.Language != -1 && wc.Language != pkm.Language) return false;
|
|
|
|
|
if (wc.Ball != pkm.Ball) return false;
|
|
|
|
|
if (wc.Fateful != pkm.FatefulEncounter)
|
|
|
|
|
{
|
|
|
|
|
// XD Gifts only at level 20 get flagged after transfer
|
|
|
|
|
bool valid = wc.Level == 20 && pkm is XK3;
|
|
|
|
|
if (!valid)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pkm.IsNative)
|
|
|
|
|
{
|
|
|
|
|
if (wc.Met_Level != pkm.Met_Level)
|
|
|
|
|
return false;
|
2018-01-02 20:00:41 +00:00
|
|
|
|
if (wc.Location != pkm.Met_Location && (!wc.IsEgg || pkm.IsEgg))
|
2017-08-24 17:09:34 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (pkm.IsEgg)
|
|
|
|
|
return false;
|
|
|
|
|
if (wc.Level > pkm.Met_Level)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
private static bool GetIsMatchPCD(PKM pkm, PKM wc, IEnumerable<DexLevel> vs)
|
|
|
|
|
{
|
|
|
|
|
if (!wc.IsEgg)
|
|
|
|
|
{
|
|
|
|
|
if (wc.TID != pkm.TID) return false;
|
|
|
|
|
if (wc.SID != pkm.SID) return false;
|
|
|
|
|
if (wc.OT_Name != pkm.OT_Name) return false;
|
|
|
|
|
if (wc.OT_Gender != pkm.OT_Gender) return false;
|
|
|
|
|
if (wc.Language != 0 && wc.Language != pkm.Language) return false;
|
|
|
|
|
|
|
|
|
|
if (pkm.Format != 4) // transferred
|
|
|
|
|
{
|
|
|
|
|
// met location: deferred to general transfer check
|
|
|
|
|
if (wc.CurrentLevel > pkm.Met_Level) return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (wc.Egg_Location + 3000 != pkm.Met_Location) return false;
|
|
|
|
|
if (wc.CurrentLevel != pkm.Met_Level) return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // Egg
|
|
|
|
|
{
|
|
|
|
|
if (wc.Egg_Location + 3000 != pkm.Egg_Location && pkm.Egg_Location != 2002) // traded
|
|
|
|
|
return false;
|
|
|
|
|
if (wc.CurrentLevel != pkm.Met_Level)
|
|
|
|
|
return false;
|
|
|
|
|
if (pkm.IsEgg && !pkm.IsNative)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-13 20:10:17 +00:00
|
|
|
|
if (wc.AltForm != pkm.AltForm && vs.All(dl => !IsFormChangeable(pkm, dl.Species, wc.AltForm)))
|
2017-08-24 17:09:34 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (wc.Ball != pkm.Ball) return false;
|
|
|
|
|
if (wc.OT_Gender < 3 && wc.OT_Gender != pkm.OT_Gender) return false;
|
|
|
|
|
if (wc.PID == 1 && pkm.IsShiny) return false;
|
|
|
|
|
if (wc.Gender != 3 && wc.Gender != pkm.Gender) return false;
|
|
|
|
|
|
|
|
|
|
if (wc.CNT_Cool > pkm.CNT_Cool) return false;
|
|
|
|
|
if (wc.CNT_Beauty > pkm.CNT_Beauty) return false;
|
|
|
|
|
if (wc.CNT_Cute > pkm.CNT_Cute) return false;
|
|
|
|
|
if (wc.CNT_Smart > pkm.CNT_Smart) return false;
|
|
|
|
|
if (wc.CNT_Tough > pkm.CNT_Tough) return false;
|
|
|
|
|
if (wc.CNT_Sheen > pkm.CNT_Sheen) return false;
|
|
|
|
|
|
2017-08-26 00:29:14 +00:00
|
|
|
|
return true;
|
2017-08-24 17:09:34 +00:00
|
|
|
|
}
|
|
|
|
|
private static bool GetIsMatchPGF(PKM pkm, PGF wc, IEnumerable<DexLevel> vs)
|
|
|
|
|
{
|
|
|
|
|
if (!wc.IsEgg)
|
|
|
|
|
{
|
|
|
|
|
if (wc.SID != pkm.SID) return false;
|
|
|
|
|
if (wc.TID != pkm.TID) return false;
|
2017-11-18 19:34:23 +00:00
|
|
|
|
if (wc.OT_Name != pkm.OT_Name) return false;
|
2017-08-24 17:09:34 +00:00
|
|
|
|
if (wc.OTGender < 3 && wc.OTGender != pkm.OT_Gender) return false;
|
|
|
|
|
if (wc.PID != 0 && pkm.PID != wc.PID) return false;
|
|
|
|
|
if (wc.PIDType == 0 && pkm.IsShiny) return false;
|
|
|
|
|
if (wc.PIDType == 2 && !pkm.IsShiny) return false;
|
|
|
|
|
if (wc.OriginGame != 0 && wc.OriginGame != pkm.Version) return false;
|
|
|
|
|
if (wc.Language != 0 && wc.Language != pkm.Language) return false;
|
|
|
|
|
|
|
|
|
|
if (wc.EggLocation != pkm.Egg_Location) return false;
|
|
|
|
|
if (wc.MetLocation != pkm.Met_Location) return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (wc.EggLocation != pkm.Egg_Location && pkm.Egg_Location != 30003) // traded
|
|
|
|
|
return false;
|
|
|
|
|
if (pkm.IsEgg && !pkm.IsNative)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-13 20:10:17 +00:00
|
|
|
|
if (wc.Form != pkm.AltForm && vs.All(dl => !IsFormChangeable(pkm, dl.Species, wc.Form))) return false;
|
2017-08-24 17:09:34 +00:00
|
|
|
|
|
|
|
|
|
if (wc.Level != pkm.Met_Level) return false;
|
|
|
|
|
if (wc.Ball != pkm.Ball) return false;
|
|
|
|
|
if (wc.Nature != 0xFF && wc.Nature != pkm.Nature) return false;
|
|
|
|
|
if (wc.Gender != 2 && wc.Gender != pkm.Gender) return false;
|
|
|
|
|
|
|
|
|
|
if (wc.CNT_Cool > pkm.CNT_Cool) return false;
|
|
|
|
|
if (wc.CNT_Beauty > pkm.CNT_Beauty) return false;
|
|
|
|
|
if (wc.CNT_Cute > pkm.CNT_Cute) return false;
|
|
|
|
|
if (wc.CNT_Smart > pkm.CNT_Smart) return false;
|
|
|
|
|
if (wc.CNT_Tough > pkm.CNT_Tough) return false;
|
|
|
|
|
if (wc.CNT_Sheen > pkm.CNT_Sheen) return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
private static bool GetIsMatchWC6(PKM pkm, WC6 wc, IEnumerable<DexLevel> vs)
|
|
|
|
|
{
|
|
|
|
|
if (pkm.Egg_Location == 0) // Not Egg
|
|
|
|
|
{
|
|
|
|
|
if (wc.CardID != pkm.SID) return false;
|
|
|
|
|
if (wc.TID != pkm.TID) return false;
|
2017-11-18 19:34:23 +00:00
|
|
|
|
if (wc.OT_Name != pkm.OT_Name) return false;
|
2017-08-24 17:09:34 +00:00
|
|
|
|
if (wc.OTGender != pkm.OT_Gender) return false;
|
|
|
|
|
if (wc.PIDType == 0 && pkm.PID != wc.PID) return false;
|
|
|
|
|
if (wc.PIDType == 2 && !pkm.IsShiny) return false;
|
|
|
|
|
if (wc.PIDType == 3 && pkm.IsShiny) return false;
|
|
|
|
|
if (wc.OriginGame != 0 && wc.OriginGame != pkm.Version) return false;
|
|
|
|
|
if (wc.EncryptionConstant != 0 && wc.EncryptionConstant != pkm.EncryptionConstant) return false;
|
|
|
|
|
if (wc.Language != 0 && wc.Language != pkm.Language) return false;
|
|
|
|
|
}
|
2018-01-13 20:10:17 +00:00
|
|
|
|
if (wc.Form != pkm.AltForm && vs.All(dl => !IsFormChangeable(pkm, dl.Species, wc.Form))) return false;
|
2017-08-24 17:09:34 +00:00
|
|
|
|
|
|
|
|
|
if (wc.IsEgg)
|
|
|
|
|
{
|
|
|
|
|
if (wc.EggLocation != pkm.Egg_Location && pkm.Egg_Location != 30002) // traded
|
|
|
|
|
return false;
|
|
|
|
|
if (pkm.IsEgg && !pkm.IsNative)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (wc.EggLocation != pkm.Egg_Location) return false;
|
|
|
|
|
if (wc.MetLocation != pkm.Met_Location) return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (wc.Level != pkm.Met_Level) return false;
|
|
|
|
|
if (wc.Ball != pkm.Ball) return false;
|
|
|
|
|
if (wc.OTGender < 3 && wc.OTGender != pkm.OT_Gender) return false;
|
|
|
|
|
if (wc.Nature != 0xFF && wc.Nature != pkm.Nature) return false;
|
|
|
|
|
if (wc.Gender != 3 && wc.Gender != pkm.Gender) return false;
|
|
|
|
|
|
|
|
|
|
if (wc.CNT_Cool > pkm.CNT_Cool) return false;
|
|
|
|
|
if (wc.CNT_Beauty > pkm.CNT_Beauty) return false;
|
|
|
|
|
if (wc.CNT_Cute > pkm.CNT_Cute) return false;
|
|
|
|
|
if (wc.CNT_Smart > pkm.CNT_Smart) return false;
|
|
|
|
|
if (wc.CNT_Tough > pkm.CNT_Tough) return false;
|
|
|
|
|
if (wc.CNT_Sheen > pkm.CNT_Sheen) return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
private static bool GetIsMatchWC7(PKM pkm, WC7 wc, IEnumerable<DexLevel> vs)
|
|
|
|
|
{
|
|
|
|
|
if (pkm.Egg_Location == 0) // Not Egg
|
|
|
|
|
{
|
|
|
|
|
if (wc.OTGender != 3)
|
|
|
|
|
{
|
|
|
|
|
if (wc.SID != pkm.SID) return false;
|
|
|
|
|
if (wc.TID != pkm.TID) return false;
|
|
|
|
|
if (wc.OTGender != pkm.OT_Gender) return false;
|
|
|
|
|
}
|
2017-11-18 19:34:23 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(wc.OT_Name) && wc.OT_Name != pkm.OT_Name) return false;
|
2017-08-24 17:09:34 +00:00
|
|
|
|
if (wc.OriginGame != 0 && wc.OriginGame != pkm.Version) return false;
|
|
|
|
|
if (wc.EncryptionConstant != 0 && wc.EncryptionConstant != pkm.EncryptionConstant) return false;
|
|
|
|
|
if (wc.Language != 0 && wc.Language != pkm.Language) return false;
|
|
|
|
|
}
|
2018-01-13 20:10:17 +00:00
|
|
|
|
if (wc.Form != pkm.AltForm && vs.All(dl => !IsFormChangeable(pkm, dl.Species, wc.Form)))
|
2017-11-17 04:59:16 +00:00
|
|
|
|
{
|
|
|
|
|
if (wc.Species == 744 && wc.Form == 1 && pkm.Species == 745 && pkm.AltForm == 2)
|
|
|
|
|
{
|
|
|
|
|
// Rockruff gift edge case; has altform 1 then evolves to altform 2
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-08-24 17:09:34 +00:00
|
|
|
|
|
|
|
|
|
if (wc.IsEgg)
|
|
|
|
|
{
|
|
|
|
|
if (wc.EggLocation != pkm.Egg_Location && pkm.Egg_Location != 30002) // traded
|
|
|
|
|
return false;
|
|
|
|
|
if (pkm.IsEgg && !pkm.IsNative)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (wc.EggLocation != pkm.Egg_Location) return false;
|
|
|
|
|
if (wc.MetLocation != pkm.Met_Location) return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (wc.MetLevel != pkm.Met_Level) return false;
|
|
|
|
|
if (wc.Ball != pkm.Ball) return false;
|
|
|
|
|
if (wc.OTGender < 3 && wc.OTGender != pkm.OT_Gender) return false;
|
|
|
|
|
if (wc.Nature != 0xFF && wc.Nature != pkm.Nature) return false;
|
|
|
|
|
if (wc.Gender != 3 && wc.Gender != pkm.Gender) return false;
|
|
|
|
|
|
|
|
|
|
if (wc.CNT_Cool > pkm.CNT_Cool) return false;
|
|
|
|
|
if (wc.CNT_Beauty > pkm.CNT_Beauty) return false;
|
|
|
|
|
if (wc.CNT_Cute > pkm.CNT_Cute) return false;
|
|
|
|
|
if (wc.CNT_Smart > pkm.CNT_Smart) return false;
|
|
|
|
|
if (wc.CNT_Tough > pkm.CNT_Tough) return false;
|
|
|
|
|
if (wc.CNT_Sheen > pkm.CNT_Sheen) return false;
|
|
|
|
|
|
|
|
|
|
if (wc.PIDType == 2 && !pkm.IsShiny) return false;
|
|
|
|
|
if (wc.PIDType == 3 && pkm.IsShiny) return false;
|
2017-08-26 00:29:14 +00:00
|
|
|
|
|
2017-11-22 16:24:54 +00:00
|
|
|
|
switch (wc.CardID)
|
2017-11-19 04:08:11 +00:00
|
|
|
|
{
|
2017-11-22 16:24:54 +00:00
|
|
|
|
case 1624: // Rockruff
|
|
|
|
|
if (pkm.Species == 745 && pkm.AltForm != 2)
|
|
|
|
|
return false;
|
|
|
|
|
if (pkm.Version == (int)GameVersion.US)
|
|
|
|
|
return wc.Move3 == 424; // Fire Fang
|
|
|
|
|
if (pkm.Version == (int)GameVersion.UM)
|
|
|
|
|
return wc.Move3 == 422; // Thunder Fang
|
2017-11-19 04:08:11 +00:00
|
|
|
|
return false;
|
2017-11-22 16:24:54 +00:00
|
|
|
|
case 2046: // Ash Greninja
|
|
|
|
|
return pkm.SM; // not USUM
|
2017-11-19 04:08:11 +00:00
|
|
|
|
}
|
2017-08-24 17:09:34 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-28 04:17:53 +00:00
|
|
|
|
// EncounterEgg
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<EncounterEgg> GenerateEggs(PKM pkm)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (NoHatchFromEgg.Contains(pkm.Species))
|
|
|
|
|
yield break;
|
2017-11-14 16:43:04 +00:00
|
|
|
|
if (FormConverter.IsTotemForm(pkm.Species, pkm.AltForm, pkm.GenNumber))
|
|
|
|
|
yield break; // no totem eggs
|
2017-09-29 00:11:30 +00:00
|
|
|
|
|
|
|
|
|
int gen = pkm.GenNumber;
|
|
|
|
|
// version is a true indicator for all generation 3-5 origins
|
|
|
|
|
var ver = (GameVersion) pkm.Version;
|
|
|
|
|
int max = GetMaxSpeciesOrigin(gen);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
|
2017-06-30 03:12:40 +00:00
|
|
|
|
var baseSpecies = GetBaseSpecies(pkm, 0);
|
2017-09-29 00:11:30 +00:00
|
|
|
|
int lvl = gen < 4 ? 5 : 1;
|
2017-06-30 03:12:40 +00:00
|
|
|
|
if (baseSpecies <= max)
|
2017-09-29 00:11:30 +00:00
|
|
|
|
{
|
2017-06-30 03:12:40 +00:00
|
|
|
|
yield return new EncounterEgg { Game = ver, Level = lvl, Species = baseSpecies };
|
2017-09-29 00:11:30 +00:00
|
|
|
|
if (gen > 5 && pkm.WasTradedEgg)
|
|
|
|
|
yield return new EncounterEgg { Game = tradePair(), Level = lvl, Species = baseSpecies };
|
|
|
|
|
}
|
2017-06-30 03:12:40 +00:00
|
|
|
|
|
2017-08-24 17:09:34 +00:00
|
|
|
|
if (!GetSplitBreedGeneration(pkm).Contains(pkm.Species))
|
2017-08-31 04:30:07 +00:00
|
|
|
|
yield break; // no other possible species
|
2017-08-24 17:09:34 +00:00
|
|
|
|
|
|
|
|
|
baseSpecies = GetBaseSpecies(pkm, 1);
|
|
|
|
|
if (baseSpecies <= max)
|
2017-09-29 00:11:30 +00:00
|
|
|
|
{
|
2017-06-30 03:12:40 +00:00
|
|
|
|
yield return new EncounterEgg { Game = ver, Level = lvl, Species = baseSpecies, SplitBreed = true };
|
2017-09-29 00:11:30 +00:00
|
|
|
|
if (gen > 5 && pkm.WasTradedEgg)
|
|
|
|
|
yield return new EncounterEgg { Game = tradePair(), Level = lvl, Species = baseSpecies, SplitBreed = true };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gen6+ update the origin game when hatched. Quick manip for X.Y<->A.O | S.M<->US.UM, ie X->A
|
2017-11-29 17:21:17 +00:00
|
|
|
|
GameVersion tradePair()
|
|
|
|
|
{
|
|
|
|
|
if (ver <= GameVersion.OR) // gen6
|
|
|
|
|
return (GameVersion)((int)ver ^ 2);
|
|
|
|
|
if (ver <= GameVersion.MN) // gen7
|
|
|
|
|
return ver + 2;
|
|
|
|
|
return ver - 2;
|
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Utility
|
2017-07-06 00:47:48 +00:00
|
|
|
|
private static bool IsRangerManaphy(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
var egg = pkm.Egg_Location;
|
|
|
|
|
const int ranger = 3001;
|
|
|
|
|
const int linkegg = 2002;
|
|
|
|
|
if (!pkm.IsEgg) // Link Trade Egg or Ranger
|
|
|
|
|
return egg == linkegg || egg == ranger;
|
|
|
|
|
if (egg != ranger)
|
|
|
|
|
return false;
|
|
|
|
|
var met = pkm.Met_Location;
|
|
|
|
|
return met == linkegg || met == 0;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool IsHiddenAbilitySlot(EncounterSlot slot)
|
2017-05-28 18:10:01 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return slot.Permissions.DexNav || slot.Type == SlotType.FriendSafari || slot.Type == SlotType.Horde || slot.Type == SlotType.SOS;
|
2017-05-28 18:10:01 +00:00
|
|
|
|
}
|
2017-05-28 04:17:53 +00:00
|
|
|
|
internal static bool IsSafariSlot(SlotType t)
|
|
|
|
|
{
|
2017-11-04 00:14:18 +00:00
|
|
|
|
return t.HasFlag(SlotType.Safari);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
internal static bool IsDexNavValid(PKM pkm)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (!pkm.AO || !pkm.InhabitedGeneration(6))
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-11-19 23:26:41 +00:00
|
|
|
|
var vs = GetValidPreEvolutions(pkm);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
IEnumerable<EncounterArea> locs = GetDexNavAreas(pkm);
|
2017-11-19 23:26:41 +00:00
|
|
|
|
var d_areas = locs.Select(loc => GetValidEncounterSlots(pkm, loc, vs, DexNav: true));
|
2017-08-24 17:09:34 +00:00
|
|
|
|
return d_areas.Any(slots => slots.Any(slot => slot.Permissions.AllowDexNav && slot.Permissions.DexNav));
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
2017-10-22 16:42:15 +00:00
|
|
|
|
private static bool IsEncounterTypeMatch(IEncounterable e, int type)
|
|
|
|
|
{
|
|
|
|
|
switch (e)
|
|
|
|
|
{
|
|
|
|
|
case EncounterStaticTyped t:
|
|
|
|
|
return t.TypeEncounter.Contains(type);
|
|
|
|
|
case EncounterSlot w:
|
|
|
|
|
return w.TypeEncounter.Contains(type);
|
|
|
|
|
default:
|
|
|
|
|
return type == 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
internal static EncounterArea GetCaptureLocation(PKM pkm)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-11-19 23:26:41 +00:00
|
|
|
|
var vs = GetValidPreEvolutions(pkm);
|
2017-11-19 20:41:23 +00:00
|
|
|
|
return (from area in GetEncounterSlots(pkm)
|
2017-11-19 23:26:41 +00:00
|
|
|
|
let slots = GetValidEncounterSlots(pkm, area, vs, DexNav: pkm.AO, ignoreLevel: true).ToArray()
|
2017-12-05 04:16:54 +00:00
|
|
|
|
where slots.Length != 0
|
2017-05-28 04:17:53 +00:00
|
|
|
|
select new EncounterArea
|
|
|
|
|
{
|
|
|
|
|
Location = area.Location,
|
|
|
|
|
Slots = slots,
|
|
|
|
|
}).OrderBy(area => area.Slots.Min(x => x.LevelMin)).FirstOrDefault();
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
internal static EncounterStatic GetStaticLocation(PKM pkm, int species = -1)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
switch (pkm.GenNumber)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
2017-07-09 15:47:17 +00:00
|
|
|
|
return GetRBYStaticTransfer(species, pkm.Met_Level);
|
|
|
|
|
case 2:
|
|
|
|
|
return GetGSStaticTransfer(species, pkm.Met_Level);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
default:
|
2017-08-29 01:12:57 +00:00
|
|
|
|
var table = GetEncounterStaticTable(pkm, (GameVersion)pkm.Version);
|
|
|
|
|
return GetStatic(pkm, table, lvl: 100, skip: true).FirstOrDefault();
|
2017-05-28 04:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-21 04:07:15 +00:00
|
|
|
|
internal static bool IsVCStaticTransferEncounterValid(PKM pkm, EncounterStatic e)
|
|
|
|
|
{
|
|
|
|
|
return pkm.Met_Location == e.Location && pkm.Egg_Location == e.EggLocation;
|
|
|
|
|
}
|
|
|
|
|
internal static IEncounterable GetVCStaticTransferEncounter(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
if (pkm.VC1)
|
|
|
|
|
return GetRBYStaticTransfer(pkm.Species, pkm.Met_Level);
|
2017-11-25 02:19:16 +00:00
|
|
|
|
if (pkm.VC2 && (pkm.Version != (int)GameVersion.C || AllowGen2VCCrystal))
|
2017-10-21 04:07:15 +00:00
|
|
|
|
return GetGSStaticTransfer(pkm.Species, pkm.Met_Level);
|
|
|
|
|
return new EncounterInvalid(pkm);
|
|
|
|
|
}
|
|
|
|
|
private static EncounterStatic GetRBYStaticTransfer(int species, int pkmMetLevel)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
return new EncounterStatic
|
|
|
|
|
{
|
|
|
|
|
Species = species,
|
|
|
|
|
Gift = true, // Forces Poké Ball
|
|
|
|
|
Ability = TransferSpeciesDefaultAbility_1.Contains(species) ? 1 : 4, // Hidden by default, else first
|
|
|
|
|
Shiny = species == 151 ? (bool?)false : null,
|
|
|
|
|
Fateful = species == 151,
|
2017-11-23 05:45:30 +00:00
|
|
|
|
Location = Transfer1,
|
2017-05-28 04:17:53 +00:00
|
|
|
|
EggLocation = 0,
|
|
|
|
|
IV3 = true,
|
2017-07-09 15:47:17 +00:00
|
|
|
|
Level = pkmMetLevel,
|
2017-05-28 04:17:53 +00:00
|
|
|
|
Version = GameVersion.RBY
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-10-21 04:07:15 +00:00
|
|
|
|
private static EncounterStatic GetGSStaticTransfer(int species, int pkmMetLevel)
|
2017-06-10 22:48:12 +00:00
|
|
|
|
{
|
|
|
|
|
return new EncounterStatic
|
|
|
|
|
{
|
|
|
|
|
Species = species,
|
|
|
|
|
Gift = true, // Forces Poké Ball
|
|
|
|
|
Ability = TransferSpeciesDefaultAbility_2.Contains(species) ? 1 : 4, // Hidden by default, else first
|
|
|
|
|
Shiny = species == 151 || species == 251 ? (bool?)false : null,
|
|
|
|
|
Fateful = species == 151 || species == 251,
|
2017-11-23 05:45:30 +00:00
|
|
|
|
Location = Transfer2,
|
2017-06-10 22:48:12 +00:00
|
|
|
|
EggLocation = 0,
|
|
|
|
|
IV3 = true,
|
2017-07-09 15:47:17 +00:00
|
|
|
|
Level = pkmMetLevel,
|
2017-06-10 22:48:12 +00:00
|
|
|
|
Version = GameVersion.GS
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
internal static bool IsEncounterTrade1Valid(PKM pkm)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
|
|
|
|
string ot = pkm.OT_Name;
|
|
|
|
|
string tr = pkm.Format <= 2 ? "TRAINER" : "Trainer"; // decaps on transfer
|
|
|
|
|
return ot == "トレーナー" || ot == tr;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool IsWurmpleEvoValid(PKM pkm)
|
2017-05-28 04:17:53 +00:00
|
|
|
|
{
|
2017-07-17 22:58:09 +00:00
|
|
|
|
uint evoVal = PKX.GetWurmpleEvoVal(pkm.EncryptionConstant);
|
2017-05-28 04:17:53 +00:00
|
|
|
|
int wIndex = Array.IndexOf(WurmpleEvolutions, pkm.Species) / 2;
|
|
|
|
|
return evoVal == wIndex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|