Check static as-egg locations accurately

Thanks @sora10pls
This commit is contained in:
Kurt 2021-05-21 13:57:07 -07:00
parent 6b693b9b7e
commit 2c9b82824a
11 changed files with 63 additions and 59 deletions

View file

@ -251,23 +251,8 @@ namespace PKHeX.Core
return Form == evo.Form || FormInfo.IsFormChangeable(Species, Form, pkm.Form, pkm.Format);
}
protected virtual bool IsMatchEggLocation(PKM pkm)
{
if (pkm.IsEgg) // unhatched
{
if (!EggEncounter)
return false;
if (EggLocation != pkm.Met_Location)
return pkm.Met_Location == Locations.LinkTrade6 && pkm.Egg_Location == EggLocation;
return pkm.Egg_Location == 0;
}
if (EggLocation == pkm.Egg_Location)
return true;
// Only way to mismatch is to be a Link Traded egg.
return EggEncounter && pkm.Egg_Location == Locations.LinkTrade6;
}
// override me if the encounter type has any eggs
protected virtual bool IsMatchEggLocation(PKM pkm) => pkm.Egg_Location == 0;
private bool IsMatchGender(PKM pkm)
{

View file

@ -30,42 +30,33 @@ namespace PKHeX.Core
return true;
var locs = GetRoamLocations(Species, pk4.EncounterType);
return locs.Contains(pkm.Met_Location);
return locs.Contains(pk4.Met_Location);
}
protected override bool IsMatchEggLocation(PKM pkm)
{
if (pkm.Egg_Location == EggLocation)
{
if (EggLocation == 0)
return true;
var eggloc = pkm.Egg_Location;
if (!EggEncounter)
return eggloc == 0;
// Check the inverse scenario for 4->5 eggs
if (!Locations.IsPtHGSSLocationEgg(EggLocation))
// Transferring 4->5 clears Pt/HG/SS location value and keeps Faraway Place
if (pkm is not G4PKM pk4)
{
if (eggloc == Locations.LinkTrade4)
return true;
return pkm.Format == 4;
var cmp = Locations.IsPtHGSSLocationEgg(EggLocation) ? Locations.Faraway4 : EggLocation;
return eggloc == cmp;
}
if (pkm.IsEgg) // unhatched
{
if (EggLocation != pkm.Met_Location)
return false;
return pkm.Egg_Location == 0;
}
if (!pk4.IsEgg) // hatched
return eggloc == EggLocation || eggloc == Locations.LinkTrade4;
// Only way to mismatch is to be a Link Traded egg, or traded to Pt/HG/SS and hatched there.
if (pkm.Egg_Location == Locations.LinkTrade4)
return true;
// check Pt/HGSS data
if (pkm.Format == 4)
// Unhatched:
if (eggloc != EggLocation)
return false;
if (!Locations.IsPtHGSSLocationEgg(EggLocation)) // non-Pt/HG/SS egg gift
if (pk4.Met_Location is not 0 or Locations.LinkTrade4)
return false;
// transferring 4->5 clears Pt/HG/SS location value and keeps Faraway Place
return pkm.Egg_Location == Locations.Faraway4;
return true;
}
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)

View file

@ -29,20 +29,19 @@ namespace PKHeX.Core
protected override bool IsMatchEggLocation(PKM pkm)
{
if (pkm.IsEgg) // unhatched
{
if (!EggEncounter)
return false;
if (EggLocation != pkm.Met_Location)
return pkm.Met_Location == Locations.LinkTrade5 && pkm.Egg_Location == EggLocation;
return pkm.Egg_Location == 0;
}
var eggloc = pkm.Egg_Location;
if (!EggEncounter)
return eggloc == EggLocation;
if (EggLocation == pkm.Egg_Location)
return true;
if (!pkm.IsEgg) // hatched
return eggloc == EggLocation || eggloc == Locations.LinkTrade5;
// Only way to mismatch is to be a Link Traded egg.
return EggEncounter && pkm.Egg_Location == Locations.LinkTrade5;
// Unhatched:
if (eggloc != EggLocation)
return false;
if (pkm.Met_Location is not 0 or Locations.LinkTrade5)
return false;
return true;
}
private static readonly int[] Roaming_MetLocation_BW =

View file

@ -30,6 +30,23 @@
return loc is 180 or 186 or 194;
}
protected override bool IsMatchEggLocation(PKM pkm)
{
var eggloc = pkm.Egg_Location;
if (!EggEncounter)
return eggloc == EggLocation;
if (!pkm.IsEgg) // hatched
return eggloc == EggLocation || eggloc == Locations.LinkTrade6;
// Unhatched:
if (eggloc != EggLocation)
return false;
if (pkm.Met_Location is not 0 or Locations.LinkTrade6)
return false;
return true;
}
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
{
base.ApplyDetails(sav, criteria, pk);

View file

@ -23,6 +23,23 @@ namespace PKHeX.Core
return base.IsMatchLocation(pkm);
}
protected override bool IsMatchEggLocation(PKM pkm)
{
var eggloc = pkm.Egg_Location;
if (!EggEncounter)
return eggloc == EggLocation;
if (!pkm.IsEgg) // hatched
return eggloc == EggLocation || eggloc == Locations.LinkTrade6;
// Unhatched:
if (eggloc != EggLocation)
return false;
if (pkm.Met_Location is not 0 or Locations.LinkTrade6)
return false;
return true;
}
protected override bool IsMatchForm(PKM pkm, DexLevel evo)
{
if (SkipFormCheck)

View file

@ -41,11 +41,6 @@ namespace PKHeX.Core
113, // Pyrite Town
};
protected override bool IsMatchEggLocation(PKM pkm)
{
return true; // transfer location verified later
}
protected override bool IsMatchLocation(PKM pkm)
{
if (pkm.Format != 3)