Misc tweaks

do things a little more directly

blank ctor: we already have the ctor, just invoke it ourselves instead of having to rediscover it
This commit is contained in:
Kurt 2023-04-10 01:26:54 -07:00
parent ebd061dcd9
commit 4caf749064
9 changed files with 34 additions and 14 deletions

View file

@ -54,7 +54,7 @@ public sealed record EncounterSlot6AO : EncounterSlot
{
var et = EvolutionTree.Evolves6;
var baby = et.GetBaseSpeciesForm(Species, Form);
return MoveEgg.GetEggMoves(6, baby.Species, baby.Form, Version);
return LearnSource6AO.Instance.GetEggMoves(baby.Species, baby.Form);
}
public bool CanBeDexNavMove(ushort move)

View file

@ -165,7 +165,7 @@ public static class MoveBreed2
if (baseEgg.IndexOf(move) != -1)
possible[i] |= 1 << (int)Base;
if (inheritLevelUp && learn.GetLevelLearnMove(move) != -1)
if (inheritLevelUp && learn.GetIsLearn(move))
possible[i] |= 1 << (int)ParentLevelUp;
if (eggMoves.Contains(move))

View file

@ -166,7 +166,7 @@ public static class MoveBreed3
if (baseEgg.IndexOf(move) != -1)
possible[i] |= 1 << (int)Base;
if (inheritLevelUp && learn.GetLevelLearnMove(move) != -1)
if (inheritLevelUp && learn.GetIsLearn(move))
possible[i] |= 1 << (int)ParentLevelUp;
if (eggMoves.Contains(move))

View file

@ -162,7 +162,7 @@ public static class MoveBreed4
if (baseEgg.IndexOf(move) != -1)
possible[i] |= 1 << (int)Base;
if (inheritLevelUp && learn.GetLevelLearnMove(move) != -1)
if (inheritLevelUp && learn.GetIsLearn(move))
possible[i] |= 1 << (int)ParentLevelUp;
if (eggMoves.Contains(move))

View file

@ -157,7 +157,7 @@ public static class MoveBreed5
if (baseEgg.IndexOf(move) != -1)
possible[i] |= 1 << (int)Base;
if (inheritLevelUp && learn.GetLevelLearnMove(move) != -1)
if (inheritLevelUp && learn.GetIsLearn(move))
possible[i] |= 1 << (int)ParentLevelUp;
if (eggMoves.Contains(move))

View file

@ -154,7 +154,7 @@ public static class MoveBreed6
if (baseEgg.IndexOf(move) != -1)
possible[i] |= 1 << (int)Base;
if (inheritLevelUp && learn.GetLevelLearnMove(move) != -1)
if (inheritLevelUp && learn.GetIsLearn(move))
possible[i] |= 1 << (int)ParentLevelUp;
if (eggMoves.Contains(move))

View file

@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Reflection;
namespace PKHeX.Core;
@ -15,13 +14,34 @@ public static class EntityBlank
/// <param name="type">Type of <see cref="PKM"/> instance desired.</param>
/// <returns>New instance of a blank <see cref="PKM"/> object.</returns>
public static PKM GetBlank(Type type)
{
var typeInfo = type.GetTypeInfo();
return GetBlank(typeInfo);
}
/// <inheritdoc cref="GetBlank(Type)"/>
public static PKM GetBlank(TypeInfo type)
{
// Not all derived types have a parameter-less constructor, so find the minimal constructor and use that.
var constructors = type.GetTypeInfo().DeclaredConstructors.Where(z => !z.IsStatic);
var argCount = constructors.Min(z => z.GetParameters().Length);
var pk = Activator.CreateInstance(type, new object[argCount]) as PKM;
ArgumentNullException.ThrowIfNull(pk);
return pk;
ConstructorInfo? info = null;
int count = int.MaxValue;
foreach (var ctor in type.DeclaredConstructors)
{
if (ctor.IsStatic)
continue;
var parameters = ctor.GetParameters();
int length = parameters.Length;
if (length >= count)
continue;
count = length;
info = ctor;
}
ArgumentNullException.ThrowIfNull(info);
var result = info.Invoke(new object?[count]);
if (result is not PKM x)
throw new InvalidCastException($"Unable to cast {result} to {typeof(PKM)}");
return x;
}
public static PKM GetBlank(int gen, GameVersion ver) => gen switch

View file

@ -19,7 +19,7 @@ public abstract class BulkStorage : SaveFile
protected readonly int SlotsPerBox;
protected internal override string ShortSummary => $"{Checksums.CRC16Invert(new ReadOnlySpan<byte>(Data, Box, Data.Length - Box)):X4}";
protected internal override string ShortSummary => $"{Checksums.CRC16Invert(Data.AsSpan(Box)):X4}";
public override string Extension => ".bin";
public sealed override bool ChecksumsValid => true;
public sealed override string ChecksumInfo => "No Info.";

View file

@ -18,7 +18,7 @@ public static class TempTests
[InlineData(Spiritomb, FoulPlay)]
public static void CanLearnEggMoveBDSP(Species species, Move move)
{
MoveEgg.GetEggMoves(8, (ushort)species, 0, GameVersion.BD).Contains((ushort)move).Should().BeFalse();
LearnSource8BDSP.Instance.GetEggMoves((ushort)species, 0).Contains((ushort)move).Should().BeFalse();
var pb8 = new PB8 { Species = (ushort)species };
var encs = EncounterMovesetGenerator.GenerateEncounters(pb8, new[] { (ushort)move }, GameVersion.BD);