PKHeX/PKHeX.Core/Legality/Areas/EncounterArea6AO.cs
Kurt 734aa33898 Split encounter areas, relocate slot finding to obj
Now logic is reasonably split, and each format of area has its own way
of yielding slots

Too much junk with checking flute boosts or catch combo applicability;
just let the area dictate how slots match.
2019-09-12 23:20:52 -07:00

60 lines
No EOL
2.4 KiB
C#

using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
{
/// <inheritdoc />
/// <summary>
/// <see cref="GameVersion.ORAS"/> encounter area
/// </summary>
public sealed class EncounterArea6AO : EncounterArea32
{
private const int FluteBoostMax = 3; // Black Flute increases levels, White Flute decreases levels.
private const int DexNavBoost = 30;
protected override IEnumerable<EncounterSlot> GetMatchFromEvoLevel(PKM pkm, IEnumerable<DexLevel> vs, int minLevel)
{
var slots = Slots.Where(slot => vs.Any(evo => evo.Species == slot.Species && evo.Level >= (slot.LevelMin - FluteBoostMax)));
int getMaxLevelBoost(EncounterSlot s) => s.Type == SlotType.Rock_Smash ? FluteBoostMax : DexNavBoost;
int fluteMinLevel = minLevel - FluteBoostMax;
// Get slots where pokemon can exist with respect to level constraints
return slots.Where(s => s.IsLevelWithinRange(fluteMinLevel, minLevel - getMaxLevelBoost(s)));
}
protected override IEnumerable<EncounterSlot> GetFilteredSlots(PKM pkm, IEnumerable<EncounterSlot> slots, int minLevel)
{
EncounterSlot slotMax = null;
foreach (EncounterSlot s in slots)
{
if (Legal.WildForms.Contains(pkm.Species) && s.Form != pkm.AltForm)
{
CachePressureSlot(s);
continue;
}
bool nav = s.Permissions.AllowDexNav && (pkm.RelearnMove1 != 0 || pkm.AbilityNumber == 4);
EncounterSlot slot = s.Clone();
slot.Permissions.DexNav = nav;
if (slot.LevelMin > minLevel)
slot.Permissions.WhiteFlute = true;
if (slot.LevelMax + 1 <= minLevel && minLevel <= slot.LevelMax + FluteBoostMax)
slot.Permissions.BlackFlute = true;
if (slot.LevelMax != minLevel && slot.Permissions.AllowDexNav)
slot.Permissions.DexNav = true;
yield return slot;
CachePressureSlot(slot);
}
void CachePressureSlot(EncounterSlot s)
{
if (slotMax != null && s.LevelMax > slotMax.LevelMax)
slotMax = s;
}
// Pressure Slot
if (slotMax != null)
yield return GetPressureSlot(slotMax, pkm);
}
}
}