Add bypass for alpha move purchased

ty @Atrius97 for finally nailing the repro on this

Co-Authored-By: Atrius97 <39707481+Atrius97@users.noreply.github.com>
Co-Authored-By: Lusamine <30205550+Lusamine@users.noreply.github.com>
This commit is contained in:
Kurt 2022-05-07 13:48:47 -07:00
parent 178069f889
commit a9443be8fa
4 changed files with 54 additions and 11 deletions

View file

@ -141,15 +141,19 @@ public sealed record EncounterSlot8a : EncounterSlot, IAlpha, IMasteryInitialMov
if (pkm is not IMoveShop8Mastery p)
return true; // Can't check.
Span<int> moves = stackalloc int[4];
bool allowAlphaPurchaseBug = Area.Type is not SlotType.OverworldMMO; // Everything else Alpha is pre-1.1
var level = pkm.Met_Level;
var index = PersonalTable.LA.GetFormIndex(Species, Form);
var mastery = Legal.MasteryLA[index];
var learn = Legal.LevelUpLA[index];
ushort alpha = 0;
ushort alpha = pkm is PA8 pa ? pa.AlphaMove : (ushort)0;
if (!p.IsValidPurchasedEncounter(learn, level, alpha, allowAlphaPurchaseBug))
return false;
Span<int> moves = stackalloc int[4];
var mastery = Legal.MasteryLA[index];
if (pkm is PA8 { AlphaMove: not 0 } pa8)
{
moves[0] = alpha = pa8.AlphaMove;
moves[0] = pa8.AlphaMove;
learn.SetEncounterMovesBackwards(level, moves, 1);
}
else
@ -157,7 +161,7 @@ public sealed record EncounterSlot8a : EncounterSlot, IAlpha, IMasteryInitialMov
learn.SetEncounterMoves(level, moves);
}
return p.IsValidMasteredEncounter(moves, learn, mastery, level, alpha);
return p.IsValidMasteredEncounter(moves, learn, mastery, level, alpha, allowAlphaPurchaseBug);
}
private OverworldParam8a GetParams()

View file

@ -122,17 +122,21 @@ public sealed record EncounterStatic8a(GameVersion Version) : EncounterStatic(Ve
if (pkm is not IMoveShop8Mastery p)
return true;
Span<int> moves = stackalloc int[4];
const bool allowAlphaPurchaseBug = true; // Everything else Alpha is pre-1.1
var level = pkm.Met_Level;
var index = PersonalTable.LA.GetFormIndex(Species, Form);
var learn = Legal.LevelUpLA[index];
if (!p.IsValidPurchasedEncounter(learn, level, alpha, allowAlphaPurchaseBug))
return false;
Span<int> moves = stackalloc int[4];
var mastery = Legal.MasteryLA[index];
if (Moves.Count != 0)
moves = (int[])Moves;
else
learn.SetEncounterMoves(level, moves);
return p.IsValidMasteredEncounter(moves, learn, mastery, level, alpha);
return p.IsValidMasteredEncounter(moves, learn, mastery, level, alpha, allowAlphaPurchaseBug);
}
protected override void SetEncounterMoves(PKM pk, GameVersion version, int level)

View file

@ -93,7 +93,7 @@ namespace PKHeX.Core
}
}
internal static EncounterStatic7 GetVCStaticTransferEncounter(PKM pkm, IEncounterTemplate enc, IReadOnlyList<EvoCriteria> chain)
internal static EncounterStatic7 GetVCStaticTransferEncounter(PKM pkm, IEncounterTemplate enc, ReadOnlySpan<EvoCriteria> chain)
{
// Obtain the lowest evolution species with matching OT friendship. Not all species chains have the same base friendship.
var met = (byte)pkm.Met_Level;
@ -113,7 +113,7 @@ namespace PKHeX.Core
}
}
private static int GetVCSpecies(IReadOnlyList<EvoCriteria> chain, PKM pkm, int max)
private static int GetVCSpecies(ReadOnlySpan<EvoCriteria> chain, PKM pkm, int max)
{
int species = pkm.Species;
foreach (var z in chain)

View file

@ -21,7 +21,36 @@ public interface IMoveShop8Mastery : IMoveShop8
public static class MoveShop8MasteryExtensions
{
public static bool IsValidMasteredEncounter(this IMoveShop8Mastery shop, Span<int> moves, Learnset learn, Learnset mastery, int level, ushort alpha)
public static bool IsValidPurchasedEncounter(this IMoveShop8 shop, Learnset learn, int level, ushort alpha, bool allowPurchasedAlpha)
{
var permit = shop.MoveShopPermitIndexes;
var current = shop.MoveShopPermitFlags;
for (int i = 0; i < current.Length; i++)
{
if (!current[i])
continue;
if (!shop.GetPurchasedRecordFlag(i))
continue;
var move = permit[i];
// Can only purchase a move if it is not already in the available learnset.
var learnLevel = learn.GetMoveLevel(move);
if (learnLevel <= level)
return false;
// Can only purchase an Alpha Move if it was pre-1.1 patch.
if (move == alpha && allowPurchasedAlpha)
continue;
return false;
}
return true;
}
public static bool IsValidMasteredEncounter(this IMoveShop8Mastery shop, Span<int> moves, Learnset learn, Learnset mastery, int level, ushort alpha, bool allowPurchasedAlpha)
{
foreach (var move in moves)
{
@ -46,7 +75,13 @@ public static class MoveShop8MasteryExtensions
}
else
{
if (p || !m)
// Pre 1.1 patch, players could purchase the Alpha Move from the move shop.
// After the patch, the Alpha Move is considered purchased (even without the flag).
// Players won't be able to waste money after the patch :)
// For legality, allow the Alpha Move to be flagged as Purchased if it was a pre-patch capture.
if (p && (move != alpha || !allowPurchasedAlpha))
return false;
if (!m)
return false;
}
}