Clean up catch rate comparisons

Add dragonite to the uncapturable list, removes catchrate comparison for dragonite since it's filtered out.

Skip some linq by doing the loop directly in the method. Replace local methods with captured variables with direct if-returns.
This commit is contained in:
Kurt
2021-05-18 10:38:01 -07:00
parent 565f161226
commit fbba64c0e6

View File

@@ -93,6 +93,7 @@ internal static class GBRestrictions
(int)Cloyster,
(int)Exeggutor,
(int)Starmie,
(int)Dragonite,
};
internal static readonly HashSet<int> Trade_Evolution1 = new()
@@ -384,17 +385,29 @@ internal static IEnumerable<GameVersion> GetGen1Versions(IEncounterable enc)
yield return RB;
}
private static bool GetCatchRateMatchesPreEvolution(PKM pkm, int catch_rate, IEnumerable<int> gen1)
private static bool GetCatchRateMatchesPreEvolution(PK1 pkm, int catch_rate)
{
// For species catch rate, discard any species that has no valid encounters and a different catch rate than their pre-evolutions
var Lineage = gen1.Except(Species_NotAvailable_CatchRate);
return IsCatchRateRBY(Lineage) || IsCatchRateTrade() || IsCatchRateStadium();
var table = EvolutionTree.GetEvolutionTree(1);
var chain = table.GetValidPreEvolutions(pkm, maxLevel: pkm.CurrentLevel);
foreach (var entry in chain)
{
var s = entry.Species;
if (Species_NotAvailable_CatchRate.Contains(s))
continue;
if (catch_rate == PersonalTable.RB[s].CatchRate || catch_rate == PersonalTable.Y[s].CatchRate)
return true;
}
// Dragonite's Catch Rate is different than Dragonair's in Yellow, but there is no Dragonite encounter.
bool IsCatchRateRBY(IEnumerable<int> ds) => ds.Any(s => catch_rate == PersonalTable.RB[s].CatchRate || (s != 149 && catch_rate == PersonalTable.Y[s].CatchRate));
// Krabby encounter trade special catch rate
bool IsCatchRateTrade() => catch_rate == 204 && (pkm.Species == (int)Krabby || pkm.Species == (int)Kingler);
bool IsCatchRateStadium() => Stadium_GiftSpecies.Contains(pkm.Species) && Stadium_CatchRate.Contains(catch_rate);
int species = pkm.Species;
if (catch_rate == 204 && (species is (int)Krabby or (int)Kingler))
return true;
if (Stadium_GiftSpecies.Contains(species) && Stadium_CatchRate.Contains(catch_rate))
return true;
return false;
}
/// <summary>
@@ -454,10 +467,7 @@ private static TradebackType GetTradebackStatusRBY(PK1 pkm)
if (catch_rate == 0)
return TradebackType.WasTradeback;
var table = EvolutionTree.GetEvolutionTree(1);
var lineage = table.GetValidPreEvolutions(pkm, maxLevel: pkm.CurrentLevel);
var gen1 = lineage.Select(evolution => evolution.Species);
bool matchAny = GetCatchRateMatchesPreEvolution(pkm, catch_rate, gen1);
bool matchAny = GetCatchRateMatchesPreEvolution(pkm, catch_rate);
if (!matchAny)
return TradebackType.WasTradeback;