PKHeX/PKHeX.Core/Legality/Areas/EncounterArea9.cs
Kurt 88830e0d00
Update from .NET Framework 4.6 to .NET 7 (#3729)
Updates from net46->net7, dropping support for mono in favor of using the latest runtime (along with the performance/API improvements). Releases will be posted as 64bit only for now.

Refactors a good amount of internal API methods to be more performant and more customizable for future updates & fixes.

Adds functionality for Batch Editor commands to `>`, `<` and <=/>=

TID/SID properties renamed to TID16/SID16 for clarity; other properties exposed for Gen7 / display variants.

Main window has a new layout to account for DPI scaling (8 point grid)

Fixed: Tatsugiri and Paldean Tauros now output Showdown form names as Showdown expects
Changed: Gen9 species now interact based on the confirmed National Dex IDs (closes #3724)
Fixed: Pokedex set all no longer clears species with unavailable non-base forms (closes #3720)
Changed: Hyper Training suggestions now apply for level 50 in SV. (closes #3714)
Fixed: B2/W2 hatched egg met locations exclusive to specific versions are now explicitly checked (closes #3691)
Added: Properties for ribbon/mark count (closes #3659)
Fixed: Traded SV eggs are now checked correctly (closes #3692)
2023-01-21 20:02:33 -08:00

83 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using static System.Buffers.Binary.BinaryPrimitives;
namespace PKHeX.Core;
/// <inheritdoc cref="EncounterArea" />
/// <summary>
/// <see cref="GameVersion.SV"/> encounter area
/// </summary>
public sealed record EncounterArea9 : EncounterArea
{
public readonly EncounterSlot9[] Slots;
public ushort CrossFrom { get; }
protected override IReadOnlyList<EncounterSlot9> Raw => Slots;
public static EncounterArea9[] GetAreas(BinLinkerAccessor input, GameVersion game)
{
var result = new EncounterArea9[input.Length];
for (int i = 0; i < result.Length; i++)
result[i] = new EncounterArea9(input[i], game);
return result;
}
private EncounterArea9(ReadOnlySpan<byte> areaData, GameVersion game) : base(game)
{
Location = areaData[0];
CrossFrom = areaData[2];
Slots = ReadSlots(areaData[4..]);
}
private EncounterSlot9[] ReadSlots(ReadOnlySpan<byte> areaData)
{
const int size = 8;
var result = new EncounterSlot9[areaData.Length / size];
for (int i = 0; i < result.Length; i++)
{
var slot = areaData[(i * size)..];
var species = ReadUInt16LittleEndian(slot);
var form = slot[2];
var gender = (sbyte)slot[3];
var min = slot[4];
var max = slot[5];
var time = slot[6];
result[i] = new EncounterSlot9(this, species, form, min, max, gender, time);
}
return result;
}
public override IEnumerable<EncounterSlot9> GetMatchingSlots(PKM pk, EvoCriteria[] chain)
{
var lvl = pk.Met_Level;
foreach (var slot in Slots)
{
foreach (var evo in chain)
{
if (slot.Species != evo.Species)
continue;
if (slot.Form != evo.Form && slot.Species is not ((int)Species.Rotom or (int)Species.Deerling or (int)Species.Sawsbuck or (int)Species.Oricorio))
break;
if (slot.Gender != -1 && pk.Gender != slot.Gender)
break;
if (!slot.IsLevelWithinRange(lvl))
break;
if (pk is ITeraType t)
{
var orig = (byte)t.TeraTypeOriginal;
var pi = PersonalTable.SV[slot.Species, slot.Form];
if (pi.Type1 != orig && pi.Type2 != orig)
break;
}
yield return slot;
break;
}
}
}
}