mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-22 10:23:09 +00:00
ef3cb34387
* Make EvolutionCriteria struct 8 bytes per object instead of 26 Unify LevelMin/LevelMax to match EncounterTemplate bubble up precise array type for better iteration * Inline queue operations, less allocation * Inline some logic * Update EvolutionChain.cs * Improve clarity on duplicate move check * Search reverse For a dual stage chain, finds it first iteration rather than second.
33 lines
1.5 KiB
C#
33 lines
1.5 KiB
C#
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>
|
|
public abstract record EncounterArea(GameVersion Version) : IVersion
|
|
{
|
|
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, IReadOnlyList<EvoCriteria> chain);
|
|
|
|
/// <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(IReadOnlyList<EvoCriteria> chain) => Raw.Where(z => chain.Any(c => z.Species == c.Species));
|
|
}
|
|
}
|