Extract catchrate check

This commit is contained in:
Kurt 2021-06-09 22:54:21 -07:00
parent 49b7d4522c
commit f984862f48
3 changed files with 20 additions and 16 deletions

View file

@ -73,9 +73,7 @@
}
// Encounters can have different Catch Rates (RBG vs Y)
var table = Version == GameVersion.Y ? PersonalTable.Y : PersonalTable.RB;
var rate = table[Species].CatchRate;
return catch_rate == rate;
return GBRestrictions.RateMatchesEncounter(Species, Version, catch_rate);
}
}
}

View file

@ -103,6 +103,18 @@ namespace PKHeX.Core
(int)Haunter,
};
public static bool RateMatchesEncounter(int species, GameVersion version, int rate)
{
if (version.Contains(YW))
{
if (rate == PersonalTable.Y[species].CatchRate)
return true;
if (version == YW) // no RB
return false;
}
return rate == PersonalTable.RB[species].CatchRate;
}
private static int[] GetMinLevelLearnMoveG1(int species, List<int> moves)
{
var result = new int[moves.Count];

View file

@ -164,25 +164,19 @@ namespace PKHeX.Core
CheckResult GetWasNotTradeback()
{
var e = data.EncounterMatch;
if (e is EncounterStatic1E {Version: GameVersion.Stadium} || e is EncounterTrade1)
if (e is EncounterStatic1E {Version: GameVersion.Stadium} or EncounterTrade1)
return GetValid(LG1CatchRateMatchPrevious); // Encounters detected by the catch rate, cant be invalid if match this encounters
int species = pk1.Species;
if ((species == (int)Species.Dragonite && catch_rate == 9) || (GBRestrictions.Species_NotAvailable_CatchRate.Contains(species) && catch_rate == PersonalTable.RB[species].CatchRate))
return GetInvalid(LG1CatchRateEvo);
if (!data.Info.EvoChainsAllGens[1].Any(c => RateMatchesEncounter(c.Species)))
if (GBRestrictions.Species_NotAvailable_CatchRate.Contains(species) && catch_rate == PersonalTable.RB[species].CatchRate)
{
if (species != (int) Species.Dragonite || catch_rate != 45 || !e.Version.Contains(GameVersion.YW))
return GetInvalid(LG1CatchRateEvo);
}
if (!GBRestrictions.RateMatchesEncounter(e.Species, e.Version, catch_rate))
return GetInvalid(pk1.Gen1_NotTradeback ? LG1CatchRateChain : LG1CatchRateNone);
return GetValid(LG1CatchRateMatchPrevious);
}
bool RateMatchesEncounter(int species)
{
if (catch_rate == PersonalTable.RB[species].CatchRate)
return true;
if (catch_rate == PersonalTable.Y[species].CatchRate)
return true;
return false;
}
}
private static void VerifyMiscFatefulEncounter(LegalityAnalysis data)