2020-12-25 00:36:50 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-06-27 18:06:28 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2020-12-25 00:36:50 +00:00
|
|
|
|
public static class MoveListSuggest
|
2020-06-27 18:06:28 +00:00
|
|
|
|
{
|
2020-12-25 00:36:50 +00:00
|
|
|
|
private static int[] GetSuggestedMoves(PKM pkm, IReadOnlyList<EvoCriteria>[] evoChains, MoveSourceType types, IEncounterable enc)
|
2020-06-27 18:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (pkm.IsEgg && pkm.Format <= 5) // pre relearn
|
|
|
|
|
return MoveList.GetBaseEggMoves(pkm, pkm.Species, 0, (GameVersion)pkm.Version, pkm.CurrentLevel);
|
|
|
|
|
|
2020-12-22 05:24:16 +00:00
|
|
|
|
if (types == MoveSourceType.None)
|
2020-06-27 18:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
// try to give current moves
|
|
|
|
|
if (enc.Generation <= 2)
|
|
|
|
|
{
|
|
|
|
|
var lvl = pkm.Format >= 7 ? pkm.Met_Level : pkm.CurrentLevel;
|
|
|
|
|
var ver = enc.Version;
|
|
|
|
|
return MoveLevelUp.GetEncounterMoves(enc.Species, 0, lvl, ver);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pkm.Species == enc.Species)
|
|
|
|
|
{
|
2020-12-11 04:42:30 +00:00
|
|
|
|
return MoveLevelUp.GetEncounterMoves(pkm.Species, pkm.Form, pkm.CurrentLevel, (GameVersion)pkm.Version);
|
2020-06-27 18:06:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-22 05:24:16 +00:00
|
|
|
|
return GetValidMoves(pkm, evoChains, types).Skip(1).ToArray(); // skip move 0
|
2020-06-27 18:06:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-22 05:24:16 +00:00
|
|
|
|
private static IEnumerable<int> GetValidMoves(PKM pkm, IReadOnlyList<EvoCriteria>[] evoChains, MoveSourceType types = MoveSourceType.ExternalSources, bool RemoveTransferHM = true)
|
2020-06-27 18:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
GameVersion version = (GameVersion)pkm.Version;
|
|
|
|
|
if (!pkm.IsUntraded)
|
|
|
|
|
version = GameVersion.Any;
|
2020-12-22 05:24:16 +00:00
|
|
|
|
return GetValidMoves(pkm, version, evoChains, minLvLG1: 1, minLvLG2: 1, types: types, RemoveTransferHM: RemoveTransferHM);
|
2020-06-27 18:06:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-22 05:24:16 +00:00
|
|
|
|
private static IEnumerable<int> GetValidMoves(PKM pkm, GameVersion version, IReadOnlyList<IReadOnlyList<EvoCriteria>> evoChains, int minLvLG1 = 1, int minLvLG2 = 1, MoveSourceType types = MoveSourceType.Reminder, bool RemoveTransferHM = true)
|
2020-06-27 18:06:28 +00:00
|
|
|
|
{
|
|
|
|
|
var r = new List<int> { 0 };
|
2020-12-22 05:24:16 +00:00
|
|
|
|
if (types.HasFlagFast(MoveSourceType.RelearnMoves) && pkm.Format >= 6)
|
2020-06-27 18:06:28 +00:00
|
|
|
|
r.AddRange(pkm.RelearnMoves);
|
|
|
|
|
|
2020-12-11 04:42:30 +00:00
|
|
|
|
int start = pkm.Generation;
|
2020-06-27 18:06:28 +00:00
|
|
|
|
if (start < 0)
|
|
|
|
|
start = pkm.Format; // be generous instead of returning nothing
|
|
|
|
|
if (pkm is IBattleVersion b)
|
2021-01-29 17:56:31 +00:00
|
|
|
|
start = Math.Max(0, b.GetMinGeneration());
|
2020-06-27 18:06:28 +00:00
|
|
|
|
|
|
|
|
|
for (int generation = start; generation <= pkm.Format; generation++)
|
|
|
|
|
{
|
|
|
|
|
var chain = evoChains[generation];
|
|
|
|
|
if (chain.Count == 0)
|
|
|
|
|
continue;
|
2020-12-22 05:24:16 +00:00
|
|
|
|
r.AddRange(MoveList.GetValidMoves(pkm, version, chain, generation, minLvLG1: minLvLG1, minLvLG2: minLvLG2, types: types, RemoveTransferHM: RemoveTransferHM));
|
2020-06-27 18:06:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r.Distinct();
|
|
|
|
|
}
|
2020-12-25 00:36:50 +00:00
|
|
|
|
|
|
|
|
|
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;
|
2021-01-02 22:47:39 +00:00
|
|
|
|
var enc = info.EncounterMatch;
|
2020-12-25 00:36:50 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2020-06-27 18:06:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|