mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-22 18:33:14 +00:00
ef3cb34387
* Make EvolutionCriteria struct 8 bytes per object instead of 26 Unify LevelMin/LevelMax to match EncounterTemplate bubble up precise array type for better iteration * Inline queue operations, less allocation * Inline some logic * Update EvolutionChain.cs * Improve clarity on duplicate move check * Search reverse For a dual stage chain, finds it first iteration rather than second.
46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
/// <summary>
|
|
/// Generation 6 Evolution Branch Entries
|
|
/// </summary>
|
|
public static class EvolutionSet6
|
|
{
|
|
internal static readonly HashSet<int> EvosWithArg = new() {6, 8, 16, 17, 18, 19, 20, 21, 22, 29};
|
|
private const int SIZE = 6;
|
|
|
|
private static EvolutionMethod[] GetMethods(ReadOnlySpan<byte> data)
|
|
{
|
|
var evos = new EvolutionMethod[data.Length / SIZE];
|
|
for (int i = 0; i < data.Length; i += SIZE)
|
|
{
|
|
var entry = data.Slice(i, SIZE);
|
|
evos[i/SIZE] = GetMethod(entry);
|
|
}
|
|
return evos;
|
|
}
|
|
|
|
private static EvolutionMethod GetMethod(ReadOnlySpan<byte> entry)
|
|
{
|
|
var method = ReadUInt16LittleEndian(entry);
|
|
var arg = ReadUInt16LittleEndian(entry[2..]);
|
|
var species = ReadUInt16LittleEndian(entry[4..]);
|
|
|
|
// Argument is used by both Level argument and Item/Move/etc. Clear if appropriate.
|
|
var lvl = EvosWithArg.Contains(method) ? 0 : arg;
|
|
|
|
return new EvolutionMethod(method, species, argument: arg, level: (byte)lvl);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|