mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-23 05:24:14 -05:00
Convert GetLevelLearnMove to use lazy dictionary
faster move lookup
This commit is contained in:
@@ -66,13 +66,23 @@ public int GetMinMoveLevel(int level)
|
||||
return Math.Max(end - 4, 1);
|
||||
}
|
||||
|
||||
|
||||
private Dictionary<int, int> Learn;
|
||||
private Dictionary<int, int> GetDictionary()
|
||||
{
|
||||
var dict = new Dictionary<int, int>();
|
||||
for (int i = 0; i < Moves.Length; i++)
|
||||
if (!dict.ContainsKey(Moves[i]))
|
||||
dict.Add(Moves[i], Levels[i]);
|
||||
return dict;
|
||||
}
|
||||
|
||||
/// <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, it cannot be learned by levelup.</returns>
|
||||
public int GetLevelLearnMove(int move)
|
||||
{
|
||||
int index = Array.IndexOf(Moves, move);
|
||||
return index < 0 ? index : Levels[index];
|
||||
return (Learn ?? (Learn = GetDictionary())).TryGetValue(move, out var level) ? level : -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user