PKHeX/PKHeX.Core/Legality/Areas/EncounterArea.cs

34 lines
1.5 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
{
/// <summary>
/// Represents an Area where <see cref="PKM"/> can be encountered, which contains a Location ID and <see cref="EncounterSlot"/> data.
/// </summary>
2021-12-05 01:56:56 +00:00
public abstract record EncounterArea(GameVersion Version) : IVersion
{
2020-12-22 01:05:05 +00:00
public int Location { get; protected init; }
public SlotType Type { get; protected init; } = SlotType.Any;
protected abstract IReadOnlyList<EncounterSlot> Raw { get; }
/// <summary>
/// Gets the slots contained in the area that match the provided data.
/// </summary>
/// <param name="pkm">Pokémon Data</param>
/// <param name="chain">Evolution lineage</param>
/// <returns>Enumerable list of encounters</returns>
public abstract IEnumerable<EncounterSlot> GetMatchingSlots(PKM pkm, EvoCriteria[] chain);
2019-11-21 01:01:34 +00:00
/// <summary>
/// Checks if the provided met location ID matches the parameters for the area.
/// </summary>
/// <param name="location">Met Location ID</param>
/// <returns>True if possibly originated from this area, false otherwise.</returns>
public virtual bool IsMatchLocation(int location) => Location == location;
public bool HasSpecies(int species) => Raw.Any(z => z.Species == species);
public IEnumerable<EncounterSlot> GetSpecies(EvoCriteria[] chain) => Raw.Where(z => chain.Any(c => z.Species == c.Species));
}
}