Fix getBaseSpecies invalid chains

Closes #555
now correctly flags trade evolution chains
This commit is contained in:
Kurt 2016-12-02 20:26:35 -08:00
parent 00d0dac85e
commit e18a2cd774
4 changed files with 16 additions and 17 deletions

View File

@ -246,7 +246,7 @@ public EncounterStatic getSuggestedMetInfo()
if (pkm.WasEgg)
return new EncounterStatic
{
Species = Legal.getBaseSpecies(pkm, lvl:100),
Species = Legal.getBaseSpecies(pkm),
Location = getSuggestedEggMetLocation(pkm),
Level = 1,
};

View File

@ -1573,7 +1573,7 @@ private void verifyG7PreBank()
if (pkm.Moves.Any(move => Legal.Bank_Sketch7.Contains(move)))
AddLine(Severity.Invalid, "Sketched move not possible prior to Bank Release.", CheckIdentifier.Special);
int baseSpecies = Legal.getBaseSpecies(pkm, lvl: 100);
int baseSpecies = Legal.getBaseSpecies(pkm);
var info = Legal.Bank_Egg7.FirstOrDefault(entry => entry.Species == baseSpecies && (entry.Form == 0 || entry.Form == pkm.AltForm)); // Grimer form edge case
if (info != null)
{

View File

@ -506,7 +506,7 @@ internal static bool getHasEvolved(PKM pkm)
internal static bool getHasTradeEvolved(PKM pkm)
{
var table = getEvolutionTable(pkm);
var lineage = table.getValidPreEvolutions(pkm, pkm.CurrentLevel);
var lineage = table.getValidPreEvolutions(pkm, 100, skipChecks:true);
return lineage.Any(evolution => EvolutionMethod.TradeMethods.Any(method => method == evolution.Flag)); // Trade Evolutions
}
internal static bool getIsFossil(PKM pkm)
@ -558,11 +558,11 @@ internal static EncounterStatic getStaticLocation(PKM pkm)
internal static int getLowestLevel(PKM pkm, int refSpecies = -1)
{
if (refSpecies == -1)
refSpecies = getBaseSpecies(pkm, lvl: 100);
refSpecies = getBaseSpecies(pkm);
for (int i = 0; i < 100; i++)
{
var table = getEvolutionTable(pkm);
var evos = table.getValidPreEvolutions(pkm, i).ToArray();
var evos = table.getValidPreEvolutions(pkm, i, skipChecks:true).ToArray();
if (evos.Any(evo => evo.Species == refSpecies))
return evos.OrderByDescending(evo => evo.Level).First().Level;
}
@ -640,7 +640,7 @@ internal static bool getCanKnowMove(PKM pkm, int move, GameVersion version = Gam
return getValidMoves(pkm, Version: version, LVL: true, Relearn: true, Tutor: true, Machine: true).Contains(move);
}
internal static int getBaseSpecies(PKM pkm, int skipOption = 0, int lvl = -1)
internal static int getBaseSpecies(PKM pkm, int skipOption = 0)
{
if (pkm.Species == 292)
return 290;
@ -648,7 +648,7 @@ internal static int getBaseSpecies(PKM pkm, int skipOption = 0, int lvl = -1)
return 113;
var table = getEvolutionTable(pkm);
var evos = table.getValidPreEvolutions(pkm, lvl == -1 ? pkm.CurrentLevel : lvl).ToArray();
var evos = table.getValidPreEvolutions(pkm, 100, skipChecks:true).ToArray();
switch (skipOption)
{

View File

@ -142,10 +142,10 @@ private int getIndex(EvolutionMethod evo)
return Personal.getFormeIndex(evolvesToSpecies, evolvesToForm);
}
public IEnumerable<DexLevel> getValidPreEvolutions(PKM pkm, int lvl)
public IEnumerable<DexLevel> getValidPreEvolutions(PKM pkm, int lvl, bool skipChecks = false)
{
int index = getIndex(pkm);
return Lineage[index].getExplicitLineage(pkm, lvl, MaxSpecies);
return Lineage[index].getExplicitLineage(pkm, lvl, skipChecks, MaxSpecies);
}
}
@ -211,7 +211,7 @@ public class EvolutionMethod
public static readonly int[] TradeMethods = {5, 6, 7};
public GameVersion[] Banlist = new GameVersion[0];
public bool Valid(PKM pkm, int lvl)
public bool Valid(PKM pkm, int lvl, bool skipChecks)
{
RequiresLevelUp = false;
if (Form > -1)
@ -233,12 +233,12 @@ public bool Valid(PKM pkm, int lvl)
case 5: // Trade Evolution
case 6: // Trade while Holding
case 7: // Trade for Opposite Species
return !pkm.IsUntraded;
return !pkm.IsUntraded || skipChecks;
// Special Levelup Cases
case 16:
if (pkm.CNT_Beauty > Argument)
return false;
return skipChecks;
goto default;
case 23: // Gender = Male
if (pkm.Gender != 0)
@ -256,8 +256,8 @@ public bool Valid(PKM pkm, int lvl)
case 36: // Any Time on Version
case 37: // Daytime on Version
case 38: // Nighttime on Version
if (pkm.Version != Argument && pkm.IsUntraded)
return false;
if (pkm.Version != Argument && pkm.IsUntraded || skipChecks)
return skipChecks;
goto default;
default:
@ -284,7 +284,6 @@ public bool Valid(PKM pkm, int lvl)
case 6:
case 7:
return lvl >= Level && (!pkm.IsNative || pkm.Met_Level < lvl);
}
return false;
}
@ -347,7 +346,7 @@ public void Insert(EvolutionStage evo)
Chain.Insert(0, evo);
}
public IEnumerable<DexLevel> getExplicitLineage(PKM pkm, int lvl, int maxSpecies)
public IEnumerable<DexLevel> getExplicitLineage(PKM pkm, int lvl, bool skipChecks, int maxSpecies)
{
List<DexLevel> dl = new List<DexLevel> { new DexLevel { Species = pkm.Species, Level = lvl, Form = pkm.AltForm } };
for (int i = Chain.Count-1; i >= 0; i--) // reverse evolution!
@ -355,7 +354,7 @@ public IEnumerable<DexLevel> getExplicitLineage(PKM pkm, int lvl, int maxSpecies
bool oneValid = false;
foreach (var evo in Chain[i].StageEntryMethods)
{
if (!evo.Valid(pkm, lvl))
if (!evo.Valid(pkm, lvl, skipChecks))
continue;
oneValid = true;