Refactoring & finish eevee test case

generates a legal pk* for every possible encounter; there's likely other
scenarios and more roughness to smooth out, but seems legit for now
This commit is contained in:
Kurt 2018-03-31 20:37:36 -07:00
parent 32f9f806db
commit ba4c911566
8 changed files with 57 additions and 37 deletions

View file

@ -19,7 +19,7 @@ namespace PKHeX.Core
public PKM ConvertToPKM(ITrainerInfo SAV)
{
int gen = Version.GetGeneration();
int gen = Math.Max(2, Version.GetGeneration());
var pk = PKMConverter.GetBlank(gen);
SAV.ApplyToPKM(pk);
@ -28,9 +28,6 @@ namespace PKHeX.Core
pk.CurrentLevel = Level;
pk.Version = (int)Version;
int gender = Util.Rand.Next(2);
pk.Gender = pk.GetSaneGender(gender);
var moves = Legal.GetEggMoves(pk, Species, pk.AltForm, Version);
pk.Moves = moves;
pk.SetMaximumPPCurrent(moves);
@ -41,16 +38,32 @@ namespace PKHeX.Core
if (pk.Format <= 2 && Version != GameVersion.C)
return pk;
pk.PID = Util.Rand32();
pk.RefreshAbility(Util.Rand.Next(2));
pk.Ball = 4;
pk.Met_Level = EncounterSuggestion.GetSuggestedEncounterEggMetLevel(pk);
pk.Met_Location = Math.Max(0, EncounterSuggestion.GetSuggestedEggMetLocation(pk));
if (pk.Format < 4)
if (pk.Format < 3)
return pk;
pk.Ball = 4;
int gender = Util.Rand.Next(2);
int nature = Util.Rand.Next(25);
gender = pk.GetSaneGender(gender);
if (pk.Format <= 5)
{
pk.SetPIDGender(gender);
pk.SetPIDNature(nature);
pk.RefreshAbility(pk.PIDAbility);
}
else
{
pk.PID = Util.Rand32();
pk.Nature = nature;
pk.Gender = gender;
pk.RefreshAbility(Util.Rand.Next(2));
}
bool traded = (int)Version == SAV.Game;
var today = pk.MetDate = DateTime.Today;
if (pk.GenNumber >= 4)
@ -61,7 +74,6 @@ namespace PKHeX.Core
if (pk.Format < 6)
return pk;
SAV.ApplyHandlingTrainerInfo(pk);
if (pk.Gen6)
pk.SetHatchMemory6();

View file

@ -71,9 +71,9 @@ namespace PKHeX.Core
int level = LevelMin;
var pk = PKMConverter.GetBlank(Generation);
int gender = Util.Rand.Next(2);
pk.Gender = pk.GetSaneGender(gender);
int nature = Util.Rand.Next(25);
SAV.ApplyToPKM(pk);
pk.Nature = nature;
pk.EncryptionConstant = Util.Rand32();
pk.Species = Species;
@ -81,13 +81,12 @@ namespace PKHeX.Core
pk.CurrentLevel = level;
pk.Version = (int) version;
pk.PID = Util.Rand32();
pk.Gender = gender = pk.GetSaneGender(gender);
pk.Nickname = PKX.GetSpeciesNameGeneration(Species, lang, Generation);
pk.Ball = 4;
pk.Met_Level = level;
pk.Met_Location = Location;
pk.MetDate = DateTime.Today;
SAV.ApplyToPKM(pk);
pk.Language = lang;
pk.SetRandomIVs(flawless: 3);
@ -111,6 +110,11 @@ namespace PKHeX.Core
PIDGenerator.SetValuesFromSeed(pk, PIDType.Method_1, Util.Rand32());
if (pk.Format == 4)
pk.EncounterType = TypeEncounter.GetIndex();
pk.Gender = pk.GetSaneGender(gender);
break;
case 5:
if (Type == SlotType.HiddenGrotto)
pk.RefreshAbility(2);
break;
case 6:
pk.SetRandomMemory6();

View file

@ -72,6 +72,10 @@ namespace PKHeX.Core
int lang = (int)Legal.GetSafeLanguage(Generation, (LanguageID)SAV.Language);
int level = LevelMin;
var pk = PKMConverter.GetBlank(Generation);
int gender = Gender < 0 ? Util.Rand.Next(2) : Gender;
int nature = Nature == Nature.Random ? Util.Rand.Next(25) : (int)Nature;
var today = DateTime.Today;
SAV.ApplyToPKM(pk);
pk.EncryptionConstant = Util.Rand32();
pk.Species = Species;
@ -79,11 +83,11 @@ namespace PKHeX.Core
pk.CurrentLevel = level;
pk.Version = (int)version;
pk.PID = Util.Rand32();
pk.Gender = gender = pk.GetSaneGender(gender);
pk.Nickname = PKX.GetSpeciesNameGeneration(Species, lang, Generation);
pk.Ball = Ball;
pk.Met_Level = level;
pk.Met_Location = Location;
var today = DateTime.Today;
pk.MetDate = today;
if (EggEncounter)
{
@ -91,13 +95,9 @@ namespace PKHeX.Core
pk.EggMetDate = today;
}
int nature = Nature == Nature.Random ? Util.Rand.Next(25) : (int)Nature;
pk.Nature = nature;
int gender = Gender < 0 ? Util.Rand.Next(2) : Gender;
pk.Gender = pk.GetSaneGender(gender);
pk.AltForm = Form;
SAV.ApplyToPKM(pk);
pk.Language = lang;
pk.RefreshAbility(Ability >> 1);
@ -114,6 +114,7 @@ namespace PKHeX.Core
PIDGenerator.SetValuesFromSeed(pk, Roaming ? PIDType.Method_1_Roamer : PIDType.Method_1, Util.Rand32());
if (this is EncounterStaticTyped t)
pk.EncounterType = t.TypeEncounter.GetIndex();
pk.Gender = pk.GetSaneGender(gender);
break;
case 6:
pk.SetRandomMemory6();

View file

@ -32,9 +32,11 @@ namespace PKHeX.Core
foreach (var enc in encs)
{
var result = enc.ConvertToPKM(info);
result.Version = (int)ver; // some encounters don't have explicit versions defined, provide one
if (result.GenNumber <= 2)
result.SID = 0;
#if DEBUG
var la = new LegalityAnalysis(result);
if (!la.Valid)
throw new Exception();
#endif
yield return result;
}
}
@ -98,6 +100,7 @@ namespace PKHeX.Core
{
// generate possible eggs
var eggs = GetEggs(pk, needs, version);
if (!GameVersion.CXD.Contains(version))
foreach (var egg in eggs)
yield return egg;

View file

@ -36,16 +36,11 @@ namespace PKHeX.Core
}
private static IEnumerable<EncounterTrade> GetEncounterTradeTableVC(GameVersion gameSource)
{
switch (gameSource)
{
case GameVersion.RBY:
return !AllowGen1Tradeback ? Encounters1.TradeGift_RBY_NoTradeback : Encounters1.TradeGift_RBY_Tradeback;
case GameVersion.GSC:
case GameVersion.C:
return Encounters2.TradeGift_GSC;
default:
return null;
}
if (GameVersion.RBY.Contains(gameSource))
return !AllowGen1Tradeback ? Encounters1.TradeGift_RBY_NoTradeback : Encounters1.TradeGift_RBY_Tradeback;
if (GameVersion.GSC.Contains(gameSource))
return Encounters2.TradeGift_GSC;
return null;
}
private static IEnumerable<EncounterTrade> GetEncounterTradeTable(PKM pkm)
{

View file

@ -25,7 +25,7 @@ namespace PKHeX.Core
{
pk.OT_Name = info.OT;
pk.TID = info.TID;
pk.SID = info.SID;
pk.SID = pk.Format < 3 || pk.VC ? 0 : info.SID;
pk.OT_Gender = info.Gender;
pk.Language = info.Language;
pk.Version = info.Game;
@ -45,7 +45,7 @@ namespace PKHeX.Core
pk.HT_Friendship = pk.OT_Friendship;
pk.CurrentHandler = 1;
if (SAV.Generation == 6)
if (pk.Format == 6)
{
pk.Geo1_Country = SAV.Country;
pk.Geo1_Region = SAV.SubRegion;

View file

@ -700,6 +700,8 @@ namespace PKHeX.Core
int[] abilities = PersonalInfo.Abilities;
if (n < abilities.Length)
Ability = abilities[n];
if (this is PK5 pk5)
pk5.HiddenAbility = n == 2;
}
/// <summary>

View file

@ -38,9 +38,12 @@ namespace PKHeX.Tests.Simulator
var la = new LegalityAnalysis(pk);
Assert.IsTrue(la.Valid);
var test = EncounterMovesetGenerator.GeneratePKMs(pk7, info);
var la2 = new LegalityAnalysis(test.First());
Assert.IsTrue(la2.Valid);
var test = EncounterMovesetGenerator.GeneratePKMs(pk7, info).ToList();
foreach (var t in test)
{
var la2 = new LegalityAnalysis(t);
Assert.IsTrue(la2.Valid);
}
}
private const string SetGlaceonUSUMTutor =