2023-03-26 06:14:50 +00:00
|
|
|
using System;
|
2022-01-03 05:35:59 +00:00
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
public sealed class Puff6 : SaveBlock<SAV6>
|
2019-06-09 02:56:11 +00:00
|
|
|
{
|
2023-09-11 04:17:47 +00:00
|
|
|
private const byte MaxPuffID = 26; // Supreme Winter Poké Puff
|
2022-06-18 18:04:24 +00:00
|
|
|
private const int PuffSlots = 100;
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public Puff6(SAV6 SAV, int offset) : base(SAV) => Offset = offset;
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2023-03-26 06:14:50 +00:00
|
|
|
public Span<byte> GetPuffs() => SAV.Data.AsSpan(Offset, PuffSlots);
|
|
|
|
public void SetPuffs(ReadOnlySpan<byte> value) => SAV.SetData(value, Offset);
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int PuffCount
|
|
|
|
{
|
|
|
|
get => ReadInt32LittleEndian(Data.AsSpan(Offset + PuffSlots));
|
|
|
|
set => WriteInt32LittleEndian(Data.AsSpan(Offset + PuffSlots), value);
|
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void Reset()
|
|
|
|
{
|
2023-09-11 04:17:47 +00:00
|
|
|
var puffs = GetPuffs();
|
|
|
|
puffs.Clear();
|
2022-06-18 18:04:24 +00:00
|
|
|
// Set the first few default Puffs
|
2023-09-11 04:17:47 +00:00
|
|
|
puffs[0] = 1;
|
|
|
|
puffs[1] = 2;
|
|
|
|
puffs[2] = 3;
|
|
|
|
puffs[3] = 4;
|
|
|
|
puffs[4] = 5;
|
2022-06-18 18:04:24 +00:00
|
|
|
PuffCount = 5;
|
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void MaxCheat(bool special = false)
|
|
|
|
{
|
|
|
|
var rnd = Util.Rand;
|
2023-09-11 04:17:47 +00:00
|
|
|
var puffs = GetPuffs();
|
2022-06-18 18:04:24 +00:00
|
|
|
if (special)
|
2019-06-09 02:56:11 +00:00
|
|
|
{
|
2023-09-11 04:17:47 +00:00
|
|
|
foreach (ref var puff in puffs)
|
|
|
|
puff = (byte)(21 + rnd.Next(2)); // Supreme Wish or Honor
|
2019-06-09 02:56:11 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
else
|
2019-06-09 02:56:11 +00:00
|
|
|
{
|
2023-09-11 04:17:47 +00:00
|
|
|
int i = 0;
|
|
|
|
foreach (ref var puff in puffs)
|
|
|
|
puff = (byte)((i++ % MaxPuffID) + 1);
|
|
|
|
rnd.Shuffle(puffs);
|
2019-06-09 02:56:11 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
PuffCount = PuffSlots;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Sort(bool reverse = false)
|
|
|
|
{
|
2023-09-11 04:17:47 +00:00
|
|
|
var puffs = GetPuffs();
|
|
|
|
puffs.Sort();
|
2022-06-18 18:04:24 +00:00
|
|
|
if (reverse)
|
2023-09-11 04:17:47 +00:00
|
|
|
puffs.Reverse();
|
2019-06-09 02:56:11 +00:00
|
|
|
}
|
2020-05-25 00:11:39 +00:00
|
|
|
}
|