mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-23 01:56:06 -05:00
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)
108 lines
3.6 KiB
C#
108 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Logic for getting valid movesets.
|
|
/// </summary>
|
|
public static class MoveSetApplicator
|
|
{
|
|
/// <summary>
|
|
/// Gets a moveset for the provided <see cref="PKM"/> data.
|
|
/// </summary>
|
|
/// <param name="pk">PKM to generate for</param>
|
|
/// <param name="random">Full movepool & shuffling</param>
|
|
/// <returns>4 moves</returns>
|
|
public static ushort[] GetMoveSet(this PKM pk, bool random = false)
|
|
{
|
|
var la = new LegalityAnalysis(pk);
|
|
var moves = la.GetMoveSet(random);
|
|
|
|
if (random)
|
|
return moves;
|
|
|
|
var clone = pk.Clone();
|
|
clone.SetMoves(moves);
|
|
clone.SetMaximumPPCurrent(moves);
|
|
var newLa = new LegalityAnalysis(clone);
|
|
|
|
// ReSharper disable once TailRecursiveCall
|
|
return newLa.Valid ? moves : GetMoveSet(pk, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a moveset for the provided <see cref="PKM"/> data.
|
|
/// </summary>
|
|
/// <param name="la">Precomputed optional</param>
|
|
/// <param name="random">Full movepool & shuffling</param>
|
|
/// <returns>4 moves</returns>
|
|
public static ushort[] GetMoveSet(this LegalityAnalysis la, bool random = false)
|
|
{
|
|
var m = la.GetSuggestedCurrentMoves(random ? MoveSourceType.All : MoveSourceType.Encounter);
|
|
if (random && !la.Entity.IsEgg)
|
|
Util.Shuffle(m.AsSpan());
|
|
|
|
const int count = 4;
|
|
if (m.Length > count)
|
|
return m[^count..];
|
|
Array.Resize(ref m, count);
|
|
return m;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fetches <see cref="PKM.RelearnMoves"/> based on the provided <see cref="LegalityAnalysis"/>.
|
|
/// </summary>
|
|
/// <param name="legal"><see cref="LegalityAnalysis"/> which contains parsed information pertaining to legality.</param>
|
|
/// <param name="enc">Encounter the relearn moves should be suggested for. If not provided, will use the original encounter from the analysis. </param>
|
|
/// <returns><see cref="PKM.RelearnMoves"/> best suited for the current <see cref="PKM"/> data.</returns>
|
|
public static IReadOnlyList<ushort> GetSuggestedRelearnMoves(this LegalityAnalysis legal, IEncounterTemplate? enc = null)
|
|
{
|
|
enc ??= legal.EncounterOriginal;
|
|
var m = legal.GetSuggestedRelearnMovesFromEncounter(enc);
|
|
if (m.Any(z => z != 0))
|
|
return m;
|
|
|
|
if (enc is MysteryGift or EncounterEgg)
|
|
return m;
|
|
|
|
if (enc is EncounterSlot6AO {CanDexNav: true} dn)
|
|
{
|
|
var moves = legal.Info.Moves;
|
|
for (int i = 0; i < moves.Length; i++)
|
|
{
|
|
if (!moves[i].ShouldBeInRelearnMoves())
|
|
continue;
|
|
|
|
var move = legal.Entity.GetMove(i);
|
|
if (dn.CanBeDexNavMove(move))
|
|
return new ushort[] { move, 0, 0, 0 };
|
|
}
|
|
}
|
|
|
|
if (enc is EncounterSlot8b { IsUnderground: true } ug)
|
|
{
|
|
var moves = legal.Info.Moves;
|
|
for (int i = 0; i < moves.Length; i++)
|
|
{
|
|
if (!moves[i].ShouldBeInRelearnMoves())
|
|
continue;
|
|
|
|
var move = legal.Entity.GetMove(i);
|
|
if (ug.CanBeUndergroundMove(move))
|
|
return new ushort[] { move, 0, 0, 0 };
|
|
}
|
|
|
|
if (ug.GetBaseEggMove(out var any))
|
|
return new ushort[] { any, 0, 0, 0 };
|
|
}
|
|
|
|
var encounter = EncounterSuggestion.GetSuggestedMetInfo(legal.Entity);
|
|
if (encounter is IRelearn {Relearn: {HasMoves:true} r})
|
|
return r.ToArray();
|
|
|
|
return m;
|
|
}
|
|
}
|