PKHeX/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot4.cs
Kurt 103aa9aa4b
Revise EncounterArea and EncounterType for clarity (#3228)
EncounterArea now stores a more specific type'd array for encounter slots. Better iteration and less casting, as the nonspecific `Slots` fetch is rarely referenced.

EncounterType renamed to GroundTile to reflect how it actually works in Gen4. Was previously an ambiguous field that was clarified a little; we can describe it a little better now. Keep the GUI the same to not scare the end users.

Change Trash Byte properties to get/set a Span. Trash Byte legality checking easier on the garbage collector?
2021-06-29 20:58:06 -07:00

45 lines
1.7 KiB
C#

namespace PKHeX.Core
{
/// <summary>
/// Encounter Slot found in <see cref="GameVersion.Gen4"/>.
/// </summary>
/// <inheritdoc cref="EncounterSlot"/>
public sealed record EncounterSlot4 : EncounterSlot, IMagnetStatic, INumberedSlot, IGroundTypeTile
{
public override int Generation => 4;
public GroundTilePermission GroundTile => ((EncounterArea4)Area).GroundTile;
public int StaticIndex { get; }
public int MagnetPullIndex { get; }
public int StaticCount { get; }
public int MagnetPullCount { get; }
public int SlotNumber { get; }
public EncounterSlot4(EncounterArea4 area, int species, int form, int min, int max, int slot, int mpi, int mpc, int sti, int stc) : base(area, species, form, min, max)
{
SlotNumber = slot;
MagnetPullIndex = mpi;
MagnetPullCount = mpc;
StaticIndex = sti;
StaticCount = stc;
}
protected override void SetFormatSpecificData(PKM pk) => ((PK4)pk).GroundTile = GroundTile.GetIndex();
public override EncounterMatchRating GetMatchRating(PKM pkm)
{
if ((pkm.Ball == (int)Ball.Safari) != Locations.IsSafariZoneLocation4(Location))
return EncounterMatchRating.PartialMatch;
if ((pkm.Ball == (int)Ball.Sport) != (Area.Type == SlotType.BugContest))
{
// Nincada => Shedinja can wipe the ball back to Poke
if (pkm.Species != (int)Core.Species.Shedinja || pkm.Ball != (int)Ball.Poke)
return EncounterMatchRating.PartialMatch;
}
return base.GetMatchRating(pkm);
}
}
}