mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-10 22:54:14 +00:00
Min move count: ignore purchased moves
This commit is contained in:
parent
07b3efd14d
commit
e8903505df
4 changed files with 71 additions and 2 deletions
|
@ -158,6 +158,50 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>Adds the learned moves by level up to the specified level.</summary>
|
||||
public void SetLevelUpMoves(int startLevel, int endLevel, Span<int> moves, ReadOnlySpan<int> ignore, int ctr = 0)
|
||||
{
|
||||
int startIndex = Array.FindIndex(Levels, z => z >= startLevel);
|
||||
int endIndex = Array.FindIndex(Levels, z => z > endLevel);
|
||||
for (int i = startIndex; i < endIndex; i++)
|
||||
{
|
||||
int move = Moves[i];
|
||||
if (ignore.IndexOf(move) >= 0)
|
||||
continue;
|
||||
|
||||
bool alreadyHasMove = moves.IndexOf(move) >= 0;
|
||||
if (alreadyHasMove)
|
||||
continue;
|
||||
|
||||
moves[ctr++] = move;
|
||||
ctr &= 3;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Adds the moves that are gained upon evolving.</summary>
|
||||
/// <param name="moves">Move array to write to</param>
|
||||
/// <param name="ignore">Ignored moves</param>
|
||||
/// <param name="ctr">Starting index to begin overwriting at</param>
|
||||
public void SetEvolutionMoves(Span<int> moves, ReadOnlySpan<int> ignore, int ctr = 0)
|
||||
{
|
||||
for (int i = 0; i < Moves.Length; i++)
|
||||
{
|
||||
if (Levels[i] != 0)
|
||||
break;
|
||||
|
||||
int move = Moves[i];
|
||||
if (ignore.IndexOf(move) >= 0)
|
||||
continue;
|
||||
|
||||
bool alreadyHasMove = moves.IndexOf(move) >= 0;
|
||||
if (alreadyHasMove)
|
||||
continue;
|
||||
|
||||
moves[ctr++] = move;
|
||||
ctr &= 3;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<int> GetUniqueMovesLearned(IEnumerable<int> seed, int maxLevel, int minLevel = 0)
|
||||
{
|
||||
int start = Array.FindIndex(Levels, z => z >= minLevel);
|
||||
|
|
|
@ -92,8 +92,12 @@ public sealed class LegendsArceusVerifier : Verifier
|
|||
if ((uint)count >= 4)
|
||||
return 4;
|
||||
|
||||
var purchasedCount = pa.GetPurchasedCount();
|
||||
Span<int> purchased = stackalloc int[purchasedCount];
|
||||
LoadPurchasedMoves(pa, purchased);
|
||||
|
||||
// Level up to current level
|
||||
moveset.SetLevelUpMoves(pa.Met_Level, pa.CurrentLevel, moves, count);
|
||||
moveset.SetLevelUpMoves(pa.Met_Level, pa.CurrentLevel, moves, purchased, count);
|
||||
count = moves.IndexOf(0);
|
||||
if ((uint)count >= 4)
|
||||
return 4;
|
||||
|
@ -104,7 +108,7 @@ public sealed class LegendsArceusVerifier : Verifier
|
|||
var (species, form) = evos[i];
|
||||
index = pt.GetFormIndex(species, form);
|
||||
moveset = Legal.LevelUpLA[index];
|
||||
moveset.SetEvolutionMoves(moves, count);
|
||||
moveset.SetEvolutionMoves(moves, purchased, count);
|
||||
count = moves.IndexOf(0);
|
||||
if ((uint)count >= 4)
|
||||
return 4;
|
||||
|
@ -114,6 +118,17 @@ public sealed class LegendsArceusVerifier : Verifier
|
|||
return AddMasteredMissing(pa, moves, count);
|
||||
}
|
||||
|
||||
private static void LoadPurchasedMoves(IMoveShop8 pa, Span<int> result)
|
||||
{
|
||||
int ctr = 0;
|
||||
var purchased = pa.MoveShopPermitIndexes;
|
||||
for (int i = 0; i < purchased.Length; i++)
|
||||
{
|
||||
if (pa.GetPurchasedRecordFlag(i))
|
||||
result[ctr++] = purchased[i];
|
||||
}
|
||||
}
|
||||
|
||||
private static int AddMasteredMissing(PA8 pa, Span<int> current, int ctr)
|
||||
{
|
||||
for (int i = 0; i < pa.MoveShopPermitIndexes.Length; i++)
|
||||
|
|
|
@ -524,6 +524,15 @@ public sealed class PA8 : PKM, ISanityChecksum,
|
|||
|
||||
public bool GetPurchasedRecordFlagAny() => Array.FindIndex(Data, 0x155, 8, z => z != 0) >= 0;
|
||||
|
||||
public int GetPurchasedCount()
|
||||
{
|
||||
var value = ReadUInt64LittleEndian(Data.AsSpan(0x155));
|
||||
ulong result = 0;
|
||||
for (int i = 0; i < 64; i++)
|
||||
result += ((value >> i) & 1);
|
||||
return (int)result;
|
||||
}
|
||||
|
||||
public bool GetMasteredRecordFlag(int index)
|
||||
{
|
||||
if ((uint)index > 63) // 8 bytes, 8 bits
|
||||
|
|
|
@ -9,6 +9,7 @@ public interface IMoveShop8
|
|||
bool GetPurchasedRecordFlag(int index);
|
||||
void SetPurchasedRecordFlag(int index, bool value);
|
||||
bool GetPurchasedRecordFlagAny();
|
||||
int GetPurchasedCount();
|
||||
}
|
||||
|
||||
public interface IMoveShop8Mastery : IMoveShop8
|
||||
|
|
Loading…
Reference in a new issue