2023-03-26 06:14:50 +00:00
|
|
|
using System;
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
public sealed class FashionBlock7 : SaveBlock<SAV7>
|
2019-06-09 02:56:11 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public FashionBlock7(SAV7SM sav, int offset) : base(sav) => Offset = offset;
|
|
|
|
public FashionBlock7(SAV7USUM sav, int offset) : base(sav) => Offset = offset;
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private const int FashionLength = 0x1A08;
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public FashionItem7[] Wardrobe
|
|
|
|
{
|
|
|
|
get
|
2019-06-09 02:56:11 +00:00
|
|
|
{
|
2023-03-26 06:14:50 +00:00
|
|
|
var data = SAV.Data.AsSpan(Offset, 0x5A8).ToArray();
|
2022-06-18 18:04:24 +00:00
|
|
|
return Array.ConvertAll(data, b => new FashionItem7(b));
|
2019-06-09 02:56:11 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
set
|
2019-09-16 05:12:32 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (value.Length != 0x5A8)
|
|
|
|
throw new ArgumentOutOfRangeException($"Unexpected size: 0x{value.Length:X}");
|
|
|
|
var arr = Array.ConvertAll(value, z => z.Value);
|
|
|
|
SAV.SetData(arr, Offset);
|
2019-09-16 05:12:32 +00:00
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
}
|
2019-10-28 03:39:07 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void Clear() => Array.Clear(Data, Offset, FashionLength);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Resets the fashion unlocks to default values.
|
|
|
|
/// </summary>
|
|
|
|
public void Reset()
|
2019-10-28 03:39:07 +00:00
|
|
|
{
|
2023-03-26 06:14:50 +00:00
|
|
|
var offsetList = GetDefaultFashionOffsets(SAV);
|
2022-06-18 18:04:24 +00:00
|
|
|
foreach (var ofs in offsetList)
|
|
|
|
SAV.Data[Offset + ofs] = 3; // owned | new
|
|
|
|
}
|
2023-03-26 06:14:50 +00:00
|
|
|
|
|
|
|
private static ReadOnlySpan<ushort> GetDefaultFashionOffsets(SAV7 sav) => sav switch
|
|
|
|
{
|
|
|
|
SAV7SM { Gender: 0 } => DefaultFashionOffsetSM_M,
|
|
|
|
SAV7SM { Gender: 1 } => DefaultFashionOffsetSM_F,
|
|
|
|
SAV7USUM { Gender: 0 } => DefaultFashionOffsetUU_M,
|
|
|
|
SAV7USUM { Gender: 1 } => DefaultFashionOffsetUU_F,
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(SAV)),
|
|
|
|
};
|
|
|
|
|
|
|
|
// Offsets that are set to '3' when the game starts for a specific gender.
|
|
|
|
private static ReadOnlySpan<ushort> DefaultFashionOffsetSM_M => new ushort[] { 0x000, 0x0FB, 0x124, 0x28F, 0x3B4, 0x452, 0x517 };
|
|
|
|
private static ReadOnlySpan<ushort> DefaultFashionOffsetSM_F => new ushort[] { 0x000, 0x100, 0x223, 0x288, 0x3B4, 0x452, 0x517 };
|
|
|
|
private static ReadOnlySpan<ushort> DefaultFashionOffsetUU_M => new ushort[] { 0x03A, 0x109, 0x1DA, 0x305, 0x3D9, 0x4B1, 0x584 };
|
|
|
|
private static ReadOnlySpan<ushort> DefaultFashionOffsetUU_F => new ushort[] { 0x05E, 0x208, 0x264, 0x395, 0x3B4, 0x4F9, 0x5A8 };
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-10-28 03:39:07 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Every fashion item is 2 bits, New Flag (high) & Owned Flag (low)
|
|
|
|
public sealed class FashionItem7
|
|
|
|
{
|
|
|
|
public bool IsOwned { get; set; }
|
|
|
|
public bool IsNew { get; set; }
|
2019-10-28 03:39:07 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public FashionItem7(byte b)
|
|
|
|
{
|
|
|
|
IsOwned = (b & 1) != 0;
|
|
|
|
IsNew = (b & 2) != 0;
|
2019-10-28 03:39:07 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
public byte Value => (byte)((IsOwned ? 1 : 0) | (IsNew ? 2 : 0));
|
|
|
|
}
|