Refactor, Check WC6 evos, Check WC6 egg

Moved the wc6 fetch logic, added event egg; added a little linq finesse
and things are clean!

Added features and cleaned with 0 net lines 👍
This commit is contained in:
Kaphotics 2016-03-04 20:43:00 -08:00
parent ea09161ffd
commit 464d686997
2 changed files with 22 additions and 22 deletions

View file

@ -1,4 +1,5 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
namespace PKHeX
{
@ -62,37 +63,23 @@ namespace PKHeX
}
public bool[] getRelearnValidity(int[] Moves)
{
if (Moves.Length != 4)
return new bool[4];
bool[] res = {true, true, true, true};
if (!pk6.Gen6)
goto noRelearn;
if (Moves.Length != 4)
return new bool[4];
bool egg = Legal.EggLocations.Contains(pk6.Egg_Location) && pk6.Met_Level == 1;
bool evnt = pk6.FatefulEncounter && pk6.Met_Location > 40000;
bool eventEgg = pk6.FatefulEncounter && (pk6.Egg_Location > 40000 || pk6.Egg_Location == 30002) && pk6.Met_Level == 1;
int[] relearnMoves = Legal.getValidRelearn(pk6, 0);
if (evnt || eventEgg)
{
if (evnt)
{
// Get WC6's that match
WC6[] vwc6 = Legal.WC6DB.Where(wc6 =>
wc6.CardID == pk6.SID &&
wc6.TID == pk6.TID &&
wc6.Species == pk6.Species &&
wc6.OT == pk6.OT_Name).ToArray();
// Iterate over all
foreach (WC6 wc6 in vwc6)
{
for (int i = 0; i < 4; i++)
res[i] = wc6.RelearnMoves[i] == Moves[i];
if (res.All(b=>b)) // At least one card matches the relearn moves.
return res;
}
}
// Get WC6's that match
IEnumerable<WC6> vwc6 = Legal.getValidWC6s(pk6);
if (vwc6.Any(wc6 => wc6.RelearnMoves.SequenceEqual(Moves)))
return res; // all true
}
else if (egg)
{

View file

@ -65,6 +65,19 @@ namespace PKHeX
r.AddRange(getLVLMoves(species, 100));
return r.Distinct().ToArray();
}
internal static IEnumerable<WC6> getValidWC6s(PK6 pk6)
{
IEnumerable<DexLevel> vs = getValidPreEvolutions(pk6);
if (pk6.Egg_Location > 0) // Was Egg, can't search TID/SID/OT
return WC6DB.Where(wc6 => vs.Any(dl => dl.Species == wc6.Species));
// Not Egg
return WC6DB.Where(wc6 =>
wc6.CardID == pk6.SID &&
wc6.TID == pk6.TID &&
vs.Any(dl => dl.Species == wc6.Species) &&
wc6.OT == pk6.OT_Name);
}
private static int getBaseSpecies(PK6 pk6, int skipOption)
{