mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00:00
Sanity check form prior to yield checks
This commit is contained in:
parent
b173c659d7
commit
200bdbd553
2 changed files with 27 additions and 0 deletions
|
@ -264,6 +264,8 @@ namespace PKHeX.Core
|
|||
{
|
||||
if (gift is WC3 {NotDistributed: true})
|
||||
continue;
|
||||
if (!IsSane(chain, gift))
|
||||
continue;
|
||||
if (needs.Count == 0)
|
||||
{
|
||||
yield return gift;
|
||||
|
@ -288,6 +290,8 @@ namespace PKHeX.Core
|
|||
var encounters = EncounterStaticGenerator.GetPossible(pk, chain, version);
|
||||
foreach (var enc in encounters)
|
||||
{
|
||||
if (!IsSane(chain, enc))
|
||||
continue;
|
||||
if (enc.IsUnobtainable())
|
||||
continue;
|
||||
if (needs.Count == 0)
|
||||
|
@ -339,6 +343,8 @@ namespace PKHeX.Core
|
|||
var trades = EncounterTradeGenerator.GetPossible(pk, chain, version);
|
||||
foreach (var trade in trades)
|
||||
{
|
||||
if (!IsSane(chain, trade))
|
||||
continue;
|
||||
if (needs.Count == 0)
|
||||
{
|
||||
yield return trade;
|
||||
|
@ -365,6 +371,8 @@ namespace PKHeX.Core
|
|||
var slots = EncounterSlotGenerator.GetPossible(pk, chain, version);
|
||||
foreach (var slot in slots)
|
||||
{
|
||||
if (!IsSane(chain, slot))
|
||||
continue;
|
||||
if (slot.IsUnobtainable())
|
||||
continue;
|
||||
|
||||
|
@ -383,6 +391,22 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static bool IsSane(IReadOnlyList<EvoCriteria> chain, IEncounterTemplate enc)
|
||||
{
|
||||
foreach (var evo in chain)
|
||||
{
|
||||
if (evo.Species != enc.Species)
|
||||
continue;
|
||||
if (evo.Form == enc.Form)
|
||||
return true;
|
||||
if (FormInfo.IsFormChangeable(enc.Species, enc.Form, evo.Form, enc.Generation))
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static bool IsUnobtainable(this EncounterSlot slot)
|
||||
{
|
||||
|
|
|
@ -19,6 +19,9 @@ namespace PKHeX.Tests.Legality
|
|||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(nameof(Species.Perrserker), "Swift")]
|
||||
[InlineData(nameof(Species.Perrserker), "Shock Wave")]
|
||||
[InlineData(nameof(Species.Sirfetchd), "False Swipe")]
|
||||
[InlineData(nameof(Species.Bulbasaur), "Fly")]
|
||||
[InlineData(nameof(Species.Charizard), "Bubble")]
|
||||
[InlineData(nameof(Species.Mew), "Struggle")]
|
||||
|
|
Loading…
Reference in a new issue