PA8: more initial move mastery suggest fixes

Evolved mon's with different learnsets need to use the initial encounter data species-form rather than the most-evolved, as some can be different.
https://github.com/kwsch/PKHeX/discussions/4725#discussioncomment-15889980
This commit is contained in:
Kurt 2026-02-22 12:22:53 -06:00
parent 3fc2971df1
commit 364e014848
7 changed files with 26 additions and 22 deletions

View File

@ -129,7 +129,7 @@ public void SetMasteredFlag(Learnset learn, Learnset mastery, byte level, int in
/// <summary>
/// Sets the "mastered" move shop flag for the encounter.
/// </summary>
public void SetEncounterMasteryFlags(ReadOnlySpan<ushort> moves, Learnset mastery, byte level)
public void SetEncounterMasteryFlags(ReadOnlySpan<ushort> moves, Learnset mastery, byte metLevel, ushort alphaMove)
{
var permit = shop.Permit;
var possible = permit.RecordPermitIndexes;
@ -145,7 +145,14 @@ public void SetEncounterMasteryFlags(ReadOnlySpan<ushort> moves, Learnset master
// and it is high enough level to master it, the game will automatically
// give it the "Mastered" flag but not the "Purchased" flag
// For moves that are not in the learnset, set as mastered.
if (!mastery.TryGetLevelLearnMove(move, out var masteryLevel) || level >= masteryLevel)
if (!mastery.TryGetLevelLearnMove(move, out var masteryLevel) || metLevel >= masteryLevel)
shop.SetMasteredRecordFlag(index, true);
}
if (alphaMove != 0)
{
var index = possible.IndexOf(alphaMove);
if (index != -1)
shop.SetMasteredRecordFlag(index, true);
}
}

View File

@ -54,9 +54,9 @@ public static ModifyResult SetSuggestedMasteryData(BatchInfo info, ReadOnlySpan<
if (IsNone(propValue))
return ModifyResult.Modified;
var e = info.Legality.EncounterMatch;
if (e is IMasteryInitialMoveShop8 enc)
enc.SetInitialMastery(pk);
var enc = info.Legality.EncounterMatch;
if (enc is IMasteryInitialMoveShop8 shop)
shop.SetInitialMastery(pk, enc);
if (IsAll(propValue))
{
t.SetPurchasedFlagsAll(pk);

View File

@ -125,9 +125,7 @@ private void SetEncounterMoves(PA8 pk, byte level)
var (learn, mastery) = GetLevelUpInfo();
LoadInitialMoveset(pk, moves, learn, level);
pk.SetMoves(moves);
pk.SetEncounterMasteryFlags(moves, mastery, level);
if (pk.AlphaMove != 0)
pk.SetMasteryFlagMove(pk.AlphaMove);
pk.SetEncounterMasteryFlags(moves, mastery, level, pk.AlphaMove);
}
public void LoadInitialMoveset(PA8 pa8, Span<ushort> moves, Learnset learn, byte level)

View File

@ -133,9 +133,7 @@ private void SetEncounterMoves(PA8 pk, byte level)
var (learn, mastery) = GetLevelUpInfo();
LoadInitialMoveset(pk, moves, learn, level);
pk.SetMoves(moves);
pk.SetEncounterMasteryFlags(moves, mastery, level);
if (pk.AlphaMove != 0)
pk.SetMasteryFlagMove(pk.AlphaMove);
pk.SetEncounterMasteryFlags(moves, mastery, level, pk.AlphaMove);
}
public (Learnset Learn, Learnset Mastery) GetLevelUpInfo() => LearnSource8LA.GetLearnsetAndMastery(Species, Form);

View File

@ -10,18 +10,18 @@ public interface IMasteryInitialMoveShop8
(Learnset Learn, Learnset Mastery) GetLevelUpInfo();
void LoadInitialMoveset(PA8 pa8, Span<ushort> moves, Learnset learn, byte level);
bool IsForcedMasteryCorrect(PKM pk);
void SetInitialMastery(PKM pk)
void SetInitialMastery<T>(PKM pk, T enc) where T : ISpeciesForm
{
if (pk is PA8 pa8)
SetInitialMastery(pa8);
SetInitialMastery(pa8, enc);
}
void SetInitialMastery(PA8 pk)
void SetInitialMastery<T>(PA8 pk, T enc) where T : ISpeciesForm
{
Span<ushort> moves = stackalloc ushort[4];
var level = pk.MetLevel;
var (learn, mastery) = LearnSource8LA.GetLearnsetAndMastery(pk.Species, pk.Form);
LoadInitialMoveset(pk, moves, learn, level);
pk.SetEncounterMasteryFlags(moves, mastery, level);
var metLevel = pk.MetLevel;
var (learn, mastery) = LearnSource8LA.GetLearnsetAndMastery(enc.Species, enc.Form);
LoadInitialMoveset(pk, moves, learn, metLevel);
pk.SetEncounterMasteryFlags(moves, mastery, metLevel, pk.AlphaMove);
}
}

View File

@ -124,8 +124,8 @@ private static void ResetDataPLA(LegalityAnalysis la, IEncounterTemplate enc, PA
ResetRelearn(pa8, la);
pa8.ClearMoveShopFlags();
if (enc is IMasteryInitialMoveShop8 e)
e.SetInitialMastery(pa8);
if (enc is IMasteryInitialMoveShop8 shop)
shop.SetInitialMastery(pa8, enc);
pa8.SetMoveShopFlags(pa8);
}

View File

@ -1965,8 +1965,9 @@ private void B_MoveShop_Click(object sender, EventArgs e)
if (ModifierKeys == Keys.Shift)
{
m.ClearMoveShopFlags();
if (Legality.EncounterMatch is IMasteryInitialMoveShop8 enc)
enc.SetInitialMastery(Entity);
var enc = Legality.EncounterMatch;
if (enc is IMasteryInitialMoveShop8 shop)
shop.SetInitialMastery(Entity, enc);
m.SetMoveShopFlags(Entity);
UpdateLegality();
return;