mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-25 11:53:11 +00:00
94d8125574
removes one GetEnumerator call for non-fsafari encounters
84 lines
No EOL
2.5 KiB
C#
84 lines
No EOL
2.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
/// <inheritdoc />
|
|
/// <summary>
|
|
/// <see cref="GameVersion.XY"/> encounter area
|
|
/// </summary>
|
|
public sealed class EncounterArea6XY : EncounterArea32
|
|
{
|
|
protected override IEnumerable<EncounterSlot> GetFilteredSlots(PKM pkm, IEnumerable<EncounterSlot> slots, int minLevel)
|
|
{
|
|
EncounterSlot? slotMax = null;
|
|
void CachePressureSlot(EncounterSlot s)
|
|
{
|
|
if (slotMax == null || s.LevelMax > slotMax.LevelMax)
|
|
slotMax = s;
|
|
}
|
|
|
|
int species = pkm.Species;
|
|
int form = pkm.AltForm;
|
|
bool ShouldMatchSlotForm() => Legal.WildForms.Contains(species);
|
|
|
|
if (ShouldMatchSlotForm()) // match slot form
|
|
{
|
|
foreach (var slot in slots)
|
|
{
|
|
if (slot.Form == form)
|
|
yield return slot;
|
|
CachePressureSlot(slot);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var slot in slots)
|
|
{
|
|
yield return slot; // no form checking
|
|
CachePressureSlot(slot);
|
|
}
|
|
}
|
|
|
|
// Filter for Form Specific
|
|
// Pressure Slot
|
|
if (slotMax == null)
|
|
yield break;
|
|
|
|
if (ShouldMatchSlotForm()) // match slot form
|
|
{
|
|
if (slotMax.Form == form)
|
|
yield return GetPressureSlot(slotMax, pkm);
|
|
}
|
|
else
|
|
{
|
|
yield return GetPressureSlot(slotMax, pkm);
|
|
}
|
|
}
|
|
|
|
public static bool WasFriendSafari(PKM pkm)
|
|
{
|
|
if (!pkm.XY)
|
|
return false;
|
|
if (pkm.Met_Location != 148)
|
|
return false;
|
|
if (pkm.Met_Level != 30)
|
|
return false;
|
|
if (pkm.Egg_Location != 0)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
public static IEnumerable<EncounterSlot> GetValidFriendSafari(PKM pkm)
|
|
{
|
|
var vs = EvolutionChain.GetValidPreEvolutions(pkm);
|
|
return GetValidFriendSafari(vs);
|
|
}
|
|
|
|
public static IEnumerable<EncounterSlot> GetValidFriendSafari(IEnumerable<EvoCriteria> vs)
|
|
{
|
|
var evos = vs.Where(d => d.Level >= 30);
|
|
return evos.SelectMany(z => Encounters6.FriendSafari[z.Species]);
|
|
}
|
|
}
|
|
} |