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