2022-06-19 02:12:41 +00:00
|
|
|
using System;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
|
|
|
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gen5 structure
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>size 0x18</remarks>
|
|
|
|
[TypeConverter(typeof(ExpandableObjectConverter))]
|
2024-03-04 05:13:16 +00:00
|
|
|
public sealed class Roamer5(Memory<byte> raw)
|
2022-06-19 02:12:41 +00:00
|
|
|
{
|
2023-06-11 18:12:34 +00:00
|
|
|
public const int SIZE = 0x14;
|
2022-06-19 02:12:41 +00:00
|
|
|
|
2024-03-04 05:13:16 +00:00
|
|
|
private Span<byte> Data => raw.Span;
|
2022-06-19 02:12:41 +00:00
|
|
|
|
2023-06-11 18:12:34 +00:00
|
|
|
public ushort Location { get => ReadUInt16LittleEndian(Data); set => WriteUInt16LittleEndian(Data , value); }
|
|
|
|
public ushort Nature { get => ReadUInt16LittleEndian(Data[0x02..]); set => WriteUInt16LittleEndian(Data[0x02..], value); }
|
|
|
|
public uint IV32 { get => ReadUInt32LittleEndian(Data[0x04..]); set => WriteUInt32LittleEndian(Data[0x04..], value); }
|
|
|
|
public uint PID { get => ReadUInt32LittleEndian(Data[0x08..]); set => WriteUInt32LittleEndian(Data[0x08..], value); }
|
|
|
|
public ushort Species { get => ReadUInt16LittleEndian(Data[0x0C..]); set => WriteUInt16LittleEndian(Data[0x0C..], value); }
|
|
|
|
public ushort Stat_HPCurrent { get => ReadUInt16LittleEndian(Data[0x0E..]); set => WriteUInt16LittleEndian(Data[0x0E..], value); }
|
|
|
|
public byte Level { get => Data[0x10]; set => Data[0x10] = value; }
|
|
|
|
public byte Status { get => Data[0x11]; set => Data[0x11] = value; }
|
|
|
|
public bool Active { get => Data[0x12] != 0; set => Data[0x12] = (byte)(value ? 1 : 0); }
|
|
|
|
public byte Unk13 { get => Data[0x13]; set => Data[0x13] = value; } // likely just alignment
|
2022-06-19 02:12:41 +00:00
|
|
|
|
|
|
|
// Derived Properties
|
2023-09-11 04:17:47 +00:00
|
|
|
private int IV_HP { get => (int)(IV32 >> 00) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 00)) | (uint)((value > 31 ? 31 : value) << 00); }
|
|
|
|
private int IV_ATK { get => (int)(IV32 >> 05) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 05)) | (uint)((value > 31 ? 31 : value) << 05); }
|
|
|
|
private int IV_DEF { get => (int)(IV32 >> 10) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 10)) | (uint)((value > 31 ? 31 : value) << 10); }
|
|
|
|
private int IV_SPE { get => (int)(IV32 >> 15) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 15)) | (uint)((value > 31 ? 31 : value) << 15); }
|
|
|
|
private int IV_SPA { get => (int)(IV32 >> 20) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 20)) | (uint)((value > 31 ? 31 : value) << 20); }
|
|
|
|
private int IV_SPD { get => (int)(IV32 >> 25) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 25)) | (uint)((value > 31 ? 31 : value) << 25); }
|
2022-06-19 02:12:41 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Roamer's IVs.
|
|
|
|
/// </summary>
|
|
|
|
public int[] IVs
|
|
|
|
{
|
2023-12-04 04:13:20 +00:00
|
|
|
get => [IV_HP, IV_ATK, IV_DEF, IV_SPE, IV_SPA, IV_SPD];
|
2022-06-19 02:12:41 +00:00
|
|
|
set => SetIVs(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetIVs(ReadOnlySpan<int> value)
|
|
|
|
{
|
|
|
|
if (value.Length != 6)
|
|
|
|
return;
|
|
|
|
IV_HP = value[0];
|
|
|
|
IV_ATK = value[1];
|
|
|
|
IV_DEF = value[2];
|
|
|
|
IV_SPE = value[3];
|
|
|
|
IV_SPA = value[4];
|
|
|
|
IV_SPD = value[5];
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Clear() => Data.Clear();
|
|
|
|
}
|