Extract logic to set initial mastery move flags

Are we done yet
This commit is contained in:
Kurt 2022-05-08 10:28:22 -07:00
parent 178e5e8bc5
commit 8c4db878dd
5 changed files with 63 additions and 14 deletions

View file

@ -33,12 +33,17 @@ namespace PKHeX.Core
if (pk is not IMoveShop8Mastery t)
return ModifyResult.Invalid;
t.ClearMoveShopFlags();
if (IsNone(propValue))
return ModifyResult.Modified;
var e = info.Legality.EncounterMatch;
if (e is IMasteryInitialMoveShop8 enc)
enc.SetInitialMastery(pk);
if (IsAll(propValue))
t.SetMoveShopFlagsAll(pk);
else if (!IsNone(propValue))
t.SetMoveShopFlags(pk);
else
t.ClearMoveShopFlags();
t.SetMoveShopFlags(pk);
return ModifyResult.Modified;
}

View file

@ -52,9 +52,15 @@ public sealed record EncounterSlot8a : EncounterSlot, IAlpha, IMasteryInitialMov
{
var pa8 = (PA8)pk;
Span<int> moves = stackalloc int[4];
var index = PersonalTable.LA.GetFormIndex(Species, Form);
var mastery = Legal.MasteryLA[index];
var learn = Legal.LevelUpLA[index];
var (learn, mastery) = GetLevelUpInfo();
LoadInitialMoveset(pa8, moves, learn, level);
pk.SetMoves(moves);
pk.SetMaximumPPCurrent(moves);
pa8.SetEncounterMasteryFlags(moves, mastery, level);
}
public void LoadInitialMoveset(PA8 pa8, Span<int> moves, Learnset learn, int level)
{
if (pa8.AlphaMove != 0)
{
moves[0] = pa8.AlphaMove;
@ -64,9 +70,14 @@ public sealed record EncounterSlot8a : EncounterSlot, IAlpha, IMasteryInitialMov
{
learn.SetEncounterMoves(level, moves);
}
pk.SetMoves(moves);
pk.SetMaximumPPCurrent(moves);
pa8.SetEncounterMasteryFlags(moves, mastery, level);
}
public (Learnset Learn, Learnset Mastery) GetLevelUpInfo()
{
var index = PersonalTable.LA.GetFormIndex(Species, Form);
var learn = Legal.LevelUpLA[index];
var mastery = Legal.MasteryLA[index];
return (learn, mastery);
}
protected override void SetFormatSpecificData(PKM pk)

View file

@ -143,9 +143,23 @@ public sealed record EncounterStatic8a(GameVersion Version) : EncounterStatic(Ve
{
var pa8 = (PA8)pk;
Span<int> moves = stackalloc int[4];
var (learn, mastery) = GetLevelUpInfo();
LoadInitialMoveset(pa8, moves, learn, level);
pk.SetMoves(moves);
pk.SetMaximumPPCurrent(moves);
pa8.SetEncounterMasteryFlags(moves, mastery, level);
}
public (Learnset Learn, Learnset Mastery) GetLevelUpInfo()
{
var index = PersonalTable.LA.GetFormIndex(Species, Form);
var mastery = Legal.MasteryLA[index];
var learn = Legal.LevelUpLA[index];
var mastery = Legal.MasteryLA[index];
return (learn, mastery);
}
public void LoadInitialMoveset(PA8 pa8, Span<int> moves, Learnset learn, int level)
{
if (IsAlpha && Moves.Count != 0)
{
moves = (int[])Moves;
@ -155,9 +169,6 @@ public sealed record EncounterStatic8a(GameVersion Version) : EncounterStatic(Ve
{
learn.SetEncounterMoves(level, moves);
}
pk.SetMoves(moves);
pk.SetMaximumPPCurrent(moves);
pa8.SetEncounterMasteryFlags(moves, mastery, level);
}
private OverworldParam8a GetParams()

View file

@ -1,6 +1,25 @@
namespace PKHeX.Core;
using System;
namespace PKHeX.Core;
public interface IMasteryInitialMoveShop8
{
(Learnset Learn, Learnset Mastery) GetLevelUpInfo();
void LoadInitialMoveset(PA8 pa8, Span<int> moves, Learnset learn, int level);
bool IsForcedMasteryCorrect(PKM pkm);
}
public static class MasteryInitialMoveShop8Extensions
{
public static void SetInitialMastery(this IMasteryInitialMoveShop8 enc, PKM pk)
{
if (pk is PA8 pa8)
{
Span<int> moves = stackalloc int[4];
var level = pa8.Met_Level;
var (learn, mastery) = enc.GetLevelUpInfo();
enc.LoadInitialMoveset(pa8, moves, learn, level);
pa8.SetEncounterMasteryFlags(moves, mastery, level);
}
}
}

View file

@ -1787,6 +1787,9 @@ namespace PKHeX.WinForms.Controls
if (ModifierKeys == Keys.Shift)
{
m.ClearMoveShopFlags();
if (Legality.EncounterMatch is IMasteryInitialMoveShop8 enc)
enc.SetInitialMastery(Entity);
m.SetMoveShopFlags(Entity);
UpdateLegality();
return;