Remove WasEgg setter

WasEgg (aka WasDefinitelyAnEgg) from stored properties is one thing,
WasEgg from encounter info is another; don't mix
This commit is contained in:
Kurt 2019-07-25 17:42:15 -07:00
parent 8ffcdc9570
commit db632905fd
6 changed files with 22 additions and 31 deletions

View file

@ -303,14 +303,12 @@ namespace PKHeX.Core
return preevomoves.Except(evomoves).Distinct();
}
internal static bool GetWasEgg23(PKM pkm)
internal static bool GetCanBeEgg23(PKM pkm)
{
if (pkm.IsEgg)
return true;
if (pkm.Format > 2 && pkm.Ball != 4)
return false;
if (pkm.Format == 3)
return pkm.WasEgg;
int lvl = pkm.CurrentLevel;
if (lvl < 5)

View file

@ -245,7 +245,7 @@ namespace PKHeX.Core
if (Nature != Nature.Random && pkm.Nature != (int)Nature)
return false;
if (pkm.WasEgg != EggEncounter && pkm.Egg_Location == 0 && pkm.Format > 3 && Generation > 3 && !pkm.IsEgg)
if (Generation > 3 && pkm.Format > 3 && pkm.WasEgg != EggEncounter && pkm.Egg_Location == 0 && !pkm.IsEgg)
return false;
if (this is EncounterStaticPID p && p.PID != pkm.PID)
return false;

View file

@ -47,7 +47,6 @@ namespace PKHeX.Core
foreach (var z in GenerateFilteredEncounters12(pkm))
{
pkm.WasEgg = z.EggEncounter;
info.Generation = z is IGeneration g ? g.Generation : 2;
info.Game = ((IVersion)z).Version;
yield return z;
@ -179,10 +178,6 @@ namespace PKHeX.Core
}
yield return s;
}
// clear egg flag
// necessary for static egg gifts which appear in wild, level 8 GS clefairy
// GetValidWildEncounters immediately returns empty otherwise
pkm.WasEgg = false;
foreach (var e in GetValidWildEncounters12(pkm, vs, game))
{
yield return e;
@ -190,17 +185,8 @@ namespace PKHeX.Core
if (gsc)
{
bool WasEgg = !pkm.Gen1_NotTradeback && GetWasEgg23(pkm) && !NoHatchFromEgg.Contains(pkm.Species);
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)
var canBeEgg = GetCanBeEgg(pkm);
if (canBeEgg)
{
int eggspec = GetBaseEggSpecies(pkm);
if (ParseSettings.AllowGen2Crystal(pkm))
@ -213,6 +199,22 @@ namespace PKHeX.Core
yield return d;
}
private static bool GetCanBeEgg(PKM pkm)
{
bool canBeEgg = !pkm.Gen1_NotTradeback && GetCanBeEgg23(pkm) && !NoHatchFromEgg.Contains(pkm.Species);
if (!canBeEgg)
return false;
// Further Filtering
if (pkm.Format < 3)
{
canBeEgg &= pkm.Met_Location == 0 || pkm.Met_Level == 1; // 2->1->2 clears met info
canBeEgg &= pkm.CurrentLevel >= 5;
}
return canBeEgg;
}
private static IEnumerable<IEncounterable> GenerateFilteredEncounters12(PKM pkm)
{
bool crystal = (pkm.Format == 2 && pkm.Met_Location != 0) || (pkm.Format >= 7 && pkm.OT_Gender == 1);
@ -430,7 +432,6 @@ namespace PKHeX.Core
int species = pkm.Species;
var deferNoFrame = new Queue<IEncounterable>();
var deferFrame = new Queue<IEncounterable>();
pkm.WasEgg = false; // clear flag if set from static
var slots = FrameFinder.GetFrames(info.PIDIV, pkm).ToList();
foreach (var z in GetValidWildEncounters34(pkm))
{

View file

@ -43,7 +43,6 @@ namespace PKHeX.Core
var EncounterMatch = info.EncounterMatch;
if (EncounterMatch.EggEncounter)
{
pkm.WasEgg = true;
return VerifyEncounterEgg(pkm);
}
if (EncounterMatch is EncounterSlot1 l)
@ -119,7 +118,6 @@ namespace PKHeX.Core
// Eggs
private static CheckResult VerifyEncounterEgg(PKM pkm)
{
pkm.WasEgg = true;
// Check Species
if (Legal.NoHatchFromEgg.Contains(pkm.Species))
return new CheckResult(Severity.Invalid, LEggSpecies, CheckIdentifier.Encounter);

View file

@ -37,9 +37,6 @@ namespace PKHeX.Core
var restrict = new LevelUpRestriction(pkm, info);
info.EncounterMoves = new ValidEncounterMoves(pkm, restrict);
if (info.Generation <= 3)
pkm.WasEgg = info.EncounterMatch.EggEncounter;
List<int> defaultG1LevelMoves = null;
List<int> defaultG2LevelMoves = null;
var defaultTradeback = pkm.TradebackStatus;

View file

@ -524,7 +524,6 @@ namespace PKHeX.Core
public bool Gen1_NotTradeback => TradebackStatus == TradebackType.Gen1_NotTradeback;
public bool Gen2_NotTradeback => TradebackStatus == TradebackType.Gen2_NotTradeback;
public virtual bool WasLink => false;
private bool _WasEgg;
public bool WasEgg
{
@ -539,9 +538,8 @@ namespace PKHeX.Core
case 7: return Legal.EggLocations7.Contains(loc);
}
// Gen 1/2 and pal park Gen 3
return _WasEgg;
return false;
}
set => _WasEgg = value;
}
public bool WasBredEgg
@ -555,10 +553,9 @@ namespace PKHeX.Core
case 5: return loc == Locations.Daycare5 || loc == Locations.LinkTrade5;
case 6:
case 7: return loc == Locations.Daycare5 || loc == Locations.LinkTrade6;
default: return _WasEgg; // Gen 1/2 and pal park Gen 3
default: return false; // Gen 1/2 and pal park Gen 3
}
}
set => _WasEgg = value;
}
public virtual bool WasGiftEgg