mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-11 07:04:16 +00:00
Move LegalityAnalysis derived movesets out of class
LegalityAnalysis just does the analysis; no need to do unnecessary suggestion logic inside the object.
This commit is contained in:
parent
749fef0ac6
commit
4d0108331a
4 changed files with 78 additions and 67 deletions
|
@ -38,7 +38,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
int[] m = la.GetSuggestedCurrentMoves(random ? MoveSourceType.All : MoveSourceType.None);
|
||||
|
||||
var learn = la.AllSuggestedMovesAndRelearn();
|
||||
var learn = la.GetSuggestedMovesAndRelearn();
|
||||
if (!m.All(z => learn.Contains(z)))
|
||||
m = m.Intersect(learn).ToArray();
|
||||
|
||||
|
|
|
@ -65,29 +65,6 @@ namespace PKHeX.Core
|
|||
/// <returns>Single line string</returns>
|
||||
public string Report(bool verbose = false) => verbose ? GetVerboseLegalityReport() : GetLegalityReport();
|
||||
|
||||
private IEnumerable<int> AllSuggestedMoves
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Parsed)
|
||||
return new int[4];
|
||||
return _allSuggestedMoves ??= GetSuggestedCurrentMoves();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<int> AllSuggestedRelearnMoves
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Parsed)
|
||||
return new int[4];
|
||||
return _allSuggestedRelearnMoves ??= MoveList.GetValidRelearn(pkm, Info.EncounterMatch.Species, Info.EncounterMatch.Form, (GameVersion)pkm.Version).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private int[]? _allSuggestedMoves, _allSuggestedRelearnMoves;
|
||||
public int[] AllSuggestedMovesAndRelearn() => AllSuggestedMoves.Concat(AllSuggestedRelearnMoves).ToArray();
|
||||
|
||||
private string EncounterName
|
||||
{
|
||||
get
|
||||
|
@ -447,44 +424,5 @@ namespace PKHeX.Core
|
|||
|
||||
return GetLegalityReport() + string.Join(Environment.NewLine, lines);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current <see cref="PKM.RelearnMoves"/> array of four moves that might be legal.
|
||||
/// </summary>
|
||||
public IReadOnlyList<int> GetSuggestedRelearnMovesFromEncounter()
|
||||
{
|
||||
var parsed = VerifyRelearnMoves.GetSuggestedRelearn(pkm, Info.EncounterOriginal, Info.Relearn);
|
||||
if (parsed.Count == 0) // Always true for Origins < 6 and encounters without relearn permitted.
|
||||
return new int[4];
|
||||
|
||||
if (!EncounterMatch.EggEncounter)
|
||||
return parsed;
|
||||
|
||||
List<int> window = new(parsed.Where(z => z != 0));
|
||||
window.AddRange(pkm.Moves.Where((_, i) => Info.Moves[i].ShouldBeInRelearnMoves()));
|
||||
window = window.Distinct().ToList();
|
||||
int[] moves = new int[4];
|
||||
int start = Math.Max(0, window.Count - 4);
|
||||
int count = Math.Min(4, window.Count);
|
||||
window.CopyTo(start, moves, 0, count);
|
||||
return moves;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets four moves which can be learned depending on the input arguments.
|
||||
/// </summary>
|
||||
/// <param name="types">Allowed move sources for populating the result array</param>
|
||||
public int[] GetSuggestedCurrentMoves(MoveSourceType types = MoveSourceType.All)
|
||||
{
|
||||
if (!Parsed)
|
||||
return new int[4];
|
||||
if (pkm.IsEgg && pkm.Format >= 6)
|
||||
return pkm.RelearnMoves;
|
||||
|
||||
if (pkm.IsEgg)
|
||||
types = types.ClearNonEggSources();
|
||||
|
||||
return MoveListSuggest.GetSuggestedMoves(pkm, Info.EvoChainsAllGens, types, EncounterOriginal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
internal static class MoveListSuggest
|
||||
public static class MoveListSuggest
|
||||
{
|
||||
internal static int[] GetSuggestedMoves(PKM pkm, IReadOnlyList<EvoCriteria>[] evoChains, MoveSourceType types, IEncounterable enc)
|
||||
private static int[] GetSuggestedMoves(PKM pkm, IReadOnlyList<EvoCriteria>[] evoChains, MoveSourceType types, IEncounterable enc)
|
||||
{
|
||||
if (pkm.IsEgg && pkm.Format <= 5) // pre relearn
|
||||
return MoveList.GetBaseEggMoves(pkm, pkm.Species, 0, (GameVersion)pkm.Version, pkm.CurrentLevel);
|
||||
|
@ -59,5 +60,77 @@ namespace PKHeX.Core
|
|||
|
||||
return r.Distinct();
|
||||
}
|
||||
|
||||
private static IEnumerable<int> AllSuggestedMoves(this LegalityAnalysis analysis)
|
||||
{
|
||||
if (!analysis.Parsed)
|
||||
return new int[4];
|
||||
return analysis.GetSuggestedCurrentMoves();
|
||||
}
|
||||
|
||||
private static IEnumerable<int> AllSuggestedRelearnMoves(this LegalityAnalysis analysis)
|
||||
{
|
||||
if (!analysis.Parsed)
|
||||
return new int[4];
|
||||
var pkm = analysis.pkm;
|
||||
var enc = analysis.EncounterMatch;
|
||||
return MoveList.GetValidRelearn(pkm, enc.Species, enc.Form, (GameVersion)pkm.Version).ToArray();
|
||||
}
|
||||
|
||||
public static int[] GetSuggestedMovesAndRelearn(this LegalityAnalysis analysis)
|
||||
{
|
||||
if (!analysis.Parsed)
|
||||
return new int[4];
|
||||
return analysis.AllSuggestedMoves().Concat(analysis.AllSuggestedRelearnMoves()).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets four moves which can be learned depending on the input arguments.
|
||||
/// </summary>
|
||||
/// <param name="analysis">Parse information to generate a moveset for.</param>
|
||||
/// <param name="types">Allowed move sources for populating the result array</param>
|
||||
public static int[] GetSuggestedCurrentMoves(this LegalityAnalysis analysis, MoveSourceType types = MoveSourceType.All)
|
||||
{
|
||||
if (!analysis.Parsed)
|
||||
return new int[4];
|
||||
var pkm = analysis.pkm;
|
||||
if (pkm.IsEgg && pkm.Format >= 6)
|
||||
return pkm.RelearnMoves;
|
||||
|
||||
if (pkm.IsEgg)
|
||||
types = types.ClearNonEggSources();
|
||||
|
||||
var info = analysis.Info;
|
||||
return GetSuggestedMoves(pkm, info.EvoChainsAllGens, types, info.EncounterOriginal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current <see cref="PKM.RelearnMoves"/> array of four moves that might be legal.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<int> GetSuggestedRelearnMovesFromEncounter(this LegalityAnalysis analysis)
|
||||
{
|
||||
var info = analysis.Info;
|
||||
if (info.Generation < 6)
|
||||
return new int[4];
|
||||
|
||||
var pkm = analysis.pkm;
|
||||
var enc = info.EncounterOriginal;
|
||||
var parsed = VerifyRelearnMoves.GetSuggestedRelearn(pkm, enc, info.Relearn);
|
||||
if (parsed.Count == 0) // Always true for Origins < 6 and encounters without relearn permitted.
|
||||
return new int[4];
|
||||
|
||||
// Invalid encounters won't be recognized as an EncounterEgg; check if it *should* be a bred egg.
|
||||
if (!enc.EggEncounter)
|
||||
return parsed;
|
||||
|
||||
List<int> window = new(parsed.Where(z => z != 0));
|
||||
window.AddRange(pkm.Moves.Where((_, i) => info.Moves[i].ShouldBeInRelearnMoves()));
|
||||
window = window.Distinct().ToList();
|
||||
int[] moves = new int[4];
|
||||
int start = Math.Max(0, window.Count - 4);
|
||||
int count = Math.Min(4, window.Count);
|
||||
window.CopyTo(start, moves, 0, count);
|
||||
return moves;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -336,7 +336,7 @@ namespace PKHeX.WinForms.Controls
|
|||
return;
|
||||
// Resort moves
|
||||
FieldsLoaded = false;
|
||||
LegalMoveSource.ReloadMoves(Legality.AllSuggestedMovesAndRelearn());
|
||||
LegalMoveSource.ReloadMoves(Legality.GetSuggestedMovesAndRelearn());
|
||||
FieldsLoaded = true;
|
||||
LegalityChanged?.Invoke(Legality.Valid, EventArgs.Empty);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue