2018-05-19 19:07:50 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2022-01-03 05:35:59 +00:00
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2018-05-19 19:07:50 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Generation 6 Evolution Branch Entries
|
|
|
|
/// </summary>
|
|
|
|
public static class EvolutionSet6
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
internal static readonly HashSet<int> EvosWithArg = new() {6, 8, 16, 17, 18, 19, 20, 21, 22, 29};
|
|
|
|
private const int SIZE = 6;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static EvolutionMethod[] GetMethods(ReadOnlySpan<byte> data)
|
|
|
|
{
|
|
|
|
var evos = new EvolutionMethod[data.Length / SIZE];
|
|
|
|
for (int i = 0; i < data.Length; i += SIZE)
|
2018-05-19 19:07:50 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var entry = data.Slice(i, SIZE);
|
|
|
|
evos[i/SIZE] = GetMethod(entry);
|
2019-03-23 17:36:28 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return evos;
|
|
|
|
}
|
2019-03-23 17:36:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static EvolutionMethod GetMethod(ReadOnlySpan<byte> entry)
|
|
|
|
{
|
|
|
|
var method = ReadUInt16LittleEndian(entry);
|
|
|
|
var arg = ReadUInt16LittleEndian(entry[2..]);
|
|
|
|
var species = ReadUInt16LittleEndian(entry[4..]);
|
2022-01-03 05:35:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Argument is used by both Level argument and Item/Move/etc. Clear if appropriate.
|
|
|
|
var lvl = EvosWithArg.Contains(method) ? 0 : arg;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return new EvolutionMethod(method, species, argument: arg, level: (byte)lvl);
|
|
|
|
}
|
2022-01-03 05:35:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static IReadOnlyList<EvolutionMethod[]> GetArray(BinLinkerAccessor data)
|
|
|
|
{
|
|
|
|
var evos = new EvolutionMethod[data.Length][];
|
|
|
|
for (int i = 0; i < evos.Length; i++)
|
|
|
|
evos[i] = GetMethods(data[i]);
|
|
|
|
return evos;
|
2018-05-19 19:07:50 +00:00
|
|
|
}
|
2022-01-03 05:35:59 +00:00
|
|
|
}
|