PKHeX/PKHeX.Core/Legality/Structures/Moveset.cs
Kurt 88830e0d00
Update from .NET Framework 4.6 to .NET 7 (#3729)
Updates from net46->net7, dropping support for mono in favor of using the latest runtime (along with the performance/API improvements). Releases will be posted as 64bit only for now.

Refactors a good amount of internal API methods to be more performant and more customizable for future updates & fixes.

Adds functionality for Batch Editor commands to `>`, `<` and <=/>=

TID/SID properties renamed to TID16/SID16 for clarity; other properties exposed for Gen7 / display variants.

Main window has a new layout to account for DPI scaling (8 point grid)

Fixed: Tatsugiri and Paldean Tauros now output Showdown form names as Showdown expects
Changed: Gen9 species now interact based on the confirmed National Dex IDs (closes #3724)
Fixed: Pokedex set all no longer clears species with unavailable non-base forms (closes #3720)
Changed: Hyper Training suggestions now apply for level 50 in SV. (closes #3714)
Fixed: B2/W2 hatched egg met locations exclusive to specific versions are now explicitly checked (closes #3691)
Added: Properties for ribbon/mark count (closes #3659)
Fixed: Traded SV eggs are now checked correctly (closes #3692)
2023-01-21 20:02:33 -08:00

89 lines
2.4 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(ReadOnlySpan<ushort> moves, 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 (moves.Contains(move))
flags |= 1 << i;
}
return flags;
}
}