using PkmnLib.Static.Utils;
namespace PkmnLib.Static.Species;
///
/// The storage of the moves a Pokemon can learn.
///
public interface ILearnableMoves
{
///
/// Adds a new level move the Pokemon can learn.
///
/// The level the Pokemon learns the move at.
/// The move the Pokemon learns.
/// Whether the move was added successfully.
void AddLevelMove(LevelInt level, StringKey move);
///
/// Gets all moves a Pokemon can learn when leveling up to a specific level.
///
/// The level the Pokemon is learning moves at.
/// The moves the Pokemon learns at that level.
IReadOnlyList GetLearnedByLevel(LevelInt level);
///
/// Gets the distinct moves a Pokemon can learn through leveling up.
///
/// The moves the Pokemon can learn through leveling up.
IReadOnlyList GetDistinctLevelMoves();
}
public class LearnableMovesImpl : ILearnableMoves
{
private readonly Dictionary> _learnedByLevel = new();
private readonly HashSet _distinctLevelMoves = new();
public void AddLevelMove(LevelInt level, StringKey move)
{
if (!_learnedByLevel.TryGetValue(level, out var value))
_learnedByLevel[level] = [move];
else
value.Add(move);
_distinctLevelMoves.Add(move);
}
public IReadOnlyList GetLearnedByLevel(LevelInt level)
{
if (!_learnedByLevel.TryGetValue(level, out var value))
return Array.Empty();
return value;
}
public IReadOnlyList GetDistinctLevelMoves()
{
return _distinctLevelMoves.ToList();
}
}