mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-22 02:13:10 +00:00
3c232505e5
In this pull request I've changed a ton of method signatures to reflect the more-narrow types of Species, Move# and Form; additionally, I've narrowed other large collections that stored lists of species / permitted values, and reworked them to be more performant with the latest API spaghetti that PKHeX provides. Roamer met locations, usually in a range of [max-min]<64, can be quickly checked using a bitflag operation on a UInt64. Other collections (like "Is this from Colosseum or XD") were eliminated -- shadow state is not transferred COLO<->XD, so having a Shadow ID or matching the met location from a gift/wild encounter is a sufficient check for "originated in XD".
89 lines
2.3 KiB
C#
89 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Set of 4 moves that are in a list of moves.
|
|
/// </summary>
|
|
public readonly record struct Moveset(ushort Move1, ushort Move2 = 0, ushort Move3 = 0, ushort Move4 = 0)
|
|
{
|
|
public bool HasMoves => Move1 != 0;
|
|
|
|
public bool Contains(ushort move) => move == Move1 || move == Move2 || move == Move3 || move == Move4;
|
|
public bool AnyAbove(int max) => Move1 > max || Move2 > max || Move3 > max || Move4 > max;
|
|
|
|
public ushort[] ToArray() => new[] { Move1, Move2, Move3, Move4 };
|
|
|
|
public void CopyTo(Span<ushort> moves)
|
|
{
|
|
moves[3] = Move4;
|
|
moves[2] = Move3;
|
|
moves[1] = Move2;
|
|
moves[0] = Move1;
|
|
}
|
|
|
|
public bool ContainsAny(ReadOnlySpan<ushort> moves)
|
|
{
|
|
foreach (var move in moves)
|
|
{
|
|
if (Contains(move))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool ContainsAll(ReadOnlySpan<ushort> needs)
|
|
{
|
|
foreach (var move in needs)
|
|
{
|
|
if (!Contains(move))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public string GetMovesetLine(IReadOnlyList<string> names, string split = " / ")
|
|
{
|
|
var sb = new StringBuilder(128);
|
|
sb.Append(names[Move1]);
|
|
if (Move2 != 0)
|
|
{
|
|
sb.Append(split).Append(names[Move2]);
|
|
if (Move3 != 0)
|
|
{
|
|
sb.Append(split).Append(names[Move3]);
|
|
if (Move4 != 0)
|
|
sb.Append(split).Append(names[Move4]);
|
|
}
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
|
|
public int BitOverlap(ReadOnlySpan<ushort> span)
|
|
{
|
|
// Flag each present index; having all moves will have all bitflags.
|
|
int flags = 0;
|
|
for (var i = 0; i < span.Length; i++)
|
|
{
|
|
var move = span[i];
|
|
if (Contains(move))
|
|
flags |= 1 << i;
|
|
}
|
|
return flags;
|
|
}
|
|
|
|
public static int BitOverlap(Span<ushort> moves, Span<ushort> span)
|
|
{
|
|
// Flag each present index; having all moves will have all bitflags.
|
|
int flags = 0;
|
|
for (var i = 0; i < span.Length; i++)
|
|
{
|
|
var move = span[i];
|
|
if (moves.Contains(move))
|
|
flags |= 1 << i;
|
|
}
|
|
return flags;
|
|
}
|
|
}
|