mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-12 23:37:07 +00:00
0626b0c29b
* Initial bred moveset validation logic Unpeel the inheritance via recursion and permitted moves * Volt tackle considerations * Optimize out empty slot skips * Add tests, fix off-by-one's * Require all base moves if empty slot in moveset * Add test to prove failure per Anubis' provided test * Tweak enum labels for easier debugging When two enums share the same underlying value, the ToString/name of the value may be either of the two (or the last defined one, in my debugging). Just give it a separate magic value. * Fix recursion oopsie Also check for scenario where no-base-moves but not enough moves to push base moves out * Add Crystal tutor checks * Add specialized gen2 verification method Game loops through father's moves and pushes in one iteration, rather than checking by type. * Add another case with returning base move * Add push-out requirement for re-added base moves * Minor tweaks Condense tests, fix another off-by-one noticed when creating tests * Disallow inherited parent levelup moves Disallow volt tackle on Gen2/R/S * Split MoveBreed into generation specific classes Gen2 behaves slightly different from Gen3/4, which behaves slightly different from Gen5... and Gen6 behaves differently too. Add some xmldoc as the api is starting to solidify * Add method overload that returns the parse Verify that the parse order is as expected * Add reordering suggestion logic Try sorting first, then go nuclear with rebuilding. * Return base moves if complete fail * Set base moves when generating eggs, only. * Use breed logic to check for egg ordering legality Don't bother helping for split-breed species
136 lines
5.9 KiB
C#
136 lines
5.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
public static class MoveListSuggest
|
|
{
|
|
private static int[] GetSuggestedMoves(PKM pkm, IReadOnlyList<IReadOnlyList<EvoCriteria>> evoChains, MoveSourceType types, IEncounterTemplate enc)
|
|
{
|
|
if (pkm.IsEgg && pkm.Format <= 5) // pre relearn
|
|
return MoveList.GetBaseEggMoves(pkm, pkm.Species, 0, (GameVersion)pkm.Version, pkm.CurrentLevel);
|
|
|
|
if (types != MoveSourceType.None)
|
|
return GetValidMoves(pkm, evoChains, types).Skip(1).ToArray(); // skip move 0
|
|
|
|
// 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)
|
|
{
|
|
return MoveLevelUp.GetEncounterMoves(pkm.Species, pkm.Form, pkm.CurrentLevel, (GameVersion)pkm.Version);
|
|
}
|
|
|
|
return GetValidMoves(pkm, evoChains, types).Skip(1).ToArray(); // skip move 0
|
|
}
|
|
|
|
private static IEnumerable<int> GetValidMoves(PKM pkm, IReadOnlyList<IReadOnlyList<EvoCriteria>> evoChains, MoveSourceType types = MoveSourceType.ExternalSources, bool RemoveTransferHM = true)
|
|
{
|
|
GameVersion version = (GameVersion)pkm.Version;
|
|
if (!pkm.IsUntraded)
|
|
version = GameVersion.Any;
|
|
return GetValidMoves(pkm, version, evoChains, minLvLG1: 1, minLvLG2: 1, types: types, RemoveTransferHM: RemoveTransferHM);
|
|
}
|
|
|
|
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)
|
|
{
|
|
var r = new List<int> { 0 };
|
|
if (types.HasFlagFast(MoveSourceType.RelearnMoves) && pkm.Format >= 6)
|
|
r.AddRange(pkm.RelearnMoves);
|
|
|
|
int start = pkm.Generation;
|
|
if (start < 0)
|
|
start = pkm.Format; // be generous instead of returning nothing
|
|
if (pkm is IBattleVersion b)
|
|
start = Math.Max(0, b.GetMinGeneration());
|
|
|
|
for (int generation = start; generation <= pkm.Format; generation++)
|
|
{
|
|
var chain = evoChains[generation];
|
|
if (chain.Count == 0)
|
|
continue;
|
|
r.AddRange(MoveList.GetValidMoves(pkm, version, chain, generation, minLvLG1: minLvLG1, minLvLG2: minLvLG2, types: types, RemoveTransferHM: RemoveTransferHM));
|
|
}
|
|
|
|
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>
|
|
/// <remarks>Returns an empty array if it should not have any moves. Use <see cref="GetSuggestedRelearnMovesFromEncounter"/> instead of calling directly.</remarks>
|
|
public static IReadOnlyList<int> GetSuggestedRelearn(this IEncounterable enc, PKM pkm)
|
|
{
|
|
if (enc.Generation < 6 || pkm is IBattleVersion { BattleVersion: not 0 })
|
|
return Empty;
|
|
|
|
// Invalid encounters won't be recognized as an EncounterEgg; check if it *should* be a bred egg.
|
|
return enc switch
|
|
{
|
|
IRelearn s when s.Relearn.Count > 0 => s.Relearn,
|
|
EncounterEgg or EncounterInvalid { EggEncounter: true } => MoveBreed.GetExpectedMoves(pkm.RelearnMoves, enc),
|
|
_ => Empty,
|
|
};
|
|
}
|
|
|
|
private static readonly IReadOnlyList<int> Empty = new int[4];
|
|
|
|
/// <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;
|
|
return info.Generation < 6 ? Empty : info.EncounterOriginal.GetSuggestedRelearn(analysis.pkm);
|
|
}
|
|
}
|
|
}
|