Allow game bug for trade evo's & plus moves

This commit is contained in:
Kurt 2025-10-29 17:40:13 -05:00
parent 702829bb20
commit d5314a00f5
4 changed files with 45 additions and 8 deletions

View File

@ -148,9 +148,9 @@ private void CheckFlagsPlus(LegalityAnalysis la, PA9 pk)
la.AddLine(GetInvalid(PlusMoveCountInvalid));
// Check for all required indexes.
var (_, plus) = LearnSource9ZA.GetLearnsetAndPlus(pk.Species, pk.Form);
var (learn, plus) = LearnSource9ZA.GetLearnsetAndPlus(pk.Species, pk.Form);
var currentLevel = pk.CurrentLevel;
CheckPlusMoveFlags(la, pk, plus, currentLevel, permit);
CheckPlusMoveFlags(la, pk, permit, plus, currentLevel);
// Check for indexes set that cannot be set via TM or NPC.
@ -167,7 +167,7 @@ private void CheckFlagsPlus(LegalityAnalysis la, PA9 pk)
la.AddLine(msg);
}
private void CheckPlusMoveFlags<T>(LegalityAnalysis la, T pk, Learnset plus, byte currentLevel, IPermitPlus permit) where T : IPlusRecord
private void CheckPlusMoveFlags<T>(LegalityAnalysis la, T pk, IPermitPlus permit, Learnset plus, byte currentLevel) where T : IPlusRecord
{
var levels = plus.GetAllLevels();
var moves = plus.GetAllMoves();
@ -182,11 +182,48 @@ private void CheckFlagsPlus(LegalityAnalysis la, PA9 pk)
if (index == -1)
throw new IndexOutOfRangeException("Unexpected learn move index, not in Plus moves?");
if (!pk.GetMovePlusFlag(index))
la.AddLine(GetInvalid(PlusMoveSufficientLevelMissing_0, move, level));
if (pk.GetMovePlusFlag(index))
continue; // All good, flagged.
// Trade evolutions forget to set the Plus flags, unlike triggered evolutions.
// If the move is not present as a previous-evolution learnset move, and the head species is a Trade evo, skip the error.
// Assume the best case -- evolved at current level, so none would get set.
if (IsTradeEvoSkip(la.Info.EvoChainsAllGens.Gen9a, move))
continue;
la.AddLine(GetInvalid(PlusMoveSufficientLevelMissing_0, move, level));
}
}
private static bool IsTradeEvoSkip(ReadOnlySpan<EvoCriteria> evos, ushort move)
{
if (evos.Length <= 1)
return false;
if (!evos[0].Method.IsTrade())
return false;
// Check if the pre-evolution could have learned it before evolving.
for (int i = 1; i < evos.Length; i++)
{
var evo = evos[i];
var (_, plus) = LearnSource9ZA.GetLearnsetAndPlus(evo.Species, evo.Form);
var moves = plus.GetAllMoves();
var index = moves.IndexOf(move);
if (index == -1)
continue; // can't learn
// if the evo must have traversed this level range (and not the head's level range), then it must have been flagged.
var levels = plus.GetAllLevels();
var plusLevel = levels[index];
var headLevel = evos[0].LevelMin;
if (plusLevel <= headLevel)
return false;
}
return true;
}
private const ushort MultipleInvalidPlusMoves = ushort.MaxValue;
private static ushort GetInvalidPlusMove<T>(T pk, int maxIndex, IPermitPlus permit, ReadOnlySpan<EvoCriteria> evos)

View File

@ -54,7 +54,7 @@ public static bool IsReplace(ReadOnlySpan<char> name, LanguageID language)
}
/// <summary>
/// Gets the replacement name for <see cref="EntityContext.Gen8"/> in the given language.
/// Gets the replacement name for <see cref="EntityContext.Gen8a"/> in the given language.
/// </summary>
public static string GetName(LanguageID language) => language switch
{

View File

@ -53,7 +53,7 @@ public static bool IsReplace(ReadOnlySpan<char> name, LanguageID language)
}
/// <summary>
/// Gets the replacement name for <see cref="EntityContext.Gen9"/> in the given language.
/// Gets the replacement name for <see cref="EntityContext.Gen9a"/> in the given language.
/// </summary>
public static string GetName(LanguageID language) => language switch
{

View File

@ -16,7 +16,7 @@ public static int GetStringLength(ReadOnlySpan<byte> buffer)
}
/// <summary>
/// Returns a 8-bit aligned index of the terminator.
/// Returns an 8-bit aligned index of the terminator.
/// </summary>
/// <param name="buffer">Backing buffer of the string.</param>
/// <returns>Index of the terminator, or -1 if not found.</returns>