PKHeX/PKHeX.Core/Legality/Encounters/IEncounterMatch.cs
Kurt ef3cb34387
Refactor EvoCriteria to be a struct, reduce allocation (#3483)
* 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.
2022-04-23 21:33:17 -07:00

53 lines
2.1 KiB
C#

using static PKHeX.Core.Species;
namespace PKHeX.Core
{
/// <summary>
/// Exposes details about the quality of a potential match compared to an input <see cref="PKM"/>.
/// </summary>
public interface IEncounterMatch
{
/// <summary>
/// Checks if the implementing object's details might have been the originator of the current <see cref="pkm"/> data.
/// </summary>
bool IsMatchExact(PKM pkm, IDexLevel dl);
/// <summary>
/// Checks if the potential match may not be a perfect match (might be a better match later during iteration).
/// </summary>
EncounterMatchRating GetMatchRating(PKM pkm);
}
internal static class EncounterMatchExtensions
{
/// <summary>
/// Some species do not have a Hidden Ability, but can be altered to have the HA slot via pre-evolution.
/// </summary>
/// <param name="_">Match object</param>
/// <param name="species">Species ID</param>
/// <returns>True if it should not originate as this species.</returns>
private static bool IsPartialMatchHidden(this IEncounterMatch _, int species)
{
return species is (int)Metapod or (int)Kakuna
or (int)Pupitar
or (int)Silcoon or (int)Cascoon
or (int)Vibrava or (int)Flygon;
}
/// <summary>
/// Some species do not have a Hidden Ability, but can be altered to have the HA slot via pre-evolution.
/// </summary>
/// <param name="_">Match object</param>
/// <param name="current">Current Species ID</param>
/// <param name="original">Original Species ID</param>
/// <returns>True if it should not originate as this species.</returns>
public static bool IsPartialMatchHidden(this IEncounterMatch _, int current, int original)
{
if (current == original)
return false;
if (!_.IsPartialMatchHidden(original))
return false;
return _.IsPartialMatchHidden(current);
}
}
}