PKHeX/PKHeX.Core/PersonalInfo/Table/PersonalTable8LA.cs
Kurt 03182ebd3d Update 22.11.24
Adds support for Scarlet & Violet.

Co-Authored-By: SciresM <8676005+SciresM@users.noreply.github.com>
Co-Authored-By: Matt <17801814+sora10pls@users.noreply.github.com>
Co-Authored-By: Lusamine <30205550+Lusamine@users.noreply.github.com>
2022-11-24 17:42:17 -08:00

74 lines
2.3 KiB
C#

using System;
namespace PKHeX.Core;
/// <summary>
/// Personal Table storing <see cref="PersonalInfo8LA"/> used in <see cref="GameVersion.PLA"/>.
/// </summary>
public sealed class PersonalTable8LA : IPersonalTable, IPersonalTable<PersonalInfo8LA>
{
private readonly PersonalInfo8LA[] Table;
private const int SIZE = PersonalInfo8LA.SIZE;
private const int MaxSpecies = Legal.MaxSpeciesID_8a;
public int MaxSpeciesID => MaxSpecies;
public PersonalTable8LA(ReadOnlySpan<byte> data)
{
Table = new PersonalInfo8LA[data.Length / SIZE];
var count = data.Length / SIZE;
for (int i = 0, ofs = 0; i < count; i++, ofs += SIZE)
{
var slice = data.Slice(ofs, SIZE).ToArray();
Table[i] = new PersonalInfo8LA(slice);
}
}
public PersonalInfo8LA this[int index] => Table[(uint)index < Table.Length ? index : 0];
public PersonalInfo8LA this[ushort species, byte form] => Table[GetFormIndex(species, form)];
public PersonalInfo8LA GetFormEntry(ushort species, byte form) => Table[GetFormIndex(species, form)];
public int GetFormIndex(ushort species, byte form)
{
if ((uint)species <= MaxSpecies)
return Table[species].FormIndex(species, form);
return 0;
}
public bool IsSpeciesInGame(ushort species)
{
if ((uint)species > MaxSpecies)
return false;
var form0 = Table[species];
if (form0.IsPresentInGame)
return true;
var fc = form0.FormCount;
for (byte i = 1; i < fc; i++)
{
var entry = GetFormEntry(species, i);
if (entry.IsPresentInGame)
return true;
}
return false;
}
public bool IsPresentInGame(ushort species, byte form)
{
if ((uint)species > MaxSpecies)
return false;
var form0 = Table[species];
if (form == 0)
return form0.IsPresentInGame;
if (!form0.HasForm(form))
return false;
var entry = GetFormEntry(species, form);
return entry.IsPresentInGame;
}
PersonalInfo IPersonalTable.this[int index] => this[index];
PersonalInfo IPersonalTable.this[ushort species, byte form] => this[species, form];
PersonalInfo IPersonalTable.GetFormEntry(ushort species, byte form) => GetFormEntry(species, form);
}