mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-04-09 10:56:04 -05:00
-288 KB (-31%) across lvlmove/eggmove/evolve binaries redesign the levelup bins: - be moves_levels rather than the "official" -1 stop of the past era. - gen1/2 reformatted from byte,byte[] to ^ to skip initialization work redesign the eggmove bins: - be simply moves[], rather than the "official" -1 stop of the past era; now is just a struct to keep the array readonly with no further allocation. - same for gen2 skipping initialization byte[]->ushort[] - for gen7/8 formtable indexed, just use the personal table indexing style of SV. added a 16-bit version of BinLinkerAccessor as start/end offsets of <65KB files are always 16bit. Saves a fair bit of space in eggmoves/evo where there's often 0 entries for a species-form. Obviously binlinker16 is an unofficial format, but there's no need to replicate official serialization formats if we instead use a universal & maintainable alternative. Plus they don't even use BinLinker across all their games. Adds a debug BinLinkerWriter because I'm tired of digging up the zipping implementation :)
65 lines
2.7 KiB
C#
65 lines
2.7 KiB
C#
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using static PKHeX.Core.LearnMethod;
|
|
using static PKHeX.Core.LearnEnvironment;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
public sealed class LearnSource2Stadium : ILearnSource<PersonalInfo2>, IEggSource
|
|
{
|
|
public static readonly LearnSource2Stadium Instance = new();
|
|
private static readonly LearnsetStadium[] Learnsets = LearnsetStadium.GetArray(BinLinkerAccessor16.Get(Util.GetBinaryResource("reminder_stad2.pkl"), "s2"u8));
|
|
|
|
private const int MaxSpecies = Legal.MaxSpeciesID_2;
|
|
private const LearnEnvironment Game = Stadium2;
|
|
public LearnEnvironment Environment => Game;
|
|
|
|
public Learnset GetLearnset(ushort species, byte form) => throw new InvalidOperationException("Not supported.");
|
|
public bool TryGetPersonal(ushort species, byte form, [NotNullWhen(true)] out PersonalInfo2? pi) => throw new InvalidOperationException("Not supported.");
|
|
public bool GetIsEggMove(ushort species, byte form, ushort move) => false;
|
|
public ReadOnlySpan<ushort> GetEggMoves(ushort species, byte form) => [];
|
|
private static bool IsSpeciesInGame(ushort species, byte form) => form is 0 && species is <= MaxSpecies and not 0;
|
|
public LearnsetStadium GetLearnsetStadium(ushort species, byte form) => Learnsets[species < Learnsets.Length ? species : 0];
|
|
|
|
public MoveLearnInfo GetCanLearn(PKM pk, PersonalInfo2 pi, EvoCriteria evo, ushort move, MoveSourceType types = MoveSourceType.All, LearnOption option = LearnOption.Current)
|
|
{
|
|
return GetCanRelearn(evo, move, types);
|
|
}
|
|
|
|
public MoveLearnInfo GetCanRelearn(EvoCriteria evo, ushort move, MoveSourceType types)
|
|
{
|
|
if (move > Legal.MaxMoveID_2) // byte
|
|
return default;
|
|
|
|
if (types.HasFlag(MoveSourceType.LevelUp))
|
|
{
|
|
var learn = GetLearnsetStadium(evo.Species, evo.Form);
|
|
if (learn.CanRelearn(move, evo.LevelMax, out var level))
|
|
return new(LevelUp, Game, level);
|
|
}
|
|
|
|
return default;
|
|
}
|
|
|
|
public void GetAllMoves(Span<bool> result, PKM pk, EvoCriteria evo, MoveSourceType types = MoveSourceType.All)
|
|
{
|
|
if (!IsSpeciesInGame(evo.Species, evo.Form))
|
|
return;
|
|
|
|
if (!types.HasFlag(MoveSourceType.LevelUp))
|
|
return;
|
|
|
|
bool removeVC = pk.Format == 1 || pk.VC1;
|
|
var learn = GetLearnsetStadium(evo.Species, evo.Form);
|
|
var span = learn.GetMoveRange(evo.LevelMax);
|
|
foreach (var tuple in span)
|
|
{
|
|
if (!tuple.Source.IsAbleToBeRelearned())
|
|
continue;
|
|
var move = tuple.Move;
|
|
if (!removeVC || move <= Legal.MaxMoveID_1)
|
|
result[move] = true;
|
|
}
|
|
}
|
|
}
|