Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
using System;
|
Gen 1 move analysis improvement. Adapted the valid moves to take into account that move deleter and move reminder do not exits in generation 1 (#1037)
* Fix getMoves with min level, when SkipWhile and TakeWhile is used together the index i in TakeWhile is calculated from the enumerator that results of the SkipWhile function, not the index of the initial array, those giving an incorrect index to check Levels array in the TakeWhile
* Fix getMoves when levelmin or levelmax is above max level in the levels array, TakeWhile and SkipWhile return empty list if the while goes beyond the last element of the array
* Include player hatched egg in the list of possible encounters for parseMoves only if the pokemon was an egg
Also change the valur of WasEgg for gen1,2,3 pokemon if the encounter analyzed is not an egg
add the non egg encounters to the list instead of checking the non-egg encounter inside parseMovesWasEggPreRelearn
* Fix for gen3 egg encounters
Remove non-egg encounters without special moves if there is an egg encounter because egg encounter already cover every possible move combination
Do not add daycare egg encounter for gen3 unhatched egg if there is another encounter, that means is an event or gift egg, not a daycare egg
Remove duplicate encounters
* Gift egg should not allow inherited moves even it they dont have special moves
Those gift eggs are hatched only with the species base moves
* Added getEncounterMoves functions, to be used for generation 1 encounters to find what moves have a pokemon at the moment of being caught because there is no move reminder in generation 1
* Added GBEncounterData, structure for refactor the tuples used in generation 1 and 2 encounters
* Add LevelMin and LevelMax to IEncounterable to get the encounter moves by the min level of the generation 1 EncounterLink
Add iGeneration to difference generation 1 and generation 2 encounters for GB Era pokemon
* Mark generation in gen 1 and 2 encounters
There is no need to mark the generation in gen 3 to 7 encounters because in that generations it match the pokemon generation number
* Add min level for generation 1 moves in getMoves functions
Add function to return the default moves for a GB encounters, for generation 1 games that included both moves from level up table and level 1 moves from personal table
Fix getMoves with min level when the moves list is empty, like Raichu generation 1
* Add maxSpecies to getBaseSpecies function for gen1 pokemon with a gen2 egg encounter
Refactor VC Encounter changing Tuples for GBData class
* Fixed for gen 2 Checks
Also do not search for generation1 encounter if the gen2 pokemon have met location from crystal
* Fix VC wild encounters, should be stored as array or else other verifyEncounter functions wont work
* Add generation 1 parse moves function including default moves
* Clean-up get encounters
* Verify empty moves for generation 1 encounters, in generation 1 does not exits move deleter
That means when a move slot have been used by a level up move or a TM/HM/Tutor move it cant be empty again
Does not apply if generation 2 tradeback is allowed, in generation 2 there is a move deleter
* Added two edge cases for pokemon that learn in red/blue and yellow different moves at the same level, this combinations can not exits until a later level when they learn again one of the levels in the other game, only happen for flareon and vaporeon
* Check incompatible moves between evolution species, it is for species that learn a move in a level as an evolved species and a move at a upper level as a preevolution
Also added most edge cases for the min slots used for generation 1 games, i think every weird combination is already covered
* Fix gen 1 eevee and evolutions move checks
* Cleanup
* Move the code to change valid moves for generation 1 to a function
* Fix getMoveMinLevelGBEncounter
* getUsedMoveSlots, removed wild Butterfree edge case, it is not possible
* Filter the min level of the encounter by the possible games the pokemon could be originated, yellow pikachu and kadabra can be detected
2017-04-09 00:17:20 +00:00
|
|
|
using System.Collections.Generic;
|
2016-11-08 16:43:57 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Level Up Learn Movepool Information
|
|
|
|
/// </summary>
|
|
|
|
public sealed class Learnset
|
2016-11-08 16:43:57 +00:00
|
|
|
{
|
2018-07-21 03:22:46 +00:00
|
|
|
/// <summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
/// Moves that can be learned.
|
2018-07-21 03:22:46 +00:00
|
|
|
/// </summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
internal readonly ushort[] Moves;
|
2018-07-21 03:22:46 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Levels at which a move at a given index can be learned.
|
|
|
|
/// </summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
private readonly byte[] Levels;
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public Learnset(ushort[] moves, byte[] levels)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
Moves = moves;
|
|
|
|
Levels = levels;
|
|
|
|
}
|
2016-11-08 16:43:57 +00:00
|
|
|
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
public (bool HasMoves, int Start, int End) GetMoveRange(int maxLevel, int minLevel = 0)
|
|
|
|
{
|
|
|
|
if (minLevel <= 1 && maxLevel >= 100)
|
|
|
|
return (true, 0, Moves.Length - 1);
|
|
|
|
if (minLevel > maxLevel)
|
|
|
|
return default;
|
|
|
|
int start = Array.FindIndex(Levels, z => z >= minLevel);
|
|
|
|
if (start < 0)
|
|
|
|
return default;
|
|
|
|
int end = Array.FindLastIndex(Levels, z => z <= maxLevel);
|
|
|
|
if (end < 0)
|
|
|
|
return default;
|
|
|
|
|
|
|
|
return (true, start, end);
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>Returns the moves a Pokémon would have if it were encountered at the specified level.</summary>
|
|
|
|
/// <remarks>In Generation 1, it is not possible to learn any moves lower than these encounter moves.</remarks>
|
|
|
|
/// <param name="level">The level the Pokémon was encountered at.</param>
|
|
|
|
/// <returns>Array of Move IDs</returns>
|
2022-08-27 06:43:36 +00:00
|
|
|
public ushort[] GetEncounterMoves(int level)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
const int count = 4;
|
2022-08-27 06:43:36 +00:00
|
|
|
var moves = new ushort[count];
|
2022-06-18 18:04:24 +00:00
|
|
|
SetEncounterMoves(level, moves);
|
|
|
|
return moves;
|
|
|
|
}
|
2018-06-13 01:35:56 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>Returns the moves a Pokémon would have if it were encountered at the specified level.</summary>
|
|
|
|
/// <remarks>In Generation 1, it is not possible to learn any moves lower than these encounter moves.</remarks>
|
|
|
|
/// <param name="level">The level the Pokémon was encountered at.</param>
|
|
|
|
/// <param name="moves">Move array to write to</param>
|
|
|
|
/// <param name="ctr">Starting index to begin overwriting at</param>
|
|
|
|
/// <returns>Array of Move IDs</returns>
|
2022-08-27 06:43:36 +00:00
|
|
|
public void SetEncounterMoves(int level, Span<ushort> moves, int ctr = 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < Moves.Length; i++)
|
2018-06-13 01:35:56 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Levels[i] > level)
|
|
|
|
break;
|
2018-06-13 01:35:56 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
var move = Moves[i];
|
2023-03-22 01:19:55 +00:00
|
|
|
if (moves.Contains(move))
|
2022-06-18 18:04:24 +00:00
|
|
|
continue;
|
2022-02-05 01:35:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
moves[ctr++] = move;
|
|
|
|
ctr &= 3;
|
2022-02-05 01:35:15 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2022-02-05 01:35:15 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public void SetEncounterMovesBackwards(int level, Span<ushort> moves, int ctr = 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
int index = Array.FindLastIndex(Levels, z => z <= level);
|
2022-05-06 22:43:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (index == -1)
|
|
|
|
return; // no moves to add?
|
2022-05-06 22:43:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// In the event we have multiple moves at the same level, insert them in regular descending order.
|
|
|
|
int start = index;
|
|
|
|
while (start != 0 && Levels[start] == Levels[start - 1])
|
|
|
|
start--;
|
2022-05-06 22:43:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int i = start; i <= index; i++)
|
|
|
|
{
|
|
|
|
var move = Moves[i];
|
2023-03-22 01:19:55 +00:00
|
|
|
if (moves.Contains(move))
|
|
|
|
continue;
|
2022-05-06 22:43:23 +00:00
|
|
|
|
2023-03-22 01:19:55 +00:00
|
|
|
moves[ctr++] = move;
|
2022-06-18 18:04:24 +00:00
|
|
|
if (ctr == 4)
|
|
|
|
return;
|
2022-05-06 22:43:23 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
index = start - 1;
|
2022-05-06 22:43:23 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2022-05-06 22:43:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>Adds the learned moves by level up to the specified level.</summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
public void SetLevelUpMoves(int startLevel, int endLevel, Span<ushort> moves, int ctr = 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
int startIndex = Array.FindIndex(Levels, z => z >= startLevel);
|
|
|
|
int endIndex = Array.FindIndex(Levels, z => z > endLevel);
|
|
|
|
for (int i = startIndex; i < endIndex; i++)
|
2022-02-05 01:35:15 +00:00
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
var move = Moves[i];
|
2022-06-18 18:04:24 +00:00
|
|
|
bool alreadyHasMove = moves.IndexOf(move) >= 0;
|
|
|
|
if (alreadyHasMove)
|
|
|
|
continue;
|
2022-02-05 01:35:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
moves[ctr++] = move;
|
|
|
|
ctr &= 3;
|
2022-02-05 01:35:15 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2022-02-05 01:35:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>Adds the moves that are gained upon evolving.</summary>
|
|
|
|
/// <param name="moves">Move array to write to</param>
|
|
|
|
/// <param name="ctr">Starting index to begin overwriting at</param>
|
2022-08-27 06:43:36 +00:00
|
|
|
public void SetEvolutionMoves(Span<ushort> moves, int ctr = 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < Moves.Length; i++)
|
2022-02-05 01:35:15 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Levels[i] != 0)
|
|
|
|
break;
|
2022-02-05 01:35:15 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
var move = Moves[i];
|
2022-06-18 18:04:24 +00:00
|
|
|
bool alreadyHasMove = moves.IndexOf(move) >= 0;
|
|
|
|
if (alreadyHasMove)
|
|
|
|
continue;
|
2017-09-24 17:36:16 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
moves[ctr++] = move;
|
|
|
|
ctr &= 3;
|
Gen 1 move analysis improvement. Adapted the valid moves to take into account that move deleter and move reminder do not exits in generation 1 (#1037)
* Fix getMoves with min level, when SkipWhile and TakeWhile is used together the index i in TakeWhile is calculated from the enumerator that results of the SkipWhile function, not the index of the initial array, those giving an incorrect index to check Levels array in the TakeWhile
* Fix getMoves when levelmin or levelmax is above max level in the levels array, TakeWhile and SkipWhile return empty list if the while goes beyond the last element of the array
* Include player hatched egg in the list of possible encounters for parseMoves only if the pokemon was an egg
Also change the valur of WasEgg for gen1,2,3 pokemon if the encounter analyzed is not an egg
add the non egg encounters to the list instead of checking the non-egg encounter inside parseMovesWasEggPreRelearn
* Fix for gen3 egg encounters
Remove non-egg encounters without special moves if there is an egg encounter because egg encounter already cover every possible move combination
Do not add daycare egg encounter for gen3 unhatched egg if there is another encounter, that means is an event or gift egg, not a daycare egg
Remove duplicate encounters
* Gift egg should not allow inherited moves even it they dont have special moves
Those gift eggs are hatched only with the species base moves
* Added getEncounterMoves functions, to be used for generation 1 encounters to find what moves have a pokemon at the moment of being caught because there is no move reminder in generation 1
* Added GBEncounterData, structure for refactor the tuples used in generation 1 and 2 encounters
* Add LevelMin and LevelMax to IEncounterable to get the encounter moves by the min level of the generation 1 EncounterLink
Add iGeneration to difference generation 1 and generation 2 encounters for GB Era pokemon
* Mark generation in gen 1 and 2 encounters
There is no need to mark the generation in gen 3 to 7 encounters because in that generations it match the pokemon generation number
* Add min level for generation 1 moves in getMoves functions
Add function to return the default moves for a GB encounters, for generation 1 games that included both moves from level up table and level 1 moves from personal table
Fix getMoves with min level when the moves list is empty, like Raichu generation 1
* Add maxSpecies to getBaseSpecies function for gen1 pokemon with a gen2 egg encounter
Refactor VC Encounter changing Tuples for GBData class
* Fixed for gen 2 Checks
Also do not search for generation1 encounter if the gen2 pokemon have met location from crystal
* Fix VC wild encounters, should be stored as array or else other verifyEncounter functions wont work
* Add generation 1 parse moves function including default moves
* Clean-up get encounters
* Verify empty moves for generation 1 encounters, in generation 1 does not exits move deleter
That means when a move slot have been used by a level up move or a TM/HM/Tutor move it cant be empty again
Does not apply if generation 2 tradeback is allowed, in generation 2 there is a move deleter
* Added two edge cases for pokemon that learn in red/blue and yellow different moves at the same level, this combinations can not exits until a later level when they learn again one of the levels in the other game, only happen for flareon and vaporeon
* Check incompatible moves between evolution species, it is for species that learn a move in a level as an evolved species and a move at a upper level as a preevolution
Also added most edge cases for the min slots used for generation 1 games, i think every weird combination is already covered
* Fix gen 1 eevee and evolutions move checks
* Cleanup
* Move the code to change valid moves for generation 1 to a function
* Fix getMoveMinLevelGBEncounter
* getUsedMoveSlots, removed wild Butterfree edge case, it is not possible
* Filter the min level of the encounter by the possible games the pokemon could be originated, yellow pikachu and kadabra can be detected
2017-04-09 00:17:20 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-06-13 01:35:56 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>Adds the learned moves by level up to the specified level.</summary>
|
2022-08-27 06:43:36 +00:00
|
|
|
public void SetLevelUpMoves(int startLevel, int endLevel, Span<ushort> moves, ReadOnlySpan<ushort> ignore, int ctr = 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
int startIndex = Array.FindIndex(Levels, z => z >= startLevel);
|
|
|
|
if (startIndex == -1)
|
|
|
|
return; // No more remain
|
|
|
|
int endIndex = Array.FindIndex(Levels, z => z > endLevel);
|
|
|
|
if (endIndex == -1)
|
|
|
|
endIndex = Levels.Length;
|
|
|
|
for (int i = startIndex; i < endIndex; i++)
|
2022-02-06 00:47:19 +00:00
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
var move = Moves[i];
|
2022-06-18 18:04:24 +00:00
|
|
|
if (ignore.IndexOf(move) >= 0)
|
|
|
|
continue;
|
2022-02-06 00:47:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
bool alreadyHasMove = moves.IndexOf(move) >= 0;
|
|
|
|
if (alreadyHasMove)
|
|
|
|
continue;
|
2022-02-06 00:47:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
moves[ctr++] = move;
|
|
|
|
ctr &= 3;
|
2022-02-06 00:47:19 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2022-02-06 00:47:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <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>
|
2022-08-27 06:43:36 +00:00
|
|
|
public void SetEvolutionMoves(Span<ushort> moves, ReadOnlySpan<ushort> ignore, int ctr = 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < Moves.Length; i++)
|
2022-02-06 00:47:19 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Levels[i] != 0)
|
|
|
|
break;
|
2022-02-06 00:47:19 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
var move = Moves[i];
|
2022-06-18 18:04:24 +00:00
|
|
|
if (ignore.IndexOf(move) >= 0)
|
|
|
|
continue;
|
2022-02-06 00:47:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
bool alreadyHasMove = moves.IndexOf(move) >= 0;
|
|
|
|
if (alreadyHasMove)
|
|
|
|
continue;
|
2022-02-06 00:47:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
moves[ctr++] = move;
|
|
|
|
ctr &= 3;
|
2022-02-06 00:47:19 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2022-02-06 00:47:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>Returns the index of the lowest level move if the Pokémon were encountered at the specified level.</summary>
|
|
|
|
/// <remarks>Helps determine the minimum level an encounter can be at.</remarks>
|
|
|
|
/// <param name="level">The level the Pokémon was encountered at.</param>
|
|
|
|
/// <returns>Array of Move IDs</returns>
|
|
|
|
public int GetMinMoveLevel(int level)
|
|
|
|
{
|
|
|
|
if (Levels.Length == 0)
|
|
|
|
return 1;
|
2017-04-09 02:05:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int end = Array.FindLastIndex(Levels, z => z <= level);
|
|
|
|
return Math.Max(end - 4, 1);
|
|
|
|
}
|
2017-04-09 02:05:29 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public int GetMoveLevel(ushort move)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var index = Array.LastIndexOf(Moves, move);
|
|
|
|
if (index == -1)
|
|
|
|
return -1;
|
|
|
|
return Levels[index];
|
|
|
|
}
|
2022-05-06 22:43:23 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
private Dictionary<ushort, byte>? Learn;
|
2018-08-02 01:30:51 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
private Dictionary<ushort, byte> GetDictionary()
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-08-27 06:43:36 +00:00
|
|
|
// Create a dictionary, with the move as the key and the level as the value.
|
|
|
|
// Due to the ordering of the object, this will result in fetching the lowest level for a move.
|
|
|
|
var dict = new Dictionary<ushort, byte>(Moves.Length);
|
|
|
|
for (int i = Moves.Length - 1; i >= 0; i--)
|
|
|
|
dict[Moves[i]] = Levels[i];
|
2022-06-18 18:04:24 +00:00
|
|
|
return dict;
|
|
|
|
}
|
2018-06-08 02:05:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>Returns the level that a Pokémon can learn the specified move.</summary>
|
|
|
|
/// <param name="move">Move ID</param>
|
|
|
|
/// <returns>Level the move is learned at. If the result is below 0, the move cannot be learned by leveling up.</returns>
|
2022-08-27 06:43:36 +00:00
|
|
|
public int GetLevelLearnMove(ushort move)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
return (Learn ??= GetDictionary()).TryGetValue(move, out var level) ? level : -1;
|
|
|
|
}
|
2018-06-09 03:10:41 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>Returns the level that a Pokémon can learn the specified move.</summary>
|
|
|
|
/// <param name="move">Move ID</param>
|
|
|
|
/// <param name="min">Minimum level to start looking at.</param>
|
|
|
|
/// <returns>Level the move is learned at. If the result is below 0, the move cannot be learned by leveling up.</returns>
|
2022-08-27 06:43:36 +00:00
|
|
|
public int GetLevelLearnMove(ushort move, int min)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < Moves.Length; i++)
|
2018-06-09 03:10:41 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (move != Moves[i])
|
|
|
|
continue;
|
2018-06-09 03:10:41 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var lv = Levels[i];
|
|
|
|
if (lv >= min)
|
|
|
|
return lv;
|
2018-06-09 03:10:41 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2021-04-05 01:30:01 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public ReadOnlySpan<ushort> GetBaseEggMoves(int level)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
// Count moves <= level
|
|
|
|
var count = 0;
|
|
|
|
foreach (var x in Levels)
|
2021-04-05 01:30:01 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (x > level)
|
|
|
|
break;
|
|
|
|
count++;
|
|
|
|
}
|
2021-04-05 01:30:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Return a slice containing the moves <= level.
|
|
|
|
if (count == 0)
|
2022-08-27 06:43:36 +00:00
|
|
|
return ReadOnlySpan<ushort>.Empty;
|
2021-04-05 01:30:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int start = 0;
|
|
|
|
if (count > 4)
|
|
|
|
{
|
|
|
|
start = count - 4;
|
|
|
|
count = 4;
|
2021-04-05 01:30:01 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return Moves.AsSpan(start, count);
|
2016-11-08 16:43:57 +00:00
|
|
|
}
|
|
|
|
}
|